Commit 971426e7 authored by Uwe Schulzweida's avatar Uwe Schulzweida
Browse files

allocate gribHandle for every grid/zaxis combination

parent 1fe0845b
2009-12-08 Uwe Schulzweida <Uwe.Schulzweida@zmaw.de>
* allocate gribHandle for every grid/zaxis combination (speed up for writing GRIB2)
2009-11-30 Uwe Schulzweida <Uwe.Schulzweida@zmaw.de>
* cdfInqContents: bug fix for GRID_CELL with levels [report: Stephan Lorenz]
......
......@@ -8,6 +8,9 @@
#include <stdio.h>
#include "cdi.h"
#include "stream_int.h"
#include "gribapi.h"
#define XSTRING(x) #x
#define STRING(x) XSTRING(x)
......@@ -30,3 +33,23 @@ const char *gribapiLibraryVersion(void)
return (gribapi_libvers);
}
void gribapiDefHandles(int streamID)
{
stream_t *streamptr = NULL;
int vlistID, ngrids, nzaxis, i;
streamptr = stream_to_pointer(streamID);
vlistID = streamInqVlist(streamID);
ngrids = vlistNgrids(vlistID);
nzaxis = vlistNzaxis(vlistID);
streamptr->gribHandleNums = ngrids*nzaxis;
streamptr->gribHandle = (void **) malloc(streamptr->gribHandleNums*sizeof(void *));
for ( i = 0; i < streamptr->gribHandleNums; ++i )
streamptr->gribHandle[i] = gribHandleNew();
}
......@@ -31,6 +31,7 @@
#define GRIBAPI_GTYPE_GME 192 /* hexagonal GME grid */
const char *gribapiLibraryVersion(void);
void gribapiDefHandles(int streamID);
void *gribHandleNew();
void gribHandleDelete(void *gh);
......
......@@ -702,10 +702,6 @@ 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);
......@@ -1125,10 +1121,17 @@ void streamClose(int streamID)
case FILETYPE_GRB2:
{
gribClose(fileID);
if ( streamptr->gribHandle )
if ( streamptr->gribHandleNums )
{
gribHandleDelete(streamptr->gribHandle);
int i;
for ( i = 0; i < streamptr->gribHandleNums; ++i )
{
gribHandleDelete(streamptr->gribHandle[0]);
streamptr->gribHandle[i] = NULL;
}
free(streamptr->gribHandle);
streamptr->gribHandle = NULL;
streamptr->gribHandleNums = 0;
}
break;
}
......@@ -2013,7 +2016,13 @@ void streamDefVlist(int streamID, int vlistID)
if ( streamptr->filetype == FILETYPE_NC ||
streamptr->filetype == FILETYPE_NC2 ||
streamptr->filetype == FILETYPE_NC4 )
cdfDefVars(streamID);
{
cdfDefVars(streamID);
}
else if ( streamptr->filetype == FILETYPE_GRB2 )
{
gribapiDefHandles(streamID);
}
}
}
else
......
......@@ -441,6 +441,7 @@ int grbWriteVarSliceDP(int streamID, int varID, int levelID, const double *data,
stream_t *streamptr;
int ljpeg = 0;
int ljpeg_warn = 1;
void *gh = NULL;
streamptr = stream_to_pointer(streamID);
......@@ -467,6 +468,13 @@ int grbWriteVarSliceDP(int streamID, int varID, int levelID, const double *data,
gribbuffersize = datasize*4+3000;
gribbuffer = (unsigned char *) malloc(gribbuffersize);
if ( filetype == FILETYPE_GRB2 )
{
int ngrids = vlistNgrids(vlistID);
int ghindex = ngrids*gridID + zaxisID;
gh = streamptr->gribHandle[ghindex];
}
if ( streamptr->ztype == COMPRESS_JPEG )
{
if ( filetype == FILETYPE_GRB2 )
......@@ -479,7 +487,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, streamptr->gribHandle);
datasize, data, nmiss, gribbuffer, gribbuffersize, ljpeg, gh);
if ( streamptr->ztype == COMPRESS_SZIP )
nbytes = grbSzip(filetype, gribbuffer, nbytes);
......
......@@ -2051,7 +2051,7 @@ void gribHandleDelete(void *gh)
#endif
}
#define GRIBAPIENCODETEST 1
//#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,
......@@ -2078,10 +2078,8 @@ size_t gribapiEncode(int varID, int levelID, int vlistID, int gridID, int zaxisI
if ( param == CDI_UNDEFPARAM ) param = cdiEncodeParam(255, tabnum, code);
#if defined(GRIBAPIENCODETEST)
gh = (grib_handle *) gribHandleNew();
// gh = (grib_handle *) grib_handle_new_from_message_copy(NULL,_grib_template_GRIB2,184);
#else
gh = gribHandle;
// gh = grib_handle_clone(gribHandle);
#endif
GRIB_CHECK(grib_set_long(gh, "editionNumber", edition), 0);
......
......@@ -379,6 +379,7 @@ static void stream_init_entry(stream_t *streamptr)
streamptr->nfiles = 0;
streamptr->fnames = NULL;
streamptr->gribHandleNums = 0;
streamptr->gribHandle = NULL;
}
......
......@@ -241,7 +241,7 @@ typedef struct {
int nfiles;
char **fnames;
int gribHandleNums;
void *gribHandle;
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