Skip to content
Snippets Groups Projects
Commit ae31b708 authored by Uwe Schulzweida's avatar Uwe Schulzweida
Browse files

ZaxisDescription: change type of string members to std::string

parent 58fd0d99
No related branches found
No related tags found
1 merge request!29M214003/develop
......@@ -60,7 +60,7 @@ cdo_append_history(int vlistID, const char *histstring)
const auto atttype = cdiInqAttType(vlistID, CDI_GLOBAL, historyAttrName);
if (atttype == CDI_DATATYPE_TXT)
{
int ghistorysize = cdiInqAttLen(vlistID, CDI_GLOBAL, historyAttrName);
auto ghistorysize = cdiInqAttLen(vlistID, CDI_GLOBAL, historyAttrName);
if (ghistorysize < 0) ghistorysize = 0;
if (ghistorysize > 0)
{
......@@ -81,7 +81,7 @@ cdo_append_history(int vlistID, const char *histstring)
history += ghistory.data();
}
cdiDefAttTxt(vlistID, CDI_GLOBAL, historyAttrName, strlen(history.c_str()), history.c_str());
cdiDefAttTxt(vlistID, CDI_GLOBAL, historyAttrName, history.size(), history.c_str());
}
void
......
......@@ -22,7 +22,7 @@
#define MAX_LINE_LEN 65536
struct zaxis_t
struct ZaxisDesciption
{
Varray<double> vals;
Varray<double> lbounds;
......@@ -67,7 +67,7 @@ getoptname(char *optname, const char *optstring, int nopt)
}
int
zaxisDefine(zaxis_t zaxis)
zaxisDefine(ZaxisDesciption zaxis)
{
if (zaxis.type == CDI_UNDEFID) cdo_abort("zaxistype undefined!");
if (zaxis.size == 0) cdo_abort("zaxis size undefined!");
......@@ -104,7 +104,7 @@ struct KVMap
};
static void
zaxis_read_data(size_t nkv, KVMap *kvmap, zaxis_t *zaxis, size_t &natts, const char *dname)
zaxis_read_data(size_t nkv, KVMap *kvmap, ZaxisDesciption &zaxis, size_t &natts, const char *dname)
{
// char uuidStr[256];
......@@ -124,60 +124,60 @@ zaxis_read_data(size_t nkv, KVMap *kvmap, zaxis_t *zaxis, size_t &natts, const c
{
auto zaxistype = parameter_to_word(value);
if (zaxistype == "pressure") zaxis->type = ZAXIS_PRESSURE;
else if (zaxistype == "hybrid_half") zaxis->type = ZAXIS_HYBRID_HALF;
else if (zaxistype == "hybrid") zaxis->type = ZAXIS_HYBRID;
else if (zaxistype == "height") zaxis->type = ZAXIS_HEIGHT;
else if (zaxistype == "depth_below_sea") zaxis->type = ZAXIS_DEPTH_BELOW_SEA;
else if (zaxistype == "depth_below_land") zaxis->type = ZAXIS_DEPTH_BELOW_LAND;
else if (zaxistype == "isentropic") zaxis->type = ZAXIS_ISENTROPIC;
else if (zaxistype == "surface") zaxis->type = ZAXIS_SURFACE;
else if (zaxistype == "generic") zaxis->type = ZAXIS_GENERIC;
if (zaxistype == "pressure") zaxis.type = ZAXIS_PRESSURE;
else if (zaxistype == "hybrid_half") zaxis.type = ZAXIS_HYBRID_HALF;
else if (zaxistype == "hybrid") zaxis.type = ZAXIS_HYBRID;
else if (zaxistype == "height") zaxis.type = ZAXIS_HEIGHT;
else if (zaxistype == "depth_below_sea") zaxis.type = ZAXIS_DEPTH_BELOW_SEA;
else if (zaxistype == "depth_below_land") zaxis.type = ZAXIS_DEPTH_BELOW_LAND;
else if (zaxistype == "isentropic") zaxis.type = ZAXIS_ISENTROPIC;
else if (zaxistype == "surface") zaxis.type = ZAXIS_SURFACE;
else if (zaxistype == "generic") zaxis.type = ZAXIS_GENERIC;
else cdo_abort("Invalid zaxis type: %s (zaxis description file: %s)", zaxistype, dname);
}
else if (key == "datatype")
{
auto datatype = parameter_to_word(value);
if (datatype == "double") zaxis->datatype = CDI_DATATYPE_FLT64;
else if (datatype == "float") zaxis->datatype = CDI_DATATYPE_FLT32;
else if (datatype == "int") zaxis->datatype = CDI_DATATYPE_INT32;
else if (datatype == "short") zaxis->datatype = CDI_DATATYPE_INT16;
if (datatype == "double") zaxis.datatype = CDI_DATATYPE_FLT64;
else if (datatype == "float") zaxis.datatype = CDI_DATATYPE_FLT32;
else if (datatype == "int") zaxis.datatype = CDI_DATATYPE_INT32;
else if (datatype == "short") zaxis.datatype = CDI_DATATYPE_INT16;
else cdo_abort("Invalid datatype: %s (zaxis description file: %s)", datatype, dname);
}
else if (key == "size") zaxis->size = parameter_to_int(value);
else if (key == "scalar") zaxis->scalar = parameter_to_bool(value);
else if (key == "vctsize") zaxis->vctsize = parameter_to_int(value);
else if (key == "name") strcpy(zaxis->name, parameter_to_word(value.c_str()));
else if (key == "units") strcpy(zaxis->units, parameter_to_word(value.c_str()));
else if (key == "longname") strcpy(zaxis->longname, value.c_str());
else if (key == "size") zaxis.size = parameter_to_int(value);
else if (key == "scalar") zaxis.scalar = parameter_to_bool(value);
else if (key == "vctsize") zaxis.vctsize = parameter_to_int(value);
else if (key == "name") strcpy(zaxis.name, parameter_to_word(value.c_str()));
else if (key == "units") strcpy(zaxis.units, parameter_to_word(value.c_str()));
else if (key == "longname") strcpy(zaxis.longname, value.c_str());
else if (key == "levels")
{
if (zaxis->size == 0) cdo_abort("size undefined (zaxis description file: %s)!", dname);
if (zaxis->size != nvalues) cdo_abort("size=%zu and number of levels=%zu differ!", zaxis->size, nvalues);
zaxis->vals.resize(zaxis->size);
for (size_t i = 0; i < zaxis->size; ++i) zaxis->vals[i] = parameter_to_double(values[i]);
if (zaxis.size == 0) cdo_abort("size undefined (zaxis description file: %s)!", dname);
if (zaxis.size != nvalues) cdo_abort("size=%zu and number of levels=%zu differ!", zaxis.size, nvalues);
zaxis.vals.resize(zaxis.size);
for (size_t i = 0; i < zaxis.size; ++i) zaxis.vals[i] = parameter_to_double(values[i]);
}
else if (key == "lbounds")
{
if (zaxis->size == 0) cdo_abort("size undefined (zaxis description file: %s)!", dname);
if (zaxis->size != nvalues) cdo_abort("size=%zu and number of lbounds=%zu differ!", zaxis->size, nvalues);
zaxis->lbounds.resize(zaxis->size);
for (size_t i = 0; i < zaxis->size; ++i) zaxis->lbounds[i] = parameter_to_double(values[i]);
if (zaxis.size == 0) cdo_abort("size undefined (zaxis description file: %s)!", dname);
if (zaxis.size != nvalues) cdo_abort("size=%zu and number of lbounds=%zu differ!", zaxis.size, nvalues);
zaxis.lbounds.resize(zaxis.size);
for (size_t i = 0; i < zaxis.size; ++i) zaxis.lbounds[i] = parameter_to_double(values[i]);
}
else if (key == "ubounds")
{
if (zaxis->size == 0) cdo_abort("size undefined (zaxis description file: %s)!", dname);
if (zaxis->size != nvalues) cdo_abort("size=%zu and number of ubounds=%zu differ!", zaxis->size, nvalues);
zaxis->ubounds.resize(zaxis->size);
for (size_t i = 0; i < zaxis->size; ++i) zaxis->ubounds[i] = parameter_to_double(values[i]);
if (zaxis.size == 0) cdo_abort("size undefined (zaxis description file: %s)!", dname);
if (zaxis.size != nvalues) cdo_abort("size=%zu and number of ubounds=%zu differ!", zaxis.size, nvalues);
zaxis.ubounds.resize(zaxis.size);
for (size_t i = 0; i < zaxis.size; ++i) zaxis.ubounds[i] = parameter_to_double(values[i]);
}
else if (key == "vct")
{
if (zaxis->vctsize == 0) cdo_abort("vctsize undefined (zaxis description file: %s)!", dname);
if (zaxis->vctsize != nvalues) cdo_abort("vctsize=%zu and size of vct=%zu differ!", zaxis->vctsize, nvalues);
zaxis->vct.resize(zaxis->vctsize);
for (size_t i = 0; i < zaxis->vctsize; ++i) zaxis->vct[i] = parameter_to_double(values[i]);
if (zaxis.vctsize == 0) cdo_abort("vctsize undefined (zaxis description file: %s)!", dname);
if (zaxis.vctsize != nvalues) cdo_abort("vctsize=%zu and size of vct=%zu differ!", zaxis.vctsize, nvalues);
zaxis.vct.resize(zaxis.vctsize);
for (size_t i = 0; i < zaxis.vctsize; ++i) zaxis.vct[i] = parameter_to_double(values[i]);
}
else
{
......@@ -267,10 +267,10 @@ zaxis_from_file(FILE *zfp, const char *filename)
ik++;
}
zaxis_t zaxis;
ZaxisDesciption zaxis;
size_t natts = 0;
zaxis_read_data(nkv, kvmap.data(), &zaxis, natts, filename);
zaxis_read_data(nkv, kvmap.data(), zaxis, natts, filename);
int zaxisID = (zaxis.type == CDI_UNDEFID) ? CDI_UNDEFID : zaxisDefine(zaxis);
if (zaxisID != CDI_UNDEFID && natts > 0) zaxis_read_attributes(natts, nkv, kvmap.data(), zaxisID);
......@@ -279,11 +279,11 @@ zaxis_from_file(FILE *zfp, const char *filename)
}
static void
gen_zaxis_height(zaxis_t *zaxis, const char *pline)
gen_zaxis_height(ZaxisDesciption &zaxis, const char *pline)
{
int zaxistype = ZAXIS_HEIGHT;
if (Options::CMOR_Mode) zaxis->scalar = true;
if (Options::CMOR_Mode) zaxis.scalar = true;
if (*pline != 0)
{
......@@ -306,18 +306,18 @@ gen_zaxis_height(zaxis_t *zaxis, const char *pline)
if (*pline == 0) return;
const char *units = pline;
zaxis->type = zaxistype;
zaxis->size = 1;
// zaxis->scalar = true;
zaxis->vals.resize(1);
zaxis->vals[0] = value;
strcpy(zaxis->units, units);
zaxis.type = zaxistype;
zaxis.size = 1;
// zaxis.scalar = true;
zaxis.vals.resize(1);
zaxis.vals[0] = value;
strcpy(zaxis.units, units);
auto len = strlen(units);
if (len > 2 && units[len - 2] == '_' && units[len - 1] == 's')
{
zaxis->units[len - 2] = 0;
zaxis->scalar = true;
zaxis.units[len - 2] = 0;
zaxis.scalar = true;
}
}
}
......@@ -332,7 +332,7 @@ zaxis_from_name(const char *zaxisnameptr)
auto zaxisname = strdup(zaxisnameptr);
cstr_to_lower(zaxisname);
zaxis_t zaxis;
ZaxisDesciption zaxis;
auto pline = zaxisname;
if (cdo_cmpstrLenRhs(pline, "surface")) // surface
......@@ -345,7 +345,7 @@ zaxis_from_name(const char *zaxisnameptr)
else if (cdo_cmpstrLenRhs(zaxisname, "height", len))
{
pline = &zaxisname[len];
gen_zaxis_height(&zaxis, pline);
gen_zaxis_height(zaxis, pline);
}
if (zaxis.type != CDI_UNDEFID) zaxisID = zaxisDefine(zaxis);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment