Commit 73157f7d authored by Uwe Schulzweida's avatar Uwe Schulzweida
Browse files

changed gribhandle from grid/level to variable

parent bc0e645a
......@@ -114,7 +114,7 @@ extern "C" {
#define GRID_FOURIER 6
#define GRID_GME 7 /* Icosahedral-hexagonal GME Grid */
#define GRID_TRAJECTORY 8
#define GRID_CELL 9
#define GRID_UNSTRUCTURED 9
#define GRID_CURVILINEAR 10
#define GRID_LCC 11 /* Lambert Conformal Conic (GRIB) */
#define GRID_LCC2 12 /* Lambert Conformal Conic (PROJ) */
......
......@@ -39,7 +39,6 @@ const char *gribapiLibraryVersion(void)
void gribapiDefHandles(int streamID)
{
stream_t *streamptr;
int vlistID, ngrids, nzaxis, i;
streamptr = stream_to_pointer(streamID);
......@@ -50,14 +49,11 @@ void gribapiDefHandles(int streamID)
else
#endif
{
vlistID = streamInqVlist(streamID);
ngrids = vlistNgrids(vlistID);
nzaxis = vlistNzaxis(vlistID);
int i;
streamptr->gribHandleNums = ngrids*nzaxis;
streamptr->gribHandle = (void **) malloc(streamptr->gribHandleNums*sizeof(void *));
streamptr->gribHandle = (void **) malloc(streamptr->nvars*sizeof(void *));
for ( i = 0; i < streamptr->gribHandleNums; ++i )
for ( i = 0; i < streamptr->nvars; ++i )
streamptr->gribHandle[i] = gribHandleNew();
}
}
......
......@@ -1107,17 +1107,16 @@ void streamClose(int streamID)
case FILETYPE_GRB2:
{
gribClose(fileID);
if ( streamptr->gribHandleNums )
if ( streamptr->gribHandle )
{
int i;
for ( i = 0; i < streamptr->gribHandleNums; ++i )
for ( i = 0; i < streamptr->nvars; ++i )
{
gribHandleDelete(streamptr->gribHandle[0]);
streamptr->gribHandle[i] = NULL;
}
free(streamptr->gribHandle);
streamptr->gribHandle = NULL;
streamptr->gribHandleNums = 0;
}
break;
}
......
......@@ -493,11 +493,7 @@ int grbWriteVarSliceDP(int streamID, int varID, int levelID, const double *data,
else
#endif
{
int ngrids = vlistNgrids(vlistID);
int ghindex = ngrids*vlistGridIndex(vlistID, gridID) + vlistZaxisIndex(vlistID, zaxisID);
if ( ghindex >= streamptr->gribHandleNums )
Error("Internal problem, grib handle not found!");
gh = streamptr->gribHandle[ghindex];
gh = streamptr->gribHandle[varID];
}
if ( streamptr->ztype == COMPRESS_JPEG )
......
......@@ -1969,6 +1969,7 @@ static
void gribapiDefGrid(grib_handle *gh, int gridID, int ljpeg)
{
int gridtype;
int status;
static short lwarn = TRUE;
size_t len;
const char *mesg;
......@@ -2219,9 +2220,20 @@ void gribapiDefGrid(grib_handle *gh, int gridID, int ljpeg)
}
case GRID_CELL:
{
GRIB_CHECK(grib_set_long(gh, "gridDefinitionTemplateNumber", GRIBAPI_GTYPE_CELL), 0);
GRIB_CHECK(grib_set_long(gh, "numberOfGridUsed", 0), 0);
GRIB_CHECK(grib_set_long(gh, "numberOfGridInReference", 0), 0);
static int warning = 1;
status = grib_set_long(gh, "gridDefinitionTemplateNumber", GRIBAPI_GTYPE_CELL);
if ( status != 0 && warning )
{
warning = 0;
Warning("Can not write grid number!");
Warning("gridDefinitionTemplateNumber %d not found (grib2/template.3.%d.def)!",
GRIBAPI_GTYPE_CELL, GRIBAPI_GTYPE_CELL);
}
else
{
GRIB_CHECK(grib_set_long(gh, "numberOfGridUsed", 0), 0);
GRIB_CHECK(grib_set_long(gh, "numberOfGridInReference", 0), 0);
}
break;
}
......
......@@ -425,7 +425,6 @@ void stream_init_entry(stream_t *streamptr)
streamptr->nfiles = 0;
streamptr->fnames = NULL;
streamptr->gribHandleNums = 0;
streamptr->gribHandle = NULL;
}
......
......@@ -241,7 +241,6 @@ typedef struct {
int curfile;
int nfiles;
char **fnames;
int gribHandleNums;
void **gribHandle;
}
stream_t;
......
Supports Markdown
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