Commit 949a0a3f authored by Uwe Schulzweida's avatar Uwe Schulzweida
Browse files

Replaced cdiGridInqKeyStr() by cdiInqKeyString() for CDI_KEY_NAME.

parent b7ccaaa1
......@@ -18,7 +18,9 @@ extern "C" {
#define CDI_MAX_NAME 256 // Max length of a name
#define CDI_UNDEFID -1
#define CDI_GLOBAL -1 // Global var ID for vlist
#define CDI_GLOBAL -1 // Global var ID for vlist and grid
#define CDI_XAXIS 1 // X-axis ID for grid
#define CDI_YAXIS 2 // Y-axis ID for grid
// Byte order
......
......@@ -11,7 +11,7 @@ cdi_keys_t *vlist_get_keysp(vlist_t *vlistptr, int varID)
{
cdi_keys_t *keysp = NULL;
if ( varID == CDI_GLOBAL )
if (varID == CDI_GLOBAL)
{
keysp = &vlistptr->keys;
}
......@@ -29,10 +29,18 @@ cdi_keys_t *grid_get_keysp(grid_t *gridptr, int varID)
{
cdi_keys_t *keysp = NULL;
if ( varID == CDI_GLOBAL )
if (varID == CDI_GLOBAL)
{
keysp = &gridptr->keys;
}
else if (varID == CDI_XAXIS)
{
keysp = &gridptr->x.keys;
}
else if (varID == CDI_YAXIS)
{
keysp = &gridptr->y.keys;
}
return keysp;
}
......@@ -55,7 +63,6 @@ cdi_key_t *new_key(cdi_keys_t *keysp, int key)
return keyp;
}
static
cdi_key_t *find_key(cdi_keys_t *keysp, int key)
{
xassert(keysp != NULL);
......@@ -292,7 +299,7 @@ int cdiInqKeyBytes(int cdiID, int varID, int key, unsigned char *bytes, int *len
xassert(bytes != NULL);
xassert(length != NULL);
if ( varID != CDI_GLOBAL ) status = cdiInqKeyBytes(cdiID, CDI_GLOBAL, key, bytes, length);
// if ( varID != CDI_GLOBAL ) status = cdiInqKeyBytes(cdiID, CDI_GLOBAL, key, bytes, length);
cdi_keys_t *keysp = cdi_get_keysp(cdiID, varID);
xassert(keysp != NULL);
......
......@@ -25,6 +25,7 @@ typedef struct {
void cdiDefVarKeyInt(cdi_keys_t *keysp, int key, int value);
void cdiDefVarKeyBytes(cdi_keys_t *keysp, int key, const unsigned char *bytes, int length);
cdi_key_t *find_key(cdi_keys_t *keysp, int key);
void cdiCopyVarKeys(cdi_keys_t *keysp, int cdiID2, int varID2);
void cdiDeleteVarKeys(cdi_keys_t *keysp);
......
......@@ -133,46 +133,50 @@ void grid_axis_init(struct gridaxis_t *axisptr)
axisptr->stdname = NULL;
axisptr->keys.nalloc = MAX_KEYS;
axisptr->keys.nelems = 0;
for ( int i = 0; i < MAX_KEYS; ++i )
axisptr->keys.value[i].length = 0;
}
void grid_init(grid_t *gridptr)
{
gridptr->self = CDI_UNDEFID;
gridptr->type = CDI_UNDEFID;
gridptr->proj = CDI_UNDEFID;
gridptr->projtype = CDI_UNDEFID;
gridptr->mask = NULL;
gridptr->mask_gme = NULL;
gridptr->size = 0;
gridptr->self = CDI_UNDEFID;
gridptr->type = CDI_UNDEFID;
gridptr->proj = CDI_UNDEFID;
gridptr->projtype = CDI_UNDEFID;
gridptr->mask = NULL;
gridptr->mask_gme = NULL;
gridptr->size = 0;
grid_axis_init(&gridptr->x);
grid_axis_init(&gridptr->y);
gridptr->area = NULL;
gridptr->reducedPoints = NULL;
gridptr->reducedPointsSize = 0;
gridptr->gme.nd = 0;
gridptr->gme.ni = 0;
gridptr->gme.ni2 = 0;
gridptr->gme.ni3 = 0;
gridptr->trunc = 0;
gridptr->nvertex = 0;
gridptr->number = 0;
gridptr->position = 0;
gridptr->reference = NULL;
gridptr->datatype = CDI_DATATYPE_FLT64;
gridptr->np = 0;
gridptr->isCyclic = CDI_UNDEFID;
gridptr->lcomplex = false;
gridptr->hasdims = true;
gridptr->area = NULL;
gridptr->reducedPoints = NULL;
gridptr->reducedPointsSize = 0;
gridptr->gme.nd = 0;
gridptr->gme.ni = 0;
gridptr->gme.ni2 = 0;
gridptr->gme.ni3 = 0;
gridptr->trunc = 0;
gridptr->nvertex = 0;
gridptr->number = 0;
gridptr->position = 0;
gridptr->reference = NULL;
gridptr->datatype = CDI_DATATYPE_FLT64;
gridptr->np = 0;
gridptr->isCyclic = CDI_UNDEFID;
gridptr->lcomplex = false;
gridptr->hasdims = true;
memset(gridptr->uuid, 0, CDI_UUID_SIZE);
gridptr->name = NULL;
gridptr->vtable = &cdiGridVtable;
gridptr->keys.nalloc = MAX_KEYS;
gridptr->keys.nelems = 0;
for ( int i = 0; i < MAX_KEYS; ++i )
gridptr->keys.value[i].length = 0;
gridptr->atts.nalloc = MAX_ATTRIBUTES;
gridptr->atts.nelems = 0;
gridptr->iScansNegatively = 0;
......@@ -279,6 +283,13 @@ void gridGetString(char *name, const char *gridstrname, size_t len)
name[len - 1] = 0;
}
static inline
void gridaxisSetKey(struct gridaxis_t *axisptr, int key, const char *name)
{
if (find_key(&axisptr->keys, key) == NULL)
cdiDefVarKeyBytes(&axisptr->keys, key, (const unsigned char*)name, (int)strlen(name)+1);
}
static inline
void gridSetName(char *gridstrname, const char *name)
{
......@@ -315,8 +326,8 @@ void cdiGridTypeInit(grid_t *gridptr, int gridtype, size_t size)
}
else
{
if ( !gridptr->x.name[0] ) gridSetName(gridptr->x.name, "lon");
if ( !gridptr->y.name[0] ) gridSetName(gridptr->y.name, "lat");
gridaxisSetKey(&gridptr->x, CDI_KEY_NAME, "lon");
gridaxisSetKey(&gridptr->y, CDI_KEY_NAME, "lat");
}
if ( !gridptr->x.longname[0] ) gridSetName(gridptr->x.longname, "longitude");
......@@ -622,10 +633,8 @@ void *grid_key_to_ptr(grid_t *gridptr, int key)
switch (key)
{
case CDI_KEY_XNAME: keyptr = (void*)gridptr->x.name; break;
case CDI_KEY_XLONGNAME: keyptr = (void*)gridptr->x.longname; break;
case CDI_KEY_XUNITS: keyptr = (void*)gridptr->x.units; break;
case CDI_KEY_YNAME: keyptr = (void*)gridptr->y.name; break;
case CDI_KEY_YLONGNAME: keyptr = (void*)gridptr->y.longname; break;
case CDI_KEY_YUNITS: keyptr = (void*)gridptr->y.units; break;
case CDI_KEY_XDIMNAME: keyptr = (void*)gridptr->x.dimname; break;
......@@ -728,7 +737,7 @@ The function @func{gridDefXname} defines the name of a X-axis.
*/
void gridDefXname(int gridID, const char *xname)
{
(void)cdiGridDefKeyStr(gridID, CDI_KEY_XNAME, CDI_MAX_NAME, xname);
(void)cdiDefKeyString(gridID, CDI_XAXIS, CDI_KEY_NAME, xname);
}
/*
......@@ -785,7 +794,7 @@ The function @func{gridDefYname} defines the name of a Y-axis.
*/
void gridDefYname(int gridID, const char *yname)
{
(void)cdiGridDefKeyStr(gridID, CDI_KEY_YNAME, CDI_MAX_NAME, yname);
(void)cdiDefKeyString(gridID, CDI_YAXIS, CDI_KEY_NAME, yname);
}
/*
......@@ -845,9 +854,10 @@ The function @func{gridInqXname} returns the name of a X-axis.
@EndFunction
*/
void gridInqXname(int gridID, char *xname)
void gridInqXname(int gridID, char *name)
{
(void)cdiGridInqKeyStr(gridID, CDI_KEY_XNAME, CDI_MAX_NAME, xname);
int length = CDI_MAX_NAME;
(void)cdiInqKeyString(gridID, CDI_XAXIS, CDI_KEY_NAME, name, &length);
}
/*
......@@ -928,9 +938,10 @@ The function @func{gridInqYname} returns the name of a Y-axis.
@EndFunction
*/
void gridInqYname(int gridID, char *yname)
void gridInqYname(int gridID, char *name)
{
(void)cdiGridInqKeyStr(gridID, CDI_KEY_YNAME, CDI_MAX_NAME, yname);
int length = CDI_MAX_NAME;
(void)cdiInqKeyString(gridID, CDI_YAXIS, CDI_KEY_NAME, name, &length);
}
/*
......@@ -3449,7 +3460,8 @@ void gridPrintKernel(int gridID, int opt, FILE *fp)
if ( nxvals > 0 )
{
attstr[0] = 0; cdiGridInqKeyStr(gridID, CDI_KEY_XNAME, CDI_MAX_NAME, attstr);
int length = CDI_MAX_NAME;
cdiInqKeyString(gridID, CDI_XAXIS, CDI_KEY_NAME, attstr, &length);
if ( attstr[0] ) fprintf(fp, "xname = %s\n", attstr);
attstr2[0] = 0; cdiGridInqKeyStr(gridID, CDI_KEY_XDIMNAME, CDI_MAX_NAME, attstr2);
if ( attstr2[0] && strcmp(attstr, attstr2) ) fprintf(fp, "xdimname = %s\n", attstr2);
......@@ -3461,7 +3473,8 @@ void gridPrintKernel(int gridID, int opt, FILE *fp)
if ( nyvals > 0 )
{
attstr[0] = 0; cdiGridInqKeyStr(gridID, CDI_KEY_YNAME, CDI_MAX_NAME, attstr);
int length = CDI_MAX_NAME;
cdiInqKeyString(gridID, CDI_YAXIS, CDI_KEY_NAME, attstr, &length);
if ( attstr[0] ) fprintf(fp, "yname = %s\n", attstr);
attstr2[0] = 0; cdiGridInqKeyStr(gridID, CDI_KEY_YDIMNAME, CDI_MAX_NAME, attstr2);
if ( attstr2[0] && strcmp(attstr, attstr2) ) fprintf(fp, "ydimname = %s\n", attstr2);
......
......@@ -2069,7 +2069,8 @@ void cdf_load_cellarea(size_t size, ncvar_t *ncvar, double **gridarea, struct cd
static
void cdf_copy_axis_attr(ncvar_t *ncvar, struct gridaxis_t *gridaxis)
{
strcpy(gridaxis->name, ncvar->name);
//strcpy(gridaxis->name, ncvar->name);
cdiDefVarKeyBytes(&gridaxis->keys, CDI_KEY_NAME, (const unsigned char*)ncvar->name, (int)sizeof(ncvar->name)+1);
strcpy(gridaxis->longname, ncvar->longname);
strcpy(gridaxis->units, ncvar->units);
#ifndef USE_MPI
......
......@@ -225,7 +225,7 @@ void cdfDefFC(stream_t *streamptr, int gridID, int gridindex)
static const struct cdfDefGridAxisInqs {
size_t (*axisSize)(int gridID);
int (*axisDimname)(int cdiID, int key, int size, char *mesg);
int (*axisName)(int cdiID, int key, int size, char *mesg);
int (*axisName)(int cdiID, int varID, int key, char *string, int *length);
int (*axisLongname)(int cdiID, int key, int size, char *mesg);
int (*axisUnits)(int cdiID, int key, int size, char *mesg);
void (*axisStdname)(int cdiID, char *dimstdname);
......@@ -235,7 +235,7 @@ static const struct cdfDefGridAxisInqs {
} gridInqsX = {
.axisSize = gridInqXsize,
.axisDimname = cdiGridInqKeyStr,
.axisName = cdiGridInqKeyStr,
.axisName = cdiInqKeyString,
.axisLongname = cdiGridInqKeyStr,
.axisUnits = cdiGridInqKeyStr,
.axisStdname = gridInqXstdname,
......@@ -245,7 +245,7 @@ static const struct cdfDefGridAxisInqs {
}, gridInqsY = {
.axisSize = gridInqYsize,
.axisDimname = cdiGridInqKeyStr,
.axisName = cdiGridInqKeyStr,
.axisName = cdiInqKeyString,
.axisLongname = cdiGridInqKeyStr,
.axisUnits = cdiGridInqKeyStr,
.axisStdname = gridInqYstdname,
......@@ -300,9 +300,10 @@ cdfDefTrajLatLon(stream_t *streamptr, int gridID, int gridindex,
const int fileID = streamptr->fileID;
if ( streamptr->ncmode == 2 ) cdf_redef(fileID);
char axisname[CDI_MAX_NAME]; axisname[0] = 0;
const int keyname = (dimtype == 'X') ? CDI_KEY_XNAME : CDI_KEY_YNAME;
inqs->axisName(gridID, keyname, CDI_MAX_NAME, axisname);
char axisname[CDI_MAX_NAME];
const int axistype = (dimtype == 'X') ? CDI_XAXIS : CDI_YAXIS;
int length = CDI_MAX_NAME;
inqs->axisName(gridID, axistype, CDI_KEY_NAME, axisname, &length);
cdf_def_var(fileID, axisname, xtype, 1, &dimNcID, &ncvarid);
cdfPutGridStdAtts(fileID, ncvarid, gridID, dimtype, inqs);
cdf_enddef(fileID);
......@@ -477,9 +478,10 @@ cdfDefAxisCommon(stream_t *streamptr, int gridID, int gridindex, int ndims, bool
if ( dimID == CDI_UNDEFID )
{
int ncvarid = CDI_UNDEFID, ncbvarid = CDI_UNDEFID;
char axisname[CDI_MAX_NAME]; axisname[0] = 0;
const int keyname = (axisLetter == 'X') ? CDI_KEY_XNAME : CDI_KEY_YNAME;
gridAxisInq->axisName(gridID, keyname, CDI_MAX_NAME, axisname);
char axisname[CDI_MAX_NAME];
const int axistype = (axisLetter == 'X') ? CDI_XAXIS : CDI_YAXIS;
int length = CDI_MAX_NAME;
gridAxisInq->axisName(gridID, axistype, CDI_KEY_NAME, axisname, &length);
if ( axisname[0] == 0 ) Error("axis name undefined!");
checkGridName(axisname, fileID);
......@@ -700,8 +702,9 @@ cdfDefIrregularGridCommon(stream_t *streamptr, int gridID,
*xboundsPtr = NULL;
if ( xvalsPtr )
{
char xaxisname[CDI_MAX_NAME]; xaxisname[0] = 0;
cdiGridInqKeyStr(gridID, CDI_KEY_XNAME, CDI_MAX_NAME, xaxisname);
char xaxisname[CDI_MAX_NAME];
int length = CDI_MAX_NAME;
cdiInqKeyString(gridID, CDI_XAXIS, CDI_KEY_NAME, xaxisname, &length);
checkGridName(xaxisname, fileID);
cdf_def_var(fileID, xaxisname, xtype, ndims-1, dimIDs, &ncxvarid);
cdfGridCompress(fileID, ncxvarid, xdimlen*ydimlen, streamptr->filetype, streamptr->comptype);
......@@ -1701,19 +1704,21 @@ void cdfDefCharacter(stream_t *streamptr, int gridID, int gridindex, int xory, i
dimIDs[0] = dimID;
dimIDs[1] = strlenID;
char axisname[CDI_MAX_NAME]; axisname[0] = 0;
char axisname[CDI_MAX_NAME];
char **cvals = (char **) Malloc(dimlen * sizeof(char *));
for ( size_t i = 0; i < dimlen; i++ )
cvals[i] = (char*) Malloc(strlen * sizeof(char));
int ncaxisid;
if ( xory == 0 )
{
cdiGridInqKeyStr(gridID, CDI_KEY_XNAME, CDI_MAX_NAME, axisname);
int length = CDI_MAX_NAME;
cdiInqKeyString(gridID, CDI_XAXIS, CDI_KEY_NAME, axisname, &length);
gridInqXCvals(gridID, cvals);
}
else
{
cdiGridInqKeyStr(gridID, CDI_KEY_YNAME, CDI_MAX_NAME, axisname);
int length = CDI_MAX_NAME;
cdiInqKeyString(gridID, CDI_YAXIS, CDI_KEY_NAME, axisname, &length);
gridInqXCvals(gridID, cvals);
}
int status = nc_inq_varid(fileID, axisname, &ncaxisid);
......
......@@ -107,6 +107,8 @@ void vlist_init_entry(vlist_t *vlistptr)
vlistptr->ntsteps = CDI_UNDEFID;
vlistptr->keys.nalloc = MAX_KEYS;
vlistptr->keys.nelems = 0;
for ( int i = 0; i < MAX_KEYS; ++i )
vlistptr->keys.value[i].length = 0;
vlistptr->atts.nalloc = MAX_ATTRIBUTES;
vlistptr->atts.nelems = 0;
vlistptr->nsubtypes = 0;
......
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