Commit 074766db authored by Uwe Schulzweida's avatar Uwe Schulzweida
Browse files

Renamed strtolower() to cstrToLowerCase().

parent 53a024a9
......@@ -177,7 +177,7 @@ Adisit(void *process)
{
vlistInqVarName(vlistID1, varID, varname);
vlistInqVarStdname(vlistID1, varID, stdname);
strtolower(varname);
cstrToLowerCase(varname);
if (cstrIsEqual(varname, "s") || cstrIsEqual(stdname, "sea_water_salinity"))
code = 5;
......
......@@ -156,7 +156,7 @@ Cloudlayer(void *process)
if (code <= 0)
{
vlistInqVarName(vlistID1, varID, varname);
strtolower(varname);
cstrToLowerCase(varname);
if (strcmp(varname, "aclcac") == 0) code = 223;
}
......
......@@ -64,7 +64,7 @@ Deltime(void *process)
char smon[32];
strncpy(smon, sarg, sizeof(smon) - 1);
smon[sizeof(smon) - 1] = 0;
strtolower(smon);
cstrToLowerCase(smon);
int im;
for (im = 0; im < 12; ++im)
if (memcmp(smon, cmons[im + 1], 3) == 0) break;
......
......@@ -149,10 +149,10 @@ Derivepar(void *process)
if (code <= 0 || code == 255)
{
vlistInqVarName(vlistID1, varID, varname);
strtolower(varname);
cstrToLowerCase(varname);
vlistInqVarStdname(vlistID1, varID, stdname);
strtolower(stdname);
cstrToLowerCase(stdname);
code = echamcode_from_stdname(stdname);
if (code < 0)
......
......@@ -75,9 +75,9 @@ cdoPrintAttributes(FILE *fp, int cdiID, int varID, int nblanks)
{
if (i > 0) fprintf(fp, ", ");
if (atttype == CDI_DATATYPE_FLT32)
fprintf(fp, "%sf", double_to_attstr(Options::CDO_flt_digits, fltstr, sizeof(fltstr), attflt[i]));
fprintf(fp, "%sf", doubleToAttstr(Options::CDO_flt_digits, fltstr, sizeof(fltstr), attflt[i]));
else
fprintf(fp, "%s", double_to_attstr(Options::CDO_dbl_digits, fltstr, sizeof(fltstr), attflt[i]));
fprintf(fp, "%s", doubleToAttstr(Options::CDO_dbl_digits, fltstr, sizeof(fltstr), attflt[i]));
}
fprintf(fp, "\n");
}
......
......@@ -44,10 +44,10 @@ printValues(const int nvalues, const std::vector<std::string> &values)
case CDI_DATATYPE_INT16: printf("%ds", literal_to_int(value)); break;
case CDI_DATATYPE_INT32: printf("%d", literal_to_int(value)); break;
case CDI_DATATYPE_FLT32:
printf("%sf", double_to_attstr(Options::CDO_flt_digits, fltstr, sizeof(fltstr), literal_to_double(value)));
printf("%sf", doubleToAttstr(Options::CDO_flt_digits, fltstr, sizeof(fltstr), literal_to_double(value)));
break;
case CDI_DATATYPE_FLT64:
printf("%s", double_to_attstr(Options::CDO_dbl_digits, fltstr, sizeof(fltstr), literal_to_double(value)));
printf("%s", doubleToAttstr(Options::CDO_dbl_digits, fltstr, sizeof(fltstr), literal_to_double(value)));
break;
default: printf("\"%s\"", value);
}
......
......@@ -161,7 +161,7 @@ Pressure(void *process)
{
vlistInqVarName(vlistID1, varID, varname);
strtolower(varname);
cstrToLowerCase(varname);
// ECHAM ECMWF
if (cstrIsEqual(varname, "geosp") || cstrIsEqual(varname, "z"))
......
......@@ -377,10 +377,10 @@ Remapeta(void *process)
if (code <= 0 || code == 255)
{
vlistInqVarName(vlistID1, varID, varname);
strtolower(varname);
cstrToLowerCase(varname);
vlistInqVarStdname(vlistID1, varID, stdname);
strtolower(stdname);
cstrToLowerCase(stdname);
code = echamcode_from_stdname(stdname);
......
......@@ -177,7 +177,7 @@ Rhopot(void *process)
{
vlistInqVarName(vlistID1, varID, varname);
vlistInqVarStdname(vlistID1, varID, stdname);
strtolower(varname);
cstrToLowerCase(varname);
if (cstrIsEqual(varname, "to"))
code = 20;
......
......@@ -53,7 +53,7 @@ season_to_months(const char *season, int *imonths)
{
if (len > 12) cdoAbort("Too many months %d (limit=12)!", (int) len);
char *season_u = strdup(season);
strtoupper(season_u);
cstrToUpperCase(season_u);
const char *sstr = strstr(smons, season_u);
free(season_u);
if (sstr == nullptr) cdoAbort("Season %s not available!", season);
......
......@@ -378,7 +378,7 @@ Settime(void *process)
{
operatorCheckArgc(1);
char *cname = operatorArgv()[0];
strtolower(cname);
cstrToLowerCase(cname);
// clang-format off
if (cstrIsEqual(cname, "standard")) newcalendar = CALENDAR_STANDARD;
else if (cstrIsEqual(cname, "gregorian")) newcalendar = CALENDAR_GREGORIAN;
......
......@@ -280,10 +280,10 @@ Sinfo(void *process)
fprintf(stdout, " RefTime = %s %s", vdatestr, vtimestr);
const int tunits = taxisInqTunit(taxisID);
if (tunits != CDI_UNDEFID) fprintf(stdout, " Units = %s", tunit2str(tunits));
if (tunits != CDI_UNDEFID) fprintf(stdout, " Units = %s", tunitToCstr(tunits));
const int calendar = taxisInqCalendar(taxisID);
if (calendar != CDI_UNDEFID) fprintf(stdout, " Calendar = %s", calendar2str(calendar));
if (calendar != CDI_UNDEFID) fprintf(stdout, " Calendar = %s", calendarToCstr(calendar));
if (taxisHasBounds(taxisID)) fprintf(stdout, " Bounds = true");
......
......@@ -71,26 +71,6 @@ cstrIsNumeric(const char *s)
return *ptr == '\0';
}
void
cstrToUpperCase(char *sPtr)
{
while (*sPtr != '\0')
{
*sPtr = toupper((unsigned char) *sPtr);
++sPtr;
}
}
void
cstrToLowerCase(char *sPtr)
{
while (*sPtr != '\0')
{
*sPtr = tolower((unsigned char) *sPtr);
++sPtr;
}
}
/* To replace a single char with another single char in a given string */
void
......
......@@ -279,10 +279,10 @@ Tinfo(void *process)
fprintf(stdout, " RefTime = %s %s", vdatestr, vtimestr);
int unit = taxisInqTunit(taxisID);
if (unit != CDI_UNDEFID) fprintf(stdout, " Units = %s", tunit2str(unit));
if (unit != CDI_UNDEFID) fprintf(stdout, " Units = %s", tunitToCstr(unit));
int calendar = taxisInqCalendar(taxisID);
if (calendar != CDI_UNDEFID) fprintf(stdout, " Calendar = %s", calendar2str(calendar));
if (calendar != CDI_UNDEFID) fprintf(stdout, " Calendar = %s", calendarToCstr(calendar));
if (taxisHasBounds(taxisID)) fprintf(stdout, " Bounds = true");
......@@ -299,7 +299,7 @@ Tinfo(void *process)
fprintf(stdout, " Forecast RefTime = %s %s", vdatestr, vtimestr);
unit = taxisInqForecastTunit(taxisID);
if (unit != CDI_UNDEFID) fprintf(stdout, " Units = %s", tunit2str(unit));
if (unit != CDI_UNDEFID) fprintf(stdout, " Units = %s", tunitToCstr(unit));
fprintf(stdout, "\n");
......
......@@ -169,7 +169,7 @@ Vertintap(void *process)
for (varID = 0; varID < nvars; varID++)
{
vlistInqVarStdname(vlistID1, varID, stdname);
strtolower(stdname);
cstrToLowerCase(stdname);
// clang-format off
if (cstrIsEqual(stdname, var_stdname(surface_air_pressure))) psID = varID;
......
......@@ -315,10 +315,10 @@ Vertintml(void *process)
if (code <= 0 || code == 255)
{
vlistInqVarName(vlistID1, varID, varname);
strtolower(varname);
cstrToLowerCase(varname);
vlistInqVarStdname(vlistID1, varID, stdname);
strtolower(stdname);
cstrToLowerCase(stdname);
code = echamcode_from_stdname(stdname);
if (code == -1)
......
......@@ -64,7 +64,7 @@ Vertwind(void *process)
if (code <= 0)
{
vlistInqVarName(vlistID1, varID, varname);
strtolower(varname);
cstrToLowerCase(varname);
// clang-format off
if (strcmp(varname, "st") == 0) code = temp_code;
......
......@@ -101,7 +101,7 @@ Wind(void *process)
if (pdis != 255 || code <= 0)
{
vlistInqVarName(vlistID1, varID, varname);
strtolower(varname);
cstrToLowerCase(varname);
if (cstrIsEqual(varname, "u")) code = 131;
if (cstrIsEqual(varname, "v")) code = 132;
}
......@@ -115,14 +115,14 @@ Wind(void *process)
if (pdis != 255) // GRIB2
{
vlistInqVarName(vlistID1, varID, varname);
strtolower(varname);
cstrToLowerCase(varname);
if (cstrIsEqual(varname, "d")) code = 155;
if (cstrIsEqual(varname, "vo")) code = 138;
}
else if (code <= 0)
{
vlistInqVarName(vlistID1, varID, varname);
strtolower(varname);
cstrToLowerCase(varname);
if (cstrIsEqual(varname, "sd")) code = 155;
if (cstrIsEqual(varname, "svo")) code = 138;
}
......
......@@ -185,8 +185,8 @@ vlistCompareNames(int vlistID1, int varID1, int vlistID2, int varID2)
char name1[CDI_MAX_NAME], name2[CDI_MAX_NAME];
vlistInqVarName(vlistID1, varID1, name1);
vlistInqVarName(vlistID2, varID2, name2);
strtolower(name1);
strtolower(name2);
cstrToLowerCase(name1);
cstrToLowerCase(name2);
return strcmp(name1, name2);
}
......
......@@ -356,7 +356,7 @@ zaxisFromName(const char *zaxisnameptr)
size_t len;
char *zaxisname = strdup(zaxisnameptr);
strtolower(zaxisname);
cstrToLowerCase(zaxisname);
zaxis_t zaxis;
zaxisInit(zaxis);
......
......@@ -53,7 +53,7 @@ getTimestatDate(TimeStat *tstat_date)
memcpy(envstrl, envstr, 8);
envstrl[7] = 0;
strtolower(envstrl);
cstrToLowerCase(envstrl);
// clang-format off
if (memcmp(envstrl, "first", 5) == 0) env_date = TimeStat::FIRST;
......
......@@ -384,7 +384,7 @@ gridFromName(const char *gridnameptr)
char *endptr;
char *gridname = strdup(gridnameptr);
strtolower(gridname);
cstrToLowerCase(gridname);
if (gridname[0] == 't') // t<RES>grid or t<RES>spec
{
......
......@@ -144,10 +144,10 @@ grid_print_attributes(FILE *fp, int gridID)
fprintf(fp, "%s =", attname);
if (atttype == CDI_DATATYPE_FLT32)
for (int i = 0; i < attlen; ++i)
fprintf(fp, " %sf", double_to_attstr(Options::CDO_flt_digits, fltstr, sizeof(fltstr), attflt[i]));
fprintf(fp, " %sf", doubleToAttstr(Options::CDO_flt_digits, fltstr, sizeof(fltstr), attflt[i]));
else
for (int i = 0; i < attlen; ++i)
fprintf(fp, " %s", double_to_attstr(Options::CDO_dbl_digits, fltstr, sizeof(fltstr), attflt[i]));
fprintf(fp, " %s", doubleToAttstr(Options::CDO_dbl_digits, fltstr, sizeof(fltstr), attflt[i]));
fprintf(fp, "\n");
}
}
......
......@@ -141,7 +141,7 @@ find_similar(std::string operatorName)
// Searching for simlar operator names in operator to module map
for (const auto &str : modules_map)
{
if (similar(string2lower(operatorName), str.first))
if (similar(stringToLower(operatorName), str.first))
{
if (found_similar_operators.size() + str.first.size() > lines * line_length)
{
......@@ -155,7 +155,7 @@ find_similar(std::string operatorName)
// Searching for similar operator names in aliases to original map
for (const auto &str : aliases)
{
if (similar(string2lower(operatorName), str.first))
if (similar(stringToLower(operatorName), str.first))
{
if (found_similar_operators.size() + str.first.size() > lines * line_length)
{
......
......@@ -133,7 +133,7 @@ void
percentile_set_method(const char *methodstr)
{
char *methodname = strdup(methodstr);
strtolower(methodname);
cstrToLowerCase(methodname);
if (cstrIsEqual("nrank", methodname))
percentile_method = NRANK;
......@@ -199,6 +199,5 @@ done
import numpy as np
np.version.version
a=np.array([15, 20, 35, 40, 50, 55])
for p in [30, 40, 50, 75, 100] : print np.percentile(a, p,
interpolation='linear')
for p in [30, 40, 50, 75, 100] : print np.percentile(a, p, interpolation='linear')
*/
......@@ -22,21 +22,21 @@
#include <cdi.h>
std::string
string2lower(std::string s)
stringToLower(std::string s)
{
std::transform(s.begin(), s.end(), s.begin(), [](unsigned char c) { return std::tolower(c); });
return s;
}
void
strtolower(char *str)
cstrToLowerCase(char *str)
{
if (str)
for (size_t i = 0; str[i]; ++i) str[i] = (char) tolower((int) str[i]);
}
void
strtoupper(char *str)
cstrToUpperCase(char *str)
{
if (str)
for (size_t i = 0; str[i]; ++i) str[i] = (char) toupper((int) str[i]);
......@@ -61,16 +61,16 @@ trim_flt(char *ss)
}
char *
double_to_attstr(int digits, char *attstr, size_t len, double value)
doubleToAttstr(int digits, char *attstr, size_t len, double value)
{
int ret = snprintf(attstr, len, "%#.*g", digits, value);
const int ret = snprintf(attstr, len, "%#.*g", digits, value);
assert(ret != -1 && ret < (int) len);
trim_flt(attstr);
return attstr;
}
const char *
tunit2str(int tunits)
tunitToCstr(int tunits)
{
// clang-format off
if ( tunits == TUNIT_YEAR ) return ("years");
......@@ -89,7 +89,7 @@ tunit2str(int tunits)
}
const char *
calendar2str(int calendar)
calendarToCstr(int calendar)
{
// clang-format off
if ( calendar == CALENDAR_STANDARD ) return ("standard");
......
......@@ -21,12 +21,12 @@
#define ADD_PLURAL(n) ((n) != 1 ? "s" : "")
std::string string2lower(std::string str);
void strtolower(char *str);
void strtoupper(char *str);
char *double_to_attstr(int digits, char *str, size_t len, double value);
std::string stringToLower(std::string str);
void cstrToLowerCase(char *str);
void cstrToUpperCase(char *str);
char *doubleToAttstr(int digits, char *str, size_t len, double value);
const char *tunit2str(int tunits);
const char *calendar2str(int calendar);
const char *tunitToCstr(int tunits);
const char *calendarToCstr(int calendar);
#endif
......@@ -84,7 +84,7 @@ expand_filename(const char *string)
if (find_wildcard(string, strlen(string)))
{
#ifdef HAVE_GLOB_H
int glob_flags = get_glob_flags();
const int glob_flags = get_glob_flags();
glob_t glob_results;
glob(string, glob_flags, 0, &glob_results);
if (glob_results.gl_pathc == 1) filename = strdup(glob_results.gl_pathv[0]);
......@@ -108,7 +108,7 @@ expandWildCards(std::vector<std::string> argv)
// if argv[idx] contains wildcard (* or [?]+), multiple ** are ignored
if (argv[idx][0] != '-' && argv[idx].find_first_of("*?[ ") != std::string::npos)
{
int status = wordexp(argv[idx].c_str(), &glob_results, flags);
const int status = wordexp(argv[idx].c_str(), &glob_results, flags);
if (status != 0)
{
fprintf(stderr, "%s: ", __func__);
......
......@@ -21,8 +21,6 @@
#include <vector>
#include <string>
int find_wildcard(const char *args, size_t len);
char *expand_filename(const char *args);
std::vector<std::string> expandWildCards(std::vector<std::string> argv);
......
Markdown is supported
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