Commit fbdcb3c7 authored by Oliver Heidmann's avatar Oliver Heidmann
Browse files

maggraph parameter tokinization now uses the new c++ tokenizer

parent c7f37a64
Pipeline #4488 passed with stages
in 23 minutes and 37 seconds
...@@ -20,6 +20,7 @@ ...@@ -20,6 +20,7 @@
#include <climits> #include <climits>
#include <cdi.h> #include <cdi.h>
#include <cctype>
#include "process_int.h" #include "process_int.h"
#include <mpim_grid.h> #include <mpim_grid.h>
...@@ -30,6 +31,7 @@ ...@@ -30,6 +31,7 @@
#include "magics_template_parser.h" #include "magics_template_parser.h"
#include "results_template_parser.h" #include "results_template_parser.h"
#include "string_utilities.h" #include "string_utilities.h"
#include "util_string.h"
#include "cdo_vlist.h" #include "cdo_vlist.h"
#include "functs.h" #include "functs.h"
#include "dmemory.h" #include "dmemory.h"
...@@ -147,18 +149,15 @@ compareTime(int time1, int time2) ...@@ -147,18 +149,15 @@ compareTime(int time1, int time2)
} }
static void 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, maggraph(const char *plotfile, const char *varname, const char *varunits, long nfiles, std::vector<long> nts,
std::vector<std::vector<double>> datatab, int nparam, std::vector<std::string> &params) 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]; char min_date_time_str[1024], max_date_time_str[1024];
int min_index = 0, max_index = 0; int min_index = 0, max_index = 0;
char legend_text_data[256]; char legend_text_data[256];
int num_sigma = 2; int num_sigma = 2;
bool stat = false, obsv = false; bool stat = false, obsv = false;
int split_str_count;
int file_begin = 0; int file_begin = 0;
int count; int count;
int num_years = 0, num_months = 0, num_days = 0; 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 ...@@ -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()); 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) for (i = 0; i < nparam; ++i)
{ {
std::vector<std::string> split_str;
split_str_count = 0; split_str_count = 0;
sep_char = "="; 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]); temp_str = stringToLower(split_str[1]);
cstrToLowerCase(temp_str); if (temp_str == "true")
if (cstrIsEqual(temp_str, "true"))
{ {
obsv = true; obsv = true;
file_begin = 1; file_begin = 1;
...@@ -193,52 +195,48 @@ maggraph(const char *plotfile, const char *varname, const char *varunits, long n ...@@ -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]); temp_str = stringToLower(split_str[1]);
cstrToLowerCase(temp_str); if (temp_str == "true")
if (cstrIsEqual(temp_str, "true"))
{ {
stat = true; stat = true;
if (DBG) fprintf(stderr, "STAT true\n"); 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 (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 (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 (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 (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]); temp_str = stringToUpper(split_str[1]);
cstrToUpperCase(temp_str); DEVICE = strdup(temp_str.c_str());
DEVICE = temp_str;
if (DBG) fprintf(stderr, "DEVICE %s\n", DEVICE); if (DBG) fprintf(stderr, "DEVICE %s\n", DEVICE);
mag_setc("output_format", DEVICE); mag_setc("output_format", DEVICE);
} }
Free(split_str);
} }
if (DBG) if (DBG)
...@@ -411,8 +409,8 @@ maggraph(const char *plotfile, const char *varname, const char *varunits, long n ...@@ -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(), sprintf(date_time_str[fileID][tsID], "%s %s", dateToString(vdates[fileID][tsID]).c_str(),
timeToString(vtimes[fileID][tsID]).c_str()); timeToString(vtimes[fileID][tsID]).c_str());
if (DBG) if (DBG)
fprintf(stderr, "%s %s %s\n", dateToString(vdates[fileID][tsID]).c_str(), timeToString(vtimes[fileID][tsID]).c_str(), fprintf(stderr, "%s %s %s\n", dateToString(vdates[fileID][tsID]).c_str(),
date_time_str[fileID][tsID]); 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] < min_val) min_val = datatab[fileID][tsID];
if (datatab[fileID][tsID] > max_val) max_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 ...@@ -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); 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; split_str_count = 0;
sep_char = "-"; 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; (void) split_str_count;
num_years = atoi(split_str[0]); num_years = std::stoi(split_str[0]);
num_months = atoi(split_str[1]); num_months = std::stoi(split_str[1]);
num_days = atoi(split_str[2]); num_days = std::stoi(split_str[2]);
Free(split_str);
split_str_count = cstrSplitWithSeperator(min_date_time_str, sep_char, &split_str); split_str_count = cstrSplitWithSeperator(min_date_time_str, sep_char, split_str);
num_years -= atoi(split_str[0]); num_years -= std::stoi(split_str[0]);
if (num_years <= 1) if (num_years <= 1)
{ {
if (num_years == 1) if (num_years == 1)
num_months += (12 - atoi(split_str[1])); num_months += (12 - std::stoi(split_str[1]));
else else
num_months -= (atoi(split_str[1])); num_months -= (std::stoi(split_str[1]));
if (!num_months) if (!num_months)
num_days -= atoi(split_str[2]); num_days -= std::stoi(split_str[2]);
else if (num_months == 1) 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); 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) ...@@ -821,7 +818,6 @@ VerifyGraphParameters(int num_param, std::vector<std::string> &param_names)
} }
#endif #endif
void * void *
Maggraph(void *process) Maggraph(void *process)
{ {
...@@ -891,7 +887,7 @@ Maggraph(void *process) ...@@ -891,7 +887,7 @@ Maggraph(void *process)
{ {
if (nrecs != 1) cdoAbort("Input stream has more than one point in time!"); 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; constexpr size_t NALLOC_INC = 1024;
nts_alloc += NALLOC_INC; nts_alloc += NALLOC_INC;
......
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