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

Added support for datatype of grid mapping var.

parent fc0cd537
2019-11-05 Uwe Schulzweida
* Added support for datatype of grid mapping var
2019-11-01 Uwe Schulzweida
* Added support gpt GRIB2 key typeOfTimeIncrement
......
......@@ -839,8 +839,9 @@ int cdiCopyKeys(int cdiID1, int varID1, int cdiID2, int varID2);
#define CDI_KEY_YLONGNAME 913 // Y-axis longname
#define CDI_KEY_YUNITS 914 // Y-axis units
#define CDI_KEY_VDIMNAME 920 // Vertex dimension name
#define CDI_KEY_GRIDMAP_VARNAME 921 // Grid mapping var name
#define CDI_KEY_GRIDMAP_NAME 922 // Grid mapping name
#define CDI_KEY_GRIDMAP_VARTYPE 921 // Grid mapping var datatype
#define CDI_KEY_GRIDMAP_VARNAME 922 // Grid mapping var name
#define CDI_KEY_GRIDMAP_NAME 923 // Grid mapping name
// CDI zaxis keys
#define CDI_KEY_NAME 941 // Z-axis name
......
#include "cdi.h"
#include "cdi_int.h"
#include "grid.h"
#include "vlist.h"
#include "resource_unpack.h"
enum {KEY_INT = 1, KEY_FLOAT, KEY_BYTES};
static
cdi_keys_t *get_keysp(vlist_t *vlistptr, int varID)
cdi_keys_t *vlist_get_keysp(vlist_t *vlistptr, int varID)
{
cdi_keys_t *keysp = NULL;
......@@ -23,6 +24,19 @@ cdi_keys_t *get_keysp(vlist_t *vlistptr, int varID)
return keysp;
}
static
cdi_keys_t *grid_get_keysp(vlist_t *gridptr, int varID)
{
cdi_keys_t *keysp = NULL;
if ( varID == CDI_GLOBAL )
{
keysp = &gridptr->keys;
}
return keysp;
}
static
cdi_key_t *new_key(cdi_keys_t *keysp, int key)
{
......@@ -64,12 +78,12 @@ cdi_keys_t *cdi_get_keysp(int objID, int varID)
{
cdi_keys_t *keysp = NULL;
/*
if ( varID == CDI_GLOBAL && reshGetTxCode(objID) == GRID )
if ( reshGetTxCode(objID) == GRID )
{
grid_t *gridptr = grid_to_pointer(objID);
keysp = &gridptr->keys;
}
/*
else if ( varID == CDI_GLOBAL && reshGetTxCode(objID) == ZAXIS )
{
zaxis_t *zaxisptr = zaxis_to_pointer(objID);
......@@ -80,7 +94,7 @@ cdi_keys_t *cdi_get_keysp(int objID, int varID)
if ( reshGetTxCode(objID) == VLIST )
{
vlist_t *vlistptr = vlist_to_pointer(objID);
keysp = get_keysp(vlistptr, varID);
keysp = vlist_get_keysp(vlistptr, varID);
}
return keysp;
......@@ -89,8 +103,8 @@ cdi_keys_t *cdi_get_keysp(int objID, int varID)
int vlist_key_compare(vlist_t *a, int varIDA, vlist_t *b, int varIDB, int keynum)
{
cdi_keys_t *keyspa = get_keysp(a, varIDA),
*keyspb = get_keysp(b, varIDB);
cdi_keys_t *keyspa = vlist_get_keysp(a, varIDA),
*keyspb = vlist_get_keysp(b, varIDB);
if (keyspa == NULL && keyspb == NULL)
return 0;
xassert(keynum >= 0 && keynum < (int)keyspa->nelems
......
......@@ -115,22 +115,24 @@ bool cdiInqAttConvertedToFloat(int gridID, int atttype, const char *attname, int
static
void grid_axis_init(struct gridaxis_t *axisptr)
{
axisptr->size = 0;
axisptr->vals = NULL;
axisptr->bounds = NULL;
axisptr->flag = 0;
axisptr->first = 0.0;
axisptr->last = 0.0;
axisptr->inc = 0.0;
axisptr->size = 0;
axisptr->vals = NULL;
axisptr->bounds = NULL;
axisptr->flag = 0;
axisptr->first = 0.0;
axisptr->last = 0.0;
axisptr->inc = 0.0;
#ifndef USE_MPI
axisptr->clength = 0;
axisptr->cvals = NULL;
axisptr->clength = 0;
axisptr->cvals = NULL;
#endif
axisptr->dimname[0] = 0;
axisptr->name[0] = 0;
axisptr->longname[0] = 0;
axisptr->units[0] = 0;
axisptr->stdname = NULL;
axisptr->dimname[0] = 0;
axisptr->name[0] = 0;
axisptr->longname[0] = 0;
axisptr->units[0] = 0;
axisptr->stdname = NULL;
axisptr->keys.nalloc = MAX_KEYS;
axisptr->keys.nelems = 0;
}
void grid_init(grid_t *gridptr)
......@@ -170,10 +172,12 @@ void grid_init(grid_t *gridptr)
gridptr->mapname[0] = 0;
gridptr->mapping[0] = 0;
memset(gridptr->uuid, 0, CDI_UUID_SIZE);
gridptr->name = NULL;
gridptr->vtable = &cdiGridVtable;
gridptr->atts.nalloc = MAX_ATTRIBUTES;
gridptr->atts.nelems = 0;
gridptr->name = NULL;
gridptr->vtable = &cdiGridVtable;
gridptr->keys.nalloc = MAX_KEYS;
gridptr->keys.nelems = 0;
gridptr->atts.nalloc = MAX_ATTRIBUTES;
gridptr->atts.nelems = 0;
gridptr->iScansNegatively = 0;
gridptr->jScansPositively = 1;
gridptr->jPointsAreConsecutive = 0;
......
......@@ -4,6 +4,7 @@
#include "cdi.h"
#include <stdbool.h>
#include "cdi_key.h"
#include "cdi_att.h"
extern int (*proj_lonlat_to_lcc_func)();
......@@ -71,6 +72,7 @@ struct gridaxis_t {
double first, last, inc;
double *vals;
double *bounds;
cdi_keys_t keys;
#ifndef USE_MPI
int clength;
char **cvals;
......@@ -115,7 +117,8 @@ struct grid_t {
struct gridaxis_t x;
struct gridaxis_t y;
const struct gridVirtTable *vtable;
cdi_atts_t atts;
cdi_keys_t keys;
cdi_atts_t atts;
int scanningMode;
bool iScansNegatively, jScansPositively, jPointsAreConsecutive;
/* scanningMode = 128 * iScansNegatively + 64 * jScansPositively + 32 * jPointsAreConsecutive;
......
......@@ -2768,9 +2768,11 @@ int cdf_define_all_grids(ncgrid_t *ncgrid, int vlistID, ncdim_t *ncdims, int nva
{
const int projID = lgrid ? grid->proj : gridID;
const int ncid = ncvars[gmapvarid].ncid;
const char *gmapname = ncvars[gmapvarid].name;
cdf_read_mapping_atts(ncid, gmapvarid, projID, gmapname);
cdiGridDefKeyStr(projID, CDI_KEY_GRIDMAP_VARNAME, (int)(strlen(gmapname)+1), gmapname);
const int gmapvartype = cdfInqDatatype(ncvars[gmapvarid].xtype, ncvars[gmapvarid].lunsigned);
if (gmapvartype != -1) cdiDefKeyInt(projID, CDI_GLOBAL, CDI_KEY_GRIDMAP_VARTYPE, gmapvartype);
const char *gmapvarname = ncvars[gmapvarid].name;
cdf_read_mapping_atts(ncid, gmapvarid, projID, gmapvarname);
cdiGridDefKeyStr(projID, CDI_KEY_GRIDMAP_VARNAME, (int)(strlen(gmapvarname)+1), gmapvarname);
gridVerifyProj(projID);
}
......
......@@ -1621,6 +1621,10 @@ void cdf_def_mapping(stream_t *streamptr, int gridID)
cdiGridInqKeyStr(gridID, CDI_KEY_GRIDMAP_NAME, CDI_MAX_NAME, mapping);
if ( mapping[0] )
{
nc_type gmapvartype = NC_INT;
int datatype = -1;
int status = cdiInqKeyInt(gridID, CDI_GLOBAL, CDI_KEY_GRIDMAP_VARTYPE, &datatype);
if (status == CDI_NOERR) gmapvartype = cdfDefDatatype(datatype, streamptr);
char gmapvarname[CDI_MAX_NAME]; gmapvarname[0] = 0;
cdiGridInqKeyStr(gridID, CDI_KEY_GRIDMAP_VARNAME, CDI_MAX_NAME, gmapvarname);
......@@ -1628,7 +1632,7 @@ void cdf_def_mapping(stream_t *streamptr, int gridID)
if ( streamptr->ncmode == 2 ) cdf_redef(fileID);
int ncvarid;
const int ncerrcode = nc_def_var(fileID, gmapvarname, (nc_type) NC_INT, 0, NULL, &ncvarid);
const int ncerrcode = nc_def_var(fileID, gmapvarname, (nc_type) gmapvartype, 0, NULL, &ncvarid);
if ( ncerrcode == NC_NOERR )
cdfDefineAttributes(gridID, CDI_GLOBAL, fileID, ncvarid);
......
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