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

Merge declaration and definition.

parent c4e80a9c
...@@ -1003,72 +1003,51 @@ void eca4(const ECA_REQUEST_4 *request) ...@@ -1003,72 +1003,51 @@ void eca4(const ECA_REQUEST_4 *request)
const int operatorID = cdoOperatorID(); const int operatorID = cdoOperatorID();
int nmiss; int nmiss;
int cmplen;
char indate1[DATE_LEN+1], indate2[DATE_LEN+1]; char indate1[DATE_LEN+1], indate2[DATE_LEN+1];
int gridsize, gridtype;
double *yvals;
int ivdate = 0, ivtime = 0; int ivdate = 0, ivtime = 0;
int ovdate = 0, ovtime = 0; int ovdate = 0, ovtime = 0;
int month, yearcnt = 0; int yearcnt = 0;
int nrecs, nrecords; int nrecs;
int gridID, zaxisID, varID, ovarID1, ovarID2, levelID; int varID, levelID;
int itsID;
int otsID;
long nsets;
int i;
int istreamID1, istreamID2, ostreamID;
int ivlistID1, ivlistID2, ovlistID, itaxisID, otaxisID;
int nlevels;
int *recVarID, *recLevelID;
double missval;
field_type *startCount , *endCount;
field_type *startDateWithHist[2], *endDateWithHist[2]; field_type *startDateWithHist[2], *endDateWithHist[2];
field_type *gslDuration, *gslFirstDay;
field_type fieldGt, fieldLt, mask;
int resetAtJan = FALSE, resetAtJul = FALSE; int resetAtJan = FALSE, resetAtJul = FALSE;
int isFirstYear = TRUE; int isFirstYear = TRUE;
cmplen = DATE_LEN - cdoOperatorF2(operatorID); int cmplen = DATE_LEN - cdoOperatorF2(operatorID);
istreamID1 = streamOpenRead(cdoStreamName(0)); int istreamID1 = streamOpenRead(cdoStreamName(0));
istreamID2 = streamOpenRead(cdoStreamName(1)); int istreamID2 = streamOpenRead(cdoStreamName(1));
ivlistID1 = streamInqVlist(istreamID1); int ivlistID1 = streamInqVlist(istreamID1);
ivlistID2 = streamInqVlist(istreamID2); int ivlistID2 = streamInqVlist(istreamID2);
ovlistID = vlistCreate(); int ovlistID = vlistCreate();
gridID = vlistInqVarGrid(ivlistID1, FIRST_VAR_ID); int gridID = vlistInqVarGrid(ivlistID1, FIRST_VAR_ID);
if ( gridID != vlistInqVarGrid(ivlistID2, FIRST_VAR_ID) ) cdoAbort("Grid sizes of the input fields do not match!"); if ( gridID != vlistInqVarGrid(ivlistID2, FIRST_VAR_ID) ) cdoAbort("Grid sizes of the input fields do not match!");
zaxisID = vlistInqVarZaxis(ivlistID1, FIRST_VAR_ID); int zaxisID = vlistInqVarZaxis(ivlistID1, FIRST_VAR_ID);
missval = vlistInqVarMissval(ivlistID1, FIRST_VAR_ID); double missval = vlistInqVarMissval(ivlistID1, FIRST_VAR_ID);
ovarID1 = vlistDefVar(ovlistID, gridID, zaxisID, TSTEP_INSTANT); int ovarID1 = vlistDefVar(ovlistID, gridID, zaxisID, TSTEP_INSTANT);
vlistDefVarMissval(ovlistID, ovarID1, missval); vlistDefVarMissval(ovlistID, ovarID1, missval);
if ( IS_SET(request->name) ) if ( IS_SET(request->name) ) vlistDefVarName(ovlistID, ovarID1, request->name);
vlistDefVarName(ovlistID, ovarID1, request->name); if ( IS_SET(request->longname) ) vlistDefVarLongname(ovlistID, ovarID1, request->longname);
if ( IS_SET(request->longname) ) if ( IS_SET(request->units) ) vlistDefVarUnits(ovlistID, ovarID1, request->units);
vlistDefVarLongname(ovlistID, ovarID1, request->longname);
if ( IS_SET(request->units) )
vlistDefVarUnits(ovlistID, ovarID1, request->units);
ovarID2 = vlistDefVar(ovlistID, gridID, zaxisID, TSTEP_INSTANT); int ovarID2 = vlistDefVar(ovlistID, gridID, zaxisID, TSTEP_INSTANT);
vlistDefVarMissval(ovlistID, ovarID2, missval); vlistDefVarMissval(ovlistID, ovarID2, missval);
if ( IS_SET(request->name2) ) if ( IS_SET(request->name2) ) vlistDefVarName(ovlistID, ovarID2, request->name2);
vlistDefVarName(ovlistID, ovarID2, request->name2); if ( IS_SET(request->longname2) ) vlistDefVarLongname(ovlistID, ovarID2, request->longname2);
if ( IS_SET(request->longname2) ) if ( IS_SET(request->units2) ) vlistDefVarUnits(ovlistID, ovarID2, request->units2);
vlistDefVarLongname(ovlistID, ovarID2, request->longname2);
if ( IS_SET(request->units2) )
vlistDefVarUnits(ovlistID, ovarID2, request->units2);
if ( cdoOperatorF2(operatorID) == 16 ) vlistDefNtsteps(ovlistID, 1); if ( cdoOperatorF2(operatorID) == 16 ) vlistDefNtsteps(ovlistID, 1);
itaxisID = vlistInqTaxis(ivlistID1); int itaxisID = vlistInqTaxis(ivlistID1);
otaxisID = taxisCreate(TAXIS_RELATIVE); int otaxisID = taxisCreate(TAXIS_RELATIVE);
taxisDefTunit(otaxisID, TUNIT_MINUTE); taxisDefTunit(otaxisID, TUNIT_MINUTE);
// taxisDefCalendar(otaxisID, CALENDAR_PROLEPTIC); // taxisDefCalendar(otaxisID, CALENDAR_PROLEPTIC);
taxisDefCalendar(otaxisID, taxisInqCalendar(itaxisID)); taxisDefCalendar(otaxisID, taxisInqCalendar(itaxisID));
...@@ -1076,44 +1055,43 @@ void eca4(const ECA_REQUEST_4 *request) ...@@ -1076,44 +1055,43 @@ void eca4(const ECA_REQUEST_4 *request)
taxisDefRtime(otaxisID, 0); taxisDefRtime(otaxisID, 0);
vlistDefTaxis(ovlistID, otaxisID); vlistDefTaxis(ovlistID, otaxisID);
ostreamID = streamOpenWrite(cdoStreamName(2), cdoFiletype()); int ostreamID = streamOpenWrite(cdoStreamName(2), cdoFiletype());
streamDefVlist(ostreamID, ovlistID); streamDefVlist(ostreamID, ovlistID);
nrecords = vlistNrecs(ivlistID1); int nrecords = vlistNrecs(ivlistID1);
recVarID = (int*) Malloc(nrecords*sizeof(int)); int *recVarID = (int*) Malloc(nrecords*sizeof(int));
recLevelID = (int*) Malloc(nrecords*sizeof(int)); int *recLevelID = (int*) Malloc(nrecords*sizeof(int));
gridtype = gridInqType(gridID); int gridtype = gridInqType(gridID);
if ( gridtype != GRID_UNSTRUCTURED && gridtype != GRID_CURVILINEAR ) if ( gridtype != GRID_UNSTRUCTURED && gridtype != GRID_CURVILINEAR )
{ {
if ( gridtype == GRID_GME ) gridID = (gridtype == GRID_GME) ? gridToUnstructured(gridID, 1) : gridToCurvilinear(gridID, 1);
gridID = gridToUnstructured(gridID, 1);
else
gridID = gridToCurvilinear(gridID, 1);
} }
gridsize = gridInqSize(gridID); int gridsize = gridInqSize(gridID);
/* for later check on northern\southern hemisphere */ /* for later check on northern\southern hemisphere */
yvals = (double*) Malloc(gridsize*sizeof(double)); double *yvals = (double*) Malloc(gridsize*sizeof(double));
gridInqYvals(gridID,yvals); gridInqYvals(gridID,yvals);
/* Two fields are needed because of the definition of gsl for northern and /* Two fields are needed because of the definition of gsl for northern and
* southern hemisphere */ * southern hemisphere */
field_type fieldGt, fieldLt;
field_init(&fieldGt); field_init(&fieldGt);
field_init(&fieldLt); field_init(&fieldLt);
fieldGt.ptr = (double*) Malloc(gridsize*sizeof(double)); fieldGt.ptr = (double*) Malloc(gridsize*sizeof(double));
fieldLt.ptr = (double*) Malloc(gridsize*sizeof(double)); fieldLt.ptr = (double*) Malloc(gridsize*sizeof(double));
/* field for the land-water-distribution */ /* field for the land-water-distribution */
field_type mask;
field_init(&mask); field_init(&mask);
mask.ptr = (double*) Malloc(gridsize*sizeof(double)); mask.ptr = (double*) Malloc(gridsize*sizeof(double));
nlevels = zaxisInqSize(zaxisID); int nlevels = zaxisInqSize(zaxisID);
startCount = (field_type*) Malloc(nlevels*sizeof(field_type)); field_type *startCount = (field_type*) Malloc(nlevels*sizeof(field_type));
endCount = (field_type*) Malloc(nlevels*sizeof(field_type)); field_type *endCount = (field_type*) Malloc(nlevels*sizeof(field_type));
gslDuration = (field_type*) Malloc(nlevels*sizeof(field_type)); field_type *gslDuration = (field_type*) Malloc(nlevels*sizeof(field_type));
gslFirstDay = (field_type*) Malloc(nlevels*sizeof(field_type)); field_type *gslFirstDay = (field_type*) Malloc(nlevels*sizeof(field_type));
/* because of the different definitions for northern and southern hemisphere, /* because of the different definitions for northern and southern hemisphere,
* the values of the last year have to be present * the values of the last year have to be present
...@@ -1174,8 +1152,8 @@ void eca4(const ECA_REQUEST_4 *request) ...@@ -1174,8 +1152,8 @@ void eca4(const ECA_REQUEST_4 *request)
} }
} }
itsID = 0; int itsID = 0;
otsID = 0; int otsID = 0;
if ( streamInqTimestep(istreamID2, itsID) ) if ( streamInqTimestep(istreamID2, itsID) )
{ {
...@@ -1191,13 +1169,13 @@ void eca4(const ECA_REQUEST_4 *request) ...@@ -1191,13 +1169,13 @@ void eca4(const ECA_REQUEST_4 *request)
while ( TRUE ) while ( TRUE )
{ {
nsets = 0; long nsets = 0;
while ( (nrecs = streamInqTimestep(istreamID1, itsID)) > 0 ) while ( (nrecs = streamInqTimestep(istreamID1, itsID)) > 0 )
{ {
ivdate = taxisInqVdate(itaxisID); ivdate = taxisInqVdate(itaxisID);
ivtime = taxisInqVtime(itaxisID); ivtime = taxisInqVtime(itaxisID);
month = (ivdate % 10000) / 100; int month = (ivdate % 10000) / 100;
if ( month < 1 || month > 12 ) cdoAbort("month %d out of range!", month); if ( month < 1 || month > 12 ) cdoAbort("month %d out of range!", month);
if ( nsets == 0 ) SET_DATE(indate2, ivdate, ivtime); if ( nsets == 0 ) SET_DATE(indate2, ivdate, ivtime);
...@@ -1222,7 +1200,7 @@ void eca4(const ECA_REQUEST_4 *request) ...@@ -1222,7 +1200,7 @@ void eca4(const ECA_REQUEST_4 *request)
if ( nsets == 0 ) if ( nsets == 0 )
{ {
for ( i = 0; i < gridsize; i++ ) for ( int i = 0; i < gridsize; i++ )
{ {
gslDuration[levelID].ptr[i] = missval; gslDuration[levelID].ptr[i] = missval;
gslFirstDay[levelID].ptr[i] = missval; gslFirstDay[levelID].ptr[i] = missval;
...@@ -1239,7 +1217,7 @@ void eca4(const ECA_REQUEST_4 *request) ...@@ -1239,7 +1217,7 @@ void eca4(const ECA_REQUEST_4 *request)
/* init the history ONCE */ /* init the history ONCE */
if ( 0 == itsID ) if ( 0 == itsID )
{ {
for ( i = 0; i < gridsize; i++ ) for ( int i = 0; i < gridsize; i++ )
{ {
startDateWithHist[1][levelID].ptr[i] = missval; startDateWithHist[1][levelID].ptr[i] = missval;
endDateWithHist[1][levelID].ptr[i] = missval; endDateWithHist[1][levelID].ptr[i] = missval;
...@@ -1262,7 +1240,7 @@ void eca4(const ECA_REQUEST_4 *request) ...@@ -1262,7 +1240,7 @@ void eca4(const ECA_REQUEST_4 *request)
if ( 1 == month && !resetAtJan ) if ( 1 == month && !resetAtJan )
{ {
/* reset northern startCount */ /* reset northern startCount */
for ( i = 0; i < gridsize; i++ ) for ( int i = 0; i < gridsize; i++ )
{ {
if ( yvals[i] >= 0.0 ) if ( yvals[i] >= 0.0 )
if ( !DBL_IS_EQUAL(startCount[levelID].ptr[i], missval) ) if ( !DBL_IS_EQUAL(startCount[levelID].ptr[i], missval) )
...@@ -1272,7 +1250,7 @@ void eca4(const ECA_REQUEST_4 *request) ...@@ -1272,7 +1250,7 @@ void eca4(const ECA_REQUEST_4 *request)
} }
} }
/* reset southern endCount */ /* reset southern endCount */
for ( i = 0; i < gridsize; i++ ) for ( int i = 0; i < gridsize; i++ )
{ {
if ( yvals[i] < 0.0 ) if ( yvals[i] < 0.0 )
if ( !DBL_IS_EQUAL(endCount[levelID].ptr[i], missval) ) if ( !DBL_IS_EQUAL(endCount[levelID].ptr[i], missval) )
...@@ -1295,7 +1273,7 @@ void eca4(const ECA_REQUEST_4 *request) ...@@ -1295,7 +1273,7 @@ void eca4(const ECA_REQUEST_4 *request)
#endif #endif
{ {
/* reset northern endCount */ /* reset northern endCount */
for ( i = 0; i < gridsize; i++ ) for ( int i = 0; i < gridsize; i++ )
{ {
if ( yvals[i] >= 0.0 ) if ( yvals[i] >= 0.0 )
{ {
...@@ -1312,7 +1290,7 @@ void eca4(const ECA_REQUEST_4 *request) ...@@ -1312,7 +1290,7 @@ void eca4(const ECA_REQUEST_4 *request)
#endif #endif
{ {
/* reset southern startCount */ /* reset southern startCount */
for ( i = 0; i < gridsize; i++ ) for ( int i = 0; i < gridsize; i++ )
{ {
if ( yvals[i] < 0.0 ) if ( yvals[i] < 0.0 )
{ {
...@@ -1353,7 +1331,7 @@ void eca4(const ECA_REQUEST_4 *request) ...@@ -1353,7 +1331,7 @@ void eca4(const ECA_REQUEST_4 *request)
if ( month < 7 ) if ( month < 7 )
{ {
for ( i = 0; i < gridsize; i++ ) for ( int i = 0; i < gridsize; i++ )
/* dictinct between northern and southern sphere */ /* dictinct between northern and southern sphere */
/* start with south */ /* start with south */
if ( yvals[i] < 0 ) if ( yvals[i] < 0 )
...@@ -1386,7 +1364,7 @@ void eca4(const ECA_REQUEST_4 *request) ...@@ -1386,7 +1364,7 @@ void eca4(const ECA_REQUEST_4 *request)
} }
else else
{ {
for ( i = 0; i < gridsize; i++ ) for ( int i = 0; i < gridsize; i++ )
{ {
if ( yvals[i] < 0 ) if ( yvals[i] < 0 )
{ {
......
Markdown is supported
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