Commit c808a5cc authored by Uwe Schulzweida's avatar Uwe Schulzweida
Browse files

New operator delindex - Delete grid cells by indices.

parent f547ed3c
......@@ -3,6 +3,10 @@
* Using CDI library version 1.8.1
* Version 1.8.1 release
2017-03-09 Uwe Schulzweida
* New operator delindex - Delete grid cells by indices
2017-03-06 Uwe Schulzweida
* New operator selmulti: Select multiple fields (patch from Michal Koutek, KMNI)
......@@ -171,7 +175,7 @@
2016-07-29 Uwe Schulzweida
* New operator selindex - Select grid indices
* New operator selindex - Select grid cells by indices
2016-07-18 Uwe Schulzweida
......
......@@ -77,10 +77,15 @@ void *Selindex(void *argument)
cdoInitialize(argument);
cdoOperatorAdd("selindex", 0, 0, "grid cell indices (1-N)");
int SELINDEX = cdoOperatorAdd("selindex", 0, 0, "grid cell indices (1-N)");
int DELINDEX = cdoOperatorAdd("delindex", 0, 0, "grid cell indices (1-N)");
UNUSED(SELINDEX);
operatorInputArg(cdoOperatorEnter(0));
int operatorID = cdoOperatorID();
int nind = args2int_lista(operatorArgc(), operatorArgv(), ilista);
int *indarr = (int*) lista_dataptr(ilista);
......@@ -111,12 +116,27 @@ void *Selindex(void *argument)
vlistDefTaxis(vlistID2, taxisID2);
int nvars = vlistNvars(vlistID1);
bool *vars = (bool*) Malloc(nvars*sizeof(bool));
bool *vars = (bool*) Malloc(nvars*sizeof(bool));
for ( varID = 0; varID < nvars; varID++ ) vars[varID] = false;
int ngrids = vlistNgrids(vlistID1);
sindex_t *sindex = (sindex_t *) Malloc(ngrids*sizeof(sindex_t));
int ncells = nind;
int *cellidx = indarr;
if ( operatorID == DELINDEX )
{
int gridsize = vlistGridsizeMax(vlistID1);
ncells = gridsize - nind;
cellidx = (int*) Malloc(gridsize*sizeof(int));
for ( int i = 0; i < gridsize; ++i ) cellidx[i] = 1;
for ( int i = 0; i < nind; ++i ) cellidx[indarr[i]] = 0;
int j = 0;
for ( int i = 0; i < gridsize; ++i )
if ( cellidx[i] == 1 ) cellidx[j++] = i;
if ( j != ncells ) cdoAbort("Internal error; number of cells differ");
}
for ( index = 0; index < ngrids; index++ )
{
gridID1 = vlistGrid(vlistID1, index);
......@@ -130,7 +150,7 @@ void *Selindex(void *argument)
continue;
}
gridID2 = genindexgrid(gridID1, nind, indarr);
gridID2 = genindexgrid(gridID1, ncells, cellidx);
if ( gridID2 == -1 )
{
......@@ -191,7 +211,7 @@ void *Selindex(void *argument)
gridsize2 = gridInqSize(sindex[index].gridID2);
sel_index(array1, array2, nind, indarr);
sel_index(array1, array2, ncells, cellidx);
if ( nmiss )
{
......@@ -223,6 +243,8 @@ void *Selindex(void *argument)
lista_destroy(ilista);
if ( operatorID == DELINDEX ) Free(cellidx);
cdoFinish();
return 0;
......
......@@ -618,8 +618,18 @@ void verify_grid(int gridtype, int gridsize, int gridno, int ngrids, int ncorner
int winding_number = winding_numbers_algorithm(cell_corners_plane_projection, actual_number_of_corners + 1, center_point_plane_projection);
// if ( winding_number == 0 ) printf("%d,", cell_no+1);
if ( winding_number == 0 )
no_of_cells_with_center_points_out_of_bounds += 1;
if ( cdoVerbose && winding_number == 0 )
{
printf("cell_no %d: ", cell_no+1);
printf(" lon=%g lat=%g : ", grid_center_lon[cell_no], grid_center_lat[cell_no]);
for ( int corner_no = 0; corner_no < ncorner; corner_no++ )
printf(" %g/%g ", grid_corner_lon[cell_no * ncorner + corner_no], grid_corner_lat[cell_no * ncorner + corner_no]);
printf("\n");
}
}
int no_nonunique_cells = gridsize - no_unique_center_points;
......
......@@ -409,7 +409,7 @@ void *Samplegrid(void *argument); // "samplegrid", "subgrid"
#define SeaspctlOperators {"seaspctl"}
#define SeasstatOperators {"seasmin", "seasmax", "seassum", "seasmean", "seasavg", "seasstd", "seasstd1", "seasvar", "seasvar1"}
#define SelboxOperators {"sellonlatbox", "selindexbox"}
#define SelindexOperators {"selindex"}
#define SelindexOperators {"selindex", "delindex"}
#define SelectOperators {"select", "delete"}
#define SelvarOperators {"selparam", "selcode", "selname", "selstdname", "sellevel", "sellevidx", "selgrid", \
"selzaxis", "selzaxisname", "seltabnum", "delparam", "delcode", "delname", "selltype"}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment