Commit 34615a8d authored by Uwe Schulzweida's avatar Uwe Schulzweida
Browse files

netcdf: added support for vertex dim name

parent 80dd7f11
......@@ -761,10 +761,11 @@ int gridInqYvals(int gridID, double yvals[]);
#define CDI_GRID_YNAME 902 // Y-axis name
#define CDI_GRID_XDIMNAME 903 // X-axis dimension name
#define CDI_GRID_YDIMNAME 904 // Y-axis dimension name
#define CDI_GRID_XLONGNAME 905 // X-axis longname
#define CDI_GRID_YLONGNAME 906 // Y-axis longname
#define CDI_GRID_XUNITS 907 // X-axis units
#define CDI_GRID_YUNITS 908 // Y-axis units
#define CDI_GRID_VDIMNAME 905 // Vertex dimension name
#define CDI_GRID_XLONGNAME 906 // X-axis longname
#define CDI_GRID_YLONGNAME 907 // Y-axis longname
#define CDI_GRID_XUNITS 908 // X-axis units
#define CDI_GRID_YUNITS 909 // Y-axis units
// cdiGridDefString: Define a CDI grid string value from a key
int cdiGridDefString(int gridID, int key, int size, const char *mesg);
......
......@@ -1534,14 +1534,16 @@
PARAMETER (CDI_GRID_XDIMNAME = 903)
INTEGER CDI_GRID_YDIMNAME
PARAMETER (CDI_GRID_YDIMNAME = 904)
INTEGER CDI_GRID_VDIMNAME
PARAMETER (CDI_GRID_VDIMNAME = 905)
INTEGER CDI_GRID_XLONGNAME
PARAMETER (CDI_GRID_XLONGNAME = 905)
PARAMETER (CDI_GRID_XLONGNAME = 906)
INTEGER CDI_GRID_YLONGNAME
PARAMETER (CDI_GRID_YLONGNAME = 906)
PARAMETER (CDI_GRID_YLONGNAME = 907)
INTEGER CDI_GRID_XUNITS
PARAMETER (CDI_GRID_XUNITS = 907)
PARAMETER (CDI_GRID_XUNITS = 908)
INTEGER CDI_GRID_YUNITS
PARAMETER (CDI_GRID_YUNITS = 908)
PARAMETER (CDI_GRID_YUNITS = 909)
INTEGER cdiGridDefString
! (INTEGER gridID,
! INTEGER key,
......
......@@ -91,81 +91,82 @@ grid_t *gridID2Ptr(int gridID)
void grid_init(grid_t *gridptr)
{
gridptr->self = CDI_UNDEFID;
gridptr->type = CDI_UNDEFID;
gridptr->proj = CDI_UNDEFID;
gridptr->mask = NULL;
gridptr->mask_gme = NULL;
gridptr->xvals = NULL;
gridptr->yvals = NULL;
gridptr->area = NULL;
gridptr->xbounds = NULL;
gridptr->ybounds = NULL;
gridptr->rowlon = NULL;
gridptr->nrowlon = 0;
gridptr->xfirst = 0.0;
gridptr->xlast = 0.0;
gridptr->xinc = 0.0;
gridptr->yfirst = 0.0;
gridptr->ylast = 0.0;
gridptr->yinc = 0.0;
gridptr->self = CDI_UNDEFID;
gridptr->type = CDI_UNDEFID;
gridptr->proj = CDI_UNDEFID;
gridptr->mask = NULL;
gridptr->mask_gme = NULL;
gridptr->xvals = NULL;
gridptr->yvals = NULL;
gridptr->area = NULL;
gridptr->xbounds = NULL;
gridptr->ybounds = NULL;
gridptr->rowlon = NULL;
gridptr->nrowlon = 0;
gridptr->xfirst = 0.0;
gridptr->xlast = 0.0;
gridptr->xinc = 0.0;
gridptr->yfirst = 0.0;
gridptr->ylast = 0.0;
gridptr->yinc = 0.0;
gridptr->lcc_originLon = 0.0;
gridptr->lcc_originLat = 0.0;
gridptr->lcc_lonParY = 0.0;
gridptr->lcc_lat1 = 0.0;
gridptr->lcc_lat2 = 0.0;
gridptr->lcc_xinc = 0.0;
gridptr->lcc_yinc = 0.0;
gridptr->lcc_projflag = 0;
gridptr->lcc_scanflag = 0;
gridptr->lcc_defined = FALSE;
gridptr->lcc2_lon_0 = 0.0;
gridptr->lcc2_lat_0 = 0.0;
gridptr->lcc2_lat_1 = 0.0;
gridptr->lcc2_lat_2 = 0.0;
gridptr->lcc2_a = 0.0;
gridptr->lcc2_defined = FALSE;
gridptr->laea_lon_0 = 0.0;
gridptr->laea_lat_0 = 0.0;
gridptr->laea_a = 0.0;
gridptr->laea_defined = FALSE;
gridptr->trunc = 0;
gridptr->nvertex = 0;
gridptr->nd = 0;
gridptr->ni = 0;
gridptr->ni2 = 0;
gridptr->ni3 = 0;
gridptr->number = 0;
gridptr->position = 0;
gridptr->reference = NULL;
gridptr->prec = 0;
gridptr->size = 0;
gridptr->xsize = 0;
gridptr->ysize = 0;
gridptr->np = 0;
gridptr->xdef = 0;
gridptr->ydef = 0;
gridptr->isCyclic = CDI_UNDEFID;
gridptr->isRotated = FALSE;
gridptr->xpole = 0.0;
gridptr->ypole = 0.0;
gridptr->angle = 0.0;
gridptr->lcomplex = 0;
gridptr->hasdims = TRUE;
gridptr->xdimname[0] = 0;
gridptr->ydimname[0] = 0;
gridptr->xname[0] = 0;
gridptr->yname[0] = 0;
gridptr->xlongname[0] = 0;
gridptr->ylongname[0] = 0;
gridptr->xunits[0] = 0;
gridptr->yunits[0] = 0;
gridptr->xstdname = NULL;
gridptr->ystdname = NULL;
gridptr->lcc_lonParY = 0.0;
gridptr->lcc_lat1 = 0.0;
gridptr->lcc_lat2 = 0.0;
gridptr->lcc_xinc = 0.0;
gridptr->lcc_yinc = 0.0;
gridptr->lcc_projflag = 0;
gridptr->lcc_scanflag = 0;
gridptr->lcc_defined = FALSE;
gridptr->lcc2_lon_0 = 0.0;
gridptr->lcc2_lat_0 = 0.0;
gridptr->lcc2_lat_1 = 0.0;
gridptr->lcc2_lat_2 = 0.0;
gridptr->lcc2_a = 0.0;
gridptr->lcc2_defined = FALSE;
gridptr->laea_lon_0 = 0.0;
gridptr->laea_lat_0 = 0.0;
gridptr->laea_a = 0.0;
gridptr->laea_defined = FALSE;
gridptr->trunc = 0;
gridptr->nvertex = 0;
gridptr->nd = 0;
gridptr->ni = 0;
gridptr->ni2 = 0;
gridptr->ni3 = 0;
gridptr->number = 0;
gridptr->position = 0;
gridptr->reference = NULL;
gridptr->prec = 0;
gridptr->size = 0;
gridptr->xsize = 0;
gridptr->ysize = 0;
gridptr->np = 0;
gridptr->xdef = 0;
gridptr->ydef = 0;
gridptr->isCyclic = CDI_UNDEFID;
gridptr->isRotated = FALSE;
gridptr->xpole = 0.0;
gridptr->ypole = 0.0;
gridptr->angle = 0.0;
gridptr->lcomplex = 0;
gridptr->hasdims = TRUE;
gridptr->xdimname[0] = 0;
gridptr->ydimname[0] = 0;
gridptr->vdimname[0] = 0;
gridptr->xname[0] = 0;
gridptr->yname[0] = 0;
gridptr->xlongname[0] = 0;
gridptr->ylongname[0] = 0;
gridptr->xunits[0] = 0;
gridptr->yunits[0] = 0;
gridptr->xstdname = NULL;
gridptr->ystdname = NULL;
memset(gridptr->uuid, 0, CDI_UUID_SIZE);
gridptr->name = NULL;
gridptr->vtable = &cdiGridVtable;
gridptr->extraData = NULL;
gridptr->name = NULL;
gridptr->vtable = &cdiGridVtable;
gridptr->extraData = NULL;
}
......@@ -610,6 +611,7 @@ char *grid_key_to_string(grid_t *gridptr, int key)
{
case CDI_GRID_XDIMNAME: gridstring = gridptr->xdimname; break;
case CDI_GRID_YDIMNAME: gridstring = gridptr->ydimname; break;
case CDI_GRID_VDIMNAME: gridstring = gridptr->vdimname; break;
}
return gridstring;
......@@ -677,7 +679,7 @@ The function @func{cdiGridInqString} return a CDI grid string value from a key.
*/
int cdiGridInqString(int gridID, int key, int size, char *mesg)
{
if ( size == 0 || mesg == NULL || *mesg == 0 ) return -1;
if ( size == 0 || mesg == NULL ) return -1;
grid_t *gridptr = gridID2Ptr(gridID);
const char *gridstring = grid_key_to_string(gridptr, key);
......
......@@ -100,6 +100,7 @@ struct grid_t {
const char *ystdname;
char xdimname[CDI_MAX_NAME];
char ydimname[CDI_MAX_NAME];
char vdimname[CDI_MAX_NAME];
char xname[CDI_MAX_NAME];
char yname[CDI_MAX_NAME];
char xlongname[CDI_MAX_NAME];
......
......@@ -448,10 +448,11 @@ module mo_cdi
integer(c_int), public, parameter :: CDI_GRID_YNAME = 902
integer(c_int), public, parameter :: CDI_GRID_XDIMNAME = 903
integer(c_int), public, parameter :: CDI_GRID_YDIMNAME = 904
integer(c_int), public, parameter :: CDI_GRID_XLONGNAME = 905
integer(c_int), public, parameter :: CDI_GRID_YLONGNAME = 906
integer(c_int), public, parameter :: CDI_GRID_XUNITS = 907
integer(c_int), public, parameter :: CDI_GRID_YUNITS = 908
integer(c_int), public, parameter :: CDI_GRID_VDIMNAME = 905
integer(c_int), public, parameter :: CDI_GRID_XLONGNAME = 906
integer(c_int), public, parameter :: CDI_GRID_YLONGNAME = 907
integer(c_int), public, parameter :: CDI_GRID_XUNITS = 908
integer(c_int), public, parameter :: CDI_GRID_YUNITS = 909
public :: cdiGridDefString
public :: cdiGridInqString
public :: gridDefXname
......
......@@ -1508,6 +1508,8 @@ void cdfDefCurvilinear(stream_t *streamptr, int gridID)
char xdimname[CDI_MAX_NAME+3];
char ydimname[CDI_MAX_NAME+3];
xdimname[0] = 0;
ydimname[0] = 0;
cdiGridInqString(gridID, CDI_GRID_XDIMNAME, CDI_MAX_NAME, xdimname);
cdiGridInqString(gridID, CDI_GRID_YDIMNAME, CDI_MAX_NAME, ydimname);
if ( xdimname[0] == 0 ) xdimname[0] = 'x';
......@@ -1569,9 +1571,13 @@ void cdfDefCurvilinear(stream_t *streamptr, int gridID)
if ( gridInqXboundsPtr(gridID) || gridInqYboundsPtr(gridID) )
{
char vdimname[CDI_MAX_NAME+3];
vdimname[0] = 0;
cdiGridInqString(gridID, CDI_GRID_VDIMNAME, CDI_MAX_NAME, vdimname);
if ( vdimname[0] == 0 ) strcpy(vdimname, "nv4");
size_t nvertex = 4;
if ( nc_inq_dimid(fileID, "nv4", &nvdimID) != NC_NOERR )
cdf_def_dim(fileID, "nv4", nvertex, &nvdimID);
if ( nc_inq_dimid(fileID, vdimname, &nvdimID) != NC_NOERR )
cdf_def_dim(fileID, vdimname, nvertex, &nvdimID);
}
dimIDs[0] = ydimID;
......@@ -1895,6 +1901,7 @@ void cdfDefUnstructured(stream_t *streamptr, int gridID)
int gridindex = vlistGridIndex(vlistID, gridID);
char xdimname[CDI_MAX_NAME+3];
xdimname[0] = 0;
cdiGridInqString(gridID, CDI_GRID_XDIMNAME, CDI_MAX_NAME, xdimname);
if ( xdimname[0] == 0 ) strcpy(xdimname, "ncells");
......@@ -1933,20 +1940,24 @@ void cdfDefUnstructured(stream_t *streamptr, int gridID)
if ( dimID == UNDEFID )
{
char vertname[CDI_MAX_NAME];
strcpy(vertname, "vertices");
checkGridName('V', xaxisname, fileID, vlistID, gridID, ngrids, 'X');
checkGridName('V', yaxisname, fileID, vlistID, gridID, ngrids, 'Y');
checkGridName('D', xdimname, fileID, vlistID, gridID, ngrids, 'X');
checkGridName('D', vertname, fileID, vlistID, gridID, ngrids, 'X');
if ( streamptr->ncmode == 2 ) cdf_redef(fileID);
cdf_def_dim(fileID, xdimname, dimlen, &dimID);
size_t nvertex = (size_t)gridInqNvertex(gridID);
if ( nvertex > 0 ) cdf_def_dim(fileID, vertname, nvertex, &nvdimID);
if ( nvertex > 0 )
{
char vdimname[CDI_MAX_NAME+3];
vdimname[0] = 0;
cdiGridInqString(gridID, CDI_GRID_VDIMNAME, CDI_MAX_NAME, vdimname);
if ( vdimname[0] == 0 ) strcpy(vdimname, "vertices");
checkGridName('D', vdimname, fileID, vlistID, gridID, ngrids, 'X');
cdf_def_dim(fileID, vdimname, nvertex, &nvdimID);
}
cdfDefGridReference(streamptr, gridID);
......@@ -5039,6 +5050,7 @@ void define_all_grids(stream_t *streamptr, int vlistID, ncdim_t *ncdims, int nva
{
int xdimids[2] = {-1,-1}, ydimids[2] = {-1,-1};
int xdimid = -1, ydimid = -1;
int vdimid = -1;
int islon = 0, islat = 0;
int nxdims = 0, nydims = 0;
size_t size = 0;
......@@ -5414,7 +5426,8 @@ void define_all_grids(stream_t *streamptr, int vlistID, ncdim_t *ncdims, int nva
int nbdims = ncvars[ncvars[xvarid].bounds].ndims;
if ( nbdims == 2 || nbdims == 3 )
{
size_t nvertex = ncdims[ncvars[ncvars[xvarid].bounds].dimids[nbdims-1]].len;
vdimid = ncvars[ncvars[xvarid].bounds].dimids[nbdims-1];
size_t nvertex = ncdims[vdimid].len;
grid->nvertex = (int)nvertex;
if (CDI_netcdf_lazy_grid_load)
{
......@@ -5459,9 +5472,8 @@ void define_all_grids(stream_t *streamptr, int vlistID, ncdim_t *ncdims, int nva
}
else
{
int vid
= ncvars[ncvars[yvarid].bounds].dimids[nbdims-1];
size_t nvertex = ncdims[vid].len;
vdimid = ncvars[ncvars[yvarid].bounds].dimids[nbdims-1];
size_t nvertex = ncdims[vdimid].len;
/*
if ( nvertex != grid->nvertex )
Warning("nvertex problem! nvertex x %d, nvertex y %d",
......@@ -5740,6 +5752,8 @@ void define_all_grids(stream_t *streamptr, int vlistID, ncdim_t *ncdims, int nva
cdiGridDefString(ncvars[ncvarid].gridID, CDI_GRID_XDIMNAME, strlen(ncdims[xdimid].name)+1, ncdims[xdimid].name);
if ( ydimid != -1 )
cdiGridDefString(ncvars[ncvarid].gridID, CDI_GRID_YDIMNAME, strlen(ncdims[ydimid].name)+1, ncdims[ydimid].name);
if ( vdimid != -1 )
cdiGridDefString(ncvars[ncvarid].gridID, CDI_GRID_VDIMNAME, strlen(ncdims[vdimid].name)+1, ncdims[vdimid].name);
if ( CDI_Debug )
Message("gridID %d %d %s", ncvars[ncvarid].gridID, ncvarid, ncvars[ncvarid].name);
......
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