Commit 6db4a4f1 authored by Uwe Schulzweida's avatar Uwe Schulzweida
Browse files

Replaced vlistDefVarUnits()/vlistInqVarUnits() by...

Replaced vlistDefVarUnits()/vlistInqVarUnits() by cdiDefKeyString()/cdiInqKeyString() with CDI_KEY_UNITS.
parent 38356003
......@@ -2,6 +2,7 @@
* Replaced vlistDefVarName()/vlistInqVarName() by cdiDefKeyString()/cdiInqKeyString() with CDI_KEY_NAME
* Replaced vlistDefVarLongname()/vlistInqVarLongname() by cdiDefKeyString()/cdiInqKeyString() with CDI_KEY_LONGNAME
* Replaced vlistDefVarUnits()/vlistInqVarUnits() by cdiDefKeyString()/cdiInqKeyString() with CDI_KEY_UNITS
2020-05-15 Uwe Schulzweida
......
......@@ -3221,7 +3221,7 @@ void cdf_define_institut_and_model_id(int vlistID, int varID)
{
cdiDeleteKey(vlistID, varID, CDI_KEY_NAME);
cdiDeleteKey(vlistID, varID, CDI_KEY_LONGNAME);
vlistDestroyVarUnits(vlistID, varID);
cdiDeleteKey(vlistID, varID, CDI_KEY_UNITS);
if ( varTableID != CDI_UNDEFID )
{
......
......@@ -230,7 +230,6 @@ void vlist_delete(vlist_t *vlistptr)
{
if ( vars[varID].levinfo ) Free(vars[varID].levinfo);
if ( vars[varID].stdname ) Free(vars[varID].stdname);
if ( vars[varID].units ) Free(vars[varID].units);
if ( vlistptr->vars[varID].opt_grib_kvpair )
{
......@@ -292,7 +291,6 @@ static
void var_copy_entries(var_t *var2, var_t *var1)
{
if ( var1->stdname ) var2->stdname = strdupx(var1->stdname);
if ( var1->units ) var2->units = strdupx(var1->units);
var2->opt_grib_kvpair_size = 0;
var2->opt_grib_kvpair = NULL;
......@@ -1117,20 +1115,20 @@ void vlistPrintKernel(vlist_t *vlistptr, FILE *fp)
int zaxisID = vlistptr->vars[varID].zaxisID;
int subtypeID = vlistptr->vars[varID].subtypeID;
int tsteptype = vlistptr->vars[varID].tsteptype;
char name[CDI_MAX_NAME], longname[CDI_MAX_NAME];
char name[CDI_MAX_NAME], longname[CDI_MAX_NAME], units[CDI_MAX_NAME];
int length = CDI_MAX_NAME;
(void)cdiInqKeyString(vlistID, varID, CDI_KEY_NAME, name, &length);
length = CDI_MAX_NAME;
(void)cdiInqKeyString(vlistID, varID, CDI_KEY_LONGNAME, longname, &length);
const char *units = vlistptr->vars[varID].units;
length = CDI_MAX_NAME;
(void)cdiInqKeyString(vlistID, varID, CDI_KEY_UNITS, units, &length);
int flag = vlistptr->vars[varID].flag;
int iorank = vlistptr->vars[varID].iorank;
char paramstr[32];
cdiParamToString(param, paramstr, sizeof(paramstr));
fprintf(fp, "%6d %-8s %6d %6d %6d %6d %5d %6d %-8s %s [%s]\n",
varID, paramstr, gridID, zaxisID, subtypeID, tsteptype, flag, iorank,
name, longname, units?units:"");
varID, paramstr, gridID, zaxisID, subtypeID, tsteptype, flag, iorank, name, longname, units);
}
fputs("\n"
......
......@@ -67,7 +67,6 @@ typedef struct
bool missvalused; // true if missval is defined
bool lvalidrange;
char *stdname;
char *units;
char *extra;
double missval;
double scalefactor;
......@@ -121,7 +120,6 @@ void cdiVlistMakeInternal(int vlistID);
void cdiVlistMakeImmutable(int vlistID);
void vlistCheckVarID(const char *caller, int vlistID, int varID);
void vlistDestroyVarStdname(int vlistID, int varID);
void vlistDestroyVarUnits(int vlistID, int varID);
void cdiVlistDestroy_(int vlistID);
int vlistInqVarMissvalUsed(int vlistID, int varID);
int vlistHasTime(int vlistID);
......
......@@ -36,7 +36,6 @@ void vlistvarInitEntry(int vlistID, int varID)
vlistptr->vars[varID].addoffset = 0.0;
vlistptr->vars[varID].scalefactor = 1.0;
vlistptr->vars[varID].stdname = NULL;
vlistptr->vars[varID].units = NULL;
vlistptr->vars[varID].extra = NULL;
vlistptr->vars[varID].levinfo = NULL;
vlistptr->vars[varID].comptype = CDI_COMPRESS_NONE;
......@@ -609,14 +608,15 @@ otherwise the result is an empty string.
*/
void vlistInqVarUnits(int vlistID, int varID, char *units)
{
vlist_t *vlistptr = vlist_to_pointer(vlistID);
int length = CDI_MAX_NAME;
(void)cdiInqKeyString(vlistID, varID, CDI_KEY_UNITS, units, &length);
vlistCheckVarID(__func__, vlistID, varID);
if (!units[0])
{
vlistCheckVarID(__func__, vlistID, varID);
units[0] = '\0';
vlist_t *vlistptr = vlist_to_pointer(vlistID);
if ( vlistptr->vars[varID].units == NULL )
{
int param = vlistptr->vars[varID].param;
int pdis, pcat, pnum;
cdiDecodeParam(param, &pnum, &pcat, &pdis);
......@@ -627,8 +627,6 @@ void vlistInqVarUnits(int vlistID, int varID, char *units)
tableInqEntry(tableID, code, -1, NULL, NULL, units);
}
}
else
strcpy(units, vlistptr->vars[varID].units);
return;
}
......@@ -900,21 +898,7 @@ The function @func{vlistDefVarUnits} defines the units of a variable.
*/
void vlistDefVarUnits(int vlistID, int varID, const char *units)
{
vlist_t *vlistptr = vlist_to_pointer(vlistID);
vlistCheckVarID(__func__, vlistID, varID);
if ( units )
{
if ( vlistptr->vars[varID].units )
{
Free(vlistptr->vars[varID].units);
vlistptr->vars[varID].units = 0;
}
vlistptr->vars[varID].units = strdupx(units);
reshSetStatus(vlistID, &vlistOps, RESH_DESYNC_IN_USE);
}
if (units) (void)cdiDefKeyString(vlistID, varID, CDI_KEY_UNITS, units);
}
/*
......@@ -1193,18 +1177,6 @@ void vlistDestroyVarStdname(int vlistID, int varID)
}
void vlistDestroyVarUnits(int vlistID, int varID)
{
vlist_t *vlistptr = vlist_to_pointer(vlistID);
if ( vlistptr->vars[varID].units )
{
Free(vlistptr->vars[varID].units);
vlistptr->vars[varID].units = NULL;
reshSetStatus(vlistID, &vlistOps, RESH_DESYNC_IN_USE);
}
}
int vlistInqVarMissvalUsed(int vlistID, int varID)
{
const vlist_t *vlistptr = vlist_to_pointer(vlistID);
......@@ -1591,7 +1563,7 @@ int vlistVarCompare(vlist_t *a, int varIDA, vlist_t *b, int varIDB)
| FCMP(chunktype) | FCMP(xyz) | FCMP2(gridID) | FCMP2(zaxisID)
| FCMP2(instID) | FCMP2(modelID) | FCMP2(tableID) | FCMP(missvalused)
| FCMPFLT(missval) | FCMPFLT(addoffset) | FCMPFLT(scalefactor)
| FCMPSTR(stdname) | FCMPSTR(units) | FCMPSTR(extra)
| FCMPSTR(stdname) | FCMPSTR(extra)
| FCMP(comptype) | FCMP(complevel) | FCMP(lvalidrange)
| FCMPFLT(validrange[0]) | FCMPFLT(validrange[1]);
#undef FCMP
......
......@@ -10,13 +10,11 @@
#endif
int vlistVarGetPackSize(vlist_t *p, int varID, void *context);
void vlistVarPack(vlist_t *p, int varID,
char * buffer, int bufferSize, int * pos, void *context);
void vlistVarUnpack(int vlistID,
char * buf, int size, int *position, int, void *context);
void vlistVarPack(vlist_t *p, int varID, char * buffer, int bufferSize, int * pos, void *context);
void vlistVarUnpack(int vlistID, char * buf, int size, int *position, int, void *context);
int vlistVarCompare(vlist_t *a, int varIDA, vlist_t *b, int varIDB);
void vlistDefVarIOrank ( int, int, int );
int vlistInqVarIOrank ( int, int );
void vlistDefVarIOrank( int, int, int );
int vlistInqVarIOrank( int, int );
void cdiVlistCreateVarLevInfo(vlist_t *vlistptr, int varID);
......
......@@ -11,9 +11,7 @@ enum {
VLISTVAR_PACK_INT_IDX_GRIDID,
VLISTVAR_PACK_INT_IDX_ZAXISID,
VLISTVAR_PACK_INT_IDX_TIMETYPE,
VLISTVAR_PACK_INT_IDX_LONGNAMESZ,
VLISTVAR_PACK_INT_IDX_STDNAMESZ,
VLISTVAR_PACK_INT_IDX_UNITSSZ,
VLISTVAR_PACK_INT_IDX_DATATYPE,
VLISTVAR_PACK_INT_IDX_PARAM,
VLISTVAR_PACK_INT_IDX_INSTID,
......@@ -38,12 +36,8 @@ int vlistVarGetPackSize(vlist_t *p, int varID, void *context)
var_t *var = p->vars + varID;
int varsize = serializeGetSize(vlistvarNint, CDI_DATATYPE_INT, context)
+ serializeGetSize(vlistvar_ndbls, CDI_DATATYPE_FLT64, context);
if (var->longname)
varsize += serializeGetSize((int)strlen(var->longname), CDI_DATATYPE_TXT, context);
if (var->stdname)
varsize += serializeGetSize((int)strlen(var->stdname), CDI_DATATYPE_TXT, context);
if (var->units)
varsize += serializeGetSize((int)strlen(var->units), CDI_DATATYPE_TXT, context);
if (var->extra)
varsize += serializeGetSize((int)strlen(var->extra), CDI_DATATYPE_TXT, context);
varsize += serializeGetSize(4 * zaxisInqSize(var->zaxisID), CDI_DATATYPE_INT, context);
......@@ -59,15 +53,13 @@ void vlistVarPack(vlist_t *p, int varID, char * buf, int size, int *position, vo
{
double dtempbuf[vlistvar_ndbls];
var_t *var = p->vars + varID;
int tempbuf[vlistvarNint], longnamesz, stdnamesz, unitssz, extralen;
int tempbuf[vlistvarNint], stdnamesz, extralen;
tempbuf[VLISTVAR_PACK_INT_IDX_FLAG] = var->flag;
tempbuf[VLISTVAR_PACK_INT_IDX_GRIDID] = var->gridID;
tempbuf[VLISTVAR_PACK_INT_IDX_ZAXISID] = var->zaxisID;
tempbuf[VLISTVAR_PACK_INT_IDX_TIMETYPE] = var->timetype;
tempbuf[VLISTVAR_PACK_INT_IDX_LONGNAMESZ] = longnamesz = var->longname?(int)strlen(var->longname):0;
tempbuf[VLISTVAR_PACK_INT_IDX_STDNAMESZ] = stdnamesz = var->stdname?(int)strlen(var->stdname):0;
tempbuf[VLISTVAR_PACK_INT_IDX_UNITSSZ] = unitssz = var->units?(int)strlen(var->units):0;
tempbuf[VLISTVAR_PACK_INT_IDX_DATATYPE] = var->datatype;
tempbuf[VLISTVAR_PACK_INT_IDX_PARAM] = var->param;
tempbuf[VLISTVAR_PACK_INT_IDX_INSTID] = var->instID;
......@@ -86,12 +78,8 @@ void vlistVarPack(vlist_t *p, int varID, char * buf, int size, int *position, vo
dtempbuf[2] = var->addoffset;
serializePack(tempbuf, vlistvarNint, CDI_DATATYPE_INT, buf, size, position, context);
serializePack(dtempbuf, vlistvar_ndbls, CDI_DATATYPE_FLT64,buf, size, position, context);
if (longnamesz)
serializePack(var->longname, longnamesz, CDI_DATATYPE_TXT, buf, size, position, context);
if (stdnamesz)
serializePack(var->stdname, stdnamesz, CDI_DATATYPE_TXT, buf, size, position, context);
if (unitssz)
serializePack(var->units, unitssz, CDI_DATATYPE_TXT, buf, size, position, context);
if (extralen)
serializePack(var->extra, extralen, CDI_DATATYPE_TXT, buf, size, position, context);
if (nlevs)
......@@ -136,19 +124,8 @@ void vlistVarUnpack(int vlistID, char * buf, int size, int *position,
namespaceAdaptKey ( tempbuf[VLISTVAR_PACK_INT_IDX_GRIDID], originNamespace ),
namespaceAdaptKey ( tempbuf[VLISTVAR_PACK_INT_IDX_ZAXISID], originNamespace ),
tempbuf[VLISTVAR_PACK_INT_IDX_TIMETYPE]);
if (tempbuf[VLISTVAR_PACK_INT_IDX_LONGNAMESZ] ||
tempbuf[VLISTVAR_PACK_INT_IDX_STDNAMESZ] || tempbuf[VLISTVAR_PACK_INT_IDX_UNITSSZ] ||
tempbuf[VLISTVAR_PACK_INT_IDX_EXTRALEN])
varname = (char *)Malloc((size_t)imax(imax(imax(tempbuf[VLISTVAR_PACK_INT_IDX_LONGNAMESZ],
tempbuf[VLISTVAR_PACK_INT_IDX_STDNAMESZ]),
tempbuf[VLISTVAR_PACK_INT_IDX_UNITSSZ]), tempbuf[VLISTVAR_PACK_INT_IDX_EXTRALEN]) + 1);
if (tempbuf[VLISTVAR_PACK_INT_IDX_LONGNAMESZ])
{
serializeUnpack(buf, size, position,
varname, tempbuf[VLISTVAR_PACK_INT_IDX_LONGNAMESZ], CDI_DATATYPE_TXT, context);
varname[tempbuf[VLISTVAR_PACK_INT_IDX_LONGNAMESZ]] = '\0';
vlistDefVarLongname(vlistID, newvar, varname);
}
if (tempbuf[VLISTVAR_PACK_INT_IDX_STDNAMESZ] || tempbuf[VLISTVAR_PACK_INT_IDX_EXTRALEN])
varname = (char *)Malloc((size_t)imax(tempbuf[VLISTVAR_PACK_INT_IDX_STDNAMESZ], tempbuf[VLISTVAR_PACK_INT_IDX_EXTRALEN]) + 1);
if (tempbuf[VLISTVAR_PACK_INT_IDX_STDNAMESZ])
{
serializeUnpack(buf, size, position,
......@@ -156,13 +133,6 @@ void vlistVarUnpack(int vlistID, char * buf, int size, int *position,
varname[tempbuf[VLISTVAR_PACK_INT_IDX_STDNAMESZ]] = '\0';
vlistDefVarStdname(vlistID, newvar, varname);
}
if (tempbuf[VLISTVAR_PACK_INT_IDX_UNITSSZ])
{
serializeUnpack(buf, size, position,
varname, tempbuf[VLISTVAR_PACK_INT_IDX_UNITSSZ], CDI_DATATYPE_TXT, context);
varname[tempbuf[VLISTVAR_PACK_INT_IDX_UNITSSZ]] = '\0';
vlistDefVarUnits(vlistID, newvar, varname);
}
if (tempbuf[VLISTVAR_PACK_INT_IDX_EXTRALEN])
{
serializeUnpack(buf, size, position,
......
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