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

Runstat: added get_timestat_date()

parent f23a67c9
...@@ -117,6 +117,35 @@ void datetime_avg(int calendar, int ndates, datetime_t *datetime) ...@@ -117,6 +117,35 @@ void datetime_avg(int calendar, int ndates, datetime_t *datetime)
} }
void get_timestat_date(int *tstat_date)
{
char *envstr;
envstr = getenv("TIMESTAT_DATE");
if ( envstr == NULL ) envstr = getenv("RUNSTAT_DATE");
if ( envstr )
{
int env_date = -1;
char envstrl[8];
memcpy(envstrl, envstr, 8);
envstrl[7] = 0;
strtolower(envstrl);
if ( memcmp(envstrl, "first", 5) == 0 ) env_date = DATE_FIRST;
else if ( memcmp(envstrl, "last", 4) == 0 ) env_date = DATE_LAST;
else if ( memcmp(envstrl, "middle", 6) == 0 ) env_date = DATE_MIDDLE;
if ( env_date >= 0 )
{
*tstat_date = env_date;
if ( cdoVerbose ) cdoPrint("Set TIMESTAT_DATE to %s", envstr);
}
}
}
void *Runstat(void *argument) void *Runstat(void *argument)
{ {
int operatorID; int operatorID;
...@@ -144,7 +173,7 @@ void *Runstat(void *argument) ...@@ -144,7 +173,7 @@ void *Runstat(void *argument)
int taxisID1, taxisID2; int taxisID1, taxisID2;
int calendar; int calendar;
int runstat_nomiss = 0; int runstat_nomiss = 0;
int runstat_date = DATE_MIDDLE; int timestat_date = DATE_MIDDLE;
char *envstr; char *envstr;
cdoInitialize(argument); cdoInitialize(argument);
...@@ -157,27 +186,7 @@ void *Runstat(void *argument) ...@@ -157,27 +186,7 @@ void *Runstat(void *argument)
if ( envval == 1 ) runstat_nomiss = 1; if ( envval == 1 ) runstat_nomiss = 1;
} }
envstr = getenv("RUNSTAT_DATE"); get_timestat_date(&timestat_date);
if ( envstr )
{
int env_date = -1;
char envstrl[8];
memcpy(envstrl, envstr, 8);
envstrl[7] = 0;
strtolower(envstrl);
if ( memcmp(envstrl, "first", 5) == 0 ) env_date = DATE_FIRST;
else if ( memcmp(envstrl, "last", 4) == 0 ) env_date = DATE_LAST;
else if ( memcmp(envstrl, "middle", 6) == 0 ) env_date = DATE_MIDDLE;
if ( env_date >= 0 )
{
runstat_date = env_date;
if ( cdoVerbose ) cdoPrint("Set RUNSTAT_DATE to %s", envstr);
}
}
cdoOperatorAdd("runmin", func_min, 0, NULL); cdoOperatorAdd("runmin", func_min, 0, NULL);
cdoOperatorAdd("runmax", func_max, 0, NULL); cdoOperatorAdd("runmax", func_max, 0, NULL);
...@@ -352,9 +361,9 @@ void *Runstat(void *argument) ...@@ -352,9 +361,9 @@ void *Runstat(void *argument)
} }
} }
if ( runstat_date == DATE_MIDDLE ) datetime_avg_dtinfo(calendar, ndates, dtinfo); if ( timestat_date == DATE_MIDDLE ) datetime_avg_dtinfo(calendar, ndates, dtinfo);
else if ( runstat_date == DATE_FIRST ) dtinfo[ndates].v = dtinfo[0].v; else if ( timestat_date == DATE_FIRST ) dtinfo[ndates].v = dtinfo[0].v;
else if ( runstat_date == DATE_LAST ) dtinfo[ndates].v = dtinfo[ndates-1].v; else if ( timestat_date == DATE_LAST ) dtinfo[ndates].v = dtinfo[ndates-1].v;
if ( taxisHasBounds(taxisID2) ) if ( taxisHasBounds(taxisID2) )
{ {
......
...@@ -166,6 +166,7 @@ juldate_t juldate_sub(juldate_t juldate2, juldate_t juldate1); ...@@ -166,6 +166,7 @@ juldate_t juldate_sub(juldate_t juldate2, juldate_t juldate1);
juldate_t juldate_add_seconds(int seconds, juldate_t juldate); juldate_t juldate_add_seconds(int seconds, juldate_t juldate);
double juldate_to_seconds(juldate_t juldate); double juldate_to_seconds(juldate_t juldate);
void get_timestat_date(int *tstat_date);
void datetime_avg(int dpy, int ndates, datetime_t *datetime); void datetime_avg(int dpy, int ndates, datetime_t *datetime);
void datetime_avg_dtinfo(int dpy, int ndates, dtinfo_t *dtinfo); void datetime_avg_dtinfo(int dpy, int ndates, dtinfo_t *dtinfo);
void taxisInqDTinfo(int taxisID, dtinfo_t *dtinfo); void taxisInqDTinfo(int taxisID, dtinfo_t *dtinfo);
......
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