Commit 78fa8c30 authored by Uwe Schulzweida's avatar Uwe Schulzweida
Browse files

Set constant variables to const.

parent c389672b
......@@ -291,10 +291,7 @@ void *EcaCfd(void *process)
cdoOperatorAdd("eca_cfd", 0, 31, nullptr);
if ( operatorArgc() > 1 ) cdoAbort("Too many arguments!");
else if ( operatorArgc() > 0 )
{
ndays = parameter2int(operatorArgv()[0]);
}
if ( operatorArgc() > 0 ) ndays = parameter2int(operatorArgv()[0]);
sprintf(cfd_longname2, CFD_LONGNAME2, ndays);
sprintf(cfd_name2, CFD_NAME2, ndays);
......@@ -416,7 +413,6 @@ void *EcaCwdi(void *process)
void *EcaCwfi(void *process)
{
char *longname;
int argN = 6;
ECA_REQUEST_2 request;
......@@ -425,7 +421,7 @@ void *EcaCwfi(void *process)
if ( operatorArgc() > 0 ) argN = parameter2int(operatorArgv()[0]);
longname = (char*) Malloc(strlen(CWFI_LONGNAME) + 40);
char *longname = (char*) Malloc(strlen(CWFI_LONGNAME) + 40);
sprintf(longname, CWFI_LONGNAME, argN);
request.var1.name = CWFI_NAME;
......@@ -593,7 +589,6 @@ void *EcaHd(void *process)
void *EcaHwdi(void *process)
{
char *longname;
int argN = 6;
double argT = 5.0;
ECA_REQUEST_2 request;
......@@ -604,7 +599,7 @@ void *EcaHwdi(void *process)
if ( operatorArgc() > 0 ) argN = parameter2int(operatorArgv()[0]);
if ( operatorArgc() > 1 ) argT = parameter2double(operatorArgv()[1]);
longname = (char*) Malloc(strlen(HWDI_LONGNAME) + 80);
char *longname = (char*) Malloc(strlen(HWDI_LONGNAME) + 80);
sprintf(longname, HWDI_LONGNAME, argN, argT);
request.var1.name = HWDI_NAME;
......@@ -636,7 +631,6 @@ void *EcaHwdi(void *process)
void *EcaHwfi(void *process)
{
char *longname;
int argN = 6;
ECA_REQUEST_2 request;
......@@ -645,7 +639,7 @@ void *EcaHwfi(void *process)
if ( operatorArgc() > 0 ) argN = parameter2int(operatorArgv()[0]);
longname = (char*) Malloc(strlen(HWFI_LONGNAME) + 40);
char *longname = (char*) Malloc(strlen(HWFI_LONGNAME) + 40);
sprintf(longname, HWFI_LONGNAME, argN);
request.var1.name = HWFI_NAME;
......@@ -703,7 +697,6 @@ void *EcaId(void *process)
void *EcaSu(void *process)
{
char *longname;
double argT = 25.0;
ECA_REQUEST_1 request;
......@@ -711,7 +704,7 @@ void *EcaSu(void *process)
cdoOperatorAdd("eca_su", 0, 31, nullptr);
if ( operatorArgc() > 0 ) argT = parameter2double(operatorArgv()[0]);
longname = (char*) Malloc(strlen(SU_LONGNAME) + 40);
char *longname = (char*) Malloc(strlen(SU_LONGNAME) + 40);
sprintf(longname, SU_LONGNAME, argT);
request.var1.name = SU_NAME;
......@@ -1023,8 +1016,6 @@ void *EcaCwd(void *process)
void *EcaPd(void *process)
{
int ECA_PD, ECA_R10MM, ECA_R20MM;
int operatorID;
char lnamebuffer[1024];
double threshold = 0;
ECA_REQUEST_1 request;
......@@ -1032,12 +1023,12 @@ void *EcaPd(void *process)
cdoInitialize(process);
// clang-format off
ECA_PD = cdoOperatorAdd("eca_pd", 0, 31, nullptr);
ECA_R10MM = cdoOperatorAdd("eca_r10mm", 0, 31, nullptr);
ECA_R20MM = cdoOperatorAdd("eca_r20mm", 0, 31, nullptr);
const int ECA_PD = cdoOperatorAdd("eca_pd", 0, 31, nullptr);
const int ECA_R10MM = cdoOperatorAdd("eca_r10mm", 0, 31, nullptr);
const int ECA_R20MM = cdoOperatorAdd("eca_r20mm", 0, 31, nullptr);
// clang-format on
operatorID = cdoOperatorID();
const int operatorID = cdoOperatorID();
if (operatorID == ECA_PD)
{
......@@ -1371,14 +1362,13 @@ EcaRx1day(void *process)
void *
EcaRx5day(void *process)
{
char *longname;
double argX = 50.0;
ECA_REQUEST_1 request;
cdoInitialize(process);
if (operatorArgc() > 0) argX = parameter2double(operatorArgv()[0]);
longname = (char *) Malloc(strlen(RX5DAY_LONGNAME2) + 40);
char *longname = (char *) Malloc(strlen(RX5DAY_LONGNAME2) + 40);
sprintf(longname, RX5DAY_LONGNAME2, argX);
cdoOperatorAdd("eca_rx5day", 0, 31, nullptr);
......@@ -1473,7 +1463,6 @@ Fdns(void *process)
void *
Strwin(void *process)
{
char *longname;
double maxWind = 10.5;
ECA_REQUEST_1 request;
......@@ -1482,7 +1471,7 @@ Strwin(void *process)
if (operatorArgc() > 0) maxWind = parameter2double(operatorArgv()[0]);
longname = (char *) Malloc(strlen(STRWIN_LONGNAME) + 40);
char *longname = (char *) Malloc(strlen(STRWIN_LONGNAME) + 40);
sprintf(longname, STRWIN_LONGNAME, maxWind);
request.var1.name = STRWIN_NAME;
......
......@@ -40,30 +40,25 @@ eca1(const ECA_REQUEST_1 *request)
const int operatorID = cdoOperatorID();
size_t nmiss;
int cmplen;
char indate1[DATE_LEN + 1], indate2[DATE_LEN + 1];
int64_t ivdate = 0, ovdate = 0;
int ivtime = 0, ovtime = 0;
int nrecs;
int gridID, zaxisID, varID, levelID;
int varID, levelID;
int itsID;
int otsID;
long nsets;
int istreamID, ostreamID;
int ivlistID, ovlistID, itaxisID, otaxisID;
int nlevels;
double missval;
cmplen = DATE_LEN - cdoOperatorF2(operatorID);
const int cmplen = DATE_LEN - cdoOperatorF2(operatorID);
istreamID = cdoStreamOpenRead(cdoStreamName(0));
const int istreamID = cdoStreamOpenRead(cdoStreamName(0));
ivlistID = cdoStreamInqVlist(istreamID);
ovlistID = vlistCreate();
const int ivlistID = cdoStreamInqVlist(istreamID);
const int ovlistID = vlistCreate();
gridID = vlistInqVarGrid(ivlistID, FIRST_VAR_ID);
zaxisID = vlistInqVarZaxis(ivlistID, FIRST_VAR_ID);
missval = vlistInqVarMissval(ivlistID, FIRST_VAR_ID);
const int gridID = vlistInqVarGrid(ivlistID, FIRST_VAR_ID);
const int zaxisID = vlistInqVarZaxis(ivlistID, FIRST_VAR_ID);
const double missval = vlistInqVarMissval(ivlistID, FIRST_VAR_ID);
varID = vlistDefVar(ovlistID, gridID, zaxisID, TIME_VARYING);
......@@ -86,8 +81,8 @@ eca1(const ECA_REQUEST_1 *request)
if (cdoOperatorF2(operatorID) == 16) vlistDefNtsteps(ovlistID, 1);
itaxisID = vlistInqTaxis(ivlistID);
otaxisID = cdoTaxisCreate(TAXIS_RELATIVE);
const int itaxisID = vlistInqTaxis(ivlistID);
const int otaxisID = cdoTaxisCreate(TAXIS_RELATIVE);
taxisDefTunit(otaxisID, TUNIT_MINUTE);
// taxisDefCalendar(otaxisID, CALENDAR_PROLEPTIC);
taxisDefCalendar(otaxisID, taxisInqCalendar(itaxisID));
......@@ -95,17 +90,17 @@ eca1(const ECA_REQUEST_1 *request)
taxisDefRtime(otaxisID, 0);
vlistDefTaxis(ovlistID, otaxisID);
ostreamID = cdoStreamOpenWrite(cdoStreamName(1));
const int ostreamID = cdoStreamOpenWrite(cdoStreamName(1));
cdoDefVlist(ostreamID, ovlistID);
size_t gridsize = gridInqSize(gridID);
const size_t gridsize = gridInqSize(gridID);
Field field1, field2;
field1.ptr = (double *) Malloc(gridsize * sizeof(double));
if (IS_SET(request->var2.h2) || IS_SET(request->var2.h3))
field2.ptr = (double *) Malloc(gridsize * sizeof(double));
nlevels = zaxisInqSize(zaxisID);
const int nlevels = zaxisInqSize(zaxisID);
FieldVector var12(nlevels), samp1(nlevels), samp2(nlevels);
FieldVector var13, var21, var23;
......@@ -327,35 +322,30 @@ eca2(const ECA_REQUEST_2 *request)
const int operatorID = cdoOperatorID();
size_t nmiss;
int cmplen;
char indate1[DATE_LEN + 1], indate2[DATE_LEN + 1];
int64_t ivdate = 0, ovdate = 0;
int ivtime = 0, ovtime = 0;
int nrecs;
int gridID, zaxisID, varID, levelID;
int varID, levelID;
int itsID;
int otsID;
long nsets;
int istreamID1, istreamID2, ostreamID;
int ivlistID1, ivlistID2, ovlistID, itaxisID1, otaxisID;
int nlevels;
double missval1, missval2;
cmplen = DATE_LEN - cdoOperatorF2(operatorID);
const int cmplen = DATE_LEN - cdoOperatorF2(operatorID);
istreamID1 = cdoStreamOpenRead(cdoStreamName(0));
istreamID2 = cdoStreamOpenRead(cdoStreamName(1));
const int istreamID1 = cdoStreamOpenRead(cdoStreamName(0));
const int istreamID2 = cdoStreamOpenRead(cdoStreamName(1));
ivlistID1 = cdoStreamInqVlist(istreamID1);
ivlistID2 = cdoStreamInqVlist(istreamID2);
ovlistID = vlistCreate();
const int ivlistID1 = cdoStreamInqVlist(istreamID1);
const int ivlistID2 = cdoStreamInqVlist(istreamID2);
const int ovlistID = vlistCreate();
vlistCompare(ivlistID1, ivlistID2, CMP_ALL);
gridID = vlistInqVarGrid(ivlistID1, FIRST_VAR_ID);
zaxisID = vlistInqVarZaxis(ivlistID1, FIRST_VAR_ID);
missval1 = vlistInqVarMissval(ivlistID1, FIRST_VAR_ID);
missval2 = vlistInqVarMissval(ivlistID2, FIRST_VAR_ID);
const int gridID = vlistInqVarGrid(ivlistID1, FIRST_VAR_ID);
const int zaxisID = vlistInqVarZaxis(ivlistID1, FIRST_VAR_ID);
const double missval1 = vlistInqVarMissval(ivlistID1, FIRST_VAR_ID);
const double missval2 = vlistInqVarMissval(ivlistID2, FIRST_VAR_ID);
varID = vlistDefVar(ovlistID, gridID, zaxisID, TIME_VARYING);
......@@ -378,8 +368,8 @@ eca2(const ECA_REQUEST_2 *request)
if (cdoOperatorF2(operatorID) == 16) vlistDefNtsteps(ovlistID, 1);
itaxisID1 = vlistInqTaxis(ivlistID1);
otaxisID = cdoTaxisCreate(TAXIS_RELATIVE);
const int itaxisID1 = vlistInqTaxis(ivlistID1);
const int otaxisID = cdoTaxisCreate(TAXIS_RELATIVE);
taxisDefTunit(otaxisID, TUNIT_MINUTE);
// taxisDefCalendar(otaxisID, CALENDAR_PROLEPTIC);
taxisDefCalendar(otaxisID, taxisInqCalendar(itaxisID1));
......@@ -387,16 +377,16 @@ eca2(const ECA_REQUEST_2 *request)
taxisDefRtime(otaxisID, 0);
vlistDefTaxis(ovlistID, otaxisID);
ostreamID = cdoStreamOpenWrite(cdoStreamName(2));
const int ostreamID = cdoStreamOpenWrite(cdoStreamName(2));
cdoDefVlist(ostreamID, ovlistID);
size_t gridsize = gridInqSize(gridID);
const size_t gridsize = gridInqSize(gridID);
Field field1, field2;
field1.ptr = (double *) Malloc(gridsize * sizeof(double));
field2.ptr = (double *) Malloc(gridsize * sizeof(double));
nlevels = zaxisInqSize(zaxisID);
const int nlevels = zaxisInqSize(zaxisID);
FieldVector var14(nlevels), samp1(nlevels), samp2(nlevels), samp3(nlevels);
FieldVector total, var15, var22;
......@@ -627,36 +617,31 @@ eca3(const ECA_REQUEST_3 *request)
const int operatorID = cdoOperatorID();
size_t nmiss;
int cmplen;
char indate1[DATE_LEN + 1], indate2[DATE_LEN + 1];
int64_t ivdate1 = 0, ivdate2 = 0;
int ivtime1 = 0, ivtime2 = 0;
int64_t ovdate = 0;
int ovtime = 0;
int nrecs;
int gridID, zaxisID, varID, levelID;
int varID, levelID;
int itsID;
int otsID;
long nsets;
int istreamID1, istreamID2, ostreamID;
int ivlistID1, ivlistID2, ovlistID, itaxisID1, itaxisID2, otaxisID;
int nlevels;
double missval;
cmplen = DATE_LEN - cdoOperatorF2(operatorID);
const int cmplen = DATE_LEN - cdoOperatorF2(operatorID);
istreamID1 = cdoStreamOpenRead(cdoStreamName(0));
istreamID2 = cdoStreamOpenRead(cdoStreamName(1));
const int istreamID1 = cdoStreamOpenRead(cdoStreamName(0));
const int istreamID2 = cdoStreamOpenRead(cdoStreamName(1));
ivlistID1 = cdoStreamInqVlist(istreamID1);
ivlistID2 = cdoStreamInqVlist(istreamID2);
ovlistID = vlistCreate();
const int ivlistID1 = cdoStreamInqVlist(istreamID1);
const int ivlistID2 = cdoStreamInqVlist(istreamID2);
const int ovlistID = vlistCreate();
vlistCompare(ivlistID1, ivlistID2, CMP_ALL);
gridID = vlistInqVarGrid(ivlistID1, FIRST_VAR_ID);
zaxisID = vlistInqVarZaxis(ivlistID1, FIRST_VAR_ID);
missval = vlistInqVarMissval(ivlistID1, FIRST_VAR_ID);
const int gridID = vlistInqVarGrid(ivlistID1, FIRST_VAR_ID);
const int zaxisID = vlistInqVarZaxis(ivlistID1, FIRST_VAR_ID);
const double missval = vlistInqVarMissval(ivlistID1, FIRST_VAR_ID);
varID = vlistDefVar(ovlistID, gridID, zaxisID, TIME_VARYING);
......@@ -668,9 +653,9 @@ eca3(const ECA_REQUEST_3 *request)
if (cdoOperatorF2(operatorID) == 16) vlistDefNtsteps(ovlistID, 1);
itaxisID1 = vlistInqTaxis(ivlistID1);
itaxisID2 = vlistInqTaxis(ivlistID2);
otaxisID = cdoTaxisCreate(TAXIS_RELATIVE);
const int itaxisID1 = vlistInqTaxis(ivlistID1);
const int itaxisID2 = vlistInqTaxis(ivlistID2);
const int otaxisID = cdoTaxisCreate(TAXIS_RELATIVE);
taxisDefTunit(otaxisID, TUNIT_MINUTE);
// taxisDefCalendar(otaxisID, CALENDAR_PROLEPTIC);
taxisDefCalendar(otaxisID, taxisInqCalendar(itaxisID1));
......@@ -678,16 +663,16 @@ eca3(const ECA_REQUEST_3 *request)
taxisDefRtime(otaxisID, 0);
vlistDefTaxis(ovlistID, otaxisID);
ostreamID = cdoStreamOpenWrite(cdoStreamName(2));
const int ostreamID = cdoStreamOpenWrite(cdoStreamName(2));
cdoDefVlist(ostreamID, ovlistID);
size_t gridsize = gridInqSize(gridID);
const size_t gridsize = gridInqSize(gridID);
Field field1, field2;
field1.ptr = (double *) Malloc(gridsize * sizeof(double));
field2.ptr = (double *) Malloc(gridsize * sizeof(double));
nlevels = zaxisInqSize(zaxisID);
const int nlevels = zaxisInqSize(zaxisID);
FieldVector var1(nlevels), var2(nlevels);
......@@ -824,21 +809,21 @@ eca4(const ECA_REQUEST_4 *request)
int ivtime = 0, ovtime = 0;
char indate1[DATE_LEN + 1], indate2[DATE_LEN + 1];
int cmplen = DATE_LEN - cdoOperatorF2(operatorID);
const int cmplen = DATE_LEN - cdoOperatorF2(operatorID);
int istreamID1 = cdoStreamOpenRead(cdoStreamName(0));
int istreamID2 = cdoStreamOpenRead(cdoStreamName(1));
const int istreamID1 = cdoStreamOpenRead(cdoStreamName(0));
const int istreamID2 = cdoStreamOpenRead(cdoStreamName(1));
int ivlistID1 = cdoStreamInqVlist(istreamID1);
int ivlistID2 = cdoStreamInqVlist(istreamID2);
int ovlistID = vlistCreate();
const int ivlistID1 = cdoStreamInqVlist(istreamID1);
const int ivlistID2 = cdoStreamInqVlist(istreamID2);
const int ovlistID = vlistCreate();
int gridID = vlistInqVarGrid(ivlistID1, FIRST_VAR_ID);
if (gridInqSize(gridID) != gridInqSize(vlistInqVarGrid(ivlistID2, FIRST_VAR_ID)))
cdoAbort("Grid sizes of the input fields do not match!");
int zaxisID = vlistInqVarZaxis(ivlistID1, FIRST_VAR_ID);
double missval = vlistInqVarMissval(ivlistID1, FIRST_VAR_ID);
const int zaxisID = vlistInqVarZaxis(ivlistID1, FIRST_VAR_ID);
const double missval = vlistInqVarMissval(ivlistID1, FIRST_VAR_ID);
int ovarID1 = vlistDefVar(ovlistID, gridID, zaxisID, TIME_VARYING);
......@@ -858,8 +843,8 @@ eca4(const ECA_REQUEST_4 *request)
if (cdoOperatorF2(operatorID) == 16) vlistDefNtsteps(ovlistID, 1);
int itaxisID = vlistInqTaxis(ivlistID1);
int otaxisID = cdoTaxisCreate(TAXIS_RELATIVE);
const int itaxisID = vlistInqTaxis(ivlistID1);
const int otaxisID = cdoTaxisCreate(TAXIS_RELATIVE);
taxisDefTunit(otaxisID, TUNIT_MINUTE);
// taxisDefCalendar(otaxisID, CALENDAR_PROLEPTIC);
taxisDefCalendar(otaxisID, taxisInqCalendar(itaxisID));
......@@ -867,11 +852,11 @@ eca4(const ECA_REQUEST_4 *request)
taxisDefRtime(otaxisID, 0);
vlistDefTaxis(ovlistID, otaxisID);
int ostreamID = cdoStreamOpenWrite(cdoStreamName(2));
const int ostreamID = cdoStreamOpenWrite(cdoStreamName(2));
cdoDefVlist(ostreamID, ovlistID);
bool lyvals = true;
int gridtype = gridInqType(gridID);
const int gridtype = gridInqType(gridID);
if (gridtype == GRID_LONLAT || gridtype == GRID_GAUSSIAN || gridtype == GRID_PROJECTION)
{
gridID = gridToCurvilinear(gridID, 1);
......@@ -884,7 +869,8 @@ eca4(const ECA_REQUEST_4 *request)
{
lyvals = false;
}
size_t gridsize = gridInqSize(gridID);
const size_t gridsize = gridInqSize(gridID);
// for later check on northern\southern hemisphere
std::vector<double> yvals(gridsize);
if (lyvals)
......@@ -905,7 +891,7 @@ eca4(const ECA_REQUEST_4 *request)
Field mask;
mask.ptr = (double *) Malloc(gridsize * sizeof(double));
int nlevels = zaxisInqSize(zaxisID);
const int nlevels = zaxisInqSize(zaxisID);
FieldVector startCount(nlevels), endCount(nlevels);
FieldVector gslDuration(nlevels), gslFirstDay(nlevels);
......
......@@ -21,7 +21,6 @@
#include "cdo_int.h"
#include "cdo_math.h"
#include "timebase.h"
#include "ecautil.h"
......@@ -107,7 +106,7 @@ gregdate_to_julday(int year, /* Gregorian year */
*
* @return the day-of-year
*/
unsigned long
static unsigned long
day_of_year(int64_t date)
{
const int year = date / 10000;
......@@ -470,7 +469,7 @@ void
adjustEndDate(int nlevels, size_t gridsize, std::vector<double> &yvals, double missval, int64_t ovdate, FieldVector2D &startDateWithHist,
FieldVector2D &endDateWithHist)
{
int64_t ovdateSouth = cdo::min(cdiEncodeDate(ovdate / 10000, 6, 30), ovdate);
const int64_t ovdateSouth = cdo::min(cdiEncodeDate(ovdate / 10000, 6, 30), ovdate);
for (int levelID = 0; levelID < nlevels; levelID++)
{
......
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