NCEPLIBS-g2c  1.7.0
grib2.h File Reference

Header file for NCEPLIBS-g2c library. More...

#include <stdio.h>
#include <stdint.h>

Go to the source code of this file.

Data Structures

struct  gribfield
 Struct for GRIB field. More...
 

Macros

#define G2_ADD_MSG_COMPLETE   -2
 GRIB message already complete. More...
 
#define G2_ADD_MSG_INIT   -1
 GRIB message was not initialized - call g2_create() first. More...
 
#define G2_ADDFIELD_BAD_BITMAP   -8
 In g2_addfield() no bitmap in the GRIB message. More...
 
#define G2_ADDFIELD_BAD_DRT   -7
 In g2_addfield() unsupported Data Representationi Template. More...
 
#define G2_ADDFIELD_BAD_GDS   -6
 In g2_addfield() section 3 (GDS) not previously defined in message. More...
 
#define G2_ADDFIELD_BAD_GDT   -9
 In g2_addfield() GDT of one of 5.50 through 5.53 required when using DRT 5.51. More...
 
#define G2_ADDFIELD_BAD_PDT   -5
 In g2_addfield() could not find requested Product Definition Template. More...
 
#define G2_ADDFIELD_ERR   -10
 In g2_addfield() error packing data field. More...
 
#define G2_ADDGRID_BAD_GDT   -5
 In g2_addgrid() Could not find requested Grid Definition Template. More...
 
#define G2_BAD_SEC   -4
 Previous Section was unexpected. More...
 
#define G2_BAD_SEC_COUNTS   -3
 Sum of Section byte counts doesn't add to total byte count. More...
 
#define G2_CREATE_GRIB_VERSION   -1
 Wrong GRIB version for g2_create(), must be 2. More...
 
#define G2_GETFLD_BAD_END   7
 g2_getfld() didn't find "7777" at end of message. More...
 
#define G2_GETFLD_BAD_SEC1   15
 Error in g2_getfld() unpacking section 1. More...
 
#define G2_GETFLD_BAD_SEC2   16
 Error in g2_getfld() unpacking section 2. More...
 
#define G2_GETFLD_BAD_SEC3   10
 Error in g2_getfld() unpacking section 3. More...
 
#define G2_GETFLD_BAD_SEC4   11
 Error in g2_getfld() unpacking section 4. More...
 
#define G2_GETFLD_BAD_SEC5   12
 Error in g2_getfld() unpacking section 5. More...
 
#define G2_GETFLD_BAD_SEC6   13
 Error in g2_getfld() unpacking section 6. More...
 
#define G2_GETFLD_BAD_SEC7   14
 Error in g2_getfld() unpacking section 7. More...
 
#define G2_GETFLD_GRIB_VERSION   2
 Wrong GRIB version for g2_getfld(), must be 2. More...
 
#define G2_GETFLD_INVAL   3
 g2_getfld() data field request number was not positive. More...
 
#define G2_GETFLD_INVAL_SEC   8
 g2_getfld() encountered unrecognized section. More...
 
#define G2_GETFLD_NO_BITMAP   17
 In g2_getfld() previous bitmap specified, yet none exists. More...
 
#define G2_GETFLD_NO_DRT   9
 In g2_getfld(), Data Representation Template not implemented. More...
 
#define G2_GETFLD_NO_GRIB   1
 g2_getfld() can't find beginning characters "GRIB". More...
 
#define G2_GETFLD_WRONG_END   4
 g2_info() found "7777" not where expected. More...
 
#define G2_GETFLD_WRONG_NFLDS   6
 In g2_getfld() message did not contain the requested number of data fields. More...
 
#define G2_GRIBEND_MSG_INIT   -1
 In g2_gribend() GRIB message was not initialized - call g2_create() first. More...
 
#define G2_INFO_BAD_END   5
 g2_info() didn't find "7777" at end of message. More...
 
#define G2_INFO_GRIB_VERSION   2
 Wrong GRIB version for g2_info(), must be 2. More...
 
#define G2_INFO_INVAL_SEC   6
 g2_info() found invalid section number. More...
 
#define G2_INFO_NO_GRIB   1
 g2_info() can't find beginning characters "GRIB". More...
 
#define G2_INFO_NO_SEC1   3
 g2_info() can't find section 1. More...
 
#define G2_INFO_WRONG_END   4
 g2_info() found "7777" not where expected. More...
 
#define G2_JASPER_DECODE   -3
 In dec_jpeg2000() error decoding image with jasper. More...
 
#define G2_JASPER_DECODE_COLOR   -5
 In dec_jpeg2000() decoded image had multiple color components. More...
 
#define G2_JASPER_ENCODE   -3
 In enc_jpeg2000() error encoding image with jasper. More...
 
#define G2_JASPER_INIT   -2
 In enc_jpeg2000()/dec_jpeg2000() error initializing jasper library. More...
 
#define G2_JPCUNPACK_MEM   1
 In jpcunpack() or other unpack function: out of memory. More...
 
#define G2_JPEG2000_ENABLED   1
 Decoding/encoding JPEG2000 is enabled. More...
 
#define G2_NO_ERROR   0
 Function succeeded. More...
 
#define G2_PNG_ENABLED   1
 Decoding/encoding PNG is enabled. More...
 
#define G2_SPECUNPACK_TYPE   -3
 In specunpack() Can't handle 64 or 128 bit floats. More...
 
#define G2_UNPACK3_BAD_GDT   5
 In g2_unpack3(), undefined Grid Definition Template. More...
 
#define G2_UNPACK4_BAD_PDT   5
 In g2_unpack4(), undefined Product Definition Template. More...
 
#define G2_UNPACK5_BAD_DRT   7
 In g2_unpack5(), undefined Data Representation Template. More...
 
#define G2_UNPACK6_BAD_BITMAP   4
 In g2_unpack6(), unrecognized pre-defined bit-map. More...
 
#define G2_UNPACK7_BAD_DRT   4
 In g2_unpack7(), unrecognized Data Representation Template. More...
 
#define G2_UNPACK7_CORRUPT_SEC   7
 In g2_unpack7(), corrupt section 7. More...
 
#define G2_UNPACK7_WRONG_GDT   5
 In g2_unpack7(), need one of GDT 3.50 through 3.53 to decode DRT 5.51. More...
 
#define G2_UNPACK_BAD_SEC   2
 Bad section number in unpacking function. More...
 
#define G2_UNPACK_NO_MEM   6
 Error allocating memory in unpack function. More...
 
#define G2_VERSION   "1.7.0"
 Current version of NCEPLIBS-g2c library. More...
 
#define G2C_MSG_COMPLETE   -51
 GRIB message already complete. More...
 
#define G2C_NO_ERROR   0
 No error. More...
 
#define G2C_NOT_GRIB   -50
 GRIB header not found. More...
 

Typedefs

typedef float g2float
 Float type. More...
 
typedef int64_t g2int
 Long integer type. More...
 
typedef uint64_t g2intu
 Unsigned long integer type. More...
 
typedef struct gribfield gribfield
 Struct for GRIB field. More...
 

Functions

g2int g2_addfield (unsigned char *cgrib, g2int ipdsnum, g2int *ipdstmpl, float *coordlist, g2int numcoord, g2int idrsnum, g2int *idrstmpl, float *fld, g2int ngrdpts, g2int ibmap, g2int *bmap)
 This routine packs up Sections 4 through 7 for a given field and adds them to a GRIB2 message. More...
 
g2int g2_addgrid (unsigned char *cgrib, g2int *igds, g2int *igdstmpl, g2int *ideflist, g2int idefnum)
 This routine packs up a Grid Definition Section (Section 3) and adds it to a GRIB2 message. More...
 
g2int g2_addlocal (unsigned char *cgrib, unsigned char *csec2, g2int lcsec2)
 This routine adds a Local Use Section (Section 2) to a GRIB2 message. More...
 
g2int g2_create (unsigned char *cgrib, g2int *listsec0, g2int *listsec1)
 This routine initializes a new GRIB2 message and packs GRIB2 Section 0 (Indicator Section) and Section 1 (Identification Section). More...
 
void g2_free (gribfield *gfld)
 This routine frees up memory that was allocated for struct gribfield. More...
 
g2int g2_getfld (unsigned char *cgrib, g2int ifldnum, g2int unpack, g2int expand, gribfield **gfld)
 This subroutine returns all the metadata, template values, bit-map (if applicable), and the unpacked data for a given data field. More...
 
g2int g2_gribend (unsigned char *cgrib)
 This routine finalizes a GRIB2 message after all grids and fields have been added. More...
 
