Commit 6b4fe2b8 authored by Uwe Schulzweida's avatar Uwe Schulzweida
Browse files

Select: added parameter date

parent 98ba69f7
......@@ -4,10 +4,20 @@
* Version 1.6.9 released
* clipping: update to YAC version 1.0.3
2015-04-17 Uwe Schulzweida
* Select: added parameter date
2015-04-16 Uwe Schulzweida
* Select: added parameter startdate, enddate
2015-04-13 Karl-Hermann Wieners
* New operator: aexpr - Evaluate expressions and append results
* New operator: aexprf - Evaluate expression script and append results
* New operator: selzaxisname - Select z-axes by name
2015-04-10 Uwe Schulzweida
* New operator: after - ECHAM standard post processor
......
......@@ -4,10 +4,13 @@ CDO NEWS
Version 1.6.9 (26 September 2015):
New features:
* select: added parameter date, startdate, enddate
* expr: added support for operator ?:,&&,||
* select: added parameter startdate, enddate
New operators:
* after: ECHAM standard post processor
* aexpr: Evaluate expressions and append results
* aexprf: Evaluate expression script and append results
* selzaxisname: Select z-axes by name
Version 1.6.8 (26 March 2015):
......
......@@ -166,7 +166,7 @@ Operator catalog:
Arithmetic
-------------------------------------------------------------
Exprf expr Evaluate expressions
Exprf exprf Evaluate expressions from script file
Exprf exprf Evaluate expressions script
Exprf aexpr Evaluate expressions and append results
Exprf aexprf Evaluate expression script and append results
Math abs Absolute value
......
......@@ -1213,8 +1213,9 @@ sub print_description {
$line =~ s/\@celsius/{\\textcelsius}/og;
$line =~ s/</\$<\$/og;
$line =~ s/>/\$>\$/og;
$line =~ s/\\or/\$||\$/og;
$line =~ s/\\exp/\\^\\/og;
$line =~ s/\\and/\\&\\&/og;
$line =~ s/\\or/\$||\$/og;
$line =~ s/%/\\%/og;
if ( $table == 1 ) { $line =~ s/$/ \\\\ \\hline/g; }
}
......@@ -1236,6 +1237,7 @@ sub print_description {
$docline =~ s/\\_/_/g;
$docline =~ s/\\cite//og;
$docline =~ s/\\neq/!=/og;
$docline =~ s/\\exp/^/og;
$docline =~ s/\\and/&&/og;
$docline =~ s/\\or/||/og;
$docline =~ s/\\/\\\\/og;
......
......@@ -28,7 +28,7 @@ The following operators are supported:
- & subtraction & x - y & Difference of x and y
* & multiplication & x * y & Product of x and y
/ & division & x / y & Quotient of x and y
\^\ & exponentiation & x\^\ y & Exponentiates x with y
\exp & exponentiation & x \exp y & Exponentiates x with y
== & equal to & x == y & 1, if x equal to y; else 0
!= & not equal to & x != y & 1, if x not equal to y; else 0
> & greater than & x > y & 1, if x greater than y; else 0
......@@ -36,8 +36,8 @@ The following operators are supported:
>= & greater equal & x >= y & 1, if x greater equal y; else 0
<= & less equal & x <= y & 1, if x less equal y; else 0
<=> & less equal greater & x <=> y & -1, if x less y; 1, if x greater y; else 0
\&\& & logical AND & x \&\& y & 1, if x and y not equal 0; else 0
\or & logical OR & x \or y & 1, if x or y not equal 0; else 0
\and & logical AND & x \and y & 1, if x and y not equal 0; else 0
\or & logical OR & x \or y & 1, if x or y not equal 0; else 0
?: & ternary conditional & x ? y : z & y, if x not equal 0, else z
@EndTable
......@@ -91,7 +91,7 @@ The processing instructions are read from the parameter.
@BeginOperator_exprf
@Title = Evaluate expressions from script file
@Title = Evaluate expressions script
@Parameter = filename
@BeginDescription
......
......@@ -12,7 +12,7 @@ This module selects some fields from @file{ifiles} and writes them to @file{ofil
@file{ifiles} is an arbitrary number of input files. All input files need to have
the same structure with the same variables on different timesteps.
The fields selected depends on the chosen parameters. Parameter is a comma
separated list of key-value pairs.
separated list of key-value pairs. Wildcards can be used for string parameter.
@EndDescription
@EndModule
......@@ -50,6 +50,8 @@ INTEGER Comma separated list of GRIB level types.
INTEGER Comma separated list of index of levels.
@Item = level
FLOAT Comma separated list of vertical levels.
@Item = date
STRING Comma separated list of dates (format YYYY-MM-DDThh:mm:ss).
@Item = startdate
STRING Start date (format YYYY-MM-DDThh:mm:ss).
@Item = enddate
......
......@@ -73,6 +73,7 @@ static int NumParameter = sizeof(Parameter) / sizeof(Parameter[0]);
#define PAR_CHECK_INT(name) par_check_int(npar_##name, par_##name, flag_##name, name)
#define PAR_CHECK_FLT(name) par_check_flt(npar_##name, par_##name, flag_##name, name)
#define PAR_CHECK_WORD(name) par_check_word(npar_##name, par_##name, flag_##name, name)
#define PAR_CHECK_DATE(name) par_check_date(npar_##name, par_##name, flag_##name, name)
#define MAX_PLIST_ENTRY 256
#define MAX_PML_ENTRY 256
......@@ -421,6 +422,24 @@ int par_check_word(int npar, char **parlist, int *flaglist, char *par)
}
int par_check_date(int npar, char **parlist, int *flaglist, char *par)
{
int found = 0;
char wcdate[512];
if ( *par == ' ' ) ++par;
for ( int i = 0; i < npar; i++ )
{
strcpy(wcdate, parlist[i]);
strcat(wcdate, "*");
if ( wildcardmatch(wcdate, par) == 0 ) { found = 1; flaglist[i] = TRUE;/* break;*/}
}
return (found);
}
void par_check_int_flag(int npar, int *parlist, int *flaglist, const char *txt)
{
for ( int i = 0; i < npar; ++i )
......@@ -491,6 +510,7 @@ void *Select(void *argument)
PML_DEF_WORD(param, 1024, "Parameter");
PML_DEF_WORD(startdate, 1, "Start date");
PML_DEF_WORD(enddate, 1, "End date");
PML_DEF_WORD(date, 1024, "Date");
PML_INIT_INT(timestep_of_year);
PML_INIT_INT(timestep);
......@@ -507,6 +527,7 @@ void *Select(void *argument)
PML_INIT_WORD(param);
PML_INIT_WORD(startdate);
PML_INIT_WORD(enddate);
PML_INIT_WORD(date);
cdoInitialize(argument);
......@@ -544,6 +565,7 @@ void *Select(void *argument)
PML_ADD_WORD(pml, param);
PML_ADD_WORD(pml, startdate);
PML_ADD_WORD(pml, enddate);
PML_ADD_WORD(pml, date);
pmlRead(pml, nsel, argnames);
......@@ -564,6 +586,7 @@ void *Select(void *argument)
PML_NUM(pml, param);
PML_NUM(pml, startdate);
PML_NUM(pml, enddate);
PML_NUM(pml, date);
/*
pmlDelete(pml);
*/
......@@ -709,7 +732,7 @@ void *Select(void *argument)
PAR_CHECK_WORD_FLAG(name);
PAR_CHECK_WORD_FLAG(param);
if ( npar_startdate || npar_enddate ) ltimsel = TRUE;
if ( npar_date || npar_startdate || npar_enddate ) ltimsel = TRUE;
if ( npar_timestep_of_year || npar_timestep || npar_year || npar_month || npar_day || npar_hour || npar_minute ) ltimsel = TRUE;
npar = 0;
......@@ -860,7 +883,7 @@ void *Select(void *argument)
if ( npar_timestep && PAR_CHECK_INT(timestep) ) copytimestep = TRUE;
if ( npar_timestep_of_year && PAR_CHECK_INT(timestep_of_year) ) copytimestep = TRUE;
if ( !copytimestep && npar_timestep == 0 && npar_timestep_of_year == 0 )
if ( !copytimestep && npar_date == 0 && npar_timestep == 0 && npar_timestep_of_year == 0 )
{
int lyear = 0, lmonth = 0, lday = 0, lhour = 0, lminute = 0;
......@@ -906,6 +929,15 @@ void *Select(void *argument)
}
}
if ( npar_date )
{
char vdatetimestr[64];
datetime2str(vdate, vtime, vdatetimestr, sizeof(vdatetimestr));
date = vdatetimestr;
if ( PAR_CHECK_DATE(date) ) copytimestep = TRUE;
}
if ( operatorID == DELETE ) copytimestep = !copytimestep;
}
......@@ -955,6 +987,8 @@ void *Select(void *argument)
END_LABEL:
if ( !cdoVerbose && nfiles > 1 ) progressStatus(0, 1, 1);
PAR_CHECK_INT_FLAG(timestep_of_year);
PAR_CHECK_INT_FLAG(timestep);
PAR_CHECK_INT_FLAG(year);
......@@ -964,6 +998,7 @@ void *Select(void *argument)
PAR_CHECK_INT_FLAG(minute);
PAR_CHECK_WORD_FLAG(startdate);
PAR_CHECK_WORD_FLAG(enddate);
PAR_CHECK_WORD_FLAG(date);
if ( streamID2 != CDI_UNDEFID ) streamClose(streamID2);
......
......@@ -59,7 +59,7 @@ void *Showinfo(void *argument)
char varname[CDI_MAX_NAME];
char stdname[CDI_MAX_NAME];
char varunits[CDI_MAX_NAME];
char vdatestr[32], vtimestr[32];
char vdatetimestr[64], vdatestr[32], vtimestr[32];
cdoInitialize(argument);
......@@ -185,9 +185,8 @@ void *Showinfo(void *argument)
vdate = taxisInqVdate(taxisID);
vtime = taxisInqVtime(taxisID);
date2str(vdate, vdatestr, sizeof(vdatestr));
time2str(vtime, vtimestr, sizeof(vtimestr));
fprintf(stdout, " %sT%s", vdatestr, vtimestr);
datetime2str(vdate, vtime, vdatetimestr, sizeof(vdatetimestr));
fprintf(stdout, " %s", vdatetimestr);
tsID++;
nout++;
......
......@@ -110,6 +110,7 @@ int ntr2nlat_linear(int ntr);
int compNlon(int nlat);
void param2str(int param, char *paramstr, int maxlen);
void datetime2str(int date, int time, char *datetimestr, int maxlen);
void date2str(int date, char *datestr, int maxlen);
void time2str(int time, char *timestr, int maxlen);
......
......@@ -458,7 +458,7 @@ static char *SelectHelp[] = {
" ifiles is an arbitrary number of input files. All input files need to have ",
" the same structure with the same variables on different timesteps.",
" The fields selected depends on the chosen parameters. Parameter is a comma",
" separated list of key-value pairs.",
" separated list of key-value pairs. Wildcards can be used for string parameter.",
"",
"OPERATORS",
" select Select fields",
......@@ -473,6 +473,7 @@ static char *SelectHelp[] = {
" ltype INTEGER Comma separated list of GRIB level types.",
" levidx INTEGER Comma separated list of index of levels.",
" level FLOAT Comma separated list of vertical levels.",
" date STRING Comma separated list of dates (format YYYY-MM-DDThh:mm:ss).",
" startdate STRING Start date (format YYYY-MM-DDThh:mm:ss).",
" enddate STRING End date (format YYYY-MM-DDThh:mm:ss).",
" minute INTEGER Comma separated list of minutes.",
......@@ -1284,7 +1285,7 @@ static char *ExprHelp[] = {
" - & subtraction & x - y & Difference of x and y ",
" * & multiplication & x * y & Product of x and y ",
" / & division & x / y & Quotient of x and y",
" \\^\\ & exponentiation & x\\^\\ y & Exponentiates x with y ",
" ^ & exponentiation & x ^ y & Exponentiates x with y ",
" == & equal to & x == y & 1, if x equal to y; else 0",
" != & not equal to & x != y & 1, if x not equal to y; else 0",
" > & greater than & x > y & 1, if x greater than y; else 0",
......@@ -1292,8 +1293,8 @@ static char *ExprHelp[] = {
" >= & greater equal & x >= y & 1, if x greater equal y; else 0",
" <= & less equal & x <= y & 1, if x less equal y; else 0",
" <=> & less equal greater & x <=> y & -1, if x less y; 1, if x greater y; else 0 ",
" \\&\\& & logical AND & x \\&\\& y & 1, if x and y not equal 0; else 0",
" || & logical OR & x || y & 1, if x or y not equal 0; else 0",
" && & logical AND & x && y & 1, if x and y not equal 0; else 0",
" || & logical OR & x || y & 1, if x or y not equal 0; else 0",
" ?: & ternary conditional & x ? y : z & y, if x not equal 0, else z ",
" ",
" The following intrinsic functions are available:",
......@@ -1317,7 +1318,7 @@ static char *ExprHelp[] = {
"OPERATORS",
" expr Evaluate expressions",
" The processing instructions are read from the parameter.",
" exprf Evaluate expressions from script file",
" exprf Evaluate expressions script",
" Contrary to expr the processing instructions are read from a file.",
" aexpr Evaluate expressions and append results",
" Same as expr, but keep input variables and append results",
......
......@@ -3,6 +3,22 @@
void uuid2str(const unsigned char uuid[CDI_UUID_SIZE], char *uuidstr);
void datetime2str(int date, int time, char *datetimestr, int maxlen)
{
int year, month, day;
int hour, minute, second;
int len;
cdiDecodeDate(date, &year, &month, &day);
cdiDecodeTime(time, &hour, &minute, &second);
len = sprintf(datetimestr, DATE_FORMAT "T" TIME_FORMAT, year, month, day, hour, minute, second);
if ( len > ( maxlen-1) )
fprintf(stderr, "Internal problem (%s): sizeof input string is too small!\n", __func__);
}
void date2str(int date, char *datestr, int maxlen)
{
int year, month, day;
......
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