Commit 59fc05c5 authored by Uwe Schulzweida's avatar Uwe Schulzweida
Browse files

netCDF: added attibute CDI_grid_latitudes for gaussian_reduced grid.

parent 711ef55b
......@@ -390,6 +390,10 @@ void cdfInqDimIds(stream_t *streamptr, int varId, int (*outDimIds)[3])
(*outDimIds)[0] = streamptr->ncgrid[gridindex].ncIDs[CDF_DIMID_X];
break;
case GRID_GAUSSIAN_REDUCED:
(*outDimIds)[0] = streamptr->ncgrid[gridindex].ncIDs[CDF_DIMID_X];
break;
default:
(*outDimIds)[0] = streamptr->ncgrid[gridindex].ncIDs[CDF_DIMID_X];
(*outDimIds)[1] = streamptr->ncgrid[gridindex].ncIDs[CDF_DIMID_Y];
......
......@@ -373,10 +373,6 @@ void cdfDefineCoordinates(const stream_t *streamptr, int ncvarID, int nczvarID,
{
const int fileID = streamptr->fileID;
char coordinates[CDI_MAX_NAME]; coordinates[0] = 0;
if (nczvarID != CDI_UNDEFID) cdfAppendCoordinates(fileID, nczvarID, coordinates);
if ( gridtype != GRID_GENERIC && gridtype != GRID_LONLAT && gridtype != GRID_GAUSSIAN &&
gridtype != GRID_PROJECTION && gridtype != GRID_CURVILINEAR && gridtype != GRID_CHARXY )
{
......@@ -394,6 +390,15 @@ void cdfDefineCoordinates(const stream_t *streamptr, int ncvarID, int nczvarID,
if (numLPE > 0)
cdf_put_att_int(fileID, ncvarID, "CDI_grid_num_LPE", NC_INT, 1, &numLPE);
const int ncyvarID = streamptr->ncgrid[gridindex].ncIDs[CDF_VARID_Y];
if (ncyvarID != CDI_UNDEFID)
{
char name[CDI_MAX_NAME]; name[0] = 0;
cdf_inq_varname(fileID, ncyvarID, name);
size_t len = strlen(name);
cdf_put_att_text(fileID, ncvarID, "CDI_grid_latitudes", len, name);
}
const int ncrpvarID = streamptr->ncgrid[gridindex].ncIDs[CDF_VARID_RP];
if (ncrpvarID != CDI_UNDEFID)
{
......@@ -404,6 +409,12 @@ void cdfDefineCoordinates(const stream_t *streamptr, int ncvarID, int nczvarID,
}
}
// define coordinates attribute
char coordinates[CDI_MAX_NAME]; coordinates[0] = 0;
if (nczvarID != CDI_UNDEFID) cdfAppendCoordinates(fileID, nczvarID, coordinates);
if ( gridtype == GRID_TRAJECTORY )
{
cdf_put_att_text(fileID, ncvarID, "coordinates", 9, "tlon tlat");
......@@ -417,10 +428,12 @@ void cdfDefineCoordinates(const stream_t *streamptr, int ncvarID, int nczvarID,
}
else if ( gridtype == GRID_GAUSSIAN_REDUCED )
{
/*
const int ncxvarID = streamptr->ncgrid[gridindex].ncIDs[CDF_VARID_X];
const int ncyvarID = streamptr->ncgrid[gridindex].ncIDs[CDF_VARID_Y];
cdfAppendCoordinates(fileID, ncyvarID, coordinates);
cdfAppendCoordinates(fileID, ncxvarID, coordinates);
*/
}
else if ( gridtype == GRID_UNSTRUCTURED || gridtype == GRID_CURVILINEAR )
{
......@@ -669,7 +682,8 @@ int cdfDefVar(stream_t *streamptr, int varID)
const int gridtype = gridInqType(gridID);
const int gridindex = nc_grid_index(streamptr, gridID);
const int xid = (gridtype != GRID_TRAJECTORY) ? streamptr->ncgrid[gridindex].ncIDs[CDF_DIMID_X] : CDI_UNDEFID;
const int yid = (gridtype != GRID_TRAJECTORY) ? streamptr->ncgrid[gridindex].ncIDs[CDF_DIMID_Y] : CDI_UNDEFID;
const int yid = (gridtype != GRID_TRAJECTORY && gridtype != GRID_GAUSSIAN_REDUCED) ?
streamptr->ncgrid[gridindex].ncIDs[CDF_DIMID_Y] : CDI_UNDEFID;
const int zaxisID = vlistInqVarZaxis(vlistID, varID);
const int zaxistype = zaxisInqType(zaxisID);
......@@ -997,7 +1011,8 @@ void cdfGetXYZid(stream_t *streamptr, int gridID, int zaxisID, int *xid, int *yi
*xid = CDI_UNDEFID;
*yid = CDI_UNDEFID;
if (gridInqType(gridID) == GRID_TRAJECTORY)
const int gridtype = gridInqType(gridID);
if (gridtype == GRID_TRAJECTORY)
{
cdfWriteGridTraj(streamptr, gridID);
}
......@@ -1005,7 +1020,8 @@ void cdfGetXYZid(stream_t *streamptr, int gridID, int zaxisID, int *xid, int *yi
{
const int gridindex = nc_grid_index(streamptr, gridID);
*xid = streamptr->ncgrid[gridindex].ncIDs[CDF_DIMID_X];
*yid = streamptr->ncgrid[gridindex].ncIDs[CDF_DIMID_Y];
if (gridtype != GRID_GAUSSIAN_REDUCED)
*yid = streamptr->ncgrid[gridindex].ncIDs[CDF_DIMID_Y];
}
const int vlistID = streamptr->vlistID;
......
......@@ -67,6 +67,7 @@ typedef struct {
int zdim;
int xvarid;
int yvarid;
int rpvarid;
int zvarid;
int cvarids[MAX_COORDVARS];
int tvarid;
......@@ -80,6 +81,7 @@ typedef struct {
int tableID;
int truncation;
int position;
int numLPE;
bool defmissval;
bool deffillval;
int xtype;
......@@ -610,6 +612,7 @@ void init_ncvars(long nvars, ncvar_t *ncvars)
ncvars[ncvarid].zdim = CDI_UNDEFID;
ncvars[ncvarid].xvarid = CDI_UNDEFID;
ncvars[ncvarid].yvarid = CDI_UNDEFID;
ncvars[ncvarid].rpvarid = CDI_UNDEFID;
ncvars[ncvarid].zvarid = CDI_UNDEFID;
ncvars[ncvarid].tvarid = CDI_UNDEFID;
ncvars[ncvarid].psvarid = CDI_UNDEFID;
......@@ -632,6 +635,7 @@ void init_ncvars(long nvars, ncvar_t *ncvars)
ncvars[ncvarid].vct = NULL;
ncvars[ncvarid].truncation = 0;
ncvars[ncvarid].position = 0;
ncvars[ncvarid].numLPE = 0;
ncvars[ncvarid].positive = 0;
ncvars[ncvarid].chunked = 0;
ncvars[ncvarid].chunktype = CDI_UNDEFID;
......@@ -1197,6 +1201,38 @@ void cdfScanVarAttr(int nvars, ncvar_t *ncvars, int ndims, ncdim_t *ncdims, int
set_gridtype(attstring, &ncvars[ncvarid].gridtype);
cdf_set_var(ncvars, ncvarid, TRUE);
}
else if ( isText && strIsEqual(attname, "CDI_grid_latitudes") )
{
int nc_yvar_id;
int status = nc_inq_varid(ncid, attstring, &nc_yvar_id);
if ( status == NC_NOERR )
{
ncvars[ncvarid].yvarid = nc_yvar_id;
cdf_set_var(ncvars, ncvars[ncvarid].yvarid, FALSE);
}
else
Warning("%s - %s", nc_strerror(status), attstring);
cdf_set_var(ncvars, ncvarid, TRUE);
}
else if ( isText && strIsEqual(attname, "CDI_grid_reduced_points") )
{
int nc_rpvar_id;
int status = nc_inq_varid(ncid, attstring, &nc_rpvar_id);
if ( status == NC_NOERR )
{
ncvars[ncvarid].rpvarid = nc_rpvar_id;
cdf_set_var(ncvars, ncvars[ncvarid].rpvarid, FALSE);
}
else
Warning("%s - %s", nc_strerror(status), attstring);
cdf_set_var(ncvars, ncvarid, TRUE);
}
else if ( isNumber && strIsEqual(attname, "CDI_grid_num_LPE") )
{
cdfGetAttInt(ncid, ncvarid, attname, 1, &ncvars[ncvarid].numLPE);
}
else if ( isText && strIsEqual(attname, "level_type") )
{
strToLower(attstring);
......@@ -2337,10 +2373,11 @@ bool cdf_read_coordinates(struct cdfLazyGrid *restrict lazyGrid, ncvar_t *ncvar,
xsize, &ysize, ntdims, start, count, &islat) )
return true;
if ( ysize == 0 ) size = xsize;
if ( ncvar->gridtype == GRID_UNSTRUCTURED ) size = xsize;
else if ( ncvar->gridtype == GRID_GAUSSIAN_REDUCED ) size = xsize;
else if ( ysize == 0 ) size = xsize;
else if ( xsize == 0 ) size = ysize;
else if ( ncvar->gridtype == GRID_UNSTRUCTURED ) size = xsize;
else size = xsize*ysize;
else size = xsize*ysize;
if ( ncvar->gridtype == CDI_UNDEFID || ncvar->gridtype == GRID_GENERIC )
cdf_check_gridtype(&ncvar->gridtype, islon, islat, xsize, ysize, grid);
......@@ -2410,6 +2447,24 @@ bool cdf_read_coordinates(struct cdfLazyGrid *restrict lazyGrid, ncvar_t *ncvar,
break;
}
case GRID_GAUSSIAN_REDUCED:
{
if (ncvar->numLPE > 0 && ncvar->rpvarid != CDI_UNDEFID)
{
if (ncvars[ncvar->rpvarid].ndims == 1)
{
grid->size = size;
int dimid = ncvars[ncvar->rpvarid].dimids[0];
size_t ysize = ncdims[dimid].len;
grid->y.size = ysize;
grid->reducedPointsSize = ysize;
grid->reducedPoints = (int*) Malloc(ysize*sizeof(int));
cdf_get_var_int(ncvar->ncid, ncvar->rpvarid, grid->reducedPoints);
grid->np = ncvar->numLPE;
}
}
break;
}
case GRID_SPECTRAL:
{
grid->size = size;
......@@ -2726,7 +2781,8 @@ int cdf_define_all_grids(ncgrid_t *ncgrid, int vlistID, ncdim_t *ncdims, int nva
ncgrid[gridindex].gridID = gridID;
if (xdimid != CDI_UNDEFID) ncgrid[gridindex].ncIDs[CDF_DIMID_X] = ncdims[xdimid].dimid;
if (ydimid != CDI_UNDEFID) ncgrid[gridindex].ncIDs[CDF_DIMID_Y] = ncdims[ydimid].dimid;
if ( grid->type == GRID_TRAJECTORY )
if (grid->type == GRID_TRAJECTORY)
{
ncgrid[gridindex].ncIDs[CDF_VARID_X] = xvarid;
ncgrid[gridindex].ncIDs[CDF_VARID_Y] = yvarid;
......
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