g2int g2_info (unsigned char *cgrib, g2int *listsec0, g2int *listsec1, g2int *numfields, g2int *numlocal)
 This subroutine searches through a GRIB2 message and returns the number of gridded fields found in the message and the number (and maximum size) of Local Use Sections. More...
 
g2int g2_unpack1 (unsigned char *cgrib, g2int *iofst, g2int **ids, g2int *idslen)
 This subroutine unpacks Section 1 - Identification Section as defined in GRIB Edition 2. More...
 
g2int g2_unpack2 (unsigned char *cgrib, g2int *iofst, g2int *lencsec2, unsigned char **csec2)
 This subroutine unpacks Section 2 (Local Use Section) as defined in GRIB Edition 2. More...
 
g2int g2_unpack3 (unsigned char *cgrib, g2int *iofst, g2int **igds, g2int **igdstmpl, g2int *mapgridlen, g2int **ideflist, g2int *idefnum)
 This routine unpacks Section 3 (Grid Definition Section) as defined in GRIB Edition 2. More...
 
g2int g2_unpack4 (unsigned char *cgrib, g2int *iofst, g2int *ipdsnum, g2int **ipdstmpl, g2int *mappdslen, float **coordlist, g2int *numcoord)
 This subroutine unpacks Section 4 (Product Definition Section) as defined in GRIB Edition 2. More...
 
g2int g2_unpack5 (unsigned char *cgrib, g2int *iofst, g2int *ndpts, g2int *idrsnum, g2int **idrstmpl, g2int *mapdrslen)
 This subroutine unpacks Section 5 (Data Representation Section) as defined in GRIB Edition 2. More...
 
g2int g2_unpack6 (unsigned char *cgrib, g2int *iofst, g2int ngpts, g2int *ibmap, g2int **bmap)
 This subroutine unpacks Section 6 (Bit-Map Section) as defined in GRIB Edition 2. More...
 
g2int g2_unpack7 (unsigned char *cgrib, g2int *iofst, g2int igdsnum, g2int *igdstmpl, g2int idrsnum, g2int *idrstmpl, g2int ndpts, float **fld)
 This subroutine unpacks Section 7 (Data Section) as defined in GRIB Edition 2. More...
 
int g2c_set_log_level (int new_level)
 Use this to set the global log level. More...
 
void jpcpack (float *fld, g2int width, g2int height, g2int *idrstmpl, unsigned char *cpack, g2int *lcpack)
 This subroutine packs up a data field into a JPEG2000 code stream. More...
 
void jpcpackd (double *fld, g2int width, g2int height, g2int *idrstmpl, unsigned char *cpack, g2int *lcpack)
 This subroutine packs up a data field into a JPEG2000 code stream. More...
 
g2int jpcunpack (unsigned char *cpack, g2int len, g2int *idrstmpl, g2int ndpts, float *fld)
 Unpack JPEG2000 compressed data into an array of floats, using info from the GRIB2 Data Representation Template 5.40 or 5.40000. More...
 
g2int jpcunpackd (unsigned char *cpack, g2int len, g2int *idrstmpl, g2int ndpts, double *fld)
 Unpack JPEG2000 compressed data into an array of doubles, using info from the GRIB2 Data Representation Template 5.40 or 5.40000. More...
 
void pngpack (float *fld, g2int width, g2int height, g2int *idrstmpl, unsigned char *cpack, g2int *lcpack)
 This subroutine packs up a float data field into PNG image format. More...
 
void pngpackd (double *fld, g2int width, g2int height, g2int *idrstmpl, unsigned char *cpack, g2int *lcpack)
 This subroutine packs up a double data field into PNG image format. More...
 
g2int pngunpack (unsigned char *cpack, g2int len, g2int *idrstmpl, g2int ndpts, float *fld)
 This subroutine unpacks a data field that was packed into a PNG image format using info from the GRIB2 Data Representation Template 5.41 or 5.40010. More...
 
g2int pngunpackd (unsigned char *cpack, g2int len, g2int *idrstmpl, g2int ndpts, double *fld)
 This subroutine unpacks a data field that was packed into a PNG image format using info from the GRIB2 Data Representation Template 5.41 or 5.40010. More...
 
void seekgb (FILE *lugb, g2int iseek, g2int mseek, g2int *lskip, g2int *lgrib)
 This subprogram searches a file for the next GRIB Message. More...
 

Detailed Description

Header file for NCEPLIBS-g2c library.

Program History Log

Date Programmer Comments
2002-10-25 Gilbert Initial
2009-01-14 Vuong Changed struct template to gtemplate
2021-11-9 Ed Hartnett Moved many prototypes to new internal header grib2_int.h.
2022-04-15 Ed Hartnett Added error codes related to JPEG.
2022-08-15 Ed Hartnett Added compression functions for double.
Author
Stephen Gilbert
Date
2002-10-25
Author
Ed Hartnett

Definition in file grib2.h.


Data Type Documentation

◆ gribfield

struct gribfield

Struct for GRIB field.

Definition at line 41 of file grib2.h.

Data Fields
g2int * bmap Integer array containing decoded bitmap, if ibmap=0 or ibap=254.

Otherwise NULL.

float * coord_list Array containing floating point values intended to document the vertical discretisation associated to model data on hybrid coordinate vertical levels (part of Section 4).
g2int discipline Message Discipline (see Table 0.0).
g2int expanded Logical value indicating whether the data field was expanded to the grid in the case where a bit-map is present.

If true, the data points in fld match the grid points and zeros were inserted at grid points where data was bit-mapped out. If false, the data values in ld were not expanded to the grid and are just a consecutive array of data points corresponding to each value of "1" in bmap.

float * fld Array of ndpts unpacked data points.
g2int griddef Source of grid definition (see Table 3.0).
  • 0 Specified in Table 3.1.
    • 1 Predetermined grid Defined by originating centre.
g2int ibmap Bitmap indicator (see Table 6.0).
  • 0 bitmap applies and is included in Section 6.
  • 1-253 = Predefined bitmap applies
  • 254 = Previously defined bitmap applies to this field
  • 255 = Bit map does not apply to this product.
g2int idrtlen Number of elements in idrtmpl.
g2int * idrtmpl Contains the data values for the Data Representation Template specified by idrtnum.
g2int idrtnum Data Representation Template Number (see Table 5.0).
g2int * idsect Contains the entries in the Identification Section (Section 1).
  • idsect[0] Identification of originating Centre (see Table 0). 7 is the identification for the US National Weather Service.
  • idsect[1] Identification of originating Sub-centre. (See Table C).
  • idsect[2] GRIB Master Tables Version Number (see Table 1.0).
    • 0 Experimental
    • 1 Initial operational version number
  • idsect[3] GRIB Local Tables Version Number (see Table 1.1).
    • 0 Local tables not used
    • 1-254 Number of local tables version used
  • idsect[4] Significance of Reference Time (See Table 1.2).
    • 0 Analysis
    • 1 Start of forecast
    • 2 Verifying time of forecast
    • 3 Observation time
  • idsect[5] Year (4 digits)
  • idsect[6] Month
  • idsect[7) Day
  • idsect[8] Hour
  • idsect[9] Minute
  • idsect[10] Second
  • idsect[11] Production status of processed data (see Table 1.3).
    • 0 Operational products
    • 1 Operational test products
    • 2 Research products
    • 3 Re-analysis products
  • idsect[12] Type of processed data (see Table 1.4).
    • 0 Analysis products
    • 1 Forecast products
    • 2 Analysis and forecast products
    • 3 Control forecast products
    • 4 Perturbed forecast products
    • 5 Control and perturbed forecast products
    • 6 Processed satellite observations
    • 7 Processed radar observations
g2int idsectlen Number of elements in idsect.
g2int ifldnum Field number within GRIB message.
g2int igdtlen Number of elements in igdtmpl - i.e.

number of entries in Grid Defintion Template.

g2int * igdtmpl Contains the data values for the Grid Definition Template specified by igdtnum.
g2int igdtnum Grid Definition Template Number (See Table 3.1).
g2int interp_opt Interpretation of list for optional points definition.

(See Table 3.11).

g2int ipdtlen Number of elements in ipdtmpl - i.e.

number of entries in Product Defintion Template.

g2int * ipdtmpl Contains the data values for the Product Definition Template specified by ipdtnum.
g2int ipdtnum Product Definition Template Number (see Table 4.0).
g2int * list_opt (Used if numoct_opt .ne.

0) This array contains the number of grid points contained in each row (or column) (part of Section 3). NULL if numoct_opt = 0.

