Commit 93e705b5 authored by Uwe Schulzweida's avatar Uwe Schulzweida
Browse files

merge.

parents 7ca934a6 5ea93407
Pipeline #4332 passed with stages
in 20 minutes and 59 seconds
Subproject commit 29548d2f58431d707184eb698f626c79f419bb8d
Subproject commit 6b38c8af43a1ab9b6e6b196d1350c1cc794a783c
......@@ -38,14 +38,14 @@ fill_vars(const VarList &varList, std::vector<bool> &vars)
{
const int nvars = vars.size();
if (Options::cdoNumVarnames)
if (Options::cdoNumVarnames() > 0)
{
auto found = false;
for (int varID = 0; varID < nvars; ++varID)
{
vars[varID] = false;
for (int i = 0; i < Options::cdoNumVarnames; ++i)
if (strcmp(varList[varID].name, Options::cdoVarnames[i]) == 0)
for (int i = 0; i < Options::cdoNumVarnames(); ++i)
if (strcmp(varList[varID].name, Options::cdoVarnames[i].c_str()) == 0)
{
vars[varID] = true;
found = true;
......@@ -53,7 +53,7 @@ fill_vars(const VarList &varList, std::vector<bool> &vars)
}
}
if (!found) cdoAbort("Variable %s%s not found!", Options::cdoVarnames[0], Options::cdoNumVarnames > 1 ? ",..." : "");
if (!found) cdoAbort("Variable %s%s not found!", Options::cdoVarnames[0], Options::cdoNumVarnames() > 1 ? ",..." : "");
}
else
{
......
......@@ -661,38 +661,26 @@ defineChunktype(const std::string &arg)
// clang-format on
}
static void
std::vector<std::string>
defineVarnames(const char *const arg)
{
size_t len = strlen(arg);
size_t istart = 0;
while (istart < len && (arg[istart] == ' ' || arg[istart] == ',')) istart++;
len -= istart;
if (len)
{
Options::cdoVarnames = (char **) Malloc(MAX_NUM_VARNAMES * sizeof(char *));
std::string strArgs = std::string(arg);
std::vector<std::string> newVarnames;
char *pbuf = strdup(arg + istart);
Options::cdoVarnames[Options::cdoNumVarnames++] = pbuf;
const char delim = ',';
size_t previous = 0;
size_t current = strArgs.find(delim);
char *commapos = pbuf;
while ((commapos = strchr(commapos, ',')) != nullptr)
{
*commapos++ = '\0';
if (strlen(commapos))
{
if (Options::cdoNumVarnames >= MAX_NUM_VARNAMES) cdoAbort("Too many variable names (limit=%d)!", MAX_NUM_VARNAMES);
Options::cdoVarnames[Options::cdoNumVarnames++] = commapos;
}
}
/*
for ( int i = 0; i < Options::cdoNumVarnames; ++i )
printf("varname %d: %s\n", i+1, Options::cdoVarnames[i]);
*/
while (current != std::string::npos)
{
newVarnames.push_back(strArgs.substr(previous, current - previous));
previous = current + 1;
current = strArgs.find(delim, previous);
}
newVarnames.push_back(strArgs.substr(previous, current - previous));
Options::cdoVarnames = newVarnames;
}
static void
......@@ -1264,7 +1252,7 @@ parseOptionsLong(int argc, char *argv[])
case 'l': defineZaxis(CDO_optarg); break;
case 'm': cdiDefMissval(atof(CDO_optarg)); break;
case 'M': cdiDefGlobal("HAVE_MISSVAL", true); break;
case 'n': defineVarnames(CDO_optarg); break;
case 'n': Options::cdoVarnames = defineVarnames(CDO_optarg); break;
case 'O': Options::cdoOverwriteMode = true; break;
case 'P': numThreads = parameter2int(CDO_optarg); break;
case 'p':
......@@ -1894,12 +1882,6 @@ main(int argc, char *argv[])
if (Options::Timer) timer_report();
}
if (Options::cdoVarnames)
{
if (Options::cdoNumVarnames) Free(Options::cdoVarnames[0]);
Free(Options::cdoVarnames);
}
if (CDO_Rusage) cdo_rusage();
if (!status) status = Options::cdoExitStatus;
......
......@@ -72,8 +72,10 @@ int cdoChunkType = CDI_UNDEFID;
bool cdoOverwriteMode = false;
bool cdoParIO = false;
bool cdoRegulargrid = false;
int cdoNumVarnames = 0;
char **cdoVarnames = nullptr;
std::vector<std::string> cdoVarnames;
size_t cdoNumVarnames(){
return cdoVarnames.size();
}
bool REMAP_genweights = true;
......
......@@ -17,6 +17,9 @@
#ifndef CDO_OPTIONS_H
#define CDO_OPTIONS_H
#include <vector>
#include <string>
namespace cdo
{
extern const char *progname;
......@@ -74,8 +77,8 @@ extern int cdoChunkType;
extern bool cdoOverwriteMode;
extern bool cdoParIO;
extern bool cdoRegulargrid;
extern int cdoNumVarnames;
extern char **cdoVarnames;
size_t cdoNumVarnames();
extern std::vector<std::string> cdoVarnames;
extern bool REMAP_genweights;
......
......@@ -136,6 +136,8 @@ cdoConvertDestroy()
void
cdoConvertUnits(void **ut_converter, bool *changeunits, char *units, char *units_old, const char *name)
{
(void) ut_converter; // removes wrong warning, caused by ifdef
if (*changeunits)
{
#ifdef HAVE_UDUNITS2
......
......@@ -84,7 +84,11 @@ gregdate_to_julday(int year, /* Gregorian year */
{
double xi = 365.25 * jy;
if (((int) xi) != xi) xi -= 1;
{
int temp = xi * 100;
if (temp % 100 != 0) xi -= 1;
}
// if (((int) xi) != xi) xi -= 1; // old version, caused warning (25.08.2020 O.Heidmann)
julday += (int) xi;
}
julday += 1720995;
......@@ -165,7 +169,7 @@ count(Field &field1, const Field &field2, double mode)
if (!DBL_IS_EQUAL(array1[i], missval1))
{
if (IS_EQUAL(mode, 0.0) || IS_EQUAL(mode, 1.0) )
if (IS_EQUAL(mode, 0.0) || IS_EQUAL(mode, 1.0))
array1[i] += 1.0;
else if (DBL_IS_EQUAL(array2[i], mode) || array2[i] > mode)
array1[i] += array2[i];
......@@ -195,7 +199,7 @@ count(Field &field1, const Field &field2, double mode)
if (IS_EQUAL(mode, 0.0) || IS_EQUAL(mode, 1.0))
array1[i] += 1.0;
else if (DBL_IS_EQUAL(array2[i], mode) || array2[i] > mode)
else if (DBL_IS_EQUAL(array2[i], mode) || array2[i] > mode)
array1[i] += array2[i];
}
}
......@@ -456,18 +460,18 @@ defineMidOfTime(int frequency, int taxisID, int year, int month, int MaxMonths)
const auto calendar = taxisInqCalendar(taxisID);
if ( frequency == 8 )
if (frequency == 8)
{
vdateb = cdiEncodeDate(year, month, 1);
int boundmonth = ( month + 1 <= MaxMonths ) ? month +1 : 1;
int boundyear = ( boundmonth != 1 ) ? year : year+1;
int boundmonth = (month + 1 <= MaxMonths) ? month + 1 : 1;
int boundyear = (boundmonth != 1) ? year : year + 1;
vdatebp1 = cdiEncodeDate(boundyear, boundmonth, 1);
}
else
{
vdateb = cdiEncodeDate(year, 1, 1);
vdatebp1 = cdiEncodeDate(year+1, 1, 1);
vdatebp1 = cdiEncodeDate(year + 1, 1, 1);
}
const auto juldate1 = julianDateEncode(calendar, vdateb, vtime0);
......
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