Commit 09fede14 authored by Uwe Schulzweida's avatar Uwe Schulzweida
Browse files

added gribapi test support

parent cba2aedc
......@@ -132,6 +132,10 @@ src/stream_cgribex.c -text
src/stream_cgribex.h -text
src/stream_ext.c -text
src/stream_ext.h -text
src/stream_grb.c -text
src/stream_grb.h -text
src/stream_gribapi.c -text
src/stream_gribapi.h -text
src/stream_history.c -text
src/stream_ieg.c -text
src/stream_ieg.h -text
......
......@@ -24,6 +24,8 @@ libcdi_a_SOURCES = \
basetime.c \
stream_history.c \
stream_cgribex.c \
stream_gribapi.c \
stream_grb.c \
stream_cdf.c \
stream_srv.c \
stream_ext.c \
......@@ -63,6 +65,8 @@ libcdi_a_SOURCES = \
vlist.h \
taxis.h \
stream_cgribex.h \
stream_gribapi.h \
stream_grb.h \
stream_cdf.h \
stream_srv.h \
stream_ext.h \
......
......@@ -64,6 +64,7 @@ am_libcdi_a_OBJECTS = cdiFortran.$(OBJEXT) cdi_error.$(OBJEXT) \
calendar.$(OBJEXT) timebase.$(OBJEXT) vlist.$(OBJEXT) \
vlist_var.$(OBJEXT) vlist_att.$(OBJEXT) basetime.$(OBJEXT) \
stream_history.$(OBJEXT) stream_cgribex.$(OBJEXT) \
stream_gribapi.$(OBJEXT) stream_grb.$(OBJEXT) \
stream_cdf.$(OBJEXT) stream_srv.$(OBJEXT) stream_ext.$(OBJEXT) \
stream_ieg.$(OBJEXT) grid.$(OBJEXT) zaxis.$(OBJEXT) \
stream.$(OBJEXT) stream_var.$(OBJEXT) stream_record.$(OBJEXT) \
......@@ -215,6 +216,8 @@ libcdi_a_SOURCES = \
basetime.c \
stream_history.c \
stream_cgribex.c \
stream_gribapi.c \
stream_grb.c \
stream_cdf.c \
stream_srv.c \
stream_ext.c \
......@@ -254,6 +257,8 @@ libcdi_a_SOURCES = \
vlist.h \
taxis.h \
stream_cgribex.h \
stream_gribapi.h \
stream_grb.h \
stream_cdf.h \
stream_srv.h \
stream_ext.h \
......@@ -385,6 +390,8 @@ distclean-compile:
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/stream_cdf.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/stream_cgribex.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/stream_ext.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/stream_grb.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/stream_gribapi.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/stream_history.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/stream_ieg.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/stream_int.Po@am__quote@
......
......@@ -71,7 +71,6 @@ static int _file_init = FALSE;
#if defined (HAVE_LIBPTHREAD)
#include <pthread.h>
#include "pthread_debug.h"
static pthread_once_t _file_init_thread = PTHREAD_ONCE_INIT;
static pthread_mutex_t _file_mutex;
......
......@@ -3,7 +3,7 @@
#endif
#if defined (HAVE_LIBGRIB_API)
# include "grib_api.h"
# include <grib_api.h>
#endif
#include <stdio.h>
......
#ifndef _GRIBAPI_H
#define _GRIBAPI_H
#define GRIBAPI_MISSVAL -9.E33
/* Level Types */
#define GRIBAPI_LTYPE_SURFACE 1
#define GRIBAPI_LTYPE_99 99
#define GRIBAPI_LTYPE_ISOBARIC 100
#define GRIBAPI_LTYPE_MEANSEA 102
#define GRIBAPI_LTYPE_ALTITUDE 103
#define GRIBAPI_LTYPE_HEIGHT 105
#define GRIBAPI_LTYPE_SIGMA 107
#define GRIBAPI_LTYPE_HYBRID 109
#define GRIBAPI_LTYPE_HYBRID_LAYER 110
#define GRIBAPI_LTYPE_LANDDEPTH 111
#define GRIBAPI_LTYPE_LANDDEPTH_LAYER 112
#define GRIBAPI_LTYPE_ISENTROPIC 113
#define GRIBAPI_LTYPE_SEADEPTH 160
#define GRIBAPI_LTYPE_99_MARGIN 1000
/*
* Data representation type (Grid Type)
*/
#define GRIBAPI_GTYPE_LATLON 0 /* latitude/longitude */
#define GRIBAPI_GTYPE_LATLON_ROT 10 /* rotated latitude/longitude */
#define GRIBAPI_GTYPE_LATLON_STR 20 /* stretched latitude/longitude */
#define GRIBAPI_GTYPE_LATLON_ROTSTR 30 /* rotated and stretched latitude/longitude */
#define GRIBAPI_GTYPE_GAUSSIAN 40 /* gaussian grid */
#define GRIBAPI_GTYPE_GAUSSIAN_ROT 14 /* rotated gaussian grid */
#define GRIBAPI_GTYPE_GAUSSIAN_STR 24 /* stretched gaussian grid */
#define GRIBAPI_GTYPE_GAUSSIAN_ROTSTR 34 /* rotated and stretched gaussian grid */
#define GRIBAPI_GTYPE_LCC 3 /* Lambert conformal */
#define GRIBAPI_GTYPE_SPECTRAL 50 /* spherical harmonics */
#define GRIBAPI_GTYPE_GME 192 /* hexagonal GME grid */
const char *gribapiLibraryVersion(void);
#endif /* _GRIBAPI_H */
......@@ -43,8 +43,25 @@ cat > ${PROG} << EOR
#include <fcntl.h>
#include <unistd.h>
#if defined (HAVE_LIBGRIB_API)
# include <grib_api.h>
#endif
#if defined (HAVE_MMAP)
# include <sys/mman.h> /* mmap() is defined in this header */
#endif
#if defined (HAVE_LIBPTHREAD)
# include <pthread.h>
#endif
#if defined (HAVE_LIBSZ)
# include <szlib.h>
#endif
#if ! defined (HAVE_CONFIG_H)
# define HAVE_LIBGRIB 1
# define HAVE_LIBCGRIBEX 1
# define HAVE_LIBSERVICE 1
# define HAVE_LIBEXTRA 1
# define HAVE_LIBIEG 1
......@@ -77,6 +94,8 @@ c="dmemory.c \
stream_int.c \
stream.c \
stream_history.c \
stream_cgribex.c \
stream_gribapi.c \
stream_grb.c \
stream_srv.c \
stream_ext.c \
......@@ -94,14 +113,14 @@ c="dmemory.c \
"
h="cdi_limits.h taxis.h error.h dtypes.h file.h cgribex.h gribapi.h service.h extra.h \
ieg.h cdi.h timebase.h calendar.h \
basetime.h stream_int.h stream_grb.h datetime.h stream_cdf.h \
ieg.h cdi.h timebase.h calendar.h basetime.h datetime.h stream_int.h \
stream_cgribex.h stream_gribapi.h stream_grb.h stream_cdf.h \
tablepar.h table.h util.h grid.h varscan.h binary.h swap.h \
service.h stream_srv.h stream_ext.h stream_ieg.h cdf_int.h \
cdf.h vlist.h"
cat $h >> ${PROG}
cat $c | grep -v '#include' >> ${PROG}
cat $c | grep -v '#include' | grep -v '# include' >> ${PROG}
if test -f config.h ; then
cpp -P -DHAVE_CONFIG_H version.c >> ${PROG}
......
......@@ -8,7 +8,7 @@
#include "cdi.h"
#include "stream_int.h"
#include "cdf.h"
#include "stream_cgribex.h"
#include "stream_grb.h"
#include "stream_cdf.h"
#include "stream_srv.h"
#include "stream_ext.h"
......@@ -53,9 +53,6 @@ void cdiDebug(int level)
#if defined (HAVE_LIBGRIB)
gribSetDebug(1);
#endif
#if defined (HAVE_LIBGRIB_API)
gribSetDebug(1);
#endif
#if defined (HAVE_LIBNETCDF)
cdfDebug(1);
#endif
......@@ -543,17 +540,9 @@ int cdiInqContents(int streamID)
{
#if defined (HAVE_LIBGRIB)
case FILETYPE_GRB:
{
status = grbInqContents(streamID);
break;
}
#endif
#if defined (HAVE_LIBGRIB_API)
case FILETYPE_GRB2:
{
Message(func, "%s unsupported!", strfiletype(filetype));
status = CDI_ELIBNAVAIL;
/* status = grb2InqContents(streamID); */
status = grbInqContents(streamID);
break;
}
#endif
......@@ -1409,15 +1398,9 @@ int streamInqTimestep(int streamID, int tsID)
{
#if defined (HAVE_LIBGRIB)
case FILETYPE_GRB:
{
nrecs = grbInqTimestep(streamID, tsID);
break;
}
#endif
#if defined (HAVE_LIBGRIB_API)
case FILETYPE_GRB2:
{
/* nrecs = grb2InqTimestep(streamID, tsID);*/
nrecs = grbInqTimestep(streamID, tsID);
break;
}
#endif
......@@ -1505,15 +1488,9 @@ void streamReadVar(int streamID, int varID, double *data, int *nmiss)
{
#if defined (HAVE_LIBGRIB)
case FILETYPE_GRB:
{
grbReadVarDP(streamID, varID, data, nmiss);
break;
}
#endif
#if defined (HAVE_LIBGRIB_API)
case FILETYPE_GRB2:
{
/*grbReadVarDP(streamID, varID, data, nmiss);*/
grbReadVarDP(streamID, varID, data, nmiss);
break;
}
#endif
......@@ -1593,15 +1570,9 @@ void streamWriteVar(int streamID, int varID, double *data, int nmiss)
{
#if defined (HAVE_LIBGRIB)
case FILETYPE_GRB:
{
grbWriteVarDP(streamID, varID, data, nmiss);
break;
}
#endif
#if defined (HAVE_LIBGRIB_API)
case FILETYPE_GRB2:
{
/*grb2WriteVarDP(streamID, varID, data, nmiss);*/
grbWriteVarDP(streamID, varID, data, nmiss);
break;
}
#endif
......@@ -1681,15 +1652,9 @@ void streamReadVarSlice(int streamID, int varID, int levelID, double *data, int
{
#if defined (HAVE_LIBGRIB)
case FILETYPE_GRB:
{
grbReadVarSliceDP(streamID, varID, levelID, data, nmiss);
break;
}
#endif
#if defined (HAVE_LIBGRIB_API)
case FILETYPE_GRB2:
{
/* grb2ReadVarSliceDP(streamID, varID, levelID, data, nmiss);*/
grbReadVarSliceDP(streamID, varID, levelID, data, nmiss);
break;
}
#endif
......@@ -1769,15 +1734,9 @@ void streamWriteVarSlice(int streamID, int varID, int levelID, double *data, int
{
#if defined (HAVE_LIBGRIB)
case FILETYPE_GRB:
{
grbWriteVarSliceDP(streamID, varID, levelID, data, nmiss);
break;
}
#endif
#if defined (HAVE_LIBGRIB_API)
case FILETYPE_GRB2:
{
/* grb2WriteVarSliceDP(streamID, varID, levelID, data, nmiss); */
grbWriteVarSliceDP(streamID, varID, levelID, data, nmiss);
break;
}
#endif
......
This diff is collapsed.
#ifndef _STREAM_GRB_H
#define _STREAM_GRB_H
#ifndef _STREAM_CGRIBEX_H
#define _STREAM_CGRIBEX_H
#ifndef _CGRIBEX_H
# include "cgribex.h"
#endif
int cgribexInqRecord(int streamID, int *varID, int *levelID);
int grbInqContents(int streamID);
int grbInqTimestep(int streamID, int tsID);
void cgribexScanTimestep1(int streamID);
int cgribexScanTimestep2(int streamID);
int cgribexScanTimestep(int streamID);
int grbInqRecord(int streamID, int *varID, int *levelID);
int grbDefRecord(int streamID);
int grbWriteRecord(int streamID, const double *data, int nmiss);
int grbReadRecord(int streamID, double *data, int *nmiss);
int grbCopyRecord(int streamIDdest, int streamIDsrc);
int cgribexDecode(unsigned char *gribbuffer, int gribsize, double *data, int gridsize,
int unreduced, int *nmiss, int *zip);
void grbReadVarDP(int streamID, int varID, double *data, int *nmiss);
void grbWriteVarDP(int streamID, int varID, const double *data, int nmiss);
size_t cgribexEncode(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);
void grbReadVarSliceDP(int streamID, int varID, int levelID, double *data, int *nmiss);
int grbWriteVarSliceDP(int streamID, int varID, int levelID, const double *data, int nmiss);
#endif /* _STREAM_GRB_H */
#endif /* _STREAM_CGRIBEX_H */
#if defined (HAVE_CONFIG_H)
# include "config.h"
#endif
#include <stdio.h>
#include <string.h>
#include "dmemory.h"
#include "cdi.h"
#include "stream_int.h"
#include "stream_cgribex.h"
#include "stream_gribapi.h"
#include "file.h"
#include "cgribex.h" /* gribZip gribGetZip gribGinfo */
int grbInqRecord(int streamID, int *varID, int *levelID)
{
int status;
status = cgribexInqRecord(streamID, varID, levelID);
return (status);
}
int grbDefRecord(int streamID)
{
static char func[] = "grbDefRecord";
int fileID;
int gridID;
int status = 0;
stream_t *streamptr;
streamptr = stream_to_pointer(streamID);
stream_check_ptr(func, streamptr);
fileID = streamInqFileID(streamID);
gridID = streamptr->record->gridID;
return (status);
}
static
int grbDecode(int filetype, unsigned char *gribbuffer, int gribsize, double *data, int gridsize,
int unreduced, int *nmiss, int *zip)
{
//static char func[] = "grbDecode";
int status = 0;
if ( filetype == FILETYPE_GRB )
{
status = cgribexDecode(gribbuffer, gribsize, data, gridsize, unreduced, nmiss, zip);
}
else
{
status = gribapiDecode(gribbuffer, gribsize, data, gridsize, unreduced, nmiss, zip);
}
return (status);
}
int grbReadRecord(int streamID, double *data, int *nmiss)
{
static char func[] = "grbReadRecord";
int status = 0;
unsigned char *gribbuffer;
int fileID;
int recID, vrecID, tsID, gridID, varID;
long recsize;
off_t recpos;
int gridsize;
int vlistID;
int zip;
int filetype;
stream_t *streamptr;
streamptr = stream_to_pointer(streamID);
stream_check_ptr(func, streamptr);
filetype = streamptr->filetype;
gribbuffer = (unsigned char *) streamptr->record->buffer;
vlistID = streamInqVlist(streamID);
fileID = streamInqFileID(streamID);
tsID = streamptr->curTsID;
vrecID = streamptr->tsteps[tsID].curRecID;
recID = streamptr->tsteps[tsID].recIDs[vrecID];
recpos = streamptr->tsteps[tsID].records[recID].position;
recsize = streamptr->tsteps[tsID].records[recID].size;
varID = streamptr->tsteps[tsID].records[recID].varID;
gridID = vlistInqVarGrid(vlistID, varID);
gridsize = gridInqSize(gridID);
streamptr->numvals += gridsize;
fileSetPos(fileID, recpos, SEEK_SET);
fileRead(fileID, gribbuffer, (size_t) recsize);
grbDecode(filetype, gribbuffer, recsize, data, gridsize, streamptr->unreduced, nmiss, &zip);
streamptr->tsteps[tsID].records[recID].zip = zip;
return (status);
}
static
void grbScanTimestep1(int streamID)
{
int filetype;
stream_t *streamptr;
streamptr = stream_to_pointer(streamID);
filetype = streamptr->filetype;
if ( filetype == FILETYPE_GRB )
{
cgribexScanTimestep1(streamID);
}
else
{
gribapiScanTimestep1(streamID);
}
}
static
int grbScanTimestep2(int streamID)
{
int status;
int filetype;
stream_t *streamptr;
streamptr = stream_to_pointer(streamID);
filetype = streamptr->filetype;
if ( filetype == FILETYPE_GRB )
{
status = cgribexScanTimestep2(streamID);
}
else
{
status = gribapiScanTimestep2(streamID);
}
return (status);
}
static
int grbScanTimestep(int streamID)
{
int status;
int filetype;
stream_t *streamptr;
streamptr = stream_to_pointer(streamID);
filetype = streamptr->filetype;
if ( filetype == FILETYPE_GRB )
{
status = cgribexScanTimestep(streamID);
}
else
{
status = gribapiScanTimestep(streamID);
}
return (status);
}
int grbInqContents(int streamID)
{
static char func[] = "grbInqContents";
int fileID;
int status = 0;
stream_t *streamptr;
streamptr = stream_to_pointer(streamID);
stream_check_ptr(func, streamptr);
fileID = streamInqFileID(streamID);
streamptr->curTsID = 0;
grbScanTimestep1(streamID);
if ( streamptr->ntsteps == -1 ) status = grbScanTimestep2(streamID);
fileSetPos(fileID, 0, SEEK_SET);
return (status);
}
int grbInqTimestep(int streamID, int tsID)
{
static char func[] = "grbInqTimestep";
int ntsteps, nrecs;
stream_t *streamptr;
streamptr = stream_to_pointer(streamID);
stream_check_ptr(func, streamptr);
if ( tsID == 0 && streamptr->rtsteps == 0 )
Error(func, "Call to cdiInqContents missing!");
if ( CDI_Debug )
Message(func, "tsid = %d rtsteps = %d", tsID, streamptr->rtsteps);
ntsteps = CDI_UNDEFID;
while ( (tsID + 1) > streamptr->rtsteps && ntsteps == CDI_UNDEFID )
{
ntsteps = grbScanTimestep(streamID);
if ( ntsteps == CDI_EUFSTRUCT )
{
streamptr->ntsteps = streamptr->rtsteps;
break;
}
}
if ( tsID >= streamptr->ntsteps && streamptr->ntsteps != CDI_UNDEFID )
{
nrecs = 0;
}
else
{
streamptr->curTsID = tsID;
nrecs = streamptr->tsteps[tsID].nrecs;
}
return (nrecs);
}
void grbReadVarDP(int streamID, int varID, double *data, int *nmiss)
{
static char func[] = "grbReadVarDP";
int fileID;
int levelID, nlevs, gridID, gridsize;
unsigned char *gribbuffer;
int tsID, recID;
long recsize;
off_t recpos, currentfilepos;
int imiss;
int vlistID;
int zip;
int filetype;
stream_t *streamptr;
streamptr = stream_to_pointer(streamID);
stream_check_ptr(func, streamptr);
filetype = streamptr->filetype;
gribbuffer = (unsigned char *) streamptr->record->buffer;
vlistID = streamInqVlist(streamID);
fileID = streamInqFileID(streamID);
tsID = streamptr->curTsID;
nlevs = streamptr->vars[varID].nlevs;
gridID = vlistInqVarGrid(vlistID, varID);
gridsize = gridInqSize(gridID);
if ( CDI_Debug )
Message(func, "nlevs = %d gridID = %d gridsize = %d", nlevs, gridID, gridsize);
currentfilepos = fileGetPos(fileID);
*nmiss = 0;
for ( levelID = 0; levelID < nlevs; levelID++ )
{
recID = streamptr->vars[varID].level[levelID];
recpos = streamptr->tsteps[tsID].records[recID].position;
recsize = streamptr->tsteps[tsID].records[recID].size;
fileSetPos(fileID, recpos, SEEK_SET);
fileRead(fileID, gribbuffer, recsize);
grbDecode(filetype, gribbuffer, recsize, &data[levelID*gridsize], gridsize, streamptr->unreduced, &imiss, &zip);
*nmiss += imiss;
streamptr->tsteps[tsID].records[recID].zip = zip;
}
fileSetPos(fileID, currentfilepos, SEEK_SET);
}
void grbReadVarSliceDP(int streamID, int varID, int levelID, double *data, int *nmiss)
{
static char func[] = "grbReadVarSliceDP";