Commit f799a0bc authored by Uwe Schulzweida's avatar Uwe Schulzweida
Browse files

added support for GRIB Gaussian grid parameter N

parent f53677f6
...@@ -2523,7 +2523,7 @@ int gridCompare(int gridID, grid_t grid) ...@@ -2523,7 +2523,7 @@ int gridCompare(int gridID, grid_t grid)
printf("grid xlast %f\n", gridInqXval(gridID, grid.size-1)); printf("grid xlast %f\n", gridInqXval(gridID, grid.size-1));
printf("grid ylast %f\n", gridInqYval(gridID, grid.size-1)); printf("grid ylast %f\n", gridInqYval(gridID, grid.size-1));
printf("grid.nv %d\n", grid.nvertex); printf("grid.nv %d\n", grid.nvertex);
printf("grid nv %d\n", gridInqNvertex(gridID)); printf("grid nv %d\n", gridInqNvertex(gridID));
*/ */
if ( grid.xsize == gridInqXsize(gridID) && grid.ysize == gridInqYsize(gridID) ) if ( grid.xsize == gridInqXsize(gridID) && grid.ysize == gridInqYsize(gridID) )
differ = compareXYvals2(gridID, grid.size, grid.xvals, grid.yvals); differ = compareXYvals2(gridID, grid.size, grid.xvals, grid.yvals);
...@@ -2552,7 +2552,7 @@ int gridGenerate(grid_t grid) ...@@ -2552,7 +2552,7 @@ int gridGenerate(grid_t grid)
grid_check_ptr(gridID, gridptr); grid_check_ptr(gridID, gridptr);
gridDefPrec(gridID, grid.prec); gridDefPrec(gridID, grid.prec);
switch (grid.type) switch (grid.type)
{ {
case GRID_LONLAT: case GRID_LONLAT:
...@@ -2569,6 +2569,8 @@ int gridGenerate(grid_t grid) ...@@ -2569,6 +2569,8 @@ int gridGenerate(grid_t grid)
if ( grid.xsize > 0 ) gridDefXsize(gridID, grid.xsize); if ( grid.xsize > 0 ) gridDefXsize(gridID, grid.xsize);
if ( grid.ysize > 0 ) gridDefYsize(gridID, grid.ysize); if ( grid.ysize > 0 ) gridDefYsize(gridID, grid.ysize);
if ( grid.type == GRID_GAUSSIAN ) gridDefNP(gridID, grid.np);
if ( grid.nvertex > 0 ) if ( grid.nvertex > 0 )
gridDefNvertex(gridID, grid.nvertex); gridDefNvertex(gridID, grid.nvertex);
...@@ -2647,6 +2649,7 @@ int gridGenerate(grid_t grid) ...@@ -2647,6 +2649,7 @@ int gridGenerate(grid_t grid)
} }
case GRID_GAUSSIAN_REDUCED: case GRID_GAUSSIAN_REDUCED:
{ {
gridDefNP(gridID, grid.np);
gridDefYsize(gridID, grid.ysize); gridDefYsize(gridID, grid.ysize);
gridDefRowlon(gridID, grid.ysize, grid.rowlon); gridDefRowlon(gridID, grid.ysize, grid.rowlon);
......
...@@ -162,7 +162,7 @@ int cgribexGetTsteptype(int timerange) ...@@ -162,7 +162,7 @@ int cgribexGetTsteptype(int timerange)
static static
void cgribexGetGrid(stream_t *streamptr, int *isec2, int *isec4, grid_t *grid) void cgribexGetGrid(stream_t *streamptr, int *isec2, int *isec4, grid_t *grid)
{ {
int gridtype; int gridtype;
gridtype = cgribexGetGridType(isec2); gridtype = cgribexGetGridType(isec2);
...@@ -185,6 +185,7 @@ void cgribexGetGrid(stream_t *streamptr, int *isec2, int *isec4, grid_t *grid) ...@@ -185,6 +185,7 @@ void cgribexGetGrid(stream_t *streamptr, int *isec2, int *isec4, grid_t *grid)
grid->size = ISEC4_NumValues; grid->size = ISEC4_NumValues;
grid->xsize = ISEC2_NumLon; grid->xsize = ISEC2_NumLon;
grid->ysize = ISEC2_NumLat; grid->ysize = ISEC2_NumLat;
if ( gridtype == GRID_GAUSSIAN ) grid->np = ISEC2_NumPar;
grid->xinc = 0; grid->xinc = 0;
grid->yinc = 0; grid->yinc = 0;
grid->xdef = 0; grid->xdef = 0;
...@@ -214,7 +215,7 @@ void cgribexGetGrid(stream_t *streamptr, int *isec2, int *isec4, grid_t *grid) ...@@ -214,7 +215,7 @@ void cgribexGetGrid(stream_t *streamptr, int *isec2, int *isec4, grid_t *grid)
} }
grid->xfirst = ISEC2_FirstLon * 0.001; grid->xfirst = ISEC2_FirstLon * 0.001;
grid->xlast = ISEC2_LastLon * 0.001; grid->xlast = ISEC2_LastLon * 0.001;
grid->xdef = 2; grid->xdef = 2;
} }
grid->ydef = 0; grid->ydef = 0;
/* if ( ISEC2_FirstLat != 0 || ISEC2_LastLat != 0 ) */ /* if ( ISEC2_FirstLat != 0 || ISEC2_LastLat != 0 ) */
...@@ -231,18 +232,19 @@ void cgribexGetGrid(stream_t *streamptr, int *isec2, int *isec4, grid_t *grid) ...@@ -231,18 +232,19 @@ void cgribexGetGrid(stream_t *streamptr, int *isec2, int *isec4, grid_t *grid)
} }
grid->yfirst = ISEC2_FirstLat * 0.001; grid->yfirst = ISEC2_FirstLat * 0.001;
grid->ylast = ISEC2_LastLat * 0.001; grid->ylast = ISEC2_LastLat * 0.001;
grid->ydef = 2; grid->ydef = 2;
} }
break; break;
} }
case GRID_GAUSSIAN_REDUCED: case GRID_GAUSSIAN_REDUCED:
{ {
grid->np = ISEC2_NumPar;
grid->size = ISEC4_NumValues; grid->size = ISEC4_NumValues;
grid->rowlon = ISEC2_RowLonPtr; grid->rowlon = ISEC2_RowLonPtr;
grid->ysize = ISEC2_NumLat; grid->ysize = ISEC2_NumLat;
grid->xinc = 0; grid->xinc = 0;
grid->yinc = 0; grid->yinc = 0;
grid->xdef = 0; grid->xdef = 0;
/* if ( ISEC2_FirstLon != 0 || ISEC2_LastLon != 0 ) */ /* if ( ISEC2_FirstLon != 0 || ISEC2_LastLon != 0 ) */
{ {
if ( grid->xsize > 1 ) if ( grid->xsize > 1 )
...@@ -254,7 +256,7 @@ void cgribexGetGrid(stream_t *streamptr, int *isec2, int *isec4, grid_t *grid) ...@@ -254,7 +256,7 @@ void cgribexGetGrid(stream_t *streamptr, int *isec2, int *isec4, grid_t *grid)
} }
grid->xfirst = ISEC2_FirstLon * 0.001; grid->xfirst = ISEC2_FirstLon * 0.001;
grid->xlast = ISEC2_LastLon * 0.001; grid->xlast = ISEC2_LastLon * 0.001;
grid->xdef = 2; grid->xdef = 2;
} }
grid->ydef = 0; grid->ydef = 0;
/* if ( ISEC2_FirstLat != 0 || ISEC2_LastLat != 0 ) */ /* if ( ISEC2_FirstLat != 0 || ISEC2_LastLat != 0 ) */
...@@ -268,7 +270,7 @@ void cgribexGetGrid(stream_t *streamptr, int *isec2, int *isec4, grid_t *grid) ...@@ -268,7 +270,7 @@ void cgribexGetGrid(stream_t *streamptr, int *isec2, int *isec4, grid_t *grid)
} }
grid->yfirst = ISEC2_FirstLat * 0.001; grid->yfirst = ISEC2_FirstLat * 0.001;
grid->ylast = ISEC2_LastLat * 0.001; grid->ylast = ISEC2_LastLat * 0.001;
grid->ydef = 2; grid->ydef = 2;
} }
break; break;
} }
...@@ -292,7 +294,7 @@ void cgribexGetGrid(stream_t *streamptr, int *isec2, int *isec4, grid_t *grid) ...@@ -292,7 +294,7 @@ void cgribexGetGrid(stream_t *streamptr, int *isec2, int *isec4, grid_t *grid)
grid->lcc_projflag = ISEC2_Lambert_ProjFlag; grid->lcc_projflag = ISEC2_Lambert_ProjFlag;
grid->lcc_scanflag = ISEC2_ScanFlag; grid->lcc_scanflag = ISEC2_ScanFlag;
grid->xdef = 0; grid->xdef = 0;
grid->ydef = 0; grid->ydef = 0;
break; break;
...@@ -1711,8 +1713,8 @@ void cgribexDefGrid(int *isec1, int *isec2, int *isec4, int gridID) ...@@ -1711,8 +1713,8 @@ void cgribexDefGrid(int *isec1, int *isec2, int *isec4, int gridID)
double yfirst = 0, ylast = 0, yinc = 0; double yfirst = 0, ylast = 0, yinc = 0;
if ( gridtype == GRID_GAUSSIAN || gridtype == GRID_GAUSSIAN_REDUCED ) if ( gridtype == GRID_GAUSSIAN || gridtype == GRID_GAUSSIAN_REDUCED )
ISEC2_GridType = GRIB1_GTYPE_GAUSSIAN; ISEC2_GridType = GRIB1_GTYPE_GAUSSIAN;
else if ( gridtype == GRID_LONLAT && gridIsRotated(gridID) ) else if ( gridtype == GRID_LONLAT && gridIsRotated(gridID) )
ISEC2_GridType = GRIB1_GTYPE_LATLON_ROT; ISEC2_GridType = GRIB1_GTYPE_LATLON_ROT;
else else
ISEC2_GridType = GRIB1_GTYPE_LATLON; ISEC2_GridType = GRIB1_GTYPE_LATLON;
...@@ -1778,7 +1780,11 @@ void cgribexDefGrid(int *isec1, int *isec2, int *isec4, int gridID) ...@@ -1778,7 +1780,11 @@ void cgribexDefGrid(int *isec1, int *isec2, int *isec4, int gridID)
ISEC2_LonIncr = 0; ISEC2_LonIncr = 0;
if ( gridtype == GRID_GAUSSIAN || gridtype == GRID_GAUSSIAN_REDUCED ) if ( gridtype == GRID_GAUSSIAN || gridtype == GRID_GAUSSIAN_REDUCED )
ISEC2_NumPar = nlat/2; {
int np = gridInqNP(gridID);
if ( np == 0 ) np = nlat/2;
ISEC2_NumPar = np;
}
else else
{ {
ISEC2_LatIncr = NINT(yinc*1000); ISEC2_LatIncr = NINT(yinc*1000);
......
...@@ -270,9 +270,16 @@ void gribapiGetGrid(grib_handle *gh, grid_t *grid) ...@@ -270,9 +270,16 @@ void gribapiGetGrid(grib_handle *gh, grid_t *grid)
GRIB_CHECK(grib_get_long(gh, "Nj", &lpar), 0); GRIB_CHECK(grib_get_long(gh, "Nj", &lpar), 0);
nlat = lpar; nlat = lpar;
if ( gridtype == GRID_GAUSSIAN )
{
GRIB_CHECK(grib_get_long(gh, "numberOfParallelsBetweenAPoleAndTheEquator", &lpar), 0);
grid->np = lpar;
}
if ( numberOfPoints != nlon*nlat ) if ( numberOfPoints != nlon*nlat )
Error("numberOfPoints (%d) and gridSize (%d) differ!", Error("numberOfPoints (%d) and gridSize (%d) differ!",
(int)numberOfPoints, nlon*nlat); (int)numberOfPoints, nlon*nlat);
grid->size = numberOfPoints; grid->size = numberOfPoints;
grid->xsize = nlon; grid->xsize = nlon;
grid->ysize = nlat; grid->ysize = nlat;
...@@ -331,6 +338,9 @@ void gribapiGetGrid(grib_handle *gh, grid_t *grid) ...@@ -331,6 +338,9 @@ void gribapiGetGrid(grib_handle *gh, grid_t *grid)
size_t dummy; size_t dummy;
long *pl; long *pl;
GRIB_CHECK(grib_get_long(gh, "numberOfParallelsBetweenAPoleAndTheEquator", &lpar), 0);
grid->np = lpar;
GRIB_CHECK(grib_get_long(gh, "Nj", &lpar), 0); GRIB_CHECK(grib_get_long(gh, "Nj", &lpar), 0);
nlat = lpar; nlat = lpar;
...@@ -1628,7 +1638,7 @@ int gribapiScanTimestep(int streamID) ...@@ -1628,7 +1638,7 @@ int gribapiScanTimestep(int streamID)
cdiParamToString(param, paramstr, sizeof(paramstr)); cdiParamToString(param, paramstr, sizeof(paramstr));
if ( memcmp(&datetime, &datetime0, sizeof(DateTime)) != 0 ) break; if ( memcmp(&datetime, &datetime0, sizeof(DateTime)) != 0 ) break;
if ( CDI_Debug ) if ( CDI_Debug )
Warning("Param=%s level=%d already exist, skipped!", paramstr, level1); Warning("Param=%s level=%d already exist, skipped!", paramstr, level1);
...@@ -1638,7 +1648,7 @@ int gribapiScanTimestep(int streamID) ...@@ -1638,7 +1648,7 @@ int gribapiScanTimestep(int streamID)
{ {
streamptr->tsteps[tsID].records[recID].used = TRUE; streamptr->tsteps[tsID].records[recID].used = TRUE;
streamptr->tsteps[tsID].recIDs[rindex] = recID; streamptr->tsteps[tsID].recIDs[rindex] = recID;
} }
} }
if ( CDI_Debug ) if ( CDI_Debug )
...@@ -1657,7 +1667,7 @@ int gribapiScanTimestep(int streamID) ...@@ -1657,7 +1667,7 @@ int gribapiScanTimestep(int streamID)
streamptr->tsteps[tsID].records[recID].ilevel, level1); streamptr->tsteps[tsID].records[recID].ilevel, level1);
Error("Invalid, unsupported or inconsistent record structure"); Error("Invalid, unsupported or inconsistent record structure");
} }
streamptr->tsteps[tsID].records[recID].position = recpos; streamptr->tsteps[tsID].records[recID].position = recpos;
streamptr->tsteps[tsID].records[recID].size = recsize; streamptr->tsteps[tsID].records[recID].size = recsize;
...@@ -2147,7 +2157,11 @@ void gribapiDefGrid(grib_handle *gh, int gridID, int ljpeg) ...@@ -2147,7 +2157,11 @@ void gribapiDefGrid(grib_handle *gh, int gridID, int ljpeg)
ISEC2_LonIncr = 0; ISEC2_LonIncr = 0;
*/ */
if ( gridtype == GRID_GAUSSIAN || gridtype == GRID_GAUSSIAN_REDUCED ) if ( gridtype == GRID_GAUSSIAN || gridtype == GRID_GAUSSIAN_REDUCED )
GRIB_CHECK(grib_set_long(gh, "numberOfParallelsBetweenAPoleAndTheEquator", nlat/2), 0); {
int np = gridInqNP(gridID);
if ( np == 0 ) np = nlat/2;
GRIB_CHECK(grib_set_long(gh, "numberOfParallelsBetweenAPoleAndTheEquator", np), 0);
}
else else
{ {
latIncr = yinc; latIncr = yinc;
......
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