diff --git a/src/cgribex.h b/src/cgribex.h index afb23c6150602b56bbd7519ceaeb657663528a27..892511532a44384d54fc69fad679b0cf445ee47c 100644 --- a/src/cgribex.h +++ b/src/cgribex.h @@ -31,29 +31,29 @@ #define GRIB1_LTYPE_LANDDEPTH 111 #define GRIB1_LTYPE_LANDDEPTH_LAYER 112 #define GRIB1_LTYPE_ISENTROPIC 113 -#define GRIB1_LTYPE_SEADEPTH 160 // Depth Below Sea Level -#define GRIB1_LTYPE_LAKE_BOTTOM 162 // Lake or River Bottom -#define GRIB1_LTYPE_SEDIMENT_BOTTOM 163 // Bottom Of Sediment Layer -#define GRIB1_LTYPE_SEDIMENT_BOTTOM_TA 164 // Bottom Of Thermally Active Sediment Layer -#define GRIB1_LTYPE_SEDIMENT_BOTTOM_TW 165 // Bottom Of Sediment Layer Penetrated By Thermal Wave -#define GRIB1_LTYPE_MIX_LAYER 166 // Mixing Layer +#define GRIB1_LTYPE_SEADEPTH 160 // Depth Below Sea Level +#define GRIB1_LTYPE_LAKE_BOTTOM 162 // Lake or River Bottom +#define GRIB1_LTYPE_SEDIMENT_BOTTOM 163 // Bottom Of Sediment Layer +#define GRIB1_LTYPE_SEDIMENT_BOTTOM_TA 164 // Bottom Of Thermally Active Sediment Layer +#define GRIB1_LTYPE_SEDIMENT_BOTTOM_TW 165 // Bottom Of Sediment Layer Penetrated By Thermal Wave +#define GRIB1_LTYPE_MIX_LAYER 166 // Mixing Layer // GRIB1 Data representation type (Grid Type) [Table 6] -#define GRIB1_GTYPE_LATLON 0 // latitude/longitude -#define GRIB1_GTYPE_LATLON_ROT 10 // rotated latitude/longitude -#define GRIB1_GTYPE_LATLON_STR 20 // stretched latitude/longitude -#define GRIB1_GTYPE_LATLON_ROTSTR 30 // rotated and stretched latitude/longitude -#define GRIB1_GTYPE_GAUSSIAN 4 // gaussian grid -#define GRIB1_GTYPE_GAUSSIAN_ROT 14 // rotated gaussian grid -#define GRIB1_GTYPE_GAUSSIAN_STR 24 // stretched gaussian grid -#define GRIB1_GTYPE_GAUSSIAN_ROTSTR 34 // rotated and stretched gaussian grid -#define GRIB1_GTYPE_LCC 3 // Lambert conformal -#define GRIB1_GTYPE_SPECTRAL 50 // spherical harmonics -#define GRIB1_GTYPE_GME 192 // hexagonal GME grid +#define GRIB1_GTYPE_LATLON 0 // latitude/longitude +#define GRIB1_GTYPE_LATLON_ROT 10 // rotated latitude/longitude +#define GRIB1_GTYPE_LATLON_STR 20 // stretched latitude/longitude +#define GRIB1_GTYPE_LATLON_ROTSTR 30 // rotated and stretched latitude/longitude +#define GRIB1_GTYPE_GAUSSIAN 4 // gaussian grid +#define GRIB1_GTYPE_GAUSSIAN_ROT 14 // rotated gaussian grid +#define GRIB1_GTYPE_GAUSSIAN_STR 24 // stretched gaussian grid +#define GRIB1_GTYPE_GAUSSIAN_ROTSTR 34 // rotated and stretched gaussian grid +#define GRIB1_GTYPE_LCC 3 // Lambert conformal +#define GRIB1_GTYPE_SPECTRAL 50 // spherical harmonics +#define GRIB1_GTYPE_GME 192 // hexagonal GME grid // Macros for the indicator section ( Section 0 ) -#define ISEC0_GRIB_Len (isec0[ 0]) // Number of octets in the GRIB message -#define ISEC0_GRIB_Version (isec0[ 1]) // GRIB edition number +#define ISEC0_GRIB_Len (isec0[ 0]) // Number of octets in the GRIB message +#define ISEC0_GRIB_Version (isec0[ 1]) // GRIB edition number // Macros for the product definition section ( Section 1 ) @@ -67,108 +67,108 @@ #define ISEC1_TABLE4_30MINUTES 14 -#define ISEC1_CodeTable (isec1[ 0]) // Version number of code table -#define ISEC1_CenterID (isec1[ 1]) // Identification of centre -#define ISEC1_ModelID (isec1[ 2]) // Identification of model -#define ISEC1_GridDefinition (isec1[ 3]) // Grid definition -#define ISEC1_Sec2Or3Flag (isec1[ 4]) // Section 2 or 3 included -#define ISEC1_Parameter (isec1[ 5]) // Parameter indicator -#define ISEC1_LevelType (isec1[ 6]) // Type of level indicator -#define ISEC1_Level1 (isec1[ 7]) // Level 1 -#define ISEC1_Level2 (isec1[ 8]) // Level 2 -#define ISEC1_Year (isec1[ 9]) // Year of century (YY) -#define ISEC1_Month (isec1[10]) // Month (MM) -#define ISEC1_Day (isec1[11]) // Day (DD) -#define ISEC1_Hour (isec1[12]) // Hour (HH) -#define ISEC1_Minute (isec1[13]) // Minute (MM) -#define ISEC1_TimeUnit (isec1[14]) // Time unit indicator -#define ISEC1_TimePeriod1 (isec1[15]) // P1 Time period -#define ISEC1_TimePeriod2 (isec1[16]) // P2 Time period -#define ISEC1_TimeRange (isec1[17]) // Time range indicator -#define ISEC1_AvgNum (isec1[18]) // Number of products included in an average -#define ISEC1_AvgMiss (isec1[19]) // Number of products missing from an average -#define ISEC1_Century (isec1[20]) // Century -#define ISEC1_SubCenterID (isec1[21]) // Subcenter identifier -#define ISEC1_DecScaleFactor (isec1[22]) // Decimal scale factor -#define ISEC1_LocalFLag (isec1[23]) // Flag field to indicate local use in isec1 +#define ISEC1_CodeTable (isec1[ 0]) // Version number of code table +#define ISEC1_CenterID (isec1[ 1]) // Identification of centre +#define ISEC1_ModelID (isec1[ 2]) // Identification of model +#define ISEC1_GridDefinition (isec1[ 3]) // Grid definition +#define ISEC1_Sec2Or3Flag (isec1[ 4]) // Section 2 or 3 included +#define ISEC1_Parameter (isec1[ 5]) // Parameter indicator +#define ISEC1_LevelType (isec1[ 6]) // Type of level indicator +#define ISEC1_Level1 (isec1[ 7]) // Level 1 +#define ISEC1_Level2 (isec1[ 8]) // Level 2 +#define ISEC1_Year (isec1[ 9]) // Year of century (YY) +#define ISEC1_Month (isec1[10]) // Month (MM) +#define ISEC1_Day (isec1[11]) // Day (DD) +#define ISEC1_Hour (isec1[12]) // Hour (HH) +#define ISEC1_Minute (isec1[13]) // Minute (MM) +#define ISEC1_TimeUnit (isec1[14]) // Time unit indicator +#define ISEC1_TimePeriod1 (isec1[15]) // P1 Time period +#define ISEC1_TimePeriod2 (isec1[16]) // P2 Time period +#define ISEC1_TimeRange (isec1[17]) // Time range indicator +#define ISEC1_AvgNum (isec1[18]) // Number of products included in an average +#define ISEC1_AvgMiss (isec1[19]) // Number of products missing from an average +#define ISEC1_Century (isec1[20]) // Century +#define ISEC1_SubCenterID (isec1[21]) // Subcenter identifier +#define ISEC1_DecScaleFactor (isec1[22]) // Decimal scale factor +#define ISEC1_LocalFLag (isec1[23]) // Flag field to indicate local use in isec1 #define ISEC1_ECMWF_LocalExtension (isec1[36]) #define ISEC1_ECMWF_Class (isec1[37]) // Macros for the grid definition section ( Section 2 ) -#define ISEC2_GridType (isec2[ 0]) // Data representation type +#define ISEC2_GridType (isec2[ 0]) // Data representation type // Triangular grids -#define ISEC2_GME_NI2 (isec2[ 1]) // Number of factor 2 in factorisation of Ni -#define ISEC2_GME_NI3 (isec2[ 2]) // Number of factor 3 in factorisation of Ni -#define ISEC2_GME_ND (isec2[ 3]) // Nubmer of diamonds -#define ISEC2_GME_NI (isec2[ 4]) // Number of tri. subdiv. of the icosahedron -#define ISEC2_GME_AFlag (isec2[ 5]) // Flag for orientation of diamonds (Table A) -#define ISEC2_GME_LatPP (isec2[ 6]) // Latitude of pole point -#define ISEC2_GME_LonPP (isec2[ 7]) // Longitude of pole point -#define ISEC2_GME_LonMPL (isec2[ 8]) // Longitude of the first diamond -#define ISEC2_GME_BFlag (isec2[ 9]) // Flag for storage sequence (Table B) +#define ISEC2_GME_NI2 (isec2[ 1]) // Number of factor 2 in factorisation of Ni +#define ISEC2_GME_NI3 (isec2[ 2]) // Number of factor 3 in factorisation of Ni +#define ISEC2_GME_ND (isec2[ 3]) // Nubmer of diamonds +#define ISEC2_GME_NI (isec2[ 4]) // Number of tri. subdiv. of the icosahedron +#define ISEC2_GME_AFlag (isec2[ 5]) // Flag for orientation of diamonds (Table A) +#define ISEC2_GME_LatPP (isec2[ 6]) // Latitude of pole point +#define ISEC2_GME_LonPP (isec2[ 7]) // Longitude of pole point +#define ISEC2_GME_LonMPL (isec2[ 8]) // Longitude of the first diamond +#define ISEC2_GME_BFlag (isec2[ 9]) // Flag for storage sequence (Table B) // Spherical harmonic coeficients -#define ISEC2_PentaJ (isec2[ 1]) // J pentagonal resolution parameter -#define ISEC2_PentaK (isec2[ 2]) // K pentagonal resolution parameter -#define ISEC2_PentaM (isec2[ 3]) // M pentagonal resolution parameter -#define ISEC2_RepType (isec2[ 4]) // Representation type -#define ISEC2_RepMode (isec2[ 5]) // Representation mode +#define ISEC2_PentaJ (isec2[ 1]) // J pentagonal resolution parameter +#define ISEC2_PentaK (isec2[ 2]) // K pentagonal resolution parameter +#define ISEC2_PentaM (isec2[ 3]) // M pentagonal resolution parameter +#define ISEC2_RepType (isec2[ 4]) // Representation type +#define ISEC2_RepMode (isec2[ 5]) // Representation mode // Gaussian grids -#define ISEC2_NumLon (isec2[ 1]) // Number of points along a parallel (Ni) -#define ISEC2_NumLat (isec2[ 2]) // Number of points along a meridian (Nj) -#define ISEC2_FirstLat (isec2[ 3]) // Latitude of the first grid point -#define ISEC2_FirstLon (isec2[ 4]) // Longitude of the first grid point -#define ISEC2_ResFlag (isec2[ 5]) // Resolution flag: 128 regular grid -#define ISEC2_LastLat (isec2[ 6]) // Latitude of the last grid point -#define ISEC2_LastLon (isec2[ 7]) // Longitude of the last grid point -#define ISEC2_LonIncr (isec2[ 8]) // i direction increment -#define ISEC2_LatIncr (isec2[ 9]) // j direction increment +#define ISEC2_NumLon (isec2[ 1]) // Number of points along a parallel (Ni) +#define ISEC2_NumLat (isec2[ 2]) // Number of points along a meridian (Nj) +#define ISEC2_FirstLat (isec2[ 3]) // Latitude of the first grid point +#define ISEC2_FirstLon (isec2[ 4]) // Longitude of the first grid point +#define ISEC2_ResFlag (isec2[ 5]) // Resolution flag: 128 regular grid +#define ISEC2_LastLat (isec2[ 6]) // Latitude of the last grid point +#define ISEC2_LastLon (isec2[ 7]) // Longitude of the last grid point +#define ISEC2_LonIncr (isec2[ 8]) // i direction increment +#define ISEC2_LatIncr (isec2[ 9]) // j direction increment #define ISEC2_NumPar (isec2[ 9]) // Number of parallels between a pole and the E. -#define ISEC2_ScanFlag (isec2[10]) // Scanning mode flags -#define ISEC2_NumVCP (isec2[11]) // Number of vertical coordinate parameters +#define ISEC2_ScanFlag (isec2[10]) // Scanning mode flags +#define ISEC2_NumVCP (isec2[11]) // Number of vertical coordinate parameters // Lambert -#define ISEC2_Lambert_Lov (isec2[ 6]) // Orientation of the grid -#define ISEC2_Lambert_dx (isec2[ 8]) // X-direction grid length -#define ISEC2_Lambert_dy (isec2[ 9]) // Y-direction grid length -#define ISEC2_Lambert_ProjFlag (isec2[12]) // Projection centre flag -#define ISEC2_Lambert_LatS1 (isec2[13]) // First lat at which the secant cone cuts the sphere -#define ISEC2_Lambert_LatS2 (isec2[14]) // Second lat at which the secant cone cuts the sphere -#define ISEC2_Lambert_LatSP (isec2[19]) // Latitude of the southern pole -#define ISEC2_Lambert_LonSP (isec2[20]) // Longitude of the southern pole +#define ISEC2_Lambert_Lov (isec2[ 6]) // Orientation of the grid +#define ISEC2_Lambert_dx (isec2[ 8]) // X-direction grid length +#define ISEC2_Lambert_dy (isec2[ 9]) // Y-direction grid length +#define ISEC2_Lambert_ProjFlag (isec2[12]) // Projection centre flag +#define ISEC2_Lambert_LatS1 (isec2[13]) // First lat at which the secant cone cuts the sphere +#define ISEC2_Lambert_LatS2 (isec2[14]) // Second lat at which the secant cone cuts the sphere +#define ISEC2_Lambert_LatSP (isec2[19]) // Latitude of the southern pole +#define ISEC2_Lambert_LonSP (isec2[20]) // Longitude of the southern pole -#define ISEC2_Reduced (isec2[16]) // 0: regular, 1: reduced grid +#define ISEC2_Reduced (isec2[16]) // 0: regular, 1: reduced grid #define ISEC2_ReducedPointsPtr (&isec2[22]) -#define ISEC2_ReducedPoints(i) (isec2[22+i]) // Number of points along each parallel +#define ISEC2_ReducedPoints(i) (isec2[22+i]) // Number of points along each parallel -#define ISEC2_LatSP (isec2[12]) // Latitude of the southern pole of rotation -#define ISEC2_LonSP (isec2[13]) // Longitude of the southern pole of rotation +#define ISEC2_LatSP (isec2[12]) // Latitude of the southern pole of rotation +#define ISEC2_LonSP (isec2[13]) // Longitude of the southern pole of rotation -#define FSEC2_RotAngle (fsec2[ 0]) // Angle of rotation -#define FSEC2_StrFact (fsec2[ 1]) // Stretching factor +#define FSEC2_RotAngle (fsec2[ 0]) // Angle of rotation +#define FSEC2_StrFact (fsec2[ 1]) // Stretching factor // Macros for the bit map section ( Section 3 ) -#define ISEC3_PredefBitmap (isec3[ 0]) // Predefined bitmap -#define ISEC3_MissVal (isec3[ 1]) // Missing data value for integers -#define FSEC3_MissVal (fsec3[ 1]) // Missing data value for floats +#define ISEC3_PredefBitmap (isec3[ 0]) // Predefined bitmap +#define ISEC3_MissVal (isec3[ 1]) // Missing data value for integers +#define FSEC3_MissVal (fsec3[ 1]) // Missing data value for floats // Macros for the binary data section ( Section 4 ) -#define ISEC4_NumValues (isec4[ 0]) // Number of data values for encode/decode -#define ISEC4_NumBits (isec4[ 1]) // Number of bits used for each encoded value -#define ISEC4_NumNonMissValues (isec4[20]) // Number of non-missing values +#define ISEC4_NumValues (isec4[ 0]) // Number of data values for encode/decode +#define ISEC4_NumBits (isec4[ 1]) // Number of bits used for each encoded value +#define ISEC4_NumNonMissValues (isec4[20]) // Number of non-missing values #ifdef __cplusplus @@ -247,6 +247,9 @@ int grib_info_for_grads(off_t recpos, long recsize, unsigned char *gribbuffer, double calculate_pfactor_float(const float* spectralField, long fieldTruncation, long subsetTruncation); double calculate_pfactor_double(const double* spectralField, long fieldTruncation, long subsetTruncation); +int grib1Sections(unsigned char *gribbuffer, long gribbufsize, unsigned char **pdsp, unsigned char **gdsp, unsigned char **bmsp, + unsigned char **bdsp, long *gribrecsize); + #ifdef __cplusplus } #endif diff --git a/src/cgribexlib.c b/src/cgribexlib.c index a19337c13e190a9af685feea5cd8497e3b124761..05ea0e60993415484c18609f72953880e5a8d32b 100644 --- a/src/cgribexlib.c +++ b/src/cgribexlib.c @@ -1,7 +1,7 @@ -// Automatically generated by m214003 at 2024-06-08, do not edit +// Automatically generated by m214003 at 2024-10-23, do not edit -// CGRIBEXLIB_VERSION="2.3.0" +// CGRIBEXLIB_VERSION="2.3.1" #if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ > 5) || defined(__clang__) #pragma GCC diagnostic push @@ -1219,8 +1219,13 @@ xlc_r -g -O3 -qhot -q64 -qarch=auto -qtune=auto -qreport -DTEST_ENCODE encode_ar #define GRIBPACK unsigned char #ifndef HOST_ENDIANNESS +#ifdef __cplusplus +static const uint32_t HOST_ENDIANNESS_temp[1] = { UINT32_C(0x00030201) }; +#define HOST_ENDIANNESS (((const unsigned char *) HOST_ENDIANNESS_temp)[0]) +#else #define HOST_ENDIANNESS (((const unsigned char *) &(const uint32_t[1]){ UINT32_C(0x00030201) })[0]) #endif +#endif #define IS_BIGENDIAN() (HOST_ENDIANNESS == 0) #define Error(x, y) @@ -1948,16 +1953,16 @@ decfp2(int kexp, int kmant) /* Section 2 . Convert other values. */ /* ----------------------------------------------------------------- */ - /* Sign of value. */ + // Sign of value. int iexp = kexp; int isign = (iexp < 128) * 2 - 1; iexp -= iexp < 128 ? 0 : 128; - /* Decode value. */ + // Decode value. - /* pval = isign * pow(2.0, -24.0) * kmant * pow(16.0, (double)(iexp - 64)); */ + // double pval = isign * pow(2.0, -24.0) * kmant * pow(16.0, (double)(iexp - 64)); iexp -= 64; @@ -1968,7 +1973,7 @@ decfp2(int kexp, int kmant) /* ----------------------------------------------------------------- */ return pval; -} /* decfp2 */ +} #include <stdarg.h> #include <stdint.h> @@ -3718,10 +3723,9 @@ gribCheckSeek(int fileID, long *offset, int *version) int gribFileSeek(int fileID, long *offset) { - /* position file pointer after GRIB */ + // position file pointer after GRIB const long GRIB = 0x47524942; long code = 0; - int ch; int retry = 4096 * 4096; *offset = 0; @@ -3730,7 +3734,7 @@ gribFileSeek(int fileID, long *offset) while (retry--) { - ch = filePtrGetc(fileptr); + int ch = filePtrGetc(fileptr); if (ch == EOF) return -1; code = ((code << 8) + ch) & 0xFFFFFFFF; @@ -3892,10 +3896,7 @@ gribGetSize(int fileID) return 0; } - if (ierr == -1) - return 0; - else if (ierr == 1) - return 0; + if (ierr == -1) return 0; size_t recSize = gribReadSize(fileID); @@ -3914,6 +3915,7 @@ gribRead(int fileID, void *buffer, size_t *buffersize) if (ierr > 0) { Warning("GRIB record not found!"); + *buffersize = 0; return -2; } @@ -3922,11 +3924,6 @@ gribRead(int fileID, void *buffer, size_t *buffersize) *buffersize = 0; return -1; } - else if (ierr == 1) - { - *buffersize = 0; - return -2; - } size_t recSize = gribReadSize(fileID); size_t readSize = recSize; @@ -12614,7 +12611,7 @@ encode_dummy(void) (void) encode_array_unrolled_double(0, 0, 0, NULL, NULL, 0, 0, NULL); (void) encode_array_unrolled_float(0, 0, 0, NULL, NULL, 0, 0, NULL); } -static const char grb_libvers[] = "2.3.0"; +static const char grb_libvers[] = "2.3.1"; const char * cgribexLibraryVersion(void) { diff --git a/src/stream_cgribex.c b/src/stream_cgribex.c index 8cbef7d610ef15b00da1f03c4afa116ec1e9ddb3..a2c73b7f0c104ce5fc2657e94d659287bcd380b2 100644 --- a/src/stream_cgribex.c +++ b/src/stream_cgribex.c @@ -82,16 +82,6 @@ cgribexDelete(void *cgribex) } } -#ifdef __cplusplus -extern "C" -{ -#endif - int grib1Sections(unsigned char *gribbuffer, long gribbufsize, unsigned char **pdsp, unsigned char **gdsp, unsigned char **bmsp, - unsigned char **bdsp, long *gribrecsize); -#ifdef __cplusplus -} -#endif - static size_t cgribexSection2Length(void *gribbuffer, size_t gribbuffersize) { @@ -201,10 +191,10 @@ cgribexGetTimeUnit(int *isec1) case ISEC1_TABLE4_DAY: timeunit = TUNIT_DAY; break; default: if (lprint) - { - Warning("GRIB time unit %d unsupported!", ISEC1_TimeUnit); - lprint = false; - } + { + Warning("GRIB time unit %d unsupported!", ISEC1_TimeUnit); + lprint = false; + } break; } // clang-format on @@ -237,10 +227,10 @@ cgribexGetTsteptype(int timerange) case 10: tsteptype = TSTEP_INSTANT3; break; default: if (lprint) - { - Warning("Time range indicator %d unsupported, set to 0!", timerange); - lprint = false; - } + { + Warning("Time range indicator %d unsupported, set to 0!", timerange); + lprint = false; + } break; } // clang-format on