Commit 3387a633 authored by Uwe Schulzweida's avatar Uwe Schulzweida
Browse files

detrend: cleanup memory allocation and use field_malloc()

parent c8819ebb
......@@ -206,6 +206,9 @@ void *Adisit(void *argument)
cdoPrint("%5d %g", i+1, pressure[i]);
}
field_init(&tho);
field_init(&sao);
field_init(&tis);
tho.ptr = (double *) malloc(gridsize*nlevel*sizeof(double));
sao.ptr = (double *) malloc(gridsize*nlevel*sizeof(double));
tis.ptr = (double *) malloc(gridsize*nlevel*sizeof(double));
......
......@@ -148,6 +148,8 @@ void *Arith(void *argument)
gridsize = vlistGridsizeMax(vlistIDx1);
field_init(&field1);
field_init(&field2);
field1.ptr = (double *) malloc(gridsize*sizeof(double));
field2.ptr = (double *) malloc(gridsize*sizeof(double));
if ( filltype == FILL_VAR || filltype == FILL_VARTS )
......
......@@ -116,6 +116,7 @@ void *Arithc(void *argument)
gridsize = vlistGridsizeMax(vlistID1);
field_init(&field);
field.ptr = (double *) malloc(gridsize*sizeof(double));
field.weight = NULL;
......
......@@ -115,6 +115,7 @@ void *Arithdays(void *argument)
gridsize = vlistGridsizeMax(vlistID1);
field_init(&field);
field.ptr = (double *) malloc(gridsize*sizeof(double));
field.weight = NULL;
......
......@@ -145,23 +145,7 @@ void *Detrend(void *argument)
taxisInqDTinfo(taxisID1, &dtinfo[tsID]);
vars[tsID] = (field_t **) malloc(nvars*sizeof(field_t *));
for ( varID = 0; varID < nvars; varID++ )
{
gridID = vlistInqVarGrid(vlistID1, varID);
missval = vlistInqVarMissval(vlistID1, varID);
nlevel = zaxisInqSize(vlistInqVarZaxis(vlistID1, varID));
vars[tsID][varID] = (field_t *) malloc(nlevel*sizeof(field_t));
for ( levelID = 0; levelID < nlevel; levelID++ )
{
vars[tsID][varID][levelID].grid = gridID;
vars[tsID][varID][levelID].missval = missval;
vars[tsID][varID][levelID].ptr = NULL;
}
}
vars[tsID] = field_malloc(vlistID1, FIELD_NONE);
for ( recID = 0; recID < nrecs; recID++ )
{
......@@ -237,11 +221,12 @@ void *Detrend(void *argument)
streamDefRecord(streamID2, varID, levelID);
streamWriteRecord(streamID2, vars[tsID][varID][levelID].ptr, nmiss);
free(vars[tsID][varID][levelID].ptr);
vars[tsID][varID][levelID].ptr = NULL;
}
}
free(vars[tsID][varID]);
}
free(vars[tsID]);
field_free(vars[tsID], vlistID1);
}
if ( vars ) free(vars);
......
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