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

Merge declaration and definition.

parent 698b8955
......@@ -31,74 +31,62 @@
void *Seascount(void *argument)
{
int gridsize;
int vdate = 0, vtime = 0;
int vdate0 = 0, vtime0 = 0;
int nrecs, nrecords;
int varID, levelID, recID;
int tsID;
int otsID;
int nrecs;
int varID, levelID;
int nmiss;
long nsets;
int i;
int year, month, day, seas, seas0 = 0;
int streamID1, streamID2;
int vlistID1, vlistID2, taxisID1, taxisID2;
int nwpv; // number of words per value; real:1 complex:2
int *recVarID, *recLevelID;
int newseas, oldmon = 0, newmon;
field_t **vars1 = NULL;
field_t field;
int season_start;
int year, month, day, seas0 = 0;
int oldmon = 0;
cdoInitialize(argument);
cdoOperatorAdd("seascount", 0, 0, NULL);
season_start = get_season_start();
int season_start = get_season_start();
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);
nrecords = vlistNrecs(vlistID1);
int nrecords = vlistNrecs(vlistID1);
recVarID = (int*) Malloc(nrecords*sizeof(int));
recLevelID = (int*) Malloc(nrecords*sizeof(int));
int *recVarID = (int*) Malloc(nrecords*sizeof(int));
int *recLevelID = (int*) Malloc(nrecords*sizeof(int));
gridsize = vlistGridsizeMax(vlistID1);
int gridsize = vlistGridsizeMax(vlistID1);
if ( vlistNumber(vlistID1) != CDI_REAL ) gridsize *= 2;
field_t field;
field_init(&field);
field.ptr = (double*) Malloc(gridsize*sizeof(double));
vars1 = field_malloc(vlistID1, FIELD_PTR);
field_t **vars1 = field_malloc(vlistID1, FIELD_PTR);
tsID = 0;
otsID = 0;
int tsID = 0;
int otsID = 0;
while ( TRUE )
{
nsets = 0;
newseas = FALSE;
int nsets = 0;
bool newseas = false;
while ( (nrecs = streamInqTimestep(streamID1, tsID)) )
{
vdate = taxisInqVdate(taxisID1);
vtime = taxisInqVtime(taxisID1);
int vdate = taxisInqVdate(taxisID1);
int vtime = taxisInqVtime(taxisID1);
cdiDecodeDate(vdate, &year, &month, &day);
newmon = month;
int newmon = month;
if ( season_start == START_DEC && newmon == 12 ) newmon = 0;
seas = month_to_season(month);
int seas = month_to_season(month);
if ( nsets == 0 )
{
......@@ -106,13 +94,13 @@ void *Seascount(void *argument)
oldmon = newmon;
}
if ( newmon < oldmon ) newseas = TRUE;
if ( newmon < oldmon ) newseas = true;
if ( (seas != seas0) || newseas ) break;
oldmon = newmon;
for ( recID = 0; recID < nrecs; recID++ )
for ( int recID = 0; recID < nrecs; recID++ )
{
streamInqRecord(streamID1, &varID, &levelID);
......@@ -121,13 +109,13 @@ void *Seascount(void *argument)
recVarID[recID] = varID;
recLevelID[recID] = levelID;
}
nwpv = vars1[varID][levelID].nwpv;
// number of words per value; real:1 complex:2
int nwpv = vars1[varID][levelID].nwpv;
gridsize = gridInqSize(vlistInqVarGrid(vlistID1, varID));
if ( nsets == 0 )
{
for ( i = 0; i < nwpv*gridsize; i++ )
for ( int i = 0; i < nwpv*gridsize; i++ )
vars1[varID][levelID].ptr[i] = vars1[varID][levelID].missval;
vars1[varID][levelID].nmiss = gridsize;
}
......@@ -152,7 +140,7 @@ void *Seascount(void *argument)
taxisDefVtime(taxisID2, vtime0);
streamDefTimestep(streamID2, otsID);
for ( recID = 0; recID < nrecords; recID++ )
for ( int recID = 0; recID < nrecords; recID++ )
{
varID = recVarID[recID];
levelID = recLevelID[recID];
......
......@@ -33,23 +33,14 @@
void *Seaspctl(void *argument)
{
int timestat_date = TIMESTAT_MEAN;
int vdate1 = 0;
int vdate2 = 0, vtime2 = 0;
int vdate3 = 0, vtime3 = 0;
int nrecs;
int gridID, varID, levelID, recID;
int tsID;
int otsID;
long nsets;
int year, month, day, seas, seas0 = 0;
int gridID, varID, levelID;
int year, month, day, seas0 = 0;
int nmiss;
int nlevels;
int newseas, oldmon = 0, newmon;
double missval;
field_t **vars1 = NULL;
field_t field;
HISTOGRAM_SET *hset = NULL;
int oldmon = 0;
int season_start;
double missval;
cdoInitialize(argument);
......@@ -97,10 +88,12 @@ void *Seaspctl(void *argument)
int gridsize = vlistGridsizeMax(vlistID1);
field_t field;
field_init(&field);
field.ptr = (double*) Malloc(gridsize*sizeof(double));
vars1 = (field_t **) Malloc(nvars * sizeof(field_t *));
hset = hsetCreate(nvars);
field_t **vars1 = (field_t **) Malloc(nvars * sizeof(field_t *));
HISTOGRAM_SET *hset = hsetCreate(nvars);
for ( varID = 0; varID < nvars; varID++ )
{
......@@ -121,29 +114,29 @@ void *Seaspctl(void *argument)
}
}
tsID = 0;
otsID = 0;
int tsID = 0;
int otsID = 0;
while ( TRUE )
{
nrecs = streamInqTimestep(streamID2, otsID);
if ( nrecs != streamInqTimestep(streamID3, otsID) )
cdoAbort("Number of records at time step %d of %s and %s differ!", otsID+1, cdoStreamName(1)->args, cdoStreamName(2)->args);
vdate2 = taxisInqVdate(taxisID2);
vtime2 = taxisInqVtime(taxisID2);
vdate3 = taxisInqVdate(taxisID3);
vtime3 = taxisInqVtime(taxisID3);
int vdate2 = taxisInqVdate(taxisID2);
int vtime2 = taxisInqVtime(taxisID2);
int vdate3 = taxisInqVdate(taxisID3);
int vtime3 = taxisInqVtime(taxisID3);
if ( vdate2 != vdate3 || vtime2 != vtime3 )
cdoAbort("Verification dates at time step %d of %s and %s differ!", otsID+1, cdoStreamName(1)->args, cdoStreamName(2)->args);
for ( recID = 0; recID < nrecs; recID++ )
for ( int recID = 0; recID < nrecs; recID++ )
{
streamInqRecord(streamID2, &varID, &levelID);
streamReadRecord(streamID2, vars1[varID][levelID].ptr, &nmiss);
vars1[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);
......@@ -154,20 +147,20 @@ void *Seaspctl(void *argument)
hsetDefVarLevelBounds(hset, varID, levelID, &vars1[varID][levelID], &field);
}
nsets = 0;
newseas = FALSE;
int nsets = 0;
bool newseas = false;
while ( nrecs && (nrecs = streamInqTimestep(streamID1, tsID)) )
{
dtlist_taxisInqTimestep(dtlist, taxisID1, nsets);
vdate1 = dtlist_get_vdate(dtlist, nsets);
int vdate1 = dtlist_get_vdate(dtlist, nsets);
cdiDecodeDate(vdate1, &year, &month, &day);
newmon = month;
int newmon = month;
if ( season_start == START_DEC && newmon == 12 ) newmon = 0;
seas = month_to_season(month);
int seas = month_to_season(month);
if ( nsets == 0 )
{
......@@ -175,13 +168,13 @@ void *Seaspctl(void *argument)
oldmon = newmon;
}
if ( newmon < oldmon ) newseas = TRUE;
if ( newmon < oldmon ) newseas = true;
if ( (seas != seas0) || newseas ) break;
oldmon = newmon;
for ( recID = 0; recID < nrecs; recID++ )
for ( int recID = 0; recID < nrecs; recID++ )
{
streamInqRecord(streamID1, &varID, &levelID);
if ( tsID == 0 )
......@@ -213,7 +206,7 @@ void *Seaspctl(void *argument)
dtlist_stat_taxisDefTimestep(dtlist, taxisID4, nsets);
streamDefTimestep(streamID4, otsID);
for ( recID = 0; recID < nrecords; recID++ )
for ( int recID = 0; recID < nrecords; recID++ )
{
varID = recVarID[recID];
levelID = recLevelID[recID];
......
......@@ -40,18 +40,14 @@
void *Seasstat(void *argument)
{
int timestat_date = TIMESTAT_MEAN;
int gridsize;
int vdate = 0, vtime = 0;
int vdate0 = 0, vtime0 = 0;
int vdate1 = 0, vtime1 = 0;
int nrecs;
int varID, levelID, recID;
int nsets;
int i;
int year, month, day, seas, seas0 = 0;
int varID, levelID;
int year, month, day, seas0 = 0;
int nmiss;
int nlevel;
int newseas, oldmon = 0, newmon;
int oldmon = 0;
int nseason = 0;
const char *seas_name[4];
......@@ -102,7 +98,7 @@ void *Seasstat(void *argument)
dtlist_set_stat(dtlist, timestat_date);
dtlist_set_calendar(dtlist, taxisInqCalendar(taxisID1));
gridsize = vlistGridsizeMax(vlistID1);
int gridsize = vlistGridsizeMax(vlistID1);
field_t field;
field_init(&field);
......@@ -117,21 +113,21 @@ void *Seasstat(void *argument)
int otsID = 0;
while ( TRUE )
{
nsets = 0;
newseas = FALSE;
long nsets = 0;
bool newseas = false;
while ( (nrecs = streamInqTimestep(streamID1, tsID)) )
{
dtlist_taxisInqTimestep(dtlist, taxisID1, nsets);
vdate = dtlist_get_vdate(dtlist, nsets);
vtime = dtlist_get_vtime(dtlist, nsets);
int vdate = dtlist_get_vdate(dtlist, nsets);
int vtime = dtlist_get_vtime(dtlist, nsets);
cdiDecodeDate(vdate, &year, &month, &day);
newmon = month;
int newmon = month;
if ( season_start == START_DEC && newmon == 12 ) newmon = 0;
seas = month_to_season(month);
int seas = month_to_season(month);
if ( nsets == 0 )
{
......@@ -142,13 +138,13 @@ void *Seasstat(void *argument)
oldmon = newmon;
}
if ( newmon < oldmon ) newseas = TRUE;
if ( newmon < oldmon ) newseas = true;
if ( (seas != seas0) || newseas ) break;
oldmon = newmon;
for ( recID = 0; recID < nrecs; recID++ )
for ( int recID = 0; recID < nrecs; recID++ )
{
streamInqRecord(streamID1, &varID, &levelID);
......@@ -170,7 +166,7 @@ void *Seasstat(void *argument)
if ( samp1[varID][levelID].ptr == NULL )
samp1[varID][levelID].ptr = (double*) Malloc(gridsize*sizeof(double));
for ( i = 0; i < gridsize; i++ )
for ( int i = 0; i < gridsize; i++ )
if ( DBL_IS_EQUAL(vars1[varID][levelID].ptr[i],
vars1[varID][levelID].missval) )
samp1[varID][levelID].ptr[i] = 0;
......@@ -190,11 +186,11 @@ void *Seasstat(void *argument)
if ( samp1[varID][levelID].ptr == NULL )
{
samp1[varID][levelID].ptr = (double*) Malloc(gridsize*sizeof(double));
for ( i = 0; i < gridsize; i++ )
for ( int i = 0; i < gridsize; i++ )
samp1[varID][levelID].ptr[i] = nsets;
}
for ( i = 0; i < gridsize; i++ )
for ( int i = 0; i < gridsize; i++ )
if ( !DBL_IS_EQUAL(field.ptr[i], vars1[varID][levelID].missval) )
samp1[varID][levelID].ptr[i]++;
}
......@@ -288,7 +284,7 @@ void *Seasstat(void *argument)
otsID+1, vdatestr, nsets, nsets == 1 ? "" : "s");
}
for ( recID = 0; recID < nrecords; recID++ )
for ( int recID = 0; recID < nrecords; recID++ )
{
varID = recVarID[recID];
levelID = recLevelID[recID];
......
......@@ -24,13 +24,13 @@
void *Seloperator(void *argument)
{
int nrecs;
int recID, varID, levelID;
double slevel = 0, level;
int varID, levelID;
int nlevs, code, zaxisID, selfound = FALSE;
int levID, ltype = 0;
int varID2, levelID2;
int sellevel, selcode, selltype;
int gridsize, nmiss;
double slevel = 0, level;
double *array = NULL;
cdoInitialize(argument);
......@@ -112,7 +112,7 @@ void *Seloperator(void *argument)
streamDefTimestep(streamID2, tsID);
for ( recID = 0; recID < nrecs; recID++ )
for ( int recID = 0; recID < nrecs; recID++ )
{
streamInqRecord(streamID1, &varID, &levelID);
if ( vlistInqFlag(vlistID1, varID, levelID) == TRUE )
......
......@@ -32,15 +32,8 @@
void *Selrec(void *argument)
{
int streamID1, streamID2;
int tsID, nrecs;
int recID, varID, levelID;
int *intarr, nsel = 0;
int vlistID1 = -1, vlistID2 = -1;
int i;
int recordID;
int filetype;
int taxisID1, taxisID2;
int nrecs;
int varID, levelID;
LIST *ilist = listNew(INT_LIST);
cdoInitialize(argument);
......@@ -49,48 +42,48 @@ void *Selrec(void *argument)
operatorInputArg("records");
nsel = args2intlist(operatorArgc(), operatorArgv(), ilist);
int nsel = args2intlist(operatorArgc(), operatorArgv(), ilist);
intarr = (int *) listArrayPtr(ilist);
int *intarr = (int *) listArrayPtr(ilist);
if ( cdoVerbose )
{
for ( i = 0; i < nsel; i++ )
for ( int i = 0; i < nsel; i++ )
cdoPrint("intarr entry: %d %d", i, intarr[i]);
}
streamID1 = streamOpenRead(cdoStreamName(0));
int streamID1 = streamOpenRead(cdoStreamName(0));
filetype = streamInqFiletype(streamID1);
int filetype = streamInqFiletype(streamID1);
if ( filetype == FILETYPE_NC || filetype == FILETYPE_NC2 || filetype == FILETYPE_NC4 || filetype == FILETYPE_NC4C )
cdoAbort("This operator does not work on NetCDF data!");
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);
recordID = 0;
tsID = 0;
int recordID = 0;
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++ )
{
recordID++;
streamInqRecord(streamID1, &varID, &levelID);
for ( i = 0; i < nsel; i++ )
for ( int i = 0; i < nsel; i++ )
{
if ( recordID == intarr[i] )
{
......
......@@ -127,7 +127,7 @@ double datestr_to_double(const char *datestr, int opt)
static
int datelist(LIST *flist)
{
int set2 = TRUE;
bool set2 = true;
double fval = 0;
int nsel = operatorArgc();
......@@ -149,7 +149,7 @@ int datelist(LIST *flist)
{
fval = datestr_to_double(operatorArgv()[i], 0);
if ( strchr(operatorArgv()[i], 'T') )
set2 = FALSE;
set2 = false;
else if ( nsel > 1 && i > 0 )
fval += 0.999;
}
......@@ -157,7 +157,7 @@ int datelist(LIST *flist)
listSetFlt(flist, i, fval);
}
if ( nsel == 1 && set2 == TRUE )
if ( nsel == 1 && set2 )
{
fval += 0.999;
listSetFlt(flist, nsel, fval);
......
......@@ -55,7 +55,6 @@ void *Template1(void *argument)
while ( (nrecs = streamInqTimestep(streamID1, tsID)) )
{
taxisCopyTimestep(taxisID2, taxisID1);
streamDefTimestep(streamID2, tsID);
for ( int recID = 0; recID < nrecs; recID++ )
......@@ -118,7 +117,6 @@ void *Template2(void *argument)
while ( (nrecs = streamInqTimestep(streamID1, tsID)) )
{
taxisCopyTimestep(taxisID2, taxisID1);
streamDefTimestep(streamID2, tsID);
for ( int recID = 0; recID < nrecs; recID++ )
......
......@@ -67,54 +67,44 @@ void *Test2(void *argument)
void *Testdata(void *argument)
{
int streamID1, streamID2 = CDI_UNDEFID;
int nrecs;
int tsID1, tsID2, recID, varID, levelID;
int gridsize, i;
int vlistID1, vlistID2 = -1;
int varID, levelID;
int nmiss;
int taxisID1, taxisID2 = CDI_UNDEFID;
double *array = NULL;
float *fval;
int *ival;
unsigned char *cval;
unsigned char *cval2;
FILE *fp;
cdoInitialize(argument);
tsID2 = 0;
int tsID2 = 0;
streamID1 = streamOpenRead(cdoStreamName(0));
int streamID1 = streamOpenRead(cdoStreamName(0));
vlistID1 = streamInqVlist(streamID1);
taxisID1 = vlistInqTaxis(vlistID1);
int vlistID1 = streamInqVlist(streamID1);
int taxisID1 = vlistInqTaxis(vlistID1);
streamID2 = streamOpenWrite(cdoStreamName(1), cdoFiletype());
int streamID2 = streamOpenWrite(cdoStreamName(1), cdoFiletype());
vlistID2 = vlistDuplicate(vlistID1);
taxisID2 = taxisDuplicate(taxisID1);
int vlistID2 = vlistDuplicate(vlistID1);
int taxisID2 = taxisDuplicate(taxisID1);
vlistDefTaxis(vlistID2, taxisID2);
streamDefVlist(streamID2, vlistID2);
gridsize = vlistGridsizeMax(vlistID1);
array = (double*) Malloc(gridsize*sizeof(double));
fval = (float*) Malloc(gridsize*sizeof(float));
ival = (int*) Malloc(gridsize*sizeof(int));
cval = (unsigned char*) Malloc(gridsize*sizeof(unsigned char)*4);
cval2 = (unsigned char*) Malloc(gridsize*sizeof(unsigned char)*4);
int gridsize = vlistGridsizeMax(vlistID1);
double *array = (double*) Malloc(gridsize*sizeof(double));
float *fval = (float*) Malloc(gridsize*sizeof(float));
int *ival = (int*) Malloc(gridsize*sizeof(int));
unsigned char *cval = (unsigned char*) Malloc(gridsize*sizeof(unsigned char)*4);
unsigned char *cval2 = (unsigned char*) Malloc(gridsize*sizeof(unsigned char)*4);
fp = fopen("testdata", "w");
FILE *fp = fopen("testdata", "w");
tsID1 = 0;
int tsID1 = 0;
while ( (nrecs = streamInqTimestep(streamID1, tsID1)) )
{
taxisCopyTimestep(taxisID2, taxisID1);
streamDefTimestep(streamID2, tsID2);
for ( recID = 0; recID < nrecs; recID++ )
for ( int recID = 0; recID < nrecs; recID++ )
{
streamInqRecord(streamID1, &varID, &levelID);
streamDefRecord(streamID2, varID, levelID);
......@@ -122,7 +112,7 @@ void *Testdata(void *argument)
streamReadRecord(streamID1, array, &nmiss);
gridsize = gridInqSize(vlistInqVarGrid(vlistID1, varID));
for ( i = 0; i < gridsize; ++i )
for ( int i = 0; i < gridsize; ++i )
{
fval[i] = (float) array[i];
......
......@@ -24,29 +24,21 @@
void *Tests(void *argument)
{
int NORMAL, STUDENTT, CHISQUARE, BETA, FISHER;
int operatorID;
int streamID1, streamID2 = CDI_UNDEFID;
int nrecs;
int i;
int tsID, recID, varID, levelID;
int vlistID1, vlistID2;