Commit 1c9b7eb9 authored by Uwe Schulzweida's avatar Uwe Schulzweida
Browse files

Replaced cdiGridDefKeyStr() by cdiDefKeyString() for CDI_KEY_GRIDMAP_NAME.

parent 67e304ba
......@@ -302,21 +302,26 @@ static
void cdf_get_gmapvarname(int gridID, char *gmapvarname)
{
int pgridID = gridID;
char mapping[CDI_MAX_NAME]; mapping[0] = 0;
cdiGridInqKeyStr(pgridID, CDI_KEY_GRIDMAP_NAME, CDI_MAX_NAME, mapping);
char gmapname[CDI_MAX_NAME];
int length = CDI_MAX_NAME;
cdiInqKeyString(pgridID, CDI_GLOBAL, CDI_KEY_GRIDMAP_NAME, gmapname, &length);
if ( !mapping[0] )
if ( !gmapname[0] )
{
int projID = gridInqProj(gridID);
if ( projID != CDI_UNDEFID )
{
pgridID = projID;
cdiGridInqKeyStr(pgridID, CDI_KEY_GRIDMAP_NAME, CDI_MAX_NAME, mapping);
length = CDI_MAX_NAME;
cdiInqKeyString(pgridID, CDI_GLOBAL, CDI_KEY_GRIDMAP_NAME, gmapname, &length);
}
}
if ( mapping[0] )
cdiGridInqKeyStr(pgridID, CDI_KEY_GRIDMAP_VARNAME, CDI_MAX_NAME, gmapvarname);
if ( gmapname[0] )
{
length = CDI_MAX_NAME;
cdiInqKeyString(pgridID, CDI_GLOBAL, CDI_KEY_GRIDMAP_VARNAME, gmapvarname, &length);
}
}
static
......
......@@ -25,7 +25,7 @@ cdi_keys_t *vlist_get_keysp(vlist_t *vlistptr, int varID)
}
static
cdi_keys_t *grid_get_keysp(vlist_t *gridptr, int varID)
cdi_keys_t *grid_get_keysp(grid_t *gridptr, int varID)
{
cdi_keys_t *keysp = NULL;
......@@ -81,7 +81,7 @@ cdi_keys_t *cdi_get_keysp(int objID, int varID)
if ( reshGetTxCode(objID) == GRID )
{
grid_t *gridptr = grid_to_pointer(objID);
keysp = &gridptr->keys;
keysp = grid_get_keysp(gridptr, varID);
}
/*
else if ( varID == CDI_GLOBAL && reshGetTxCode(objID) == ZAXIS )
......
......@@ -169,8 +169,6 @@ void grid_init(grid_t *gridptr)
gridptr->lcomplex = false;
gridptr->hasdims = true;
gridptr->vdimname[0] = 0;
gridptr->mapname[0] = 0;
gridptr->mapping[0] = 0;
memset(gridptr->uuid, 0, CDI_UUID_SIZE);
gridptr->name = NULL;
gridptr->vtable = &cdiGridVtable;
......@@ -349,7 +347,8 @@ void cdiGridTypeInit(grid_t *gridptr, int gridtype, size_t size)
if ( gridptr->y.name[0] == 0 ) gridSetName(gridptr->y.name, "y");
if ( gridtype == GRID_PROJECTION )
{
gridSetName(gridptr->mapname, "Projection");
const char *gmapname = "Projection";
cdiDefVarKeyBytes(&gridptr->keys, CDI_KEY_GRIDMAP_NAME, (const unsigned char *)gmapname, (int)sizeof(gmapname)+1);
gridptr->x.stdname = xystdname_tab[grid_xystdname_projection][0];
gridptr->y.stdname = xystdname_tab[grid_xystdname_projection][1];
......@@ -633,8 +632,6 @@ void *grid_key_to_ptr(grid_t *gridptr, int key)
case CDI_KEY_XDIMNAME: keyptr = (void*)gridptr->x.dimname; break;
case CDI_KEY_YDIMNAME: keyptr = (void*)gridptr->y.dimname; break;
case CDI_KEY_VDIMNAME: keyptr = (void*)gridptr->vdimname; break;
case CDI_KEY_GRIDMAP_VARNAME: keyptr = (void*)gridptr->mapname; break;
case CDI_KEY_GRIDMAP_NAME: keyptr = (void*)gridptr->mapping; break;
}
return keyptr;
......@@ -1026,16 +1023,17 @@ int gridInqProjType(int gridID)
int projtype = gridptr->projtype;
if ( projtype == -1 )
{
char mapping[CDI_MAX_NAME]; mapping[0] = 0;
cdiGridInqKeyStr(gridID, CDI_KEY_GRIDMAP_NAME, CDI_MAX_NAME, mapping);
if ( mapping[0] )
char gmapname[CDI_MAX_NAME];
int length = CDI_MAX_NAME;
cdiInqKeyString(gridID, CDI_GLOBAL, CDI_KEY_GRIDMAP_NAME, gmapname, &length);
if ( gmapname[0] )
{
// clang-format off
if ( strIsEqual(mapping, "rotated_latitude_longitude") ) projtype = CDI_PROJ_RLL;
else if ( strIsEqual(mapping, "lambert_azimuthal_equal_area") ) projtype = CDI_PROJ_LAEA;
else if ( strIsEqual(mapping, "lambert_conformal_conic") ) projtype = CDI_PROJ_LCC;
else if ( strIsEqual(mapping, "sinusoidal") ) projtype = CDI_PROJ_SINU;
else if ( strIsEqual(mapping, "polar_stereographic") ) projtype = CDI_PROJ_STERE;
if ( strIsEqual(gmapname, "rotated_latitude_longitude") ) projtype = CDI_PROJ_RLL;
else if ( strIsEqual(gmapname, "lambert_azimuthal_equal_area") ) projtype = CDI_PROJ_LAEA;
else if ( strIsEqual(gmapname, "lambert_conformal_conic") ) projtype = CDI_PROJ_LCC;
else if ( strIsEqual(gmapname, "sinusoidal") ) projtype = CDI_PROJ_SINU;
else if ( strIsEqual(gmapname, "polar_stereographic") ) projtype = CDI_PROJ_STERE;
// clang-format on
gridptr->projtype = projtype;
}
......@@ -1999,9 +1997,10 @@ void gridInqParamRLL(int gridID, double *xpole, double *ypole, double *angle)
*xpole = 0; *ypole = 0; *angle = 0;
const char *projection = "rotated_latitude_longitude";
char mapping[CDI_MAX_NAME]; mapping[0] = 0;
cdiGridInqKeyStr(gridID, CDI_KEY_GRIDMAP_NAME, CDI_MAX_NAME, mapping);
if ( mapping[0] && strIsEqual(mapping, projection) )
char gmapname[CDI_MAX_NAME];
int length = CDI_MAX_NAME;
cdiInqKeyString(gridID, CDI_GLOBAL, CDI_KEY_GRIDMAP_NAME, gmapname, &length);
if ( gmapname[0] && strIsEqual(gmapname, projection) )
{
int atttype, attlen;
char attname[CDI_MAX_NAME+1];
......@@ -2039,11 +2038,11 @@ void gridInqParamRLL(int gridID, double *xpole, double *ypole, double *angle)
*/
void gridDefParamRLL(int gridID, double xpole, double ypole, double angle)
{
cdiGridDefKeyStr(gridID, CDI_KEY_GRIDMAP_VARNAME, CDI_MAX_NAME, "rotated_pole");
cdiDefKeyString(gridID, CDI_GLOBAL, CDI_KEY_GRIDMAP_VARNAME, "rotated_pole");
const char *mapping = "rotated_latitude_longitude";
cdiGridDefKeyStr(gridID, CDI_KEY_GRIDMAP_NAME, CDI_MAX_NAME, mapping);
cdiDefAttTxt(gridID, CDI_GLOBAL, "grid_mapping_name", (int)(strlen(mapping)), mapping);
const char *gmapname = "rotated_latitude_longitude";
cdiDefKeyString(gridID, CDI_GLOBAL, CDI_KEY_GRIDMAP_NAME, gmapname);
cdiDefAttTxt(gridID, CDI_GLOBAL, "grid_mapping_name", (int)(strlen(gmapname)), gmapname);
cdiDefAttFlt(gridID, CDI_GLOBAL, "grid_north_pole_longitude", CDI_DATATYPE_FLT64, 1, &xpole);
cdiDefAttFlt(gridID, CDI_GLOBAL, "grid_north_pole_latitude", CDI_DATATYPE_FLT64, 1, &ypole);
if ( IS_NOT_EQUAL(angle, 0) ) cdiDefAttFlt(gridID, CDI_GLOBAL, "north_pole_grid_longitude", CDI_DATATYPE_FLT64, 1, &angle);
......@@ -2613,8 +2612,6 @@ int gridCompareP(void *gridptr1, void *gridptr2)
if (strcmp(g1->x.units, g2->x.units)) return differ;
if (strcmp(g1->y.units, g2->y.units)) return differ;
if (strcmp(g1->mapping, g2->mapping)) return differ;
if ( g1->reference )
{
if ( !g2->reference ) return differ;
......@@ -3710,11 +3707,11 @@ void gridDefParamLCC(int gridID, double missval, double lon_0, double lat_0, dou
double a, double rf, double xval_0, double yval_0, double x_0, double y_0)
{
(void)lat_0;
cdiGridDefKeyStr(gridID, CDI_KEY_GRIDMAP_VARNAME, CDI_MAX_NAME, "Lambert_Conformal");
cdiDefKeyString(gridID, CDI_GLOBAL, CDI_KEY_GRIDMAP_VARNAME, "Lambert_Conformal");
const char *mapname = "lambert_conformal_conic";
cdiGridDefKeyStr(gridID, CDI_KEY_GRIDMAP_NAME, CDI_MAX_NAME, mapname);
cdiDefAttTxt(gridID, CDI_GLOBAL, "grid_mapping_name", (int)(strlen(mapname)), mapname);
const char *gmapname = "lambert_conformal_conic";
cdiDefKeyString(gridID, CDI_GLOBAL, CDI_KEY_GRIDMAP_NAME, gmapname);
cdiDefAttTxt(gridID, CDI_GLOBAL, "grid_mapping_name", (int)(strlen(gmapname)), gmapname);
int nlats = 0;
double lats[2];
lats[nlats++] = lat_1;
......@@ -3773,9 +3770,10 @@ int gridInqParamLCC(int gridID, double missval, double *lon_0, double *lat_0, do
status = -2;
const char *projection = "lambert_conformal_conic";
char mapname[CDI_MAX_NAME]; mapname[0] = 0;
cdiGridInqKeyStr(gridID, CDI_KEY_GRIDMAP_NAME, CDI_MAX_NAME, mapname);
if ( mapname[0] && strIsEqual(mapname, projection) )
char gmapname[CDI_MAX_NAME];
int length = CDI_MAX_NAME;
cdiInqKeyString(gridID, CDI_GLOBAL, CDI_KEY_GRIDMAP_NAME, gmapname, &length);
if ( gmapname[0] && strIsEqual(gmapname, projection) )
{
int atttype, attlen;
char attname[CDI_MAX_NAME+1];
......@@ -3895,11 +3893,11 @@ The function @func{gridDefParamSTERE} defines the parameter of a Polar stereogra
void gridDefParamSTERE(int gridID, double missval, double lon_0, double lat_ts, double lat_0,
double a, double xval_0, double yval_0, double x_0, double y_0)
{
cdiGridDefKeyStr(gridID, CDI_KEY_GRIDMAP_VARNAME, CDI_MAX_NAME, "Polar_Stereographic");
cdiDefKeyString(gridID, CDI_GLOBAL, CDI_KEY_GRIDMAP_VARNAME, "Polar_Stereographic");
const char *mapname = "polar_stereographic";
cdiGridDefKeyStr(gridID, CDI_KEY_GRIDMAP_NAME, CDI_MAX_NAME, mapname);
cdiDefAttTxt(gridID, CDI_GLOBAL, "grid_mapping_name", (int)(strlen(mapname)), mapname);
const char *gmapname = "polar_stereographic";
cdiDefKeyString(gridID, CDI_GLOBAL, CDI_KEY_GRIDMAP_NAME, gmapname);
cdiDefAttTxt(gridID, CDI_GLOBAL, "grid_mapping_name", (int)(strlen(gmapname)), gmapname);
cdiDefAttFlt(gridID, CDI_GLOBAL, "standard_parallel", CDI_DATATYPE_FLT64, 1, &lat_ts);
cdiDefAttFlt(gridID, CDI_GLOBAL, "straight_vertical_longitude_from_pole", CDI_DATATYPE_FLT64, 1, &lon_0);
cdiDefAttFlt(gridID, CDI_GLOBAL, "latitude_of_projection_origin", CDI_DATATYPE_FLT64, 1, &lat_0);
......@@ -3949,9 +3947,10 @@ int gridInqParamSTERE(int gridID, double missval, double *lon_0, double *lat_ts,
status = -2;
const char *projection = "polar_stereographic";
char mapname[CDI_MAX_NAME]; mapname[0] = 0;
cdiGridInqKeyStr(gridID, CDI_KEY_GRIDMAP_NAME, CDI_MAX_NAME, mapname);
if ( mapname[0] && strIsEqual(mapname, projection) )
char gmapname[CDI_MAX_NAME];
int length = CDI_MAX_NAME;
cdiInqKeyString(gridID, CDI_GLOBAL, CDI_KEY_GRIDMAP_NAME, gmapname, &length);
if ( gmapname[0] && strIsEqual(gmapname, projection) )
{
int atttype, attlen;
char attname[CDI_MAX_NAME+1];
......@@ -4899,8 +4898,7 @@ struct addIfNewRes cdiVlistAddGridIfNew(int vlistID, grid_t *grid, int mode)
{
struct gridCompareSearchState query;
query.queryKey = grid;// = { .queryKey = grid };
if ( (gridglobdefined = (cdiResHFilterApply(&gridOps, gridCompareSearch, &query)
== CDI_APPLY_STOP)) )
if ( (gridglobdefined = (cdiResHFilterApply(&gridOps, gridCompareSearch, &query) == CDI_APPLY_STOP)) )
gridID = query.resIDValue;
if ( mode == 1 && gridglobdefined )
......
......@@ -86,8 +86,6 @@ 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;
size_t size;
......
......@@ -2584,7 +2584,7 @@ void cdf_read_mapping_atts(int ncid, int gmapvarid, int projID, const char *varn
{
char attstring[CDI_MAX_NAME];
cdfGetAttText(ncid, gmapvarid, "grid_mapping_name", CDI_MAX_NAME, attstring);
cdiGridDefKeyStr(projID, CDI_KEY_GRIDMAP_NAME, (int)(strlen(attstring)+1), attstring);
cdiDefKeyString(projID, CDI_GLOBAL, CDI_KEY_GRIDMAP_NAME, attstring);
}
else
{
......@@ -2772,7 +2772,7 @@ int cdf_define_all_grids(ncgrid_t *ncgrid, int vlistID, ncdim_t *ncdims, int nva
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);
cdiDefKeyString(projID, CDI_GLOBAL, CDI_KEY_GRIDMAP_VARNAME, gmapvarname);
gridVerifyProj(projID);
}
......
......@@ -1617,16 +1617,18 @@ void cdfDefZaxis(stream_t *streamptr, int zaxisID)
static
void cdf_def_mapping(stream_t *streamptr, int gridID)
{
char mapping[CDI_MAX_NAME]; mapping[0] = 0;
cdiGridInqKeyStr(gridID, CDI_KEY_GRIDMAP_NAME, CDI_MAX_NAME, mapping);
if ( mapping[0] )
char gmapname[CDI_MAX_NAME];
int length = CDI_MAX_NAME;
cdiInqKeyString(gridID, CDI_GLOBAL, CDI_KEY_GRIDMAP_NAME, gmapname, &length);
if ( gmapname[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 = (nc_type) datatype;
char gmapvarname[CDI_MAX_NAME]; gmapvarname[0] = 0;
cdiGridInqKeyStr(gridID, CDI_KEY_GRIDMAP_VARNAME, CDI_MAX_NAME, gmapvarname);
char gmapvarname[CDI_MAX_NAME];
length = CDI_MAX_NAME;
cdiInqKeyString(gridID, CDI_GLOBAL, CDI_KEY_GRIDMAP_VARNAME, gmapvarname, &length);
const int fileID = streamptr->fileID;
if ( streamptr->ncmode == 2 ) cdf_redef(fileID);
......
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