unsigned char * local Pointer to character array containing contents of Local Section 2, if included.
g2int locallen Length of array local.
g2int ndpts Number of data points unpacked and returned.
g2int ngrdpts Number of grid points in the defined grid.
g2int num_coord Number of values in array coord_list.
g2int num_opt (Used if numoct_opt .ne.

0) The number of entries in array ideflist - i.e. number of rows (or columns) for which optional grid points are defined. This value is set to zero, if numoct_opt=0.

g2int numoct_opt Number of octets needed for each additional grid points definition.

Used to define number of points in each row (or column) for non-regular grids. = 0, if using regular grid.

g2int unpacked Logical value indicating whether the bitmap and data values were unpacked.

If false, bmap and fld pointers are NULL.

g2int version GRIB edition number (2).

Macro Definition Documentation

◆ G2_ADD_MSG_COMPLETE

#define G2_ADD_MSG_COMPLETE   -2

GRIB message already complete.

Cannot add new section.

Definition at line 311 of file grib2.h.

◆ G2_ADD_MSG_INIT

#define G2_ADD_MSG_INIT   -1

GRIB message was not initialized - call g2_create() first.

Definition at line 310 of file grib2.h.

◆ G2_ADDFIELD_BAD_BITMAP

#define G2_ADDFIELD_BAD_BITMAP   -8

In g2_addfield() no bitmap in the GRIB message.

Definition at line 316 of file grib2.h.

◆ G2_ADDFIELD_BAD_DRT

#define G2_ADDFIELD_BAD_DRT   -7

In g2_addfield() unsupported Data Representationi Template.

Definition at line 315 of file grib2.h.

◆ G2_ADDFIELD_BAD_GDS

#define G2_ADDFIELD_BAD_GDS   -6

In g2_addfield() section 3 (GDS) not previously defined in message.

Definition at line 314 of file grib2.h.

◆ G2_ADDFIELD_BAD_GDT

#define G2_ADDFIELD_BAD_GDT   -9

In g2_addfield() GDT of one of 5.50 through 5.53 required when using DRT 5.51.

Definition at line 317 of file grib2.h.

◆ G2_ADDFIELD_BAD_PDT

#define G2_ADDFIELD_BAD_PDT   -5

In g2_addfield() could not find requested Product Definition Template.

Definition at line 313 of file grib2.h.

◆ G2_ADDFIELD_ERR

#define G2_ADDFIELD_ERR   -10

In g2_addfield() error packing data field.

Definition at line 318 of file grib2.h.

◆ G2_ADDGRID_BAD_GDT

#define G2_ADDGRID_BAD_GDT   -5

In g2_addgrid() Could not find requested Grid Definition Template.

Definition at line 319 of file grib2.h.

◆ G2_BAD_SEC

#define G2_BAD_SEC   -4

Previous Section was unexpected.

Definition at line 300 of file grib2.h.

◆ G2_BAD_SEC_COUNTS

#define G2_BAD_SEC_COUNTS   -3

Sum of Section byte counts doesn't add to total byte count.

Definition at line 312 of file grib2.h.

◆ G2_CREATE_GRIB_VERSION

#define G2_CREATE_GRIB_VERSION   -1

Wrong GRIB version for g2_create(), must be 2.

Definition at line 276 of file grib2.h.

◆ G2_GETFLD_BAD_END

#define G2_GETFLD_BAD_END   7

g2_getfld() didn't find "7777" at end of message.

Definition at line 288 of file grib2.h.

◆ G2_GETFLD_BAD_SEC1

#define G2_GETFLD_BAD_SEC1   15

Error in g2_getfld() unpacking section 1.

Definition at line 291 of file grib2.h.

◆ G2_GETFLD_BAD_SEC2

#define G2_GETFLD_BAD_SEC2   16

Error in g2_getfld() unpacking section 2.

Definition at line 292 of file grib2.h.

◆ G2_GETFLD_BAD_SEC3

#define G2_GETFLD_BAD_SEC3   10

Error in g2_getfld() unpacking section 3.

Definition at line 293 of file grib2.h.

◆ G2_GETFLD_BAD_SEC4

#define G2_GETFLD_BAD_SEC4   11

Error in g2_getfld() unpacking section 4.

Definition at line 294 of file grib2.h.

◆ G2_GETFLD_BAD_SEC5

#define G2_GETFLD_BAD_SEC5   12

Error in g2_getfld() unpacking section 5.

Definition at line 295 of file grib2.h.

◆ G2_GETFLD_BAD_SEC6

#define G2_GETFLD_BAD_SEC6   13

Error in g2_getfld() unpacking section 6.

Definition at line 296 of file grib2.h.

◆ G2_GETFLD_BAD_SEC7

#define G2_GETFLD_BAD_SEC7   14

Error in g2_getfld() unpacking section 7.

Definition at line 297 of file grib2.h.

◆ G2_GETFLD_GRIB_VERSION

#define G2_GETFLD_GRIB_VERSION   2

Wrong GRIB version for g2_getfld(), must be 2.

Definition at line 284 of file grib2.h.

◆ G2_GETFLD_INVAL

#define G2_GETFLD_INVAL   3

g2_getfld() data field request number was not positive.

Definition at line 285 of file grib2.h.

◆ G2_GETFLD_INVAL_SEC

#define G2_GETFLD_INVAL_SEC   8

g2_getfld() encountered unrecognized section.

Definition at line 289 of file grib2.h.

◆ G2_GETFLD_NO_BITMAP

#define G2_GETFLD_NO_BITMAP   17

In g2_getfld() previous bitmap specified, yet none exists.

Definition at line 298 of file grib2.h.

◆ G2_GETFLD_NO_DRT

#define G2_GETFLD_NO_DRT   9

In g2_getfld(), Data Representation Template not implemented.

Definition at line 290 of file grib2.h.

◆ G2_GETFLD_NO_GRIB

#define G2_GETFLD_NO_GRIB   1

g2_getfld() can't find beginning characters "GRIB".

Definition at line 283 of file grib2.h.

◆ G2_GETFLD_WRONG_END

#define G2_GETFLD_WRONG_END   4

g2_info() found "7777" not where expected.

Definition at line 286 of file grib2.h.

◆ G2_GETFLD_WRONG_NFLDS

#define G2_GETFLD_WRONG_NFLDS   6

In g2_getfld() message did not contain the requested number of data fields.

Definition at line 287 of file grib2.h.

◆ G2_GRIBEND_MSG_INIT

#define G2_GRIBEND_MSG_INIT   -1

In g2_gribend() GRIB message was not initialized - call g2_create() first.

Definition at line 299 of file grib2.h.

◆ G2_INFO_BAD_END

#define G2_INFO_BAD_END   5

g2_info() didn't find "7777" at end of message.

Definition at line 281 of file grib2.h.

◆ G2_INFO_GRIB_VERSION

#define G2_INFO_GRIB_VERSION   2

Wrong GRIB version for g2_info(), must be 2.

Definition at line 278 of file grib2.h.

◆ G2_INFO_INVAL_SEC

#define G2_INFO_INVAL_SEC   6

g2_info() found invalid section number.

Definition at line 282 of file grib2.h.

◆ G2_INFO_NO_GRIB

#define G2_INFO_NO_GRIB   1

g2_info() can't find beginning characters "GRIB".

Definition at line 277 of file grib2.h.

◆ G2_INFO_NO_SEC1

#define G2_INFO_NO_SEC1   3

g2_info() can't find section 1.

Definition at line 279 of file grib2.h.

◆ G2_INFO_WRONG_END

#define G2_INFO_WRONG_END   4

g2_info() found "7777" not where expected.

Definition at line 280 of file grib2.h.

◆ G2_JASPER_DECODE

#define G2_JASPER_DECODE   -3

In dec_jpeg2000() error decoding image with jasper.

Definition at line 324 of file grib2.h.

◆ G2_JASPER_DECODE_COLOR

#define G2_JASPER_DECODE_COLOR   -5

In dec_jpeg2000() decoded image had multiple color components.

Definition at line 325 of file grib2.h.

◆ G2_JASPER_ENCODE

#define G2_JASPER_ENCODE   -3

In enc_jpeg2000() error encoding image with jasper.

Definition at line 323 of file grib2.h.

◆ G2_JASPER_INIT

#define G2_JASPER_INIT   -2

In enc_jpeg2000()/dec_jpeg2000() error initializing jasper library.

Definition at line 322 of file grib2.h.

◆ G2_JPCUNPACK_MEM

#define G2_JPCUNPACK_MEM   1

In jpcunpack() or other unpack function: out of memory.

Definition at line 320 of file grib2.h.

◆ G2_JPEG2000_ENABLED

#define G2_JPEG2000_ENABLED   1

Decoding/encoding JPEG2000 is enabled.

Definition at line 25 of file grib2.h.

◆ G2_NO_ERROR

#define G2_NO_ERROR   0

Function succeeded.

Definition at line 275 of file grib2.h.

◆ G2_PNG_ENABLED

#define G2_PNG_ENABLED   1

Decoding/encoding PNG is enabled.

Definition at line 24 of file grib2.h.

◆ G2_SPECUNPACK_TYPE

#define G2_SPECUNPACK_TYPE   -3

In specunpack() Can't handle 64 or 128 bit floats.

Definition at line 321 of file grib2.h.

◆ G2_UNPACK3_BAD_GDT

#define G2_UNPACK3_BAD_GDT   5

In g2_unpack3(), undefined Grid Definition Template.

Definition at line 303 of file grib2.h.

◆ G2_UNPACK4_BAD_PDT

#define G2_UNPACK4_BAD_PDT   5

In g2_unpack4(), undefined Product Definition Template.

Definition at line 304 of file grib2.h.

◆ G2_UNPACK5_BAD_DRT

#define G2_UNPACK5_BAD_DRT   7

In g2_unpack5(), undefined Data Representation Template.

Definition at line 305 of file grib2.h.

◆ G2_UNPACK6_BAD_BITMAP

#define G2_UNPACK6_BAD_BITMAP   4

In g2_unpack6(), unrecognized pre-defined bit-map.

Definition at line 306 of file grib2.h.

◆ G2_UNPACK7_BAD_DRT

#define G2_UNPACK7_BAD_DRT   4

In g2_unpack7(), unrecognized Data Representation Template.

Definition at line 309 of file grib2.h.

◆ G2_UNPACK7_CORRUPT_SEC

#define G2_UNPACK7_CORRUPT_SEC   7

In g2_unpack7(), corrupt section 7.

Definition at line 307 of file grib2.h.

◆ G2_UNPACK7_WRONG_GDT

#define G2_UNPACK7_WRONG_GDT   5

In g2_unpack7(), need one of GDT 3.50 through 3.53 to decode DRT 5.51.

Definition at line 308 of file grib2.h.

◆ G2_UNPACK_BAD_SEC

#define G2_UNPACK_BAD_SEC   2

Bad section number in unpacking function.

Definition at line 301 of file grib2.h.

◆ G2_UNPACK_NO_MEM

#define G2_UNPACK_NO_MEM   6

Error allocating memory in unpack function.

Definition at line 302 of file grib2.h.

◆ G2_VERSION

#define G2_VERSION   "1.7.0"

Current version of NCEPLIBS-g2c library.

Definition at line 22 of file grib2.h.

◆ G2C_MSG_COMPLETE

#define G2C_MSG_COMPLETE   -51

GRIB message already complete.

Definition at line 330 of file grib2.h.

◆ G2C_NO_ERROR

#define G2C_NO_ERROR   0

No error.

Definition at line 328 of file grib2.h.

◆ G2C_NOT_GRIB

#define G2C_NOT_GRIB   -50

GRIB header not found.

Definition at line 329 of file grib2.h.

Typedef Documentation

◆ g2float

typedef float g2float

Float type.

This typedef is provided for backward compatibility and is not used by the library any more. Use float in new code.

Definition at line 36 of file grib2.h.

◆ g2int

typedef int64_t g2int

Long integer type.

Definition at line 28 of file grib2.h.

◆ g2intu

typedef uint64_t g2intu

Unsigned long integer type.

This typedef is provided for backward compatibility and is not used by the library any more.

Definition at line 32 of file grib2.h.

◆ gribfield

typedef struct gribfield gribfield

Struct for GRIB field.

Definition at line 217 of file grib2.h.

Function Documentation

◆ g2_addfield()

g2int g2_addfield ( unsigned char *  cgrib,
g2int  ipdsnum,
g2int ipdstmpl,
float *  coordlist,
g2int  numcoord,
g2int  idrsnum,
g2int idrstmpl,
float *  fld,
g2int  ngrdpts,
g2int  ibmap,
g2int bmap 
)

This routine packs up Sections 4 through 7 for a given field and adds them to a GRIB2 message.

They are Product Definition Section, Data Representation Section, Bit-Map Section and Data Section, respectively.

This routine is used with routines g2_create(), g2_addlocal(), g2_addgrid(), and g2_gribend() to create a complete GRIB2 message. Function g2_create() must be called first to initialize a new GRIB2 message. Function g2_addgrid() must be called after g2_create() and before this routine to add the appropriate grid description to the GRIB2 message. A call to g2_gribend() is required to complete GRIB2 message after all fields have been added.

Program History Log

Date Programmer Comments
2002-11-05 Gilbert Initial
2002-12-23 Gilbert Added complex spherical harmonic packing
2003-08-27 Gilbert Added support for new templates using PNG and JPEG2000 algorithms/templates.
2004-11-29 Gilbert JPEG2000 now can use WMO Template 5.40 PNG can use WMO Template 5.41. Added packing algorithm check.
2005-05-10 Gilbert Imposed minimum size on cpack.
2009-01-14 Vuong Changed structure name template to gtemplate
Parameters
cgribChar array that contains the GRIB2 message to which sections 4 through 7 should be added. Must be allocated large enough to store the entire GRIB2 message.
ipdsnumProduct Definition Template Number (see Code Table 4.0).
ipdstmplContains the data values for the Product Definition Template specified by ipdsnum.
coordlistArray containg floating point values intended to document the vertical discretisation associated to model data on hybrid coordinate vertical levels.
numcoordnumber of values in array coordlist.
idrsnumData Representation Template Number (see Code Table 5.0).
idrstmplThe data values for the Data Representation Template specified by idrsnum. Note that some values in this template (eg. reference values, number of bits, etc...) may be changed by the data packing algorithms. Use this to specify scaling factors and order of spatial differencing, if desired.
fldArray of data points to pack.
ngrdptsNumber of data points in grid. i.e. size of fld and bmap.
ibmapBitmap indicator (see Code Table 6.0)
  • 0 = bitmap applies and is included in Section 6.
  • 1-253 = Predefined bitmap applies.
  • 254 = Previously defined bitmap applies to this field.
  • 255 = Bit map does not apply to this product.
bmapInteger array containing bitmap to be added (if ibmap = 0).
Returns
Note
Note that the Sections 4 through 7 can only follow Section 3 or Section 7 in a GRIB2 message.
Author
Stephen Gilbert
Date
2002-11-05

Definition at line 98 of file g2_addfield.c.

References cmplxpack(), gtemplate::ext, gtemplate::extlen, extpdstemplate(), G2_ADD_MSG_COMPLETE, G2_ADD_MSG_INIT, G2_ADDFIELD_BAD_BITMAP, G2_ADDFIELD_BAD_DRT, G2_ADDFIELD_BAD_GDS, G2_ADDFIELD_BAD_GDT, G2_ADDFIELD_BAD_PDT, G2_ADDFIELD_ERR, G2_BAD_SEC, G2_BAD_SEC_COUNTS, g2c_check_msg(), G2C_MSG_COMPLETE, G2C_NOT_GRIB, gbit(), getdim(), getdrstemplate(), getpdstemplate(), getpoly(), jpcpack(), gtemplate::map, gtemplate::maplen, mkieee(), gtemplate::needext, pngpack(), sbit(), sbits(), simpack(), and specpack().

◆ g2_addgrid()

g2int g2_addgrid ( unsigned char *  cgrib,
g2int igds,
g2int igdstmpl,
g2int ideflist,
g2int  idefnum 
)

This routine packs up a Grid Definition Section (Section 3) and adds it to a GRIB2 message.

It is used with routines g2_create(), g2_addlocal(), g2_addfield(), and g2_gribend() to create a complete GRIB2 message. g2_create() must be called first to initialize a new GRIB2 message.

Program History Log

Date Programmer Comments
2002-11-01 Gilbert Initial.
2009-01-14 Vuong Changed structure name template to gtemplate
Parameters
cgribChar array that contains the GRIB2 message to which section should be added. Must be allocated large enough to store the entire GRIB2 message.
igdsContains information needed for GRIB Grid Definition Section 3. Must be dimensioned >= 5.
  • igds[0] Source of grid definition (see Code Table 3.0).
  • igds[1] Number of grid points in the defined grid.
  • igds[2] Number of octets needed for each additional grid points definition. Used to define number of points in each row (or column) for non-regular grids. = 0, if using regular grid.
  • igds[3] Interpretation of list for optional points definition. (See Code Table 3.11).
  • igds[4] Grid Definition Template Number (See Code Table 3.1).
igdstmplContains the data values for the specified Grid Definition Template (igds[4]). Each element of this integer array contains an entry (in the order specified) of Grid Defintion Template.
ideflist(Used if igds[2] != 0) This array contains the number of grid points contained in each row (or column).
idefnum(Used if igds[2] != 0) The number of entries in array ideflist. i.e. number of rows (or columns) for which optional grid points are defined.
Returns
  • > 0 Current size of updated GRIB2 message
  • G2_ADD_MSG_INIT GRIB message was not initialized. Need to call routine gribcreate first.
  • G2_ADD_MSG_COMPLETE GRIB message already complete. Cannot add new section.
  • G2_BAD_SEC_COUNTS Sum of Section byte counts doesn't add to total byte count
  • G2_BAD_SEC Previous Section was not 1, 2 or 7.
  • G2_ADDGRID_BAD_GDT Could not find requested Grid Definition Template.
Note
The Grid Def Section (Section 3) can only follow Section 1, 2 or Section 7 in a GRIB2 message.
Author
Stephen Gilbeert
Date
2002-11-01

Definition at line 70 of file g2_addgrid.c.

References gtemplate::ext, extgridtemplate(), gtemplate::extlen, G2_ADD_MSG_COMPLETE, G2_ADD_MSG_INIT, G2_ADDGRID_BAD_GDT, G2_BAD_SEC, G2_BAD_SEC_COUNTS, g2c_check_msg(), G2C_MSG_COMPLETE, G2C_NOT_GRIB, gbit(), getgridtemplate(), gtemplate::map, gtemplate::maplen, gtemplate::needext, sbit(), and sbits().

◆ g2_addlocal()

g2int g2_addlocal ( unsigned char *  cgrib,
unsigned char *  csec2,
g2int  lcsec2 
)

This routine adds a Local Use Section (Section 2) to a GRIB2 message.

It is used with routines g2_create(), g2_addgrid(), g2_addfield(), and g2_gribend() to create a complete GRIB2 message.

Parameters
cgribChar array that contains the GRIB2 message to which section 2 should be added. Must be allocated large enough to store the entire GRIB2 message.
csec2Character array containing information to be added in Section 2.
lcsec2Number of bytes of character array csec2 to be added to Section 2.
Returns
> 0 = Current size of updated GRIB2 message.
Note
The Local Use Section (Section 2) can only follow Section 1 or Section 7 in a GRIB2 message.
Author
Stephen Gilbeert
Date
2002-11-01

Definition at line 40 of file g2_addlocal.c.

References G2_ADD_MSG_COMPLETE, G2_ADD_MSG_INIT, G2_BAD_SEC, G2_BAD_SEC_COUNTS, g2c_check_msg(), G2C_MSG_COMPLETE, G2C_NOT_GRIB, gbit(), and sbit().

◆ g2_create()

g2int g2_create ( unsigned char *  cgrib,
g2int listsec0,
g2int listsec1 
)

This routine initializes a new GRIB2 message and packs GRIB2 Section 0 (Indicator Section) and Section 1 (Identification Section).

This routine is used with routines g2_addlocal(), g2_addgrid(), g2_addfield(), and g2_gribend() to create a complete GRIB2 message. g2_create() must be called first to initialize a new GRIB2 message. A call to g2_gribend() is required to complete GRIB2 message after all fields have been added.

Parameters
[in]cgribCharacter array to contain the GRIB2 message. Must be allocated large enough to store the entire GRIB2 message.
[in]listsec0Contains information needed for GRIB Indicator Section 0. Must be dimensioned >= 2.
  • listsec0[0] Discipline-GRIB Master Table Number (Code Table 0.0).
  • listsec0[1] GRIB Edition Number (currently 2).
[in]listsec1Contains information needed for GRIB Identification Section 1. Must be dimensioned >= 13.
  • listsec1[0] Id of orginating centre (Table 0).
  • listsec1[1] Id of orginating sub-centre (Table C).
  • listsec1[2] GRIB Master Tables Version Number (Table 1.0).
  • listsec1[3] GRIB Local Tables Version Number (Table 1.1).
  • listsec1[4] Significance of Reference Time (Table 1.2)
  • listsec1[5] Reference Time - Year (4 digits)
  • listsec1[6] Reference Time - Month
  • listsec1[7] Reference Time - Day
  • listsec1[8] Reference Time - Hour
  • listsec1[9] Reference Time - Minute
  • listsec1[10] Reference Time - Second
  • listsec1[11] Production status of data (Table 1.3).
  • listsec1[12] Type of processed data (Table 1.4).
Returns
  • > 0 Current size of new GRIB2 message
  • G2_CREATE_GRIB_VERSION Tried to use for version other than GRIB Edition 2

This routine is intended for use with routines g2_addlocal(), g2_addgrid(), g2_addfield(), and g2_gribend() to create a complete GRIB2 message.

Author
Stephen Gilbeert
Date
2002-10-31

Definition at line 68 of file g2_create.c.

References G2_CREATE_GRIB_VERSION, LENSEC0, MAPSEC1LEN, and sbit().

◆ g2_free()

void g2_free ( gribfield gfld)

This routine frees up memory that was allocated for struct gribfield.

Parameters
gfldpointer to gribfield structure (defined in include file grib2.h) returned from routine g2_getfld().
Note
This routine must be called to free up memory used by the decode routine, g2_getfld(), when user no longer needs to reference this data.
Author
Stephen Gilbeert
Date
2002-10-28

Definition at line 24 of file g2_free.c.

References gribfield::bmap, gribfield::coord_list, gribfield::fld, gribfield::idrtmpl, gribfield::idsect, gribfield::igdtmpl, gribfield::ipdtmpl, gribfield::list_opt, and gribfield::local.

Referenced by g2_getfld().

◆ g2_getfld()

g2int g2_getfld ( unsigned char *  cgrib,
g2int  ifldnum,
g2int  unpack,
g2int  expand,
gribfield **  gfld 
)

This subroutine returns all the metadata, template values, bit-map (if applicable), and the unpacked data for a given data field.

All of the information returned is stored in a gribfield structure, which is defined in file grib2.h. Users of this routine will need to include grib2.h in their source code that calls this routine.

Since there can be multiple data fields packed into a GRIB2 message, the calling routine indicates which field is being requested with the ifldnum argument.

Program History Log

Date Programmer Comments
2002-10-28 Gilbert Initial
2013-08-08 Vuong Free up memory in array igds - free(igds)
Parameters
cgribCharacter pointer to the GRIB2 message.
ifldnumSpecifies which field in the GRIB2 message to return. The first field is number 1, Fortran style.
unpackBoolean value indicating whether to unpack bitmap/data field.
  • 1 unpack bitmap (if present) and data values.
  • 0 do not unpack bitmap and data values.
expandBoolean value indicating whether the data points should be expanded to the correspond grid, if a bit-map is present. This argument is ignored if unpack == 0 OR if the returned field does not contain a bit-map.
  • 1 if possible, expand data field to grid, inserting zero values at gridpoints that are bitmapped out. (SEE REMARKS2)
  • 0 do not expand data field, leaving it an array of consecutive data points for each "1" in the bitmap.
gfldpointer to structure gribfield containing all decoded data for the data field.
Returns
Note
Struct gribfield is allocated by this routine and it also contains pointers to many arrays of data that were allocated during decoding. Users are encouraged to free up this memory, when it is no longer needed, by an explicit call to routine g2_free().

Example:

#include "grib2.h"
gribfield *gfld;
ret=g2_getfld(cgrib,1,1,1,&gfld);
...
g2_free(gfld);

Routine g2_info() can be used to first determine how many data fields exist in a given GRIB message.

Note
It may not always be possible to expand a bit-mapped data field. If a pre-defined bit-map is used and not included in the GRIB2 message itself, this routine would not have the necessary information to expand the data. In this case, gfld->expanded would would be set to 0 (false), regardless of the value of input argument expand.
Author
Stephen Gilbert
Date
2002-10-28

Definition at line 91 of file g2_getfld.c.

