Commit c6f57a13 authored by Uwe Schulzweida's avatar Uwe Schulzweida
Browse files

Merge branch 'develop' of gitlab.dkrz.de:mpim-sw/cdo into develop

parents c082e383 fbdcb3c7
Pipeline #4489 passed with stages
in 21 minutes and 47 seconds
......@@ -20,6 +20,7 @@
#include <climits>
#include <cdi.h>
#include <cctype>
#include "process_int.h"
#include <mpim_grid.h>
......@@ -30,6 +31,7 @@
#include "magics_template_parser.h"
#include "results_template_parser.h"
#include "string_utilities.h"
#include "util_string.h"
#include "cdo_vlist.h"
#include "functs.h"
#include "dmemory.h"
......@@ -147,18 +149,15 @@ compareTime(int time1, int time2)
}
static void
maggraph(const char *plotfile, const char *varname, const char *varunits, long nfiles, std::vector<long> nts, std::vector<std::vector<int64_t>> vdates, std::vector<std::vector<int>> vtimes,
std::vector<std::vector<double>> datatab, int nparam, std::vector<std::string> &params)
maggraph(const char *plotfile, const char *varname, const char *varunits, long nfiles, std::vector<long> nts,
std::vector<std::vector<int64_t>> vdates, std::vector<std::vector<int>> vtimes, std::vector<std::vector<double>> datatab,
int nparam, std::vector<std::string> &params)
{
char *temp_str;
char **split_str = nullptr;
const char *sep_char = "=";
char min_date_time_str[1024], max_date_time_str[1024];
int min_index = 0, max_index = 0;
char legend_text_data[256];
int num_sigma = 2;
bool stat = false, obsv = false;
int split_str_count;
int file_begin = 0;
int count;
int num_years = 0, num_months = 0, num_days = 0;
......@@ -175,17 +174,20 @@ maggraph(const char *plotfile, const char *varname, const char *varunits, long n
for (i = 0; i < nparam; i++) fprintf(stderr, "Param %s\n", params[i].c_str());
}
int split_str_count;
const char *sep_char = "=";
std::string temp_str;
for (i = 0; i < nparam; ++i)
{
std::vector<std::string> split_str;
split_str_count = 0;
sep_char = "=";
split_str_count = cstrSplitWithSeperator(params[i].c_str(), sep_char, &split_str);
split_str_count = cstrSplitWithSeperator(params[i].c_str(), sep_char, split_str);
if (cstrIsEqual(split_str[0], "obsv"))
if (split_str[0] == "obsv")
{
temp_str = strdup(split_str[1]);
cstrToLowerCase(temp_str);
if (cstrIsEqual(temp_str, "true"))
temp_str = stringToLower(split_str[1]);
if (temp_str == "true")
{
obsv = true;
file_begin = 1;
......@@ -193,52 +195,48 @@ maggraph(const char *plotfile, const char *varname, const char *varunits, long n
}
}
if (cstrIsEqual(split_str[0], "stat"))
if (split_str[0] == "stat")
{
temp_str = strdup(split_str[1]);
cstrToLowerCase(temp_str);
if (cstrIsEqual(temp_str, "true"))
temp_str = stringToLower(split_str[1]);
if (temp_str == "true")
{
stat = true;
if (DBG) fprintf(stderr, "STAT true\n");
}
}
if (cstrIsEqual(split_str[0], "ymin"))
if (split_str[0] == "ymin")
{
y_min_val = atof(split_str[1]);
y_min_val = std::stod(split_str[1]);
if (DBG) fprintf(stderr, "Y min Val %g\n", y_min_val);
}
if (cstrIsEqual(split_str[0], "ymax"))
if (split_str[0] == "ymax")
{
y_max_val = atof(split_str[1]);
y_max_val = std::stod(split_str[1]);
if (DBG) fprintf(stderr, "Y max Val %g\n", y_max_val);
}
if (cstrIsEqual(split_str[0], "linewidth"))
if (split_str[0] == "linewidth")
{
linewidth_val = atoi(split_str[1]);
linewidth_val = std::stoi(split_str[1]);
if (DBG) fprintf(stderr, "linewidth Val %d\n", linewidth_val);
}
if (cstrIsEqual(split_str[0], "sigma"))
if (split_str[0] == "sigma")
{
num_sigma = atof(split_str[1]);
num_sigma = std::stod(split_str[1]);
if (DBG) fprintf(stderr, "SIGMA %d\n", num_sigma);
}
if (cstrIsEqual(split_str[0], "device"))
if (split_str[0] == "device")
{
temp_str = strdup(split_str[1]);
cstrToUpperCase(temp_str);
DEVICE = temp_str;
temp_str = stringToUpper(split_str[1]);
DEVICE = strdup(temp_str.c_str());
if (DBG) fprintf(stderr, "DEVICE %s\n", DEVICE);
mag_setc("output_format", DEVICE);
}
Free(split_str);
}
if (DBG)
......@@ -411,8 +409,8 @@ maggraph(const char *plotfile, const char *varname, const char *varunits, long n
sprintf(date_time_str[fileID][tsID], "%s %s", dateToString(vdates[fileID][tsID]).c_str(),
timeToString(vtimes[fileID][tsID]).c_str());
if (DBG)
fprintf(stderr, "%s %s %s\n", dateToString(vdates[fileID][tsID]).c_str(), timeToString(vtimes[fileID][tsID]).c_str(),
date_time_str[fileID][tsID]);
fprintf(stderr, "%s %s %s\n", dateToString(vdates[fileID][tsID]).c_str(),
timeToString(vtimes[fileID][tsID]).c_str(), date_time_str[fileID][tsID]);
if (datatab[fileID][tsID] < min_val) min_val = datatab[fileID][tsID];
if (datatab[fileID][tsID] > max_val) max_val = datatab[fileID][tsID];
......@@ -464,31 +462,30 @@ maggraph(const char *plotfile, const char *varname, const char *varunits, long n
if (DBG) fprintf(stderr, "%s %s\n", min_date_time_str, max_date_time_str);
std::vector<std::string> split_str;
split_str_count = 0;
sep_char = "-";
split_str_count = cstrSplitWithSeperator(max_date_time_str, sep_char, &split_str);
split_str_count = cstrSplitWithSeperator(max_date_time_str, sep_char, split_str);
(void) split_str_count;
num_years = atoi(split_str[0]);
num_months = atoi(split_str[1]);
num_days = atoi(split_str[2]);
Free(split_str);
num_years = std::stoi(split_str[0]);
num_months = std::stoi(split_str[1]);
num_days = std::stoi(split_str[2]);
split_str_count = cstrSplitWithSeperator(min_date_time_str, sep_char, &split_str);
num_years -= atoi(split_str[0]);
split_str_count = cstrSplitWithSeperator(min_date_time_str, sep_char, split_str);
num_years -= std::stoi(split_str[0]);
if (num_years <= 1)
{
if (num_years == 1)
num_months += (12 - atoi(split_str[1]));
num_months += (12 - std::stoi(split_str[1]));
else
num_months -= (atoi(split_str[1]));
num_months -= (std::stoi(split_str[1]));
if (!num_months)
num_days -= atoi(split_str[2]);
num_days -= std::stoi(split_str[2]);
else if (num_months == 1)
num_days += (31 - atoi(split_str[2]));
num_days += (31 - std::stoi(split_str[2]));
}
Free(split_str);
if (DBG) fprintf(stderr, " %d %d\n", num_years, num_months);
......@@ -821,7 +818,6 @@ VerifyGraphParameters(int num_param, std::vector<std::string> &param_names)
}
#endif
void *
Maggraph(void *process)
{
......@@ -891,7 +887,7 @@ Maggraph(void *process)
{
if (nrecs != 1) cdoAbort("Input stream has more than one point in time!");
if ((size_t)tsID >= nts_alloc)
if ((size_t) tsID >= nts_alloc)
{
constexpr size_t NALLOC_INC = 1024;
nts_alloc += NALLOC_INC;
......
......@@ -14,6 +14,7 @@
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
*/
#include <algorithm>
#include "cdo_output.h"
#include "dmemory.h"
......@@ -22,6 +23,17 @@
#define DBG 0
int
cstrSplitWithSeperator(const char *source_string, const char *seperator, std::vector<std::string> &split_string)
{
std::stringstream ss(source_string);
std::string token;
while (std::getline(ss, token, *seperator))
{
split_string.push_back(token);
}
return split_string.size();
}
int
cstrSplitWithSeperator(const char *source_string, const char *seperator, char ***ptr_split_string)
{
......
......@@ -17,14 +17,14 @@
#ifndef STR_UTILITIES_H
#define STR_UTILITIES_H
int cstrSplitWithSeperator(const char *source_string, const char *seperator, std::vector<std::string> &split_string);
int cstrSplitWithSeperator(const char *source_string, const char *seperator, char ***ptr_split_string);
int cstrIsNumeric(const char *s);
void cstrToUpperCase(char *sPtr);
void cstrReplaceChar(char *str_in, char orig_char, char rep_char);
void cstrToUpperCase(char *sPtr);
void cstrToLowerCase(char *sPtr);
void cstrReplaceChar(char *str_in, char orig_char, char rep_char);
#endif
......@@ -23,12 +23,20 @@
#include <cdi.h>
std::string
stringToLower(std::string s)
stringToUpper(std::string p_str)
{
std::transform(s.begin(), s.end(), s.begin(), [](unsigned char c) { return std::tolower(c); });
return s;
std::transform(p_str.begin(), p_str.end(), p_str.begin(), [](unsigned char c) { return std::toupper(c); });
return p_str;
}
std::string
stringToLower(std::string p_str)
{
std::transform(p_str.begin(), p_str.end(), p_str.begin(), [](unsigned char c) { return std::tolower(c); });
return p_str;
}
void
cstrToLowerCase(char *str)
{
......
......@@ -21,7 +21,9 @@
#define ADD_PLURAL(n) ((n) != 1 ? "s" : "")
std::string stringToLower(std::string str);
std::string stringToUpper(std::string p_str);
std::string stringToLower(std::string p_str);
void cstrToLowerCase(char *str);
void cstrToUpperCase(char *str);
char *doubleToAttstr(int digits, char *str, size_t len, double value);
......
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