Commit 3c0965e9 authored by Uwe Schulzweida's avatar Uwe Schulzweida
Browse files

Added environment variable CDI_GRIBAPI_GRIB1 to set GRIB1 decoder/encoder to GRIBAPI.

parent 1785865f
......@@ -3,6 +3,10 @@
* using EXSE library version 1.4.1
* Version 1.9.6 released
2018-10-31 Uwe Schulzweida
* Added environment variable CDI_GRIBAPI_GRIB1 to set GRIB1 decoder/encoder to GRIBAPI
2018-10-11 Uwe Schulzweida
* cdf_read: removed limitation of nmiss_ to INT_MAX [Bug #8691]
......
......@@ -290,6 +290,19 @@ void cdiSetChunk(const char *chunkAlgo)
}
void cdiSetGribapiGrib1(bool value)
{
#ifndef HAVE_LIBGRIB_API
if (value)
{
Warning("%s: GRIB_API support not compiled in, used CGRIBEX to decode GRIB1 record!", __func__);
value = false;
}
#endif
CDI_gribapi_grib1 = value;
}
void cdiInitialize(void)
{
static bool Init_CDI = false;
......@@ -312,7 +325,7 @@ void cdiInitialize(void)
if ( value >= 0 ) CDI_gribapi_debug = (bool) value;
value = cdiGetenvInt("CDI_GRIBAPI_GRIB1");
if ( value >= 0 ) CDI_gribapi_grib1 = (bool) value;
if ( value >= 0 ) cdiSetGribapiGrib1((bool) value);
value = cdiGetenvInt("CDI_READ_CELL_CORNERS");
if ( value >= 0 ) CDI_read_cell_corners = (int) value;
......@@ -437,21 +450,21 @@ const char *strfiletype(int filetype)
}
void cdiDefGlobal(const char *string, int val)
void cdiDefGlobal(const char *string, int value)
{
// clang-format off
if (strcmp(string, "REGULARGRID") == 0) cdiDataUnreduced = val;
else if (strcmp(string, "GRIBAPI_DEBUG") == 0) CDI_gribapi_debug = (bool) val;
else if (strcmp(string, "GRIBAPI_GRIB1") == 0) CDI_gribapi_grib1 = (bool) val;
else if (strcmp(string, "SORTNAME") == 0) cdiSortName = val;
else if (strcmp(string, "SORTPARAM") == 0) cdiSortParam = val;
else if (strcmp(string, "HAVE_MISSVAL") == 0) cdiHaveMissval = val;
else if (strcmp(string, "NC_CHUNKSIZEHINT") == 0) cdiNcChunksizehint = val;
else if (strcmp(string, "READ_CELL_CORNERS") == 0) CDI_read_cell_corners = val;
else if (strcmp(string, "CMOR_MODE") == 0) CDI_cmor_mode = val;
else if (strcmp(string, "REDUCE_DIM") == 0) CDI_reduce_dim = val;
else if (strcmp(string, "NETCDF_HDR_PAD") == 0) CDI_netcdf_hdr_pad = (size_t) val;
else if (strcmp(string, "NETCDF_LAZY_GRID_LOAD") == 0) CDI_netcdf_lazy_grid_load = (bool) val;
if (strcmp(string, "REGULARGRID") == 0) cdiDataUnreduced = value;
else if (strcmp(string, "GRIBAPI_DEBUG") == 0) CDI_gribapi_debug = (bool) value;
else if (strcmp(string, "GRIBAPI_GRIB1") == 0) cdiSetGribapiGrib1((bool) value);
else if (strcmp(string, "SORTNAME") == 0) cdiSortName = value;
else if (strcmp(string, "SORTPARAM") == 0) cdiSortParam = value;
else if (strcmp(string, "HAVE_MISSVAL") == 0) cdiHaveMissval = value;
else if (strcmp(string, "NC_CHUNKSIZEHINT") == 0) cdiNcChunksizehint = value;
else if (strcmp(string, "READ_CELL_CORNERS") == 0) CDI_read_cell_corners = value;
else if (strcmp(string, "CMOR_MODE") == 0) CDI_cmor_mode = value;
else if (strcmp(string, "REDUCE_DIM") == 0) CDI_reduce_dim = value;
else if (strcmp(string, "NETCDF_HDR_PAD") == 0) CDI_netcdf_hdr_pad = (size_t) value;
else if (strcmp(string, "NETCDF_LAZY_GRID_LOAD") == 0) CDI_netcdf_lazy_grid_load = (bool) value;
else Warning("Unsupported global key: %s", string);
// clang-format on
}
......
......@@ -21,7 +21,7 @@ int grbDecode(int filetype, int memtype, void *cgribexp, void *gribbuffer, size_
int status = 0;
#ifdef HAVE_LIBCGRIBEX
if ( filetype == CDI_FILETYPE_GRB )
if ( filetype == CDI_FILETYPE_GRB && !CDI_gribapi_grib1 )
{
#ifdef HAVE_LIBGRIB_API
extern int cdiNAdditionalGRIBKeys;
......
......@@ -25,7 +25,7 @@ size_t grbEncode(int filetype, int memtype, int varID, int levelID, int vlistID,
size_t nbytes = 0;
#ifdef HAVE_LIBCGRIBEX
if ( filetype == CDI_FILETYPE_GRB )
if ( filetype == CDI_FILETYPE_GRB && !CDI_gribapi_grib1 )
{
size_t gribbuffersize = datasize*4+3000;
*gribbuffer = Malloc(gribbuffersize);
......@@ -116,23 +116,37 @@ void grbCopyRecord(stream_t * streamptr2, stream_t * streamptr1)
size_t nbytes = recsize;
if ( filetype == CDI_FILETYPE_GRB )
#ifdef HAVE_LIBCGRIBEX
if ( filetype == CDI_FILETYPE_GRB && !CDI_gribapi_grib1 )
{
if ( cdiGribChangeParameterID.active )
{
// Even if you are stream-copy records you might need to change a bit of grib-header !
#if defined HAVE_LIBCGRIBEX
void *gh = cgribex_handle_new_from_meassage((void*) gribbuffer, recsize);
cgribexChangeParameterIdentification(gh, cdiGribChangeParameterID.code, cdiGribChangeParameterID.ltype, cdiGribChangeParameterID.lev);
cgribex_handle_delete(gh);
#elif defined HAVE_LIBGRIB_API
cdiGribChangeParameterID.active = false; // after grib attributes have been changed turn it off again
}
}
else
#endif
#ifdef HAVE_LIBGRIB_API
{
if ( cdiGribChangeParameterID.active )
{
// Even if you are stream-copy records you might need to change a bit of grib-header !
void *gh = (void*)grib_handle_new_from_message(NULL, (void*) gribbuffer, recsize);
gribapiChangeParameterIdentification(gh, cdiGribChangeParameterID.code, cdiGribChangeParameterID.ltype, cdiGribChangeParameterID.lev);
grib_handle_delete(gh);
#endif
cdiGribChangeParameterID.active = false; // after grib attributes have been changed turn it off again
}
}
#else
{
(void)vlistID; (void)varID;
Error("GRIB_API support not compiled in!");
}
#endif
#ifdef HIRLAM_EXTENSIONS
// Even if you are stream-copy records you might need to change a bit of grib-header !
......@@ -240,7 +254,7 @@ void grb_write_var_slice(stream_t *streamptr, int varID, int levelID, int memtyp
size_t datasize = gridInqSize(gridID);
#ifdef HAVE_LIBCGRIBEX
if ( filetype == CDI_FILETYPE_GRB )
if ( filetype == CDI_FILETYPE_GRB && !CDI_gribapi_grib1 )
{
}
else
......@@ -257,7 +271,7 @@ void grb_write_var_slice(stream_t *streamptr, int varID, int levelID, int memtyp
if ( comptype != CDI_COMPRESS_JPEG && comptype != CDI_COMPRESS_SZIP && comptype != CDI_COMPRESS_AEC ) comptype = CDI_COMPRESS_NONE;
if ( filetype == CDI_FILETYPE_GRB && comptype == CDI_COMPRESS_JPEG )
if ( filetype == CDI_FILETYPE_GRB && !CDI_gribapi_grib1 && comptype == CDI_COMPRESS_JPEG )
{
static int ljpeg_warn = 1;
if ( ljpeg_warn ) Warning("JPEG compression of GRIB1 records not available!");
......
#ifdef HAVE_CONFIG_H
# include "config.h"
#include "config.h"
#endif
#ifdef HAVE_LIBGRIB_API
# include <grib_api.h>
#include <grib_api.h>
#endif
#include <stdio.h>
......@@ -56,7 +56,7 @@ void gribContainersNew(stream_t * streamptr)
int editionNumber = (streamptr->filetype == CDI_FILETYPE_GRB) ? 1 : 2;
#ifdef HAVE_LIBCGRIBEX
if ( editionNumber == 1 )
if ( editionNumber == 1 && !CDI_gribapi_grib1 )
{
}
else
......
......@@ -64,7 +64,7 @@ int streamGrbInqDataScanningMode(void)
int grib1ltypeToZaxisType(int grib_ltype)
{
int zaxistype = ZAXIS_GENERIC;
// clang-format off
switch ( grib_ltype )
{
case GRIB1_LTYPE_SURFACE: zaxistype = ZAXIS_SURFACE; break;
......@@ -94,7 +94,7 @@ int grib1ltypeToZaxisType(int grib_ltype)
case GRIB1_LTYPE_SEDIMENT_BOTTOM_TW: zaxistype = ZAXIS_SEDIMENT_BOTTOM_TW; break;
case GRIB1_LTYPE_MIX_LAYER: zaxistype = ZAXIS_MIX_LAYER; break;
}
// clang-format on
return zaxistype;
}
......@@ -102,7 +102,7 @@ int grib1ltypeToZaxisType(int grib_ltype)
int grib2ltypeToZaxisType(int grib_ltype)
{
int zaxistype = ZAXIS_GENERIC;
// clang-format off
switch ( grib_ltype )
{
case GRIB2_LTYPE_SURFACE: zaxistype = ZAXIS_SURFACE; break;
......@@ -131,7 +131,7 @@ int grib2ltypeToZaxisType(int grib_ltype)
case GRIB2_LTYPE_MIX_LAYER: zaxistype = ZAXIS_MIX_LAYER; break;
case GRIB2_LTYPE_REFERENCE: zaxistype = ZAXIS_REFERENCE; break;
}
// clang-format on
return zaxistype;
}
......@@ -139,7 +139,7 @@ int grib2ltypeToZaxisType(int grib_ltype)
int zaxisTypeToGrib1ltype(int zaxistype)
{
int grib_ltype = -1;
// clang-format off
switch (zaxistype)
{
case ZAXIS_SURFACE: grib_ltype = GRIB1_LTYPE_SURFACE; break;
......@@ -169,7 +169,7 @@ int zaxisTypeToGrib1ltype(int zaxistype)
case ZAXIS_MIX_LAYER: grib_ltype = GRIB1_LTYPE_MIX_LAYER; break;
case ZAXIS_REFERENCE: grib_ltype = -1; break;
}
// clang-format on
return grib_ltype;
}
......@@ -177,7 +177,7 @@ int zaxisTypeToGrib1ltype(int zaxistype)
int zaxisTypeToGrib2ltype(int zaxistype)
{
int grib_ltype = -1;
// clang-format off
switch (zaxistype)
{
case ZAXIS_SURFACE: grib_ltype = GRIB2_LTYPE_SURFACE; break;
......@@ -207,7 +207,7 @@ int zaxisTypeToGrib2ltype(int zaxistype)
case ZAXIS_MIX_LAYER: grib_ltype = GRIB2_LTYPE_MIX_LAYER; break;
case ZAXIS_REFERENCE: grib_ltype = GRIB2_LTYPE_REFERENCE; break;
}
// clang-format on
return grib_ltype;
}
......@@ -257,14 +257,14 @@ int grbScanTimestep1(stream_t * streamptr)
#ifdef HAVE_LIBCGRIBEX
int filetype = streamptr->filetype;
if ( filetype == CDI_FILETYPE_GRB )
if ( filetype == CDI_FILETYPE_GRB && !CDI_gribapi_grib1 )
status = cgribexScanTimestep1(streamptr);
#endif
#if defined(HAVE_LIBCGRIBEX) && defined (HAVE_LIBGRIB_API)
else
#endif
#ifdef HAVE_LIBGRIB_API
status = gribapiScanTimestep1(streamptr);
#else
Error("Sufficient GRIB support unavailable!");
#endif
return status;
......@@ -278,14 +278,14 @@ int grbScanTimestep2(stream_t * streamptr)
#ifdef HAVE_LIBCGRIBEX
int filetype = streamptr->filetype;
if ( filetype == CDI_FILETYPE_GRB )
if ( filetype == CDI_FILETYPE_GRB && !CDI_gribapi_grib1 )
status = cgribexScanTimestep2(streamptr);
#endif
#if defined(HAVE_LIBCGRIBEX) && defined (HAVE_LIBGRIB_API)
else
#endif
#ifdef HAVE_LIBGRIB_API
status = gribapiScanTimestep2(streamptr);
#else
Error("Sufficient GRIB support unavailable!");
#endif
return status;
......@@ -299,7 +299,7 @@ int grbScanTimestep(stream_t * streamptr)
#ifdef HAVE_LIBCGRIBEX
int filetype = streamptr->filetype;
if ( filetype == CDI_FILETYPE_GRB )
if ( filetype == CDI_FILETYPE_GRB && !CDI_gribapi_grib1 )
status = cgribexScanTimestep(streamptr);
else
#endif
......@@ -369,7 +369,8 @@ void streamInqGRIBinfo(int streamID, int *intnum, float *fltnum, off_t *bignum)
int filetype = streamptr->filetype;
if ( filetype == CDI_FILETYPE_GRB )
#ifdef HAVE_LIBCGRIBEX
if ( filetype == CDI_FILETYPE_GRB && !CDI_gribapi_grib1 )
{
int tsID = streamptr->curTsID;
int vrecID = streamptr->tsteps[tsID].curRecID;
......@@ -385,6 +386,13 @@ void streamInqGRIBinfo(int streamID, int *intnum, float *fltnum, off_t *bignum)
else
grib_info_for_grads(recpos, (long)gribbuffersize, (unsigned char *) gribbuffer, intnum, fltnum, bignum);
}
else if (CDI_gribapi_grib1)
{
Error("CGRIBEX support deactivated!");
}
#else
Error("CGRIBEX support not compiled in!");
#endif
}
......
......@@ -32,7 +32,7 @@ int cdiStreamReadVar(int streamID, int varID, int memtype, void *data, size_t *n
switch (filetype)
{
#if defined (HAVE_LIBGRIB)
#ifdef HAVE_LIBGRIB
case CDI_FILETYPE_GRB:
case CDI_FILETYPE_GRB2:
{
......@@ -159,7 +159,7 @@ int cdiStreamReadVarSlice(int streamID, int varID, int levelID, int memtype, voi
switch (filetype)
{
#if defined (HAVE_LIBGRIB)
#ifdef HAVE_LIBGRIB
case CDI_FILETYPE_GRB:
case CDI_FILETYPE_GRB2:
{
......@@ -289,7 +289,7 @@ int stream_read_record(int streamID, int memtype, void *data, size_t *nmiss)
switch (streamptr->filetype)
{
#if defined (HAVE_LIBGRIB)
#ifdef HAVE_LIBGRIB
case CDI_FILETYPE_GRB:
case CDI_FILETYPE_GRB2:
grb_read_record(streamptr, memtype, data, nmiss);
......
......@@ -182,7 +182,7 @@ void streamDefRecord(int streamID, int varID, int levelID)
switch (streamptr->filetype)
{
#if defined (HAVE_LIBGRIB)
#ifdef HAVE_LIBGRIB
case CDI_FILETYPE_GRB:
case CDI_FILETYPE_GRB2:
grbDefRecord(streamptr);
......@@ -258,7 +258,7 @@ void streamCopyRecord(int streamID2, int streamID1)
switch (filetype)
{
#if defined (HAVE_LIBGRIB)
#ifdef HAVE_LIBGRIB
case CDI_FILETYPE_GRB:
case CDI_FILETYPE_GRB2:
grbCopyRecord(streamptr2, streamptr1);
......
......@@ -35,7 +35,7 @@ int cdiStreamWriteVar_(int streamID, int varID, int memtype, const void *data, s
switch (filetype)
{
#if defined (HAVE_LIBGRIB)
#ifdef HAVE_LIBGRIB
case CDI_FILETYPE_GRB:
case CDI_FILETYPE_GRB2:
{
......@@ -172,7 +172,7 @@ int cdiStreamWriteVarSlice(int streamID, int varID, int levelID, int memtype, co
switch (filetype)
{
#if defined (HAVE_LIBGRIB)
#ifdef HAVE_LIBGRIB
case CDI_FILETYPE_GRB:
case CDI_FILETYPE_GRB2:
{
......@@ -348,7 +348,7 @@ int stream_write_record(int streamID, int memtype, const void *data, size_t nmis
switch (streamptr->filetype)
{
#if defined (HAVE_LIBGRIB)
#ifdef HAVE_LIBGRIB
case CDI_FILETYPE_GRB:
case CDI_FILETYPE_GRB2:
grb_write_record(streamptr, memtype, data, nmiss);
......
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