References gribfield::bmap, gribfield::coord_list, gribfield::discipline, gribfield::expanded, gribfield::fld, g2_free(), G2_GETFLD_BAD_END, G2_GETFLD_BAD_SEC1, G2_GETFLD_BAD_SEC2, G2_GETFLD_BAD_SEC3, G2_GETFLD_BAD_SEC4, G2_GETFLD_BAD_SEC5, G2_GETFLD_BAD_SEC6, G2_GETFLD_BAD_SEC7, G2_GETFLD_GRIB_VERSION, G2_GETFLD_INVAL, G2_GETFLD_INVAL_SEC, G2_GETFLD_NO_BITMAP, G2_GETFLD_NO_GRIB, G2_GETFLD_WRONG_END, G2_GETFLD_WRONG_NFLDS, G2_NO_ERROR, g2_unpack1(), g2_unpack2(), g2_unpack3(), g2_unpack4(), g2_unpack5(), g2_unpack6(), g2_unpack7(), gbit(), gribfield::griddef, gribfield::ibmap, gribfield::idrtlen, gribfield::idrtmpl, gribfield::idrtnum, gribfield::idsect, gribfield::idsectlen, gribfield::ifldnum, gribfield::igdtlen, gribfield::igdtmpl, gribfield::igdtnum, gribfield::interp_opt, gribfield::ipdtlen, gribfield::ipdtmpl, gribfield::ipdtnum, gribfield::list_opt, gribfield::local, gribfield::locallen, gribfield::ndpts, gribfield::ngrdpts, gribfield::num_coord, gribfield::num_opt, gribfield::numoct_opt, gribfield::unpacked, and gribfield::version.

◆ g2_gribend()

g2int g2_gribend ( unsigned char *  cgrib)

This routine finalizes a GRIB2 message after all grids and fields have been added.

It adds the End Section ("7777") to the end of the GRIB message and calculates the length and stores it in the appropriate place in Section 0. This routine is used with routines g2_create(), g2_addlocal(), g2_addgrid(), and g2_addfield() to create a complete GRIB2 message.

Parameters
cgribChar array containing all the data sections added be previous calls to g2_create(), g2_addlocal(), g2_addgrid(), and g2_addfield(). After function is called, contains the finalized GRIB2 message.
Returns
Note
This routine is intended for use with routines g2_create(), g2_addlocal(), g2_addgrid(), and g2_addfield() to create a complete GRIB2 message.
Author
Stephen Gilbert
Date
2002-10-31

Definition at line 37 of file g2_gribend.c.

References G2_ADD_MSG_COMPLETE, G2_ADD_MSG_INIT, G2_BAD_SEC, G2_BAD_SEC_COUNTS, g2c_check_msg(), G2C_MSG_COMPLETE, G2C_NOT_GRIB, gbit(), and sbit().

◆ g2_info()

g2int g2_info ( unsigned char *  cgrib,
g2int listsec0,
g2int listsec1,
g2int numfields,
g2int numlocal 
)

This subroutine searches through a GRIB2 message and returns the number of gridded fields found in the message and the number (and maximum size) of Local Use Sections.

Also various checks are performed to see if the message is a valid GRIB2 message.

Parameters
cgribCharacter pointer to the GRIB2 message.
listsec0pointer to an array containing information decoded from GRIB Indicator Section 0. Must be allocated with >= 3 elements.
  • listsec0(0) Discipline-GRIB Master Table Number (Code Table 0.0).
  • listsec0[1] GRIB Edition Number (currently 2).
  • listsec0[2] Length of GRIB message.
listsec1Pointer to an array containing information read from GRIB Identification Section 1. Must be allocated with >= 13 elements.
  • listsec1[0] Id of orginating centre (Table 0).
  • listsec1[1] Id of orginating sub-centre (Table C).
  • listsec1[2] GRIB Master Tables Version Number (Table 1.0).
  • listsec1[3] GRIB Local Tables Version Number (Table 1.1).
  • listsec1[4] Significance of Reference Time (Table 1.2)
  • listsec1[5] Reference Time - Year (4 digits)
  • listsec1[6] Reference Time - Month
  • listsec1[7] Reference Time - Day
  • listsec1[8] Reference Time - Hour
  • listsec1[9] Reference Time - Minute
  • listsec1[10] Reference Time - Second
  • listsec1[11] Production status of data (Table 1.3).
  • listsec1[12] Type of processed data (Table 1.4).
numfieldsThe number of gridded fields found in the GRIB message. That is, the number of occurences of Sections 4 - 7.
numlocalThe number of Local Use Sections ( Section 2 ) found in the GRIB message.
Returns
0 foe success, otherwise:
Author
Stephen Gilbeert
Date
2002-10-28

Definition at line 67 of file g2_info.c.

References G2_INFO_BAD_END, G2_INFO_GRIB_VERSION, G2_INFO_INVAL_SEC, G2_INFO_NO_GRIB, G2_INFO_NO_SEC1, G2_INFO_WRONG_END, and gbit().

◆ g2_unpack1()

g2int g2_unpack1 ( unsigned char *  cgrib,
g2int iofst,
g2int **  ids,
g2int idslen 
)

This subroutine unpacks Section 1 - Identification Section as defined in GRIB Edition 2.

Parameters
cgribchar array containing Section 1 of the GRIB2 message.
iofstBit offset for the beginning of Section 1 in cgrib.
idsPointer that gets an array which contians the information read from Section 1, the Identification section. This array is allocated by this function, and must be freed by caller (using g2_free()).
  • ids[0] Identification of originating Centre (see Table 0).
  • ids[1] Identification of originating Sub-centre (see Table C).
  • ids[2] GRIB Master Tables Version Number (see Table 1.0).
  • ids[3] GRIB Local Tables Version Number (see Table 1.1).
  • ids[4] Significance of Reference Time (see Table 1.2).
  • ids[5] Year (4 digits)
  • ids[6] Month
  • ids[7] Day
  • ids[8] Hour
  • ids[9] Minute
  • ids[10] Second
  • ids[11] Production status of processed data (see Table 1.3).
  • ids[12] Type of processed data (see Table 1.4).
idslenNumber of elements in ids.
Returns
Author
Stephen Gilbert
Date
2002-10-29

Definition at line 55 of file g2_unpack1.c.

References G2_NO_ERROR, G2_UNPACK_BAD_SEC, G2_UNPACK_NO_MEM, and gbit().

Referenced by g2_getfld().

◆ g2_unpack2()

g2int g2_unpack2 ( unsigned char *  cgrib,
g2int iofst,
g2int lencsec2,
unsigned char **  csec2 
)

This subroutine unpacks Section 2 (Local Use Section) as defined in GRIB Edition 2.

Program History Log

Date Programmer Comments
2002-10-31 Gilbert Initial
2008-12-23 Wesley Initialize lencsec2 Length of Local Use data
2010-08-05 Vuong If section 2 has zero length, ierr=0
Parameters
cgribchar array containing Section 2 of the GRIB2 message.
iofstPointer that contains the bit offset for the beginning of Section 2 in cgrib. The modified version will be returned.
lencsec2Length (in octets) of Local Use data.
csec2Pointer to a pointer that will get an allocated array containing local use data. This memory must be freed by the caller.
Returns
Author
Stephen Gilbert
Date
2002-10-31

Definition at line 38 of file g2_unpack2.c.

References G2_NO_ERROR, G2_UNPACK_BAD_SEC, G2_UNPACK_NO_MEM, and gbit().

Referenced by g2_getfld().

◆ g2_unpack3()

g2int g2_unpack3 ( unsigned char *  cgrib,
g2int iofst,
g2int **  igds,
g2int **  igdstmpl,
g2int mapgridlen,
g2int **  ideflist,
g2int idefnum 
)

This routine unpacks Section 3 (Grid Definition Section) as defined in GRIB Edition 2.

Program History Log

Date Programmer Comments
2002-10-31 Gilbert Initial
2009-01-14 Vuong Changed structure name template to gtemplate
Parameters
cgribChar array ontaining Section 3 of the GRIB2 message.
iofstBit offset for the beginning of Section 3 in cgrib.
igdsContains information read from the appropriate GRIB Grid Definition Section 3 for the field being returned.
  • igds[0] Source of grid definition (see Table 3.0).
  • igds[1] Number of grid points in the defined grid.
  • igds[2] Number of octets needed for each additional grid points definition. Used to define number of points in each row (or column) for non-regular grids. = 0, if using regular grid.
  • igds[3] Interpretation of list for optional points definition. (See Table 3.11)
  • igds[4] Grid Definition Template Number (see Table 3.1).
igdstmplPointer to integer array containing the data values for the Grid Definition Template specified by igds[4].
mapgridlenNumber of elements in igdstmpl. i.e. number of entries in Grid Defintion Template specified by igds[4].
ideflist(Used if igds[2] .ne. 0) Pointer to integer array containing the number of grid points contained in each row (or column).
idefnum(Used if igds[2] .ne. 0) The number of entries in array ideflist - i.e. number of rows (or columns) for which optional grid points are defined.
Returns
Author
Stephen Gilbert
Date
2002-10-31

Definition at line 57 of file g2_unpack3.c.

