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

zaxis: added support for user defined attributes.

parent 1eb05d1e
2016-09-15 Uwe Schulzweida
* zaxis: added support for user defined attributes
2016-08-29 Uwe Schulzweida
* CDI_cmor_mode: Convert Zaxis with one level to Scalar Z-Coordinate on all input streams
......
......@@ -16,6 +16,7 @@
#include "error.h"
#include "serialize.h"
#include "grid.h"
#include "zaxis.h"
#include "resource_unpack.h"
......@@ -107,6 +108,11 @@ cdi_atts_t *cdi_get_attsp(int objID, int varID)
grid_t *gridptr = gridID2Ptr(objID);
attsp = &gridptr->atts;
}
else if ( varID == CDI_GLOBAL && reshGetTxCode(objID) == ZAXIS )
{
zaxis_t *zaxisptr = zaxisID2Ptr(objID);
attsp = &zaxisptr->atts;
}
else
{
vlist_t *vlistptr = vlist_to_pointer(objID);
......
......@@ -78,6 +78,10 @@ struct grid_gme_t {
};
struct grid_t {
char vdimname[CDI_MAX_NAME];
char mapname[CDI_MAX_NAME];
char mapping[CDI_MAX_NAME];
char *name;
int self;
int type; /* grid type */
int prec; /* grid precision */
......@@ -100,10 +104,6 @@ struct grid_t {
int np; /* number of parallels between a pole and the equator */
bool lcomplex;
bool hasdims;
char vdimname[CDI_MAX_NAME];
char mapname[CDI_MAX_NAME];
char mapping[CDI_MAX_NAME];
char *name;
struct gridaxis_t x;
struct gridaxis_t y;
const struct gridVirtTable *vtable;
......
......@@ -1566,8 +1566,7 @@ void cdf_scan_var_attr(int nvars, ncvar_t *ncvars, ncdim_t *ncdims, int timedimi
else
{
if ( ncvars[ncvarid].natts == 0 )
ncvars[ncvarid].atts
= (int *) Malloc((size_t)nvatts * sizeof (int));
ncvars[ncvarid].atts = (int*) Malloc((size_t)nvatts*sizeof(int));
ncvars[ncvarid].atts[ncvars[ncvarid].natts++] = iatt;
/*
......@@ -2832,35 +2831,50 @@ void cdf_define_all_zaxes(stream_t *streamptr, int vlistID, ncdim_t *ncdims, int
ncvar->zaxisID = varDefZaxis(vlistID, zaxisType, (int) zsize, zvar, with_bounds, lbounds, ubounds,
(int)vctsize, vct, pname, plongname, punits, zprec, 1, 0);
if ( CDI_cmor_mode && zsize == 1 && zaxisType != ZAXIS_HYBRID ) zaxisDefScalar(ncvar->zaxisID);
int zaxisID = ncvar->zaxisID;
if ( CDI_cmor_mode && zsize == 1 && zaxisType != ZAXIS_HYBRID ) zaxisDefScalar(zaxisID);
if ( uuidOfVGrid[0] != 0 )
{
// printf("uuidOfVGrid: defined\n");
zaxisDefUUID(ncvar->zaxisID, uuidOfVGrid);
zaxisDefUUID(zaxisID, uuidOfVGrid);
}
if ( zaxisType == ZAXIS_HYBRID && psvarid != -1 )
cdiZaxisDefKeyStr(ncvar->zaxisID, CDI_KEY_PSNAME, strlen(ncvars[psvarid].name)+1, ncvars[psvarid].name);
cdiZaxisDefKeyStr(zaxisID, CDI_KEY_PSNAME, strlen(ncvars[psvarid].name)+1, ncvars[psvarid].name);
if ( positive > 0 ) zaxisDefPositive(ncvar->zaxisID, positive);
if ( is_scalar ) zaxisDefScalar(ncvar->zaxisID);
if ( positive > 0 ) zaxisDefPositive(zaxisID, positive);
if ( is_scalar ) zaxisDefScalar(zaxisID);
if ( zdimid != -1 )
cdiZaxisDefKeyStr(ncvar->zaxisID, CDI_KEY_DIMNAME, (int)(strlen(ncdims[zdimid].name)+1), ncdims[zdimid].name);
cdiZaxisDefKeyStr(zaxisID, CDI_KEY_DIMNAME, (int)(strlen(ncdims[zdimid].name)+1), ncdims[zdimid].name);
/*
if ( vdimid != -1 )
cdiZaxisDefKeyStr(ncvar->zaxisID, CDI_KEY_VDIMNAME, strlen(ncdims[vdimid].name)+1, ncdims[vdimid].name);
cdiZaxisDefKeyStr(zaxisID, CDI_KEY_VDIMNAME, strlen(ncdims[vdimid].name)+1, ncdims[vdimid].name);
*/
Free(zvar);
Free(lbounds);
Free(ubounds);
int zaxisindex = vlistZaxisIndex(vlistID, ncvar->zaxisID);
if ( zvarid != UNDEFID )
{
int ncid = ncvars[zvarid].ncid;
int nvatts = ncvars[zvarid].natts;
printf("nvarid %d name %s nvatts %d\n", zvarid, ncvars[zvarid].name, nvatts);
for ( int iatt = 0; iatt < nvatts; ++iatt )
{
int attnum = ncvars[zvarid].atts[iatt];
printf("attnum %d\n", attnum);
cdf_set_cdi_attr(ncid, zvarid, attnum, zaxisID, CDI_GLOBAL);
}
}
int zaxisindex = vlistZaxisIndex(vlistID, zaxisID);
streamptr->zaxisID[zaxisindex] = zdimid;
if ( CDI_Debug )
Message("zaxisID %d %d %s", ncvar->zaxisID, ncvarid, ncvar->name);
Message("zaxisID %d %d %s", zaxisID, ncvarid, ncvar->name);
for ( int ncvarid2 = ncvarid+1; ncvarid2 < nvars; ncvarid2++ )
if ( ncvars[ncvarid2].isvar == TRUE && ncvars[ncvarid2].zaxisID == UNDEFID /*&& ncvars[ncvarid2].zaxistype == UNDEFID*/ )
......@@ -2885,8 +2899,8 @@ void cdf_define_all_zaxes(stream_t *streamptr, int vlistID, ncdim_t *ncdims, int
(zdimid == UNDEFID && zvarid2 == UNDEFID && ncvars[ncvarid2].zaxistype == UNDEFID) )
{
if ( CDI_Debug )
Message("zaxisID %d %d %s", ncvar->zaxisID, ncvarid2, ncvars[ncvarid2].name);
ncvars[ncvarid2].zaxisID = ncvar->zaxisID;
Message("zaxisID %d %d %s", zaxisID, ncvarid2, ncvars[ncvarid2].name);
ncvars[ncvarid2].zaxisID = zaxisID;
}
}
}
......@@ -3230,9 +3244,7 @@ void cdf_scan_global_attr(int fileID, int vlistID, stream_t *streamptr, int ngat
else
{
if ( strcmp(attname, "ICON_grid_file_uri") == 0 && gridfile[0] == 0 )
{
memcpy(gridfile, attstring, attstrlen+1);
}
cdiDefAttTxt(vlistID, CDI_GLOBAL, attname, (int)attstrlen, attstring);
}
......
......@@ -1513,14 +1513,16 @@ void cdf_def_vct_cf(stream_t *streamptr, int zaxisID, int nclevID, int ncbndsID)
struct attTxtTab { const char *txt; size_t txtLen; };
static
void cdf_def_zaxis_hybrid_echam(stream_t *streamptr, int type, int ncvarid, int zaxisID, int zaxisindex, int xtype, size_t dimlen, int *dimID, char *axisname)
void cdf_def_zaxis_hybrid_echam(stream_t *streamptr, int type, int *ncvaridp, int zaxisID, int zaxisindex, int xtype, size_t dimlen, int *dimID, char *axisname)
{
int fileID = streamptr->fileID;
if ( streamptr->ncmode == 2 ) cdf_redef(fileID);
int ncvarid;
cdf_def_dim(fileID, axisname, dimlen, dimID);
cdf_def_var(fileID, axisname, (nc_type) xtype, 1, dimID, &ncvarid);
*ncvaridp = ncvarid;
{
static const char sname[] = "hybrid_sigma_pressure";
......@@ -1584,7 +1586,7 @@ void cdf_def_zaxis_hybrid_echam(stream_t *streamptr, int type, int ncvarid, int
}
static
void cdf_def_zaxis_hybrid_cf(stream_t *streamptr, int type, int ncvarid, int zaxisID, int zaxisindex, int xtype, size_t dimlen, int *dimID, char *axisname)
void cdf_def_zaxis_hybrid_cf(stream_t *streamptr, int type, int *ncvaridp, int zaxisID, int zaxisindex, int xtype, size_t dimlen, int *dimID, char *axisname)
{
char psname[CDI_MAX_NAME]; psname[0] = 0;
cdiZaxisInqKeyStr(zaxisID, CDI_KEY_PSNAME, CDI_MAX_NAME, psname);
......@@ -1595,8 +1597,10 @@ void cdf_def_zaxis_hybrid_cf(stream_t *streamptr, int type, int ncvarid, int zax
strcpy(axisname, "lev");
int ncvarid;
cdf_def_dim(fileID, axisname, dimlen, dimID);
cdf_def_var(fileID, axisname, (nc_type) xtype, 1, dimID, &ncvarid);
*ncvaridp = ncvarid;
{
static const char sname[] = "standard_name",
......@@ -1709,7 +1713,7 @@ void cdf_def_zaxis_hybrid_cf(stream_t *streamptr, int type, int ncvarid, int zax
}
static
void cdf_def_zaxis_hybrid(stream_t *streamptr, int type, int ncvarid, int zaxisID, int zaxisindex, int xtype, size_t dimlen, int *dimID, char *axisname)
void cdf_def_zaxis_hybrid(stream_t *streamptr, int type, int *ncvarid, int zaxisID, int zaxisindex, int xtype, size_t dimlen, int *dimID, char *axisname)
{
if ( (!CDI_cmor_mode && cdiConvention == CDI_CONVENTION_ECHAM) || type == ZAXIS_HYBRID_HALF )
cdf_def_zaxis_hybrid_echam(streamptr, type, ncvarid, zaxisID, zaxisindex, xtype, dimlen, dimID, axisname);
......@@ -1788,7 +1792,7 @@ void cdfDefZaxis(stream_t *streamptr, int zaxisID)
if ( type == ZAXIS_HYBRID || type == ZAXIS_HYBRID_HALF )
{
cdf_def_zaxis_hybrid(streamptr, type, ncvarid, zaxisID, zaxisindex, xtype, dimlen, &dimID, axisname);
cdf_def_zaxis_hybrid(streamptr, type, &ncvarid, zaxisID, zaxisindex, xtype, dimlen, &dimID, axisname);
}
else
{
......@@ -1813,8 +1817,7 @@ void cdfDefZaxis(stream_t *streamptr, int zaxisID)
if ( positive == POSITIVE_UP || positive == POSITIVE_DOWN )
{
size_t select = positive == POSITIVE_DOWN;
cdf_put_att_text(fileID, ncvarid, "positive",
tab[select].txtLen, tab[select].txt);
cdf_put_att_text(fileID, ncvarid, "positive", tab[select].txtLen, tab[select].txt);
}
}
cdf_put_att_text(fileID, ncvarid, "axis", 1, "Z");
......@@ -1858,6 +1861,17 @@ void cdfDefZaxis(stream_t *streamptr, int zaxisID)
if ( ndims == 0 ) streamptr->nczvarID[zaxisindex] = ncvarid;
}
{
int natts;
cdiInqNatts(zaxisID, CDI_GLOBAL, &natts);
if ( natts > 0 && streamptr->ncmode == 2 ) cdf_redef(fileID);
cdfDefineAttributes(zaxisID, CDI_GLOBAL, fileID, ncvarid);
if ( natts > 0 && streamptr->ncmode == 2 ) cdf_enddef(fileID);
}
}
if ( dimID != UNDEFID )
......
......@@ -64,35 +64,6 @@ enum {
};
typedef struct {
char dimname[CDI_MAX_NAME];
char vdimname[CDI_MAX_NAME];
char name[CDI_MAX_NAME];
char longname[CDI_MAX_NAME];
char stdname[CDI_MAX_NAME];
char units[CDI_MAX_NAME];
char psname[CDI_MAX_NAME];
double *vals;
double *lbounds;
double *ubounds;
double *weights;
int self;
int prec;
int scalar;
int type;
int ltype; /* GRIB level type */
int ltype2;
int size;
int direction;
int vctsize;
unsigned positive;
double *vct;
int number; /* Reference number to a generalized Z-axis */
int nhlev;
unsigned char uuid[CDI_UUID_SIZE];
}
zaxis_t;
static int zaxisCompareP (zaxis_t *z1, zaxis_t *z2);
static void zaxisDestroyP ( void * zaxisptr );
static void zaxisPrintP ( void * zaxisptr, FILE * fp );
......@@ -164,6 +135,8 @@ void zaxisDefaultValue(zaxis_t *zaxisptr)
zaxisptr->number = 0;
zaxisptr->nhlev = 0;
memset(zaxisptr->uuid, 0, CDI_UUID_SIZE);
zaxisptr->atts.nalloc = MAX_ATTRIBUTES;
zaxisptr->atts.nelems = 0;
}
......@@ -185,7 +158,7 @@ zaxis_t *zaxisNewEntry(int id)
return zaxisptr;
}
static inline
zaxis_t *zaxisID2Ptr(int id)
{
return (zaxis_t *)reshGetVal(id, &zaxisOps);
......
#ifndef _ZAXIS_H
#define _ZAXIS_H
typedef struct {
char dimname[CDI_MAX_NAME];
char vdimname[CDI_MAX_NAME];
char name[CDI_MAX_NAME];
char longname[CDI_MAX_NAME];
char stdname[CDI_MAX_NAME];
char units[CDI_MAX_NAME];
char psname[CDI_MAX_NAME];
double *vals;
double *lbounds;
double *ubounds;
double *weights;
int self;
int prec;
int scalar;
int type;
int ltype; /* GRIB level type */
int ltype2;
int size;
int direction;
int vctsize;
unsigned positive;
double *vct;
int number; /* Reference number to a generalized Z-axis */
int nhlev;
unsigned char uuid[CDI_UUID_SIZE];
cdi_atts_t atts;
}
zaxis_t;
void zaxisGetTypeDescription(int zaxisType, int* outPositive, const char** outName, const char** outLongName, const char** outStdName, const char** outUnit); //The returned const char* point to static storage. Don't free or modify them.
unsigned cdiZaxisCount(void);
zaxis_t *zaxisID2Ptr(int zaxisID);
void cdiZaxisGetIndexList(unsigned numIDs, int *IDs);
void
......
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