Commit d2f2c891 authored by Uwe Schulzweida's avatar Uwe Schulzweida
Browse files

Replaced cdiZaxisDefKeyStr() by cdiDefKeyString() for CDI_KEY_PSNAME.

parent 071bcf51
......@@ -814,6 +814,12 @@ int cdiDefKeyInt(int cdiID, int varID, int key, int value);
// cdiInqKeyInt: Get an integer value from a key of a CDI variable
int cdiInqKeyInt(int cdiID, int varID, int key, int *value);
// cdiDefKeyFloat: Define a float value from a key of a CDI variable
int cdiDefKeyFloat(int cdiID, int varID, int key, double value);
// cdiInqKeyFloat Get a float value from a key of a CDI variable
int cdiInqKeyFloat(int cdiID, int varID, int key, double *value);
// cdiDefKeyBytes: Define a bytes array from a key of a CDI variable
int cdiDefKeyBytes(int cdiID, int varID, int key, const unsigned char bytes[], int length);
......@@ -843,9 +849,9 @@ int cdiCopyKeys(int cdiID1, int varID1, int cdiID2, int varID2);
#define CDI_KEY_LONGNAME 943 // Long name of the variable
#define CDI_KEY_STDNAME 944 // CF Standard name of the variable
#define CDI_KEY_UNITS 945 // Units of the variable
#define CDI_KEY_PSNAME 950 // Z-axis surface pressure name
#define CDI_KEY_P0NAME 951 // Z-axis reference pressure name
#define CDI_KEY_P0VALUE 952 // Z-axis reference pressure in Pa
#define CDI_KEY_PSNAME 950 // Z-axis surface pressure name
#define CDI_KEY_P0NAME 951 // Z-axis reference pressure name
#define CDI_KEY_P0VALUE 952 // Z-axis reference pressure in Pa
// cdiZaxisDefKeyStr: Define a CDI Z-axis string value from a key
int cdiZaxisDefKeyStr(int zaxisID, int key, int size, const char *mesg);
......@@ -853,12 +859,6 @@ int cdiZaxisDefKeyStr(int zaxisID, int key, int size, const char *mesg);
// cdiZaxisInqKeyStr: Get a CDI Z-axis string value from a key
int cdiZaxisInqKeyStr(int zaxisID, int key, int size, char *mesg);
// cdiZaxisDefKeyFlt: Define a CDI Z-axis floating point value from a key
int cdiZaxisDefKeyFlt(int zaxisID, int key, double value);
// cdiZaxisInqKeyFlt: Get a CDI Z-axis floating point value from a key
int cdiZaxisInqKeyFlt(int zaxisID, int key, double *value);
// gridDefXname: Define the name of a X-axis
void gridDefXname(int gridID, const char *xname);
......
......@@ -145,6 +145,10 @@ void cdiPrintVarKeys(cdi_keys_t *keysp)
{
printf("%d key %d length %d value %s\n", keyid+1, keyp->key, keyp->length, keyp->v.s);
}
else if (keyp->type == KEY_FLOAT)
{
printf("%d key %d value %g\n", keyid+1, keyp->key, keyp->v.d);
}
else if (keyp->type == KEY_INT)
{
printf("%d key %d value %d\n", keyid+1, keyp->key, keyp->v.i);
......@@ -222,7 +226,25 @@ void cdiDefVarKeyInt(cdi_keys_t *keysp, int key, int value)
}
}
// cdiDefKeyInt: Define an integer value from a key of a CDI variable
/*
@Function cdiDefKeyInt
@Title Define an integer value from a key of a CDI variable
@Prototype int cdiDefKeyInt(int cdiID, int varID, int key, int value)
@Parameter
@Item cdiID CDI ID, from a previous call to @fref{vlistCreate}, @fref{gridCreate} or @fref{zaxisCreate}.
@Item varID Variable identifier or CDI_GLOBAL.
@Item key The key to be searched
@Item value An integer where the data will be read
@Description
The function @func{cdiDefKeyInt} defines a CDI integer value from a key.
@Result
@func{cdiDefKeyInt} returns CDI_NOERR if OK.
@EndFunction
*/
int cdiDefKeyInt(int cdiID, int varID, int key, int value)
{
int status = CDI_NOERR;
......@@ -235,12 +257,30 @@ int cdiDefKeyInt(int cdiID, int varID, int key, int value)
return status;
}
// cdiInqKeyInt: Get an integer value from a key of a CDI variable
/*
@Function cdiInqKeyInt
@Title Get a CDI floating point value from a key
@Prototype int cdiInqKeyInt(int cdiID, int varID, int key, int *value)
@Parameter
@Item cdiID CDI ID, from a previous call to @fref{zaxisCreate}, @fref{gridCreate} or @fref{zaxisCreate}.
@Item varID Variable identifier or CDI_GLOBAL.
@Item key The key to be searched.
@Item value The address of an integer where the data will be retrieved.
@Description
The function @func{cdiInqKeyInt} return a CDI integer value from a key.
@Result
@func{cdiInqKeyInt} returns CDI_NOERR if key is available.
@EndFunction
*/
int cdiInqKeyInt(int cdiID, int varID, int key, int *value)
{
int status = -1;
if ( varID != CDI_GLOBAL ) status = cdiInqKeyInt(cdiID, CDI_GLOBAL, key, value);
// if ( varID != CDI_GLOBAL ) status = cdiInqKeyInt(cdiID, CDI_GLOBAL, key, value);
cdi_keys_t *keysp = cdi_get_keysp(cdiID, varID);
xassert(keysp != NULL);
......@@ -259,6 +299,94 @@ int cdiInqKeyInt(int cdiID, int varID, int key, int *value)
}
void cdiDefVarKeyFloat(cdi_keys_t *keysp, int key, double value)
{
cdi_key_t *keyp = find_key(keysp, key);
if ( keyp == NULL ) keyp = new_key(keysp, key);
if ( keyp != NULL )
{
//if ( keyp->v.i != value )
{
keyp->type = KEY_INT;
keyp->v.d = value;
}
}
}
/*
@Function cdiDefKeyFloat
@Title Define a floating point value from a key of a CDI variable
@Prototype int cdiDefKeyFloat(int cdiID, int varID, int key, double value)
@Parameter
@Item cdiID CDI ID, from a previous call to @fref{vlistCreate}, @fref{gridCreate} or @fref{zaxisCreate}.
@Item varID Variable identifier or CDI_GLOBAL.
@Item key The key to be searched
@Item value A double where the data will be read
@Description
The function @func{cdiDefKeyFloat} defines a CDI floating point value from a key.
@Result
@func{cdiDefKeyFloat} returns CDI_NOERR if OK.
@EndFunction
*/
int cdiDefKeyFloat(int cdiID, int varID, int key, double value)
{
int status = CDI_NOERR;
cdi_keys_t *keysp = cdi_get_keysp(cdiID, varID);
xassert(keysp != NULL);
cdiDefVarKeyFloat(keysp, key, value);
return status;
}
/*
@Function cdiInqKeyFloat
@Title Get a CDI floating point value from a key
@Prototype int cdiInqKeyFloat(int cdiID, int varID, int key, double *value)
@Parameter
@Item cdiID CDI ID, from a previous call to @fref{zaxisCreate}, @fref{gridCreate} or @fref{zaxisCreate}.
@Item varID Variable identifier or CDI_GLOBAL.
@Item key The key to be searched.
@Item value The address of a double where the data will be retrieved.
@Description
The function @func{cdiInqKeyFloat} return a CDI floating point value from a key.
@Result
@func{cdiInqKeyFloat} returns CDI_NOERR if key is available.
@EndFunction
*/
int cdiInqKeyFloat(int cdiID, int varID, int key, double *value)
{
int status = -1;
// if ( varID != CDI_GLOBAL ) status = cdiInqKeyFloat(cdiID, CDI_GLOBAL, key, value);
cdi_keys_t *keysp = cdi_get_keysp(cdiID, varID);
xassert(keysp != NULL);
cdi_key_t *keyp = find_key(keysp, key);
if ( keyp != NULL ) // key in use
{
if ( keyp->type == KEY_FLOAT )
{
*value = keyp->v.d;
status = CDI_NOERR;
}
}
return status;
}
void cdiDefVarKeyBytes(cdi_keys_t *keysp, int key, const unsigned char *bytes, int length)
{
cdi_key_t *keyp = find_key(keysp, key);
......@@ -323,11 +451,11 @@ int cdiInqKeyBytes(int cdiID, int varID, int key, unsigned char *bytes, int *len
/*
@Function cdiDefKeyString
@Title Define a CDI grid string value from a key
@Title Define a string value from a key of a CDI variable
@Prototype int cdiDefKeyString(int cdiID, int varID, int key, const char *string)
@Parameter
@Item cdiID CDI ID, from a previous call to @fref{vlistCreate} or @fref{gridCreate}.
@Item cdiID CDI ID, from a previous call to @fref{vlistCreate}, @fref{gridCreate} or @fref{zaxisCreate}.
@Item varID Variable identifier or CDI_GLOBAL.
@Item key The key to be searched.
@Item string The address of a string where the data will be read.
......@@ -352,18 +480,18 @@ int cdiDefKeyString(int cdiID, int varID, int key, const char *string)
/*
@Function cdiInqKeyString
@Title Get a CDI grid string value from a key
@Title Get a CDI string value from a key
@Prototype int cdiInqKeyString(int cdiID, int varID, int key, char *string, int *length)
@Parameter
@Item cdiID CDI ID, from a previous call to @fref{vlistCreate} or @fref{gridCreate}.
@Item cdiID CDI ID, from a previous call to @fref{vlistCreate}, @fref{gridCreate} or @fref{zaxisCreate}.
@Item varID Variable identifier or CDI_GLOBAL.
@Item key The key to be searched.
@Item string The address of a string where the data will be retrieved.
The caller must allocate space for the returned string.
@Item length The allocated length of the string on input.
@Description
The function @func{cdiInqKeyString} return a CDI grid string value from a key.
The function @func{cdiInqKeyString} return a CDI string value from a key.
@Result
@func{cdiInqKeyString} returns CDI_NOERR if key is available.
......
......@@ -25,7 +25,9 @@ typedef struct {
enum {KEY_INT = 1, KEY_FLOAT, KEY_BYTES};
void cdiDefVarKeyInt(cdi_keys_t *keysp, int key, int value);
void cdiDefVarKeyFloat(cdi_keys_t *keysp, int key, double 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);
const char *cdiInqVarKeyStringPtr(cdi_keys_t *keysp, int key);
......
......@@ -2983,13 +2983,13 @@ int cdf_define_all_zaxes(stream_t *streamptr, int vlistID, ncdim_t *ncdims, int
if ( zaxisType == ZAXIS_HYBRID )
{
if ( psvarid != -1 )
cdiZaxisDefKeyStr(zaxisID, CDI_KEY_PSNAME, (int)(strlen(ncvars[psvarid].name)+1), ncvars[psvarid].name);
cdiDefKeyString(zaxisID, CDI_GLOBAL, CDI_KEY_PSNAME, ncvars[psvarid].name);
if ( p0varid != -1 )
{
double px = 1;
cdf_get_var_double(ncvars[p0varid].ncid, p0varid, &px);
cdiZaxisDefKeyFlt(zaxisID, CDI_KEY_P0VALUE, px);
cdiZaxisDefKeyStr(zaxisID, CDI_KEY_P0NAME, (int)(strlen(ncvars[p0varid].name)+1), ncvars[p0varid].name);
cdiDefKeyFloat(zaxisID, CDI_GLOBAL, CDI_KEY_P0VALUE, px);
cdiDefKeyString(zaxisID, CDI_GLOBAL, CDI_KEY_P0NAME, ncvars[p0varid].name);
}
}
......
......@@ -1214,17 +1214,19 @@ void cdf_def_zaxis_hybrid_cf(stream_t *streamptr, int type, int *ncvaridp, int z
const int fileID = streamptr->fileID;
if ( streamptr->ncmode == 2 ) cdf_redef(fileID);
char psname[CDI_MAX_NAME]; psname[0] = 0;
cdiZaxisInqKeyStr(zaxisID, CDI_KEY_PSNAME, CDI_MAX_NAME, psname);
char psname[CDI_MAX_NAME];
int length = CDI_MAX_NAME;
cdiInqKeyString(zaxisID, CDI_GLOBAL, CDI_KEY_PSNAME, psname, &length);
if ( psname[0] == 0 ) strcpy(psname, "ps");
char p0name[CDI_MAX_NAME]; p0name[0] = 0;
double p0value = 1;
int p0varid = CDI_UNDEFID;
const int p0status = cdiZaxisInqKeyFlt(zaxisID, CDI_KEY_P0VALUE, &p0value);
if ( p0status == 0 )
const int p0status = cdiInqKeyFloat(zaxisID, CDI_GLOBAL, CDI_KEY_P0VALUE, &p0value);
if ( p0status == CDI_NOERR )
{
cdiZaxisInqKeyStr(zaxisID, CDI_KEY_P0NAME, CDI_MAX_NAME, p0name);
length = CDI_MAX_NAME;
cdiInqKeyString(zaxisID, CDI_GLOBAL, CDI_KEY_P0NAME, p0name, &length);
if ( p0name[0] == 0 ) strcpy(p0name, "p0");
cdf_def_var(fileID, p0name, NC_DOUBLE, 0, 0, &p0varid);
static const char longname[] = "reference pressure";
......
......@@ -115,9 +115,6 @@ void zaxis_init(zaxis_t *zaxisptr)
zaxisptr->self = CDI_UNDEFID;
zaxisptr->dimname[0] = 0;
zaxisptr->vdimname[0] = 0;
zaxisptr->psname[0] = 0;
zaxisptr->p0name[0] = 0;
zaxisptr->p0value.defined = false;
zaxisptr->vals = NULL;
#ifndef USE_MPI
zaxisptr->cvals = NULL;
......@@ -357,9 +354,6 @@ void *zaxis_key_to_ptr(zaxis_t *zaxisptr, int key)
{
case CDI_KEY_DIMNAME: keyptr = (void*)zaxisptr->dimname; break;
case CDI_KEY_VDIMNAME: keyptr = (void*)zaxisptr->vdimname; break;
case CDI_KEY_PSNAME: keyptr = (void*)zaxisptr->psname; break;
case CDI_KEY_P0NAME: keyptr = (void*)zaxisptr->p0name; break;
case CDI_KEY_P0VALUE: keyptr = (void*)&zaxisptr->p0value; break;
}
return keyptr;
......@@ -442,79 +436,6 @@ int cdiZaxisInqKeyStr(int zaxisID, int key, int size, char *mesg)
return 0;
}
/*
@Function cdiZaxisDefKeyFlt
@Title Define a CDI Z-axis floating point value from a key
@Prototype int cdiZaxisDefKeyFlt(int zaxisID, int key, double value)
@Parameter
@Item zaxisID Z-axis ID, from a previous call to @fref{zaxisCreate}.
@Item key The key to be searched
@Item value A double where the data will be read
@Description
The function @func{cdiZaxisDefKeyFlt} defines a CDI Z-axis double value from a key.
@Result
@func{cdiZaxisDefKeyFlt} returns 0 if OK and integer value on error.
@EndFunction
*/
int cdiZaxisDefKeyFlt(int zaxisID, int key, double value)
{
zaxis_t *zaxisptr = zaxis_to_pointer(zaxisID);
zkey_double_t *keyptr = (zkey_double_t*)zaxis_key_to_ptr(zaxisptr, key);
if ( keyptr == NULL)
{
Warning("CDI zaxis double key %d not supported!", key);
return -1;
}
keyptr->value = value;
keyptr->defined = true;
reshSetStatus(zaxisID, &zaxisOps, RESH_DESYNC_IN_USE);
return 0;
}
/*
@Function cdiZaxisInqKeyFlt
@Title Get a CDI Z-axis floating point value from a key
@Prototype int cdiZaxisInqKeyFlt(int zaxisID, int key, double *value)
@Parameter
@Item zaxisID Z-axis ID, from a previous call to @fref{zaxisCreate}.
@Item key The key to be searched.
@Item value The address of a double where the data will be retrieved.
@Description
The function @func{cdiZaxisInqKeyFlt} return a CDI Z-axis double value from a key.
@Result
@func{cdiZaxisInqKeyFlt} returns 0 if OK and integer value on error.
@EndFunction
*/
int cdiZaxisInqKeyFlt(int zaxisID, int key, double *value)
{
zaxis_t *zaxisptr = zaxis_to_pointer(zaxisID);
zkey_double_t *keyptr = (zkey_double_t*)zaxis_key_to_ptr(zaxisptr, key);
if ( keyptr == NULL)
{
Warning("CDI zaxis double key %d not supported!", key);
return -1;
}
if ( !keyptr->defined ) return 1;
*value = keyptr->value;
return 0;
}
/*
@Function zaxisDefName
@Title Define the name of a Z-axis
......
......@@ -8,18 +8,10 @@
#include "cdi_key.h"
#include "cdi_att.h"
typedef struct {
double value;
bool defined;
}
zkey_double_t;
typedef struct {
char dimname[CDI_MAX_NAME];
char vdimname[CDI_MAX_NAME];
char psname[CDI_MAX_NAME];
char p0name[CDI_MAX_NAME];
zkey_double_t p0value;
double *vals;
#ifndef USE_MPI
char **cvals;
......
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