References gtemplate::ext, extgridtemplate(), gtemplate::extlen, G2_NO_ERROR, G2_UNPACK3_BAD_GDT, G2_UNPACK_BAD_SEC, G2_UNPACK_NO_MEM, gbit(), gbits(), getgridtemplate(), gtemplate::map, gtemplate::maplen, and gtemplate::needext.

Referenced by g2_getfld(), getdim(), and getpoly().

◆ g2_unpack4()

g2int g2_unpack4 ( unsigned char *  cgrib,
g2int iofst,
g2int ipdsnum,
g2int **  ipdstmpl,
g2int mappdslen,
float **  coordlist,
g2int numcoord 
)

This subroutine unpacks Section 4 (Product Definition Section) as defined in GRIB Edition 2.

Program History Log

Date Programmer Comments
2002-10-31 Gilbert Initial
2009-01-14 Vuong Changed structure name template to gtemplate
Parameters
cgribArray containing Section 4 of the GRIB2 message.
iofstBit offset of the beginning of Section 4 in cgrib. Returned with updated bit offset.
ipdsnumProduct Definition Template Number (see Table 4.0).
ipdstmplPointer that gets an integer array containing the data values for the Product Definition Template specified by ipdsnum.
mappdslenNumber of elements in ipdstmpl - i.e. number of entries in Product Defintion Template specified by ipdsnum.
coordlistPointer that gets an array containing floating point values intended to document the vertical discretisation associated to model data on hybrid coordinate vertical levels.
numcoordnumber of values in array coordlist.
Returns
Author
Stephen Gilbert
Date
2002-10-31

Definition at line 46 of file g2_unpack4.c.

References gtemplate::ext, gtemplate::extlen, extpdstemplate(), G2_NO_ERROR, G2_UNPACK4_BAD_PDT, G2_UNPACK_BAD_SEC, G2_UNPACK_NO_MEM, gbit(), gbits(), getpdstemplate(), gtemplate::map, gtemplate::maplen, gtemplate::needext, and rdieee().

Referenced by g2_getfld().

◆ g2_unpack5()

g2int g2_unpack5 ( unsigned char *  cgrib,
g2int iofst,
g2int ndpts,
g2int idrsnum,
g2int **  idrstmpl,
g2int mapdrslen 
)

This subroutine unpacks Section 5 (Data Representation Section) as defined in GRIB Edition 2.

Program History Log

Date Programmer Comments
2002-10-31 Gilbert Initial
2009-01-14 Vuong Changed structure name template to gtemplate
Parameters
cgribchar array containing Section 5 of the GRIB2 message.
iofstBit offset for the beginning of Section 5 in cgrib. Returned with bit offset at the end of Section 5.
ndptsNumber of data points unpacked and returned.
idrsnumData Representation Template Number (see Code Table 5.0).
idrstmplPointer to an integer array containing the data values for the specified Data Representation Template (N=idrsnum). Each element of this integer array contains an entry (in the order specified) of Data Representation Template 5.N.
mapdrslen-Number of elements in idrstmpl. i.e. number of entries in Data Representation Template 5.N (N=idrsnum).
Returns
Author
Stephen Gilbert
Date
2002-10-31

Definition at line 42 of file g2_unpack5.c.

References gtemplate::ext, extdrstemplate(), gtemplate::extlen, G2_NO_ERROR, G2_UNPACK5_BAD_DRT, G2_UNPACK_BAD_SEC, G2_UNPACK_NO_MEM, gbit(), getdrstemplate(), gtemplate::map, gtemplate::maplen, and gtemplate::needext.

Referenced by g2_getfld().

◆ g2_unpack6()

g2int g2_unpack6 ( unsigned char *  cgrib,
g2int iofst,
g2int  ngpts,
g2int ibmap,
g2int **  bmap 
)

This subroutine unpacks Section 6 (Bit-Map Section) as defined in GRIB Edition 2.

Parameters
cgribchar array containing Section 6 of the GRIB2 message.
iofstBit offset of the beginning of Section 6 in cgrib.
ngptsNumber of grid points specified in the bit-map
ibmapBitmap indicator (see Code Table 6.0)
  • 0 bitmap applies and is included in Section 6.
  • 1-253 Predefined bitmap applies
  • 254 Previously defined bitmap applies to this field
  • 255 Bit map does not apply to this product.
bmapPointer to an integer array containing decoded bitmap. (if ibmap=0)
Returns
Author
Stephen Gilbert
Date
2002-10-31

Definition at line 33 of file g2_unpack6.c.

References G2_NO_ERROR, G2_UNPACK_BAD_SEC, G2_UNPACK_NO_MEM, gbit(), and gbits().

Referenced by g2_getfld().

◆ g2_unpack7()

g2int g2_unpack7 ( unsigned char *  cgrib,
g2int iofst,
g2int  igdsnum,
g2int igdstmpl,
g2int  idrsnum,
g2int idrstmpl,
g2int  ndpts,
float **  fld 
)

This subroutine unpacks Section 7 (Data Section) as defined in GRIB Edition 2.

Program History Log

Date Programmer Comments
2002-10-31 Gilbert Initial
2002-12-20 Gilbert Added GDT info to arguments and added 5.51 processing.
2003-08-29 Gilbert New templates using PNG and JPEG2000 algorithms/templates.
2004-11-29 Gilbert JPEG2000 now allowed to use WMO Template 5.40 PNG allowed to use 5.41
2004-12-16 Taylor Added check on comunpack return code.
2008-12-23 Wesley Initialize Number of data points unpacked
Parameters
cgribchar array containing Section 7 of the GRIB2 message
iofstBit offset of the beginning of Section 7 in cgrib.
igdsnumGrid Definition Template Number (see Code Table 3.0) (Only used for DRS Template 5.51)
igdstmplPointer to an integer array containing the data values for the specified Grid Definition Template (N=igdsnum). Each element of this integer array contains an entry (in the order specified) of Grid Definition Template 3.N. (Only used for DRS Template 5.51).
idrsnumData Representation Template Number (see Code Table 5.0)
idrstmplPointer to an integer array containing the data values for the specified Data Representation Template (N=idrsnum). Each element of this integer array contains an entry (in the order specified) of Data Representation Template 5.N
ndptsNumber of data points unpacked and returned.
fldPointer to a float array containing the unpacked data field.
Returns
Author
Stephen Gilbert
Date
2002-10-31

Definition at line 55 of file g2_unpack7.c.

References comunpack(), G2_NO_ERROR, G2_UNPACK7_BAD_DRT, G2_UNPACK7_CORRUPT_SEC, G2_UNPACK7_WRONG_GDT, G2_UNPACK_BAD_SEC, G2_UNPACK_NO_MEM, gbit(), jpcunpack(), pngunpack(), rdieee(), simunpack(), and specunpack().

Referenced by g2_getfld().

◆ g2c_set_log_level()

int g2c_set_log_level ( int  new_level)

Use this to set the global log level.

Set it to -1 to turn off all logging. Set it to 0 to show only errors, and to higher numbers to show more and more logging details. If logging is not enabled when building NCEPLIBS-g2c, this function will do nothing.

Parameters
new_levelThe new logging level.
Returns
G2_NO_ERROR No error.
Author
Ed Hartnett

Definition at line 124 of file util.c.

References G2C_NO_ERROR, and LOG.

◆ jpcpack()

void jpcpack ( float *  fld,
g2int  width,
g2int  height,
g2int idrstmpl,
unsigned char *  cpack,
g2int lcpack 
)

This subroutine packs up a data field into a JPEG2000 code stream.

After the data field is scaled, and the reference value is subtracted out, it is treated as a grayscale image and passed to a JPEG2000 encoder. It also fills in GRIB2 Data Representation Template 5.40 or 5.40000 with the appropriate values.

Parameters
fldPointer to the float or double data values to pack.
widthThe number of points in the x direction.
heightThe number of points in the y direction.
idrstmplContains the array of values for Data Representation Template Table 5.40 or 5.40000.
  • 0 Reference value - ignored on input, set by jpcpack routine.
  • 1 Binary Scale Factor - used on input, unchanged by jpcpack routine.
  • 2 Decimal Scale Factor - used on input, unchanged by jpcpack routine.
  • 3 number of bits for each data value - ignored on input
  • 4 Original field type - currently ignored on input Data values assumed to be reals. Set to 0 on output.
  • 5 if 0 use lossless compression, if 1 use lossy compression.
  • 6 Desired compression ratio, if idrstmpl[5]=1. Set to 255, if idrstmpl[5]=0.
