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