Commit 637c1198 authored by Uwe Schulzweida's avatar Uwe Schulzweida
Browse files

selseas: added support for season ANN

parent e286c2a4
......@@ -3,6 +3,10 @@
* using CDI library version 1.7.1
* Version 1.7.1 released
2016-02-03 Uwe Schulzweida
* selseas: added support for season ANN
2016-01-13 Uwe Schulzweida
* Expr: added support for temporary variables (starting with underscore)
......
......@@ -530,6 +530,7 @@ void *Select(void *argument)
PML_DEF_WORD(steptype, 32, "Time step type");
PML_DEF_WORD(startdate, 1, "Start date");
PML_DEF_WORD(enddate, 1, "End date");
PML_DEF_WORD(seas, 12, "Season");
PML_DEF_WORD(date, 1024, "Date");
PML_INIT_INT(timestep_of_year);
......@@ -552,6 +553,7 @@ void *Select(void *argument)
PML_INIT_WORD(steptype);
PML_INIT_WORD(startdate);
PML_INIT_WORD(enddate);
PML_INIT_WORD(seas);
PML_INIT_WORD(date);
cdoInitialize(argument);
......@@ -595,6 +597,7 @@ void *Select(void *argument)
PML_ADD_WORD(pml, steptype);
PML_ADD_WORD(pml, startdate);
PML_ADD_WORD(pml, enddate);
PML_ADD_WORD(pml, seas);
PML_ADD_WORD(pml, date);
pmlRead(pml, nsel, argnames);
......@@ -621,6 +624,7 @@ void *Select(void *argument)
PML_NUM(pml, steptype);
PML_NUM(pml, startdate);
PML_NUM(pml, enddate);
PML_NUM(pml, seas);
PML_NUM(pml, date);
int streamCnt = cdoStreamCnt();
......@@ -803,7 +807,7 @@ void *Select(void *argument)
PAR_CHECK_WORD_FLAG(gridname);
PAR_CHECK_WORD_FLAG(steptype);
if ( npar_date || npar_startdate || npar_enddate ) ltimsel = true;
if ( npar_date || npar_startdate || npar_enddate || npar_seas ) ltimsel = true;
if ( npar_timestep_of_year || npar_timestep || npar_year || npar_month || npar_day || npar_hour || npar_minute ) ltimsel = true;
int npar = 0;
......@@ -1126,6 +1130,7 @@ void *Select(void *argument)
PAR_CHECK_WORD_FLAG(startdate);
UNUSED(str_enddate);
// PAR_CHECK_WORD_FLAG(enddate);
PAR_CHECK_WORD_FLAG(seas);
PAR_CHECK_WORD_FLAG(date);
if ( streamID2 != CDI_UNDEFID ) streamClose(streamID2);
......
......@@ -43,74 +43,55 @@
static
int seaslist(LIST *ilist)
{
int i;
char Seas[3];
int seas[4] = {FALSE, FALSE, FALSE, FALSE};
const char *smons = "JFMAMJJASONDJFMAMJJASOND";
int imons[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12};
assert(strlen(smons)==(sizeof(imons)/sizeof(int)));
int imon[17]; /* 1-16 ! */
int ival;
size_t len;
for ( int i = 0; i < 17; ++i ) imon[i] = 0;
int season_start = get_season_start();
int nsel = operatorArgc();
if ( isdigit(*operatorArgv()[0]))
for ( i = 0; i < nsel; i++ )
{
ival = parameter2int(operatorArgv()[i]);
if ( ival == 1 || ival == 13 ) seas[0] = TRUE;
else if ( ival == 2 || ival == 14 ) seas[1] = TRUE;
else if ( ival == 3 || ival == 15 ) seas[2] = TRUE;
else if ( ival == 4 || ival == 16 ) seas[3] = TRUE;
else cdoAbort("Season %d not available!", ival);
}
else
for ( i = 0; i < nsel; i++ )
{
len = strlen(operatorArgv()[i]);
if ( len > 3 ) len = 3;
while ( len-- > 0 ) Seas[len] = toupper(operatorArgv()[i][len]);
if ( season_start == START_DEC )
{
if ( memcmp(Seas, "DJF", 3) == 0 ) seas[0] = TRUE;
else if ( memcmp(Seas, "MAM", 3) == 0 ) seas[1] = TRUE;
else if ( memcmp(Seas, "JJA", 3) == 0 ) seas[2] = TRUE;
else if ( memcmp(Seas, "SON", 3) == 0 ) seas[3] = TRUE;
else cdoAbort("Season %s not available!", operatorArgv()[i]);
}
else
{
if ( memcmp(Seas, "JFM", 3) == 0 ) seas[0] = TRUE;
else if ( memcmp(Seas, "AMJ", 3) == 0 ) seas[1] = TRUE;
else if ( memcmp(Seas, "JAS", 3) == 0 ) seas[2] = TRUE;
else if ( memcmp(Seas, "OND", 3) == 0 ) seas[3] = TRUE;
else cdoAbort("Season %s not available!", operatorArgv()[i]);
}
}
for ( i = 0; i < 17; ++i ) imon[i] = 0;
if ( season_start == START_DEC )
{
if ( seas[0] ) { imon[12]++; imon[ 1]++; imon[ 2]++; imon[13]++; }
if ( seas[1] ) { imon[ 3]++; imon[ 4]++; imon[ 5]++; imon[14]++; }
if ( seas[2] ) { imon[ 6]++; imon[ 7]++; imon[ 8]++; imon[15]++; }
if ( seas[3] ) { imon[ 9]++; imon[10]++; imon[11]++; imon[16]++; }
for ( int i = 0; i < nsel; i++ )
{
int ival = parameter2int(operatorArgv()[i]);
if ( ival == 1 ) { imon[12]++; imon[ 1]++; imon[ 2]++; }
else if ( ival == 2 ) { imon[ 3]++; imon[ 4]++; imon[ 5]++; }
else if ( ival == 3 ) { imon[ 6]++; imon[ 7]++; imon[ 8]++; }
else if ( ival == 4 ) { imon[ 9]++; imon[10]++; imon[11]++; }
else cdoAbort("Season %d not available!", ival);
}
}
else
{
if ( seas[0] ) { imon[ 1]++; imon[ 2]++; imon[ 3]++; imon[13]++; }
if ( seas[1] ) { imon[ 4]++; imon[ 5]++; imon[ 6]++; imon[14]++; }
if ( seas[2] ) { imon[ 7]++; imon[ 8]++; imon[ 9]++; imon[15]++; }
if ( seas[3] ) { imon[10]++; imon[11]++; imon[12]++; imon[16]++; }
for ( int i = 0; i < nsel; i++ )
{
const char *sname = operatorArgv()[i];
size_t len = strlen(sname);
if ( len == 3 && strcmp(sname, "ANN") == 0 )
{
for ( size_t k = 0; k < 12; ++k ) imon[k+1] = 1;
}
else
{
if ( len > 12 ) cdoAbort("Too many months %d (limit=12)!", (int)len);
char *sstr = strcasestr(smons, sname);
if ( sstr == NULL ) cdoAbort("Season %s not available!", sname);
size_t ks = (size_t)(sstr-smons);
size_t ke = ks + len;
for ( size_t k = ks; k < ke; ++k ) imon[imons[k]]++;
}
}
}
nsel = 0;
for ( i = 1; i < 17; ++i )
for ( int i = 1; i < 17; ++i )
{
if ( imon[i] )
listSetInt(ilist, nsel++, i);
if ( imon[i] ) listSetInt(ilist, nsel++, i);
}
return (nsel);
return nsel;
}
......
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