Commit 21b02bcb authored by Uwe Schulzweida's avatar Uwe Schulzweida
Browse files

Merstat: call gridWeights only if needed

parent 3c38bf41
......@@ -12,6 +12,7 @@
* splitgrid: generate file name from gridID+1
* Vardup: bug fix for missing values
* Timsort: bug fix for time constant fields
* Merstat: call gridWeights only if needed
* Math: rename log to ln
* Change help info format
* Selbox, Maskbox, Fldrms, Mergegrid, Zonstat, Merstat, Output: check number of different grids
......
......@@ -119,7 +119,7 @@ void *Fldstat(void *argument)
field.grid = vlistInqVarGrid(vlistID1, varID);
field.size = gridInqSize(field.grid);
if ( field.grid != lastgrid )
if ( needWeights && field.grid != lastgrid )
{
lastgrid = field.grid;
if ( needWeights ) gridWeights(field.grid, field.weight);
......
......@@ -50,6 +50,7 @@ void *Merstat(void *argument)
int lim;
int ndiffgrids;
int taxisID1, taxisID2;
int needWeights = FALSE;
FIELD field1, field2;
cdoInitialize(argument);
......@@ -65,6 +66,10 @@ void *Merstat(void *argument)
operatorID = cdoOperatorID();
operfunc = cdoOperatorFunc(operatorID);
if ( operfunc == func_mean || operfunc == func_avg ||
operfunc == func_var || operfunc == func_std )
needWeights = TRUE;
streamID1 = streamOpenRead(cdoStreamName(0));
if ( streamID1 < 0 ) cdiError(streamID1, "Open failed on %s", cdoStreamName(0));
......@@ -102,7 +107,9 @@ void *Merstat(void *argument)
lim = vlistGridsizeMax(vlistID1);
field1.ptr = (double *) malloc(lim*sizeof(double));
field1.weight = (double *) malloc(lim*sizeof(double));
field1.weight = NULL;
if ( needWeights )
field1.weight = (double *) malloc(lim*sizeof(double));
field2.ptr = (double *) malloc(nlonmax*sizeof(double));
field2.grid = gridID2;
......@@ -120,7 +127,7 @@ void *Merstat(void *argument)
streamReadRecord(streamID1, field1.ptr, &field1.nmiss);
field1.grid = vlistInqVarGrid(vlistID1, varID);
if ( field1.grid != lastgrid )
if ( needWeights && field1.grid != lastgrid )
{
lastgrid = field1.grid;
gridWeights(field1.grid, field1.weight);
......
......@@ -157,6 +157,7 @@ void *Setgrid(void *argument)
else if ( gridtype == GRID_CELL ) gridID2 = gridToCell(gridID1);
else cdoAbort("%s grid unsupported!", gridname);
/* gridCompress(gridID2); */
vlistChangeGridIndex(vlistID2, index, gridID2);
}
}
......
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