Commit 60a1b827 authored by Uwe Schulzweida's avatar Uwe Schulzweida
Browse files

Replace defines by constexpr

parent e1e553c5
......@@ -26,26 +26,16 @@
#include <cdi.h>
#include "cdo_vlist.h"
#include "datetime.h"
#include "functs.h"
#include "process_int.h"
#include "cdo_vlist.h"
#define MAX_DOY 373
static int
getDayOfYearIndex(int64_t vdate)
{
int year, month, day;
cdiDecodeDate(vdate, &year, &month, &day);
const int dayoy = (month >= 1 && month <= 12) ? (month - 1) * 31 + day : 0;
if (dayoy < 0 || dayoy >= MAX_DOY) cdoAbort("Day of year %d out of range (date=%d)!", dayoy, vdate);
return dayoy;
}
void *
Ydayarith(void *process)
{
constexpr int MaxDays = 373;
int nrecs;
int varID, levelID;
......@@ -85,12 +75,14 @@ Ydayarith(void *process)
const auto streamID3 = cdoOpenWrite(2);
cdoDefVlist(streamID3, vlistID3);
FieldVector2D vars2[MAX_DOY];
FieldVector2D vars2[MaxDays];
int tsID = 0;
while ((nrecs = cdoStreamInqTimestep(streamID2, tsID)))
{
const auto dayoy = getDayOfYearIndex(taxisInqVdate(taxisID2));
const auto vdate = taxisInqVdate(taxisID2);
const auto dayoy = decodeDayOfYear(vdate);
if (dayoy < 0 || dayoy >= MaxDays) cdoAbort("Day of year %d out of range (date=%d)!", dayoy, vdate);
if (vars2[dayoy].size() > 0) cdoAbort("Day of year index %d already allocated (date=%d)!", dayoy);
fieldsFromVlist(vlistID2, vars2[dayoy], FIELD_VEC);
......@@ -109,7 +101,9 @@ Ydayarith(void *process)
tsID = 0;
while ((nrecs = cdoStreamInqTimestep(streamID1, tsID)))
{
const auto dayoy = getDayOfYearIndex(taxisInqVdate(taxisID1));
const auto vdate = taxisInqVdate(taxisID1);
const auto dayoy = decodeDayOfYear(vdate);
if (dayoy < 0 || dayoy >= MaxDays) cdoAbort("Day of year %d out of range (date=%d)!", dayoy, vdate);
if (vars2[dayoy].size() == 0) cdoAbort("Day of year index %d not found (date=%d)!", dayoy);
taxisCopyTimestep(taxisID3, taxisID1);
......
......@@ -24,31 +24,28 @@
#include <cdi.h>
#include "cdo_options.h"
#include "cdo_vlist.h"
#include "datetime.h"
#include "functs.h"
#include "process_int.h"
#include "cdo_vlist.h"
#include "param_conversion.h"
#include "percentiles_hist.h"
#include "percentiles.h"
constexpr int MAX_DAYS = 373;
int getmonthday(int64_t date);
void *
Ydaypctl(void *process)
{
constexpr int MaxDays = 373;
int varID;
int year, month, day;
int nrecs;
int levelID;
size_t nmiss;
int64_t vdates1[MAX_DAYS], vdates2[MAX_DAYS];
int vtimes1[MAX_DAYS];
long nsets[MAX_DAYS];
FieldVector2D vars1[MAX_DAYS];
HistogramSet hsets[MAX_DAYS];
int64_t vdates1[MaxDays], vdates2[MaxDays];
int vtimes1[MaxDays];
long nsets[MaxDays];
FieldVector2D vars1[MaxDays];
HistogramSet hsets[MaxDays];
cdoInitialize(process);
cdoOperatorAdd("ydaypctl", func_pctl, 0, nullptr);
......@@ -57,7 +54,7 @@ Ydaypctl(void *process)
const auto pn = parameter2double(cdoOperatorArgv(0));
percentile_check_number(pn);
for (int dayoy = 0; dayoy < MAX_DAYS; dayoy++) nsets[dayoy] = 0;
for (int dayoy = 0; dayoy < MaxDays; dayoy++) nsets[dayoy] = 0;
const auto streamID1 = cdoOpenRead(0);
const auto streamID2 = cdoOpenRead(1);
......@@ -107,10 +104,8 @@ Ydaypctl(void *process)
if (Options::cdoVerbose) cdoPrint("process timestep: %d %d %d", tsID + 1, vdate, vtime);
cdiDecodeDate(vdate, &year, &month, &day);
const int dayoy = (month >= 1 && month <= 12) ? (month - 1) * 31 + day : 0;
if (dayoy < 0 || dayoy >= MAX_DAYS) cdoAbort("Day %d out of range!", dayoy);
const auto dayoy = decodeDayOfYear(vdate);
if (dayoy < 0 || dayoy >= MaxDays) cdoAbort("Day %d out of range!", dayoy);
vdates2[dayoy] = vdate;
......@@ -155,10 +150,8 @@ Ydaypctl(void *process)
if (Options::cdoVerbose) cdoPrint("process timestep: %d %d %d", tsID + 1, vdate, vtime);
cdiDecodeDate(vdate, &year, &month, &day);
const int dayoy = (month >= 1 && month <= 12) ? (month - 1) * 31 + day : 0;
if (dayoy < 0 || dayoy >= MAX_DAYS) cdoAbort("Day %d out of range!", dayoy);
const auto dayoy = decodeDayOfYear(vdate);
if (dayoy < 0 || dayoy >= MaxDays) cdoAbort("Day %d out of range!", dayoy);
vdates1[dayoy] = vdate;
vtimes1[dayoy] = vtime;
......@@ -187,10 +180,10 @@ Ydaypctl(void *process)
}
int otsID = 0;
for (int dayoy = 0; dayoy < MAX_DAYS; dayoy++)
for (int dayoy = 0; dayoy < MaxDays; dayoy++)
if (nsets[dayoy])
{
if (getmonthday(vdates1[dayoy]) != getmonthday(vdates2[dayoy]))
if (decodeMonthAndDay(vdates1[dayoy]) != decodeMonthAndDay(vdates2[dayoy]))
cdoAbort("Verification dates for the day %d of %s and %s are different!", dayoy, cdoGetStreamName(0),
cdoGetStreamName(1));
......
......@@ -33,17 +33,17 @@
#include <cdi.h>
#include "cdo_options.h"
#include "datetime.h"
#include "functs.h"
#include "process_int.h"
#include "param_conversion.h"
#include "pmlist.h"
#define MAX_DOY 373
int yearMode = 0;
static void
set_parameter(void)
setParameter(void)
{
const auto pargc = operatorArgc();
if (pargc)
......@@ -90,17 +90,17 @@ addOperators(void)
void *
Ydaystat(void *process)
{
constexpr int MaxDays = 373;
int varID, levelID;
int year, month, day;
int nrecs;
int dayoy_nsets[MAX_DOY];
int64_t vdates[MAX_DOY];
int vtimes[MAX_DOY];
FieldVector2D vars1[MAX_DOY], vars2[MAX_DOY], samp1[MAX_DOY];
int dayoy_nsets[MaxDays];
int64_t vdates[MaxDays];
int vtimes[MaxDays];
FieldVector2D vars1[MaxDays], vars2[MaxDays], samp1[MaxDays];
cdoInitialize(process);
set_parameter();
setParameter();
addOperators();
......@@ -114,7 +114,7 @@ Ydaystat(void *process)
const int divisor = operfunc == func_std1 || operfunc == func_var1;
const bool lvars2 = lvarstd || lrange;
for (int dayoy = 0; dayoy < MAX_DOY; ++dayoy) dayoy_nsets[dayoy] = 0;
for (int dayoy = 0; dayoy < MaxDays; ++dayoy) dayoy_nsets[dayoy] = 0;
const auto streamID1 = cdoOpenRead(0);
......@@ -146,10 +146,8 @@ Ydaystat(void *process)
if (Options::cdoVerbose) cdoPrint("process timestep: %d %d %d", tsID + 1, vdate, vtime);
cdiDecodeDate(vdate, &year, &month, &day);
const int dayoy = (month >= 1 && month <= 12) ? (month - 1) * 31 + day : 0;
if (dayoy < 0 || dayoy >= MAX_DOY) cdoAbort("Day of year %d out of range (date=%d)!", dayoy, vdate);
const auto dayoy = decodeDayOfYear(vdate);
if (dayoy < 0 || dayoy >= MaxDays) cdoAbort("Day of year %d out of range (date=%d)!", dayoy, vdate);
vdates[dayoy] = vdate;
vtimes[dayoy] = vtime;
......@@ -242,14 +240,15 @@ Ydaystat(void *process)
// set the year to the minimum of years found on output timestep
if (yearMode)
{
int year, month, day;
int outyear = 1e9;
for (int dayoy = 0; dayoy < MAX_DOY; dayoy++)
for (int dayoy = 0; dayoy < MaxDays; dayoy++)
if (dayoy_nsets[dayoy])
{
cdiDecodeDate(vdates[dayoy], &year, &month, &day);
if (year < outyear) outyear = year;
}
for (int dayoy = 0; dayoy < MAX_DOY; dayoy++)
for (int dayoy = 0; dayoy < MaxDays; dayoy++)
if (dayoy_nsets[dayoy])
{
cdiDecodeDate(vdates[dayoy], &year, &month, &day);
......@@ -259,7 +258,7 @@ Ydaystat(void *process)
}
}
for (int dayoy = 0; dayoy < MAX_DOY; dayoy++)
for (int dayoy = 0; dayoy < MaxDays; dayoy++)
if (dayoy_nsets[dayoy])
{
const auto nsets = dayoy_nsets[dayoy];
......
......@@ -24,40 +24,30 @@
#include <cdi.h>
#include "cdo_options.h"
#include "cdo_vlist.h"
#include "datetime.h"
#include "functs.h"
#include "process_int.h"
#include "cdo_vlist.h"
#include "param_conversion.h"
#include "calendar.h"
#include "percentiles_hist.h"
#include "percentiles.h"
#include "datetime.h"
constexpr int MAX_DAYS = 373;
int
getmonthday(int64_t date)
{
int year, month, day;
cdiDecodeDate(date, &year, &month, &day);
return month * 100 + day;
}
void *
Ydrunpctl(void *process)
{
constexpr int MaxDays = 373;
int varID;
int nrecs;
int levelID;
int inp, its;
size_t nmiss;
int year, month, day;
int64_t vdates1[MAX_DAYS], vdates2[MAX_DAYS];
int vtimes1[MAX_DAYS] /*, vtimes2[MAX_DAYS]*/;
int nsets[MAX_DAYS];
FieldVector2D vars2[MAX_DAYS];
HistogramSet hsets[MAX_DAYS];
int64_t vdates1[MaxDays], vdates2[MaxDays];
int vtimes1[MaxDays] /*, vtimes2[MaxDays]*/;
int nsets[MaxDays];
FieldVector2D vars2[MaxDays];
HistogramSet hsets[MaxDays];
cdoInitialize(process);
cdoOperatorAdd("ydrunpctl", func_pctl, 0, nullptr);
......@@ -68,7 +58,7 @@ Ydrunpctl(void *process)
percentile_check_number(pn);
const auto ndates = parameter2int(cdoOperatorArgv(1));
for (int dayoy = 0; dayoy < MAX_DAYS; dayoy++) nsets[dayoy] = 0;
for (int dayoy = 0; dayoy < MaxDays; dayoy++) nsets[dayoy] = 0;
const auto streamID1 = cdoOpenRead(0);
const auto streamID2 = cdoOpenRead(1);
......@@ -125,10 +115,8 @@ Ydrunpctl(void *process)
if (Options::cdoVerbose) cdoPrint("process timestep: %d %d %d", tsID + 1, vdate, vtime);
cdiDecodeDate(vdate, &year, &month, &day);
const int dayoy = (month >= 1 && month <= 12) ? (month - 1) * 31 + day : 0;
if (dayoy < 0 || dayoy >= MAX_DAYS) cdoAbort("Day %d out of range!", dayoy);
const auto dayoy = decodeDayOfYear(vdate);
if (dayoy < 0 || dayoy >= MaxDays) cdoAbort("Day %d out of range!", dayoy);
vdates2[dayoy] = vdate;
// vtimes2[dayoy] = vtime;
......@@ -197,10 +185,8 @@ Ydrunpctl(void *process)
const auto vdate = datetime[ndates].date;
const auto vtime = datetime[ndates].time;
cdiDecodeDate(vdate, &year, &month, &day);
const int dayoy = (month >= 1 && month <= 12) ? (month - 1) * 31 + day : 0;
if (dayoy < 0 || dayoy >= MAX_DAYS) cdoAbort("Day %d out of range!", dayoy);
const auto dayoy = decodeDayOfYear(vdate);
if (dayoy < 0 || dayoy >= MaxDays) cdoAbort("Day %d out of range!", dayoy);
vdates1[dayoy] = vdate;
vtimes1[dayoy] = vtime;
......@@ -244,7 +230,7 @@ Ydrunpctl(void *process)
}
/*
int outyear = 1e9;
for ( dayoy = 0; dayoy < MAX_DAYS; dayoy++ )
for ( dayoy = 0; dayoy < MaxDays; dayoy++ )
if ( nsets[dayoy] )
{
int year, month, day;
......@@ -252,7 +238,7 @@ Ydrunpctl(void *process)
if ( year < outyear ) outyear = year;
}
for ( dayoy = 0; dayoy < MAX_DAYS; dayoy++ )
for ( dayoy = 0; dayoy < MaxDays; dayoy++ )
if ( nsets[dayoy] )
{
int year, month, day;
......@@ -261,10 +247,10 @@ Ydrunpctl(void *process)
}
*/
int otsID = 0;
for (int dayoy = 0; dayoy < MAX_DAYS; dayoy++)
for (int dayoy = 0; dayoy < MaxDays; dayoy++)
if (nsets[dayoy])
{
if (getmonthday(vdates1[dayoy]) != getmonthday(vdates2[dayoy]))
if (decodeMonthAndDay(vdates1[dayoy]) != decodeMonthAndDay(vdates2[dayoy]))
cdoAbort("Verification dates for day %d of %s, %s and %s are different!", dayoy, cdoGetStreamName(0),
cdoGetStreamName(1));
......
......@@ -38,21 +38,21 @@
#include "datetime.h"
constexpr int MAX_DAYS = 373;
constexpr int MaxDays = 373;
class YDAY_STATS
{
public:
int64_t vdate[MAX_DAYS];
int vtime[MAX_DAYS];
FieldVector2D vars1[MAX_DAYS];
FieldVector2D vars2[MAX_DAYS];
int nsets[MAX_DAYS];
int64_t vdate[MaxDays];
int vtime[MaxDays];
FieldVector2D vars1[MaxDays];
FieldVector2D vars2[MaxDays];
int nsets[MaxDays];
int vlist;
YDAY_STATS(int vlistID) : vlist(vlistID)
{
for (int dayoy = 0; dayoy < MAX_DAYS; dayoy++)
for (int dayoy = 0; dayoy < MaxDays; dayoy++)
{
vdate[dayoy] = 0;
vtime[dayoy] = 0;
......@@ -69,11 +69,8 @@ ydstatUpdate(YDAY_STATS &stats, int64_t vdate, int vtime, const FieldVector2D &v
const auto nvars = vlistNvars(stats.vlist);
int year, month, day;
cdiDecodeDate(vdate, &year, &month, &day);
const int dayoy = (month >= 1 && month <= 12) ? (month - 1) * 31 + day : 0;
if (dayoy < 0 || dayoy >= MAX_DAYS) cdoAbort("day %d out of range!", dayoy);
const auto dayoy = decodeDayOfYear(vdate);
if (dayoy < 0 || dayoy >= MaxDays) cdoAbort("Day %d out of range!", dayoy);
stats.vdate[dayoy] = vdate;
stats.vtime[dayoy] = vtime;
......@@ -128,7 +125,7 @@ ydstatFinalize(YDAY_STATS &stats, int operfunc)
const auto nvars = vlistNvars(stats.vlist);
for (int dayoy = 0; dayoy < MAX_DAYS; dayoy++)
for (int dayoy = 0; dayoy < MaxDays; dayoy++)
if (stats.nsets[dayoy])
{
switch (operfunc)
......@@ -333,7 +330,7 @@ Ydrunstat(void *process)
int otsID = 0;
for (int dayoy = 0; dayoy < MAX_DAYS; dayoy++)
for (int dayoy = 0; dayoy < MaxDays; dayoy++)
if (stats.nsets[dayoy])
{
taxisDefVdate(taxisID2, stats.vdate[dayoy]);
......
......@@ -26,26 +26,21 @@
#include <cdi.h>
#include "cdo_vlist.h"
#include "datetime.h"
#include "functs.h"
#include "process_int.h"
#include "cdo_vlist.h"
#include "printinfo.h"
#define MAX_HOUR 9301 /* 31*12*25 + 1 */
constexpr int MaxHours = 9301; // 31*12*25 + 1
static int
getHourOfYearIndex(int64_t vdate, int vtime)
{
int year, month, day;
int hour, minute, second;
cdiDecodeDate(vdate, &year, &month, &day);
cdiDecodeTime(vtime, &hour, &minute, &second);
int houroy = 0;
if (month >= 1 && month <= 12 && day >= 1 && day <= 31 && hour >= 0 && hour < 24)
houroy = ((month - 1) * 31 + day - 1) * 25 + hour + 1;
const auto houroy = decodeHourOfYear(vdate, vtime);
if (houroy < 0 || houroy >= MAX_HOUR)
if (houroy < 0 || houroy >= MaxHours)
cdoAbort("Hour of year %d out of range (%s %s)!", houroy, dateToString(vdate).c_str(), timeToString(vtime).c_str());
return houroy;
......@@ -93,12 +88,12 @@ Yhourarith(void *process)
const auto streamID3 = cdoOpenWrite(2);
cdoDefVlist(streamID3, vlistID3);
FieldVector2D vars2[MAX_HOUR];
FieldVector2D vars2[MaxHours];
int tsID = 0;
while ((nrecs = cdoStreamInqTimestep(streamID2, tsID)))
{
const int houroy = getHourOfYearIndex(taxisInqVdate(taxisID2), taxisInqVtime(taxisID2));
const auto houroy = getHourOfYearIndex(taxisInqVdate(taxisID2), taxisInqVtime(taxisID2));
if (vars2[houroy].size() > 0) cdoAbort("Hour of year index %d already allocated!", houroy);
fieldsFromVlist(vlistID2, vars2[houroy], FIELD_VEC);
......
......@@ -44,39 +44,11 @@
#include <cdi.h>
#include "cdo_options.h"
#include "datetime.h"
#include "functs.h"
#include "process_int.h"
#include "datetime.h"
#include "printinfo.h"
static int
hour_of_year(int64_t vdate, int vtime)
{
int year, month, day;
int hour, minute, second;
cdiDecodeDate(vdate, &year, &month, &day);
cdiDecodeTime(vtime, &hour, &minute, &second);
int houroy = 0;
if (month >= 1 && month <= 12 && day >= 1 && day <= 31 && hour >= 0 && hour < 24)
houroy = ((month - 1) * 31 + day - 1) * 25 + hour + 1;
return houroy;
}
static int
hour_of_day(int64_t vdate, int vtime)
{
int year, month, day;
int hour, minute, second;
cdiDecodeDate(vdate, &year, &month, &day);
cdiDecodeTime(vtime, &hour, &minute, &second);
int hourod = 0;
if (month >= 1 && month <= 12 && day >= 1 && day <= 31 && hour >= 0 && hour < 24) hourod = hour + 1;
return hourod;
}
static void
addOperators(void)
......@@ -139,12 +111,12 @@ Yhourstat(void *process)
taxisWithBounds(taxisID2);
if (taxisInqType(taxisID2) == TAXIS_FORECAST) taxisDefType(taxisID2, TAXIS_RELATIVE);
const int maxHours = ldaily ? 25 : 9301; // year: 31*12*25 + 1
std::vector<int> hourot_nsets(maxHours, 0); // hour of time
FieldVector3D vars1(maxHours), vars2(maxHours), samp1(maxHours);
const int MaxHours = ldaily ? 25 : 9301; // year: 31*12*25 + 1
std::vector<int> hourot_nsets(MaxHours, 0); // hour of time
FieldVector3D vars1(MaxHours), vars2(MaxHours), samp1(MaxHours);
std::vector<DateTimeList> dtlist(maxHours);
for (int hourot = 0; hourot < maxHours; ++hourot)
std::vector<DateTimeList> dtlist(MaxHours);
for (int hourot = 0; hourot < MaxHours; ++hourot)
{
dtlist[hourot].setStat(timestat_date);
dtlist[hourot].setCalendar(taxisInqCalendar(taxisID1));
......@@ -172,8 +144,8 @@ Yhourstat(void *process)
if (Options::cdoVerbose) cdoPrint("process timestep: %d %d %d", tsID + 1, vdate, vtime);
const auto hourot = ldaily ? hour_of_day(vdate, vtime) : hour_of_year(vdate, vtime);
if (hourot < 0 || hourot >= maxHours)
const auto hourot = ldaily ? decodeHourOfDay(vdate, vtime) : decodeHourOfYear(vdate, vtime);
if (hourot < 0 || hourot >= MaxHours)
cdoAbort("Hour of year %d out of range (%s %s)!", hourot, dateToString(vdate).c_str(), timeToString(vtime).c_str());
dtlist[hourot].taxisInqTimestep(taxisID1, hourot_nsets[hourot]);
......@@ -264,7 +236,7 @@ Yhourstat(void *process)
tsID++;
}
for (int hourot = 0; hourot < maxHours; ++hourot)
for (int hourot = 0; hourot < MaxHours; ++hourot)
if (hourot_nsets[hourot])
{
const int nsets = hourot_nsets[hourot];
......
......@@ -30,19 +30,19 @@
#include <cdi.h>
#include "functs.h"
#include "process_int.h"
#include "cdo_vlist.h"
#include "cdo_season.h"
#include "functs.h"
#include "process_int.h"
#define MAX_MON 12
constexpr int MaxMonths = 12;
static int
getMonthIndex(const int64_t vdate)
{
int year, mon, day;
cdiDecodeDate(vdate, &year, &mon, &day);
if (mon < 1 || mon > MAX_MON) cdoAbort("Month %d out of range!", mon);
if (mon < 1 || mon > MaxMonths) cdoAbort("Month %d out of range!", mon);
mon--;
return mon;
}
......@@ -129,7 +129,7 @@ Ymonarith(void *process)
if (opertype == SEASONAL) get_season_name(seas_name);
FieldVector2D vars2[MAX_MON];
FieldVector2D vars2[MaxMonths];
int tsID = 0;
while ((nrecs = cdoStreamInqTimestep(streamID2, tsID)))
......
......@@ -24,36 +24,28 @@
#include <cdi.h>
#include "cdo_options.h"
#include "cdo_vlist.h"
#include "datetime.h"
#include "functs.h"
#include "process_int.h"
#include "cdo_vlist.h"
#include "param_conversion.h"
#include "percentiles_hist.h"
#include "percentiles.h"
#define NMONTH 17
static int
getmonth(int64_t date)
{
int year, month, day;
cdiDecodeDate(date, &year, &month, &day);
return month;
}
void *
Ymonpctl(void *process)
{
constexpr int MaxMonths = 17;
int varID;
int year, month, day;
int levelID;
size_t nmiss;
int nrecs;
int64_t vdates1[NMONTH], vdates2[NMONTH];
int vtimes1[NMONTH];
long nsets[NMONTH];
FieldVector2D vars1[NMONTH];
HistogramSet hsets[NMONTH];
int64_t vdates1[MaxMonths], vdates2[MaxMonths];
int vtimes1[MaxMonths];
long nsets[MaxMonths];
FieldVector2D vars1[MaxMonths];
HistogramSet hsets[MaxMonths];
cdoInitialize(process);
cdoOperatorAdd("ymonpctl", func_pctl, 0, nullptr);
......@@ -62,7 +54,7 @@ Ymonpctl(void *process)
const auto pn = parameter2double(cdoOperatorArgv(0));
percentile_check_number(pn);
for (month = 0; month < NMONTH; month++) nsets[month] = 0;
for (int month = 0; month < MaxMonths; month++) nsets[month] = 0;
const auto streamID1 = cdoOpenRead(0);
const auto streamID2 = cdoOpenRead(1);
......@@ -112,8 +104,8 @@ Ymonpctl(void *process)