Commit 61fd3ec3 authored by Uwe Schulzweida's avatar Uwe Schulzweida
Browse files

yseaspctl: check of verification date failed [Bug #5810]

parent b69669e9
......@@ -3,6 +3,10 @@
* using CDI library version 1.7.0
* Version 1.7.0 released
2015-05-29 Uwe Schulzweida
* yseaspctl: check of verification date failed [Bug #5810]
2015-05-28 Uwe Schulzweida
* Remap: fixed memory leak for r=max_remaps-1
......
......@@ -8,9 +8,8 @@
@Operators = diff diffn
@BeginDescription
Compares the contents of two datasets field by field. The input
datasets need to have the same structure and its fields need to have
the same header information and dimensions.
Compares the contents of two datasets field by field. The input datasets need to have the
same structure and its fields need to have the same header information and dimensions.
@EndDescription
@EndModule
......
......@@ -93,30 +93,11 @@ void *Seascount(void *argument)
vdate = taxisInqVdate(taxisID1);
vtime = taxisInqVtime(taxisID1);
cdiDecodeDate(vdate, &year, &month, &day);
if ( month < 0 || month > 16 )
cdoAbort("Month %d out of range!", month);
newmon = month;
if ( season_start == START_DEC && newmon == 12 ) newmon = 0;
if ( season_start == START_DEC )
{
if ( newmon == 12 ) newmon = 0;
if ( month <= 12 )
seas = (month % 12) / 3;
else
seas = month - 13;
}
else
{
if ( month <= 12 )
seas = (month - 1) / 3;
else
seas = month - 13;
}
if ( seas < 0 || seas > 3 )
cdoAbort("Season %d out of range!", seas+1);
seas = month_to_season(month);
if ( nsets == 0 )
{
......
......@@ -164,30 +164,12 @@ void *Seaspctl(void *argument)
vdate1 = dtlist_get_vdate(dtlist, nsets);
cdiDecodeDate(vdate1, &year, &month, &day);
if ( month < 0 || month > 16 )
cdoAbort("Month %d out of range!", month);
newmon = month;
if ( season_start == START_DEC )
{
if ( newmon == 12 ) newmon = 0;
if ( month <= 12 )
seas = (month % 12) / 3;
else
seas = month - 13;
}
else
{
if ( month <= 12 )
seas = (month - 1) / 3;
else
seas = month - 13;
}
if ( season_start == START_DEC && newmon == 12 ) newmon = 0;
if ( seas < 0 || seas > 3 )
cdoAbort("Season %d out of range!", seas + 1);
seas = month_to_season(month);
if ( nsets == 0 )
{
......
......@@ -126,30 +126,12 @@ void *Seasstat(void *argument)
vtime = dtlist_get_vtime(dtlist, nsets);
cdiDecodeDate(vdate, &year, &month, &day);
if ( month < 1 || month > 12 )
cdoAbort("Month %d out of range!", month);
newmon = month;
if ( season_start == START_DEC )
{
if ( newmon == 12 ) newmon = 0;
if ( month <= 12 )
seas = (month % 12) / 3;
else
seas = month - 13;
}
else
{
if ( month <= 12 )
seas = (month - 1) / 3;
else
seas = month - 13;
}
if ( season_start == START_DEC && newmon == 12 ) newmon = 0;
if ( seas < 0 || seas > 3 )
cdoAbort("Season %d out of range!", seas+1);
seas = month_to_season(month);
if ( nsets == 0 )
{
......
......@@ -97,7 +97,6 @@ void *Splittime(void *argument)
if ( operatorArgc() == 1 ) format = operatorArgv()[0];
}
int season_start = get_season_start();
const char *seas_name[4];
get_season_name(seas_name);
......@@ -167,29 +166,7 @@ void *Splittime(void *argument)
index = (vdate/operintval)%100;
if ( index < 0 ) index = -index;
if ( operatorID == SPLITSEAS )
{
if ( index < 0 || index > 16 )
cdoAbort("Month %d out of range!", index);
if ( season_start == START_DEC )
{
if ( index <= 12 )
index = (index % 12) / 3;
else
index = index - 13;
}
else
{
if ( index <= 12 )
index = (index - 1) / 3;
else
index = index - 13;
}
if ( index < 0 || index > 3 )
cdoAbort("Season %d out of range!", index+1);
}
if ( operatorID == SPLITSEAS ) index = month_to_season(index);
}
else if ( operfunc == func_time )
{
......
......@@ -30,6 +30,7 @@
#define NDAY 373
int getmonthday(int date);
void *Ydaypctl(void *argument)
{
......
......@@ -30,7 +30,6 @@
#define NDAY 373
static
int getmonthday(int date)
{
int year, month, day;
......@@ -294,11 +293,9 @@ void *Ydrunpctl(void *argument)
if ( nsets[dayoy] )
{
if ( getmonthday(vdates1[dayoy]) != getmonthday(vdates2[dayoy]) )
cdoAbort("Verification dates for day %d of %s, %s and %s are different!", dayoy, cdoStreamName(1)->args, cdoStreamName(2)->args, cdoStreamName(3)->args);
/*
if ( vtimes1[dayoy] != vtimes2[dayoy] )
cdoAbort("Verification times for day %d of %s, %s and %s are different!", dayoy, cdoStreamName(1)->args, cdoStreamName(2)->args, cdoStreamName(3)->args);
*/
cdoAbort("Verification dates for day %d of %s, %s and %s are different!",
dayoy, cdoStreamName(1)->args, cdoStreamName(2)->args, cdoStreamName(3)->args);
for ( varID = 0; varID < nvars; varID++ )
{
if ( vlistInqVarTsteptype(vlistID1, varID) == TSTEP_CONSTANT ) continue;
......
......@@ -36,34 +36,6 @@
#define MAX_MON 12
static
int month_to_season(int mon)
{
int seas = -1;
switch ( mon )
{
case 12:
case 1:
case 2:
seas = 0; break;
case 3:
case 4:
case 5:
seas = 1; break;
case 6:
case 7:
case 8:
seas = 2; break;
case 9:
case 10:
case 11:
seas = 3; break;
}
return seas;
}
void *Ymonarith(void *argument)
{
......
......@@ -29,6 +29,14 @@
#define NMONTH 17
static
int getmonth(int date)
{
int year, month, day;
cdiDecodeDate(date, &year, &month, &day);
return month;
}
void *Ymonpctl(void *argument)
{
int gridsize;
......@@ -48,7 +56,7 @@ void *Ymonpctl(void *argument)
int nvars, nlevels;
int *recVarID, *recLevelID;
int vdates1[NMONTH], vtimes1[NMONTH];
int vdates2[NMONTH], vtimes2[NMONTH];
int vdates2[NMONTH];
field_t **vars1[NMONTH];
field_t field;
double pn;
......@@ -124,7 +132,6 @@ void *Ymonpctl(void *argument)
cdoAbort("Month %d out of range!", month);
vdates2[month] = vdate;
vtimes2[month] = vtime;
if ( vars1[month] == NULL )
{
......@@ -202,10 +209,9 @@ void *Ymonpctl(void *argument)
for ( month = 0; month < NMONTH; month++ )
if ( nsets[month] )
{
if ( vdates1[month] != vdates2[month] )
cdoAbort("Verification dates for month %d of %s, %s and %s are different!", month, cdoStreamName(1)->args, cdoStreamName(2)->args, cdoStreamName(3)->args);
if ( vtimes1[month] != vtimes2[month] )
cdoAbort("Verification times for month %d of %s, %s and %s are different!", month, cdoStreamName(1)->args, cdoStreamName(2)->args, cdoStreamName(3)->args);
if ( getmonth(vdates1[month]) != getmonth(vdates2[month]) )
cdoAbort("Verification dates for month %d of %s, %s and %s are different!",
month, cdoStreamName(1)->args, cdoStreamName(2)->args, cdoStreamName(3)->args);
for ( varID = 0; varID < nvars; varID++ )
{
......
......@@ -30,85 +30,90 @@
#define NSEAS 4
typedef struct {
int vdate;
int vtime;
}
date_time_t;
void set_date(int vdate_new, int vtime_new, date_time_t *datetime);
int getmonthday(int date);
void *Yseaspctl(void *argument)
{
int gridsize;
int varID;
int recID;
int gridID;
int vdate, vtime;
int year, month, day, seas;
int nrecs, nrecords;
int nrecs;
int levelID;
int tsID;
int otsID;
long nsets[NSEAS];
int streamID1, streamID2, streamID3, streamID4;
int vlistID1, vlistID2, vlistID3, vlistID4, taxisID1, taxisID2, taxisID3, taxisID4;
int nmiss;
int nvars, nlevels;
int *recVarID, *recLevelID;
int vdates1[NSEAS], vtimes1[NSEAS];
int vdates2[NSEAS], vtimes2[NSEAS];
int nlevels;
date_time_t datetime1[NSEAS], datetime2[NSEAS];
field_t **vars1[NSEAS];
field_t field;
double pn;
HISTOGRAM_SET *hsets[NSEAS];
int season_start;
cdoInitialize(argument);
cdoOperatorAdd("yseaspctl", func_pctl, 0, NULL);
operatorInputArg("percentile number");
pn = parameter2double(operatorArgv()[0]);
double pn = parameter2double(operatorArgv()[0]);
if ( !(pn > 0 && pn < 100) )
cdoAbort("Illegal argument: percentile number %g is not in the range 0..100!", pn);
season_start = get_season_start();
for ( seas = 0; seas < NSEAS; seas++ )
{
vars1[seas] = NULL;
hsets[seas] = NULL;
nsets[seas] = 0;
datetime1[seas].vdate = 0;
datetime1[seas].vtime = 0;
datetime2[seas].vdate = 0;
datetime2[seas].vtime = 0;
}
streamID1 = streamOpenRead(cdoStreamName(0));
streamID2 = streamOpenRead(cdoStreamName(1));
streamID3 = streamOpenRead(cdoStreamName(2));
int streamID1 = streamOpenRead(cdoStreamName(0));
int streamID2 = streamOpenRead(cdoStreamName(1));
int streamID3 = streamOpenRead(cdoStreamName(2));
vlistID1 = streamInqVlist(streamID1);
vlistID2 = streamInqVlist(streamID2);
vlistID3 = streamInqVlist(streamID3);
vlistID4 = vlistDuplicate(vlistID1);
int vlistID1 = streamInqVlist(streamID1);
int vlistID2 = streamInqVlist(streamID2);
int vlistID3 = streamInqVlist(streamID3);
int vlistID4 = vlistDuplicate(vlistID1);
vlistCompare(vlistID1, vlistID2, CMP_ALL);
vlistCompare(vlistID1, vlistID3, CMP_ALL);
taxisID1 = vlistInqTaxis(vlistID1);
taxisID2 = vlistInqTaxis(vlistID2);
taxisID3 = vlistInqTaxis(vlistID3);
int taxisID1 = vlistInqTaxis(vlistID1);
int taxisID2 = vlistInqTaxis(vlistID2);
int taxisID3 = vlistInqTaxis(vlistID3);
/* TODO - check that time axes 2 and 3 are equal */
taxisID4 = taxisDuplicate(taxisID1);
int taxisID4 = taxisDuplicate(taxisID1);
if ( taxisHasBounds(taxisID4) ) taxisDeleteBounds(taxisID4);
vlistDefTaxis(vlistID4, taxisID4);
streamID4 = streamOpenWrite(cdoStreamName(3), cdoFiletype());
int streamID4 = streamOpenWrite(cdoStreamName(3), cdoFiletype());
streamDefVlist(streamID4, vlistID4);
nvars = vlistNvars(vlistID1);
nrecords = vlistNrecs(vlistID1);
int nvars = vlistNvars(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);
field_t field;
field_init(&field);
field.ptr = (double*) malloc(gridsize*sizeof(double));
tsID = 0;
int tsID = 0;
while ( (nrecs = streamInqTimestep(streamID2, tsID)) )
{
if ( nrecs != streamInqTimestep(streamID3, tsID) )
......@@ -123,29 +128,10 @@ void *Yseaspctl(void *argument)
if ( cdoVerbose ) cdoPrint("process timestep: %d %d %d", tsID+1, vdate, vtime);
cdiDecodeDate(vdate, &year, &month, &day);
if ( month < 0 || month > 16 )
cdoAbort("Month %d out of range!", month);
if ( season_start == START_DEC )
{
if ( month <= 12 )
seas = (month % 12) / 3;
else
seas = month - 13;
}
else
{
if ( month <= 12 )
seas = (month - 1) / 3;
else
seas = month - 13;
}
if ( seas < 0 || seas > 3 )
cdoAbort("Season %d out of range!", seas+1);
seas = month_to_season(month);
vdates2[seas] = vdate;
vtimes2[seas] = vtime;
set_date(vdate, vtime, &datetime2[seas]);
if ( vars1[seas] == NULL )
{
......@@ -198,8 +184,7 @@ void *Yseaspctl(void *argument)
if ( seas < 0 || seas > 3 )
cdoAbort("Season %d out of range!", seas+1);
vdates1[seas] = vdate;
vtimes1[seas] = vtime;
set_date(vdate, vtime, &datetime1[seas]);
if ( vars1[seas] == NULL )
cdoAbort("No data for season %d in %s and %s", seas, cdoStreamName(1)->args, cdoStreamName(2)->args);
......@@ -224,14 +209,12 @@ void *Yseaspctl(void *argument)
tsID++;
}
otsID = 0;
int otsID = 0;
for ( seas = 0; seas < NSEAS; seas++ )
if ( nsets[seas] )
{
if ( vdates1[seas] != vdates2[seas] )
if ( getmonthday(datetime1[seas].vdate) != getmonthday(datetime2[seas].vdate) )
cdoAbort("Verification dates for season %d of %s, %s and %s are different!", seas, cdoStreamName(1)->args, cdoStreamName(2)->args, cdoStreamName(3)->args);
if ( vtimes1[seas] != vtimes2[seas] )
cdoAbort("Verification times for season %d of %s, %s and %s are different!", seas, cdoStreamName(1)->args, cdoStreamName(2)->args, cdoStreamName(3)->args);
for ( varID = 0; varID < nvars; varID++ )
{
......@@ -242,8 +225,8 @@ void *Yseaspctl(void *argument)
hsetGetVarLevelPercentiles(&vars1[seas][varID][levelID], hsets[seas], varID, levelID, pn);
}
taxisDefVdate(taxisID4, vdates1[seas]);
taxisDefVtime(taxisID4, vtimes1[seas]);
taxisDefVdate(taxisID4, datetime1[seas].vdate);
taxisDefVtime(taxisID4, datetime1[seas].vtime);
streamDefTimestep(streamID4, otsID);
for ( recID = 0; recID < nrecords; recID++ )
......
......@@ -44,8 +44,6 @@ typedef struct {
}
date_time_t;
static
void set_date(int vdate_new, int vtime_new, date_time_t *datetime)
{
int year, month, day;
......@@ -91,7 +89,6 @@ void *Yseasstat(void *argument)
int operatorID = cdoOperatorID();
int operfunc = cdoOperatorF1(operatorID);
int season_start = get_season_start();
for ( seas = 0; seas < NSEAS; seas++ )
{
vars1[seas] = NULL;
......@@ -140,26 +137,8 @@ void *Yseasstat(void *argument)
vdate = taxisInqVdate(taxisID1);
vtime = taxisInqVtime(taxisID1);
cdiDecodeDate(vdate, &year, &month, &day);
if ( month < 0 || month > 16 )
cdoAbort("Month %d out of range!", month);
if ( season_start == START_DEC )
{
if ( month <= 12 )
seas = (month % 12) / 3;
else
seas = month - 13;
}
else
{
if ( month <= 12 )
seas = (month - 1) / 3;
else
seas = month - 13;
}
if ( seas < 0 || seas > 3 )
cdoAbort("Season %d out of range!", seas+1);
seas = month_to_season(month);
set_date(vdate, vtime, &datetime[seas]);
......
......@@ -406,27 +406,33 @@ int parameter2intlist(const char *string)
const char *seas_name_dec[4] = {"DJF", "MAM", "JJA", "SON"};
const char *seas_name_jan[4] = {"JFM", "AMJ", "JAS", "OND"};
static int season_start = START_DEC;
int get_season_start(void)
{
int season_start = START_DEC;
char *envstr;
static int lgetenv = TRUE;
envstr = getenv("CDO_SEASON_START");
if ( envstr )
if ( lgetenv )
{
if ( strcmp(envstr, "DEC") == 0 ) season_start = START_DEC;
else if ( strcmp(envstr, "JAN") == 0 ) season_start = START_JAN;
if ( cdoVerbose )
lgetenv = FALSE;
char *envstr = getenv("CDO_SEASON_START");
if ( envstr )
{
if ( season_start == START_DEC )
cdoPrint("Set SEASON_START to December");
else if ( season_start == START_JAN )
cdoPrint("Set SEASON_START to January");
if ( strcmp(envstr, "DEC") == 0 ) season_start = START_DEC;
else if ( strcmp(envstr, "JAN") == 0 ) season_start = START_JAN;
if ( cdoVerbose )
{
if ( season_start == START_DEC )
cdoPrint("Set SEASON_START to December");
else if ( season_start == START_JAN )
cdoPrint("Set SEASON_START to January");
}
}
}
return (season_start);
return season_start;
}
......@@ -441,6 +447,33 @@ void get_season_name(const char *seas_name[])
}
int month_to_season(int month)
{
int season_start = get_season_start();
int seas = -1;
if ( month < 0 || month > 16 ) cdoAbort("Month %d out of range!", month);
if ( season_start == START_DEC )
{
if ( month <= 12 )
seas = (month % 12) / 3;
else
seas = month - 13;
}
else
{
if ( month <= 12 )
seas = (month - 1) / 3;
else
seas = month - 13;
}
if ( seas < 0 || seas > 3 ) cdoAbort("Season %d out of range!", seas+1);
return seas;
}
//#include <sys/types.h>
#include <sys/stat.h>
//#include <unistd.h>
......
......@@ -120,6 +120,7 @@ char *getFileArg(char *argument);
enum {START_DEC, START_JAN};
int get_season_start(void);
void get_season_name(const char *seas_name[]);
int month_to_season(int month);
void init_is_tty(void);
......
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