Commit 27b1363f authored by Uwe Schulzweida's avatar Uwe Schulzweida
Browse files

replaced calloc/malloc/realloc/free by Calloc/Malloc/Realloc/Free from dmemory.h

parent 7628316b
......@@ -247,7 +247,7 @@ void *Adisit(void *argument)
if ( nlevel1 != nlevel2 ) cdoAbort("temperature and salinity have different number of levels!");
nlevel = nlevel1;
pressure = (double*) malloc(nlevel*sizeof(double));
pressure = (double*) Malloc(nlevel*sizeof(double));
zaxisInqLevels(zaxisID, pressure);
if ( pin >= 0 )
......@@ -265,9 +265,9 @@ void *Adisit(void *argument)
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));
tho.ptr = (double*) Malloc(gridsize*nlevel*sizeof(double));
sao.ptr = (double*) Malloc(gridsize*nlevel*sizeof(double));
tis.ptr = (double*) Malloc(gridsize*nlevel*sizeof(double));
tho.nmiss = 0;
sao.nmiss = 0;
......@@ -373,10 +373,10 @@ void *Adisit(void *argument)
vlistDestroy(vlistID2);
free(pressure);
free(tis.ptr);
free(tho.ptr);
free(sao.ptr);
Free(pressure);
Free(tis.ptr);
Free(tho.ptr);
Free(sao.ptr);
cdoFinish();
......
......@@ -1486,7 +1486,7 @@ void after_precntl(struct Control *globs, struct Variable *vars)
iVertID = zaxisID;
globs->NumLevelFound = numlevel;
LevelFound = (double *) malloc(globs->NumLevelFound*sizeof(double));
LevelFound = (double *) Malloc(globs->NumLevelFound*sizeof(double));
for ( l = 0; l < globs->NumLevelFound; l++ )
LevelFound[l] = (int) zaxisInqLevel(zaxisID, l);
......@@ -1500,7 +1500,7 @@ void after_precntl(struct Control *globs, struct Variable *vars)
if ( globs->vct == NULL )
{
globs->vct = (double *) malloc(globs->nvct*sizeof(double));
globs->vct = (double *) Malloc(globs->nvct*sizeof(double));
memcpy(globs->vct, zaxisInqVctPtr(zaxisID), globs->nvct*sizeof(double));
}
}
......@@ -1510,7 +1510,7 @@ void after_precntl(struct Control *globs, struct Variable *vars)
{
fprintf(stderr," Using internal VCT for L191\n");
globs->nvct = (191+1)*2;
globs->vct = (double *) malloc(globs->nvct*sizeof(double));
globs->vct = (double *) Malloc(globs->nvct*sizeof(double));
memcpy(globs->vct, VCT_L191, globs->nvct*sizeof(double));
zaxisDefVct(zaxisID, globs->nvct, globs->vct);
}
......@@ -1609,7 +1609,7 @@ void after_precntl(struct Control *globs, struct Variable *vars)
if ( globs->Debug )
Message( "FieldDim = %d", FieldDim);
globs->Field = (double *) malloc(FieldDim*sizeof(double));
globs->Field = (double *) Malloc(FieldDim*sizeof(double));
if ( globs->Debug )
for ( code = 0; code < MaxCodes; code++ )
......@@ -1776,7 +1776,7 @@ void after_readVct(struct Control *globs, const char *vctfile)
while ( fgets(line, 1023, fp) ) globs->nvct++;
globs->nvct *= 2;
globs->vct = (double *) malloc(globs->nvct*sizeof(double));
globs->vct = (double *) Malloc(globs->nvct*sizeof(double));
rewind(fp);
for ( i = 0; i < globs->nvct/2; i++ )
......@@ -2057,9 +2057,9 @@ void after_processing(struct Control *globs, struct Variable *vars)
after_dimcalc(globs);
globs->rcoslat = (double *) malloc(globs->Latitudes*sizeof(double));
globs->coslat = (double *) malloc(globs->Latitudes*sizeof(double));
globs->DerivationFactor = (double *) malloc(globs->Latitudes*sizeof(double));
globs->rcoslat = (double *) Malloc(globs->Latitudes*sizeof(double));
globs->coslat = (double *) Malloc(globs->Latitudes*sizeof(double));
globs->DerivationFactor = (double *) Malloc(globs->Latitudes*sizeof(double));
if ( globs->Type < 50 && globs->AnalysisData )
{
......@@ -2123,8 +2123,8 @@ void after_processing(struct Control *globs, struct Variable *vars)
/* if ( vars[U_WIND].needed || vars[V_WIND].needed ) */
if ( vars[U_WIND].comp || vars[V_WIND].comp )
{
globs->dv2uv_f1 = (double *) malloc(globs->DimSP_half*sizeof(double));
globs->dv2uv_f2 = (double *) malloc(globs->DimSP_half*sizeof(double));
globs->dv2uv_f1 = (double *) Malloc(globs->DimSP_half*sizeof(double));
globs->dv2uv_f2 = (double *) Malloc(globs->DimSP_half*sizeof(double));
geninx(globs->Truncation, globs->dv2uv_f1, globs->dv2uv_f2);
}
......@@ -2152,16 +2152,16 @@ void after_processing(struct Control *globs, struct Variable *vars)
#endif
streamClose(globs->istreamID);
if ( globs->rcoslat ) free(globs->rcoslat);
if ( globs->coslat ) free(globs->coslat);
if ( globs->DerivationFactor ) free(globs->DerivationFactor);
if ( globs->rcoslat ) Free(globs->rcoslat);
if ( globs->coslat ) Free(globs->coslat);
if ( globs->DerivationFactor ) Free(globs->DerivationFactor);
if ( globs->Field ) free(globs->Field);
if ( globs->Field ) Free(globs->Field);
if ( globs->poli ) free(globs->poli);
if ( globs->pold ) free(globs->pold);
if ( globs->pdev ) free(globs->pdev);
if ( globs->pol2 ) free(globs->pol2); if ( globs->pol3 ) free(globs->pol3);
if ( globs->poli ) Free(globs->poli);
if ( globs->pold ) Free(globs->pold);
if ( globs->pdev ) Free(globs->pdev);
if ( globs->pol2 ) Free(globs->pol2); if ( globs->pol3 ) Free(globs->pol3);
}
extern char *optarg;
......@@ -2223,7 +2223,7 @@ int afterburner(int argc, char *argv[])
fclose(fp);
}
struct Control *globs = (struct Control *) malloc(sizeof(struct Control));
struct Control *globs = (struct Control *) Malloc(sizeof(struct Control));
after_control_init(globs);
globs->Verbose = 1;
......@@ -2319,7 +2319,7 @@ int afterburner(int argc, char *argv[])
if ( globs->Multi > 0 )
Error( "Namelist parameter MULTI works only with one inputfile");
ifiles = (char **) malloc(globs->Nfiles*sizeof(char*));
ifiles = (char **) Malloc(globs->Nfiles*sizeof(char*));
for ( i = 0; i < globs->Nfiles; i++ )
ifiles[i] = argv[--fargcn];
}
......@@ -2350,7 +2350,7 @@ int afterburner(int argc, char *argv[])
FreeMean(vars);
free(globs);
Free(globs);
return(0);
}
......@@ -2363,7 +2363,7 @@ void *Afterburner(void *argument)
lstdout = !cdoSilentMode;
struct Control *globs = (struct Control *) malloc(sizeof(struct Control));
struct Control *globs = (struct Control *) Malloc(sizeof(struct Control));
after_control_init(globs);
globs->Verbose = cdoVerbose;
......@@ -2389,7 +2389,7 @@ void *Afterburner(void *argument)
if ( globs->Multi > 0 )
Error( "Namelist parameter MULTI works only with one inputfile");
ifiles = (char **) malloc(globs->Nfiles*sizeof(char*));
ifiles = (char **) Malloc(globs->Nfiles*sizeof(char*));
for ( int i = 0; i < globs->Nfiles; ++i )
ifiles[i] = cdoStreamName(--nfiles)->args;
for ( int i = 0; i < globs->Nfiles; ++i ) printf("files %d %s\n", i+1, ifiles[i]);
......@@ -2399,7 +2399,7 @@ void *Afterburner(void *argument)
FreeMean(vars);
free(globs);
Free(globs);
cdoFinish();
......
......@@ -147,12 +147,12 @@ void *Arith(void *argument)
field_init(&field1);
field_init(&field2);
field1.ptr = (double*) malloc(gridsize*sizeof(double));
field2.ptr = (double*) malloc(gridsize*sizeof(double));
field1.ptr = (double*) Malloc(gridsize*sizeof(double));
field2.ptr = (double*) Malloc(gridsize*sizeof(double));
if ( filltype == FILL_VAR || filltype == FILL_VARTS )
{
vardata2 = (double*) malloc(gridsize*nlevels2*sizeof(double));
varnmiss2 = (int*) malloc(nlevels2*sizeof(int));
vardata2 = (double*) Malloc(gridsize*nlevels2*sizeof(double));
varnmiss2 = (int*) Malloc(nlevels2*sizeof(int));
}
if ( cdoVerbose ) cdoPrint("Number of timesteps: file1 %d, file2 %d", ntsteps1, ntsteps2);
......@@ -180,14 +180,14 @@ void *Arith(void *argument)
if ( filltype == FILL_TS )
{
nvars = vlistNvars(vlistIDx2);
vardata = (double **) malloc(nvars*sizeof(double *));
varnmiss = (int **) malloc(nvars*sizeof(int *));
vardata = (double **) Malloc(nvars*sizeof(double *));
varnmiss = (int **) Malloc(nvars*sizeof(int *));
for ( varID = 0; varID < nvars; varID++ )
{
gridsize = gridInqSize(vlistInqVarGrid(vlistIDx2, varID));
nlev = zaxisInqSize(vlistInqVarZaxis(vlistIDx2, varID));
vardata[varID] = (double*) malloc(nlev*gridsize*sizeof(double));
varnmiss[varID] = (int*) malloc(nlev*sizeof(int));
vardata[varID] = (double*) Malloc(nlev*gridsize*sizeof(double));
varnmiss[varID] = (int*) Malloc(nlev*sizeof(int));
}
}
}
......@@ -325,18 +325,18 @@ void *Arith(void *argument)
{
for ( varID = 0; varID < nvars; varID++ )
{
free(vardata[varID]);
free(varnmiss[varID]);
Free(vardata[varID]);
Free(varnmiss[varID]);
}
free(vardata);
free(varnmiss);
Free(vardata);
Free(varnmiss);
}
if ( field1.ptr ) free(field1.ptr);
if ( field2.ptr ) free(field2.ptr);
if ( vardata2 ) free(vardata2);
if ( varnmiss2 ) free(varnmiss2);
if ( field1.ptr ) Free(field1.ptr);
if ( field2.ptr ) Free(field2.ptr);
if ( vardata2 ) Free(vardata2);
if ( varnmiss2 ) Free(varnmiss2);
cdoFinish();
......
......@@ -36,7 +36,7 @@ int *fill_vars(int vlistID)
{
int varID;
int nvars = vlistNvars(vlistID);
int *vars = (int*) malloc(nvars*sizeof(int));
int *vars = (int*) Malloc(nvars*sizeof(int));
if ( cdoNumVarnames )
{
......@@ -109,7 +109,7 @@ void *Arithc(void *argument)
field_t field;
field_init(&field);
field.ptr = (double*) malloc(gridsize*sizeof(double));
field.ptr = (double*) Malloc(gridsize*sizeof(double));
field.weight = NULL;
int tsID = 0;
......@@ -147,8 +147,8 @@ void *Arithc(void *argument)
streamClose(streamID2);
streamClose(streamID1);
if ( field.ptr ) free(field.ptr);
if ( vars ) free(vars);
if ( field.ptr ) Free(field.ptr);
if ( vars ) Free(vars);
vlistDestroy(vlistID2);
......
......@@ -116,7 +116,7 @@ void *Arithdays(void *argument)
gridsize = vlistGridsizeMax(vlistID1);
field_init(&field);
field.ptr = (double*) malloc(gridsize*sizeof(double));
field.ptr = (double*) Malloc(gridsize*sizeof(double));
field.weight = NULL;
tsID = 0;
......@@ -165,7 +165,7 @@ void *Arithdays(void *argument)
streamClose(streamID2);
streamClose(streamID1);
if ( field.ptr ) free(field.ptr);
if ( field.ptr ) Free(field.ptr);
cdoFinish();
......
......@@ -71,7 +71,7 @@ void *Arithlat(void *argument)
gridsize = vlistGridsizeMax(vlistID1);
array = (double*) malloc(gridsize*sizeof(double));
array = (double*) Malloc(gridsize*sizeof(double));
tsID = 0;
while ( (nrecs = streamInqTimestep(streamID1, tsID)) )
......@@ -118,7 +118,7 @@ void *Arithlat(void *argument)
gridsize = gridInqSize(gridID);
scale = (double*) realloc(scale, gridsize*sizeof(double));
scale = (double*) Realloc(scale, gridsize*sizeof(double));
gridInqYvals(gridID, scale);
/* Convert lat/lon units if required */
......@@ -147,8 +147,8 @@ void *Arithlat(void *argument)
streamClose(streamID2);
streamClose(streamID1);
if ( array ) free(array);
if ( scale ) free(scale);
if ( array ) Free(array);
if ( scale ) Free(scale);
cdoFinish();
......
......@@ -134,8 +134,8 @@ void *CDIread(void *argument)
gridsize = vlistGridsizeMax(vlistID);
if ( darray == NULL ) darray = (double*) malloc(gridsize*sizeof(double));
if ( farray == NULL && memtype == MEMTYPE_FLOAT ) farray = (float*) malloc(gridsize*sizeof(float));
if ( darray == NULL ) darray = (double*) Malloc(gridsize*sizeof(double));
if ( farray == NULL && memtype == MEMTYPE_FLOAT ) farray = (float*) Malloc(gridsize*sizeof(float));
t0 = timer_val(timer_read);
......@@ -189,8 +189,8 @@ void *CDIread(void *argument)
if ( nruns > 1 )
print_stat("(mean)", memtype, datatype, filetype, nvalues, data_size, file_size, twsum/nruns);
if ( darray ) free(darray);
if ( farray ) free(farray);
if ( darray ) Free(darray);
if ( farray ) Free(farray);
cdoFinish();
......
......@@ -79,7 +79,7 @@ void *CDItest(void *argument)
streamDefVlist(streamID2, vlistID2);
gridsize = vlistGridsizeMax(vlistID1);
array = (double*) malloc(gridsize*sizeof(double));
array = (double*) Malloc(gridsize*sizeof(double));
tsID1 = 0;
tsID2 = 0;
......@@ -114,7 +114,7 @@ void *CDItest(void *argument)
vlistDestroy(vlistID2);
taxisDestroy(taxisID2);
if ( array ) free(array);
if ( array ) Free(array);
n++;
......
......@@ -165,9 +165,9 @@ void *CDIwrite(void *argument)
cdoPrint("nvars : %d", nvars);
}
double *array = (double*) malloc(gridsize*sizeof(double));
double *xvals = (double*) malloc(gridsize*sizeof(double));
double *yvals = (double*) malloc(gridsize*sizeof(double));
double *array = (double*) Malloc(gridsize*sizeof(double));
double *xvals = (double*) Malloc(gridsize*sizeof(double));
double *yvals = (double*) Malloc(gridsize*sizeof(double));
int gridID2 = gridID;
if ( gridInqType(gridID) == GRID_GME ) gridID2 = gridToUnstructured(gridID, 0);
......@@ -188,23 +188,23 @@ void *CDIwrite(void *argument)
for ( i = 0; i < gridsize; i++ )
array[i] = 2 - cos(acos(cos(xvals[i]) * cos(yvals[i]))/1.2);
free(xvals);
free(yvals);
Free(xvals);
Free(yvals);
vars = (double ***) malloc(nvars*sizeof(double **));
vars = (double ***) Malloc(nvars*sizeof(double **));
for ( varID = 0; varID < nvars; varID++ )
{
vars[varID] = (double **) malloc(nlevs*sizeof(double *));
vars[varID] = (double **) Malloc(nlevs*sizeof(double *));
for ( levelID = 0; levelID < nlevs; levelID++ )
{
vars[varID][levelID] = (double*) malloc(gridsize*sizeof(double));
vars[varID][levelID] = (double*) Malloc(gridsize*sizeof(double));
for ( i = 0; i < gridsize; ++i )
vars[varID][levelID][i] = varID + array[i]*(levelID+1);
// vars[varID][levelID][i] = varID + rand()/(RAND_MAX+1.0);
}
}
if ( memtype == MEMTYPE_FLOAT ) farray = (float*) malloc(gridsize*sizeof(float));
if ( memtype == MEMTYPE_FLOAT ) farray = (float*) Malloc(gridsize*sizeof(float));
vlistID = vlistCreate();
......@@ -293,14 +293,14 @@ void *CDIwrite(void *argument)
for ( varID = 0; varID < nvars; varID++ )
{
for ( levelID = 0; levelID < nlevs; levelID++ ) free(vars[varID][levelID]);
free(vars[varID]);
for ( levelID = 0; levelID < nlevs; levelID++ ) Free(vars[varID][levelID]);
Free(vars[varID]);
}
free(vars);
Free(vars);
free(array);
Free(array);
if ( farray ) free(farray);
if ( farray ) Free(farray);
cdoFinish();
......
......@@ -114,7 +114,7 @@ void *Cat(void *argument)
if ( ! lcopy )
{
gridsize = vlistGridsizeMax(vlistID1);
array = (double*) malloc(gridsize*sizeof(double));
array = (double*) Malloc(gridsize*sizeof(double));
}
}
else
......@@ -166,7 +166,7 @@ void *Cat(void *argument)
if ( cdoTimer ) timer_stop(timer_cat);
if ( array ) free(array);
if ( array ) Free(array);
cdoFinish();
......
......@@ -204,8 +204,8 @@ void *Change(void *argument)
{
zaxisID1 = vlistZaxis(vlistID2, index);
nlevs = zaxisInqSize(zaxisID1);
levels = (double*) malloc(nlevs*sizeof(double));
newlevels = (double*) malloc(nlevs*sizeof(double));
levels = (double*) Malloc(nlevs*sizeof(double));
newlevels = (double*) Malloc(nlevs*sizeof(double));
zaxisInqLevels(zaxisID1, levels);
for ( k = 0; k < nlevs; k++ ) newlevels[k] = levels[k];
......@@ -227,8 +227,8 @@ void *Change(void *argument)
vlistChangeZaxis(vlistID2, zaxisID1, zaxisID2);
}
free(levels);
free(newlevels);
Free(levels);
Free(newlevels);
}
}
else if ( operatorID == CHLEVELC || operatorID == CHLEVELV )
......@@ -255,7 +255,7 @@ void *Change(void *argument)
zaxisID1 = vlistInqVarZaxis(vlistID2, varID);
nlevs = zaxisInqSize(zaxisID1);
levels = (double*) malloc(nlevs*sizeof(double));
levels = (double*) Malloc(nlevs*sizeof(double));
zaxisInqLevels(zaxisID1, levels);
nfound = 0;
for ( k = 0; k < nlevs; k++ )
......@@ -274,7 +274,7 @@ void *Change(void *argument)
else
cdoAbort("Level %g not found!", chlevels[0]);
free(levels);
Free(levels);
}
else if ( operatorID == CHLTYPE )
{
......@@ -308,7 +308,7 @@ void *Change(void *argument)
streamDefVlist(streamID2, vlistID2);
gridsize = vlistGridsizeMax(vlistID2);
array = (double*) malloc(gridsize*sizeof(double));
array = (double*) Malloc(gridsize*sizeof(double));
tsID1 = 0;
while ( (nrecs = streamInqTimestep(streamID1, tsID1)) )
......@@ -331,7 +331,7 @@ void *Change(void *argument)
streamClose(streamID1);
streamClose(streamID2);
if ( array ) free(array);
if ( array ) Free(array);
cdoFinish();
......
......@@ -75,9 +75,9 @@ void *Change_e5slm(void *argument)
gridsize = gridInqSize(vlistInqVarGrid(vlistIDslm, 0));
array = (double*) malloc(gridsize*sizeof(double));
cland = (double*) malloc(gridsize*sizeof(double));
lsea = (short*) malloc(gridsize*sizeof(short));
array = (double*) Malloc(gridsize*sizeof(double));
cland = (double*) Malloc(gridsize*sizeof(double));
lsea = (short*) Malloc(gridsize*sizeof(short));
streamInqTimestep(streamIDslm, 0);
......@@ -102,7 +102,7 @@ void *Change_e5slm(void *argument)
nvars = vlistNvars(vlistID1);
codes = (short*) malloc(nvars*sizeof(short));
codes = (short*) Malloc(nvars*sizeof(short));
for ( varID = 0; varID < nvars; ++varID )
{
......@@ -183,10 +183,10 @@ void *Change_e5slm(void *argument)
streamClose(streamID1);
streamClose(streamID2);
free(array);
free(cland);
free(lsea);
free(codes);
Free(array);
Free(cland);
Free(lsea);
Free(codes);
cdoFinish();
......
......@@ -200,13 +200,13 @@ void *Cloudlayer(void *argument)
nlevel = zaxisInqSize(zaxisID);
int nhlev = nlevel+1;
double *aclcac = (double*) malloc(gridsize*nlevel*sizeof(double));
double *aclcac = (double*) Malloc(gridsize*nlevel*sizeof(double));
for ( varID = 0; varID < nvars2; ++varID )
cloud[varID] = (double*) malloc(gridsize*sizeof(double));
cloud[varID] = (double*) Malloc(gridsize*sizeof(double));
if ( zaxisInqType(zaxisID) == ZAXIS_PRESSURE )
{
plevs = (double*) malloc(nlevel*sizeof(double));
plevs = (double*) Malloc(nlevel*sizeof(double));
zaxisInqLevels(zaxisID, plevs);
if ( plevs[0] > plevs[nlevel-1] )
{
......@@ -236,7 +236,7 @@ void *Cloudlayer(void *argument)
pl_index(&kmax[0], &kmin[0], 75000.,101300., nlevel, plevs);
}
free(plevs);
Free(plevs);
}
else if ( zaxisInqType(zaxisID) == ZAXIS_HYBRID )
{
......@@ -247,13 +247,13 @@ void *Cloudlayer(void *argument)
{
double *vct;
vct = (double*) malloc(nvct*sizeof(double));
vct = (double*) Malloc(nvct*sizeof(double));
zaxisInqVct(zaxisID, vct);
nlevs = nlevel + 1;
plevs = (double*) malloc(nlevs*sizeof(double));
plevs = (double*) Malloc(nlevs*sizeof(double));
vct2plev(vct, plevs, nlevs);
free(vct);
Free(vct);
if ( nvars2 == 1 )
{
......@@ -266,7 +266,7 @@ void *Cloudlayer(void *argument)
hl_index(&kmax[0], &kmin[0], 75000.,101300., nhlev, plevs);
}
free(plevs);
Free(plevs);
}
else
cdoAbort("Unsupported vertical coordinate table format!");
......@@ -369,9 +369,9 @@ void *Cloudlayer(void *argument)
vlistDestroy(vlistID2);
free(aclcac);
Free(aclcac);
for ( varID = 0; varID < nvars2; ++varID )
free(cloud[varID]);
Free(cloud[varID]);
cdoFinish();
......
......@@ -96,11 +96,11 @@ int genGrid(int nfiles, ens_file_t *ef, int **gridindex, int igrid, int nxblocks
if ( gridtype == GRID_GENERIC && gridInqXsize(gridID) == 0 && gridInqYsize(gridID) == 0 )
return gridID2;
int *xsize = (int*) malloc(nfiles*sizeof(int));
int *ysize = (int*) malloc(nfiles*sizeof(int));
xyinfo_t *xyinfo = (xyinfo_t*) malloc(nfiles*sizeof(xyinfo_t));
double **xvals = (double**) malloc(nfiles*sizeof(double*));
double **yvals = (double**) malloc(nfiles*sizeof(double*));