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

Added function cgribexSection2Length().

parent 81324990
......@@ -29,21 +29,21 @@ int cdiSplitLtype105 = CDI_UNDEFID;
bool cdiIgnoreAttCoordinates = false;
bool cdiCoordinatesLonLat = false;
bool cdiIgnoreValidRange = false;
int cdiSkipRecords = 0;
int cdiSkipRecords = 0;
int CDI_convention = CDI_CONVENTION_ECHAM;
int CDI_inventory_mode = 1;
int CDO_version_info = 1;
int CDI_read_cell_corners = 1;
int CDI_cmor_mode = 0;
int CDI_reduce_dim = 0;
size_t CDI_netcdf_hdr_pad = 0UL;
int CDI_inventory_mode = 1;
int CDO_version_info = 1;
int CDI_read_cell_corners = 1;
int CDI_cmor_mode = 0;
int CDI_reduce_dim = 0;
size_t CDI_netcdf_hdr_pad = 0UL;
bool CDI_netcdf_lazy_grid_load = false;
char *cdiPartabPath = NULL;
int cdiPartabIntern = 1;
double CDI_default_missval = -9.E33;
double CDI_grid_missval = -9999.;
double CDI_grid_missval = -9999.;
static const char Filetypes[][9] = {
"UNKNOWN",
......@@ -60,8 +60,8 @@ static const char Filetypes[][9] = {
"HDF5",
};
int CDI_Debug = 0; /* If set to 1, debugging */
int CDI_Recopt = 0;
int CDI_Debug = 0; // If set to 1, debugging
int CDI_Recopt = 0;
int cdiGribApiDebug = 0;
int cdiDefaultLeveltype = -1;
......@@ -71,7 +71,8 @@ int cdiSortParam = 0;
int cdiHaveMissval = 0;
static long cdiGetenvInt(const char *envName)
static
long cdiGetenvInt(const char *envName)
{
long envValue = -1;
......@@ -107,8 +108,8 @@ static long cdiGetenvInt(const char *envName)
return envValue;
}
static void
cdiPrintDefaults(void)
static
void cdiPrintDefaults(void)
{
fprintf(stderr, "default instID : %d\n"
"default modelID : %d\n"
......@@ -135,21 +136,11 @@ void cdiPrintVersion(void)
#ifdef HAVE_LIBSERVICE
fprintf(stderr, " EXSE library version : %s\n", srvLibraryVersion());
#endif
/*
#ifdef HAVE_LIBSERVICE
fprintf(stderr, " SERVICE library version : %s\n", srvLibraryVersion());
#endif
#ifdef HAVE_LIBEXTRA
fprintf(stderr, " EXTRA library version : %s\n", extLibraryVersion());
#endif
#ifdef HAVE_LIBIEG
fprintf(stderr, " IEG library version : %s\n", iegLibraryVersion());
#endif
*/
fprintf(stderr, " FILE library version : %s\n", fileLibraryVersion());
}
static void cdiPrintDatatypes(void)
static
void cdiPrintDatatypes(void)
{
#define XSTRING(x) #x
#define STRING(x) XSTRING(x)
......@@ -271,6 +262,7 @@ int cdiHaveFiletype(int filetype)
return status;
}
void cdiDefTableID(int tableID)
{
cdiDefaultTableID = tableID;
......@@ -281,29 +273,11 @@ void cdiDefTableID(int tableID)
static
void cdiSetChunk(const char *chunkAlgo)
{
//char *pch;
//size_t len = strlen(chunkAlgo);
int algo = -1;
if ( strcmp("auto", chunkAlgo) == 0 ) algo = CDI_CHUNK_AUTO;
else if ( strcmp("grid", chunkAlgo) == 0 ) algo = CDI_CHUNK_GRID;
else if ( strcmp("lines", chunkAlgo) == 0 ) algo = CDI_CHUNK_LINES;
/*
else if ( (pch = strstr(chunkAlgo,"x")) != 0 )
{
int ix, iy;
ix = atoi(chunkAlgo);
iy = atoi(pch+1);
if ( ix > 0 && iy > 0 )
{
cdiChunkX = ix;
cdiChunkY = iy;
algo = CHUNK_USER;
}
else
Warning("Invalid environment variable CDI_CHUNK_ALGO: %s", chunkAlgo);
}
*/
if ( strcmp("auto", chunkAlgo) == 0 ) algo = CDI_CHUNK_AUTO;
else if ( strcmp("grid", chunkAlgo) == 0 ) algo = CDI_CHUNK_GRID;
else if ( strcmp("lines", chunkAlgo) == 0 ) algo = CDI_CHUNK_LINES;
else
Warning("Invalid environment variable CDI_CHUNK_ALGO: %s", chunkAlgo);
......
......@@ -114,23 +114,23 @@ bool str_is_equal(const char *vstr, const char *cstr);
typedef struct
{
void *buffer; /* gribapi, cgribex */
size_t buffersize; /* gribapi, cgribex */
off_t position; /* ieg */
int param; /* srv */
int level; /* ext, srv */
int date; /* ext, srv */
int time; /* srv */
int gridID; /* ieg, ext */
int varID; /* ieg */
int levelID; /* ieg */
int prec; /* ext, srv */
int sec0[2]; /* cgribex */
int sec1[1024]; /* cgribex */
int sec2[4096]; /* cgribex */
int sec3[2]; /* cgribex */
int sec4[512]; /* cgribex */
void *exsep; /* ieg, ext, srv */
void *buffer; // gribapi, cgribex
size_t buffersize; // gribapi, cgribex
off_t position; // file position
int param;
int level;
int date;
int time;
int gridID;
int varID;
int levelID;
int prec; // ext, srv
int sec0[2]; // cgribex
int sec1[1024]; // cgribex
int sec2[8192]; // cgribex
int sec3[2]; // cgribex
int sec4[512]; // cgribex
void *exsep; // ieg, ext, srv
}
Record;
......@@ -169,23 +169,23 @@ typedef struct
short varID;
short levelID;
short used;
char varname[32]; /* needed for grib decoding with GRIB_API */
var_tile_t tiles; /* tile-related meta-data, currently for GRIB-API only. */
char varname[32]; // needed for grib decoding with GRIB_API
var_tile_t tiles; // tile-related meta-data, currently for GRIB-API only.
}
record_t;
typedef struct {
record_t *records;
int *recIDs; /* IDs of non constant records */
int recordSize; /* number of allocated records */
int nrecs; /* number of used records */
/* tsID=0 nallrecs */
/* tsID>0 number of non constant records */
int nallrecs; /* number of all records */
int curRecID; /* current record ID */
int *recIDs; // IDs of non constant records
int recordSize; // number of allocated records
int nrecs; // number of used records
// tsID=0 nallrecs
// tsID>0 number of non constant records
int nallrecs; // number of all records
int curRecID; // current record ID
bool next;
off_t position; /* timestep file position */
off_t position; // timestep file position
taxis_t taxis;
}
tsteps_t;
......@@ -193,9 +193,9 @@ tsteps_t;
typedef struct {
int nlevs;
int subtypeIndex; /* corresponding tile in subtype_t structure (subtype->self) */
int *recordID; /* record IDs: [nlevs] */
int *lindex; /* level index */
int subtypeIndex; // corresponding tile in subtype_t structure (subtype->self)
int *recordID; // record IDs: [nlevs]
int *lindex; // level index
} sleveltable_t;
......@@ -240,22 +240,22 @@ ncgrid_t;
typedef struct {
int self;
int accesstype; /* TYPE_REC or TYPE_VAR */
int accesstype; // TYPE_REC or TYPE_VAR
int accessmode;
int filetype;
int byteorder;
int fileID;
int filemode;
int nrecs; /* number of records */
int nrecs; // number of records
size_t numvals;
char *filename;
Record *record;
svarinfo_t *vars;
int nvars; /* number of variables */
int nvars; // number of variables
int varsAllocated;
int curTsID; /* current timestep ID */
int rtsteps; /* number of tsteps accessed */
long ntsteps; /* number of tsteps : only set if all records accessed */
int curTsID; // current timestep ID
int rtsteps; // number of tsteps accessed
long ntsteps; // number of tsteps : only set if all records accessed
tsteps_t *tsteps;
int tstepsTableSize;
int tstepsNextID;
......@@ -264,7 +264,7 @@ typedef struct {
int vlistID;
#ifdef HAVE_LIBNETCDF
ncgrid_t ncgrid[MAX_GRIDS_PS];
int zaxisID[MAX_ZAXES_PS]; //Warning: synchronous array to vlist_to_pointer(vlistID)->zaxisIDs
int zaxisID[MAX_ZAXES_PS]; // Warning: synchronous array to vlist_to_pointer(vlistID)->zaxisIDs
int nczvarID[MAX_ZAXES_PS];
VCT vct;
#endif
......@@ -293,24 +293,24 @@ stream_t;
enum cdi_convention {CDI_CONVENTION_ECHAM, CDI_CONVENTION_CF};
/* Data type specification for optional key/value pairs (GRIB) */
// Data type specification for optional key/value pairs (GRIB)
typedef enum {
t_double = 0,
t_int = 1
} key_val_pair_datatype;
/* Data structure holding optional key/value pairs for GRIB */
// Data structure holding optional key/value pairs for GRIB
typedef struct
{
char* keyword; /* keyword string */
char* keyword; // keyword string
bool update;
key_val_pair_datatype data_type; /* data type of this key/value pair */
double dbl_val; /* double value (data_type == t_double) */
int int_val; /* integer value (data_type == t_int) */
int subtype_index; /* tile index for this key-value pair */
key_val_pair_datatype data_type; // data type of this key/value pair
double dbl_val; // double value (data_type == t_double)
int int_val; // integer value (data_type == t_int)
int subtype_index; // tile index for this key-value pair
} opt_key_val_pair_t;
//enum for differenciating between the different times that we handle
// enum for differenciating between the different times that we handle
typedef enum {
kCdiTimeType_referenceTime,
kCdiTimeType_startTime,
......@@ -318,11 +318,11 @@ typedef enum {
} CdiTimeType;
#define CDI_FILETYPE_UNDEF -1 /* Unknown/not yet defined file type */
#define CDI_FILETYPE_UNDEF -1 // Unknown/not yet defined file type
extern int cdiDebugExt;
extern int CDI_Debug; /* If set to 1, debuggig (default 0) */
extern int CDI_Debug; // If set to 1, debuggig (default 0)
extern int CDI_Recopt;
extern int cdiGribApiDebug;
extern double CDI_default_missval;
......@@ -385,7 +385,7 @@ void streamDefineTaxis(int streamID);
int streamsNewEntry(int filetype);
void streamsInitEntry(int streamID);
void cdiStreamSetupVlist(stream_t *streamptr, int vlistID);
/* default implementation of the overridable function */
// default implementation of the overridable function
void cdiStreamSetupVlist_(stream_t *streamptr, int vlistID);
int stream_new_var(stream_t *streamptr, int gridID, int zaxisID, int tilesetID);
......@@ -466,7 +466,7 @@ void cdiStreamSync_(stream_t *streamptr);
const char *cdiUnitNamePtr(int cdi_unit);
enum {
/* 8192 is known to work on most systems (4096 isn't on Alpha) */
// 8192 is known to work on most systems (4096 isn't on Alpha)
commonPageSize = 8192,
};
......
......@@ -28,6 +28,69 @@ typedef struct {
#ifdef HAVE_LIBCGRIBEX
typedef struct
{
void *gribbuffer;
size_t gribbuffersize;
unsigned char *pds;
unsigned char *gds;
unsigned char *bms;
unsigned char *bds;
} cgribex_handle;
int grib1Sections(unsigned char *gribbuffer, long gribbufsize, unsigned char **pdsp,
unsigned char **gdsp, unsigned char **bmsp, unsigned char **bdsp, long *gribrecsize);
long cgribexSection2Length(void *gribbuffer, size_t gribbuffersize)
{
long sec2len = 0;
if ( gribbuffersize && gribbuffer )
{
unsigned char *pds = NULL, *gds = NULL, *bms = NULL, *bds = NULL;
long gribrecsize;
int status = grib1Sections((unsigned char *)gribbuffer, (long)gribbuffersize, &pds, &gds, &bms, &bds, &gribrecsize);
if (status >= 0 && gds != NULL) sec2len = (unsigned) ((gds[0] << 16) + (gds[1] << 8) + (gds[3]));
}
return sec2len;
}
void *cgribex_handle_new_from_meassage(void *gribbuffer, size_t gribbuffersize)
{
cgribex_handle *gh = (cgribex_handle*) Malloc(sizeof(cgribex_handle));
gh->gribbuffer = NULL;
gh->gribbuffersize = 0;
gh->pds = NULL;
if ( gribbuffersize && gribbuffer )
{
unsigned char *pds = NULL, *gds = NULL, *bms = NULL, *bds = NULL;
long gribrecsize;
int status = grib1Sections((unsigned char *)gribbuffer, (long)gribbuffersize, &pds, &gds, &bms, &bds, &gribrecsize);
if ( status >= 0 )
{
gh->gribbuffer = gribbuffer;
gh->gribbuffersize = gribbuffersize;
gh->pds = pds;
gh->gds = gds;
gh->bms = bms;
gh->bds = bds;
}
}
return (void*)gh;
}
void cgribex_handle_delete(void *gh)
{
if ( gh ) Free(gh);
}
static
int cgribexGetGridType(int *isec2)
{
......@@ -655,32 +718,28 @@ int cgribexScanTimestep1(stream_t *streamptr)
int tsID = tstepsNewEntry(streamptr);
taxis_t *taxis = &streamptr->tsteps[tsID].taxis;
if ( tsID != 0 )
Error("Internal problem! tstepsNewEntry returns %d", tsID);
if (tsID != 0) Error("Internal problem! tstepsNewEntry returns %d", tsID);
int fileID = streamptr->fileID;
while ( nskip-- > 0 )
while (nskip-- > 0)
{
recsize = gribGetSize(fileID);
if ( recsize == 0 )
Error("Skipping of %d records failed!", cdiSkipRecords);
if (recsize == 0) Error("Skipping of %d records failed!", cdiSkipRecords);
recpos = fileGetPos(fileID);
recpos = fileGetPos(fileID);
fileSetPos(fileID, (off_t)recsize, SEEK_CUR);
}
unsigned nrecs = 0;
while ( true )
while (true)
{
recsize = gribGetSize(fileID);
recpos = fileGetPos(fileID);
if ( recsize == 0 )
{
if ( nrecs == 0 )
Error("No GRIB records found!");
if ( nrecs == 0 ) Error("No GRIB records found!");
streamptr->ntsteps = 1;
break;
}
......@@ -706,6 +765,8 @@ int cgribexScanTimestep1(stream_t *streamptr)
}
}
long sec2len = cgribexSection2Length(gribbuffer, buffersize);
nrecs_scanned++;
cgribexDecodeHeader(isec0, isec1, isec2, fsec2, isec3, fsec3, isec4, fsec4,
(int *) gribbuffer, (int)recsize, &lmv, &iret);
......@@ -1333,7 +1394,7 @@ int cgribexDecode(int memtype, void *gribbuffer, size_t gribsize, void *data, si
{
int status = 0;
int iret = 0, iword = 0;
int isec0[2], isec1[4096], isec2[4096], isec3[2], isec4[512];
int isec0[2], isec1[4096], isec2[8192], isec3[2], isec4[512];
float fsec2f[512], fsec3f[2];
double fsec2[512], fsec3[2];
char hoper[2];
......@@ -2130,53 +2191,6 @@ size_t cgribexEncode(int memtype, int varID, int levelID, int vlistID, int gridI
}
typedef struct
{
void *gribbuffer;
size_t gribbuffersize;
unsigned char *pds;
unsigned char *gds;
unsigned char *bms;
unsigned char *bds;
} cgribex_handle;
int grib1Sections(unsigned char *gribbuffer, long gribbufsize, unsigned char **pdsp,
unsigned char **gdsp, unsigned char **bmsp, unsigned char **bdsp, long *gribrecsize);
void *cgribex_handle_new_from_meassage(void *gribbuffer, size_t gribbuffersize)
{
cgribex_handle *gh = (cgribex_handle*) Malloc(sizeof(cgribex_handle));
gh->gribbuffer = NULL;
gh->gribbuffersize = 0;
gh->pds = NULL;
if ( gribbuffersize && gribbuffer )
{
unsigned char *pds = NULL, *gds = NULL, *bms = NULL, *bds = NULL;
long gribrecsize;
int status = grib1Sections((unsigned char *)gribbuffer, (long)gribbuffersize, &pds, &gds, &bms, &bds, &gribrecsize);
if ( status >= 0 )
{
gh->gribbuffer = gribbuffer;
gh->gribbuffersize = gribbuffersize;
gh->pds = pds;
gh->gds = gds;
gh->bms = bms;
gh->bds = bds;
}
}
return (void*)gh;
}
void cgribex_handle_delete(void *gh)
{
if ( gh ) Free(gh);
}
void cgribexChangeParameterIdentification(void *gh, int code, int ltype, int lev)
{
if ( !gh ) return;
......
#ifndef STREAM_CGRIBEX_H
#define STREAM_CGRIBEX_H
int cgribexScanTimestep1(stream_t * streamptr);
int cgribexScanTimestep2(stream_t * streamptr);
int cgribexScanTimestep(stream_t * streamptr);
int cgribexScanTimestep1(stream_t *streamptr);
int cgribexScanTimestep2(stream_t *streamptr);
int cgribexScanTimestep(stream_t *streamptr);
int cgribexDecode(int memtype, void *gribbuffer, size_t gribsize, void *data, size_t datasize,
int unreduced, size_t *nmiss, double missval);
......
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