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

Read arbitrary GRIB keys

parent db166e0e
......@@ -3,6 +3,10 @@
* Version 1.6.0 released
* using CGRIBEX library version 1.6.0
2013-03-13 Florian Prill <Florian.Prill@dwd.de>
* Read arbitrary GRIB keys [Feature #3267]
2013-03-13 Uwe Schulzweida <Uwe.Schulzweida@zmaw.de>
* GRIB: added support for time step unit: seconds (Bug #3352)
......
......@@ -939,6 +939,24 @@ Get the name of a Variable.
Get the parameter number of a Variable.
\section*{\tt \htmlref{vlistInqVarRawBegin}{vlistInqVarRawBegin}}
\begin{verbatim}
void vlistInqVarRawBegin (int streamID, int varID);
\end{verbatim}
Open GRIB record to retrieve raw meta-data in subsequent calls.
\section*{\tt \htmlref{vlistInqVarRawEnd}{vlistInqVarRawEnd}}
\begin{verbatim}
void vlistInqVarRawEnd (int streamID);
\end{verbatim}
Free previously opened GRIB record.
\section*{\tt \htmlref{vlistInqVarStdname}{vlistInqVarStdname}}
\begin{verbatim}
......
......@@ -955,6 +955,24 @@ Get the name of a Variable.
Get the parameter number of a Variable.
\section*{\tt \htmlref{vlistInqVarRawBegin}{vlistInqVarRawBegin}}
\begin{verbatim}
SUBROUTINE vlistInqVarRawBegin (INTEGER streamID, INTEGER varID)
\end{verbatim}
Open GRIB record to retrieve raw meta-data in subsequent calls.
\section*{\tt \htmlref{vlistInqVarRawEnd}{vlistInqVarRawEnd}}
\begin{verbatim}
SUBROUTINE vlistInqVarRawEnd (INTEGER streamID)
\end{verbatim}
Free previously opened GRIB record.
\section*{\tt \htmlref{vlistInqVarStdname}{vlistInqVarStdname}}
\begin{verbatim}
......
......@@ -537,6 +537,20 @@ void vlistDefVarIntKey(int vlistID, int varID, const char *name, int value);
/* vlistDefVarDblKey: Set an arbitrary keyword/double value pair for GRIB API */
void vlistDefVarDblKey(int vlistID, int varID, const char *name, double value);
/* ---------------------------------- */
/* Local change: 2013-02-18, FP (DWD) */
/* ---------------------------------- */
/* vlistInqVarRawBegin: Open GRIB record to retrieve raw meta-data in subsequent calls */
void vlistInqVarRawBegin(int streamID, int varID);
/* vlistInqVarDblKey: raw access to GRIB meta-data */
double vlistInqVarDblKey(int streamID, const char* name);
/* vlistInqVarIntKey: raw access to GRIB meta-data */
int vlistInqVarIntKey(int streamID, const char* name);
/* vlistInqVarRawEnd: Free previously opened GRIB record */
void vlistInqVarRawEnd(int streamID);
/* VLIST attributes */
/* vlistInqNatts: Get number of variable attributes assigned to this variable */
......
......@@ -1206,6 +1206,24 @@
! DOUBLEPRECISION value)
EXTERNAL vlistDefVarDblKey
!
! ----------------------------------
!
!
! Local change: 2013-02-18, FP (DWD)
!
!
! ----------------------------------
!
! vlistInqVarRawBegin
! (INTEGER streamID,
! INTEGER varID)
EXTERNAL vlistInqVarRawBegin
! vlistInqVarRawEnd
! (INTEGER streamID)
EXTERNAL vlistInqVarRawEnd
!
! VLIST attributes
!
......
......@@ -259,6 +259,17 @@ FCALLSCFUN5 (INT, vlistInqVarEnsemble, VLISTINQVARENSEMBLE, vlistinqvarensemble,
FCALLSCSUB4 (vlistDefVarIntKey, VLISTDEFVARINTKEY, vlistdefvarintkey, INT, INT, STRING, INT)
FCALLSCSUB4 (vlistDefVarDblKey, VLISTDEFVARDBLKEY, vlistdefvardblkey, INT, INT, STRING, DOUBLE)
/* ---------------------------------- */
/* Local change: 2013-02-18, FP (DWD) */
/* ---------------------------------- */
FCALLSCSUB2 (vlistInqVarRawBegin, VLISTINQVARRAWBEGIN, vlistinqvarrawbegin, INT, INT)
FCALLSCSUB1 (vlistInqVarRawEnd, VLISTINQVARRAWEND, vlistinqvarrawend, INT)
/* VLIST attributes */
FCALLSCFUN3 (INT, vlistInqNatts, VLISTINQNATTS, vlistinqnatts, INT, INT, PINT)
......
......@@ -348,7 +348,7 @@ void grbReadVarDP(stream_t * streamptr, int varID, double *data, int *nmiss)
missval = vlistInqVarMissval(vlistID, varID);
grbDecode(filetype, gribbuffer, recsize, &data[levelID*gridsize], gridsize,
grbDecode(filetype, gribbuffer, recsize, &data[levelID*gridsize], gridsize,
streamptr->unreduced, &imiss, &zip, missval);
*nmiss += imiss;
......
......@@ -251,6 +251,12 @@ typedef struct {
void *gribContainers;
#endif
int vlistIDorig;
/* ---------------------------------- */
/* Local change: 2013-02-18, FP (DWD) */
/* ---------------------------------- */
void *gh; // grib handle
}
stream_t;
......
......@@ -674,7 +674,7 @@ void vlistInqVarStdname(int vlistID, int varID, char *stdname)
if ( vlistptr->vars[varID].stdname == NULL )
{
stdname[0] = '\0';
}
}
else
strcpy(stdname, vlistptr->vars[varID].stdname);
......@@ -689,7 +689,7 @@ void vlistInqVarStdname(int vlistID, int varID, char *stdname)
@Parameter
@Item vlistID Variable list ID, from a previous call to @fref{vlistCreate}.
@Item varID Variable identifier.
@Item units Units of the variable. The caller must allocate space for the
@Item units Units of the variable. The caller must allocate space for the
returned string. The maximum possible length, in characters, of
the string is given by the predefined constant @func{CDI_MAX_NAME}.
......@@ -1848,6 +1848,74 @@ void vlistDefVarDblKey(int vlistID, int varID, const char *name, double value)
Error("Internal error!");
}
#if defined (HAVE_LIBGRIB_API)
# include "file.h"
# include "grib_api.h"
#endif
/* vlistInqVarRawBegin: Open GRIB record to retrieve raw meta-data in subsequent calls */
void vlistInqVarRawBegin(int streamID, int varID)
{
#if defined (HAVE_LIBGRIB_API)
stream_t *streamptr;
int recID, tsID, fileID;
long recpos, recsize;
streamptr = stream_to_pointer(streamID);
stream_check_ptr(__func__, streamptr);
fileID = streamInqFileID(streamID);
tsID = streamptr->curTsID;
// determine record ID for varID in current time step
for (recID=0; (recID<streamptr->tsteps[0].nrecs) && (varID != streamptr->tsteps[tsID].records[recID].varID); recID++);
recpos = streamptr->tsteps[tsID].records[recID].position;
recsize = streamptr->tsteps[tsID].records[recID].size;
fileSetPos(fileID, recpos, SEEK_SET);
fileRead(fileID, streamptr->record->buffer, (size_t) recsize);
streamptr->gh = (void *) grib_handle_new_from_message(NULL, (void *) streamptr->record->buffer, recsize);
#endif
}
/* vlistInqVarDblKey: raw access to GRIB meta-data */
double vlistInqVarDblKey(int streamID, const char* name)
{
double value = 0;
#if defined (HAVE_LIBGRIB_API)
stream_t *streamptr = stream_to_pointer(streamID);
stream_check_ptr(__func__, streamptr);
GRIB_CHECK(grib_get_double((grib_handle*) streamptr->gh, name, &value), 0);
#endif
return value;
}
/* vlistInqVarIntKey: raw access to GRIB meta-data */
int vlistInqVarIntKey(int streamID, const char* name)
{
long int value = 0;
#if defined (HAVE_LIBGRIB_API)
stream_t *streamptr = stream_to_pointer(streamID);
stream_check_ptr(__func__, streamptr);
GRIB_CHECK(grib_get_long((grib_handle*) streamptr->gh, name, &value), 0);
#endif
return (int) value;
}
/* vlistInqVarRawEnd: Free previously opened GRIB record */
void vlistInqVarRawEnd(int streamID)
{
#if defined (HAVE_LIBGRIB_API)
stream_t *streamptr = stream_to_pointer(streamID);
stream_check_ptr(__func__, streamptr);
grib_handle_delete((grib_handle*) streamptr->gh);
#endif
}
void vlistDefVarDeco ( int vlistID, int varID, int decoSize, deco_t * deco )
{
......
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