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

Merge declaration and definition.

parent ea0d6452
......@@ -82,49 +82,41 @@ static void farexpr(field_t *field1, field_t field2, double (*expression)(double
void *Wct(void *argument)
{
int streamID1, streamID2, streamID3;
int gridsize;
int nrecs, nrecs2, recID;
int tsID;
int nrecs, nrecs2;
int nmiss;
int gridID, zaxisID;
int varID1, varID2, varID3;
int varID1, varID2;
int levelID1, levelID2;
int vlistID1, vlistID2, vlistID3;
int taxisID1, taxisID2, taxisID3;
field_t field1, field2;
cdoInitialize(argument);
cdoOperatorAdd("wct", 0, 0, NULL);
streamID1 = streamOpenRead(cdoStreamName(0));
streamID2 = streamOpenRead(cdoStreamName(1));
int streamID1 = streamOpenRead(cdoStreamName(0));
int streamID2 = streamOpenRead(cdoStreamName(1));
vlistID1 = streamInqVlist(streamID1);
vlistID2 = streamInqVlist(streamID2);
int vlistID1 = streamInqVlist(streamID1);
int vlistID2 = streamInqVlist(streamID2);
taxisID1 = vlistInqTaxis(vlistID1);
taxisID2 = vlistInqTaxis(vlistID2);
int taxisID1 = vlistInqTaxis(vlistID1);
vlistCompare(vlistID1, vlistID2, CMP_DIM);
gridsize = vlistGridsizeMax(vlistID1);
int gridsize = vlistGridsizeMax(vlistID1);
field_t field1, field2;
field_init(&field1);
field_init(&field2);
field1.ptr = (double*) Malloc(gridsize*sizeof(double));
field2.ptr = (double*) Malloc(gridsize*sizeof(double));
if ( cdoVerbose )
cdoPrint("Number of timesteps: file1 %d, file2 %d", vlistNtsteps(vlistID1), vlistNtsteps(vlistID2));
vlistID3 = vlistCreate();
gridID = vlistInqVarGrid(vlistID1, FIRST_VAR);
zaxisID = vlistInqVarZaxis(vlistID1, FIRST_VAR);
varID3 = vlistDefVar(vlistID3, gridID, zaxisID, TSTEP_INSTANT);
int vlistID3 = vlistCreate();
int gridID = vlistInqVarGrid(vlistID1, FIRST_VAR);
int zaxisID = vlistInqVarZaxis(vlistID1, FIRST_VAR);
int varID3 = vlistDefVar(vlistID3, gridID, zaxisID, TSTEP_INSTANT);
taxisID3 = taxisCreate(TAXIS_RELATIVE);
int taxisID3 = taxisCreate(TAXIS_RELATIVE);
taxisDefTunit(taxisID3, TUNIT_MINUTE);
taxisDefCalendar(taxisID3, CALENDAR_STANDARD);
taxisDefRdate(taxisID3, 19550101);
......@@ -135,11 +127,11 @@ void *Wct(void *argument)
vlistDefVarLongname(vlistID3, varID3, WCT_LONGNAME);
vlistDefVarUnits(vlistID3, varID3, WCT_UNITS);
streamID3 = streamOpenWrite(cdoStreamName(2), cdoFiletype());
int streamID3 = streamOpenWrite(cdoStreamName(2), cdoFiletype());
streamDefVlist(streamID3, vlistID3);
tsID = 0;
int tsID = 0;
while ( (nrecs = streamInqTimestep(streamID1, tsID)) )
{
nrecs2 = streamInqTimestep(streamID2, tsID);
......@@ -149,7 +141,7 @@ void *Wct(void *argument)
taxisCopyTimestep(taxisID3, taxisID1);
streamDefTimestep(streamID3, tsID);
for ( recID = 0; recID < nrecs; recID++ )
for ( int recID = 0; recID < nrecs; recID++ )
{
streamInqRecord(streamID1, &varID1, &levelID1);
streamReadRecord(streamID1, field1.ptr, &nmiss);
......
......@@ -35,7 +35,7 @@
void *Wind(void *argument)
{
int nrecs;
int recID, varID, levelID;
int varID, levelID;
int nlev = 0;
int index, ngrids;
int gridIDsp = -1, gridIDgp = -1;
......@@ -319,7 +319,7 @@ void *Wind(void *argument)
streamDefTimestep(streamID2, tsID);
for ( recID = 0; recID < nrecs; recID++ )
for ( int recID = 0; recID < nrecs; recID++ )
{
streamInqRecord(streamID1, &varID, &levelID);
......
......@@ -30,22 +30,15 @@
void *Writegrid(void *argument)
{
int streamID;
int vlistID;
int gridID;
long gridsize, i;
int gridtype;
int *mask = NULL;
cdoInitialize(argument);
streamID = streamOpenRead(cdoStreamName(0));
int streamID = streamOpenRead(cdoStreamName(0));
vlistID = streamInqVlist(streamID);
gridID = vlistGrid(vlistID, 0);
int vlistID = streamInqVlist(streamID);
int gridID = vlistGrid(vlistID, 0);
gridtype = gridInqType(gridID);
gridsize = gridInqSize(gridID);
int gridtype = gridInqType(gridID);
int gridsize = gridInqSize(gridID);
if ( gridtype == GRID_GME ) gridID = gridToUnstructured(gridID, 1);
......@@ -55,7 +48,7 @@ void *Writegrid(void *argument)
if ( gridInqXbounds(gridID, NULL) == 0 || gridInqYbounds(gridID, NULL) == 0 )
cdoAbort("Grid corner missing!");
mask = (int*) Malloc(gridsize*sizeof(int));
int *mask = (int*) Malloc(gridsize*sizeof(int));
if ( gridInqMask(gridID, NULL) )
{
......@@ -63,7 +56,7 @@ void *Writegrid(void *argument)
}
else
{
for ( i = 0; i < gridsize; i++ ) mask[i] = 1;
for ( int i = 0; i < gridsize; i++ ) mask[i] = 1;
}
writeNCgrid(cdoStreamName(1)->args, gridID, mask);
......
......@@ -29,46 +29,40 @@
void *Writerandom(void *argument)
{
int streamID1, streamID2;
int vlistID1, vlistID2;
int gridsize;
int recID, nrecs;
int tsID, varID, levelID;
int index, rindex, ipos;
double **recdata = NULL;
int *recvarID, *reclevelID, *recnmiss, *recindex;
int taxisID1, taxisID2;
int nrecs;
int varID, levelID;
int rindex;
cdoInitialize(argument);
streamID1 = streamOpenRead(cdoStreamName(0));
int streamID1 = streamOpenRead(cdoStreamName(0));
vlistID1 = streamInqVlist(streamID1);
vlistID2 = vlistDuplicate(vlistID1);
int vlistID1 = streamInqVlist(streamID1);
int vlistID2 = vlistDuplicate(vlistID1);
taxisID1 = vlistInqTaxis(vlistID1);
taxisID2 = taxisDuplicate(taxisID1);
int taxisID1 = vlistInqTaxis(vlistID1);
int taxisID2 = taxisDuplicate(taxisID1);
vlistDefTaxis(vlistID2, taxisID2);
streamID2 = streamOpenWrite(cdoStreamName(1), cdoFiletype());
int streamID2 = streamOpenWrite(cdoStreamName(1), cdoFiletype());
streamDefVlist(streamID2, vlistID2);
tsID = 0;
int tsID = 0;
while ( (nrecs = streamInqTimestep(streamID1, tsID)) )
{
taxisCopyTimestep(taxisID2, taxisID1);
streamDefTimestep(streamID2, tsID);
recdata = (double**) Malloc(nrecs*sizeof(double*));
recvarID = (int*) Malloc(nrecs*sizeof(int));
reclevelID = (int*) Malloc(nrecs*sizeof(int));
recnmiss = (int*) Malloc(nrecs*sizeof(int));
recindex = (int*) Malloc(nrecs*sizeof(int));
double **recdata = (double**) Malloc(nrecs*sizeof(double*));
int *recvarID = (int*) Malloc(nrecs*sizeof(int));
int *reclevelID = (int*) Malloc(nrecs*sizeof(int));
int *recnmiss = (int*) Malloc(nrecs*sizeof(int));
int *recindex = (int*) Malloc(nrecs*sizeof(int));
for ( recID = 0; recID < nrecs; recID++ )
for ( int recID = 0; recID < nrecs; recID++ )
{
streamInqRecord(streamID1, &varID, &levelID);
gridsize = gridInqSize(vlistInqVarGrid(vlistID1, varID));
......@@ -78,14 +72,14 @@ void *Writerandom(void *argument)
streamReadRecord(streamID1, recdata[recID], &recnmiss[recID]);
}
for ( recID = 0; recID < nrecs; recID++ ) recindex[recID] = -1;
for ( int recID = 0; recID < nrecs; recID++ ) recindex[recID] = -1;
for ( rindex = nrecs-1; rindex >= 0; rindex-- )
{
index = (int) (rindex*((double)rand())/((double)RAND_MAX));
int index = (int) (rindex*((double)rand())/((double)RAND_MAX));
/* printf("rindex %d %d\n", rindex, index); */
ipos = -1;
for ( recID = 0; recID < nrecs; recID++ )
int ipos = -1;
for ( int recID = 0; recID < nrecs; recID++ )
{
if ( recindex[recID] == -1 ) ipos++;
if ( recindex[recID] == -1 && ipos == index )
......@@ -100,11 +94,11 @@ void *Writerandom(void *argument)
for ( recID = 0; recID < nrecs; recID++ )
printf("recID %d %d\n", recID, recindex[recID]);
*/
for ( recID = 0; recID < nrecs; recID++ )
for ( int recID = 0; recID < nrecs; recID++ )
if ( recindex[recID] == -1 )
cdoAbort("Internal problem! Random initialize.");
for ( recID = 0; recID < nrecs; recID++ )
for ( int recID = 0; recID < nrecs; recID++ )
{
rindex = recindex[recID];
varID = recvarID[rindex];
......@@ -114,7 +108,7 @@ void *Writerandom(void *argument)
streamWriteRecord(streamID2, recdata[rindex], recnmiss[rindex]);
}
for ( recID = 0; recID < nrecs; recID++ ) Free(recdata[recID]);
for ( int recID = 0; recID < nrecs; recID++ ) Free(recdata[recID]);
Free(recdata);
Free(recvarID);
......
......@@ -162,11 +162,10 @@ void *XTimstat(void *argument)
int vdate = 0, vtime = 0;
int vdate0 = 0, vtime0 = 0;
int varID;
int nsets;
int streamID3 = -1;
int vlistID3, taxisID3 = -1;
int nmiss;
int lvfrac = FALSE;
bool lvfrac = false;
int nwpv; // number of words per value; real:1 complex:2
char indate1[DATE_LEN+1], indate2[DATE_LEN+1];
double vfrac = 1;
......@@ -206,10 +205,10 @@ void *XTimstat(void *argument)
int operfunc = cdoOperatorF1(operatorID);
int comparelen = cdoOperatorF2(operatorID);
int lmean = operfunc == func_mean || operfunc == func_avg;
int lstd = operfunc == func_std || operfunc == func_std1;
int lvarstd = operfunc == func_std || operfunc == func_var || operfunc == func_std1 || operfunc == func_var1;
int divisor = operfunc == func_std1 || operfunc == func_var1;
bool lmean = operfunc == func_mean || operfunc == func_avg;
bool lstd = operfunc == func_std || operfunc == func_std1;
bool lvarstd = operfunc == func_std || operfunc == func_var || operfunc == func_std1 || operfunc == func_var1;
int divisor = operfunc == func_std1 || operfunc == func_var1;
if ( operfunc == func_mean )
{
......@@ -218,7 +217,7 @@ void *XTimstat(void *argument)
if ( oargc == 1 )
{
lvfrac = TRUE;
lvfrac = true;
vfrac = atof(oargv[0]);
if ( cdoVerbose ) cdoPrint("Set vfrac to %g", vfrac);
if ( vfrac < 0 || vfrac > 1 ) cdoAbort("vfrac out of range!");
......@@ -305,7 +304,7 @@ void *XTimstat(void *argument)
readarg.vars = input_vars;
int lparallelread = CDO_Parallel_Read;
int ltsfirst = TRUE;
bool ltsfirst = true;
void *read_task = NULL;
void *readresult = NULL;
......@@ -328,7 +327,7 @@ void *XTimstat(void *argument)
tsID++;
while ( TRUE )
{
nsets = 0;
int nsets = 0;
while ( nrecs > 0 )
{
dtlist_taxisInqTimestep(dtlist, taxisID1, nsets);
......@@ -346,7 +345,7 @@ void *XTimstat(void *argument)
if ( ltsfirst || lparallelread == FALSE )
{
ltsfirst = FALSE;
ltsfirst = false;
readresult = cdoReadTimestep(&readarg);
}
else
......
......@@ -741,7 +741,7 @@ void *YAR(void *argument)
{
int nrecs;
int index;
int recID, varID, levelID;
int varID, levelID;
int gridID1 = -1;
int nmiss;
int xinc = 0, yinc = 0;
......@@ -797,19 +797,18 @@ void *YAR(void *argument)
streamDefVlist(streamID2, vlistID2);
int gridsize = vlistGridsizeMax(vlistID1);
double *array1 = (double*) Malloc(gridsize*sizeof(double));
double *array1 = (double*) Malloc(gridsize*sizeof(double));
gridsize = gridInqSize(gridID2);
double *array2 = (double*) Malloc(gridsize*sizeof(double));
double *array2 = (double*) Malloc(gridsize*sizeof(double));
int tsID = 0;
while ( (nrecs = streamInqTimestep(streamID1, tsID)) )
{
taxisCopyTimestep(taxisID2, taxisID1);
streamDefTimestep(streamID2, tsID);
for ( recID = 0; recID < nrecs; recID++ )
for ( int recID = 0; recID < nrecs; recID++ )
{
streamInqRecord(streamID1, &varID, &levelID);
streamReadRecord(streamID1, array1, &nmiss);
......
......@@ -35,7 +35,6 @@ int getmonthday(int date);
void *Ydaypctl(void *argument)
{
int varID;
int recID;
int gridID;
int vdate, vtime;
int year, month, day, dayoy;
......@@ -140,13 +139,13 @@ void *Ydaypctl(void *argument)
}
}
for ( recID = 0; recID < nrecs; recID++ )
for ( int recID = 0; recID < nrecs; recID++ )
{
streamInqRecord(streamID2, &varID, &levelID);
streamReadRecord(streamID2, vars1[dayoy][varID][levelID].ptr, &nmiss);
vars1[dayoy][varID][levelID].nmiss = nmiss;
}
for ( recID = 0; recID < nrecs; recID++ )
for ( int recID = 0; recID < nrecs; recID++ )
{
streamInqRecord(streamID3, &varID, &levelID);
streamReadRecord(streamID3, field.ptr, &nmiss);
......@@ -184,7 +183,7 @@ void *Ydaypctl(void *argument)
if ( vars1[dayoy] == NULL )
cdoAbort("No data for day %d in %s and %s", dayoy, cdoStreamName(1)->args, cdoStreamName(2)->args);
for ( recID = 0; recID < nrecs; recID++ )
for ( int recID = 0; recID < nrecs; recID++ )
{
streamInqRecord(streamID1, &varID, &levelID);
......@@ -225,7 +224,7 @@ void *Ydaypctl(void *argument)
taxisDefVtime(taxisID4, vtimes1[dayoy]);
streamDefTimestep(streamID4, otsID);
for ( recID = 0; recID < nrecords; recID++ )
for ( int recID = 0; recID < nrecords; recID++ )
{
varID = recVarID[recID];
levelID = recLevelID[recID];
......
......@@ -64,10 +64,10 @@ void *Ydaystat(void *argument)
int operatorID = cdoOperatorID();
int operfunc = cdoOperatorF1(operatorID);
int lmean = operfunc == func_mean || operfunc == func_avg;
int lstd = operfunc == func_std || operfunc == func_std1;
int lvarstd = operfunc == func_std || operfunc == func_var || operfunc == func_std1 || operfunc == func_var1;
int divisor = operfunc == func_std1 || operfunc == func_var1;
bool lmean = operfunc == func_mean || operfunc == func_avg;
bool lstd = operfunc == func_std || operfunc == func_std1;
bool lvarstd = operfunc == func_std || operfunc == func_var || operfunc == func_std1 || operfunc == func_var1;
int divisor = operfunc == func_std1 || operfunc == func_var1;
for ( int dayoy = 0; dayoy < MAX_DOY; dayoy++ )
{
......
......@@ -42,20 +42,18 @@ int getmonthday(int date)
void *Ydrunpctl(void *argument)
{
int varID;
int recID;
int gridID;
int nrecs;
int levelID;
int inp, its;
int nmiss;
int nlevels;
field_t ***vars1 = NULL, **vars2[NDAY];
cdo_datetime_t *datetime;
int year, month, day, dayoy;
int vdate, vtime;
int vdates1[NDAY], vtimes1[NDAY];
int vdates2[NDAY] /*, vtimes2[NDAY]*/;
int nsets[NDAY];
int year, month, day, dayoy;
field_t **vars2[NDAY];
HISTOGRAM_SET *hsets[NDAY];
cdoInitialize(argument);
......@@ -114,9 +112,9 @@ void *Ydrunpctl(void *argument)
field_init(&field);
field.ptr = (double*) Malloc(gridsize*sizeof(double));
datetime = (cdo_datetime_t*) Malloc((ndates+1)*sizeof(cdo_datetime_t));
cdo_datetime_t *datetime = (cdo_datetime_t*) Malloc((ndates+1)*sizeof(cdo_datetime_t));
vars1 = (field_t ***) Malloc((ndates+1)*sizeof(field_t **));
field_t ***vars1 = (field_t ***) Malloc((ndates+1)*sizeof(field_t **));
for ( its = 0; its < ndates; its++ )
{
......@@ -164,13 +162,13 @@ void *Ydrunpctl(void *argument)
}
}
for ( recID = 0; recID < nrecs; recID++ )
for ( int recID = 0; recID < nrecs; recID++ )
{
streamInqRecord(streamID2, &varID, &levelID);
streamReadRecord(streamID2, vars2[dayoy][varID][levelID].ptr, &nmiss);
vars2[dayoy][varID][levelID].nmiss = nmiss;
}
for ( recID = 0; recID < nrecs; recID++ )
for ( int recID = 0; recID < nrecs; recID++ )
{
streamInqRecord(streamID3, &varID, &levelID);
streamReadRecord(streamID3, field.ptr, &nmiss);
......@@ -193,7 +191,7 @@ void *Ydrunpctl(void *argument)
datetime[tsID].date = taxisInqVdate(taxisID1);
datetime[tsID].time = taxisInqVtime(taxisID1);
for ( recID = 0; recID < nrecs; recID++ )
for ( int recID = 0; recID < nrecs; recID++ )
{
streamInqRecord(streamID1, &varID, &levelID);
......@@ -256,7 +254,7 @@ void *Ydrunpctl(void *argument)
datetime[ndates-1].date = taxisInqVdate(taxisID1);
datetime[ndates-1].time = taxisInqVtime(taxisID1);
for ( recID = 0; recID < nrecs; recID++ )
for ( int recID = 0; recID < nrecs; recID++ )
{
streamInqRecord(streamID1, &varID, &levelID);
......@@ -306,7 +304,7 @@ void *Ydrunpctl(void *argument)
taxisDefVtime(taxisID4, vtimes1[dayoy]);
streamDefTimestep(streamID4, otsID);
for ( recID = 0; recID < nrecords; recID++ )
for ( int recID = 0; recID < nrecords; recID++ )
{
varID = recVarID[recID];
levelID = recLevelID[recID];
......
......@@ -60,11 +60,9 @@ static void ydstatFinalize(YDAY_STATS *stats, int operfunc);
void *Ydrunstat(void *argument)
{
int varID;
int recID;
int nrecs;
int levelID;
int tsID;
int otsID;
int inp, its;
int nmiss;
int vdate, vtime;
......@@ -88,7 +86,7 @@ void *Ydrunstat(void *argument)
operatorInputArg("number of timesteps");
int ndates = parameter2int(operatorArgv()[0]);
int lvarstd = operfunc == func_std || operfunc == func_var || operfunc == func_std1 || operfunc == func_var1;
bool lvarstd = operfunc == func_std || operfunc == func_var || operfunc == func_std1 || operfunc == func_var1;
int streamID1 = streamOpenRead(cdoStreamName(0));
......@@ -136,7 +134,7 @@ void *Ydrunstat(void *argument)
datetime[tsID].date = taxisInqVdate(taxisID1);
datetime[tsID].time = taxisInqVtime(taxisID1);
for ( recID = 0; recID < nrecs; recID++ )
for ( int recID = 0; recID < nrecs; recID++ )
{
streamInqRecord(streamID1, &varID, &levelID);
......@@ -199,7 +197,7 @@ void *Ydrunstat(void *argument)
datetime[ndates-1].date = taxisInqVdate(taxisID1);
datetime[ndates-1].time = taxisInqVtime(taxisID1);
for ( recID = 0; recID < nrecs; recID++ )
for ( int recID = 0; recID < nrecs; recID++ )
{
streamInqRecord(streamID1, &varID, &levelID);
......@@ -247,7 +245,7 @@ void *Ydrunstat(void *argument)
*/
ydstatFinalize(stats, operfunc);
otsID = 0;
int otsID = 0;
for ( dayoy = 0; dayoy < NDAY; dayoy++ )
if ( stats->nsets[dayoy] )
......@@ -256,7 +254,7 @@ void *Ydrunstat(void *argument)
taxisDefVtime(taxisID2, stats->vtime[dayoy]);
streamDefTimestep(streamID2, otsID);
for ( recID = 0; recID < nrecords; recID++ )
for ( int recID = 0; recID < nrecords; recID++ )
{
varID = recVarID[recID];
levelID = recLevelID[recID];
......
......@@ -33,13 +33,10 @@
void *Yearmonstat(void *argument)
{
int timestat_date = TIMESTAT_MEAN;
int gridsize;
int vdate = 0, vtime = 0;
int vdate0 = 0, vtime0 = 0;
int nrecs;
int varID, levelID, recID;
int tsID;
int otsID;
int varID, levelID;
int i;
int dpm;
int year0 = 0, month0 = 0;
......@@ -49,8 +46,6 @@ void *Yearmonstat(void *argument)
long nsets;
double dsets;
char vdatestr[32], vtimestr[32];
field_t **vars1 = NULL, **samp1 = NULL;
field_t field;
cdoInitialize(argument);
......@@ -84,16 +79,17 @@ void *Yearmonstat(void *argument)
dtlist_set_stat(dtlist, timestat_date);
dtlist_set_calendar(dtlist, calendar);
gridsize = vlistGridsizeMax(vlistID1);
int gridsize = vlistGridsizeMax(vlistID1);
field_t field;
field_init(&field);
field.ptr = (double*) Malloc(gridsize*sizeof(double));
vars1 = field_malloc(vlistID1, FIELD_PTR);
samp1 = field_malloc(vlistID1, FIELD_NONE);
field_t **vars1 = field_malloc(vlistID1, FIELD_PTR);
field_t **samp1 = field_malloc(vlistID1, FIELD_NONE);
tsID = 0;
otsID = 0;
int tsID = 0;
int otsID = 0;
while ( TRUE )
{
nsets = 0;
......@@ -122,7 +118,7 @@ void *Yearmonstat(void *argument)
dpm = days_per_month(calendar, year, month);
for ( recID = 0; recID < nrecs; recID++ )
for ( int recID = 0; recID < nrecs; recID++ )
{
streamInqRecord(streamID1, &varID, &levelID);
......@@ -213,7 +209,7 @@ void *Yearmonstat(void *argument)
dtlist_stat_taxisDefTimestep(dtlist, taxisID2, nsets);
streamDefTimestep(streamID2, otsID);
for ( recID = 0; recID < nrecords; recID++ )
for ( int recID = 0; recID < nrecords; recID++ )
{
varID = recVarID[recID];
levelID = recLevelID[recID];
......
......@@ -60,20 +60,12 @@ int hour_of_year(int vdate, int vtime)
void *Yhourarith(void *argument)
{
int operatorID;
int operfunc;
int streamID1, streamID2, streamID3;
int gridsize;
int nrecs, nvars, nlev, recID;
int tsID;
int nrecs, nlev;
int varID, levelID;
int offset;
int vlistID1, vlistID2, vlistID3;
int taxisID1, taxisID2, taxisID3;