Commit 28bd9690 authored by Uwe Schulzweida's avatar Uwe Schulzweida
Browse files

Replaced cdiZaxisDefKeyStr() by cdiDefKeyString() for key CDI_KEY_NAME.

parent 7cb4a1c5
......@@ -29,6 +29,14 @@ void cdiDefVarKeyBytes(cdi_keys_t *keysp, int key, const unsigned char *bytes, i
cdi_key_t *find_key(cdi_keys_t *keysp, int key);
const char *cdiInqVarKeyStringPtr(cdi_keys_t *keysp, int key);
static inline
const char *cdiInqVarKeyString(cdi_keys_t *keysp, int key)
{
const char *string = cdiInqVarKeyStringPtr(keysp, key);
if (string == NULL) string = "";
return string;
}
void cdiCopyVarKeys(cdi_keys_t *keysp, int cdiID2, int varID2);
void cdiDeleteVarKeys(cdi_keys_t *keysp);
void cdiDeleteKeys(int cdiID, int varID);
......
......@@ -269,22 +269,6 @@ unsigned cdiGridCount(void)
return reshCountType(&gridOps);
}
static inline
void gridSetString(char *gridstrname, const char *name, size_t len)
{
if ( len > CDI_MAX_NAME ) len = CDI_MAX_NAME;
strncpy(gridstrname, name, len - 1);
gridstrname[len - 1] = 0;
}
static inline
void gridGetString(char *name, const char *gridstrname, size_t len)
{
if ( len > CDI_MAX_NAME ) len = CDI_MAX_NAME;
strncpy(name, gridstrname, len);
name[len - 1] = 0;
}
static inline
void gridaxisSetKey(struct gridaxis_t *axisptr, int key, const char *name)
{
......@@ -2389,14 +2373,6 @@ int gridIsEqual(int gridID1, int gridID2)
}
*/
static
const char *gridInqKeyStringPtr(cdi_keys_t *keysp, int key)
{
const char *string = cdiInqVarKeyStringPtr(keysp, key);
if (string == NULL) string = "";
return string;
}
int gridCompareP(void *gridptr1, void *gridptr2)
{
grid_t *g1 = ( grid_t * ) gridptr1;
......@@ -2525,12 +2501,12 @@ int gridCompareP(void *gridptr1, void *gridptr2)
return differ;
}
if (strcmp(gridInqKeyStringPtr(&g1->x.keys, CDI_KEY_NAME), gridInqKeyStringPtr(&g2->x.keys, CDI_KEY_NAME))) return differ;
if (strcmp(gridInqKeyStringPtr(&g1->y.keys, CDI_KEY_NAME), gridInqKeyStringPtr(&g2->y.keys, CDI_KEY_NAME))) return differ;
if (strcmp(gridInqKeyStringPtr(&g1->x.keys, CDI_KEY_LONGNAME), gridInqKeyStringPtr(&g2->x.keys, CDI_KEY_LONGNAME))) return differ;
if (strcmp(gridInqKeyStringPtr(&g1->y.keys, CDI_KEY_LONGNAME), gridInqKeyStringPtr(&g2->y.keys, CDI_KEY_LONGNAME))) return differ;
if (strcmp(gridInqKeyStringPtr(&g1->x.keys, CDI_KEY_UNITS), gridInqKeyStringPtr(&g2->x.keys, CDI_KEY_UNITS))) return differ;
if (strcmp(gridInqKeyStringPtr(&g1->y.keys, CDI_KEY_UNITS), gridInqKeyStringPtr(&g2->y.keys, CDI_KEY_UNITS))) return differ;
if (strcmp(cdiInqVarKeyString(&g1->x.keys, CDI_KEY_NAME), cdiInqVarKeyString(&g2->x.keys, CDI_KEY_NAME))) return differ;
if (strcmp(cdiInqVarKeyString(&g1->y.keys, CDI_KEY_NAME), cdiInqVarKeyString(&g2->y.keys, CDI_KEY_NAME))) return differ;
if (strcmp(cdiInqVarKeyString(&g1->x.keys, CDI_KEY_LONGNAME), cdiInqVarKeyString(&g2->x.keys, CDI_KEY_LONGNAME))) return differ;
if (strcmp(cdiInqVarKeyString(&g1->y.keys, CDI_KEY_LONGNAME), cdiInqVarKeyString(&g2->y.keys, CDI_KEY_LONGNAME))) return differ;
if (strcmp(cdiInqVarKeyString(&g1->x.keys, CDI_KEY_UNITS), cdiInqVarKeyString(&g2->x.keys, CDI_KEY_UNITS))) return differ;
if (strcmp(cdiInqVarKeyString(&g1->y.keys, CDI_KEY_UNITS), cdiInqVarKeyString(&g2->y.keys, CDI_KEY_UNITS))) return differ;
if (g1->x.stdname != g2->x.stdname) return differ;
if (g1->y.stdname != g2->y.stdname) return differ;
......@@ -2611,17 +2587,17 @@ void gridComplete(grid_t *grid)
if ( grid->projtype == CDI_PROJ_RLL )
{
const char *name = gridInqKeyStringPtr(&grid->x.keys, CDI_KEY_NAME);
const char *name = cdiInqVarKeyString(&grid->x.keys, CDI_KEY_NAME);
if ( name[0] == 0 || name[0] == 'x' ) cdiDefKeyString(gridID, CDI_XAXIS, CDI_KEY_NAME, "rlon");
name = gridInqKeyStringPtr(&grid->y.keys, CDI_KEY_NAME);
name = cdiInqVarKeyString(&grid->y.keys, CDI_KEY_NAME);
if ( name[0] == 0 || name[0] == 'y' ) cdiDefKeyString(gridID, CDI_YAXIS, CDI_KEY_NAME, "rlat");
name = gridInqKeyStringPtr(&grid->x.keys, CDI_KEY_LONGNAME);
name = cdiInqVarKeyString(&grid->x.keys, CDI_KEY_LONGNAME);
if ( name[0] == 0 ) cdiDefKeyString(gridID, CDI_XAXIS, CDI_KEY_LONGNAME, "longitude in rotated pole grid");
name = gridInqKeyStringPtr(&grid->y.keys, CDI_KEY_LONGNAME);
name = cdiInqVarKeyString(&grid->y.keys, CDI_KEY_LONGNAME);
if ( name[0] == 0 ) cdiDefKeyString(gridID, CDI_YAXIS, CDI_KEY_LONGNAME, "latitude in rotated pole grid");
name = gridInqKeyStringPtr(&grid->x.keys, CDI_KEY_UNITS);
name = cdiInqVarKeyString(&grid->x.keys, CDI_KEY_UNITS);
if ( name[0] == 0 ) cdiDefKeyString(gridID, CDI_XAXIS, CDI_KEY_UNITS, "degrees");
name = gridInqKeyStringPtr(&grid->y.keys, CDI_KEY_UNITS);
name = cdiInqVarKeyString(&grid->y.keys, CDI_KEY_UNITS);
if ( name[0] == 0 ) cdiDefKeyString(gridID, CDI_YAXIS, CDI_KEY_UNITS, "degrees");
grid->x.stdname = xystdname_tab[grid_xystdname_grid_latlon][0];
grid->y.stdname = xystdname_tab[grid_xystdname_grid_latlon][1];
......
......@@ -113,7 +113,7 @@ static
void zaxis_init(zaxis_t *zaxisptr)
{
zaxisptr->self = CDI_UNDEFID;
zaxisptr->name[0] = 0;
// zaxisptr->name[0] = 0;
zaxisptr->longname[0] = 0;
zaxisptr->stdname[0] = 0;
zaxisptr->dimname[0] = 0;
......@@ -143,6 +143,7 @@ void zaxis_init(zaxis_t *zaxisptr)
zaxisptr->number = 0;
zaxisptr->nhlev = 0;
memset(zaxisptr->uuid, 0, CDI_UUID_SIZE);
zaxisptr->keys.nalloc = MAX_KEYS;
zaxisptr->keys.nelems = 0;
for ( int i = 0; i < MAX_KEYS; ++i )
......@@ -357,7 +358,7 @@ void *zaxis_key_to_ptr(zaxis_t *zaxisptr, int key)
switch (key)
{
case CDI_KEY_NAME: keyptr = (void*)zaxisptr->name; break;
// case CDI_KEY_NAME: keyptr = (void*)zaxisptr->name; break;
case CDI_KEY_LONGNAME: keyptr = (void*)zaxisptr->longname; break;
case CDI_KEY_UNITS: keyptr = (void*)zaxisptr->units; break;
case CDI_KEY_DIMNAME: keyptr = (void*)zaxisptr->dimname; break;
......@@ -536,7 +537,7 @@ The function @func{zaxisDefName} defines the name of a Z-axis.
*/
void zaxisDefName(int zaxisID, const char *name)
{
(void)cdiZaxisDefKeyStr(zaxisID, CDI_KEY_NAME, CDI_MAX_NAME, name);
(void)cdiDefKeyString(zaxisID, CDI_GLOBAL, CDI_KEY_NAME, name);
}
/*
......@@ -598,13 +599,14 @@ The function @func{zaxisInqName} returns the name of a Z-axis.
*/
void zaxisInqName(int zaxisID, char *name)
{
(void)cdiZaxisInqKeyStr(zaxisID, CDI_KEY_NAME, CDI_MAX_NAME, name);
int length = CDI_MAX_NAME;
(void)cdiInqKeyString(zaxisID, CDI_GLOBAL, CDI_KEY_NAME, name, &length);
}
const char *zaxisInqNamePtr(int zaxisID)
{
zaxis_t *zaxisptr = zaxis_to_pointer(zaxisID);
return zaxisptr->name;
return cdiInqVarKeyString(&zaxisptr->keys, CDI_KEY_NAME);
}
/*
......@@ -1361,6 +1363,14 @@ void zaxisResize(int zaxisID, int size)
zaxisptr->vals = (double *) Realloc(zaxisptr->vals, (size_t)size*sizeof(double));
}
static inline
void zaxisCopyKeyStr(zaxis_t *zaxisptr1, zaxis_t *zaxisptr2, int key)
{
cdi_key_t *keyp = find_key(&zaxisptr1->keys, key);
if (keyp && keyp->type == KEY_BYTES)
cdiDefVarKeyBytes(&zaxisptr2->keys, key, (const unsigned char*)keyp->v.s, (int)keyp->length);
}
int zaxisDuplicate(int zaxisID)
{
......@@ -1374,7 +1384,8 @@ int zaxisDuplicate(int zaxisID)
zaxis_copy(zaxisptrnew, zaxisptr);
strcpy(zaxisptrnew->name, zaxisptr->name);
zaxisCopyKeyStr(zaxisptr, zaxisptrnew, CDI_KEY_NAME);
//strcpy(zaxisptrnew->name, zaxisptr->name);
strcpy(zaxisptrnew->longname, zaxisptr->longname);
strcpy(zaxisptrnew->units, zaxisptr->units);
......@@ -1435,7 +1446,9 @@ void zaxisPrintKernel(zaxis_t *zaxisptr, FILE *fp)
const bool zscalar = (bool)zaxisptr->scalar;
if ( zscalar ) fprintf(fp, "scalar = true\n");
}
if ( zaxisptr->name[0] ) fprintf(fp, "name = %s\n", zaxisptr->name);
const char *string = cdiInqVarKeyString(&zaxisptr->keys, CDI_KEY_NAME);
if ( string[0] ) fprintf(fp, "name = %s\n", string);
if ( zaxisptr->longname[0] ) fprintf(fp, "longname = %s\n", zaxisptr->longname);
if ( zaxisptr->units[0] ) fprintf(fp, "units = %s\n", zaxisptr->units);
......@@ -1595,7 +1608,7 @@ int zaxisCompareP(zaxis_t *z1, zaxis_t *z2)
if (anyPresent)
xassert(size);
diff |= strcmp(z1->name, z2->name)
diff |= strcmp(cdiInqVarKeyString(&z1->keys, CDI_KEY_NAME), cdiInqVarKeyString(&z2->keys, CDI_KEY_NAME))
| strcmp(z1->longname, z2->longname)
| strcmp(z1->stdname, z2->stdname)
| strcmp(z1->units, z2->units)
......@@ -1619,8 +1632,7 @@ enum { zaxisNint = 8,
zaxisHasUUIDFlag = 1 << 5,
};
#define ZAXIS_STR_SERIALIZE { zaxisP->name, zaxisP->longname, \
zaxisP->stdname, zaxisP->units }
#define ZAXIS_STR_SERIALIZE { zaxisP->longname, zaxisP->stdname, zaxisP->units }
static
int zaxisGetMemberMask( zaxis_t * zaxisP )
......@@ -1676,6 +1688,8 @@ zaxisGetPackSize(void * voidP, void *context)
+= serializeStrTabGetPackSize(strTab, (int)numStr, context);
}
packBufferSize += serializeKeysGetPackSize(&zaxisP->keys, context);
packBufferSize += serializeGetSize(1, CDI_DATATYPE_UCHAR, context);
if (!cdiUUIDIsNull(zaxisP->uuid))
......@@ -1786,6 +1800,8 @@ zaxisUnpack(char * unpackBuffer, int unpackBufferSize,
strTab, numStr, context);
}
serializeKeysUnpack(unpackBuffer, unpackBufferSize, unpackBufferPos, &zaxisP->keys, context);
serializeUnpack(unpackBuffer, unpackBufferSize, unpackBufferPos,
&zaxisP->positive, 1, CDI_DATATYPE_UINT, context);
......@@ -1882,6 +1898,8 @@ zaxisPack(void * voidP, void * packBuffer, int packBufferSize,
packBuffer, packBufferSize, packBufferPos, context);
}
serializeKeysPack(&zaxisP->keys, packBuffer, packBufferSize, packBufferPos, context);
serializePack(&zaxisP->positive, 1, CDI_DATATYPE_UINT,
packBuffer, packBufferSize, packBufferPos, context);
......
......@@ -17,7 +17,7 @@ zkey_double_t;
typedef struct {
char dimname[CDI_MAX_NAME];
char vdimname[CDI_MAX_NAME];
char name[CDI_MAX_NAME];
// char name[CDI_MAX_NAME];
char longname[CDI_MAX_NAME];
char stdname[CDI_MAX_NAME];
char units[CDI_MAX_NAME];
......
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