cpackA pointer that will get the packed data field. Must be allocated before this function is called. Pass the allocated size in the lcpack parameter.
lcpackPointer that gets the length of packed field in cpack. This must be set by the calling function to the size available in cpack.
Author
Stephen Gilbert, Ed Hartnett

Definition at line 253 of file jpcpack.c.

References jpcpack_int().

◆ jpcpackd()

void jpcpackd ( double *  fld,
g2int  width,
g2int  height,
g2int idrstmpl,
unsigned char *  cpack,
g2int lcpack 
)

This subroutine packs up a data field into a JPEG2000 code stream.

After the data field is scaled, and the reference value is subtracted out, it is treated as a grayscale image and passed to a JPEG2000 encoder. It also fills in GRIB2 Data Representation Template 5.40 or 5.40000 with the appropriate values.

Parameters
fldPointer to the float or double data values to pack.
widthThe number of points in the x direction.
heightThe number of points in the y direction.
idrstmplContains the array of values for Data Representation Template Table 5.40 or 5.40000.
  • 0 Reference value - ignored on input, set by jpcpack routine.
  • 1 Binary Scale Factor - used on input, unchanged by jpcpack routine.
  • 2 Decimal Scale Factor - used on input, unchanged by jpcpack routine.
  • 3 number of bits for each data value - ignored on input
  • 4 Original field type - currently ignored on input Data values assumed to be reals. Set to 0 on output.
  • 5 if 0 use lossless compression, if 1 use lossy compression.
  • 6 Desired compression ratio, if idrstmpl[5]=1. Set to 255, if idrstmpl[5]=0.
cpackA pointer that will get the packed data field. Must be allocated before this function is called. Pass the allocated size in the lcpack parameter.
lcpackPointer that gets the length of packed field in cpack. This must be set by the calling function to the size available in cpack.
Author
Ed Hartnett

Definition at line 294 of file jpcpack.c.

References jpcpack_int().

◆ jpcunpack()

g2int jpcunpack ( unsigned char *  cpack,
g2int  len,
g2int idrstmpl,
g2int  ndpts,
float *  fld 
)

Unpack JPEG2000 compressed data into an array of floats, using info from the GRIB2 Data Representation Template 5.40 or 5.40000.

Parameters
cpackThe packed data.
lenThe length of the packed data.
idrstmplPointer to array of values for Data Representation Template 5.40 or 5.40000.
ndptsThe number of data values to unpack.
fldA pointer that gets the unpacked data values as an array of float.
Returns
0 for success, 1 for memory allocation error.
Author
Stephem Gilbert
Date
2003-08-27
Author
Ed Hartnett

Definition at line 108 of file jpcunpack.c.

References jpcunpack_int().

◆ jpcunpackd()

g2int jpcunpackd ( unsigned char *  cpack,
g2int  len,
g2int idrstmpl,
g2int  ndpts,
double *  fld 
)

Unpack JPEG2000 compressed data into an array of doubles, using info from the GRIB2 Data Representation Template 5.40 or 5.40000.

Parameters
cpackThe packed data.
lenThe length of the packed data.
idrstmplPointer to array of values for Data Representation Template 5.40 or 5.40000.
ndptsThe number of data values to unpack.
fldA pointer that gets the unpacked data values as an array of double.
Returns
0 for success, 1 for memory allocation error.
Author
Ed Hartnett
Date
2022-08-12

Definition at line 135 of file jpcunpack.c.

References jpcunpack_int().

◆ pngpack()

void pngpack ( float *  fld,
g2int  width,
g2int  height,
g2int idrstmpl,
unsigned char *  cpack,
g2int lcpack 
)

This subroutine packs up a float data field into PNG image format.

After the data field is scaled, and the reference value is subtracted out, it is treated as a grayscale image and passed to a PNG encoder. It also fills in GRIB2 Data Representation Template 5.41 or 5.40010 with the appropriate values.

Parameters
fldPointer to array of float that contains the data values to pack.
widthNumber of points in the x direction.
heightNumber of points in the y direction.
idrstmplContains the array of values for Data Representation Template 5.41 or 5.40010.
  • 0 Reference value - ignored on input, set by pngpack routine.
  • 1 Binary Scale Factor - used on input.
  • 2 Decimal Scale Factor - used on input.
  • 3 number of bits for each grayscale pixel value - ignored on input.
  • 4 Original field type - currently ignored on input, set = 0 on output. Data values assumed to be reals.
cpackThe packed data field.
lcpacklength of packed field cpack.
Author
Stephen Gilbert
Date
2003-08-27
Author
Ed Hartnett

Definition at line 224 of file pngpack.c.

References pngpack_int().

◆ pngpackd()

void pngpackd ( double *  fld,
g2int  width,
g2int  height,
g2int idrstmpl,
unsigned char *  cpack,
g2int lcpack 
)

This subroutine packs up a double data field into PNG image format.

After the data field is scaled, and the reference value is subtracted out, it is treated as a grayscale image and passed to a PNG encoder. It also fills in GRIB2 Data Representation Template 5.41 or 5.40010 with the appropriate values.

Parameters
fldPointer to array of double that contains the data values to pack.
widthNumber of points in the x direction.
heightNumber of points in the y direction.
idrstmplContains the array of values for Data Representation Template 5.41 or 5.40010.
  • 0 Reference value - ignored on input, set by pngpack routine.
  • 1 Binary Scale Factor - used on input.
  • 2 Decimal Scale Factor - used on input.
  • 3 number of bits for each grayscale pixel value - ignored on input.
  • 4 Original field type - currently ignored on input, set = 0 on output. Data values assumed to be reals.
cpackThe packed data field.
lcpacklength of packed field cpack.
Author
Ed Hartnett
Date
Aug 8, 2022

Definition at line 259 of file pngpack.c.

References pngpack_int().

◆ pngunpack()

g2int pngunpack ( unsigned char *  cpack,
g2int  len,
g2int idrstmpl,
g2int  ndpts,
float *  fld 
)

This subroutine unpacks a data field that was packed into a PNG image format using info from the GRIB2 Data Representation Template 5.41 or 5.40010.

Parameters
cpackThe packed data field (character*1 array).
lenlength of packed field cpack().
idrstmplPointer to array of values for Data Representation Template 5.41 or 5.40010.
ndptsThe number of data values to unpack.
fldContains the unpacked data values.
Returns
0 for success, 1 for memory allocation error.
Author
Stephen Gilbert
Date
2003-08-27
Author
Ed Hartnett

Definition at line 105 of file pngunpack.c.

References pngunpack_int().

◆ pngunpackd()

g2int pngunpackd ( unsigned char *  cpack,
g2int  len,
g2int idrstmpl,
g2int  ndpts,
double *  fld 
)

This subroutine unpacks a data field that was packed into a PNG image format using info from the GRIB2 Data Representation Template 5.41 or 5.40010.

Parameters
cpackThe packed data field (character*1 array).
lenlength of packed field cpack().
idrstmplPointer to array of values for Data Representation Template 5.41 or 5.40010.
ndptsThe number of data values to unpack.
fldContains the unpacked data values.
Returns
0 for success, 1 for memory allocation error.
Author
Ed Hartnett
Date
Aug 8, 2022

Definition at line 128 of file pngunpack.c.

References pngunpack_int().

◆ seekgb()

void seekgb ( FILE *  lugb,
g2int  iseek,
g2int  mseek,
g2int lskip,
g2int lgrib 
)

This subprogram searches a file for the next GRIB Message.

The search is done starting at byte offset iseek of the file referenced by lugb for mseek bytes at a time. If found, the starting position and length of the message are returned in lskip and lgrib, respectively. The search is terminated when an EOF or I/O error is encountered.

Program History Log

Date Programmer Comments
2002-10-28 GILBERT Modified from Iredell's skgb subroutine
2009-01-16 VUONG Changed lskip to 4 instead of sizof(g2int)
Parameters
lugbFILE pointer for the file to search. File must be opened before this routine is called.
iseeknumber of bytes in the file to skip before search.
mseeknumber of bytes to search at a time (must be at least 16).
lskipnumber of bytes to skip from the beggining of the file to where the GRIB message starts.
lgribnumber of bytes in message (set to 0, if no message found).
Author
Stephen Gilbert
Date
2002-10-28

Definition at line 39 of file seekgb.c.

References BITS_PER_BYTE, and gbit().

grib2.h
Header file for NCEPLIBS-g2c library.
gribfield
Struct for GRIB field.
Definition: grib2.h:41
g2_getfld
g2int g2_getfld(unsigned char *cgrib, g2int ifldnum, g2int unpack, g2int expand, gribfield **gfld)
This subroutine returns all the metadata, template values, bit-map (if applicable),...
Definition: g2_getfld.c:91