grib2.h(3)
okay so bestie, you just opened grib2.h(3) from the Library Functions Manual and honestly? iconic. this is the header file page for the NCEPLIBS-g2c library, and it's a big one, so we're doing this in parts. grab a snack 🍓
✨ NAME ✨
grib2.h — the header file for the NCEPLIBS-g2c library. that's the whole vibe. 💅
🌈 SYNOPSIS 🌈
before literally anything else, you pull in these bad boys right here:
#include <stdint.h>
#include <stdio.h>
#include <string.h>
#include <sys/types.h>
🦋 Data Structures 🦋
struct gribfield— the struct for a GRIB2 field. the whole field. everything about it. she contains multitudes. 💖
✨ Macros ✨
okay this is the long part, and no, we are not skipping any of them, because every single one matters. buckle up 🫶
G2_ADD_MSG_COMPLETE=-2— GRIB message already complete. it's done, girl, stop adding to it 💀G2_ADD_MSG_INIT=-1— GRIB message was not initialized — you gotta callg2_create()first.G2_ADDFIELD_BAD_BITMAP=-8— ing2_addfield()there's no bitmap in the GRIB message.G2_ADDFIELD_BAD_DRT=-7— ing2_addfield()there's an unsupported Data Representationi Template. (yes that's the spelling, we don't fix it, we respect it 🎀)G2_ADDFIELD_BAD_GDS=-6— ing2_addfield()section 3 (GDS) was not previously defined in the message.G2_ADDFIELD_BAD_GDT=-9— ing2_addfield()you need a GDT of one of 5.50 through 5.53 when using DRT 5.51.G2_ADDFIELD_BAD_PDT=-5— ing2_addfield()it could not find the requested Product Definition Template.G2_ADDFIELD_ERR=-10— ing2_addfield()there was an error packing the data field. 😭G2_ADDGRID_BAD_GDT=-5— ing2_addgrid()it could not find the requested Grid Definition Template.G2_AEC_ENABLED=1— decoding/encoding AEC/CCSDS is enabled. slay.G2_BAD_SEC=-4— the previous Section was unexpected. rude, honestly.G2_BAD_SEC_COUNTS=-3— the sum of Section byte counts doesn't add to the total byte count. math said no 🧚G2_CREATE_GRIB_VERSION=-1— wrong GRIB version forg2_create(), it must be 2.G2_GETFLD_BAD_END=7—g2_getfld()didn't find7777"atendofmessage.G2_GETFLD_BAD_SEC1=15— error ing2_getfld()unpacking section 1.G2_GETFLD_BAD_SEC2=16— error ing2_getfld()unpacking section 2.G2_GETFLD_BAD_SEC3=10— error ing2_getfld()unpacking section 3.G2_GETFLD_BAD_SEC4=11— error ing2_getfld()unpacking section 4.G2_GETFLD_BAD_SEC5=12— error ing2_getfld()unpacking section 5.G2_GETFLD_BAD_SEC6=13— error ing2_getfld()unpacking section 6.G2_GETFLD_BAD_SEC7=14— error ing2_getfld()unpacking section 7.G2_GETFLD_GRIB_VERSION=2— wrong GRIB version forg2_getfld(), it must be 2.G2_GETFLD_INVAL=3—g2_getfld()data field request number was not positive.G2_GETFLD_INVAL_SEC=8—g2_getfld()encountered an unrecognized section.G2_GETFLD_NO_BITMAP=17— ing2_getfld()a previous bitmap was specified, yet none exists.G2_GETFLD_NO_DRT=9— ing2_getfld(), the Data Representation Template is not implemented.G2_GETFLD_NO_GRIB=1—g2_getfld()can't find the beginning charactersGRIB".G2_GETFLD_WRONG_END=4—g2_info()found7777"notwhereexpected.G2_GETFLD_WRONG_NFLDS=6— ing2_getfld()the message did not contain the requested number of data fields.G2_GRIBEND_MSG_INIT=-1— ing2_gribend()the GRIB message was not initialized — you gotta callg2_create()first.G2_INFO_BAD_END=5—g2_info()didn't find7777"atendofmessage.G2_INFO_GRIB_VERSION=2— wrong GRIB version forg2_info(), it must be 2.G2_INFO_INVAL_SEC=6—g2_info()found an invalid section number.G2_INFO_NO_GRIB=1—g2_info()can't find the beginning charactersGRIB".G2_INFO_NO_SEC1=3—g2_info()can't find section 1.G2_INFO_WRONG_END=4—g2_info()found7777"notwhereexpected.G2_JASPER_DECODE=-3— indec_jpeg2000()there was an error decoding the image with jasper.G2_JASPER_DECODE_COLOR=-5— indec_jpeg2000()the decoded image had multiple color components.G2_JASPER_ENCODE=-3— inenc_jpeg2000()there was an error encoding the image with jasper.G2_JASPER_INIT=-2— inenc_jpeg2000()/dec_jpeg2000()there was an error initializing the jasper library.G2_JPCUNPACK_MEM=1— injpcunpack()or another unpack function: out of memory. 💀G2_JPEG2000_ENABLED=1— decoding/encoding JPEG2000 is enabled. ate.G2_NO_ERROR=0— the function succeeded. we love to see it 👑G2_PNG_ENABLED=1— decoding/encoding PNG is enabled.G2_SPECUNPACK_TYPE=-3— inspecunpack()it can't handle 64 or 128 bit floats.G2_UNPACK3_BAD_GDT=5— ing2_unpack3(), undefined Grid Definition Template.G2_UNPACK4_BAD_PDT=5— ing2_unpack4(), undefined Product Definition Template.G2_UNPACK5_BAD_DRT=7— ing2_unpack5(), undefined Data Representation Template.G2_UNPACK6_BAD_BITMAP=4— ing2_unpack6(), unrecognized pre-defined bit-map.G2_UNPACK7_BAD_DRT=4— ing2_unpack7(), unrecognized Data Representation Template.G2_UNPACK7_CORRUPT_SEC=7— ing2_unpack7(), corrupt section 7.G2_UNPACK7_WRONG_GDT=5— ing2_unpack7(), you need one of GDT 3.50 through 3.53 to decode DRT 5.51.G2_UNPACK_BAD_SEC=2— bad section number in the unpacking function.G2_UNPACK_NO_MEM=6— error allocating memory in the unpack function.G2C_AEC_DRS_TEMPLATE_LEN=8— length of theidrstmplarray for AEC packing.G2C_BYTE=1— signed 1 byte integer.G2C_CHAR=2— ISO/ASCII character.G2C_CLOBBER=0x0000— destroy the existing file. bestie. that file is GONE 😭G2C_DOUBLE=6— double precision floating point number.G2C_EAEC=(-74)— error encoding/decoding AEC data.G2C_EBADEND=(-65)— end of message in the wrong place.G2C_EBADID=(-55)— bad ID.G2C_EBADSECTION=(-66)— invalid section number.G2C_EBADTEMPLATE=(-70)— template problem.G2C_EBADTYPE=(-73)— type not found.G2C_ECSV=(-75)— CSV error.G2C_EFILE=(-54)— file I/O error.G2C_EINVAL=(-53)— invalid input.G2C_EJPEG=(-67)— error encoding/decoding JPEG data.G2C_EMSG=(-58)— error decoding GRIB message.G2C_EMSGCOMPLETE=(-51)— GRIB message already complete.G2C_ENAMETOOLONG=(-52)— name too long.G2C_ENOEND=(-64)— cannot find the end of the GRIB message.G2C_ENOMEM=(-57)— out of memory.G2C_ENOMSG=(-59)— no GRIB message found.G2C_ENOPARAM=(-71)— parameter not found.G2C_ENOPRODUCT=(-72)— product not found.G2C_ENOSECTION=(-63)— cannot find section.G2C_ENOTEMPLATE=(-69)— template not found.G2C_ENOTFOUND=(-61)— table or entry not found.G2C_ENOTGRIB=(-50)— GRIB header not found.G2C_ENOTGRIB2=(-62)— not GRIB 2.G2C_EPNG=(-68)— error encoding/decoding PNG data.G2C_ERROR=1— general error code, returned for some test errors.G2C_ETOOMANYFILES=(-56)— trying to open too many files.G2C_EXML=(-60)— XML error.G2C_FLOAT=5— single precision floating point number.G2C_INT=4— signed 4 byte integer.G2C_INT64=10— signed 8-byte int.G2C_JASPER_MAX_MEM— maximum size for the Jasper memory buffer. (no value attached, she's just vibes ✨)G2C_JPEG_DRS_TEMPLATE_LEN=7— length of theidrstmplarray for JPEG packing.G2C_LARGE_FILE_INDEX=0x0008— create a large file index.G2C_MAX_DRS_TEMPLATE=11— maximum number of DRS templates.G2C_MAX_DRS_TEMPLATE_MAPLEN=18— maximum DRS template map length.G2C_MAX_FILES=3— maximum number of open files.G2C_MAX_GDS_TEMPLATE=38— maximum number of grid templates.G2C_MAX_GDS_TEMPLATE_MAPLEN=28— maximum grid template map length.G2C_MAX_GRIB_CODE_LEN=20— maximum length of code.G2C_MAX_GRIB_DESC_LEN=512— maximum length of code description.G2C_MAX_GRIB_LEVEL_DESC_LEN=40— maximum length of level description.G2C_MAX_GRIB_STATUS_LEN=40— maximum length of code status.G2C_MAX_GRIB_TITLE_LEN=200— maximum length of code table title.G2C_MAX_NAME=1024— maximum length of a name.G2C_MAX_NOAA_ABBREV_LEN=11— maximum length of a NOAA abbreviation of a parameter.G2C_MAX_NOAA_PARAM_LINE_LEN=120— maximum length of a line in the NOAA abbreviation CSV file.G2C_MAX_NOAA_PARAMS=2000— maximum number of known parameters with NOAA abbreviations.G2C_MAX_NUM_SECTIONS=1024— maximum number of sections that can be handled in one message.G2C_MAX_PDS_TEMPLATE=102— maximum number of PDS templates.G2C_MAX_PDS_TEMPLATE_MAPLEN=50— maximum template map length.G2C_NOCLOBBER=0x0004— don't destroy the existing file. (the respectful option 🫶)G2C_NOERROR=0— no error.G2C_NOWRITE=0x0000— set read-only access forg2c_open().G2C_PNG_DRS_TEMPLATE_LEN=5— length of theidrstmplarray for PNG packing.G2C_PNG_HEIGHT_MAX=100000— maximum height of a PNG grid.G2C_PNG_WIDTH_MAX=100000000— maximum width of a PNG grid.G2C_SECTION0_ARRAY_LEN=3— length of the section 0 array.G2C_SECTION0_BYTES=16— number of bytes in section 0.G2C_SECTION0_LEN=3— length of the section 0 array.G2C_SECTION1_ARRAY_LEN=13— length of the section 1 array.G2C_SECTION1_BYTES=21— number of bytes in section 1 (not including reserved, optional data at the end of the section).G2C_SECTION1_LEN=13— length of the section 1 array.G2C_SHORT=3— signed 2 byte integer.G2C_UBYTE=7— unsigned 1 byte int.G2C_UINT=9— unsigned 4-byte int.G2C_UINT64=11— unsigned 8-byte int.G2C_USHORT=8— unsigned 2-byte int.G2C_VERSION='2.3.0'— current version of the NCEPLIBS-g2c library. 💜G2C_WRITE=0x0001— set read-write access forg2c_open().
🎀 Typedefs 🎀
typedef float g2float— float type.typedef int64_t g2int— long integer type.typedef uint64_t g2intu— unsigned long integer type.typedef struct gribfield gribfield— the struct for a GRIB field. her again, still iconic 💖
part 1 done, bestie — there's more coming, don't go anywhere 🦋
🦋 Functions 🦋
okay bestie, this is the entire function roster — every signature, every one-liner, zero skips, no crumbs left behind 🍓 grab a snack, we're doing all of them.
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)— packs sections 4 through 7 and adds them onto a GRIB2 message. section stacking, but make it cute 🎀g2int g2_addgrid (unsigned char *cgrib, g2int *igds, g2int *igdstmpl, g2int *ideflist, g2int idefnum)— packs a Grid Definition Section (Section 3) and adds it onto a GRIB2 message. grid goes in, grid goes on 📐g2int g2_addlocal (unsigned char *cgrib, unsigned char *csec2, g2int lcsec2)— adds a Local Use Section (Section 2) onto a GRIB2 message. your lil local secret, tucked in 🙈g2int g2_create (unsigned char *cgrib, g2int *listsec0, g2int *listsec1)— initializes a brand new GRIB2 message and packs GRIB2 Section 0 (Indicator Section) and Section 1 (Identification Section). birth of a message, main character energy ✨void g2_free (gribfield *gfld)— frees the memory that was allocated forstruct gribfield. cleanup era 🧹g2int g2_getfld (unsigned char *cgrib, g2int ifldnum, g2int unpack, g2int expand, gribfield **gfld)— hands you back all the metadata, the template values, the bit-map (if there is one), and the unpacked data for a data field. the full reveal 💖g2int g2_gribend (unsigned char *cgrib)— finalizes a GRIB2 message once all the grids and fields have been added. closing the chapter, periodt 🔥g2int g2_info (unsigned char *cgrib, g2int *listsec0, g2int *listsec1, g2int *numfields, g2int *numlocal)— searches through a GRIB2 message and returns how many gridded fields it found in there, plus the number (and the maximum size) of Local Use Sections. receipts, but for message structure 🧾g2int g2_unpack1 (unsigned char *cgrib, g2int *iofst, g2int **ids, g2int *idslen)— unpacks Section 1 — the Identification Section — of a GRIB2 message. 🪪g2int g2_unpack2 (unsigned char *cgrib, g2int *iofst, g2int *lencsec2, unsigned char **csec2)— unpacks Section 2 (the Local Use Section) of a GRIB2 message. 🎁g2int g2_unpack3 (unsigned char *cgrib, g2int *iofst, g2int **igds, g2int **igdstmpl, g2int *mapgridlen, g2int **ideflist, g2int *idefnum)— unpacks Section 3 (the Grid Definition Section) of a GRIB2 message. 🗺️g2int g2_unpack4 (unsigned char *cgrib, g2int *iofst, g2int *ipdsnum, g2int **ipdstmpl, g2int *mappdslen, float **coordlist, g2int *numcoord)— unpacks Section 4 (the Product Definition Section) of a GRIB2 message. 📦g2int g2_unpack5 (unsigned char *cgrib, g2int *iofst, g2int *ndpts, g2int *idrsnum, g2int **idrstmpl, g2int *mapdrslen)— unpacks Section 5 (the Data Representation Section) of a GRIB2 message. 🧬g2int g2_unpack6 (unsigned char *cgrib, g2int *iofst, g2int ngpts, g2int *ibmap, g2int **bmap)— unpacks Section 6 (the Bit-Map Section) of a GRIB2 message. little dots, big meaning ⚫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 (the Data Section) of a GRIB2 message. the actual numbers, bestie 🌈int g2c_aecpackd (double *fld, size_t width, size_t height, int *idrstmpl, unsigned char *cpack, size_t *lcpack)— packs up a double array into an AEC code stream. squish it down, doubles 🗜️int g2c_aecpackf (float *fld, size_t width, size_t height, int *idrstmpl, unsigned char *cpack, size_t *lcpack)— packs up a float array into an AEC code stream. 🗜️int g2c_aecunpackd (unsigned char *cpack, size_t len, int *idrstmpl, size_t ndpts, double *fld)— unpacks AEC compressed data into an array of doubles, using the info from GRIB2 Data Representation Template 5.42. 🪄int g2c_aecunpackf (unsigned char *cpack, size_t len, int *idrstmpl, size_t ndpts, float *fld)— unpacks AEC compressed data into an array of floats, using the info from GRIB2 Data Representation Template 5.42. 🪄int g2c_close (int g2cid)— closes a GRIB2 file and frees the resources. bye babe, take your memory with you 👋int g2c_compare (int g2cid1, int g2cid2)— compares the metadata of two open GRIB2 files. vibe check, but for metadata ⚖️int g2c_csv_init ()— initializes tables fromCodeFlag.txt". 📊int g2c_dec_aec (unsigned char *cpack, int len, int nbits, int flags, int block_size, int rsi, unsigned char *cfld, int cfldlen)— decodes an AEC code stream specified in the CCSDS 121.0-B-3 Blue Book. 📘int g2c_dec_jpeg2000 (char *injpc, size_t bufsize, int *outfld)— decodes a JPEG2000 code stream specified in the JPEG2000 Part-1 standard (i.e.,ISO/IEC 15444-1) using JasPer Software. 🖼️int g2c_dec_png (unsigned char *pngbuf, int *width, int *height, unsigned char *cout)— decodes PNG. 🌷int g2c_degrib2 (int g2cid, const char *fileout)— writes a summary file like thedegrib2utility does. 📝int g2c_enc_aec (unsigned char *data, int ctemplen, int nbits, int flags, int block_size, int rsi, unsigned char *aecbuf, int *aecbuflen)— encodes data into an AEC code stream specified in the CCSDS 121.0-B-3 Blue Book. 📘int g2c_enc_jpeg2000 (unsigned char *cin, int width, int height, int nbits, int ltype, int ratio, int retry, char *outjpc, size_t jpclen)— encodes a grayscale image into a JPEG2000 code stream specified in the JPEG2000 Part-1 standard (i.e.,ISO/IEC 15444-1) using JasPer Software. 🖼️int g2c_enc_png (unsigned char *data, int width, int height, int nbits, unsigned char *pngbuf)— encodes PNG. 🌷int g2c_find_desc (char *title, int code, char *desc)— given a table title and an integer code, finds you a description. 🔍int g2c_find_desc_str (char *title, char *code, char *desc)— given a table title and a code, finds you a description. 🔍int g2c_find_msg2 (int g2cid, size_t skip_bytes, size_t max_bytes, size_t *bytes_to_msg, size_t *bytes_in_msg)— searches a file for the next GRIB1 or GRIB2 message. 🕵️void g2c_free_tables ()— frees the table memory. tables cleared, no crumbs 🧹void g2c_gbit_int (unsigned char *in, int *iout, int iskip, int nbits)— extracts arbitrary size values out of a packed bit string, right justifying each value in the unpackedioutarray. 🧷int g2c_gbits_int (unsigned char *in, int *iout, int iskip, int nbits, int nskip, int n)— extracts arbitrary size values out of a packed bit string, right justifying each value in the unpackedioutarray. same energy, more args 🧷int g2c_get_drs_template (int drs_template_num, int *maplen, int *map, int *needext)— gets DRS template information. 📋int g2c_get_gdt_len (int grid_template_num, int *maplen)— gets the initial length (number of entries) in the static part of a Grid Definition Template. 📏int g2c_get_grid_template (int grid_template_num, int *maplen, int *map, int *needext)— gets grid template information. 📋int g2c_get_grid_template_extension (int grid_template_num, int *g2c_template, int *extlen, int *ext)— gets grid template extension information. 📋int g2c_get_msg (int g2cid, size_t skip_bytes, size_t max_bytes, size_t *bytes_to_msg, size_t *bytes_in_msg, unsigned char **cbuf)— searches a file for the next GRIB1 or GRIB2 message, and reads it, allocating space in memory to hold that message. find it AND hold it, multi-tasking queen 💅int g2c_get_pds_template (int pds_template_num, int *maplen, int *map, int *needext)— gets PDS template information. 📋int g2c_get_pds_template_extension (int pds_template_num, int *g2c_template, int *extlen, int *ext)— gets pds template extension information. 📋int g2c_get_pdt_len (int pds_template_num, int *maplen)— gets the initial length (number of entries) in the static part of a PDS template. 📏int g2c_get_prod (int g2cid, int msg_num, int prod_num, int *num_data_points, float *data)— reads the data for a product. 📖int g2c_inq (int g2cid, int *num_msg)— learns about a GRIB2 file. getting to know u fr fr 🫶int g2c_inq_dim (int g2cid, int msg_num, int prod_num, int dim_num, size_t *len, char *name, float *val)— learns about one of the dimensions of a GRIB2 product. 📐int g2c_inq_dim_info (int g2cid, int msg_num, int prod_num, int dim_num, size_t *len, char *name)— learns about one of the dimensions of a GRIB2 product. 📐int g2c_inq_msg (int g2cid, int msg_num, unsigned char *discipline, int *num_fields, int *num_local, short *center, short *subcenter, unsigned char *master_version, unsigned char *local_version)— learns about a GRIB2 message. 💌int g2c_inq_msg_time (int g2cid, int msg_num, unsigned char *sig_ref_time, short *year, unsigned char *month, unsigned char *day, unsigned char *hour, unsigned char *minute, unsigned char *second)— learns about the date/time information in a GRIB2 message. ⏰int g2c_inq_prod (int g2cid, int msg_num, int prod_num, int *pds_template_len, long long int *pds_template, int *gds_template_len, long long int *gds_template, int *drs_template_len, long long int *drs_template)— inquires about a product. all the deets, all three templates 🧐int g2c_jpcpackd (double *fld, size_t width, size_t height, int *idrstmpl, unsigned char *cpack, size_t *lcpack)— packs up a double array into a JPEG2000 code stream. 🗜️int g2c_jpcpackf (float *fld, size_t width, size_t height, int *idrstmpl, unsigned char *cpack, size_t *lcpack)— packs up a float array into a JPEG2000 code stream. 🗜️int g2c_jpcunpackd (unsigned char *cpack, size_t len, int *idrstmpl, size_t ndpts, double *fld)— unpacks JPEG2000 compressed data into an array of doubles, using the info from GRIB2 Data Representation Template 5.40 or 5.40000. 🪄int g2c_jpcunpackf (unsigned char *cpack, size_t len, int *idrstmpl, size_t ndpts, float *fld)— unpacks JPEG2000 compressed data into an array of floats, using the info from GRIB2 Data Representation Template 5.40 or 5.40000. 🪄int g2c_log_file (int g2cid)— prints a summary of the contents of an open GRIB2 file. 🪵int g2c_open (const char *path, int mode, int *g2cid)— opens an existing GRIB2 file. come on in bestie 🚪int g2c_open_index (const char *data_file, const char *index_file, int mode, int *g2cid)— opens a GRIB2 file with the help of an index file. 🗂️int g2c_open_index1 (const char *index_file)— opens a GRIB1 index file and reads the contents. 🗂️int g2c_param_abbrev (int g2disc, int g2cat, int g2num, char *abbrev)— gets the NOAA abbreviation for a GRIB2 parameter. 🏷️int g2c_param_all (int param_idx, int *g1ver, int *g1val, int *g2disc, int *g2cat, int *g2num, char *abbdrev)— returns all the information about a parameter. the whole lore drop 📚int g2c_param_g1tog2 (int g1val, int g1ver, int *g2disc, int *g2cat, int *g2num)— translates a GRIB1 parameter to a GRIB2 parameter. 🔄int g2c_param_g2tog1 (int g2disc, int g2cat, int g2num, int *g1val, int *g1ver)— translates a GRIB2 parameter to a GRIB1 parameter. 🔄int g2c_pngpackd (double *fld, size_t width, size_t height, int *idrstmpl, unsigned char *cpack, int *lcpack)— this subroutine packs up a double data field into PNG image format. 🎨int g2c_pngpackf (float *fld, size_t width, size_t height, int *idrstmpl, unsigned char *cpack, int *lcpack)— …
Okay bestie, we're still in the function lineup, so let's keep it moving 💅
This subroutine packs up a float data field into PNG image format.
int g2c_pngunpackd (unsigned char *cpack, size_t len, int *idrstmpl,
size_t ndpts, double *fld)
This one unpacks a data field that got packed into PNG image format, using the info from the GRIB2 Data Representation Template 5.41 or 5.40010.
int g2c_pngunpackf (unsigned char *cpack, size_t len, int *idrstmpl,
size_t ndpts, float *fld)
Same energy, also unpacks a data field packed into PNG image format using info from GRIB2 Data Representation Template 5.41 or 5.40010.
int g2c_seekmsg (int g2cid, size_t skip, size_t *offset, size_t *msglen)
Search a file for the next GRIB2 Message. it's giving "where's the message, bestie" 🔍
int g2c_set_log_level (int new_level)
Use this to set the global log level. yes she has a volume knob, and yes you can turn her up 🔊
const char * g2c_strerror (int g2cerr)
Hand it an error code, she hands you back an error message. emotional support for your errno 💖
int g2c_unpack7 (unsigned char *cgrib, int igdsnum, int gds_tmpl_len,
long long int *gdstmpl, int idrsnum, int drs_tmpl_len, long long int
*drstmpl, int ndpts, float *fld)
This subroutine unpacks Section 7 (Data Section) of a GRIB2 message. the main character section fr fr ✨
int g2c_write_index (int g2cid, int mode, const char *index_file)
Create an index file from a GRIB2 file, just like the ones the grb2index utility makes. matching sets, iconic 👑
void seekgb (FILE *lugb, g2int iseek, g2int mseek, g2int *lskip, g2int
*lgrib)
Search a file for the next GRIB Message.
💫 Detailed Description 💫
Header file for NCEPLIBS-g2c library. that's the whole vibe, she's the blueprint 🎀
📜 Program History Log 📜
2002-10-25— Gilbert — Initial2009-01-14— Vuong — Changed struct template togtemplate2021-11-9— Ed Hartnett — Moved many prototypes to new internal headergrib2_int.h.2022-04-15— Ed Hartnett — Added error codes related to JPEG.2022-08-15— Ed Hartnett — Added compression functions for double.2023-09-10— Eric Engle — Added AEC compression.
✍️ Author
Stephen Gilbert
📅 Date
2002-10-25
✍️ Author
Ed Hartnett
📂 Definition in file
grib2.h.
🧬 Data Type Documentation 🧬
🌸 struct gribfield 🌸
Struct for GRIB2 field. the moment, the icon, the legend 💖
Definition at line 45 of file grib2.h.
Data Fields:
g2int * bmap— Integer array holding the decoded bitmap, ifibmap=0oribap=254. OtherwiseNULL.float * coord_list— Array holding floating point values meant 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 saying whether the data field was expanded to the grid in the case where a bit-map is present. If true, the data points infldmatch the grid points and zeros were inserted at grid points where data was bit-mapped out. If false, the data values inldwere not expanded to the grid and are just a consecutive array of data points corresponding to each value of"1"inbmap.float * fld— Array ofndptsunpacked data points.g2int griddef— Source of grid definition (see Table 3.0).0Specified in Table 3.1.1Predetermined grid Defined by originating centre.
g2int ibmap— Bitmap indicator (see Table 6.0).0bitmap applies and is included in Section 6.1-253= Predefined bitmap applies254= Previously defined bitmap applies to this field255= Bit map does not apply to this product.
g2int idrtlen— Number of elements inidrtmpl.g2int * idrtmpl— Contains the data values for the Data Representation Template specified byidrtnum.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).7is 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).0Experimental1Initial operational version number
idsect[3]GRIB Local Tables Version Number (see Table 1.1).0Local tables not used1-254Number of local tables version used
idsect[4]Significance of Reference Time (See Table 1.2).0Analysis1Start of forecast2Verifying time of forecast3Observation time
idsect[5]Year (4 digits)idsect[6]Monthidsect[7)Dayidsect[8]Houridsect[9]Minuteidsect[10]Secondidsect[11]Production status of processed data (see Table 1.3).0Operational products1Operational test products2Research products3Re-analysis products
idsect[12]Type of processed data (see Table 1.4).0Analysis products1Forecast products2Analysis and forecast products3Control forecast products4Perturbed forecast products5Control and perturbed forecast products6Processed satellite observations7Processed radar observations
g2int idsectlen— Number of elements inidsect.g2int ifldnum— Field number within GRIB message.g2int igdtlen— Number of elements inigdtmpl- i.e. number of entries in Grid Defintion Template.g2int * igdtmpl— Contains the data values for the Grid Definition Template specified byigdtnum.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 inipdtmpl- i.e. number of entries in Product Defintion Template.g2int * ipdtmpl— Contains the data values for the Product Definition Template specified byipdtnum.g2int ipdtnum— Product Definition Template Number (see Table 4.0).g2int * list_opt— (Used ifnumoct_opt .ne. 0) This array contains the number of grid points contained in each row (or column) (part of Section 3).NULLifnumoct_opt = 0.unsigned char * local— Pointer to character array containing contents of Local Section 2, if included.g2int locallen— Length of arraylocal.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 arraycoord_list.g2int num_opt— (Used ifnumoct_opt .ne. 0) The number of entries in arrayideflist- i.e. number of rows (or columns) for which optional grid points are defined. This value is set to zero, ifnumoct_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 saying whether the bitmap and data values were unpacked. If false,bmapandfldpointers areNULL.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. sorry babe, the message said goodbye 💀
Definition at line 473 of file grib2.h.
Referenced by g2_addfield(), g2_addgrid(), g2_addlocal(), and g2_gribend().
🔥 G2_ADD_MSG_INIT 🔥
#define G2_ADD_MSG_INIT -1
GRIB message was not initialized - call g2_create() first. you forgot to start it bestie, go start it 😭
Definition at line 472 of file grib2.h.
Referenced by g2_addfield(), g2_addgrid(), g2_addlocal(), and g2_gribend().
🔥 G2_ADDFIELD_BAD_BITMAP 🔥
#define G2_ADDFIELD_BAD_BITMAP -8
In g2_addfield() no bitmap in the GRIB message.
Definition at line 478 of file grib2.h.
Referenced by g2_addfield().
🔥 G2_ADDFIELD_BAD_DRT 🔥
#define G2_ADDFIELD_BAD_DRT -7
In g2_addfield() unsupported Data Representationi Template.
Definition at line 477 of file grib2.h.
Referenced by g2_addfield().
🔥 G2_ADDFIELD_BAD_GDS 🔥
#define G2_ADDFIELD_BAD_GDS -6
In g2_addfield() section 3 (GDS) not previously defined in message.
Definition at line 476 of file grib2.h.
Referenced by g2_addfield().
🔥 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. very specific, very picky, we respect it 💅
Definition at line 479 of file grib2.h.
Referenced by g2_addfield().
🔥 G2_ADDFIELD_BAD_PDT 🔥
#define G2_ADDFIELD_BAD_PDT -5
In g2_addfield() could not find requested Product Definition Template.
Definition at line 475 of file grib2.h.
Referenced by g2_addfield().
🔥 G2_ADDFIELD_ERR 🔥
#define G2_ADDFIELD_ERR -10
In g2_addfield() error packing data field.
Definition at line 480 of file grib2.h.
Referenced by g2_addfield().
🔥 G2_ADDGRID_BAD_GDT 🔥
#define G2_ADDGRID_BAD_GDT -5
In g2_addgrid() Could not find requested Grid Definition Template.
Definition at line 481 of file grib2.h.
Referenced by g2_addgrid().
🔥 G2_AEC_ENABLED 🔥
#define G2_AEC_ENABLED 1
Decoding/encoding AEC/CCSDS is enabled. she's awake and thriving ✨
Definition at line 29 of file grib2.h.
🔥 G2_BAD_SEC 🔥
#define G2_BAD_SEC -4
Previous Section was unexpected. plot twist nobody asked for 😭
Definition at line 462 of file grib2.h.
Referenced by g2_addfield(), g2_addgrid(), g2_addlocal(), and g2_gribend().
🔥 G2_BAD_SEC_COUNTS 🔥
#define G2_BAD_SEC_COUNTS -3
Sum of Section byte counts doesn't add to total byte count. the math is not mathing 💀
Definition at line 474 of file grib2.h.
Referenced by g2_addfield(), g2_addgrid(), g2_addlocal(), and g2_gribend().
🔥 G2_CREATE_GRIB_VERSION 🔥
#define G2_CREATE_GRIB_VERSION -1
Wrong GRIB version for g2_create(), must be 2. she only dates version 2, periodt 👑
Definition at line 438 of file grib2.h.
Referenced by g2_create().
🔥 G2_GETFLD_BAD_END 🔥
#define G2_GETFLD_BAD_END 7
g2_getfld() didn't find "7777" at end of message.
Definition at line 450 of file grib2.h.
Referenced by g2_getfld().
🔥 G2_GETFLD_BAD_SEC1 🔥
#define G2_GETFLD_BAD_SEC1 15
Error in g2_getfld() unpacking section 1.
Definition at line 453 of file grib2.h.
Referenced by g2_getfld().
🔥 G2_GETFLD_BAD_SEC2 🔥
#define G2_GETFLD_BAD_SEC2 16
Error in g2_getfld() unpacking section 2.
Definition at line 454 of file grib2.h.
Referenced by g2_getfld().
🔥 G2_GETFLD_BAD_SEC3 🔥
#define G2_GETFLD_BAD_SEC3 10
Error in g2_getfld() unpacking section 3.
Definition at line 455 of file grib2.h.
Referenced by g2_getfld().
🔥 G2_GETFLD_BAD_SEC4 🔥
#define G2_GETFLD_BAD_SEC4 11
Error in g2_getfld() unpacking section 4.
Definition at line 456 of file grib2.h.
Referenced by g2_getfld().
🔥 G2_GETFLD_BAD_SEC5 🔥
#define G2_GETFLD_BAD_SEC5 12
Error in g2_getfld() unpacking section 5.
Definition at line 457 of file grib2.h.
Referenced by g2_getfld().
🔥 G2_GETFLD_BAD_SEC6 🔥
#define G2_GETFLD_BAD_SEC6 13
Error in g2_getfld() unpacking section 6.
Definition at line 458 of file grib2.h.
Referenced by g2_getfld().
🔥 G2_GETFLD_BAD_SEC7 🔥
#define G2_GETFLD_BAD_SEC7 14
Error in g2_getfld() unpacking section 7.
Definition at line 459 of file grib2.h.
#define G2_GETFLD_GRIB_VERSION 2
Bestie, if g2_getfld() sees this it means the GRIB version is wrong — it has to be 2. No exceptions, no vibes. 💅
Defined at line 446 of file grib2.h.
Referenced by g2_getfld().
#define G2_GETFLD_INVAL 3
g2_getfld() got a data field request number that wasn't positive. We don't do negative field requests here, queen. 🚫
Defined at line 447 of file grib2.h.
Referenced by g2_getfld().
#define G2_GETFLD_INVAL_SEC 8
g2_getfld() ran into a section it does not recognize. It's giving mystery section, and we're not into it. 😭
Defined at line 451 of file grib2.h.
Referenced by g2_getfld().
#define G2_GETFLD_NO_BITMAP 17
In g2_getfld(), a previous bitmap was specified — but literally none exists. The audacity. 💀
Defined at line 460 of file grib2.h.
Referenced by g2_getfld().
#define G2_GETFLD_NO_DRT 9
In g2_getfld(), the Data Representation Template just isn't implemented. Not our fault, not our problem. 🙈
Defined at line 452 of file grib2.h.
#define G2_GETFLD_NO_GRIB 1
g2_getfld() can't find the opening characters "GRIB". Where is it bestie, where did it go. 🔍
Defined at line 445 of file grib2.h.
Referenced by g2_getfld().
#define G2_GETFLD_WRONG_END 4
g2_info() found "7777" somewhere it was absolutely not supposed to be. Rude of it, honestly. 💅
Defined at line 448 of file grib2.h.
Referenced by g2_getfld().
#define G2_GETFLD_WRONG_NFLDS 6
In g2_getfld(), the message did not contain the number of data fields that were requested. Close but no. ✋
Defined at line 449 of file grib2.h.
Referenced by g2_getfld().
#define G2_GRIBEND_MSG_INIT -1
In g2_gribend() the GRIB message was not initialized — so bestie, call g2_create() first. Order matters, always. 🎀
Defined at line 461 of file grib2.h.
#define G2_INFO_BAD_END 5
g2_info() didn't find "7777" at the end of the message. The ending is giving unfinished. 😭
Defined at line 443 of file grib2.h.
Referenced by g2_info().
#define G2_INFO_GRIB_VERSION 2
Wrong GRIB version for g2_info() — it must be 2. That's the whole rule. ✨
Defined at line 440 of file grib2.h.
Referenced by g2_info().
#define G2_INFO_INVAL_SEC 6
g2_info() found an invalid section number. Not every number is a valid section, babe. 💅
Defined at line 444 of file grib2.h.
Referenced by g2_info().
#define G2_INFO_NO_GRIB 1
g2_info() can't find the beginning characters "GRIB". Same energy as losing your keys, except it's the whole file. 🔥
Defined at line 439 of file grib2.h.
Referenced by g2_info().
#define G2_INFO_NO_SEC1 3
g2_info() can't find section 1. It's just… not there. 😶
Defined at line 441 of file grib2.h.
Referenced by g2_info().
#define G2_INFO_WRONG_END 4
g2_info() found "7777" not where it was expected. Main character in the wrong scene. 🎬
Defined at line 442 of file grib2.h.
Referenced by g2_info().
#define G2_JASPER_DECODE -3
In dec_jpeg2000() there was an error decoding the image with jasper. Jasper said no. 🙅
Defined at line 486 of file grib2.h.
Referenced by int_dec_jpeg2000().
#define G2_JASPER_DECODE_COLOR -5
In dec_jpeg2000() the decoded image had multiple color components. Too many colors, too much drama. 🌈
Defined at line 487 of file grib2.h.
Referenced by int_dec_jpeg2000().
#define G2_JASPER_ENCODE -3
In enc_jpeg2000() there was an error encoding the image with jasper. Encoding said nope. 😭
Defined at line 485 of file grib2.h.
Referenced by enc_jpeg2000().
#define G2_JASPER_INIT -2
In enc_jpeg2000() / dec_jpeg2000() there was an error initializing the jasper library. Can't even get started fr. 💀
Defined at line 484 of file grib2.h.
Referenced by enc_jpeg2000(), and int_dec_jpeg2000().
#define G2_JPCUNPACK_MEM 1
In jpcunpack() or another unpack function: out of memory. Bestie ran out of room. 😵
Defined at line 482 of file grib2.h.
Referenced by jpcunpack(), pngunpack(), and simunpack().
#define G2_JPEG2000_ENABLED 1
Decoding/encoding JPEG2000 is enabled. It's on, it's live, it's slaying. 🔥
Defined at line 28 of file grib2.h.
#define G2_NO_ERROR 0
The function succeeded. Literally the best outcome, we love to see it. 👑
Defined at line 437 of file grib2.h.
Referenced by g2_getfld(), g2_unpack1(), g2_unpack2(), g2_unpack3(), g2_unpack4(), g2_unpack5(), g2_unpack6(), g2c_unpack7_int(), simunpack(), and specunpack().
#define G2_PNG_ENABLED 1
Decoding/encoding PNG is enabled. PNG girlies rise. 🌸
Defined at line 27 of file grib2.h.
#define G2_SPECUNPACK_TYPE -3
In specunpack() it can't handle 64 or 128 bit floats. Those floats are simply too much for it, no cap. 💅
Defined at line 483 of file grib2.h.
Referenced by specunpack().
#define G2_UNPACK3_BAD_GDT 5
In g2_unpack3(), undefined Grid Definition Template. The GDT is a mystery. 🕵️
Defined at line 465 of file grib2.h.
Referenced by g2_unpack3().
#define G2_UNPACK4_BAD_PDT 5
In g2_unpack4(), undefined Product Definition Template. Same vibe, different template. 😭
Defined at line 466 of file grib2.h.
Referenced by g2_unpack4().
#define G2_UNPACK5_BAD_DRT 7
In g2_unpack5(), undefined Data Representation Template. It's giving undefined, and not in a cute way. 🙈
Defined at line 467 of file grib2.h.
Referenced by g2_unpack5().
#define G2_UNPACK6_BAD_BITMAP 4
In g2_unpack6(), unrecognized pre-defined bit-map. That bitmap is a stranger. 💀
Defined at line 468 of file grib2.h.
#define G2_UNPACK7_BAD_DRT 4
In g2_unpack7(), unrecognized Data Representation Template. We don't know her. 🚫
Defined at line 471 of file grib2.h.
Referenced by g2c_unpack7_int().
#define G2_UNPACK7_CORRUPT_SEC 7
In g2_unpack7(), corrupt section 7. Something is very wrong in there bestie, do not look. 😵
Defined at line 469 of file grib2.h.
Referenced by g2c_unpack7_int().
#define G2_UNPACK7_WRONG_GDT 5
In g2_unpack7(), you need one of GDT 3.50 through 3.53 to decode DRT 5.51. Specific much? But that's the requirement. ✨
Defined at line 470 of file grib2.h.
Referenced by g2c_unpack7_int().
#define G2_UNPACK_BAD_SEC 2
Bad section number in an unpacking function. Wrong number, wrong place. 💅
Defined at line 463 of file grib2.h.
Referenced by g2_unpack1(), g2_unpack2(), g2_unpack3(), g2_unpack4(), g2_unpack5(), g2_unpack6(), and g2c_unpack7_int().
#define G2_UNPACK_NO_MEM 6
Error allocating memory in an unpack function. Out of memory, out of patience. 😭
Defined at line 464 of file grib2.h.
Referenced by g2_unpack1(), g2_unpack2(), g2_unpack3(), g2_unpack4(), g2_unpack5(), g2_unpack6(), and g2c_unpack7_int().
#define G2C_AEC_DRS_TEMPLATE_LEN 8
The length of the idrstmpl array for AEC packing. It's 8, remember it. 🎀
Defined at line 419 of file grib2.h.
Referenced by g2c_aecpackd(), g2c_aecpackf(), g2c_aecunpackd(), and g2c_aecunpackf().
#define G2C_BYTE 1
Signed 1 byte integer. Tiny but mighty. 💖
Defined at line 260 of file grib2.h.
Referenced by g2c_file_io(), and g2c_file_io_byte().
#define G2C_CHAR 2
ISO/ASCII character. Just one little guy. ✨
Defined at line 261 of file grib2.h.
#define G2C_CLOBBER 0x0000
Destroy existing file. It's a mode flag for g2c_create(). Yes bestie, it literally obliterates what was there. 💀
Defined at line 277 of file grib2.h.
Referenced by main().
#define G2C_DOUBLE 6
Double precision floating point number. Fancy and precise. 💅
Defined at line 265 of file grib2.h.
#define G2C_EAEC (-74)
Error encoding/decoding AEC data. AEC said no thank you. 😭
Defined at line 516 of file grib2.h.
Referenced by aecpack_int().
#define G2C_EBADEND (-65)
End of message in the wrong place. The ending flopped. 🎬
Defined at line 507 of file grib2.h.
Referenced by g2c_strerror().
#define G2C_EBADID (-55)
Bad ID. That's it, that's the whole issue. 🚫
Defined at line 497 of file grib2.h.
Referenced by free_metadata(), g2c_close(), g2c_compare(), g2c_degrib2(), g2c_find_msg2(), g2c_get_msg(), g2c_get_prod(), g2c_inq(), g2c_inq_dim(), g2c_inq_msg(), g2c_inq_msg_time(), g2c_inq_prod(), g2c_log_file(), g2c_seekmsg(), g2c_strerror(), g2c_write_index(), and read_metadata().
#define G2C_EBADSECTION (-66)
Invalid section number. Not a real section, bestie. 💅
Defined at line 508 of file grib2.h.
Referenced by add_section(), g2c_open_index(), g2c_strerror(), and read_msg_metadata().
#define G2C_EBADTEMPLATE (-70)
Template problem. The template is not templating. 🙈
Defined at line 512 of file grib2.h.
Referenced by g2c_file_io_template(), and g2c_strerror().
#define G2C_EBADTYPE (-73)
Type not found. Can't find the type anywhere. 🔍
Defined at line 515 of file grib2.h.
Referenced by g2c_file_io(), and g2c_strerror().
#define G2C_ECSV (-75)
CSV error. The commas are not comma-ing. 😭
Defined at line 517 of file grib2.h.
Referenced by g2c_csv_init().
#define G2C_EFILE (-54)
File I/O error. The file said nope. 💀
Defined at line 496 of file grib2.h.
Referenced by g2c_add_file(), g2c_close(), g2c_degrib2(), g2c_file_io(), g2c_find_msg2(), g2c_get_msg(), g2c_get_prod(), g2c_open_index(), g2c_open_index1(), g2c_seekmsg(), g2c_start_index1_record(), g2c_strerror(), g2c_write_index(), read_hdr_rec1(), read_hdr_rec2(), and read_msg_metadata().
#define G2C_EINVAL (-53)
Invalid input. Bestie, that input was not it. 🚫
Defined at line 495 of file grib2.h.
Referenced by find_available_g2cid(), g2c_add_file(), g2c_degrib2(), g2c_file_io(), g2c_find_desc_str(), g2c_find_msg2(), g2c_gbits_int(), g2c_get_grid_template_extension(), g2c_get_msg(), g2c_get_pds_template_extension(), g2c_get_prod(), g2c_get_prod_sections(), g2c_inq_dim(), g2c_inq_msg(), g2c_inq_msg_time(), g2c_inq_prod(), g2c_open_index(), g2c_open_index1(), g2c_param_all(), g2c_rw_section3_metadata(), g2c_rw_section4_metadata(), g2c_rw_section5_metadata(), g2c_rw_section6_metadata(), g2c_start_index1_record(), g2c_start_index_record(), g2c_start_index_record_lf(), g2c_strerror(), g2c_unpack7(), and g2c_write_index().
#define G2C_EJPEG (-67)
Error encoding/decoding JPEG data. JPEG is being difficult today. 😭
Defined at line 509 of file grib2.h.
Referenced by g2c_strerror(), and jpcpack_int().
#define G2C_EMSG (-58)
Error decoding GRIB message. The message is not messaging. 💀
Defined at line 500 of file grib2.h.
Referenced by g2c_find_msg2(), and g2c_strerror().
#define G2C_EMSGCOMPLETE (-51)
GRIB message already complete. Bestie it's done, stop adding to it. ✋
Defined at line 493 of file grib2.h.
Referenced by g2_addfield(), g2_addgrid(), g2_addlocal(), g2_gribend(), g2c_check_msg(), and g2c_strerror().
#define G2C_ENAMETOOLONG (-52)
Name too long. It's giving essay title. 📝
Defined at line 494 of file grib2.h.
Referenced by g2c_add_file(), g2c_csv_init(), g2c_open_index(), and g2c_strerror().
#define G2C_ENOEND (-64)
Cannot find the end of the GRIB message. Where does it end?? Nobody knows. 😵
Defined at line 506 of file grib2.h.
Referenced by g2c_strerror().
#define G2C_ENOMEM (-57)
Out of memory. Bestie needs more RAM, immediately. 🔥
Defined at line 499 of file grib2.h.
Referenced by add_msg(), add_section(), aecunpack_int(), determine_dims(), g2c_csv_init(), g2c_find_msg2(), g2c_gbits_int(), g2c_get_grid_template_extension(), g2c_get_msg(), g2c_get_pds_template_extension(), g2c_get_prod(), g2c_rw_section3_metadata(), g2c_rw_section4_metadata(), g2c_rw_section5_metadata(), g2c_rw_section6_metadata(), g2c_seekmsg(), g2c_strerror(), g2c_unpack7(), jpcunpack_int(), main(), pngunpack(), and pngunpack_int().
#define G2C_ENOMSG (-59)
No GRIB message found. It's simply not here. 🫥
Defined at line 501 of file grib2.h.
Referenced by g2c_get_msg(), g2c_get_prod(), g2c_inq_dim(), g2c_inq_msg(), g2c_inq_msg_time(), g2c_inq_prod(), g2c_strerror(), and read_metadata().
#define G2C_ENOPARAM (-71)
Parameter not found. That parameter does not exist, bestie. 🔍
Defined at line 513 of file grib2.h.
Referenced by g2c_param_g1tog2(), g2c_param_g2tog1(), and g2c_strerror().
#define G2C_ENOPRODUCT (-72)
Product not found. The product is missing in action. 📦
Defined at line 514 of file grib2.h.
Referenced by g2c_get_prod(), g2c_inq_dim(), g2c_inq_prod(), and g2c_strerror().
#define G2C_ENOSECTION (-63)
Cannot find section. It's just not there, periodt. 💅
Defined at line 505 of file grib2.h.
- Referenced by
g2c_compare(),g2c_degrib2(),g2c_get_prod(),g2c_get_prod_sections(),g2c_inq_dim(),g2c_inq_prod(),g2c_rw_section1_metadata(), andg2c_strerror().
#define G2C_ENOTEMPLATE (-69)— Template not found. bestie went looking and there was nothing there 💀- Definition at line 511 of file
grib2.h. - Referenced by
g2c_get_drs_template(),g2c_get_gdt_len(),g2c_get_grid_template(),g2c_get_grid_template_extension(),g2c_get_pds_template(),g2c_get_pds_template_extension(),g2c_get_pdt_len(), andg2c_strerror().
- Definition at line 511 of file
#define G2C_ENOTFOUND (-61)— Table or entry not found.- Definition at line 503 of file
grib2.h. - Referenced by
g2c_find_desc_str(), andg2c_strerror().
- Definition at line 503 of file
#define G2C_ENOTGRIB (-50)— GRIB header not found. not a single one, we checked 😭- Definition at line 492 of file
grib2.h. - Referenced by
g2_addfield(),g2_addgrid(),g2_addlocal(),g2_gribend(),g2c_check_msg(), andg2c_strerror().
- Definition at line 492 of file
#define G2C_ENOTGRIB2 (-62)— Not GRIB 2. it's giving imposter 🙈- Definition at line 504 of file
grib2.h. - Referenced by
g2c_strerror().
- Definition at line 504 of file
#define G2C_EPNG (-68)— Error encoding/decoding PNG data.- Definition at line 510 of file
grib2.h. - Referenced by
g2c_strerror(), andpngpack_int().
- Definition at line 510 of file
#define G2C_ERROR 1— General error code, returned for some test errors.- Definition at line 491 of file
grib2.h. - Referenced by
g2c_compare(),g2c_degrib2(),g2c_find_msg2(),g2c_get_msg(),g2c_get_prod(), andmain().
- Definition at line 491 of file
#define G2C_ETOOMANYFILES (-56)— Trying to open too many files. girl, put some down ✋- Definition at line 498 of file
grib2.h. - Referenced by
find_available_g2cid(), andg2c_strerror().
- Definition at line 498 of file
#define G2C_EXML (-60)— XML error.- Definition at line 502 of file
grib2.h. - Referenced by
g2c_strerror().
- Definition at line 502 of file
#define G2C_FLOAT 5— single precision floating point number 🌊- Definition at line 264 of file
grib2.h.
- Definition at line 264 of file
#define G2C_INT 4— signed 4 byte integer 🔢- Definition at line 263 of file
grib2.h. - Referenced by
g2c_file_io(), andg2c_file_io_int().
- Definition at line 263 of file
#define G2C_INT64 10— signed 8-byte int 🫶- Definition at line 269 of file
grib2.h. - Referenced by
g2c_file_io(), andg2c_file_io_longlong().
- Definition at line 269 of file
#define G2C_JASPER_MAX_MEM— Maximum size for the Jasper memory buffer.- Definition at line 432 of file
grib2.h. - Referenced by
int_dec_jpeg2000().
- Definition at line 432 of file
#define G2C_JPEG_DRS_TEMPLATE_LEN 7— Length of theidrstmplarray for JPEG packing.- Definition at line 417 of file
grib2.h. - Referenced by
g2c_jpcpackd(),g2c_jpcpackf(),g2c_jpcunpackd(), andg2c_jpcunpackf().
- Definition at line 417 of file
#define G2C_LARGE_FILE_INDEX 0x0008— Create a large file index. Mode flag forg2c_write_index(). 🗂️- Definition at line 279 of file
grib2.h. - Referenced by
g2c_write_index(), andmain().
- Definition at line 279 of file
#define G2C_MAX_DRS_TEMPLATE 11— Maximum number of DRS templates.- Definition at line 296 of file
grib2.h. - Referenced by
g2c_get_drs_template(), andgetdrsindex().
- Definition at line 296 of file
#define G2C_MAX_DRS_TEMPLATE_MAPLEN 18— Maximum DRS template map length.- Definition at line 297 of file
grib2.h.
- Definition at line 297 of file
#define G2C_MAX_FILES 3— Maximum number of open files. that's it, that's the whole capacity bestie 💅- Definition at line 273 of file
grib2.h. - Referenced by
find_available_g2cid(),free_metadata(),g2c_close(),g2c_compare(),g2c_degrib2(),g2c_get_prod(),g2c_inq(),g2c_inq_dim(),g2c_inq_msg(),g2c_inq_msg_time(),g2c_inq_prod(), andg2c_write_index().
- Definition at line 273 of file
#define G2C_MAX_GDS_TEMPLATE 38— Maximum number of grid templates.- Definition at line 292 of file
grib2.h. - Referenced by
g2c_get_gdt_len(),g2c_get_grid_template(),g2c_get_grid_template_extension(), andgetgridindex().
- Definition at line 292 of file
#define G2C_MAX_GDS_TEMPLATE_MAPLEN 28— Maximum grid template map length.- Definition at line 293 of file
grib2.h. - Referenced by
g2c_rw_section3_metadata().
- Definition at line 293 of file
#define G2C_MAX_GRIB_CODE_LEN 20— Maximum length of code.- Definition at line 424 of file
grib2.h. - Referenced by
g2c_csv_init(),g2c_find_desc(), andg2c_find_desc_str().
- Definition at line 424 of file
#define G2C_MAX_GRIB_DESC_LEN 512— Maximum length of code description.- Definition at line 421 of file
grib2.h. - Referenced by
g2c_csv_init(),g2c_find_entry(), andg2c_log_section1().
- Definition at line 421 of file
#define G2C_MAX_GRIB_LEVEL_DESC_LEN 40— Maximum length of level description.- Definition at line 423 of file
grib2.h. - Referenced by
g2c_csv_init().
- Definition at line 423 of file
#define G2C_MAX_GRIB_STATUS_LEN 40— Maximum length of code status.- Definition at line 422 of file
grib2.h. - Referenced by
g2c_csv_init().
- Definition at line 422 of file
#define G2C_MAX_GRIB_TITLE_LEN 200— Maximum length of code table title.- Definition at line 425 of file
grib2.h. - Referenced by
g2c_csv_init(),g2c_find_desc_str(), andg2c_find_table().
- Definition at line 425 of file
#define G2C_MAX_NAME 1024— Maximum length of a name.- Definition at line 274 of file
grib2.h. - Referenced by
determine_dims(),g2c_add_file(),g2c_inq_dim(), andg2c_open_index().
- Definition at line 274 of file
#define G2C_MAX_NOAA_ABBREV_LEN 11— Maximum length of a NOAA abbreviation of a parameter.- Definition at line 429 of file
grib2.h. - Referenced by
g2c_degrib2(),g2c_log_section(),g2c_param_abbrev(), andg2c_param_all().
- Definition at line 429 of file
#define G2C_MAX_NOAA_PARAM_LINE_LEN 120— Maximum length of a line in the NOAA abbreviation CSV file.- Definition at line 430 of file
grib2.h.
- Definition at line 430 of file
#define G2C_MAX_NOAA_PARAMS 2000— Maximum number of known parameters with NOAA abbreviations.- Definition at line 428 of file
grib2.h. - Referenced by
g2c_param_abbrev(),g2c_param_all(),g2c_param_g1tog2(), andg2c_param_g2tog1().
- Definition at line 428 of file
#define G2C_MAX_NUM_SECTIONS 1024— Maximum number of sections that can be handled in one message.- Definition at line 426 of file
grib2.h.
- Definition at line 426 of file
#define G2C_MAX_PDS_TEMPLATE 102— Maximum number of PDS templates.- Definition at line 294 of file
grib2.h. - Referenced by
g2c_get_pds_template(),g2c_get_pds_template_extension(),g2c_get_pdt_len(), andgetpdsindex().
- Definition at line 294 of file
#define G2C_MAX_PDS_TEMPLATE_MAPLEN 50— Maximum template map length.- Definition at line 295 of file
grib2.h. - Referenced by
g2c_rw_section4_metadata(), andg2c_rw_section5_metadata().
- Definition at line 295 of file
#define G2C_NOCLOBBER 0x0004— Don't destroy existing file. Mode flag forg2c_create(). Respect the existing file bestie, it's ✨thriving✨- Definition at line 278 of file
grib2.h. - Referenced by
g2c_write_index().
- Definition at line 278 of file
#define G2C_NOERROR 0— No error. the dream, the goal, the vibe 🌈- Definition at line 490 of file
grib2.h. - Referenced by
add_msg(),add_section(),aecpack_int(),aecunpack_int(),determine_dims(),find_available_g2cid(),format_level(),free_metadata(),g2c_add_file(),g2c_check_msg(),g2c_close(),g2c_compare(),g2c_csv_init(),g2c_degrib2(),g2c_file_io(),g2c_file_io_template(),g2c_find_desc_str(),g2c_find_msg2(),g2c_gbits_int(),g2c_get_datetime(),g2c_get_drs_template(),g2c_get_gdt_len(),g2c_get_grid_template(),g2c_get_grid_template_extension(),g2c_get_level_desc(),g2c_get_msg(),g2c_get_pds_template(),g2c_get_pds_template_extension(),g2c_get_pdt_len(),g2c_get_prod(),g2c_get_prod_sections(),g2c_inq(),g2c_inq_dim(),g2c_inq_msg(),g2c_inq_msg_time(),g2c_inq_prod(),g2c_log_file(),g2c_log_section(),g2c_log_section1(),g2c_open_index(),g2c_open_index1(),g2c_param_abbrev(),g2c_param_all(),g2c_param_g1tog2(),g2c_param_g2tog1(),g2c_rw_section1_metadata(),g2c_rw_section3_metadata(),g2c_rw_section4_metadata(),g2c_rw_section5_metadata(),g2c_rw_section6_metadata(),g2c_seekmsg(),g2c_set_log_level(),g2c_start_index1_record(),g2c_start_index_record(),g2c_start_index_record_lf(),g2c_strerror(),g2c_write_index(),jpcpack_int(),jpcunpack_int(),pngpack_int(),read_hdr_rec1(),read_hdr_rec2(),read_metadata(), andread_msg_metadata().
- Definition at line 490 of file
#define G2C_NOWRITE 0x0000— Set read-only access forg2c_open(). look, don't touch 👀- Definition at line 275 of file
grib2.h. - Referenced by
main().
- Definition at line 275 of file
#define G2C_PNG_DRS_TEMPLATE_LEN 5— Length of theidrstmplarray for PNG packing.- Definition at line 418 of file
grib2.h. - Referenced by
g2c_pngpackd(),g2c_pngpackf(),g2c_pngunpackd(), andg2c_pngunpackf().
- Definition at line 418 of file
#define G2C_PNG_HEIGHT_MAX 100000— Maximum height of PNG grid.- Definition at line 435 of file
grib2.h. - Referenced by
dec_png().
- Definition at line 435 of file
#define G2C_PNG_WIDTH_MAX 100000000— Maximum width of PNG grid.- Definition at line 434 of file
grib2.h. - Referenced by
dec_png().
- Definition at line 434 of file
#define G2C_SECTION0_ARRAY_LEN 3— Length of section 0 array.- Definition at line 414 of file
grib2.h.
- Definition at line 414 of file
#define G2C_SECTION0_BYTES 16— Number of bytes in section 0.- Definition at line 282 of file
grib2.h. - Referenced by
read_msg_metadata().
- Definition at line 282 of file
#define G2C_SECTION0_LEN 3— Length of section 0 array.- Definition at line 288 of file
grib2.h.
- Definition at line 288 of file
#define G2C_SECTION1_ARRAY_LEN 13— Length of section 1 array.- Definition at line 415 of file
grib2.h.
- Definition at line 415 of file
#define G2C_SECTION1_BYTES 21— Number of bytes in section 1 (not including reserved, optional data at the end of the section).- Definition at line 286 of file
grib2.h. - Referenced by
g2c_rw_section1_metadata().
- Definition at line 286 of file
#define G2C_SECTION1_LEN 13— Length of section 1 array.- Definition at line 289 of file
grib2.h.
- Definition at line 289 of file
#define G2C_SHORT 3— signed 2 byte integer 🧮- Definition at line 262 of file
grib2.h. - Referenced by
g2c_file_io(), andg2c_file_io_short().
- Definition at line 262 of file
#define G2C_UBYTE 7— unsigned 1 byte int 🔢- Definition at line 266 of file
grib2.h. - Referenced by
g2c_file_io(), andg2c_file_io_ubyte().
- Definition at line 266 of file
#define G2C_UINT 9— unsigned 4-byte int 🫶- Definition at line 268 of file
grib2.h. - Referenced by
g2c_file_io(), andg2c_file_io_uint().
- Definition at line 268 of file
#define G2C_UINT64 11— unsigned 8-byte int 🫶- Definition at line 270 of file
grib2.h. - Referenced by
g2c_file_io(), andg2c_file_io_ulonglong().
- Definition at line 270 of file
#define G2C_USHORT 8— unsigned 2-byte int 🔢- Definition at line 267 of file
grib2.h. - Referenced by
g2c_file_io(), andg2c_file_io_ushort().
- Definition at line 267 of file
#define G2C_VERSION '2.3.0'— Current version of NCEPLIBS-g2c library. hi bestie, this is the era we're in ✨👑- Definition at line 25 of file
grib2.h. - Referenced by
main().
- Definition at line 25 of file
#define G2C_WRITE 0x0001— Set read-write access forg2c_open(). now you can change things 💅- Definition at line 276 of file
grib2.h. - Referenced by
g2c_add_file().
- Definition at line 276 of file
🧬 Typedef Documentation 🧬
typedef float g2float— Float type. This typedef is provided for backward compatibility and is not used by the library any more. Usefloatin new code, bestie, we've moved on 💖- Definition at line 40 of file
grib2.h.
- Definition at line 40 of file
typedef int64_t g2int— Long integer type. our ride-or-die integer 🫶- Definition at line 32 of file
grib2.h.
- Definition at line 32 of file
typedef uint64_t g2intu— Unsigned long integer type. This typedef is provided for backward compatibility and is not used by the library any more. no cap, it's retired 🎀- Definition at line 36 of file
grib2.h.
- Definition at line 36 of file
typedef struct gribfield gribfield— Struct for GRIB field. the whole point of the function, lowkey iconic 👑- Definition at line 221 of file
grib2.h.
- Definition at line 221 of file
🛠️ 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)
Pack sections 4 through 7 and adds them to a GRIB2 message. It's giving assembly line but make it meteorological 🏭🌈
They are:
- Product Definition Section
- Data Representation Section
- Bit-Map Section
- Data Section
okay so bestie, this routine is your lil construction crew 💖 — you team it up with g2_create(), g2_addlocal(), g2_addgrid(), and g2_gribend() to build a whole entire GRIB2 message. Order matters, no cap: g2_create() has to go first to spin up a fresh GRIB2 message. Then g2_addgrid() has to be called after g2_create() and before this routine, so the right grid description is sitting in the message already. And after all your fields are in? You must call g2_gribend() to actually complete the GRIB2 message. Miss that step and it's giving unfinished business 😭
Program History Log
2002-11-05— Gilbert — Initial2002-12-23— Gilbert — Added complex spherical harmonic packing2003-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 gtemplate2023-09-08— Engle — Added support for new template, 5.42, using CCSDS compression (libaec).
Parameters
cgrib— aChararray holding the GRIB2 message you're adding Sections 4 through 7 to. Gotta be allocated big enough to store the entire GRIB2 message, fr fr.ipdsnum— Product Definition Template Number (see Code Table 4.0).ipdstmpl— holds the data values for the Product Definition Template thatipdsnumpicked out.coordlist— an array containing floating point values meant to document the vertical discretisation tied to model data on hybrid coordinate vertical levels.numcoord— how many values live in thecoordlistarray.idrsnum— Data Representation Template Number (see Code Table 5.0).idrstmpl— the data values for the Data Representation Template thatidrsnumpicked out. Heads up bestie: some values in this template (eg. reference values, number of bits, etc...) may get changed by the data packing algorithms. Use this to specify scaling factors and order of spatial differencing, if you want them.fld— array of data points to pack.ngrdpts— number of data points in grid. i.e. size offldandbmap.ibmap— Bitmap 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.
bmap— Integer array containing the bitmap to be added (ifibmap = 0).
Returns
> 0— current size of the updated GRIB2 message ✨G2_ADD_MSG_INIT— GRIB message was not initialized. Need to call routineg2_create()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 3 or 7.G2_ADDFIELD_BAD_PDT— Could not find requested Product Definition Template.G2_ADDFIELD_BAD_GDS— Section 3 (GDS) not previously defined in message.G2_ADDFIELD_BAD_DRT— Tried to use unsupported Data Representation Template.G2_ADDFIELD_BAD_BITMAP— Specified use of a previously defined bitmap, but one does not exist in the GRIB message.G2_ADDFIELD_BAD_GDT— GDT of one of 5.50 through 5.53 required to pack field using DRT 5.51.G2_ADDFIELD_ERR— Error packing data field.
Note
Note that the Sections 4 through 7 can only follow Section 3 or Section 7 in a GRIB2 message. That's the law, bestie 💅
Author
Stephen Gilbert
Date
2002-11-05
Definition at line 100 of file g2_addfield.c.
References
aecpack(), 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_EMSGCOMPLETE, G2C_ENOTGRIB, gbit(), getdim(), getdrstemplate(), getpdstemplate(), getpoly(), jpcpack(), gtemplate::map, gtemplate::maplen, mkieee(), gtemplate::needext, pngpack(), sbit(), sbits(), simpack(), and specpack().
g2int g2_addgrid (unsigned char * cgrib, g2int * igds, g2int * igdstmpl, g2int * ideflist, g2int idefnum)
Packs a Grid Definition Section (Section 3) and adds it to a GRIB2 message 🎀 This one hangs out with g2_create(), g2_addlocal(), g2_addfield(), and g2_gribend() to build a complete GRIB2 message. And yes — g2_create() must be called first to initialize a new GRIB2 message. Non-negotiable, iykyk.
Parameters
cgrib—Chararray containing the GRIB2 message that the section should be added to. Must be allocated large enough to store the entire GRIB2 message.igds— contains 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).
igdstmpl— contains 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 Definition Template.ideflist— (Used ifigds[2] != 0) This array contains the number of grid points contained in each row (or column).idefnum— (Used ifigds[2] != 0) The number of entries in arrayideflist. i.e. number of rows (or columns) for which optional grid points are defined.
Returns
> 0— current size of the updated GRIB2 message 💖G2_ADD_MSG_INIT— GRIB message was not initialized. Need to call routinegribcreatefirst.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 countG2_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. Them's the rules 🦋
Author
Stephen Gilbeert
Date
2002-11-01
Definition at line 66 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_EMSGCOMPLETE, G2C_ENOTGRIB, gbit(), getgridtemplate(), gtemplate::map, gtemplate::maplen, gtemplate::needext, sbit(), and sbits().
g2int g2_addlocal (unsigned char * cgrib, unsigned char * csec2, g2int lcsec2)
Adds a Local Use Section (Section 2) to a GRIB2 message 🌸 This function runs with g2_create(), g2_addgrid(), g2_addfield(), and g2_gribend() to create a complete GRIB2 message.
Parameters
cgrib—Chararray containing the GRIB2 message that section 2 should be added to. Must be allocated large enough to store the entire GRIB2 message.csec2—Characterarray containing information to be added in Section 2.lcsec2— Number of bytes of character arraycsec2to be added to Section 2.
Returns
> 0= Current size of updated GRIB2 message.G2_ADD_MSG_INIT— GRIB message was not initialized. Need to call routinegribcreatefirst.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 or 7.
Note
The Local Use Section (Section 2) can only follow Section 1 or Section 7 in a GRIB2 message. Yeah bestie, order is everything 😤
Author
Stephen Gilbeert
Date
2002-11-01
Definition at line 41 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_EMSGCOMPLETE, G2C_ENOTGRIB, gbit(), and sbit().
g2int g2_create (unsigned char * cgrib, g2int * listsec0, g2int * listsec1)
Initialize a new GRIB2 message and pack 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 — it's the main character, periodt. And a call to g2_gribend() is required to complete the GRIB2 message after all fields have been added.
Parameters
cgrib—Characterarray to contain the GRIB2 message. Must be allocated large enough to store the entire GRIB2 message.listsec0— contains information needed for GRIB Indicator Section 0. Must be dimensioned>= 2.listsec0[0]Discipline-GRIB Master Table Number (Code Table 0.0 —https://www.nco.ncep.noaa.gov/pmb/docs/grib2/grib2_doc/grib2_table0-0.shtml).listsec0[1]GRIB Edition Number (currently 2).
listsec1— contains information needed for GRIB Identification Section 1. Must be dimensioned>= 13.listsec1[0]Id of orginating centre (Table 0 —https://www.nco.ncep.noaa.gov/pmb/docs/on388/table0.html).listsec1[1]Id of orginating sub-centre (Table C —https://www.nco.ncep.noaa.gov/pmb/docs/on388/tablec.html).listsec1[2]GRIB Master Tables Version Number (Table 1.0 —https://www.nco.ncep.noaa.gov/pmb/docs/grib2/grib2_doc/grib2_table1-0.shtml).listsec1[3]GRIB Local Tables Version Number (Table 1.1 —https://www.nco.ncep.noaa.gov/pmb/docs/grib2/grib2_doc/grib2_table1-1.shtml).listsec1[4]Significance of Reference Time (Table 1.2 —https://www.nco.ncep.noaa.gov/pmb/docs/grib2/grib2_doc/grib2_table1-2.shtml)listsec1[5]Reference Time - Year (4 digits)listsec1[6]Reference Time - Monthlistsec1[7]Reference Time - Daylistsec1[8]Reference Time - Hourlistsec1[9]Reference Time - Minutelistsec1[10]Reference Time - Secondlistsec1[11]Production status of data (Table 1.3 —https://www.nco.ncep.noaa.gov/pmb/docs/grib2/grib2_doc/grib2_table1-3.shtml).listsec1[12]Type of processed data (Table 1.4 —https://www.nco.ncep.noaa.gov/pmb/docs/grib2/grib2_doc/grib2_table1-4.shtml).
Returns
> 0— current size of the new GRIB2 message ⭐G2_CREATE_GRIB_VERSION— you tried to use this for a version that isn't GRIB Edition 2 💀 bestie that is not a GRIB2 message, that is a problem
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().
void g2_free (gribfield * gfld) 🎀
Free memory that was allocated for struct gribfield. It's giving cleanup era and honestly? iconic.
Parameters
gfld— pointer togribfieldstructure (defined in include filegrib2.h) returned from routineg2_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. No cap, if you skip this your memory just sits there rotting 💀
Author
Stephen Gilbert
Date
2002-10-28
Definition at line 23 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().
g2int g2_getfld (unsigned char * cgrib, g2int ifldnum, g2int unpack, g2int expand, gribfield ** gfld) 🔥
Return all the metadata, template values, bit-map (if applicable), and the unpacked data for a 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. Yeah bestie, you gotta #include it, that's the vibe check 🌸
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. It's a whole little ✨choose your own adventure✨.
Program History Log
- Date
2002-10-28, ProgrammerGilbert, CommentsInitial - Date
2013-08-08, ProgrammerVuong, CommentsFree up memory in array igds - free(igds)
Parameters
cgrib— Character pointer to the GRIB2 message.ifldnum— Specifies which field in the GRIB2 message to return. The first field is number 1, Fortran style.unpack— Boolean value indicating whether to unpack bitmap/data field.1unpack bitmap (if present) and data values. 🫶0do not unpack bitmap and data values.
expand— Boolean value indicating whether the data points should be expanded to the correspond grid, if a bit-map is present. This argument is ignored ifunpack == 0OR if the returned field does not contain a bit-map.1if possible, expand data field to grid, inserting zero values at gridpoints that are bitmapped out. (SEE REMARKS2)0do not expand data field, leaving it an array of consecutive data points for each"1"in the bitmap.
gfld— pointer to structuregribfieldcontaining all decoded data for the data field.
Returns
G2_NO_ERROR— no error ✨ slayG2_GETFLD_NO_GRIB— Beginning characters"GRIB"not found. 😭 where is itG2_GETFLD_GRIB_VERSION— GRIB message is not Edition 2.G2_GETFLD_INVAL— The data field request number was not positive.G2_GETFLD_WRONG_END— End string"7777"found, but not where expected.G2_GETFLD_WRONG_NFLDS— GRIB message did not contain the requested number of data fields.G2_GETFLD_BAD_END— End string"7777"not found at end of message.G2_GETFLD_INVAL_SEC— Unrecognized Section encountered.G2_GETFLD_NO_DRT— Data Representation Template5.NNnot yet implemented.G2_GETFLD_BAD_SEC1— Error unpacking Section 1.G2_GETFLD_BAD_SEC2— Error unpacking Section 2.G2_GETFLD_BAD_SEC3— Error unpacking Section 3.G2_GETFLD_BAD_SEC4— Error unpacking Section 4.G2_GETFLD_BAD_SEC5— Error unpacking Section 5.G2_GETFLD_BAD_SEC6— Error unpacking Section 6.G2_GETFLD_BAD_SEC7— Error unpacking Section 7.G2_GETFLD_NO_BITMAP— Previous bitmap specified, yet none exists.
Note
Structgribfieldis 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 routineg2_free(). Like. please. be a responsible main character 🧚
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->expandedwould be set to0(false), regardless of the value of input argumentexpand. So like, don't @ it, it literally can't 💅
Author
Stephen Gilbert
Date
2002-10-28
Definition at line 93 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.
g2int g2_gribend (unsigned char * cgrib) 🌈
Finalize a GRIB2 message after all grids and fields have been added. This function 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. It's the grand finale bestie, the bow on top 🎀
Parameters
cgrib— Char array containing all the data sections added be previous calls tog2_create(),g2_addlocal(),g2_addgrid(), andg2_addfield(). After function is called, contains the finalized GRIB2 message.
Returns
> 0— Length of the final GRIB2 message in bytes. 💖G2_GRIBEND_MSG_INIT— GRIB message was not initialized - callg2_create()first.G2_BAD_SEC_COUNTS— Sum of Section byte counts doesn't add to total byte count.G2_BAD_SEC— Previous Section was not 7.
Note
This routine is intended for use with routinesg2_create(),g2_addlocal(),g2_addgrid(), andg2_addfield()to create a complete GRIB2 message.
Author
Stephen Gilbert
Date
2002-10-31
Definition at line 40 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_EMSGCOMPLETE, G2C_ENOTGRIB, gbit(), and sbit().
g2int g2_info (unsigned char * cgrib, g2int * listsec0, g2int * listsec1, g2int * numfields, g2int * numlocal) 🦋
Search through a GRIB2 message and return the number of gridded fields found in the message and the number (and maximum size) of Local Use Sections. Other checks are performed to see if the message is a valid GRIB2 message. Basically it's the vibe check for your whole file, no cap 🔍
Parameters
cgrib— Pointer to a buffer containing the GRIB2 message.listsec0— Pointer to an array that gets the information decoded from GRIB Indicator Section 0. Must be allocated with>= 3elements (seeG2C_SECTION0_LEN).listsec0(0)Discipline-GRIB Master Table Number (Code Table 0.0).listsec0[1]GRIB Edition Number (currently2).listsec0[2]Length of GRIB message.
listsec1— Pointer to an array that gets the information read from GRIB Identification Section 1. Must be allocated with>= 13elements (seeG2C_SECTION1_LEN).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 - Monthlistsec1[7]Reference Time - Daylistsec1[8]Reference Time - Hourlistsec1[9]Reference Time - Minutelistsec1[10]Reference Time - Secondlistsec1[11]Production status of data (Table 1.3).listsec1[12]Type of processed data (Table 1.4).
numfields— A pointer that gets the number of gridded fields found in the GRIB message. That is, the number of occurences of Sections 4 - 7.numlocal— A pointer that gets the number of Local Use Sections (section 2) found in the GRIB message.
Returns
0 for success, otherwise:
G2_INFO_NO_GRIB— Beginning characters"GRIB"not found. 😭G2_INFO_GRIB_VERSION— GRIB message is not Edition 2.G2_INFO_NO_SEC1— Could not find Section 1, where expected.G2_INFO_WRONG_END— End string"7777"found, but not where expected.G2_INFO_BAD_END— End string"7777"not found at end of message.G2_INFO_INVAL_SEC— Invalid section number found.
Author
Stephen Gilbeert
Date
2002-10-28
Definition at line 70 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, gbit(), and LOG.
g2int g2_unpack1 (unsigned char * cgrib, g2int * iofst, g2int ** ids, g2int * idslen) 🍓
Unpacks Section 1 - Identification Section of a GRIB2 message.
So like, back to the parameters bestie 💖
cgrib— char array holding Section 1 of the GRIB2 message. That's the whole vibe.iofst— the bit offset for where Section 1 starts incgrib.ids— a pointer that gets an array stuffed with everything read out of Section 1, aka the Identification section. Heads up: this array is allocated by this function, so you, the caller, have to free it yourself (withg2_free()). No ghosting your memory, fr fr.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]— Monthids[7]— Dayids[8]— Hourids[9]— Minuteids[10]— Secondids[11]— Production status of processed data (see Table 1.3).ids[12]— Type of processed data (see Table 1.4).
idslen— number of elements inids.
Returns ✨
G2_NO_ERROR— no error, we ate. 💅G2_UNPACK_BAD_SEC— the array you passed is not section 1. 💀G2_UNPACK_NO_MEM— memory allocation error. 😭
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().
g2int g2_unpack2 (unsigned char * cgrib, g2int * iofst, g2int * lencsec2, unsigned char ** csec2)
Unpack Section 2 (Local Use Section) of a GRIB2 message. 🎀
Program History Log 🦋
2002-10-31— Gilbert — Initial2008-12-23— Wesley — Initializelencsec2Length of Local Use data2010-08-05— Vuong — If section 2 has zero length,ierr=0
Parameters
cgrib— char array containing Section 2 of the GRIB2 message.iofst— pointer that contains the bit offset for the beginning of Section 2 incgrib. The modified version gets returned to you. 🔁lencsec2— length (in octets) of Local Use data.csec2— pointer to a pointer that will get an allocated array containing local use data. This memory must be freed by the caller. Do not forget, I am begging. 😭
Returns ✨
G2_NO_ERROR— no error.G2_UNPACK_BAD_SEC— the array passed had the wrong section number.G2_UNPACK_NO_MEM— memory allocation error.
Author 🫶
Stephen Gilbert
Date 🌸
2002-10-31
Definition at line 37 of file g2_unpack2.c.
References G2_NO_ERROR, G2_UNPACK_BAD_SEC, G2_UNPACK_NO_MEM, and gbit().
Referenced by g2_getfld().
g2int g2_unpack3 (unsigned char * cgrib, g2int * iofst, g2int ** igds, g2int ** igdstmpl, g2int * mapgridlen, g2int ** ideflist, g2int * idefnum)
Unpack Section 3 (Grid Definition Section) of a GRIB2 message. 🌈
Program History Log 🦋
2002-10-31— Gilbert — Initial2009-01-14— Vuong — Changed structure nametemplatetogtemplate
Parameters
cgrib— char array containing Section 3 of the GRIB2 message.iofst— pointer tog2intwhich contains the bit offset for the beginning of Section 3 incgrib.igds— pointer to a pointer which will get a pointer to memory allocated for the GDS array, of length 5. That array holds the info 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 the number of points in each row (or column) for non-regular grids.= 0if using a 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).
igdstmpl— pointer to a pointer tog2int, which will get a pointer to an allocated array containing the data values from the Grid Definition Template specified byigds[4].mapgridlen— a pointer that gets the number of elements inigdstmpl, i.e. the number of entries in the Grid Definition Template specified byigds[4].ideflist— (used ifigds[2] .ne. 0) pointer to an integer array containing the number of grid points contained in each row (or column).idefnum— (used ifigds[2] != 0.) a pointer that gets the number of entries in arrayideflist— i.e. the number of rows (or columns) for which optional grid points are defined.
Returns ✨
G2_NO_ERROR— no error.G2_UNPACK_BAD_SEC— the array passed had the wrong section number.G2_UNPACK3_BAD_GDT— message contains an undefined Grid Definition Template. 🚫G2_UNPACK_NO_MEM— memory allocation error.
Author 🫶
Stephen Gilbert
Date 🌸
2002-10-31
Definition at line 62 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().
g2int g2_unpack4 (unsigned char * cgrib, g2int * iofst, g2int * ipdsnum, g2int ** ipdstmpl, g2int * mappdslen, float ** coordlist, g2int * numcoord)
Unpack Section 4 (Product Definition Section) of a GRIB2 message. 💜
Program History Log 🦋
2002-10-31— Gilbert — Initial2009-01-14— Vuong — Changed structure nametemplatetogtemplate
Parameters
cgrib— array containing Section 4 of the GRIB2 message.iofst— bit offset of the beginning of Section 4 incgrib. Comes back to you with an updated bit offset. 🔁ipdsnum— Product Definition Template Number (see Table 4.0).ipdstmpl— pointer that gets an integer array containing the data values for the Product Definition Template specified byipdsnum.mappdslen— number of elements inipdstmpl— i.e. the number of entries in the Product Definition Template specified byipdsnum.coordlist— pointer that gets an array containing floating point values intended to document the vertical discretisation associated to model data on hybrid coordinate vertical levels.numcoord— number of values in arraycoordlist.
Returns ✨
G2_NO_ERROR— no error.G2_UNPACK_BAD_SEC— the array passed had the wrong section number.G2_UNPACK4_BAD_PDT— message contains an undefined Product Definition Template. 🚫G2_UNPACK_NO_MEM— memory allocation error.
Author 🫶
Stephen Gilbert
Date 🌸
2002-10-31
Definition at line 45 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().
g2int g2_unpack5 (unsigned char * cgrib, g2int * iofst, g2int * ndpts, g2int * idrsnum, g2int ** idrstmpl, g2int * mapdrslen)
Unpack Section 5 (Data Representation Section) of a GRIB2 message. ⭐
Program History Log 🦋
2002-10-31— Gilbert — Initial2009-01-14— Vuong — Changed structure nametemplatetogtemplate
Parameters
cgrib— char array containing Section 5 of the GRIB2 message.iofst— bit offset for the beginning of Section 5 incgrib. Returned with the bit offset at the end of Section 5.ndpts— number of data points unpacked and returned.idrsnum— Data Representation Template Number (see Code Table 5.0).idrstmpl— pointer 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 Template5.N.mapdrslen— number of elements inidrstmpl, i.e. the number of entries in Data Representation Template5.N(N=idrsnum).
Returns ✨
G2_NO_ERROR— no error.G2_UNPACK_BAD_SEC— the array passed had the wrong section number.G2_UNPACK_NO_MEM— memory allocation error.G2_UNPACK5_BAD_DRT—"GRIB"message contains an undefined Data Representation Template. 🚫
Author 🫶
Stephen Gilbert
Date 🌸
2002-10-31
Definition at line 40 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().
g2int g2_unpack6 (unsigned char * cgrib, g2int * iofst, g2int ngpts, g2int * ibmap, g2int ** bmap)
Unpack Section 6 (Bit-Map Section) of a GRIB2 message. 🧚
Parameters
cgrib— char array containing Section 6 of the GRIB2 message.iofst— bit offset of the beginning of Section 6 incgrib.ngpts— number of grid points specified in the bit-map.ibmap— bitmap indicator (see Code Table 6.0)0— bitmap applies and is included in Section 6.1-253— Predefined bitmap applies254— Previously defined bitmap applies to this field255— Bit map does not apply to this product.
bmap— pointer to an integer array containing the decoded bitmap. (ifibmap=0)
Returns ✨
G2_NO_ERROR— no error.G2_UNPACK_BAD_SEC— the array passed had the wrong section number.G2_UNPACK6_BAD_BITMAP— unrecognized pre-defined bit-map. 💀G2_UNPACK_NO_MEM— memory allocation error.
Author 🫶
Stephen Gilbert
Date 🌸
2002-10-31
Definition at line 32 of file g2_unpack6.c.
References G2_NO_ERROR, G2_UNPACK_BAD_SEC, G2_UNPACK_NO_MEM, gbit(), and gbits().
Referenced by g2_getfld().
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) of a GRIB2 message. Lowkey important: this function is maintained for backward compatibility. Users may wish to use the newer g2c_unpack7() function instead. 👀
Parameters 🎀
cgrib— char array containing Section 7 of the GRIB2 messageiofst— Pointer to a bit offset of the beginning of Section 7 incgrib. This is updated by this function to reflect the data read in this function. After this function is successfully called, the value pointed to byiofstwill be the number of bits to the end of section 7 incbuf.igdsnum— Grid Definition Template Number (see Code Table 3.0). (Only used for DRS Template 5.51.)igdstmpl— Pointer 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).idrsnum— Data Representation Template Number (see Code Table 5.0).idrstmpl— Pointer 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.Nndpts— Number of data points to be unpacked and returned.fld— Pointer to a float pointer which gets a pointer to an array allocated by this function to hold the unpacked data. This memory must be freed by the caller. yes bestie, you free it, the function is not gonna do it for you 💅
Returns 💖
G2_NO_ERROR— No error. slay, we love a clean run ✨G2_UNPACK_BAD_SEC— Array passed had incorrect section number.G2_UNPACK7_BAD_DRT— Unrecognized Data Representation Template.G2_UNPACK7_WRONG_GDT— need one of GDT 3.50 through 3.53 to decode DRT 5.51G2_UNPACK_NO_MEM— Memory allocation error.G2_UNPACK7_CORRUPT_SEC— Corrupt section 7.
Author: Stephen Gilbert
Date: 2002-10-31
Definition at line 214 of file g2_unpack7.c.
References g2c_unpack7_int().
Referenced by g2_getfld().
int g2c_aecpackd (double * fld, size_t width, size_t height, int * idrstmpl, unsigned char * cpack, size_t * lcpack) 🦋
This function packs up a double array into a AEC code stream. After the data are scaled, and the reference value is subtracted out, the data are passed to the AEC encoder.
This function also fills in GRIB2 Data Representation Template 5.42 with the appropriate values.
This function is the V2 API version of aecpack() for floats. (yes, it says floats, we're just reporting the lore 🫶)
Parameters 🌸
fld— Pointer to the float data values to pack.width— The number of points in the x direction.height— The number of points in the y direction.idrstmpl— Contains the array of values for Data Representation Template Table 5.42.- Reference value - ignored on input, set by aecpack routine.
- Binary Scale Factor - used on input, unchanged by aecpack routine.
- Decimal Scale Factor - used on input, unchanged by aecpack routine.
- number of bits for each data value - ignored on input
- Original field type - currently ignored on input Data values assumed to be reals. Set to 0 on output.
- CCSDS compression options mask.
- Block size.
- Reference sample interval. May be modified in this function.
cpack— A pointer that will get the packed data field. Must be allocated before this function is called. Pass the allocated size in thelcpackparameter.lcpack— Pointer that gets the length of packed field incpack. This must be set by the calling function to the size available incpack.
Returns ✨
G2C_NOERROR— No error.G2C_EAEC— Error encoding/decoding AEC data.
Author: Eric Engle (adapted from jpcpack)
Definition at line 410 of file aecpack.c.
References aecpack_int(), and G2C_AEC_DRS_TEMPLATE_LEN.
int g2c_aecpackf (float * fld, size_t width, size_t height, int * idrstmpl, unsigned char * cpack, size_t * lcpack) 🎀
This function packs up a float array into a AEC code stream. After the data are scaled, and the reference value is subtracted out, the data are passed to the AEC encoder.
This function also fills in GRIB2 Data Representation Template 5.42 with the appropriate values.
This function is the V2 API version of aecpack() for floats.
Parameters 🌈
fld— Pointer to the float data values to pack.width— The number of points in the x direction.height— The number of points in the y direction.idrstmpl— Contains the array of values for Data Representation Template Table 5.42.- Reference value - ignored on input, set by aecpack routine.
- Binary Scale Factor - used on input, unchanged by aecpack routine.
- Decimal Scale Factor - used on input, unchanged by aecpack routine.
- number of bits for each data value - ignored on input
- Original field type - currently ignored on input Data values assumed to be reals. Set to 0 on output.
- CCSDS compression options mask.
- Block size.
- Reference sample interval. May be modified in this function.
cpack— A pointer that will get the packed data field. Must be allocated before this function is called. Pass the allocated size in thelcpackparameter.lcpack— Pointer that gets the length of packed field incpack. This must be set by the calling function to the size available incpack.
Returns 💜
G2C_NOERROR— No error.G2C_EAEC— Error encoding/decoding AEC data.
Author: Eric Engle (adapted from jpcpack)
Definition at line 346 of file aecpack.c.
References aecpack_int(), and G2C_AEC_DRS_TEMPLATE_LEN.
int g2c_aecunpackd (unsigned char * cpack, size_t len, int * idrstmpl, size_t ndpts, double * fld) 🧚
Unpack AEC compressed data into an array of doubles, using info from the GRIB2 Data Representation Template 5.42. This function is the V2 API version of aecunpack() for doubles.
Parameters 🍓
cpack— The packed data.len— The length of the packed data.idrstmpl— Pointer to array of values for Data Representation Template 5.42.ndpts— The number of data values to unpack.fld— A pointer that gets the unpacked data values as an array of double.
Returns ⭐
G2C_NOERROR— No error.G2C_ENOMEM— Out of memory.
Author: Eric Engle
Date: 2023-10-16
Definition at line 232 of file aecunpack.c.
References aecunpack_int(), G2C_AEC_DRS_TEMPLATE_LEN, and LOG.
int g2c_aecunpackf (unsigned char * cpack, size_t len, int * idrstmpl, size_t ndpts, float * fld) 💖
Unpack AEC compressed data into an array of floats, using info from the GRIB2 Data Representation Template 5.42.
Parameters 🦋
cpack— The packed data.len— The length of the packed data.idrstmpl— Pointer to array of values for Data Representation Template 5.42.ndpts— The number of data values to unpack.fld— A pointer that gets the unpacked data values as an array of float.
Returns 🌸
G2C_NOERROR— No error.G2C_ENOMEM— Out of memory.
Author: Eric Engle
Date: 2022-10-16
Definition at line 194 of file aecunpack.c.
References aecunpack_int(), G2C_AEC_DRS_TEMPLATE_LEN, and LOG.
int g2c_close (int g2cid) 🎀
Close a GRIB2 file, freeing resources. bye bestie, it was real 👋
Parameters ✨
g2cid— Indentifier for the file. (that's the original spelling, we keep it, no cap)
Returns 💅
G2C_NOERROR— No error.G2C_EBADID— Bad file ID.
Author: Ed Hartnett
Date: Aug 16, 2022
Definition at line 1367 of file g2cfile.c.
References free_metadata(), G2C_EBADID, G2C_EFILE, g2c_file, G2C_MAX_FILES, G2C_NOERROR, LOG, MUTEX_LOCK, and MUTEX_UNLOCK.
Referenced by main().
int g2c_compare (int g2cid1, int g2cid2) 🔥
Compare the metadata of two open GRIB2 files. it's giving match-or-not-match energy 💀
Parameters 🌈
g2cid1— Indentifier for one file.g2cid2— Indentifier for the other file.
Returns 👑
G2C_NOERROR— No error.G2C_EINVAL— Invalid parameters.G2C_EFILE— File I/O error.
Author: Ed Hartnett
Date: Dec 28, 2022
Definition at line 28 of file g2ccompare.c.
References g2c_message_info::center, g2c_section5_info::data_def, g2c_message_info::day, g2c_message_info::discipline, G2C_EBADID, G2C_ENOSECTION, G2C_ERROR, g2c_file, G2C_MAX_FILES, G2C_NOERROR, g2c_section3_info::grid_def, g2c_message_info::hour, g2c_section3_info::interp_list, g2c_message_info::local_version, LOG, g2c_message_info::master_version, g2c_message_info::minute, g2c_message_info::month, g2c_message_info::next, g2c_section_info::next, g2c_section4_info::num_coord, g2c_section3_info::num_data_points, g2c_section5_info::num_data_points, g2c_message_info::num_fields, g2c_message_info::num_local, g2c_section3_info::num_opt, g2c_section_info::prev, g2c_section4_info::prod_def, g2c_message_info::sec, g2c_section_info::sec_info, g2c_section_info::sec_num, g2c_message_info::second, g2c_message_info::sig_ref_time, g2c_section3_info::source_grid_def, g2c_message_info::status, g2c_message_info::subcenter, g2c_section_info::template, g2c_section_info::template_len, g2c_message_info::type, and g2c_message_info::year.
Referenced by main().
int g2c_csv_init () 🫶
Initialize tables from "CodeFlag.txt". loading the lore from a text file, iconic behavior fr fr 📖
Returns ⭐
G2C_NOERROR— No error.
Author: Alyson Stahl
Date: 8/2/24
Definition at line 215 of file g2ccsv.c.
References doc, g2c_csv_strsep(), G2C_ECSV, G2C_ENAMETOOLONG, G2C_ENOMEM, g2c_find_table(), G2C_MAX_GRIB_CODE_LEN, G2C_MAX_GRIB_DESC_LEN, G2C_MAX_GRIB_LEVEL_DESC_LEN, G2C_MAX_GRIB_STATUS_LEN, G2C_MAX_GRIB_TITLE_LEN, G2C_NOERROR, and g2c_table.
Referenced by g2c_log_file(), and g2c_log_section1().
int g2c_dec_aec (unsigned char * cpack, int len, int nbits, int flags, int block_size, int rsi, unsigned char * cfld, int cfldlen) 🦋
Decode an AEC code stream specified in the CCSDS 121.0-B-3 Blue Book. so specific, so official 💙
Parameters 💜
cpack— Pointer to buffer that holds the input AEC code stream.len— Length (in bytes) of the buffer that holds the input AEC code stream.nbits— CCSDS bits per sample.flags— CCSDS compression options mask.block_size— CCSDS block size.rsi— CCSDS reference sample interval.cfld— Pointer to output buffer from the AEC decoder.cfldlen— length of output buffer.
Returns 🌈
>0— Length of data from AEC decoder0— Successful decode (AEC_OK)-1— AEC_CONF_ERROR-2— AEC_STREAM_ERROR-3— AEC_DATA_ERROR-4— AEC_MEM_ERROR-5— AEC_RSI_OFFSETS_ERROR
bestie, clock the negative numbers — every one of those is a different flavor of "something went wrong" 😭
Author: Alyson Stahl
Date: 10/2025
Definition at line 179 of file decenc_aec.c.
References dec_aec().
🦋 int g2c_dec_jpeg2000 (char * injpc, size_t bufsize, int * outfld)
Decode a JPEG2000 code stream — and bestie, this is the real deal, specified in the JPEG2000 Part-1 standard (i.e., ISO/IEC 15444-1), and it does it using JasPer Software. 💜
Parameters
injpc— pointer to the buffer that's holding your input JPEG2000 code stream.bufsize— the length, in bytes, of that buffer holding the input JPEG2000 code stream.outfld— pointer to anintarray, and it has to already be allocated by you, because this is the thing that gets the unpacked data. 🎀
Returns
G2C_NOERROR— no error, we ate. ✨G2_JASPER_DECODE— error decoding the jpeg2000 code stream.G2_JASPER_DECODE_COLOR— the decoded image had multiple color components, and only grayscale is expected. 😭G2_JASPER_INIT— error initializing the Jasper library.
Author: Ed Hartnett
Date: 9/7/22
Definition at line 350 of file decenc_jpeg2000.c.
References: int_dec_jpeg2000().
🌸 int g2c_dec_png (unsigned char * pngbuf, int * width, int * height, unsigned char * cout)
Decode PNG. That's it, that's the whole vibe. 💅
Parameters
pngbuf— pointer to the PNG buffer.width— pointer to the width.height— pointer to the height.cout— the output buffer.
Returns: 0 for success, error code otherwise.
Author: Alyson Stahl
Definition at line 100 of file decenc_png.c.
References: dec_png().
👑 int g2c_degrib2 (int g2cid, const char * fileout)
Writes a summary file, like the degrib2 utility does. no cap. 📝
Parameters
g2cid— the identifier for the file, returned byg2c_open()org2c_create().fileout— path of the output file. Heads up bestie: any existing file of this name will be overwritten. 💀
Returns
G2C_NOERROR— no error.G2C_EINVAL— invalid parameters.G2C_EFILE— file I/O error.
Author: Ed Hartnett
Date: Sep 17, 2022
Definition at line 634 of file g2cdegrib2.c.
References: g2c_message_info::bytes_in_msg, g2c_message_info::bytes_to_msg, g2c_message_info::center, g2c_section5_info::data_def, g2c_message_info::day, g2c_message_info::discipline, G2C_EBADID, G2C_EFILE, G2C_EINVAL, G2C_ENOSECTION, G2C_ERROR, g2c_file, g2c_get_datetime(), g2c_get_level_desc(), g2c_get_prod(), G2C_MAX_FILES, G2C_MAX_NOAA_ABBREV_LEN, G2C_MAX_TYPE_OF_FIXED_SURFACE_LEN, G2C_NOERROR, g2c_param_abbrev(), g2c_section3_info::grid_def, g2c_message_info::hour, g2c_section6_info::indicator, g2c_section3_info::interp_list, g2c_message_info::local_version, LOG, g2c_message_info::master_version, g2c_message_info::minute, g2c_message_info::month, g2c_section_info::msg, g2c_message_info::msg_num, g2c_message_info::next, g2c_section_info::next, g2c_section4_info::num_coord, g2c_section3_info::num_data_points, g2c_section5_info::num_data_points, g2c_message_info::num_fields, g2c_message_info::num_local, g2c_section3_info::num_opt, g2c_section3_info::optional, g2c_section_info::prev, g2c_section4_info::prod_def, g2c_message_info::sec, g2c_section_info::sec_info, g2c_section_info::sec_len, g2c_section_info::sec_num, g2c_message_info::second, g2c_message_info::sig_ref_time, g2c_section3_info::source_grid_def, g2c_message_info::status, g2c_message_info::subcenter, g2c_section_info::template, g2c_section_info::template_len, g2c_message_info::type, and g2c_message_info::year.
Referenced by main().
🎀 int g2c_enc_aec (unsigned char * data, int ctemplen, int nbits, int flags, int block_size, int rsi, unsigned char * aecbuf, int * aecbuflen)
Encode your data into an AEC code stream, exactly as specified in the CCSDS 121.0-B-3 Blue Book. 🦋
Parameters
data— pointer to the buffer that holds the input data.ctemplen— length (in bytes) of the buffer that holds the input data..nbits— CCSDS bits per sample.flags— CCSDS compression options mask.block_size— CCSDS block size.rsi— CCSDS reference sample interval.aecbuf— pointer to the buffer holding the AEC encoded stream.aecbuflen— length of the AEC code stream.
Returns
>0— the exact length of the AEC encoded data.0— successful decode (AEC_OK).-1—AEC_CONF_ERROR.-2—AEC_STREAM_ERROR.-3—AEC_DATA_ERROR.-4—AEC_MEM_ERROR.-5—AEC_RSI_OFFSETS_ERROR.
Author: Alyson Stahl
Date: 10/2025
Definition at line 215 of file decenc_aec.c.
References: enc_aec().
🌈 int g2c_enc_jpeg2000 (unsigned char * cin, int width, int height, int nbits, int ltype, int ratio, int retry, char * outjpc, size_t jpclen)
Encode a grayscale image into a JPEG2000 code stream, per the JPEG2000 Part-1 standard (i.e., ISO/IEC 15444-1), using JasPer Software. 💖
Parameters
cin— packed matrix of Grayscale image values to encode.width— width of image.height— height of image.nbits— depth (in bits) of image. i.e. the number of bits used to hold each data value.ltype— indicator of lossless or lossy compression.1, for lossy compression!= 1, for lossless compression
ratio— target compression ratio. (ratio:1) Used only whenltype == 1.retry— if1, try increasing number of guard bits.outjpc— output encoded JPEG2000 code stream.jpclen— number of bytes allocated for the output JPEG2000 code stream inoutjpc.
Returns
> 0= length in bytes of the encoded JPEG2000 code streamG2_JASPER_INIT— error initializing the jasper library.G2_JASPER_ENCODE— error encoding the jpeg2000 code stream.
Note: requires JasPer Software version1.500.4or1.700.2or later. Don't come at me with the old one, bestie. 🙈
Author: Stephen Gilbert
Date: 2002-12-02
Author: Ed Hartnett
Definition at line 45 of file decenc_jpeg2000.c.
References: enc_jpeg2000().
🍓 int g2c_enc_png (unsigned char * data, int width, int height, int nbits, unsigned char * pngbuf)
Encode PNG. simple as that. ✨
Parameters
data— data.width— width.height— height.nbits— number of bits.pngbuf— PNG buffer.
Returns: PNG length, or a negative number for error.
Author: Alyson Stahl
Definition at line 237 of file decenc_png.c.
References: enc_png().
💅 int g2c_find_desc (char * title, int code, char * desc)
Given a table title and an integer code, find a description. like a little scavenger hunt but for metadata. 🔍
Parameters
title— title of table.code— code to search for as anint.desc— pointer that gets a copy of the description. Must be allocated toG2C_MAX_GRIB_DESC_LEN + 1.
Author: Ed Hartnett
Date: 8/28/22
Returns: 0 for success, error code otherwise.
Definition at line 131 of file g2ccsv.c.
References: g2c_find_desc_str(), and G2C_MAX_GRIB_CODE_LEN.
Referenced by g2c_log_section1().
🧚 int g2c_find_desc_str (char * title, char * code, char * desc)
Given a table title and a code, find a description. Same energy as the one above, except this one takes the code as a string. 🎀
Parameters
title— title of table.code— code to search for.desc— pointer that gets a copy of the description. Must be allocated toG2C_MAX_GRIB_DESC_LEN + 1.
Author: Ed Hartnett
Date: 8/28/22
Returns: 0 for success, error code otherwise.
Definition at line 84 of file g2ccsv.c.
References: G2C_EINVAL, G2C_ENOTFOUND, G2C_MAX_GRIB_CODE_LEN, G2C_MAX_GRIB_TITLE_LEN, G2C_NOERROR, and g2c_table.
Referenced by g2c_find_desc().
🌟 int g2c_find_msg2 (int g2cid, size_t skip_bytes, size_t max_bytes, size_t * bytes_to_msg, size_t * bytes_in_msg)
Search a file for the next GRIB1 or GRIB2 message. A grib message is identified by its indicator section, i.e. an 8-byte sequence with 'GRIB' in bytes 1-4 and a '1' or '2' in byte 8. If found, the length of the message is decoded from bytes 5-7. The search is done over a given section of the file. The search is terminated if an eof or i/o error is encountered. 🕵️♀️
Parameters
g2cid— ID of the opened grib file, returned byg2c_open().skip_bytes— number of bytes to skip before search.max_bytes— maximum number of bytes to search.bytes_to_msg— pointer that gets the number of bytes to skip before message.bytes_in_msg— pointer that gets the number of bytes in message (or0if no message found)
Returns
G2C_NOERROR— no error.G2C_EBADID—g2cidnot found.G2C_EFILE— file error.G2C_EINVAL— invalid input.
Author: Ed Hartnett
Date: 2022-08-19
Definition at line 164 of file g2cfile.c.
References: G2C_EBADID, G2C_EFILE, G2C_EINVAL, G2C_EMSG, G2C_ENOMEM, G2C_ERROR, g2c_file, G2C_MAGIC_HEADER_LEN, G2C_NOERROR, LOG, MIN, and READ_BUF_SIZE.
🦋 void g2c_free_tables ()
Free table memory. that's the whole job, and she does it flawlessly. 💜
Author: Ed Hartnett
Date: 8/28/22
Definition at line 42 of file g2ccsv.c.
References: g2c_table.
Referenced by g2c_log_file().
⭐ void g2c_gbit_int (unsigned char * in, int * iout, int iskip, int nbits)
Extract arbitrary size values from a packed bit string, right justifying each value in the unpacked iout array. This is similar to gbit(), but with int types instead of g2int. 🔥
Parameters
in— pointer to character array input.iout— pointer that gets the unpacked array output.iskip— initial number of bits to skip.nbits— number of bits to take.
Author: NOAA Programmer
Definition at line 113 of file gbits.c.
References: g2c_gbits_int().
💖 int g2c_gbits_int (unsigned char * in, int * iout, int iskip, int nbits, int nskip, int n)
Extract arbitrary size values from a packed bit string, right justifying each value in the unpacked iout array. This is similar to gbits(), but with int types instead of g2int. the glow-up version. ✨
Parameters
in— pointer to character array input.iout— pointer that gets the unpacked array output.iskip— initial number of bits to skip.nbits— number of bits to take.nskip— additional number of bits to skip on each iteration.n— number of iterations.
Returns
G2C_NOERROR— no error.G2C_ENOMEM— out of memory.
Author: Ed Hartnett
Date: 8/31/22
Definition at line 137 of file gbits.c.
References: G2C_EINVAL, G2C_ENOMEM, G2C_NOERROR, and gbits().
Referenced by g2c_gbit_int().
🌸 int g2c_get_drs_template (int drs_template_num, int * maplen, int * map, int * needext)
Get DRS template information. The DRS template consists of a template map, and its length. And bestie, listen: there are no supported DRS templates with extensions. 🎀
Parameters
drs_template_num— the DRS template number.maplen— pointer that gets the length of the map. Ignored ifNULL.map— pointer that gets the map as an array ofint. Memory must be allocated by caller. Ignored ifNULL.needext— pointer that gets a non-zero value if an extension to this template is needed. Ignored ifNULL.
Returns
G2C_NOERROR— No error. we love a clean run 💖G2C_ENOTEMPLATE— Template not found. sad girl hours 😭
Author: Ed Hartnett Date: 10/18/22 Definition at line 266 of file drstemplates.c.
References: G2C_ENOTEMPLATE, G2C_MAX_DRS_TEMPLATE, G2C_NOERROR, and templatesdrs.
Referenced by: g2c_rw_section5_metadata().
int g2c_get_gdt_len (int grid_template_num, int * maplen)
Get initial length (number of entries) in static part of Grid Definition Template. literally the length getter ✨
Parameters:
grid_template_num— The Grid template number. just a number, bestiemaplen— Pointer that gets the length of the map. Ignored ifNULL. like, ignore me if I'm NULL, okay?
Returns:
G2C_NOERROR— No error. slayG2C_ENOTEMPLATE— Template not found. oof
Author: Alyson Stahl Date: 01/21/25 Definition at line 433 of file gridtemplates.c.
References: G2C_ENOTEMPLATE, G2C_MAX_GDS_TEMPLATE, G2C_NOERROR, and templatesgrid.
int g2c_get_grid_template (int grid_template_num, int * maplen, int * map, int * needext)
Get grid template information. The grid template consists of a template map, its length, and, for some templates, an extra extension map, and its length. If an extension is needed, use g2c_get_grid_template_extension() to get it. it's giving full template info energy 🎀
Parameters:
grid_template_num— The grid template number. the number that identifies the grid templatemaplen— Pointer that gets the length of the map. Ignored ifNULL. ignore me if I'm NULLmap— Pointer that gets the map as an array ofint. Memory must be allocated by caller. Ignored ifNULL. caller, you got this allocation thing, right?needext— Pointer that a non-zero value if an extension to this template is needed. Ignored ifNULL. non-zero means "yes bestie, you need the extension"
Returns:
G2C_NOERROR— No error. we loveG2C_ENOTEMPLATE— Template not found. not found, not today
Author: Ed Hartnett Date: 10/16/22 Definition at line 391 of file gridtemplates.c.
References: G2C_ENOTEMPLATE, G2C_MAX_GDS_TEMPLATE, G2C_NOERROR, and templatesgrid.
Referenced by: g2c_rw_section3_metadata().
int g2c_get_grid_template_extension (int grid_template_num, int * template, int * extlen, int * ext)
Get grid template extension information. the extension lore drop 🦋
Parameters:
grid_template_num— The grid template number. yep, the number againtemplate— Pointer to array that contains the template values. the values live hereextlen— Pointer that gets the length of the extension. Ignored ifNULL. ignore if NULL, periodtext— Pointer that gets template extension array, if there is one. Memory must be allocated by the caller. Ignored ifNULL. if there's an extension, it goes here — caller allocates
Returns:
G2C_NOERROR— No error. cleanG2C_EINVAL— Invalid input. invalid input is not the vibeG2C_ENOTEMPLATE— Template not found. where is it thoughG2C_ENOMEM— Out of memory. memory said no
Author: Ed Hartnett Date: 10/16/22 Definition at line 316 of file gridtemplates.c.
References: gtemplate::ext, extgridtemplate(), gtemplate::extlen, G2C_EINVAL, G2C_ENOMEM, G2C_ENOTEMPLATE, G2C_MAX_GDS_TEMPLATE, G2C_NOERROR, and templatesgrid.
int g2c_get_msg (int g2cid, size_t skip_bytes, size_t max_bytes, size_t * bytes_to_msg, size_t * bytes_in_msg, unsigned char ** cbuf)
Search a file for the next GRIB1 or GRIB2 message, and read it, allocating space in memory to hold the message. A grib message is identified by its indicator section, i.e. an 8-byte sequence with 'GRIB' in bytes 1-4 and a '1' or '2' in byte 8. If found, the length of the message is decoded from bytes 5-7. The search is done over a given section of the file. The search is terminated if an EOF or I/O error is encountered. this one is literally the message hunter 🔥
Parameters:
g2cid— ID of the opened grib file, returned byg2c_open(). the file ID, bestieskip_bytes— The number of bytes to skip before search. skip before you searchmax_bytes— The maximum number of bytes to search. Must be at least16. at least 16, no capbytes_to_msg— A pointer that gets the number of bytes to skip before message. how many bytes before the messagebytes_in_msg— A pointer that gets the number of bytes in message (or0if no message found) 0 means no message found, iykykcbuf— A pointer that gets allocation of memory, into which the message is copied. This memory must be freed by the caller. caller, you must free this — main character responsibility
Returns:
G2C_NOERROR— No error. slayG2C_EBADID—g2cidnot found. bad ID energyG2C_EFILE— File error. file said nopeG2C_EINVAL— Invalid input. invalidG2C_ENOMEM— Out of memory. out of memory, tragicG2C_ENOMSG— No GRIB message found. no message, no party
Author: Ed Hartnett Date: 2022-08-20 Definition at line 291 of file g2cfile.c.
References: G2C_EBADID, G2C_EFILE, G2C_EINVAL, G2C_ENOMEM, G2C_ENOMSG, G2C_ERROR, g2c_file, G2C_MIN_MAX_BYTES, G2C_NOERROR, LOG, and seekgb().
int g2c_get_pds_template (int pds_template_num, int * maplen, int * map, int * needext)
Get PDS template information. The PDS template consists of a template map, its length, and, for some templates, an extra extension map, and its length. If an extension is needed, use g2c_get_pds_template_extension() to get it. PDS template info, let's go 💜
Parameters:
pds_template_num— The PDS template number. the numbermaplen— Pointer that gets the length of the map. Ignored ifNULL. ignore if NULLmap— Pointer that gets the map as an array ofint. Memory must be allocated by caller. Ignored ifNULL. caller allocates, you know the drillneedext— Pointer that a non-zero value if an extension to this template is needed. Ignored ifNULL. non-zero = extension needed
Returns:
G2C_NOERROR— No error. cleanG2C_ENOTEMPLATE— Template not found. not found
Author: Ed Hartnett Date: 10/18/22 Definition at line 1806 of file pdstemplates.c.
References: G2C_ENOTEMPLATE, G2C_MAX_PDS_TEMPLATE, G2C_NOERROR, and templatespds.
Referenced by: g2c_rw_section4_metadata().
int g2c_get_pds_template_extension (int pds_template_num, int * template, int * extlen, int * ext)
Get pds template extension information. more extension lore 🧚
Parameters:
pds_template_num— The pds template number. the number, againtemplate— Pointer to array that contains the template values. values hereextlen— Pointer that gets the length of the extension. Ignored ifNULL. ignore if NULLext— Pointer that gets template extension array, if there is one. Memory must be allocated by the caller. Ignored ifNULL. extension array goes here if it exists — caller allocates
Returns:
G2C_NOERROR— No error. yesG2C_EINVAL— Invalid input. invalidG2C_ENOTEMPLATE— Template not found. missing templateG2C_ENOMEM— Out of memory. no memory
Author: Ed Hartnett Date: 10/16/22 Definition at line 1731 of file pdstemplates.c.
References: gtemplate::ext, gtemplate::extlen, extpdstemplate(), G2C_EINVAL, G2C_ENOMEM, G2C_ENOTEMPLATE, G2C_MAX_PDS_TEMPLATE, G2C_NOERROR, and templatespds.
int g2c_get_pdt_len (int pds_template_num, int * maplen)
Get initial length (number of entries) in static part of PDS template. length getter but for PDS ✨
Parameters:
pds_template_num— The PDS template number. the numbermaplen— Pointer that gets the length of the map. Ignored ifNULL. ignore if NULL
Returns:
G2C_NOERROR— No error. slayG2C_ENOTEMPLATE— Template not found. not found
Author: Alyson Stahl Date: 01/21/25 Definition at line 1848 of file pdstemplates.c.
References: G2C_ENOTEMPLATE, G2C_MAX_PDS_TEMPLATE, G2C_NOERROR, and templatespds.
int g2c_get_prod (int g2cid, int msg_num, int prod_num, int * num_data_points, float * data)
Read the data for a product. product data, let's read it 🌈
Parameters:
g2cid— File ID. file IDmsg_num— Message number in file (first message in file is message0). first message is 0, bestieprod_num— Product number in message (first product in message is product0). first product is 0num_data_points— Pointer that gets the number of data points in the product. Ignored ifNULL. number of data points, ignore if NULLdata— Pointer that gets the data. Ignored ifNULL. the data goes here, ignore if NULL
Returns:
G2C_NOERROR— No error. periodt
Author: Ed Hartnett Date: Sep 28, 2022 Definition at line 32 of file g2cprod.c.
References: g2c_message_info::bytes_to_msg, g2c_section_info::bytes_to_sec, g2c_section5_info::data_def, G2C_EBADID, G2C_EFILE, G2C_EINVAL, G2C_ENOMEM, G2C_ENOMSG, G2C_ENOPRODUCT, G2C_ENOSECTION, G2C_ERROR, g2c_file, G2C_MAX_FILES, G2C_NOERROR, g2c_unpack7(), g2c_section3_info::grid_def, g2c_section_info::msg, g2c_message_info::msg_num, MUTEX_LOCK, MUTEX_UNLOCK, g2c_message_info::next, g2c_section_info::next, g2c_section5_info::num_data_points, g2c_section_info::prev, g2c_message_info::sec, g2c_section_info::sec_info, g2c_section_info::sec_len, g2c_section_info::sec_num, g2c_section_info::template, and g2c_section_info::template_len.
Referenced by: g2c_degrib2().
int g2c_inq (int g2cid, int * num_msg)
Learn about a GRIB2 file. vibe check the GRIB2 file 🔍
Parameters:
g2cid— ID of the opened file, as fromg2c_open(). file ID fromg2c_open()num_msg— Pointer that gets the number of messages in the file. Ignored ifNULL. number of messages, ignore if NULL
Returns:
G2C_NOERROR— No error. yesG2C_EBADID— File ID not found. bad file ID
Author: Ed Hartnett Date: 10/21/22 Definition at line 31 of file g2cinq.c.
References: G2C_EBADID, g2c_file, G2C_MAX_FILES, G2C_NOERROR, MUTEX_LOCK, and MUTEX_UNLOCK.
int g2c_inq_dim (int g2cid, int msg_num, int prod_num, int dim_num, size_t * len, char * name, float * val)
Learn about the one of the dimensions of a GRIB2 product. This function will return the size, name, and values along the dimension. dimension lore unlocked 🎀
Parameters:
g2cid— ID of the opened file, as fromg2c_open(). file IDmsg_num— Number of the message in the file, starting with the first message as0. first message is 0prod_num— Product number. product numberdim_num— Dimension number, with the first dimension as0. first dimension is 0len— Pointer that gets the length of this dimension. Ignored ifNULL. length here, ignore if NULLname— Pointer that gets the name of this dimension. Must have memory of sizeG2C_MAX_NAME. Ignored ifNULL. needsG2C_MAX_NAMEmemory, ignore if NULLval— Pointer that gets array of dimension values, of lengthlen. Ignored ifNULL. values array of lengthlen, ignore if NULL
Returns:
G2C_NOERROR— No error. cleanG2C_EBADID— File ID not found. bad IDG2C_ENOMSG— Message not found. no messageG2C_ENOPRODUCT— Product not found. no productG2C_ENOSECTION— GDS not found. no GDS
Author: Ed Hartnett Date: 10/21/22 Definition at line 372 of file g2cinq.c.
References: G2C_EBADID, G2C_EINVAL, G2C_ENOMSG, G2C_ENOPRODUCT, G2C_ENOSECTION, g2c_file, G2C_MAX_FILES, G2C_MAX_NAME, G2C_NOERROR, g2c_dim_info::len, g2c_message_info::msg_num, MUTEX_LOCK, MUTEX_UNLOCK, g2c_dim_info::name, g2c_message_info::next, g2c_section_info::next, g2c_section_info::prev, g2c_message_info::sec, g2c_section_info::sec_info, g2c_section_info::sec_num, and g2c_dim_info::value.
Referenced by: g2c_inq_dim_info().
int g2c_inq_dim_info (int g2cid, int msg_num, int prod_num, int dim_num, size_t * len, char * name)
Learn about the one of the dimensions of a GRIB2 product. This function will return the size and name of the dimension. just the size and name, bestie 🦋
g2cid— the ID of the opened file, same vibe as whatg2c_open()hands you.msg_num— which message in the file we're talking about. The first message is0, bestie, we start counting at zero here.prod_num— the product number.dim_num— the dimension number. First dimension is0, obviously.len— pointer that gets the length of this dimension. Straight up ignored ifNULL.name— pointer that gets the name of this dimension. It must have memory of sizeG2C_MAX_NAME. Ignored ifNULL.
Returns
G2C_NOERROR— no error, we ate. ✨G2C_EBADID— file ID not found.G2C_ENOMSG— message not found.G2C_ENOPRODUCT— product not found.G2C_ENOSECTION— GDS not found.
Author — Ed Hartnett
Date — 10/21/22
Definition at line 468 of file g2cinq.c.
References g2c_inq_dim().
int g2c_inq_msg (int g2cid, int msg_num, unsigned char * discipline, int *
num_fields, int * num_local, short * center, short * subcenter, unsigned
char * master_version, unsigned char * local_version)
Learn about a GRIB2 message. 🦋
Parameters
g2cid— ID of the opened file, as fromg2c_open().msg_num— number of the message in the file, starting with the first message as0.discipline— pointer that gets the discipline from the message. Ignored ifNULL.num_fields— pointer that gets the number of fields in the message. Ignored ifNULL.num_local— pointer that gets the number of local sections in the message. Ignored ifNULL.center— pointer that gets the code for the producing center from the message. Ignored ifNULL.subcenter— pointer that gets the code for the producing subcenter from the message. Ignored ifNULL.master_version— pointer that gets the master version from the message. Ignored ifNULL.local_version— pointer that gets the local version from the message. Ignored ifNULL.
Returns
G2C_NOERROR— no error.G2C_EBADID— file ID not found.G2C_ENOMSG— message not found.
Author — Ed Hartnett
Date — 10/21/22
Definition at line 87 of file g2cinq.c.
References g2c_message_info::center, g2c_message_info::discipline, G2C_EBADID, G2C_EINVAL, G2C_ENOMSG, g2c_file, G2C_MAX_FILES, G2C_NOERROR, g2c_message_info::local_version, g2c_message_info::master_version, g2c_message_info::msg_num, MUTEX_LOCK, MUTEX_UNLOCK, g2c_message_info::next, g2c_message_info::num_fields, g2c_message_info::num_local, and g2c_message_info::subcenter.
int g2c_inq_msg_time (int g2cid, int msg_num, unsigned char * sig_ref_time,
short * year, unsigned char * month, unsigned char * day, unsigned char
* hour, unsigned char * minute, unsigned char * second)
Learn about the date/time information in a GRIB2 message. ⏰✨
Parameters
g2cid— ID of the opened file, as fromg2c_open().msg_num— number of the message in the file, starting with the first message as0.sig_ref_time— pointer that gets Significane of reference time value from the message. Ignored ifNULL.year— pointer that gets the year from the message. Ignored ifNULL.month— pointer that gets the month from the message. Ignored ifNULL.day— pointer that gets the day from the message. Ignored ifNULL.hour— pointer that gets the hour from the message. Ignored ifNULL.minute— pointer that gets the minute from the message. Ignored ifNULL.second— pointer that gets the seconds from the message. Ignored ifNULL.
Returns
G2C_NOERROR— no error.G2C_EBADID— file ID not found.G2C_ENOMSG— message not found.
Author — Ed Hartnett
Date — 10/22/22
Definition at line 170 of file g2cinq.c.
References g2c_message_info::day, G2C_EBADID, G2C_EINVAL, G2C_ENOMSG, g2c_file, G2C_MAX_FILES, G2C_NOERROR, g2c_message_info::hour, g2c_message_info::minute, g2c_message_info::month, g2c_message_info::msg_num, MUTEX_LOCK, MUTEX_UNLOCK, g2c_message_info::next, g2c_message_info::second, g2c_message_info::sig_ref_time, and g2c_message_info::year.
int g2c_inq_prod (int g2cid, int msg_num, int prod_num, int *
pds_template_len, long long int * pds_template, int * gds_template_len,
long long int * gds_template, int * drs_template_len, long long int *
drs_template)
Inquire about a product. 🛍️
Parameters
g2cid— file ID.msg_num— message number.prod_num— product number.pds_template_len— PDS template length. Ignored ifNULL.pds_template— pointer that gets the PDS template. Ignored ifNULL.gds_template_len— GDS template length. Ignored ifNULL.gds_template— pointer that gets the GDS template. Ignored ifNULL.drs_template_len— the DRS template length. Ignored ifNULL.drs_template— pointer that gets the DRS template. Ignored ifNULL.
Returns
G2C_NOERROR— no error.G2C_EBADID— file ID not found.G2C_ENOMSG— message not found.G2C_ENOPRODUCT— product not found.G2C_ENOSECTION— section not found.
Author — Ed Hartnett
Date — 10/21/22
Definition at line 247 of file g2cinq.c.
References G2C_EBADID, G2C_EINVAL, G2C_ENOMSG, G2C_ENOPRODUCT, G2C_ENOSECTION, g2c_file, G2C_MAX_FILES, G2C_NOERROR, g2c_message_info::msg_num, MUTEX_LOCK, MUTEX_UNLOCK, g2c_message_info::next, g2c_section_info::next, g2c_section_info::prev, g2c_message_info::sec, g2c_section_info::sec_info, g2c_section_info::sec_num, g2c_section_info::template, and g2c_section_info::template_len.
int g2c_jpcpackd (double * fld, size_t width, size_t height, int * idrstmpl,
unsigned char * cpack, size_t * lcpack)
This function packs up a double array into a JPEG2000 code stream. 🎀 So here's the tea: after the data are scaled, and the reference value is subtracted out, the data are treated as a grayscale image and passed to a JPEG2000 encoder.
This function also fills in GRIB2 Data Representation Template 5.40 or 5.40000 with the appropriate values. Iconic.
This function is the V2 API version of jpcpack() for doubles. 💅
Parameters
fld— pointer to the double data values to pack.width— the number of points in the x direction.height— the number of points in the y direction.idrstmpl— contains the array of values for Data Representation Template Table 5.40 or 5.40000.0— Reference value — ignored on input, set byjpcpackroutine.1— Binary Scale Factor — used on input, unchanged byjpcpackroutine.2— Decimal Scale Factor — used on input, unchanged byjpcpackroutine.3— number of bits for each data value — ignored on input4— Original field type — currently ignored on input. Data values assumed to be reals. Set to0on output.5— if0use lossless compression, if1use lossy compression.6— Desired compression ratio, ifidrstmpl[5]=1. Set to255, ifidrstmpl[5]=0. May be modified in this function.
cpack— a pointer that will get the packed data field. Must be allocated before this function is called. Pass the allocated size in thelcpackparameter.lcpack— pointer that gets the length of packed field incpack. This must be set by the calling function to the size available incpack.
Returns
G2C_NOERROR— no error.G2C_EJPEG— error encoding/decoding JPEG data.
Author — Ed Hartnett
Definition at line 386 of file jpcpack.c.
References G2C_JPEG_DRS_TEMPLATE_LEN, and jpcpack_int().
int g2c_jpcpackf (float * fld, size_t width, size_t height, int * idrstmpl,
unsigned char * cpack, size_t * lcpack)
This function packs up a float array into a JPEG2000 code stream. 🌸 Same deal as before: after the data are scaled, and the reference value is subtracted out, the data are treated as a grayscale image and passed to a JPEG2000 encoder.
This function also fills in GRIB2 Data Representation Template 5.40 or 5.40000 with the appropriate values. Slay.
This function is the V2 API version of jpcpack() for floats. 💅
Parameters
fld— pointer to the float data values to pack.width— the number of points in the x direction.height— the number of points in the y direction.idrstmpl— contains the array of values for Data Representation Template Table 5.40 or 5.40000.0— Reference value — ignored on input, set byjpcpackroutine.1— Binary Scale Factor — used on input, unchanged byjpcpackroutine.2— Decimal Scale Factor — used on input, unchanged byjpcpackroutine.3— number of bits for each data value — ignored on input4— Original field type — currently ignored on input. Data values assumed to be reals. Set to0on output.5— if0use lossless compression, if1use lossy compression.6— Desired compression ratio, ifidrstmpl[5]=1. Set to255, ifidrstmpl[5]=0. May be modified in this function.
cpack— a pointer that will get the packed data field. Must be allocated before this function is called. Pass the allocated size in thelcpackparameter.lcpack— pointer that gets the length of packed field incpack. This must be set by the calling function to the size available incpack.
Returns
G2C_NOERROR— no error.G2C_EJPEG— error encoding/decoding JPEG data.
Author — Ed Hartnett
Definition at line 320 of file jpcpack.c.
References G2C_JPEG_DRS_TEMPLATE_LEN, and jpcpack_int().
int g2c_jpcunpackd (unsigned char * cpack, size_t len, int * idrstmpl,
size_t 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. This function is the V2 API version of jpcunpack() for doubles. 🦋
Parameters
cpack— the packed data.len— the length of the packed data.idrstmpl— pointer to array of values for Data Representation Template 5.40 or 5.40000.ndpts— the number of data values to unpack.fld— a pointer that gets the unpacked data values as an array ofdouble.
Returns
G2C_NOERROR— no error.G2C_ENOMEM— out of memory.
Author — Ed Hartnett
Date — 2022-08-12
Definition at line 199 of file jpcunpack.c.
References G2C_JPEG_DRS_TEMPLATE_LEN, jpcunpack_int(), and LOG.
int g2c_jpcunpackf (unsigned char * cpack, size_t len, int * idrstmpl,
size_t 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. 🫶
the parameters, continued
cpack— the packed data. that's what you're feeding in, bestie.len— the length of the packed data. how big it is, iconic.idrstmpl— pointer to the array of values for Data Representation Template5.40or5.40000. 🎀ndpts— the number of data values to unpack.fld— a pointer that gets the unpacked data values, handed back to you as an array offloat. 💖
Returns
G2C_NOERROR— no error, we ate.G2C_ENOMEM— out of memory. 😭
Author — Ed Hartnett
Date — 2022-09-08
Definition at line 159 of file jpcunpack.c.
References G2C_JPEG_DRS_TEMPLATE_LEN, jpcunpack_int(), and LOG.
int g2c_log_file (int g2cid)
Prints a lil summary of everything inside an open GRIB2 file. lowkey the vibe check for your file's contents. but heads up: if the NCEPLIBS-g2c library was built without the LOGGING option, this function literally does nothing. it's giving ghost. 💀
Parameters
g2cid— the file ID, which you got back fromg2c_open()org2c_create().
Returns
G2C_NOERROR— no error.G2C_EBADID—g2cidnot found. 🙈
Author — Ed Hartnett 8/22/22
Definition at line 189 of file g2cutil.c.
References g2c_message_info::bytes_in_msg, g2c_message_info::bytes_to_msg, g2c_message_info::center, g2c_message_info::day, g2c_csv_init(), G2C_EBADID, g2c_file, g2c_free_tables(), g2c_log_section(), g2c_log_section1(), G2C_NOERROR, g2c_table, g2c_message_info::hour, g2c_message_info::local_version, LOG, g2c_message_info::master_version, g2c_message_info::minute, g2c_message_info::month, g2c_message_info::msg_num, g2c_message_info::next, g2c_section_info::next, g2c_message_info::num_fields, g2c_message_info::num_local, g2c_message_info::sec, g2c_message_info::sec1_len, g2c_message_info::second, g2c_message_info::sig_ref_time, g2c_message_info::status, g2c_message_info::subcenter, g2c_message_info::type, and g2c_message_info::year.
Referenced by read_metadata().
int g2c_open (const char * path, int mode, int * g2cid)
Opens up an existing GRIB2 file. it opens the file and reads all its metadata for you, no extra steps. 🦋
GRIB2 messages in the file each get assigned a message ID, starting with 0 for the first message in the file.
Each product inside a message gets assigned a product ID, starting with 0 for the first product in the message.
Files you open with this function should be closed with a call to g2c_close() to release resources. periodt — don't leave them hanging.
Parameters
path— path of the file.mode— open mode flags.g2cid— pointer that gets an identifier for the file.
Returns
G2C_NOERROR— No error.G2C_EINVAL— Invalid input.G2C_ETOOMANYFILES— you're trying to open too many files at the same time. one at a time pls, the limit is real.
Author — Ed Hartnett
Date — Aug 16, 2022
Definition at line 1201 of file g2cfile.c.
References g2c_add_file(), LOG, MUTEX_LOCK, MUTEX_UNLOCK, and read_metadata().
Referenced by main().
int g2c_open_index (const char * data_file, const char * index_file, int mode, int * g2cid)
Opens a GRIB2 file with the help of an index file. the index file — made by the grb2index utility, or by the g2c_write_index() function — holds the byte offsets for the sections of every message in the GRIB2 file. so when you open a GRIB2 file with an index file, the library doesn't have to scan the whole thing to find all the metadata. it's giving shortcuts. ✨
Parameters
data_file— the name of the data file that the index applies to.index_file— the name that will be given to the index file. an existing file will be overwritten. 😳mode— open mode flags.g2cid— pointer that gets theg2cidfor this file. ignored ifNULL.
Returns
G2C_NOERROR— No error.
Author — Ed Hartnett
Date — 10/12/22
Definition at line 914 of file g2cindex.c.
References add_msg(), add_section(), g2c_message_info::bytes_to_bms, g2c_message_info::bytes_to_data, g2c_message_info::bytes_to_local, g2c_message_info::bytes_to_msg, g2c_message_info::discipline, g2c_add_file(), G2C_EBADSECTION, G2C_EFILE, G2C_EINVAL, G2C_ENAMETOOLONG, g2c_file, g2c_file_io_ubyte(), g2c_file_io_uint(), G2C_FILE_READ, G2C_INDEX_BASENAME_LEN, G2C_INDEX_DATE_STR_LEN, G2C_INDEX_HEADER_LEN, G2C_INDEX_STR1_LEN, G2C_INDEX_TIME_STR_LEN, g2c_log_section1(), G2C_MAX_NAME, G2C_NOERROR, g2c_rw_section1_metadata(), g2c_start_index_record(), g2c_start_index_record_lf(), LOG, g2c_message_info::master_version, MUTEX_LOCK, and MUTEX_UNLOCK.
Referenced by main().
int g2c_open_index1 (const char * index_file)
Opens a GRIB1 index file and reads what's inside. this function opens the GRIB2 index file, reads its metadata, and opens the accompanying GRIB2 file. 🌸
GRIB2 messages in the file each get a message ID, starting with 0 for the first message in the file.
Each product inside a message gets a product ID, starting with 0 for the first product in the message.
Files you open with this function should be closed with a call to g2c_close() to release resources.
Parameters
index_file— the name that will be given to the index file. an existing file will be overwritten. 🙈
Returns
G2C_NOERROR— No error.
Author — Ed Hartnett
Date — 10/12/22
Definition at line 812 of file g2cindex.c.
References G2C_EFILE, G2C_EINVAL, G2C_FILE_READ, G2C_INDEX1_BDS_VAL_LEN, G2C_INDEX1_BMS_VAL_LEN, G2C_INDEX1_GDS_VAL_LEN, G2C_INDEX1_PDS_VAL_LEN, G2C_INDEX_BASENAME_LEN, G2C_INDEX_DATE_STR_LEN, G2C_INDEX_HEADER_LEN, G2C_INDEX_TIME_STR_LEN, G2C_NOERROR, g2c_start_index1_record(), LOG, MUTEX_LOCK, MUTEX_UNLOCK, read_hdr_rec1(), and read_hdr_rec2().
int g2c_param_abbrev (int g2disc, int g2cat, int g2num, char * abbrev)
Grabs the NOAA abbreviation for a GRIB2 parameter. 🎀
Parameters
g2disc— the GRIB2 discipline number.g2cat— the GRIB2 category number.g2num— the GRIB2 parameter number.abbrev— pointer that gets the abbreviation. ignored ifNULL.
Returns
G2C_NOERROR— No error.G2C_EFILE— Error reading CSV file. 😭G2C_ENOPARAM— Parameter not found.
Author — Ed Hartnett
Date — 9/19/22
Definition at line 1430 of file g2cparams.c.
References G2C_MAX_NOAA_ABBREV_LEN, G2C_MAX_NOAA_PARAMS, G2C_NOERROR, LOG, and param.
Referenced by g2c_degrib2(), and g2c_log_section().
int g2c_param_all (int param_idx, int * g1num, int * g1ver, int * g2disc, int * g2cat, int * g2num, char * abbrev)
Returns all the info about a parameter. the whole lore drop. 👑
Parameters
param_idx— parameter index between0andG2C_MAX_NOAA_PARAMS.g1num— pointer that gets the GRIB1 parameter. ignored ifNULL.g1ver— pointer that gets the GRIB1 parameter table version number. ignored ifNULL.g2disc— pointer that gets the GRIB2 discipline number. ignored ifNULL.g2cat— pointer that gets the GRIB2 category number. ignored ifNULL.g2num— pointer that gets the GRIB2 parameter number. ignored ifNULL.abbrev— pointer that gets the abbreviation.
Returns
G2C_NOERROR— No error.G2C_EINVAL— Invalid input.G2C_EFILE— Error reading CSV file.G2C_ENOPARAM— Parameter not found.
Author — Ed Hartnett
Date — 9/19/22
Definition at line 1524 of file g2cparams.c.
References G2C_EINVAL, G2C_MAX_NOAA_ABBREV_LEN, G2C_MAX_NOAA_PARAMS, G2C_NOERROR, and param.
int g2c_param_g1tog2 (int g1num, int g1ver, int * g2disc, int * g2cat, int * g2num)
Translates a GRIB1 parameter into a GRIB2 parameter. glow-up translation, bestie. 💅
Parameters
g1num— the GRIB1 parameter.g1ver— the GRIB1 parameter table version number.g2disc— pointer that gets the GRIB2 discipline number. ignored ifNULL.g2cat— pointer that gets the GRIB2 category number. ignored ifNULL.g2num— pointer that gets the GRIB2 parameter number. ignored ifNULL.
Returns
G2C_NOERROR— No error.G2C_EFILE— Error reading CSV file.G2C_ENOPARAM— Parameter not found.
Author — Ed Hartnett
Date — 9/19/22
Definition at line 1390 of file g2cparams.c.
References G2C_ENOPARAM, G2C_MAX_NOAA_PARAMS, G2C_NOERROR, and param.
int g2c_param_g2tog1 (int g2disc, int g2cat, int g2num, int * g1num, int * g1ver)
Translates a GRIB2 parameter into a GRIB1 parameter. going the other way, no cap. 🌈
Parameters
g2disc— the GRIB2 discipline number.g2cat— the GRIB2 category number.g2num— the GRIB2 parameter number.g1num— pointer that gets the GRIB1 parameter. ignored ifNULL.g1ver— pointer that gets the GRIB1 parameter table version number. ignored ifNULL.
Returns
G2C_NOERROR— No error.G2C_EFILE— Error reading CSV file.G2C_ENOPARAM— Parameter not found.
Author — Ed Hartnett
Date — 9/19/22
Definition at line 1475 of file g2cparams.c.
References G2C_ENOPARAM, G2C_MAX_NOAA_PARAMS, G2C_NOERROR, LOG, and param.
int g2c_pngpackd (double * fld, size_t width, size_t height, int * idrstmpl, unsigned char * cpack, int * lcpack)
This subroutine packs up a double data field into PNG image format. once the data field is scaled and the reference value is subtracted out, it's treated as a grayscale image and handed off to a PNG encoder. it also fills in GRIB2 Data Representation Template 5.41 or 5.40010 with the appropriate values. slay. 🎀
Parameters
fld— pointer to array ofdoublethat contains the data values to pack.width— number of points in the x direction.height— number of points in the y direction.idrstmpl— contains the array of values for Data Representation Template5.41or5.40010.0— Reference value — ignored on input, set bypngpackroutine.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 =0on output. data values assumed to be reals.
cpack— the packed data field.lcpack— length of packed fieldcpack.
Returns
G2C_NOERROR— No error.G2C_EPNG— Error encoding/decoding PNG data. 😭
Author — Ed Hartnett
Date — Aug 8, 2022
Definition at line 348 of file pngpack.c.
References G2C_PNG_DRS_TEMPLATE_LEN, and pngpack_int().
int g2c_pngpackf (float * fld, size_t width, size_t height, int * idrstmpl, unsigned char * cpack, int * 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's 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 🌸
fld— a pointer to an array offloatthat's holding the data values you want to pack. 💖width— the number of points in the x direction.height— the number of points in the y direction.idrstmpl— holds the array of values for Data Representation Template 5.41 or 5.40010. Here's the lil breakdown bestie, pay attention:- 0 — Reference value — literally ignored on input, it's set by the
pngpackroutine. Not your problem. 💅 - 1 — Binary Scale Factor — used on input, so yes this one matters.
- 2 — Decimal Scale Factor — also used on input.
- 3 — number of bits for each grayscale pixel value — ignored on input, we said what we said.
- 4 — Original field type — currently ignored on input, and it gets set = 0 on output. Data values are assumed to be reals, no cap.
- 0 — Reference value — literally ignored on input, it's set by the
cpack— the packed data field itself.lcpack— length of packed fieldcpack.
Returns ✨
G2C_NOERROR— No error. We ate, zero crumbs. 🎀G2C_EPNG— Error encoding/decoding PNG data. 😭
Author 🫶
Ed Hartnett
Definition 📍
Definition at line 294 of file pngpack.c.
References 🔗
References G2C_PNG_DRS_TEMPLATE_LEN, and pngpack_int().
int g2c_pngunpackd (unsigned char * cpack, size_t len, int * idrstmpl, size_t ndpts, double * fld)
int g2c_pngunpackd (unsigned char * cpack, size_t len, int * idrstmpl,
size_t ndpts, double * fld)
Okay so this subroutine unpacks a data field that got packed into a PNG image format, using the info from the GRIB2 Data Representation Template 5.41 or 5.40010. It's giving unpacking era. 🦋
Parameters 🌸
cpack— the packed data field (acharacter*1array, iconic).len— length of packed fieldcpack().idrstmpl— pointer to array of values for Data Representation Template 5.41 or 5.40010.ndpts— the number of data values to unpack.fld— contains the unpacked data values. 💖
Returns ✨
G2C_NOERROR— No Error.G2C_ENOMEM— Out of memory. RIP your RAM. 💀
Author 🫶
Ed Hartnett
Date 🗓️
Aug 8, 2022
Definition 📍
Definition at line 188 of file pngunpack.c.
References 🔗
References G2C_PNG_DRS_TEMPLATE_LEN, and pngunpack_int().
int g2c_pngunpackf (unsigned char * cpack, size_t len, int * idrstmpl, size_t ndpts, float * fld)
int g2c_pngunpackf (unsigned char * cpack, size_t len, int * idrstmpl,
size_t ndpts, float * fld)
Same energy as its sibling up there, except the unpacked values come out as float instead of double. 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. Slay. 💅
Parameters 🌸
cpack— the packed data field (acharacter*1array).len— length of packed fieldcpack().idrstmpl— pointer to array of values for Data Representation Template 5.41 or 5.40010.ndpts— the number of data values to unpack.fld— contains the unpacked data values. ✨
Returns ✨
G2C_NOERROR— No Error.G2C_ENOMEM— Out of memory. 😭
Author 🫶
Ed Hartnett
Date 🗓️
Sep 8, 2022
Definition 📍
Definition at line 156 of file pngunpack.c.
References 🔗
References G2C_PNG_DRS_TEMPLATE_LEN, and pngunpack_int().
int g2c_seekmsg (int g2cid, size_t skip, size_t * offset, size_t * msglen)
int g2c_seekmsg (int g2cid, size_t skip, size_t * offset, size_t * msglen)
Bestie this one searches a file for the next GRIB2 Message. That's it, that's the job. The search is terminated when a GRIB2 message is found, or when you hit the end of the file. Whichever comes first, no notes. 🔍
Parameters 🌸
g2cid— ID of an open GRIB2 file, returned fromg2c_open()/g2c_create().skip— the number of bytes in the file to skip before starting the search.offset— pointer that gets the number of bytes to skip from the beggining of the file to where the GRIB message starts. Ignored ifNULL.msglen— pointer that gets the number of bytes in message (set to 0, if no message found). Ignored ifNULL.
Returns ✨
G2C_NOERROR— No error.G2C_EBADID— Badg2cid.G2C_ENOMEM— Out of memory. 💀
Author 🫶
Ed Hartnett
Date 🗓️
2022-09-11
Definition 📍
Definition at line 56 of file g2cfile.c.
References 🔗
References G2C_EBADID, G2C_EFILE, G2C_ENOMEM, g2c_file, G2C_MAGIC_HEADER, G2C_NOERROR, G2C_SEEKMSG_BUFSIZE, hton64, and LOG.
Referenced by 🔁
Referenced by read_metadata().
int g2c_set_log_level (int new_level)
int g2c_set_log_level (int new_level)
Use this to set the global log level. Here's the vibe chart, pick your fave:
- -1 — turn off all logging. Silence era, honestly valid. 🤫
- 0 — show only errors.
- 1 — output useful as verbose to utilities.
- 2 or 3 — shows some/all calls to top-level functions.
- 4+ — ever greater levels of detail. Chaos mode, we love her. 🔥
Heads up bestie: if logging is not enabled when building NCEPLIBS-g2c, this function will do nothing. Zero. Zilch. It's giving decorative. 💀
Parameters 🌸
new_level— the new logging level.
Returns ✨
G2C_NOERROR — No error.
Author 🫶
Ed Hartnett
Definition 📍
Definition at line 165 of file util.c.
References 🔗
References G2C_NOERROR, and LOG.
Referenced by 🔁
Referenced by main().
const char * g2c_strerror (int g2cerr)
const char * g2c_strerror (int g2cerr)
Give it an error code, it hands you back an error message. Translation services but make it GRIB2. 🗣️✨
Parameters 🌸
g2cerr— an error number returned by one of theg2c_*functions.
Returns ✨
The error message. Periodt.
Author 🫶
Ed Hartnett
Definition 📍
Definition at line 29 of file g2cutil.c.
References 🔗
References G2C_EBADEND, G2C_EBADID, G2C_EBADSECTION, G2C_EBADTEMPLATE, G2C_EBADTYPE, G2C_EFILE, G2C_EINVAL, G2C_EJPEG, G2C_EMSG, G2C_EMSGCOMPLETE, G2C_ENAMETOOLONG, G2C_ENOEND, G2C_ENOMEM, G2C_ENOMSG, G2C_ENOPARAM, G2C_ENOPRODUCT, G2C_ENOSECTION, G2C_ENOTEMPLATE, G2C_ENOTFOUND, G2C_ENOTGRIB, G2C_ENOTGRIB2, G2C_EPNG, G2C_ETOOMANYFILES, G2C_EXML, and G2C_NOERROR. (Yes, all of them. She's thorough. 💅)
int g2c_unpack7 (unsigned char * cgrib, int igdsnum, int gds_tmpl_len, long long int * gdstmpl, int idrsnum, int drs_tmpl_len, long long int * drstmpl, int ndpts, float * fld)
int g2c_unpack7 (unsigned char * cgrib, int igdsnum, int gds_tmpl_len, long
long int * gdstmpl, int idrsnum, int drs_tmpl_len, long long int *
drstmpl, int ndpts, float * fld)
This subroutine unpacks Section 7 (Data Section) of a GRIB2 message. Iconic behaviour honestly. Also FYI: this function is the newer version of g2_unpack7(), so if you were on the old one, come get your upgrade bestie. 👑
Parameters 🌸
cgrib— char array containing Section 7 of the GRIB2 message.igdsnum— Grid Definition Template Number (see Code Table 3.0). (Only used for DRS Template 5.51.) May be zero for other templates.gds_tmpl_len— number of elements in the GDS template.gdstmpl— pointer 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). May beNULL.idrsnum— Data Representation Template Number (see Code Table 5.0).drs_tmpl_len— number of elements in the DRS template.drstmpl— pointer 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.ndpts— number of data points to be unpacked and returned.fld— pointer which the data. Memory must be allocated in advance by caller, so like, don't forget. 🙈
Returns ✨
G2_NO_ERROR— No error.G2_UNPACK_BAD_SEC— Array passed had incorrect section number.G2_UNPACK7_BAD_DRT— Unrecognized Data Representation Template.G2_UNPACK7_WRONG_GDT— need one of GDT 3.50 through 3.53 to decode DRT 5.51.G2_UNPACK_NO_MEM— Memory allocation error.G2_UNPACK7_CORRUPT_SEC— Corrupt section 7. 😭
Author 🫶
Stephen Gilbert
Date 🗓️
2002-10-31
Definition 📍
Definition at line 259 of file g2_unpack7.c.
References 🔗
References G2C_EINVAL, G2C_ENOMEM, g2c_unpack7_int(), and LOG.
Referenced by 🔁
Referenced by g2c_get_prod().
int g2c_write_index (int g2cid, int mode, const char * index_file)
int g2c_write_index (int g2cid, int mode, const char * index_file)
Create an index file from a GRIB2 file, just like those created by the grb2index utility. Same energy, different function. The index file starts with two header records:
- 81-byte header with
'gb2ix1'in columns 42-47. - 81-byte header with number of bytes to skip before index records, total length in bytes of the index records, number of index records, and grib file basename written in format (
'ix1form:',3i10,2x,a40).
Each following index record corresponds to a grib message and has the internal format — buckle up bestie, this is a whole list:
- byte 001 - 004 length of index record
- byte 005 - 008 bytes to skip in data file before grib message
- byte 009 - 012 bytes to skip in message before lus (local use) (0, if none).
- byte 013 - 016 bytes to skip in message before gds
- byte 017 - 020 bytes to skip in message before pds
- byte 021 - 024 bytes to skip in message before drs
- byte 025 - 028 bytes to skip in message before bms
- byte 029 - 032 bytes to skip in message before data section
- byte 033 - 040 bytes total in the message
- byte 041 - 041 grib version number (currently 2)
- byte 042 - 042 message discipline
- byte 043 - 044 field number within grib2 message (1-based)
- byte 045 - ii identification section (ids)
- byte ii+1- jj grid definition section (gds)
- byte jj+1- kk product definition section (pds)
- byte kk+1- ll the data representation section (drs)
- byte ll+1-ll+6 first 6 bytes of the bit map section (bms)
Parameters 🌸
g2cid— File it for an open GRIB2 file, as returned byg2c_open().mode— Mode flags. SetG2C_NOCLOBBERto avoid overwriting and existing file.index_file— The name that will be given to the index file. An existing file will be overwritten. ⚠️
Returns ✨
G2C_NOERROR— No error.
Author 🫶
Ed Hartnett
Date 🗓️
10/12/22
Definition 📍
Definition at line 431 of file g2cindex.c.
References 🔗
References g2c_message_info::bytes_in_msg, g2c_message_info::bytes_to_local, g2c_message_info::bytes_to_msg, g2c_section_info::bytes_to_sec, g2c_message_info::discipline, g2c_file_info::f, g2c_message_info::file, G2C_EBADID, G2C_EFILE, G2C_EINVAL, g2c_file, g2c_file_io_ubyte(), g2c_file_io_uint(), G2C_FILE_WRITE, g2c_get_prod_sections(), G2C_INDEX_BASENAME_LEN, G2C_INDEX_BITMAP_BYTES, G2C_INDEX_FIXED_LEN, G2C_INDEX_FIXED_LEN_2, G2C_INDEX_HEADER_LEN, G2C_LARGE_FILE_INDEX, G2C_MAX_FILES, G2C_NOCLOBBER, G2C_NOERROR, g2c_rw_section1_metadata(), g2c_rw_section3_metadata(), g2c_rw_section4_metadata(), g2c_rw_section5_metadata(), g2c_start_index_record(), g2c_start_index_record_lf(), LOG, g2c_message_info::master_version, MUTEX_LOCK, MUTEX_UNLOCK, g2c_message_info::next, g2c_message_info::num_fields, ONE_BYTE, g2c_message_info::sec1_len, and g2c_section_info::sec_len.
Referenced by 🔁
Referenced by main().
void seekgb (FILE * lugb, g2int iseek, g2int mseek, g2int * lskip, g2int * lgrib)
void seekgb (FILE * lugb, g2int iseek, g2int mseek, g2int * lskip, g2int *
lgrib)
Search 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. That's the whole deal, no cap. 🦋
Program History Log 📜
- 2002-10-28 — GILBERT — Modified from Iredell's
skgbsubroutine. - 2009-01-16 — VUONG — Changed
lskipto 4 instead ofsizof(g2int).
Parameters 🎀
ok so here's everything you gotta hand over to this function, bestie, don't skip any of it:
lugb— aFILEpointer for the file you wanna search. 💖 Real talk: the file must be opened before this routine is called, like, do not come at it with an unopened file, that's not the vibe.iseek— the number of bytes in the file to skip before the search even starts.mseek— the maximum number of bytes to search at a time. It must be at least16, but ngl larger numbers like4092will result in better perfomance. ✨lskip— a pointer that gets the number of bytes to skip from the beggining of the file to where the GRIB message starts. 🦋lgrib— a pointer that gets the number of bytes in message (set to0, if no message found). 😭
- Author — Stephen Gilbert 👑
- Date —
2002-10-28 - Definition at line 46 of file
seekgb.c. 💅 - References —
BYTE,gbit(), andLOG. - Referenced by —
g2c_get_msg().
✨ Author ✨
Generated automatically by Doxygen for NCEPLIBS-g2c from the source code. 🤖💜
aaaand that's the whole thing, we made it to the end!! 🎉🫶 this absolute icon of a page is NCEPLIBS-g2c, Version 2.3.0, and the footer stamp on it says grib2.h(3) — so if you ever need to cite it, that's your girl. go read some GRIB2 messages, you got this. periodt. 💖✨🌸
📦 where this page comes from
- ubuntu resolute: libg2c-dev 2.3.0-4 · LGPL-3.0-only
- ubuntu stonking: libg2c-dev 2.3.0-7 · LGPL-3.0-only
- 💖 girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms