Commit 6f773b52 authored by Uwe Schulzweida's avatar Uwe Schulzweida
Browse files

added function cgribexGetGrid

parent 8d03d6b5
......@@ -4854,6 +4854,7 @@ void define_all_grids(stream_t *streamptr, int fileID, int vlistID, ncdim_t *ncd
size_t size = 0, xsize, ysize;
char name[256];
int iatt;
int ltwarn = TRUE;
size_t attlen;
char attname[256];
const int attstringlen = 8192; char attstring[8192];
......@@ -4975,8 +4976,10 @@ void define_all_grids(stream_t *streamptr, int fileID, int vlistID, ncdim_t *ncd
if ( ncvars[xvarid].ndims == 3 && ncvars[xvarid].dimids[0] == timedimid &&
ncvars[yvarid].ndims == 3 && ncvars[yvarid].dimids[0] == timedimid )
{
Warning("Time varying grids unsupported, using grid at time step 1!");
if ( ltwarn )
Warning("Time varying grids unsupported, using grid at time step 1!");
ltgrid = TRUE;
ltwarn = FALSE;
start[0] = start[1] = start[2] = 0;
count[0] = 1; count[1] = ysize; count[2] = xsize;
}
......
......@@ -159,44 +159,9 @@ int cgribexGetTsteptype(int timerange)
#if defined (HAVE_LIBCGRIBEX)
static
void cgribexAddRecord(int streamID, int param, int *isec1, int *isec2, double *fsec2, double *fsec3,
int *isec4, long recsize, off_t position, int prec, int ztype, int lmv)
void cgribexGetGrid(stream_t *streamptr, int *isec2, int *isec4, grid_t *grid)
{
int gridtype;
int zaxistype;
int gridID = CDI_UNDEFID, varID;
int levelID = 0;
int tsID, recID;
int level1, level2;
int numavg;
int tsteptype;
int lbounds = 0;
record_t *record;
grid_t grid;
int vlistID;
stream_t *streamptr;
streamptr = stream_to_pointer(streamID);
vlistID = streamInqVlist(streamID);
tsID = streamptr->curTsID;
recID = recordNewEntry(streamID, tsID);
record = &streamptr->tsteps[tsID].records[recID];
tsteptype = cgribexGetTsteptype(ISEC1_TimeRange);
numavg = ISEC1_AvgNum;
level1 = ISEC1_Level1;
level2 = ISEC1_Level2;
/* fprintf(stderr, "param %d %d %d %d\n", param, level1, level2, ISEC1_LevelType); */
(*record).size = recsize;
(*record).position = position;
(*record).param = param;
(*record).ilevel = level1;
(*record).ilevel2 = level2;
(*record).ltype = ISEC1_LevelType;
int gridtype;
gridtype = cgribexGetGridType(isec2);
......@@ -207,7 +172,7 @@ void cgribexAddRecord(int streamID, int param, int *isec1, int *isec2, double *f
ISEC4_NumValues = ISEC2_NumLon*ISEC2_NumLat;
}
memset(&grid, 0, sizeof(grid_t));
memset(grid, 0, sizeof(grid_t));
switch (gridtype)
{
case GRID_LONLAT:
......@@ -216,93 +181,93 @@ void cgribexAddRecord(int streamID, int param, int *isec1, int *isec2, double *f
if ( ISEC4_NumValues != ISEC2_NumLon*ISEC2_NumLat )
Error("numberOfPoints (%d) and gridSize (%d) differ!",
ISEC4_NumValues, ISEC2_NumLon*ISEC2_NumLat);
grid.size = ISEC4_NumValues;
grid.xsize = ISEC2_NumLon;
grid.ysize = ISEC2_NumLat;
grid.xinc = 0;
grid.yinc = 0;
grid.xdef = 0;
grid->size = ISEC4_NumValues;
grid->xsize = ISEC2_NumLon;
grid->ysize = ISEC2_NumLat;
grid->xinc = 0;
grid->yinc = 0;
grid->xdef = 0;
/* if ( ISEC2_FirstLon != 0 || ISEC2_LastLon != 0 ) */
{
if ( grid.xsize > 1 )
if ( grid->xsize > 1 )
{
if ( ISEC2_ResFlag && ISEC2_LonIncr > 0 )
if ( ISEC2_LonIncr*(grid.xsize-1) > 360000 ) ISEC2_LonIncr = 0;
if ( ISEC2_LonIncr*(grid->xsize-1) > 360000 ) ISEC2_LonIncr = 0;
if ( ISEC2_ResFlag && ISEC2_LonIncr > 0 )
grid.xinc = ISEC2_LonIncr * 0.001;
grid->xinc = ISEC2_LonIncr * 0.001;
else
grid.xinc = (ISEC2_LastLon - ISEC2_FirstLon) * 0.001 / (grid.xsize - 1);
grid->xinc = (ISEC2_LastLon - ISEC2_FirstLon) * 0.001 / (grid->xsize - 1);
/* correct xinc if necessary */
if ( ISEC2_FirstLon == 0 && ISEC2_LastLon > 354000 )
{
double xinc = 360. / grid.xsize;
double xinc = 360. / grid->xsize;
if ( fabs(grid.xinc-xinc) > 0.0 )
if ( fabs(grid->xinc-xinc) > 0.0 )
{
grid.xinc = xinc;
if ( CDI_Debug ) Message("set xinc to %g", grid.xinc);
grid->xinc = xinc;
if ( CDI_Debug ) Message("set xinc to %g", grid->xinc);
}
}
}
grid.xfirst = ISEC2_FirstLon * 0.001;
grid.xlast = ISEC2_LastLon * 0.001;
grid.xdef = 2;
grid->xfirst = ISEC2_FirstLon * 0.001;
grid->xlast = ISEC2_LastLon * 0.001;
grid->xdef = 2;
}
grid.ydef = 0;
grid->ydef = 0;
/* if ( ISEC2_FirstLat != 0 || ISEC2_LastLat != 0 ) */
{
if ( grid.ysize > 1 )
if ( grid->ysize > 1 )
{
if ( ISEC2_ResFlag && ISEC2_LatIncr > 0 )
if ( ISEC2_LatIncr*(grid.ysize-1) > 180000 ) ISEC2_LatIncr = 0;
if ( ISEC2_LatIncr*(grid->ysize-1) > 180000 ) ISEC2_LatIncr = 0;
if ( ISEC2_ResFlag && ISEC2_LatIncr > 0 )
grid.yinc = ISEC2_LatIncr * 0.001;
grid->yinc = ISEC2_LatIncr * 0.001;
else
grid.yinc = (ISEC2_LastLat - ISEC2_FirstLat) * 0.001 / (grid.ysize - 1);
grid->yinc = (ISEC2_LastLat - ISEC2_FirstLat) * 0.001 / (grid->ysize - 1);
}
grid.yfirst = ISEC2_FirstLat * 0.001;
grid.ylast = ISEC2_LastLat * 0.001;
grid.ydef = 2;
grid->yfirst = ISEC2_FirstLat * 0.001;
grid->ylast = ISEC2_LastLat * 0.001;
grid->ydef = 2;
}
break;
}
case GRID_GAUSSIAN_REDUCED:
{
grid.size = ISEC4_NumValues;
grid.rowlon = ISEC2_RowLonPtr;
grid.ysize = ISEC2_NumLat;
grid.xinc = 0;
grid.yinc = 0;
grid.xdef = 0;
grid->size = ISEC4_NumValues;
grid->rowlon = ISEC2_RowLonPtr;
grid->ysize = ISEC2_NumLat;
grid->xinc = 0;
grid->yinc = 0;
grid->xdef = 0;
/* if ( ISEC2_FirstLon != 0 || ISEC2_LastLon != 0 ) */
{
if ( grid.xsize > 1 )
if ( grid->xsize > 1 )
{
if ( ISEC2_ResFlag && ISEC2_LonIncr > 0 )
grid.xinc = ISEC2_LonIncr * 0.001;
grid->xinc = ISEC2_LonIncr * 0.001;
else
grid.xinc = (ISEC2_LastLon - ISEC2_FirstLon) * 0.001 / (grid.xsize - 1);
grid->xinc = (ISEC2_LastLon - ISEC2_FirstLon) * 0.001 / (grid->xsize - 1);
}
grid.xfirst = ISEC2_FirstLon * 0.001;
grid.xlast = ISEC2_LastLon * 0.001;
grid.xdef = 2;
grid->xfirst = ISEC2_FirstLon * 0.001;
grid->xlast = ISEC2_LastLon * 0.001;
grid->xdef = 2;
}
grid.ydef = 0;
grid->ydef = 0;
/* if ( ISEC2_FirstLat != 0 || ISEC2_LastLat != 0 ) */
{
if ( grid.ysize > 1 )
if ( grid->ysize > 1 )
{
if ( ISEC2_ResFlag && ISEC2_LatIncr > 0 )
grid.yinc = ISEC2_LatIncr * 0.001;
grid->yinc = ISEC2_LatIncr * 0.001;
else
grid.yinc = (ISEC2_LastLat - ISEC2_FirstLat) * 0.001 / (grid.ysize - 1);
grid->yinc = (ISEC2_LastLat - ISEC2_FirstLat) * 0.001 / (grid->ysize - 1);
}
grid.yfirst = ISEC2_FirstLat * 0.001;
grid.ylast = ISEC2_LastLat * 0.001;
grid.ydef = 2;
grid->yfirst = ISEC2_FirstLat * 0.001;
grid->ylast = ISEC2_LastLat * 0.001;
grid->ydef = 2;
}
break;
}
......@@ -312,50 +277,50 @@ void cgribexAddRecord(int streamID, int param, int *isec1, int *isec2, double *f
Error("numberOfPoints (%d) and gridSize (%d) differ!",
ISEC4_NumValues, ISEC2_NumLon*ISEC2_NumLat);
grid.size = ISEC4_NumValues;
grid.xsize = ISEC2_NumLon;
grid.ysize = ISEC2_NumLat;
grid->size = ISEC4_NumValues;
grid->xsize = ISEC2_NumLon;
grid->ysize = ISEC2_NumLat;
grid.lcc_xinc = ISEC2_Lambert_dx;
grid.lcc_yinc = ISEC2_Lambert_dy;
grid.lcc_originLon = ISEC2_FirstLon * 0.001;
grid.lcc_originLat = ISEC2_FirstLat * 0.001;
grid.lcc_lonParY = ISEC2_Lambert_Lov * 0.001;
grid.lcc_lat1 = ISEC2_Lambert_LatS1 * 0.001;
grid.lcc_lat2 = ISEC2_Lambert_LatS2 * 0.001;
grid.lcc_projflag = ISEC2_Lambert_ProjFlag;
grid.lcc_scanflag = ISEC2_ScanFlag;
grid->lcc_xinc = ISEC2_Lambert_dx;
grid->lcc_yinc = ISEC2_Lambert_dy;
grid->lcc_originLon = ISEC2_FirstLon * 0.001;
grid->lcc_originLat = ISEC2_FirstLat * 0.001;
grid->lcc_lonParY = ISEC2_Lambert_Lov * 0.001;
grid->lcc_lat1 = ISEC2_Lambert_LatS1 * 0.001;
grid->lcc_lat2 = ISEC2_Lambert_LatS2 * 0.001;
grid->lcc_projflag = ISEC2_Lambert_ProjFlag;
grid->lcc_scanflag = ISEC2_ScanFlag;
grid.xdef = 0;
grid.ydef = 0;
grid->xdef = 0;
grid->ydef = 0;
break;
}
case GRID_SPECTRAL:
{
grid.size = ISEC4_NumValues;
grid.trunc = ISEC2_PentaJ;
grid->size = ISEC4_NumValues;
grid->trunc = ISEC2_PentaJ;
if ( ISEC2_RepMode == 2 )
grid.lcomplex = 1;
grid->lcomplex = 1;
else
grid.lcomplex = 0;
grid->lcomplex = 0;
break;
}
case GRID_GME:
{
grid.size = ISEC4_NumValues;
grid.nd = ISEC2_GME_ND;
grid.ni = ISEC2_GME_NI;
grid.ni2 = ISEC2_GME_NI2;
grid.ni3 = ISEC2_GME_NI3;
grid->size = ISEC4_NumValues;
grid->nd = ISEC2_GME_ND;
grid->ni = ISEC2_GME_NI;
grid->ni2 = ISEC2_GME_NI2;
grid->ni3 = ISEC2_GME_NI3;
break;
}
case GRID_GENERIC:
{
grid.size = ISEC4_NumValues;
grid.xsize = 0;
grid.ysize = 0;
grid->size = ISEC4_NumValues;
grid->xsize = 0;
grid->ysize = 0;
break;
}
default:
......@@ -365,18 +330,62 @@ void cgribexAddRecord(int streamID, int param, int *isec1, int *isec2, double *f
}
}
grid.isRotated = FALSE;
grid->isRotated = FALSE;
if ( cgribexGetIsRotated(isec2) )
{
grid.isRotated = TRUE;
grid.ypole = - ISEC2_LatSP * 0.001;
grid.xpole = ISEC2_LonSP * 0.001 - 180;
grid.angle = 0;
grid->isRotated = TRUE;
grid->ypole = - ISEC2_LatSP * 0.001;
grid->xpole = ISEC2_LonSP * 0.001 - 180;
grid->angle = 0;
}
grid.xvals = NULL;
grid.yvals = NULL;
grid.type = gridtype;
grid->xvals = NULL;
grid->yvals = NULL;
grid->type = gridtype;
}
#endif
#if defined (HAVE_LIBCGRIBEX)
static
void cgribexAddRecord(int streamID, int param, int *isec1, int *isec2, double *fsec2, double *fsec3,
int *isec4, long recsize, off_t position, int prec, int ztype, int lmv)
{
int zaxistype;
int gridID = CDI_UNDEFID, varID;
int levelID = 0;
int tsID, recID;
int level1, level2;
int numavg;
int tsteptype;
int lbounds = 0;
record_t *record;
grid_t grid;
int vlistID;
stream_t *streamptr;
streamptr = stream_to_pointer(streamID);
vlistID = streamInqVlist(streamID);
tsID = streamptr->curTsID;
recID = recordNewEntry(streamID, tsID);
record = &streamptr->tsteps[tsID].records[recID];
tsteptype = cgribexGetTsteptype(ISEC1_TimeRange);
numavg = ISEC1_AvgNum;
level1 = ISEC1_Level1;
level2 = ISEC1_Level2;
/* fprintf(stderr, "param %d %d %d %d\n", param, level1, level2, ISEC1_LevelType); */
(*record).size = recsize;
(*record).position = position;
(*record).param = param;
(*record).ilevel = level1;
(*record).ilevel2 = level2;
(*record).ltype = ISEC1_LevelType;
cgribexGetGrid(streamptr, isec2, isec4, &grid);
gridID = varDefGrid(vlistID, grid, 0);
......
......@@ -73,13 +73,11 @@ int gribapiGetGridType(grib_handle *gh)
switch (gribgridtype)
{
case GRIB2_GTYPE_LATLON: { GRIB_CHECK(grib_get_long(gh, "Ni", &lpar), 0);
// printf("lpar = %ld\n", lpar);
if ( lpar < 0 ) break;
}
case GRIB2_GTYPE_LATLON_ROT: { gridtype = GRID_LONLAT; break; }
case GRIB2_GTYPE_LCC: { gridtype = GRID_LCC; break; }
case GRIB2_GTYPE_GAUSSIAN: { GRIB_CHECK(grib_get_long(gh, "Ni", &lpar), 0);
// printf("lpar = %ld\n", lpar);
if ( lpar < 0 )
gridtype = GRID_GAUSSIAN_REDUCED;
else
......@@ -603,7 +601,8 @@ void gribapiAddRecord(int streamID, int param, grib_handle *gh,
if ( grib_get_long(gh, "Nj", &lpar) == 0 ) nlat = lpar;
grid.size = numberOfPoints;
if ( nlon && nlat )
if ( nlon > 0 && nlat > 0 && nlon*nlat == grid.size )
{
grid.xsize = nlon;
grid.ysize = nlat;
......
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