Commit 7ac2fac9 authored by Uwe Schulzweida's avatar Uwe Schulzweida
Browse files

added env. CDO_SEASON_START to set the start month of seasons

parent f15698a1
......@@ -5,7 +5,7 @@
* added support of time units 'seconds' to all operators
- the format of all time parameter changed from hh:mm to hh:mm:ss!
* gridarea: added support for hexagonal GME grid and tripolar MPIOM grid
* Seasstat: added env. CDO_SEASON_START to set the start month of the seasons [request: Laurent Mortier]
* Seasstat: added env. CDO_SEASON_START to set the start month of seasons [request: Laurent Mortier]
* store_link_cnsrv: remove two restrict keywords (bug fix) [report: Clement Alo]
* Version 1.4.0 released
......
......@@ -26,6 +26,7 @@
#include "cdo.h"
#include "cdo_int.h"
#include "pstream.h"
#include "util.h"
void *Seascount(void *argument)
......@@ -51,9 +52,7 @@ void *Seascount(void *argument)
double missval;
FIELD **vars1 = NULL;
FIELD field;
enum {START_DEC, START_JAN};
int season_start = START_DEC;
char *envstr;
int season_start;
cdoInitialize(argument);
......@@ -62,20 +61,7 @@ void *Seascount(void *argument)
operatorID = cdoOperatorID();
operfunc = cdoOperatorFunc(operatorID);
envstr = getenv("CDO_SEASON_START");
if ( envstr )
{
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");
}
}
season_start = get_season_start();
streamID1 = streamOpenRead(cdoStreamName(0));
if ( streamID1 < 0 ) cdiError(streamID1, "Open failed on %s", cdoStreamName(0));
......
......@@ -27,6 +27,7 @@
#include "cdo_int.h"
#include "pstream.h"
#include "percentiles.h"
#include "util.h"
void *Seaspctl(void *argument)
......@@ -54,9 +55,7 @@ void *Seaspctl(void *argument)
FIELD field;
int pn;
HISTOGRAM_SET *hset = NULL;
enum {START_DEC, START_JAN};
int season_start = START_DEC;
char *envstr;
int season_start;
cdoInitialize(argument);
......@@ -68,20 +67,7 @@ void *Seaspctl(void *argument)
if ( pn < 1 || pn > 99 )
cdoAbort("Illegal argument: percentile number %d is not in the range 1..99!", pn);
envstr = getenv("CDO_SEASON_START");
if ( envstr )
{
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");
}
}
season_start = get_season_start();
streamID1 = streamOpenRead(cdoStreamName(0));
if ( streamID1 < 0 ) cdiError(streamID1, "Open failed on %s", cdoStreamName(0));
......
......@@ -32,6 +32,7 @@
#include "cdo.h"
#include "cdo_int.h"
#include "pstream.h"
#include "util.h"
void *Seasstat(void *argument)
......@@ -60,12 +61,8 @@ void *Seasstat(void *argument)
double missval;
FIELD **vars1 = NULL, **vars2 = NULL, **samp1 = NULL;
FIELD field;
enum {START_DEC, START_JAN};
int season_start = START_DEC;
const char seas_str1[4][4] = {"DJF", "MAM", "JJA", "SON"};
const char seas_str2[4][4] = {"JFM", "AMJ", "JAS", "OND"};
const char *seas_str[4];
char *envstr;
int season_start;
const char *seas_name[4];
cdoInitialize(argument);
......@@ -80,25 +77,8 @@ void *Seasstat(void *argument)
operatorID = cdoOperatorID();
operfunc = cdoOperatorFunc(operatorID);
envstr = getenv("CDO_SEASON_START");
if ( envstr )
{
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");
}
}
if ( season_start == START_DEC )
for ( i = 0; i < 4; ++i ) seas_str[i] = seas_str1[i];
else
for ( i = 0; i < 4; ++i ) seas_str[i] = seas_str2[i];
season_start = get_season_start();
get_season_name(seas_name);
streamID1 = streamOpenRead(cdoStreamName(0));
if ( streamID1 < 0 ) cdiError(streamID1, "Open failed on %s", cdoStreamName(0));
......@@ -343,7 +323,7 @@ void *Seasstat(void *argument)
"start %4.4d-%2.2d-%2.2d %2.2d:%2.2d:%2.2d "
"end %4.4d-%2.2d-%2.2d %2.2d:%2.2d:%2.2d "
"ntimesteps %d",
nseason, seas_str[seas0],
nseason, seas_name[seas0],
year0, month0, day0, hour0, minute0, second0,
year1, month1, day1, hour1, minute1, second1,
nsets);
......
......@@ -121,17 +121,22 @@ void *Seltime(void *argument)
{
char Seas[3];
int seas[4] = {FALSE, FALSE, FALSE, FALSE};
int ival[4] = {0, 0, 0, 0};
int imon[17]; /* 1-16 ! */
int ival;
size_t len;
int season_start;
season_start = get_season_start();
nsel = operatorArgc();
if ( isdigit(*operatorArgv()[0]))
for ( i = 0; i < nsel; i++ )
{
if ( atoi(operatorArgv()[i]) == 1 || atoi(operatorArgv()[i]) == 13 ) seas[0] = TRUE;
else if ( atoi(operatorArgv()[i]) == 2 || atoi(operatorArgv()[i]) == 14 ) seas[1] = TRUE;
else if ( atoi(operatorArgv()[i]) == 3 || atoi(operatorArgv()[i]) == 15 ) seas[2] = TRUE;
else if ( atoi(operatorArgv()[i]) == 4 || atoi(operatorArgv()[i]) == 16 ) seas[3] = TRUE;
ival = atoi(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++ )
......@@ -139,23 +144,47 @@ void *Seltime(void *argument)
len = strlen(operatorArgv()[i]);
if ( len > 3 ) len = 3;
while ( len-- > 0 ) Seas[len] = toupper(operatorArgv()[i][len]);
if ( Seas[0] == 'D' && Seas[1] == 'J' && Seas[2] == 'F' ) seas[0] = TRUE;
else if ( Seas[0] == 'M' && Seas[1] == 'A' && Seas[2] == 'M' ) seas[1] = TRUE;
else if ( Seas[0] == 'J' && Seas[1] == 'J' && Seas[2] == 'A' ) seas[2] = TRUE;
else if ( Seas[0] == 'S' && Seas[1] == 'O' && Seas[2] == 'N' ) seas[3] = TRUE;
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]);
}
}
nsel = 4;
for ( i = 0; i < 17; ++i ) imon[i] = 0;
if ( seas[0] ) { ival[0] = 12; ival[1] = 1; ival[2] = 2; ival[3] = 13; }
if ( seas[1] ) { ival[0] = 3; ival[1] = 4; ival[2] = 5; ival[3] = 14; }
if ( seas[2] ) { ival[0] = 6; ival[1] = 7; ival[2] = 8; ival[3] = 15; }
if ( seas[3] ) { ival[0] = 9; ival[1] = 10; ival[2] = 11; ival[3] = 16; }
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]++; }
}
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]++; }
}
listSetInt(ilist, 0, ival[0]);
listSetInt(ilist, 1, ival[1]);
listSetInt(ilist, 2, ival[2]);
listSetInt(ilist, 3, ival[3]);
nsel = 0;
for ( i = 1; i < 17; ++i )
{
if ( imon[i] )
listSetInt(ilist, nsel++, i);
}
}
else if ( operatorID == SELDATE )
{
......
......@@ -2,7 +2,7 @@
This file is part of CDO. CDO is a collection of Operators to
manipulate and analyse Climate model Data.
Copyright (C) 2003-2006 Uwe Schulzweida, Uwe.Schulzweida@zmaw.de
Copyright (C) 2003-2009 Uwe Schulzweida, Uwe.Schulzweida@zmaw.de
See COPYING file for copying and redistribution conditions.
This program is free software; you can redistribute it and/or modify
......@@ -31,6 +31,7 @@
#include "cdo.h"
#include "cdo_int.h"
#include "pstream.h"
#include "util.h"
#define MAX_STREAMS 32
......@@ -50,7 +51,6 @@ void *Splittime(void *argument)
int streamIDs[MAX_STREAMS], tsIDs[MAX_STREAMS];
char filesuffix[32];
char filename[1024];
char *Seas[4] = {"DJF", "MAM", "JJA", "SON"};
int index = 0;
int i;
int taxisID1, taxisID2;
......@@ -59,6 +59,8 @@ void *Splittime(void *argument)
int gridsize;
int nmiss;
double *array = NULL;
int season_start;
const char *seas_name[4];
cdoInitialize(argument);
......@@ -73,6 +75,9 @@ void *Splittime(void *argument)
if ( UNCHANGED_RECORD ) lcopy = TRUE;
season_start = get_season_start();
get_season_name(seas_name);
for ( i = 0; i < MAX_STREAMS; i++ ) streamIDs[i] = -1;
for ( i = 0; i < MAX_STREAMS; i++ ) tsIDs[i] = 0;
......@@ -119,11 +124,21 @@ void *Splittime(void *argument)
if ( index < 0 || index > 16 )
cdoAbort("Month %d out of range!", index);
if ( index <= 12 )
index = (index % 12) / 3;
if ( season_start == START_DEC )
{
if ( index <= 12 )
index = (index % 12) / 3;
else
index = index - 13;
}
else
index = index - 13;
{
if ( index <= 12 )
index = (index - 1) / 3;
else
index = index - 13;
}
if ( index < 0 || index > 3 )
cdoAbort("Season %d out of range!", index+1);
}
......@@ -141,7 +156,7 @@ void *Splittime(void *argument)
{
if ( operatorID == SPLITSEAS )
{
sprintf(filename+nchars, "%3s", Seas[index]);
sprintf(filename+nchars, "%3s", seas_name[index]);
if ( filesuffix[0] )
sprintf(filename+nchars+3, "%s", filesuffix);
}
......
......@@ -31,6 +31,7 @@
#include "pstream.h"
#include "field.h"
#include "percentiles.h"
#include "util.h"
#define NSEAS 4
......@@ -60,9 +61,7 @@ void *Yseaspctl(void *argument)
FIELD field;
int pn;
HISTOGRAM_SET *hsets[NSEAS];
enum {START_DEC, START_JAN};
int season_start = START_DEC;
char *envstr;
int season_start;
cdoInitialize(argument);
cdoOperatorAdd("yseaspctl", func_pctl, 0, NULL);
......@@ -73,21 +72,7 @@ void *Yseaspctl(void *argument)
if ( pn < 1 || pn > 99 )
cdoAbort("Illegal argument: percentile number %d is not in the range 1..99!", pn);
envstr = getenv("CDO_SEASON_START");
if ( envstr )
{
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");
}
}
season_start = get_season_start();
for ( seas = 0; seas < NSEAS; seas++ )
{
vars1[seas] = NULL;
......
......@@ -36,6 +36,7 @@
#include "cdo_int.h"
#include "pstream.h"
#include "field.h"
#include "util.h"
#define NSEAS 4
......@@ -66,9 +67,7 @@ void *Yseasstat(void *argument)
double missval;
FIELD **vars1[NSEAS], **vars2[NSEAS], **samp1[NSEAS];
FIELD field;
enum {START_DEC, START_JAN};
int season_start = START_DEC;
char *envstr;
int season_start;
cdoInitialize(argument);
......@@ -83,21 +82,7 @@ void *Yseasstat(void *argument)
operatorID = cdoOperatorID();
operfunc = cdoOperatorFunc(operatorID);
envstr = getenv("CDO_SEASON_START");
if ( envstr )
{
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");
}
}
season_start = get_season_start();
for ( seas = 0; seas < NSEAS; seas++ )
{
vars1[seas] = NULL;
......
......@@ -22,6 +22,7 @@
#include "cdo.h"
#include "modules.h"
#include "dmemory.h"
#include "util.h"
char *getProgname(char *string)
{
......@@ -169,3 +170,42 @@ void strtolower(char *str)
str[i] = tolower((int) str[i]);
}
}
const char *seas_name_dec[4] = {"DJF", "MAM", "JJA", "SON"};
const char *seas_name_jan[4] = {"JFM", "AMJ", "JAS", "OND"};
int get_season_start(void)
{
int season_start = START_DEC;
char *envstr;
envstr = getenv("CDO_SEASON_START");
if ( envstr )
{
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);
}
void get_season_name(const char *seas_name[4])
{
long i;
if ( get_season_start() == START_DEC )
for ( i = 0; i < 4; ++i ) seas_name[i] = seas_name_dec[i];
else
for ( i = 0; i < 4; ++i ) seas_name[i] = seas_name_jan[i];
}
......@@ -2,7 +2,7 @@
This file is part of CDO. CDO is a collection of Operators to
manipulate and analyse Climate model Data.
Copyright (C) 2003-2006 Uwe Schulzweida, Uwe.Schulzweida@zmaw.de
Copyright (C) 2003-2009 Uwe Schulzweida, Uwe.Schulzweida@zmaw.de
See COPYING file for copying and redistribution conditions.
This program is free software; you can redistribute it and/or modify
......@@ -25,4 +25,9 @@ char *getOperatorName(char *xoperator);
char *makeArgument(int argc, char *argv[]);
char *getFileArg(char *argument);
enum {START_DEC, START_JAN};
int get_season_start(void);
void get_season_name(const char *seas_name[4]);
#endif /* _UTIL_H */
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