Commit 3c500c02 authored by Uwe Schulzweida's avatar Uwe Schulzweida
Browse files

stream_srv: add support for GRID_CELL (bug fix)

parent fc612d05
......@@ -4,6 +4,8 @@
* configure: --with-szlib=<directory>
* configure: check stat.st_blksize [report: Klaus Wyser]
* fileOpen: add O_BINARY if available [report: Klaus Wyser]
* stream_cdf: add ICON grid support
* stream_srv: add support for GRID_CELL (bug fix)
* cdfInqContents: support of lon/lat units radian
* cdfInqContents: bug fix for gridtype cell
* cdfInqContents: bug fix for inconsistent curvilinear grid [report: Holger Goettel]
......
......@@ -39,7 +39,7 @@ int Zlevel = 0;
static void version(void)
{
fprintf(stderr, "CDI version 1.6.2\n");
fprintf(stderr, "CDI version 1.6.3\n");
cdiPrintVersion();
fprintf(stderr, "\n");
/*
......@@ -56,6 +56,7 @@ static void version(void)
1.6.0 1 Aug 2006 : add option -z szip for SZIP compression of GRIB records
1.6.1 27 Feb 2007 : short info with ltype for GENERIC zaxis
1.6.2 3 Jan 2008 : changes for CDI library version 1.1.0 (compress)
1.6.3 26 Mar 2008 : call streamDefTimestep also if ntsteps = 0 (buf fix)
*/
}
......@@ -974,7 +975,7 @@ int main(int argc, char *argv[])
if ( Info || fname2 )
while ( (nrecs = streamInqTimestep(streamID1, tsID)) > 0 )
{
if ( fname2 && ntsteps != 0 )
if ( fname2 /* && ntsteps != 0*/ )
streamDefTimestep(streamID2, tsID);
vdate = taxisInqVdate(taxisID);
......
......@@ -679,6 +679,10 @@ int gridCreate(int gridtype, int size)
{
gridDefXname(gridID, "x");
gridDefYname(gridID, "y");
strcpy(gridptr->xstdname, "grid_longitude");
strcpy(gridptr->ystdname, "grid_latitude");
gridDefXunits(gridID, "degrees");
gridDefYunits(gridID, "degrees");
break;
}
}
......
......@@ -1577,13 +1577,23 @@ void cdfDefGdim(int streamID, int gridID)
void cdfDefCell(int streamID, int gridID)
{
#if defined (HAVE_LIBNETCDF)
char axisname[6] = "cellX";
char axisname[] = "cellX";
char vertname[] = "nvX";
char xunits[256];
char xlongname[256];
char xstdname[256];
char yunits[256];
char ylongname[256];
char ystdname[256];
char xaxisname[256];
char yaxisname[256];
int index, iz = 0;
int gridID0, gridtype0, gridindex;
int dimID = UNDEFID;
int ngrids;
int fileID;
int dimlen, dimlen0;
size_t len;
int ncxvarid = UNDEFID, ncyvarid = UNDEFID;
int ncbxvarid = UNDEFID, ncbyvarid = UNDEFID, ncavarid = UNDEFID;
int nvertex, nvdimID = -1;
......@@ -1603,6 +1613,15 @@ void cdfDefCell(int streamID, int gridID)
dimlen = gridInqSize(gridID);
gridindex = vlistGridIndex(vlistID, gridID);
gridInqXname(gridID, xaxisname);
gridInqXlongname(gridID, xlongname);
gridInqXstdname(gridID, xstdname);
gridInqXunits(gridID, xunits);
gridInqYname(gridID, yaxisname);
gridInqYlongname(gridID, ylongname);
gridInqYstdname(gridID, ystdname);
gridInqYunits(gridID, yunits);
for ( index = 0; index < ngrids; index++ )
{
if ( streamptr->xdimID[index] != UNDEFID )
......@@ -1625,59 +1644,67 @@ void cdfDefCell(int streamID, int gridID)
if ( dimID == UNDEFID )
{
if ( iz == 0 ) axisname[4] = '\0';
else sprintf(&axisname[4], "%1d", iz+1);
if ( iz == 0 )
{
axisname[4] = '\0';
vertname[2] = '\0';
}
else
{
sprintf(&axisname[4], "%1d", iz+1);
sprintf(&vertname[2], "%1d", iz+1);
}
if ( streamptr->ncmode == 2 ) cdf_redef(fileID);
cdf_def_dim(fileID, axisname, dimlen, &dimID);
nvertex = gridInqNvertex(gridID);
if ( nvertex > 0 ) cdf_def_dim(fileID, "nv", nvertex, &nvdimID);
if ( nvertex > 0 ) cdf_def_dim(fileID, vertname, nvertex, &nvdimID);
if ( gridInqXvalsPtr(gridID) )
{
char xaxisname[] = "lon";
char units[] = "degrees_east";
char longname[] = "longitude";
cdf_def_var(fileID, xaxisname, (nc_type) xtype, 1, &dimID, &ncxvarid);
cdf_put_att_text(fileID, ncxvarid, "long_name", strlen(longname), longname);
cdf_put_att_text(fileID, ncxvarid, "units", strlen(units), units);
if ( (len = strlen(xlongname)) )
cdf_put_att_text(fileID, ncxvarid, "long_name", len, xlongname);
if ( (len = strlen(xunits)) )
cdf_put_att_text(fileID, ncxvarid, "units", len, xunits);
if ( (len = strlen(xstdname)) )
cdf_put_att_text(fileID, ncxvarid, "standard_name", len, xstdname);
streamptr->ncxvarID[gridindex] = ncxvarid;
if ( nvdimID != UNDEFID && gridInqXboundsPtr(gridID) )
{
char bxaxisname[] = "lon_vertices";
strcat(xaxisname, "_vertices");
int dimIDs[2];
dimIDs[0] = dimID;
dimIDs[1] = nvdimID;
cdf_def_var(fileID, bxaxisname, (nc_type) xtype, 2, dimIDs, &ncbxvarid);
cdf_put_att_text(fileID, ncxvarid, "bounds", strlen(bxaxisname), bxaxisname);
cdf_def_var(fileID, xaxisname, (nc_type) xtype, 2, dimIDs, &ncbxvarid);
cdf_put_att_text(fileID, ncxvarid, "bounds", strlen(xaxisname), xaxisname);
}
}
if ( gridInqYvalsPtr(gridID) )
{
char yaxisname[] = "lat";
char units[] = "degrees_north";
char longname[] = "latitude";
cdf_def_var(fileID, yaxisname, (nc_type) xtype, 1, &dimID, &ncyvarid);
cdf_put_att_text(fileID, ncyvarid, "long_name", strlen(longname), longname);
cdf_put_att_text(fileID, ncyvarid, "units", strlen(units), units);
if ( (len = strlen(ylongname)) )
cdf_put_att_text(fileID, ncyvarid, "long_name", len, ylongname);
if ( (len = strlen(yunits)) )
cdf_put_att_text(fileID, ncyvarid, "units", len, yunits);
if ( (len = strlen(ystdname)) )
cdf_put_att_text(fileID, ncyvarid, "standard_name", len, ystdname);
streamptr->ncyvarID[gridindex] = ncyvarid;
if ( nvdimID != UNDEFID && gridInqYboundsPtr(gridID) )
{
char byaxisname[] = "lat_vertices";
strcat(yaxisname, "_vertices");
int dimIDs[2];
dimIDs[0] = dimID;
dimIDs[1] = nvdimID;
cdf_def_var(fileID, byaxisname, (nc_type) xtype, 2, dimIDs, &ncbyvarid);
cdf_put_att_text(fileID, ncyvarid, "bounds", strlen(byaxisname), byaxisname);
cdf_def_var(fileID, yaxisname, (nc_type) xtype, 2, dimIDs, &ncbyvarid);
cdf_put_att_text(fileID, ncyvarid, "bounds", strlen(yaxisname), yaxisname);
}
}
......
......@@ -218,6 +218,7 @@ int srvDefRecord(int streamID)
header[1] = streamptr->record->level;
header[2] = streamptr->record->date;
header[3] = streamptr->record->time;
xsize = gridInqXsize(gridID);
ysize = gridInqYsize(gridID);
if ( xsize == 0 || ysize == 0 )
......@@ -225,6 +226,10 @@ int srvDefRecord(int streamID)
xsize = gridInqSize(gridID);
ysize = 1;
}
if ( gridInqType(gridID) == GRID_CELL ) ysize = 1;
if ( gridInqSize(gridID) != xsize*ysize )
Error(func, "Internal problem with gridsize!");
header[4] = xsize;
header[5] = ysize;
header[6] = 0;
......@@ -953,6 +958,7 @@ void srvWriteVarDP(int streamID, int varID, const double *data)
int zaxisID;
double level;
int header[8];
int xsize, ysize;
int datatype;
int tsID;
int vlistID;
......@@ -979,13 +985,20 @@ void srvWriteVarDP(int streamID, int varID, const double *data)
header[0] = vlistInqVarCode(vlistID, varID);
header[2] = streamptr->tsteps[tsID].taxis.vdate;
header[3] = streamptr->tsteps[tsID].taxis.vtime;
header[4] = gridInqXsize(gridID);
header[5] = gridInqYsize(gridID);
if ( header[4] == 0 )
xsize = gridInqXsize(gridID);
ysize = gridInqYsize(gridID);
if ( xsize == 0 || ysize == 0 )
{
header[4] = gridInqSize(gridID);
header[5] = 1;
xsize = gridInqSize(gridID);
ysize = 1;
}
if ( gridInqType(gridID) == GRID_CELL ) ysize = 1;
if ( gridInqSize(gridID) != xsize*ysize )
Error(func, "Internal problem with gridsize!");
header[4] = xsize;
header[5] = ysize;
header[6] = 0;
header[7] = 0;
......@@ -993,7 +1006,7 @@ void srvWriteVarDP(int streamID, int varID, const double *data)
srvp->dprec = srvDefDatatype(datatype);
for ( levID = 0; levID < nlevs; levID++ )
for ( levID = 0; levID < nlevs; levID++ )
{
level = zaxisInqLevel(zaxisID, levID);
......@@ -1013,6 +1026,7 @@ void srvWriteVarSliceDP(int streamID, int varID, int levID, const double *data)
int zaxisID;
double level;
int header[8];
int xsize, ysize;
int datatype;
int tsID;
int vlistID;
......@@ -1036,13 +1050,20 @@ void srvWriteVarSliceDP(int streamID, int varID, int levID, const double *data)
header[1] = (int) level;
header[2] = streamptr->tsteps[tsID].taxis.vdate;
header[3] = streamptr->tsteps[tsID].taxis.vtime;
header[4] = gridInqXsize(gridID);
header[5] = gridInqYsize(gridID);
if ( header[4] == 0 )
xsize = gridInqXsize(gridID);
ysize = gridInqYsize(gridID);
if ( xsize == 0 || ysize == 0 )
{
header[4] = gridInqSize(gridID);
header[5] = 1;
xsize = gridInqSize(gridID);
ysize = 1;
}
if ( gridInqType(gridID) == GRID_CELL ) ysize = 1;
if ( gridInqSize(gridID) != xsize*ysize )
Error(func, "Internal problem with gridsize!");
header[4] = xsize;
header[5] = ysize;
header[6] = 0;
header[7] = 0;
......
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