Commit 9dcde362 authored by Uwe Schulzweida's avatar Uwe Schulzweida
Browse files

test performance of global gribHandle

parent 9a13992e
......@@ -31,5 +31,7 @@
#define GRIBAPI_GTYPE_GME 192 /* hexagonal GME grid */
const char *gribapiLibraryVersion(void);
void *gribHandleNew();
void gribHandleDelete(void *gh);
#endif /* _GRIBAPI_H */
......@@ -702,6 +702,10 @@ int streamOpen(const char *filename, const char *filemode, int filetype)
vlistptr = vlist_to_pointer(streamptr->vlistID);
vlistptr->ntsteps = streamNtsteps(streamID);
}
else if ( streamptr->filemode == 'w' )
{
if ( filetype == FILETYPE_GRB2 ) streamptr->gribHandle = gribHandleNew();
}
}
return (streamID);
......@@ -1121,6 +1125,11 @@ void streamClose(int streamID)
case FILETYPE_GRB2:
{
gribClose(fileID);
if ( streamptr->gribHandle )
{
gribHandleDelete(streamptr->gribHandle);
streamptr->gribHandle = NULL;
}
break;
}
#endif
......
......@@ -372,7 +372,8 @@ void grbReadVarSliceDP(int streamID, int varID, int levelID, double *data, int *
static
size_t grbEncode(int filetype, int varID, int levelID, int vlistID, int gridID, int zaxisID, int date, int time, int numavg,
long datasize, const double *data, int nmiss, unsigned char *gribbuffer, size_t gribbuffersize, int ljpeg)
long datasize, const double *data, int nmiss, unsigned char *gribbuffer, size_t gribbuffersize,
int ljpeg, void *gribHandle)
{
size_t nbytes;
......@@ -384,7 +385,7 @@ size_t grbEncode(int filetype, int varID, int levelID, int vlistID, int gridID,
else
{
nbytes = gribapiEncode(varID, levelID, vlistID, gridID, zaxisID, date, time, numavg,
datasize, data, nmiss, gribbuffer, gribbuffersize, ljpeg);
datasize, data, nmiss, gribbuffer, gribbuffersize, ljpeg, gribHandle);
}
return (nbytes);
......@@ -478,7 +479,7 @@ int grbWriteVarSliceDP(int streamID, int varID, int levelID, const double *data,
}
nbytes = grbEncode(filetype, varID, levelID, vlistID, gridID, zaxisID, date, time, numavg,
datasize, data, nmiss, gribbuffer, gribbuffersize, ljpeg);
datasize, data, nmiss, gribbuffer, gribbuffersize, ljpeg, streamptr->gribHandle);
if ( streamptr->ztype == COMPRESS_SZIP )
nbytes = grbSzip(filetype, gribbuffer, nbytes);
......
......@@ -1870,6 +1870,7 @@ void gribapiDefLevel(grib_handle *gh, int param, int zaxisID, int levelID)
}
// ISEC2_NumVCP = 0;
// GRIB_CHECK(grib_set_long(gh, "PVPresent", 0), 0);
switch (zaxistype)
{
......@@ -2029,8 +2030,28 @@ void gribapiDefLevel(grib_handle *gh, int param, int zaxisID, int levelID)
#endif
void *gribHandleNew()
{
static char func[] = "gribHandleNew";
void *gh = NULL;
gh = (void *) grib_handle_new_from_template(NULL, "GRIB2");
if ( gh == NULL ) Error(func, "grib_handle_new_from_template failed!");
return (gh);
}
void gribHandleDelete(void *gh)
{
grib_handle_delete(gh);
}
#define GRIBAPIENCODETEST 1
size_t gribapiEncode(int varID, int levelID, int vlistID, int gridID, int zaxisID, int date, int time, int numavg,
long datasize, const double *data, int nmiss, unsigned char *gribbuffer, size_t gribbuffersize, int ljpeg)
long datasize, const double *data, int nmiss, unsigned char *gribbuffer, size_t gribbuffersize,
int ljpeg, void *gribHandle)
{
static char func[] = "gribapiEncode";
size_t nbytes = 0;
......@@ -2050,9 +2071,11 @@ size_t gribapiEncode(int varID, int levelID, int vlistID, int gridID, int zaxisI
datatype = vlistInqVarDatatype(vlistID, varID);
if ( param == CDI_UNDEFPARAM ) param = cdiEncodeParam(255, tabnum, code);
gh = grib_handle_new_from_template(NULL, "GRIB2");
if ( gh == NULL ) Error(func, "grib_handle_new_from_template failed!");
#if defined(GRIBAPIENCODETEST)
gh = (grib_handle *) gribHandleNew();
#else
gh = gribHandle;
#endif
GRIB_CHECK(grib_set_long(gh, "editionNumber", edition), 0);
......@@ -2085,7 +2108,9 @@ size_t gribapiEncode(int varID, int levelID, int vlistID, int gridID, int zaxisI
/* get a copy of the coded message */
GRIB_CHECK(grib_get_message_copy(gh, gribbuffer, &recsize), 0);
grib_handle_delete(gh);
#if defined(GRIBAPIENCODETEST)
gribHandleDelete(gh);
#endif
nbytes = recsize;
#else
......
......@@ -9,6 +9,7 @@ int gribapiDecode(unsigned char *gribbuffer, int gribsize, double *data, int gri
int unreduced, int *nmiss, int *zip);
size_t gribapiEncode(int varID, int levelID, int vlistID, int gridID, int zaxisID, int date, int time, int numavg,
long datasize, const double *data, int nmiss, unsigned char *gribbuffer, size_t gribbuffersize, int ljpeg);
long datasize, const double *data, int nmiss, unsigned char *gribbuffer, size_t gribbuffersize,
int ljpeg, void *gribHandle);
#endif /* _STREAM_GRIBAPI_H */
......@@ -380,6 +380,8 @@ static void stream_init_entry(stream_t *streamptr)
streamptr->curfile = 0;
streamptr->nfiles = 0;
streamptr->fnames = NULL;
streamptr->gribHandle = NULL;
}
......
......@@ -242,6 +242,7 @@ typedef struct {
int curfile;
int nfiles;
char **fnames;
void *gribHandle;
}
stream_t;
......
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