Commit 092865f6 authored by Thomas Jahns's avatar Thomas Jahns 🤸
Browse files

Transform ncgrid xdimID into array component.

* With the conversion of the other IDs it will be easier to iterate
  over these field programmatically.
parent 5ba03c52
......@@ -23,7 +23,7 @@ void cdfReadGridTraj(stream_t *streamptr, int gridID)
int fileID = streamptr->fileID;
int gridindex = vlistGridIndex(vlistID, gridID);
int lonID = streamptr->ncgrid[gridindex].xdimID;
int lonID = streamptr->ncgrid[gridindex].ncIDs[CDF_DIMID_X];
int latID = streamptr->ncgrid[gridindex].ydimID;
int tsID = streamptr->curTsID;
......@@ -56,7 +56,7 @@ void cdfGetSlapDescription(stream_t *streamptr, int varID, size_t (*start)[4], s
}
else
{
xid = streamptr->ncgrid[gridindex].xdimID;
xid = streamptr->ncgrid[gridindex].ncIDs[CDF_DIMID_X];
yid = streamptr->ncgrid[gridindex].ydimID;
}
int zaxisindex = vlistZaxisIndex(vlistID, zaxisID);
......@@ -369,11 +369,11 @@ void cdfInqDimIds(stream_t *streamptr, int varId, int (*outDimIds)[3])
break;
case GRID_UNSTRUCTURED:
(*outDimIds)[0] = streamptr->ncgrid[gridindex].xdimID;
(*outDimIds)[0] = streamptr->ncgrid[gridindex].ncIDs[CDF_DIMID_X];
break;
default:
(*outDimIds)[0] = streamptr->ncgrid[gridindex].xdimID;
(*outDimIds)[0] = streamptr->ncgrid[gridindex].ncIDs[CDF_DIMID_X];
(*outDimIds)[1] = streamptr->ncgrid[gridindex].ydimID;
break;
}
......
......@@ -355,7 +355,7 @@ int cdfDefVar(stream_t *streamptr, int varID)
int gridindex = nc_grid_index(streamptr, gridID);
if ( gridtype != GRID_TRAJECTORY )
{
xid = streamptr->ncgrid[gridindex].xdimID;
xid = streamptr->ncgrid[gridindex].ncIDs[CDF_DIMID_X];
yid = streamptr->ncgrid[gridindex].ydimID;
if ( xid != CDI_UNDEFID ) cdf_inq_dimlen(fileID, xid, &xsize);
if ( yid != CDI_UNDEFID ) cdf_inq_dimlen(fileID, yid, &ysize);
......@@ -754,7 +754,7 @@ static
void cdfWriteGridTraj(stream_t *streamptr, int gridID)
{
int gridindex = nc_grid_index(streamptr, gridID);
int lonID = streamptr->ncgrid[gridindex].xdimID;
int lonID = streamptr->ncgrid[gridindex].ncIDs[CDF_DIMID_X];
int latID = streamptr->ncgrid[gridindex].ydimID;
double xlon = gridInqXval(gridID, 0);
......@@ -980,7 +980,7 @@ void cdf_write_var(stream_t *streamptr, int varID, int memtype, const void *data
else
{
int gridindex = nc_grid_index(streamptr, gridID);
xid = streamptr->ncgrid[gridindex].xdimID;
xid = streamptr->ncgrid[gridindex].ncIDs[CDF_DIMID_X];
yid = streamptr->ncgrid[gridindex].ydimID;
}
......@@ -1077,7 +1077,7 @@ void cdf_write_var_chunk(stream_t *streamptr, int varID, int memtype,
else
{
int gridindex = nc_grid_index(streamptr, gridID);
xid = streamptr->ncgrid[gridindex].xdimID;
xid = streamptr->ncgrid[gridindex].ncIDs[CDF_DIMID_X];
yid = streamptr->ncgrid[gridindex].ydimID;
}
......@@ -1175,7 +1175,7 @@ void cdf_write_var_slice(stream_t *streamptr, int varID, int levelID, int memtyp
else
{
int gridindex = nc_grid_index(streamptr, gridID);
xid = streamptr->ncgrid[gridindex].xdimID;
xid = streamptr->ncgrid[gridindex].ncIDs[CDF_DIMID_X];
yid = streamptr->ncgrid[gridindex].ydimID;
}
......
......@@ -217,9 +217,13 @@ typedef struct {
VCT;
#ifdef HAVE_LIBNETCDF
enum {
CDF_DIMID_X,
CDF_SIZE_ncIDs,
};
typedef struct {
int gridID;
int xdimID;
int ncIDs[CDF_SIZE_ncIDs];
int ydimID;
int xvarID;
int yvarID;
......
......@@ -892,7 +892,8 @@ void streamDefaultValue ( stream_t * streamptr )
for ( int i = 0; i < MAX_GRIDS_PS; i++ )
{
streamptr->ncgrid[i].gridID = CDI_UNDEFID;
streamptr->ncgrid[i].xdimID = CDI_UNDEFID;
for (size_t j = 0; j < CDF_SIZE_ncIDs; ++j)
streamptr->ncgrid[i].ncIDs[j] = CDI_UNDEFID;
streamptr->ncgrid[i].ydimID = CDI_UNDEFID;
streamptr->ncgrid[i].xvarID = CDI_UNDEFID;
streamptr->ncgrid[i].yvarID = CDI_UNDEFID;
......
......@@ -2654,7 +2654,7 @@ void cdf_define_all_grids(ncgrid_t *ncgrid, int vlistID, ncdim_t *ncdims, int nv
int gridindex = vlistGridIndex(vlistID, gridID);
ncgrid[gridindex].gridID = gridID;
ncgrid[gridindex].xdimID = xdimid;
ncgrid[gridindex].ncIDs[CDF_DIMID_X] = xdimid;
ncgrid[gridindex].ydimID = ydimid;
if ( xdimid == CDI_UNDEFID && ydimid == CDI_UNDEFID && grid->size == 1 )
......@@ -2998,7 +2998,7 @@ void cdf_define_all_vars(stream_t *streamptr, int vlistID, int instID, int model
vlistInqVarGrid(vlistID, varID), vlistInqVarZaxis(vlistID, varID));
int gridindex = vlistGridIndex(vlistID, gridID);
int xdimid = streamptr->ncgrid[gridindex].xdimID;
int xdimid = streamptr->ncgrid[gridindex].ncIDs[CDF_DIMID_X];
int ydimid = streamptr->ncgrid[gridindex].ydimID;
int zaxisindex = vlistZaxisIndex(vlistID, zaxisID);
......
......@@ -342,13 +342,13 @@ void cdfDefComplex(stream_t *streamptr, int gridID, int gridindex)
for ( int index = 0; index < gridindex; ++index )
{
if ( ncgrid[index].xdimID != CDI_UNDEFID )
if ( ncgrid[index].ncIDs[CDF_DIMID_X] != CDI_UNDEFID )
{
int gridID0 = ncgrid[index].gridID;
int gridtype0 = gridInqType(gridID0);
if ( gridtype0 == GRID_SPECTRAL || gridtype0 == GRID_FOURIER )
{
dimID = ncgrid[index].xdimID;
dimID = ncgrid[index].ncIDs[CDF_DIMID_X];
break;
}
}
......@@ -367,7 +367,7 @@ void cdfDefComplex(stream_t *streamptr, int gridID, int gridindex)
}
ncgrid[gridindex].gridID = gridID;
ncgrid[gridindex].xdimID = dimID;
ncgrid[gridindex].ncIDs[CDF_DIMID_X] = dimID;
}
static void
......@@ -508,7 +508,7 @@ cdfDefTrajLatLon(stream_t *streamptr, int gridID, int gridindex,
int ncvarid = CDI_UNDEFID;
if ( dimtype == 'X' )
ncvarid = ncgrid[gridindex].xdimID;
ncvarid = ncgrid[gridindex].ncIDs[CDF_DIMID_X];
else
ncvarid = ncgrid[gridindex].ydimID;
......@@ -529,7 +529,7 @@ cdfDefTrajLatLon(stream_t *streamptr, int gridID, int gridindex,
ncgrid[gridindex].gridID = gridID;
if ( dimtype == 'X' )
ncgrid[gridindex].xdimID = ncvarid; /* var ID for trajectory !!! */
ncgrid[gridindex].ncIDs[CDF_DIMID_X] = ncvarid; /* var ID for trajectory !!! */
else
ncgrid[gridindex].ydimID = ncvarid; /* var ID for trajectory !!! */
}
......@@ -690,7 +690,7 @@ cdfDefAxisCommon(stream_t *streamptr, int gridID, int gridindex, int ndims,
if ( IS_EQUAL(inqVal(gridID0, 0), inqVal(gridID, 0)) &&
IS_EQUAL(inqVal(gridID0, (int)dimlen-1), inqVal(gridID, (int)dimlen-1)) )
{
dimID = (dimKey == CDI_KEY_XDIMNAME) ? ncgrid[index].xdimID : ncgrid[index].ydimID;
dimID = (dimKey == CDI_KEY_XDIMNAME) ? ncgrid[index].ncIDs[CDF_DIMID_X] : ncgrid[index].ydimID;
break;
}
}
......@@ -783,7 +783,7 @@ cdfDefAxisCommon(stream_t *streamptr, int gridID, int gridindex, int ndims,
ncgrid[gridindex].gridID = gridID;
if ( dimKey == CDI_KEY_XDIMNAME )
ncgrid[gridindex].xdimID = dimID;
ncgrid[gridindex].ncIDs[CDF_DIMID_X] = dimID;
else
ncgrid[gridindex].ydimID = dimID;
}
......@@ -845,7 +845,7 @@ void cdfDefCurvilinear(stream_t *streamptr, int gridID, int gridindex)
for ( int index = 0; index < gridindex; index++ )
{
if ( ncgrid[index].xdimID != CDI_UNDEFID )
if ( ncgrid[index].ncIDs[CDF_DIMID_X] != CDI_UNDEFID )
{
int gridID0 = ncgrid[index].gridID;
int gridtype0 = gridInqType(gridID0);
......@@ -858,7 +858,7 @@ void cdfDefCurvilinear(stream_t *streamptr, int gridID, int gridindex)
IS_EQUAL(gridInqYval(gridID0, 0), gridInqYval(gridID, 0)) &&
IS_EQUAL(gridInqYval(gridID0, (int)dimlen-1), gridInqYval(gridID, (int)dimlen-1)) )
{
xdimID = ncgrid[index].xdimID;
xdimID = ncgrid[index].ncIDs[CDF_DIMID_X];
ydimID = ncgrid[index].ydimID;
ncxvarid = ncgrid[index].xvarID;
ncyvarid = ncgrid[index].yvarID;
......@@ -982,7 +982,7 @@ void cdfDefCurvilinear(stream_t *streamptr, int gridID, int gridindex)
}
ncgrid[gridindex].gridID = gridID;
ncgrid[gridindex].xdimID = xdimID;
ncgrid[gridindex].ncIDs[CDF_DIMID_X] = xdimID;
ncgrid[gridindex].ydimID = ydimID;
ncgrid[gridindex].xvarID = ncxvarid;
ncgrid[gridindex].yvarID = ncyvarid;
......@@ -1000,7 +1000,7 @@ void cdfDefRgrid(stream_t *streamptr, int gridID, int gridindex)
int iz = 0;
for ( int index = 0; index < gridindex; index++ )
{
if ( ncgrid[index].xdimID != CDI_UNDEFID )
if ( ncgrid[index].ncIDs[CDF_DIMID_X] != CDI_UNDEFID )
{
int gridID0 = ncgrid[index].gridID;
int gridtype0 = gridInqType(gridID0);
......@@ -1010,7 +1010,7 @@ void cdfDefRgrid(stream_t *streamptr, int gridID, int gridindex)
if ( dimlen == dimlen0 )
{
dimID = ncgrid[index].xdimID;
dimID = ncgrid[index].ncIDs[CDF_DIMID_X];
break;
}
iz++;
......@@ -1042,7 +1042,7 @@ void cdfDefRgrid(stream_t *streamptr, int gridID, int gridindex)
}
ncgrid[gridindex].gridID = gridID;
ncgrid[gridindex].xdimID = dimID;
ncgrid[gridindex].ncIDs[CDF_DIMID_X] = dimID;
}
static
......@@ -1057,7 +1057,7 @@ void cdfDefGdim(stream_t *streamptr, int gridID, int gridindex)
if ( gridInqYsize(gridID) == 0 )
for ( int index = 0; index < gridindex; index++ )
{
if ( ncgrid[index].xdimID != CDI_UNDEFID )
if ( ncgrid[index].ncIDs[CDF_DIMID_X] != CDI_UNDEFID )
{
int gridID0 = ncgrid[index].gridID;
int gridtype0 = gridInqType(gridID0);
......@@ -1066,7 +1066,7 @@ void cdfDefGdim(stream_t *streamptr, int gridID, int gridindex)
size_t dimlen0 = (size_t)gridInqSize(gridID0);
if ( dimlen == dimlen0 )
{
dimID = ncgrid[index].xdimID;
dimID = ncgrid[index].ncIDs[CDF_DIMID_X];
break;
}
else
......@@ -1113,7 +1113,7 @@ void cdfDefGdim(stream_t *streamptr, int gridID, int gridindex)
}
ncgrid[gridindex].gridID = gridID;
ncgrid[gridindex].xdimID = dimID;
ncgrid[gridindex].ncIDs[CDF_DIMID_X] = dimID;
}
static
......@@ -1183,7 +1183,7 @@ void cdfDefUnstructured(stream_t *streamptr, int gridID, int gridindex)
for ( int index = 0; index < gridindex; index++ )
{
if ( ncgrid[index].xdimID != CDI_UNDEFID )
if ( ncgrid[index].ncIDs[CDF_DIMID_X] != CDI_UNDEFID )
{
int gridID0 = ncgrid[index].gridID;
int gridtype0 = gridInqType(gridID0);
......@@ -1197,7 +1197,7 @@ void cdfDefUnstructured(stream_t *streamptr, int gridID, int gridindex)
IS_EQUAL(gridInqYval(gridID0, 0), gridInqYval(gridID, 0)) &&
IS_EQUAL(gridInqYval(gridID0, (int)dimlen-1), gridInqYval(gridID, (int)dimlen-1)) )
{
dimID = ncgrid[index].xdimID;
dimID = ncgrid[index].ncIDs[CDF_DIMID_X];
ncxvarid = ncgrid[index].xvarID;
ncyvarid = ncgrid[index].yvarID;
ncavarid = ncgrid[index].avarID;
......@@ -1312,7 +1312,7 @@ void cdfDefUnstructured(stream_t *streamptr, int gridID, int gridindex)
}
ncgrid[gridindex].gridID = gridID;
ncgrid[gridindex].xdimID = dimID;
ncgrid[gridindex].ncIDs[CDF_DIMID_X] = dimID;
ncgrid[gridindex].xvarID = ncxvarid;
ncgrid[gridindex].yvarID = ncyvarid;
ncgrid[gridindex].avarID = ncavarid;
......@@ -1975,7 +1975,7 @@ void cdf_def_mapping(stream_t *streamptr, int gridID)
static
void cdfDefGrid(stream_t *streamptr, int gridID, int gridindex)
{
if ( streamptr->ncgrid[gridindex].xdimID != CDI_UNDEFID ) return;
if ( streamptr->ncgrid[gridindex].ncIDs[CDF_DIMID_X] != CDI_UNDEFID ) return;
int gridtype = gridInqType(gridID);
int size = gridInqSize(gridID);
......@@ -2077,7 +2077,7 @@ void cdfDefVars(stream_t *streamptr)
for ( int index = 0; index < 2*ngrids; ++index )
{
streamptr->ncgrid[index].gridID = CDI_UNDEFID;
streamptr->ncgrid[index].xdimID = CDI_UNDEFID;
streamptr->ncgrid[index].ncIDs[CDF_DIMID_X] = CDI_UNDEFID;
streamptr->ncgrid[index].ydimID = CDI_UNDEFID;
streamptr->ncgrid[index].xvarID = CDI_UNDEFID;
streamptr->ncgrid[index].yvarID = CDI_UNDEFID;
......
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