Commit 38cb1841 authored by Fabian Wachsmann's avatar Fabian Wachsmann
Browse files

Added output frequency option for all ECA_REQUEST_1 indices

parent ee237adc
......@@ -70,6 +70,7 @@
#include "ecacore.h"
#include "ecautil.h"
#include "util_date.h"
#include "pmlist.h"
#define TO_DEG_CELSIUS(x) ((x) -273.15)
#define TO_KELVIN(x) ((x) + 273.15)
......@@ -278,6 +279,22 @@ static const char HURR_LONGNAME2[] = "Greatest number of consecutive hurricane
/* ECA temperature indices */
static void addWithFrequency(std::vector<std::string> &params, const char *operatorName)
{
//copy everything from params except the first
KVList kvlist;
if (kvlist.parseArguments(1, params) != 0) cdoAbort("Argument parse error!");
auto kv = kvlist.search("freq");
if (kv && kv->nvalues > 0 )
{
if ( kv->values[0].compare("month") == 0 )
cdoOperatorAdd(operatorName, 0, 8, nullptr);
else if ( kv->values[0].compare("year") == 0 )
cdoOperatorAdd(operatorName, 0, 10, nullptr);
}
else
cdoOperatorAdd(operatorName, 0, 31, nullptr);
}
void *EcaCfd(void *process)
{
......@@ -287,10 +304,20 @@ void *EcaCfd(void *process)
char cfd_name2[1024];
cdoInitialize(process);
cdoOperatorAdd("eca_cfd", 0, 31, nullptr);
if ( operatorArgc() > 1 ) cdoAbort("Too many arguments!");
if ( operatorArgc() > 0 ) ndays = parameter2int(cdoOperatorArgv(0));
if ( operatorArgc() > 2 ) cdoAbort("Too many arguments!");
if ( operatorArgc() > 1 )
{
auto params = cdoGetOperArgv();
//copy everything from params except the first
params = std::vector<std::string>(params.begin() + 1, params.end());
addWithFrequency(params, "eca_cfd");
}
else
{
if ( operatorArgc() > 0 ) ndays = parameter2int(cdoOperatorArgv(0));
cdoOperatorAdd("eca_cfd", 0, 31, nullptr);
}
sprintf(cfd_longname2, CFD_LONGNAME2, ndays);
sprintf(cfd_name2, CFD_NAME2, ndays);
......@@ -329,14 +356,23 @@ void *EcaCsu(void *process)
char csu_name2[1024];
cdoInitialize(process);
cdoOperatorAdd("eca_csu", 0, 31, nullptr);
if ( operatorArgc() > 2 ) cdoAbort("Too many arguments!");
if ( operatorArgc() > 3 ) cdoAbort("Too many arguments!");
if ( operatorArgc() > 2 )
{
auto params = cdoGetOperArgv();
//copy everything from params except the first
params = std::vector<std::string>(params.begin() + 2, params.end());
addWithFrequency(params, "eca_csu");
}
else if ( operatorArgc() > 0 )
{
cdoOperatorAdd("eca_csu", 0, 31, nullptr);
argT = parameter2double(cdoOperatorArgv(0));
if ( operatorArgc() == 2 ) ndays = parameter2int(cdoOperatorArgv(1));
}
else
cdoOperatorAdd("eca_csu", 0, 31, nullptr);
sprintf(csu_longname2, CSU_LONGNAME2, ndays);
sprintf(csu_name2, CSU_NAME2, ndays);
......@@ -475,7 +511,14 @@ void *EcaFd(void *process)
ECA_REQUEST_1 request;
cdoInitialize(process);
cdoOperatorAdd("eca_fd", 0, 31, nullptr);
if ( operatorArgc() > 0 )
{
auto params = cdoGetOperArgv();
addWithFrequency(params, "eca_fd");
}
else
cdoOperatorAdd("eca_fd", 0, 31, nullptr);
request.var1.name = FD_NAME;
request.var1.longname = FD_LONGNAME;
......@@ -672,7 +715,14 @@ void *EcaId(void *process)
ECA_REQUEST_1 request;
cdoInitialize(process);
cdoOperatorAdd("eca_id", 0, 31, nullptr);
if ( operatorArgc() > 0 )
{
auto params = cdoGetOperArgv();
//copy everything from params except the first
addWithFrequency(params, "eca_id");
}
else
cdoOperatorAdd("eca_id", 0, 31, nullptr);
request.var1.name = ID_NAME;
request.var1.longname = ID_LONGNAME;
......@@ -700,9 +750,18 @@ void *EcaSu(void *process)
ECA_REQUEST_1 request;
cdoInitialize(process);
cdoOperatorAdd("eca_su", 0, 31, nullptr);
if ( operatorArgc() > 0 ) argT = parameter2double(cdoOperatorArgv(0));
if ( operatorArgc() > 1 )
{
auto params = cdoGetOperArgv();
params = std::vector<std::string>(params.begin() + 1, params.end());
addWithFrequency(params, "eca_su");
}
else
cdoOperatorAdd("eca_su", 0, 31, nullptr);
char *longname = (char*) Malloc(strlen(SU_LONGNAME) + 40);
sprintf(longname, SU_LONGNAME, argT);
......@@ -835,9 +894,17 @@ void *EcaTr(void *process)
char tr_longname[1024];
cdoInitialize(process);
cdoOperatorAdd("eca_tr", 0, 31, nullptr);
if ( operatorArgc() > 0 ) argT = parameter2double(cdoOperatorArgv(0));
if ( operatorArgc() > 1 )
{
auto params = cdoGetOperArgv();
params = std::vector<std::string>(params.begin() + 1, params.end());
addWithFrequency(params, "eca_tr");
}
else
cdoOperatorAdd("eca_tr", 0, 31, nullptr);
sprintf(tr_longname, TR_LONGNAME, argT);
......@@ -892,7 +959,18 @@ void *EcaTx90p(void *process)
ECA_REQUEST_2 request;
cdoInitialize(process);
cdoOperatorAdd("eca_tx90p", 0, 31, nullptr);
if (operatorArgc() > 0)
{
if ('m' == cdoOperatorArgv(0)[0])
cdoOperatorAdd("eca_tx90p", 0, 8, nullptr); /* monthly mode */
else
cdoWarning("Parameter value '%s' is invalid. The only valid value is "
"'m' indicating monthly mode. Operating in yearly mode now.",
cdoOperatorArgv(0));
}
else
cdoOperatorAdd("eca_tx90p", 0, 31, nullptr);
request.var1.name = TX90P_NAME;
request.var1.longname = TX90P_LONGNAME;
......@@ -925,14 +1003,22 @@ void *EcaCdd(void *process)
char cdd_name2[1024];
cdoInitialize(process);
cdoOperatorAdd("eca_cdd", 0, 31, nullptr);
if ( operatorArgc() > 2 ) cdoAbort("Too many arguments!");
if ( operatorArgc() > 3 ) cdoAbort("Too many arguments!");
else if ( operatorArgc() > 2 )
{
auto params = cdoGetOperArgv();
params = std::vector<std::string>(params.begin() + 2, params.end());
addWithFrequency(params, "eca_cdd");
}
else if ( operatorArgc() > 0 )
{
threshold = parameter2double(cdoOperatorArgv(0));
if ( operatorArgc() == 2 ) ndays = parameter2int(cdoOperatorArgv(1));
cdoOperatorAdd("eca_cdd", 0, 31, nullptr);
}
else
cdoOperatorAdd("eca_cdd", 0, 31, nullptr);
sprintf(cdd_longname, CDD_LONGNAME, threshold);
sprintf(cdd_longname2, CDD_LONGNAME2, ndays);
......@@ -974,14 +1060,22 @@ void *EcaCwd(void *process)
char cwd_name2[1024];
cdoInitialize(process);
cdoOperatorAdd("eca_cwd", 0, 31, nullptr);
if ( operatorArgc() > 2 ) cdoAbort("Too many arguments!");
if ( operatorArgc() > 3 ) cdoAbort("Too many arguments!");
else if ( operatorArgc() > 2 )
{
auto params = cdoGetOperArgv();
params = std::vector<std::string>(params.begin() + 2, params.end());
addWithFrequency(params, "eca_cwd");
}
else if ( operatorArgc() > 0 )
{
threshold = parameter2double(cdoOperatorArgv(0));
if ( operatorArgc() == 2 ) ndays = parameter2int(cdoOperatorArgv(1));
cdoOperatorAdd("eca_cwd", 0, 31, nullptr);
}
else
cdoOperatorAdd("eca_cwd", 0, 31, nullptr);
sprintf(cwd_longname, CWD_LONGNAME, threshold);
sprintf(cwd_longname2, CWD_LONGNAME2, ndays);
......@@ -1021,10 +1115,26 @@ void *EcaPd(void *process)
cdoInitialize(process);
int datelenOp = 31;
if ( operatorArgc() > 0 )
{
auto params = cdoGetOperArgv();
KVList kvlist;
if (kvlist.parseArguments(operatorArgc(), params) != 0) cdoAbort("Argument parse error!");
auto kv = kvlist.search("freq");
if (kv && kv->nvalues > 0 )
{
if ( kv->values[0].compare("month") == 0 )
datelenOp = 8;
else if ( kv->values[0].compare("year") == 0 )
datelenOp = 10;
}
}
// clang-format off
const auto ECA_PD = cdoOperatorAdd("eca_pd", 0, 31, nullptr);
const auto ECA_R10MM = cdoOperatorAdd("eca_r10mm", 0, 31, nullptr);
const auto ECA_R20MM = cdoOperatorAdd("eca_r20mm", 0, 31, nullptr);
const auto ECA_PD = cdoOperatorAdd("eca_pd", 0, datelenOp, nullptr);
const auto ECA_R10MM = cdoOperatorAdd("eca_r10mm", 0, datelenOp, nullptr);
const auto ECA_R20MM = cdoOperatorAdd("eca_r20mm", 0, datelenOp, nullptr);
// clang-format on
const auto operatorID = cdoOperatorID();
......@@ -1034,7 +1144,7 @@ void *EcaPd(void *process)
operatorInputArg("daily precipitation amount threshold in [mm]");
if (operatorArgc() < 1) cdoAbort("Too few arguments!");
if (operatorArgc() > 1) cdoAbort("Too many arguments!");
if (operatorArgc() > 2) cdoAbort("Too many arguments!");
threshold = parameter2double(cdoOperatorArgv(0));
......@@ -1298,8 +1408,18 @@ EcaRr1(void *process)
cdoInitialize(process);
cdoOperatorAdd("eca_rr1", 0, 31, nullptr);
if (operatorArgc() == 1) threshold = parameter2double(cdoOperatorArgv(0));
if (operatorArgc() > 1) cdoAbort("Too many arguments!");
if (operatorArgc() > 2) cdoAbort("Too many arguments!");
else if ( operatorArgc() > 1 )
{
auto params = cdoGetOperArgv();
params = std::vector<std::string>(params.begin() + 1, params.end());
addWithFrequency(params, "eca_rr1");
}
else
{
if (operatorArgc() == 1) threshold = parameter2double(cdoOperatorArgv(0));
cdoOperatorAdd("eca_rr1", 0, 31, nullptr);
}
sprintf(lnamebuffer, RR1_LONGNAME, threshold);
......@@ -1330,12 +1450,8 @@ EcaRx1day(void *process)
cdoInitialize(process);
if (operatorArgc() > 0)
{
if ('m' == cdoOperatorArgv(0)[0])
cdoOperatorAdd("eca_rx1day", 0, 8, nullptr); /* monthly mode */
else
cdoWarning("Parameter value '%s' is invalid. The only valid value is "
"'m' indicating monthly mode. Operating in yearly mode now.",
cdoOperatorArgv(0));
auto params = cdoGetOperArgv();
addWithFrequency(params, "eca_rx1day");
}
else
cdoOperatorAdd("eca_rx1day", 0, 31, nullptr);
......@@ -1365,13 +1481,24 @@ EcaRx5day(void *process)
ECA_REQUEST_1 request;
cdoInitialize(process);
if (operatorArgc() > 0) argX = parameter2double(cdoOperatorArgv(0));
if (operatorArgc() > 0)
{
argX = parameter2double(cdoOperatorArgv(0));
if (operatorArgc() > 1)
{
auto params = cdoGetOperArgv();
params = std::vector<std::string>(params.begin() + 1, params.end());
addWithFrequency(params, "eca_rx5day");
}
else
cdoOperatorAdd("eca_rx5day", 0, 31, nullptr);
}
else
cdoOperatorAdd("eca_rx5day", 0, 31, nullptr);
char *longname = (char *) Malloc(strlen(RX5DAY_LONGNAME2) + 40);
sprintf(longname, RX5DAY_LONGNAME2, argX);
cdoOperatorAdd("eca_rx5day", 0, 31, nullptr);
request.var1.name = RX5DAY_NAME;
request.var1.longname = RX5DAY_LONGNAME;
request.var1.units = RX5DAY_UNITS;
......@@ -1405,10 +1532,20 @@ EcaSdii(void *process)
double threshold = 1;
cdoInitialize(process);
cdoOperatorAdd("eca_sdii", 0, 31, nullptr);
if (operatorArgc() == 1) threshold = parameter2double(cdoOperatorArgv(0));
if (operatorArgc() > 1) cdoAbort("Too many arguments!");
if (operatorArgc() > 2) cdoAbort("Too many arguments!");
else if ( operatorArgc() > 1 )
{
auto params = cdoGetOperArgv();
params = std::vector<std::string>(params.begin() + 1, params.end());
addWithFrequency(params, "eca_sdii");
}
else
{
cdoOperatorAdd("eca_sdii", 0, 31, nullptr);
if (operatorArgc() == 1) threshold = parameter2double(cdoOperatorArgv(0));
}
sprintf(lnamebuffer, SDII_LONGNAME, threshold);
......@@ -1466,9 +1603,19 @@ Strwin(void *process)
ECA_REQUEST_1 request;
cdoInitialize(process);
cdoOperatorAdd("strwin", 0, 31, nullptr);
if (operatorArgc() > 0) maxWind = parameter2double(cdoOperatorArgv(0));
if (operatorArgc() > 2) cdoAbort("Too many arguments!");
else if ( operatorArgc() > 1 )
{
auto params = cdoGetOperArgv();
params = std::vector<std::string>(params.begin() + 1, params.end());
addWithFrequency(params, "strwin");
}
else
{
if (operatorArgc() > 0) maxWind = parameter2double(cdoOperatorArgv(0));
cdoOperatorAdd("strwin", 0, 31, nullptr);
}
char *longname = (char *) Malloc(strlen(STRWIN_LONGNAME) + 40);
sprintf(longname, STRWIN_LONGNAME, maxWind);
......@@ -1506,7 +1653,13 @@ Strbre(void *process)
ECA_REQUEST_1 request;
cdoInitialize(process);
cdoOperatorAdd("strbre", 0, 31, nullptr);
if ( operatorArgc() > 0 )
{
auto params = cdoGetOperArgv();
addWithFrequency(params, "strbre");
}
else
cdoOperatorAdd("strbre", 0, 31, nullptr);
request.var1.name = STRBRE_NAME;
request.var1.longname = STRBRE_LONGNAME;
......@@ -1539,7 +1692,13 @@ Strgal(void *process)
ECA_REQUEST_1 request;
cdoInitialize(process);
cdoOperatorAdd("strgal", 0, 31, nullptr);
if ( operatorArgc() > 0 )
{
auto params = cdoGetOperArgv();
addWithFrequency(params, "strgal");
}
else
cdoOperatorAdd("strgal", 0, 31, nullptr);
request.var1.name = STRBRE_NAME;
request.var1.longname = STRBRE_LONGNAME;
......@@ -1572,7 +1731,13 @@ Hurr(void *process)
ECA_REQUEST_1 request;
cdoInitialize(process);
cdoOperatorAdd("hurr", 0, 31, nullptr);
if ( operatorArgc() > 0 )
{
auto params = cdoGetOperArgv();
addWithFrequency(params, "hurr");
}
else
cdoOperatorAdd("hurr", 0, 31, nullptr);
request.var1.name = HURR_NAME;
request.var1.longname = HURR_LONGNAME;
......
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