grib2_int.h(3)

๐Ÿ“ฆ
version 2.3.0 ยท 2 versions
, in ubuntu resolute, ubuntu stonking

๐Ÿ’– grib2_int.h(3) โ€” Library Functions Manual ๐Ÿ’–

(part 1 of 11, bestie โ€” buckle up)

๐ŸŒธ NAME ๐ŸŒธ

grib2_int.h โ€” header file with internal function prototypes for the NCEPLIBS-g2c library. it's giving backstage pass energy, no cap. ๐Ÿ’…

โœจ SYNOPSIS โœจ

#include <assert.h>
#include <ctype.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <arpa/inet.h>
#include 'grib2.h'

๐Ÿ“š Data Structures ๐Ÿ“š

okay so here are the structs, and they are all main characters in their own right:

  • struct g2c_code_table โ€” A GRIB2 code table. ๐Ÿ’–
  • struct g2c_dim_info โ€” Keep information about dimensions defined in section 3. ๐Ÿฆ‹
  • struct g2c_entry โ€” An entry in a GRIB2 code table. โœจ
  • struct g2c_file_info โ€” This is the information about each open file. ๐Ÿ“‚
  • struct g2c_message_info โ€” This is the information about each message. ๐Ÿ’Œ
  • struct g2c_param โ€” An entry in the table of NOAA abbreviations for GRIB parameters. ๐ŸŒธ
  • struct g2c_section3_info โ€” Information about Section 3 GRID DEFINITION SECTION. ๐Ÿ—บ๏ธ
  • struct g2c_section4_info โ€” Information about Section 4 PRODUCT DEFINITION SECTION. ๐Ÿ›๏ธ
  • struct g2c_section5_info โ€” Information about Section 5 DATA REPRESENTATION SECTION. ๐Ÿ”ข
  • struct g2c_section6_info โ€” Information about Section 6 BIT-MAP SECTION. ๐Ÿ—บ๏ธ
  • struct g2c_section_info โ€” Information about a section 3 through 7 in a GRIB2 message. ๐Ÿ“ฆ
  • struct gtemplate โ€” Struct for GRIB template, returned by getgridtemplate(). ๐ŸŒˆ

๐Ÿงš Macros ๐Ÿงš

these defines? they're literally the blueprint, bestie. don't skip a single one:

  • #define ALOG2 (0.69314718) โ€” ln(2.0) ๐ŸŒฟ
  • #define BYTE 8 โ€” Number of bits in a byte. ๐Ÿ’พ
  • #define EIGHT_BYTES 8 โ€” Eight bytes. 8๏ธโƒฃ
  • #define EXTERN_MUTEX(m) โ€” Pthreads not enabled, so do nothing. ๐Ÿงต
  • #define FOUR_BYTES 4 โ€” Four bytes. 4๏ธโƒฃ
  • #define G2C_FILE_READ 0 โ€” Read. ๐Ÿ“–
  • #define G2C_FILE_WRITE 1 โ€” Write. โœ๏ธ
  • #define G2C_INDEX1_BDS_VAL_LEN 10 โ€” Length of the binary data section (bds) in index file. ๐Ÿ“
  • #define G2C_INDEX1_BMS_VAL_LEN 5 โ€” Length of the bitmap section (bms) in index file. ๐Ÿ—บ๏ธ
  • #define G2C_INDEX1_GDS_VAL2_LEN 27 โ€” Length of the gds in index file. ๐Ÿ“
  • #define G2C_INDEX1_GDS_VAL_LEN 41 โ€” Length of the grid definition section (gds) in index file. ๐Ÿ“
  • #define G2C_INDEX1_PDS_VAL2_LEN 27 โ€” Length of the pds 2 section in the index file. ๐Ÿ“„
  • #define G2C_INDEX1_PDS_VAL3_LEN 27 โ€” Length of the pds 3 section in the index file. ๐Ÿ“„
  • #define G2C_INDEX1_PDS_VAL_LEN 27 โ€” Length of the product definition section (pds) in index file. ๐Ÿ“„
  • #define G2C_JASPER_JPEG_FORMAT_NAME 'jpc' โ€” Name of JPEG codec in Jasper. ๐Ÿ–ผ๏ธ
  • #define G2C_MAGIC_HEADER 'GRIB' โ€” GRIB magic header string. ๐Ÿช„
  • #define G2C_MAGIC_HEADER_LEN 8 โ€” Full length of magic header string (includes GRIB version byte). โœจ
  • #define G2C_MAX_MESSAGES 1024 โ€” Maximum number of messages in a file. ๐Ÿ“ฌ
  • #define G2C_MIN_MAX_BYTES 16 โ€” Minimum acceptable value for max_bytes parameter of g2c_get_msg(). โš ๏ธ
  • #define hton64(x) โ€” Byte swap 64-bit ints. ๐Ÿ”„
  • #define LATITUDE 'Latitude' โ€” Latitude. ๐ŸŒ
  • #define LOG(e) โ€” Ignore logging to stdout. ๐Ÿคซ
  • #define LONGITUDE 'Longitude' โ€” Longitude. ๐ŸŒ
  • #define MUTEX(m) โ€” Pthreads not enabled, so do nothing. ๐Ÿงต
  • #define MUTEX_LOCK(m) โ€” Pthreads not enabled, so do nothing. ๐Ÿ”’
  • #define MUTEX_UNLOCK(m) โ€” Pthreads not enabled, so do nothing. ๐Ÿ”“
  • #define ntoh64(x) โ€” Byte swap 64-bit ints. ๐Ÿ”„
  • #define ONE_BYTE 1 โ€” One byte. 1๏ธโƒฃ
  • #define TWO_BYTES 2 โ€” Two bytes. 2๏ธโƒฃ
  • #define WORD 32 โ€” Number of bits in four bytes. ๐Ÿ”ข

๐ŸŽ€ Typedefs ๐ŸŽ€

and now the glow-up names, bestie:

  • typedef struct g2c_entry G2C_CODE_ENTRY_T โ€” An entry in a GRIB2 code table. ๐Ÿ’–
  • typedef struct g2c_code_table G2C_CODE_TABLE_T โ€” A GRIB2 code table. ๐Ÿ“š
  • typedef struct g2c_dim_info G2C_DIM_INFO_T โ€” Keep information about dimensions defined in section 3. ๐Ÿฆ‹
  • typedef struct g2c_file_info G2C_FILE_INFO_T โ€” This is the information about each open file. ๐Ÿ“‚
  • typedef struct g2c_message_info G2C_MESSAGE_INFO_T โ€” This is the information about each message. ๐Ÿ’Œ
  • typedef struct g2c_param G2C_PARAM_T โ€” An entry in the table of NOAA abbreviations for GRIB parameters. ๐ŸŒธ
  • typedef struct g2c_section3_info G2C_SECTION3_INFO_T โ€” Information about Section 3 GRID DEFINITION SECTION. ๐Ÿ—บ๏ธ
  • typedef struct g2c_section4_info G2C_SECTION4_INFO_T โ€” Information about Section 4 PRODUCT DEFINITION SECTION. ๐Ÿ›๏ธ
  • typedef struct g2c_section5_info G2C_SECTION5_INFO_T โ€” Information about Section 5 DATA REPRESENTATION SECTION. ๐Ÿ”ข
  • typedef struct g2c_section6_info G2C_SECTION6_INFO_T โ€” Information about Section 6 BIT-MAP SECTION. ๐Ÿ—บ๏ธ
  • typedef struct g2c_section_info G2C_SECTION_INFO_T โ€” Information about a section 3 through 7 in a GRIB2 message. ๐Ÿ“ฆ
  • typedef struct gtemplate gtemplate โ€” Struct for GRIB template. ๐ŸŒˆ

โœจ Functions โœจ

okay bestie, buckle UP, this is the function roster and it's long but we're doing it together ๐Ÿ’–

  • int add_msg (G2C_FILE_INFO_T *file, int msg_num, size_t bytes_to_msg, size_t bytes_in_msg, int read_file, G2C_MESSAGE_INFO_T **msg) โ€” adds a shiny new message to the linked list ๐Ÿซถ
  • int add_section (FILE *f, G2C_MESSAGE_INFO_T *msg, int sec_id, unsigned int sec_len, size_t bytes_to_sec, unsigned char sec_num) โ€” drops in the metadata about a brand new section 3, 4, 5, 6, or 7 โœจ
  • void aecpack (float *fld, g2int width, g2int height, g2int *idrstmpl, unsigned char *cpack, g2int *lcpack) โ€” packs a float array up into an AEC code stream, no cap ๐Ÿ’…
  • g2int aecunpack (unsigned char *cpack, g2int len, g2int *idrstmpl, g2int ndpts, float *fld) โ€” unpacks AEC compressed data into an array of floats, using the info from GRIB2 Data Representation Template 5.42 ๐Ÿฆ‹
  • void cmplxpack (float *fld, g2int ndpts, g2int idrsnum, g2int *idrstmpl, unsigned char *cpack, g2int *lcpack) โ€” packs up a data field with a complex packing algorithm โœจ
  • void compack (float *fld, g2int ndpts, g2int idrsnum, g2int *idrstmpl, unsigned char *cpack, g2int *lcpack) โ€” packs a data field using a complex packing algorithm ๐Ÿ’–
  • int comunpack (unsigned char *cpack, g2int lensec, g2int idrsnum, g2int *idrstmpl, g2int ndpts, float *fld) โ€” unpacks a data field that got packed with a complex packing algorithm, using info from GRIB2 Data Representation Template 5.2 or Template 5.3 ๐ŸŒธ
  • int dec_aec (unsigned char *cpack, g2int len, g2int nbits, g2int flags, g2int block_size, g2int rsi, unsigned char *cfld, g2int cfldlen) โ€” decodes an AEC code stream, exactly as specified in the CCSDS 121.0-B-3 Blue Book ๐Ÿ‘‘
  • int dec_jpeg2000 (char *injpc, g2int bufsize, g2int *outfld) โ€” decodes a JPEG2000 code stream as specified in the JPEG2000 Part-1 standard (i.e., ISO/IEC 15444-1) using JasPer Software ๐ŸŽ€
  • int dec_png (unsigned char *pngbuf, g2int *width, g2int *height, unsigned char *cout) โ€” decodes PNG, that's it, that's the whole vibe ๐Ÿ–ผ๏ธ
  • int enc_aec (unsigned char *data, g2int ctemplen, g2int nbits, g2int flags, g2int block_size, g2int rsi, unsigned char *aecbuf, g2int *aecbuflen) โ€” encodes data into an AEC code stream, again per the CCSDS 121.0-B-3 Blue Book โœจ
  • int enc_jpeg2000 (unsigned char *cin, g2int width, g2int height, g2int nbits, g2int ltype, g2int ratio, g2int retry, char *outjpc, g2int jpclen) โ€” encodes a grayscale image into a JPEG2000 code stream as specified in the JPEG2000 Part-1 standard (i.e., ISO/IEC 15444-1) using JasPer Software ๐Ÿ’…
  • int enc_png (unsigned char *data, g2int width, g2int height, g2int nbits, unsigned char *pngbuf) โ€” encodes PNG, queen behavior only ๐ŸŒˆ
  • gtemplate * extdrstemplate (g2int number, g2int *list) โ€” this subroutine generates the remaining octet map for a given Data Representation Template, if it's required ๐Ÿงš
  • gtemplate * extgridtemplate (g2int number, g2int *list) โ€” this subroutine generates the remaining octet map for a given Grid Definition Template, if it's required ๐Ÿฆ‹
  • gtemplate * extpdstemplate (g2int number, g2int *list) โ€” this subroutine generates the remaining octet map for a given Product Definition Template, if it's required ๐Ÿ’œ
  • int g2c_add_file (const char *path, int mode, int *g2cid) โ€” opens a GRIB2 file and adds it to the list of open files, welcome to the party ๐ŸŽ‰
  • int g2c_check_msg (unsigned char *cgrib, g2int *lencurr, int verbose, int from) โ€” checks for 'GRIB' at the start of a GRIB message, and checks whether the message is already terminated with '7777' ๐Ÿ‘€
  • int g2c_file_io (FILE *f, int write, int g2ctype, void *var) โ€” reads or writes a big-endian integer type to an open file, converting between native and big-endian format ๐Ÿ”„
  • int g2c_file_io_byte (FILE *f, int write, char *var) โ€” reads or writes a big-endian signed byte to an open GRIB2 file, with native โ‡„ big-endian conversion plus the special GRIB2 handling of negative numbers ๐Ÿ˜ค
  • int g2c_file_io_int (FILE *f, int write, int *var) โ€” reads or writes a big-endian 4-byte signed int to an open GRIB2 file, with native โ‡„ big-endian conversion and that special GRIB2 handling of negative numbers โœจ
  • int g2c_file_io_longlong (FILE *f, int write, long long *var) โ€” reads or writes a big-endian signed long long to an open GRIB2 file, with native โ‡„ big-endian conversion and the special GRIB2 negative-number handling ๐Ÿ’–
  • int g2c_file_io_short (FILE *f, int write, short *var) โ€” reads or writes a big-endian signed short to an open GRIB2 file, with native โ‡„ big-endian conversion and the special GRIB2 negative-number handling ๐ŸŒธ
  • int g2c_file_io_template (FILE *f, int rw_flag, int map, long long int *template_value) โ€” reads or writes a big-endian 4-byte int or unsigned int from or to an open file, converting between native and big-endian format, and handling GRIB negative numbers ๐Ÿซถ
  • int g2c_file_io_ubyte (FILE *f, int write, unsigned char *var) โ€” reads or writes a big-endian unsigned byte to an open GRIB2 file, with native โ‡„ big-endian conversion ๐ŸŽ€
  • int g2c_file_io_uint (FILE *f, int write, unsigned int *var) โ€” reads or writes a big-endian 4-byte unsigned int to an open GRIB2 file, with native โ‡„ big-endian conversion ๐Ÿ’…
  • int g2c_file_io_ulonglong (FILE *f, int write, unsigned long long *var) โ€” reads or writes a big-endian unsigned long long to an open GRIB2 file, with native โ‡„ big-endian conversion ๐Ÿ‘‘
  • int g2c_file_io_ushort (FILE *f, int write, unsigned short *var) โ€” reads or writes a big-endian unsigned short to an open GRIB2 file, with native โ‡„ big-endian conversion ๐Ÿฆ‹
  • int g2c_get_datetime (int ipdtn, long long int *ipdtmpl, short year, unsigned char month, unsigned char day, unsigned char hour, unsigned char minute, unsigned char second, char *tabbrev) โ€” converts the date and time from GRIB2 info into string output โฐ
  • int g2c_get_level_desc (int ipdtn, long long int *ipdtmpl, char *level_desc) โ€” figures out the string that describes the level info, given the GRIB2 Product Definition Template information ๐Ÿงš
  • int g2c_log_section1 (G2C_MESSAGE_INFO_T *msg) โ€” logs section 0 information ๐Ÿ“
  • int g2c_rw_section1_metadata (FILE *f, int rw_flag, G2C_MESSAGE_INFO_T *msg) โ€” reads Section 1 ๐Ÿ“–
  • int g2c_rw_section3_metadata (FILE *f, int rw_flag, G2C_SECTION_INFO_T *sec) โ€” reads the metadata from section 3 (Grid Definition Section) of a GRIB2 message ๐ŸŒ
  • int g2c_rw_section4_metadata (FILE *f, int rw_flag, G2C_SECTION_INFO_T *sec) โ€” reads or writes the metadata from section 4 (Product Definition Section) of a GRIB2 message ๐ŸŒธ
  • int g2c_rw_section5_metadata (FILE *f, int rw_flag, G2C_SECTION_INFO_T *sec) โ€” reads or writes the metadata from section 5 (Data Representation Section) of a GRIB2 message ๐Ÿ’œ
  • int g2c_rw_section6_metadata (FILE *f, int rw_flag, G2C_SECTION_INFO_T *sec) โ€” reads or writes the metadata from section 6 (Data Representation Section) of a GRIB2 message ๐ŸŽ€
  • void gbit (unsigned char *in, g2int *iout, g2int iskip, g2int nbits) โ€” grabs arbitrary-size values out of a packed bit string, right-justifying each value in the unpacked iout array โœจ
  • void gbits (unsigned char *in, g2int *iout, g2int iskip, g2int nbits, g2int nskip, g2int n) โ€” unpacks arbitrary-size values from a packed bit string, right-justifying each value in the unpacked iout array ๐Ÿซถ
  • g2int getdim (unsigned char *csec3, g2int *width, g2int *height, g2int *iscan) โ€” returns the dimensions and scanning mode of a grid definition ๐Ÿ“
  • gtemplate * getdrstemplate (g2int number) โ€” this subroutine returns DRS template info for a specified Data Representation Template ๐Ÿฆ‹
  • gtemplate * getgridtemplate (g2int number) โ€” this subroutine returns grid template info for a specified Grid Definition Template for [Section 3 - the Grid Definition Section (GDS)](https://www.nco.ncep.noaa.gov/pmb/docs/grib2/grib2_doc/grib2_sect3.shtml) ๐ŸŒ
  • gtemplate * getpdstemplate (g2int number) โ€” this subroutine returns PDS template info for a specified Product Definition Template ๐Ÿ’–
  • g2int getpoly (unsigned char *csec3, g2int *jj, g2int *kk, g2int *mm) โ€” this subroutine returns the J, K, and M pentagonal resolution parameters specified in a GRIB Grid Definition Section (GDS) used for spherical harmonic coefficients using GDT 5.50 through 5.53 ๐Ÿ”ฎ
  • double int_power (double x, g2int y) โ€” a function similar to C's pow() power function, she's the understudy and she ate ๐Ÿ”ฅ
  • void jpcpack (float *fld, g2int width, g2int height, g2int *idrstmpl, unsigned char *cpack, g2int *lcpack) โ€” this function packs up a float array into a JPEG2000 code stream ๐Ÿ–ผ๏ธ
  • g2int jpcunpack (unsigned char *cpack, g2int len, g2int *idrstmpl, g2int ndpts, float *fld) โ€” unpacks JPEG2000 compressed data into an array of floats, using info from the GRIB2 Data Representation Template 5.40 or 5.40000 โœจ
  • void misspack (float *fld, g2int ndpts, g2int idrsnum, g2int *idrstmpl, unsigned char *cpack, g2int *lcpack) โ€” packs a data field using a complex packing algorithm ๐Ÿ’…
  • void mkieee (float *a, g2int *rieee, g2int num) โ€” stores a list of real values in 32-bit IEEE floating point format ๐Ÿ’พ
  • int pack_gp (g2int *kfildo, g2int *ic, g2int *nxy, g2int *is523, g2int *minpk, g2int *inc, g2int *missp, g2int *misss, g2int *jmin, g2int *jmax, g2int *lbit, g2int *nov, g2int *ndg, g2int *lx, g2int *ibit, g2int *jbit, g2int *kbit, g2int *novref, g2int *lbitref, g2int *ier) โ€” determines groups of variable size, but at least of size minpk; the associated max (jmax( )) and min (jmin( )); the number of bits necessary to hold the values in each group (lbit( )); the number of values in each group (nov( )); the number of bits necessary to pack the jmin( ) values (ibit); the number of bits necessary to pack the lbit( ) values (jbit); and the number of bits necessary to pack the nov( ) values (kbit) ๐Ÿง 
  • void pngpack (float *fld, g2int width, g2int height, g2int *idrstmpl, unsigned char *cpack, g2int *lcpack) โ€” this subroutine packs up a float data field into PNG image format ๐ŸŒˆ
  • g2int pngunpack (unsigned char *cpack, g2int len, g2int *idrstmpl, g2int ndpts, float *fld) โ€” this subroutine unpacks a data field that was packed into a PNG image format, using info from the GRIB2 Data Representation Template 5.41 or 5.40010 ๐ŸŽ€
  • void rdieee (g2int *rieee, float *a, g2int num) โ€” reads a list of real values in 32-bit IEEE floating point format ๐Ÿ“–
  • void sbit (unsigned char *out, g2int *in, g2int iskip, g2int nbits) โ€” stores arbitrary-size values into a packed bit string, taking the low-order bits from each value in the unpacked array โœจ
  • void sbits (unsigned char *out, g2int *in, g2int iskip, g2int nbits,
g2int nskip, g2int n)
void simpack (float *fld, g2int ndpts, g2int *idrstmpl, unsigned char
    *cpack, g2int *lcpack)

okay so simpack takes your data field and squishes it all down using the simple packing algorithm ๐Ÿ’… no notes, she's efficient.

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

this one unpacks a data field that got packed with the simple packing algorithm, using all the info from the GRIB2 Data Representation Template 5.0, and it hands you back a g2int ๐Ÿซถ

void specpack (float *fld, g2int ndpts, g2int JJ, g2int KK, g2int MM,
    g2int *idrstmpl, unsigned char *cpack, g2int *lcpack)

specpack packs a spectral data field using the complex packing algorithm for spherical harmonic data, exactly as defined in the GRIB2 Data Representation Template 5.51 โœจ

g2int specunpack (unsigned char *cpack, g2int *idrstmpl, g2int ndpts,
    g2int JJ, g2int KK, g2int MM, float *fld)

and specunpack unpacks a spectral data field that was packed using that same complex packing algorithm for spherical harmonic data โ€” as defined in the GRIB2 documentation โ€” using info from the GRIB2 Data Representation Template 5.51. returns a g2int, bestie ๐Ÿ’–


๐ŸŒธ DETAILED DESCRIPTION ๐ŸŒธ

real talk: this is the header file holding all the internal function prototypes for the NCEPLIBS-g2c library. that's the whole vibe. ๐ŸŽ€

๐Ÿ‘‘ Author

Ed Hartnett

๐Ÿ“… Date

2021-11-08

๐Ÿ“‚ Definition in file

grib2_int.h


๐Ÿ”ฅ DATA TYPE DOCUMENTATION ๐Ÿ”ฅ

bestie. buckle up. this is the part where we meet the structs. every single one. i love them all equally. ๐Ÿ’–

๐ŸŒˆ struct g2c_code_table

a GRIB2 code table. that's her. ๐Ÿ‘‘

Definition at line 256 of file grib2_int.h.

โœจ Data Fields

  • G2C_CODE_ENTRY_T * entry
  • struct g2c_code_table * next
  • char title[G2C_MAX_GRIB_TITLE_LEN+1]

๐Ÿฆ‹ struct g2c_dim_info

keeps info about the dimensions defined in section 3. very organized of her.

Definition at line 185 of file grib2_int.h.

โœจ Data Fields

  • int dimid โ€” Dimension ID.
  • size_t len โ€” Length of dimension.
  • char name[G2C_MAX_NAME+1] โ€” Name of dimension.
  • float * value โ€” Array of dimension values.

๐ŸŽ€ struct g2c_entry

an entry in a GRIB2 code table. one little entry, living her life. ๐Ÿ’…

Definition at line 247 of file grib2_int.h.

โœจ Data Fields

  • char code[G2C_MAX_GRIB_CODE_LEN+1]
  • char desc[G2C_MAX_GRIB_DESC_LEN+1]
  • struct g2c_entry * next
  • char status[G2C_MAX_GRIB_STATUS_LEN+1]

๐Ÿ“ struct g2c_file_info

this is the info about each open file. every single one of them gets her own lil record. ๐Ÿซถ

Definition at line 237 of file grib2_int.h.

โœจ Data Fields

  • FILE * f โ€” FILE pointer to open file.
  • int g2cid โ€” ID of the file.
  • G2C_MESSAGE_INFO_T * msg โ€” Information about each message in the file.
  • size_t num_messages โ€” Number of messages in the file.
  • char path[G2C_MAX_NAME+1] โ€” Path of the file.

๐Ÿ’Œ struct g2c_message_info

and THIS is the info about each message. she is long. she is thorough. she ate. ๐Ÿ˜ญ

Definition at line 135 of file grib2_int.h.

โœจ Data Fields

  • size_t bytes_in_msg โ€” Number of bytes in this message.
  • size_t bytes_to_bms โ€” Number of bytes in the message to the bitmap section.
  • size_t bytes_to_data โ€” Number of bytes in the message to the (first) data section.
  • size_t bytes_to_local โ€” Number of bytes in the message before the (first) local section.
  • size_t bytes_to_msg โ€” Number of bytes to skip in the file, to get to this message.
  • short center โ€” Originating center.
  • unsigned char day โ€” Day.
  • unsigned char discipline โ€” Discipline from section 0.
  • struct g2c_file_info * file โ€” Pointer to containing file.
  • unsigned char hour โ€” Hour.
  • unsigned char local_version โ€” Version number of GRIB local tables used to augment Master Tables.
  • unsigned char master_version โ€” GRIB master tables version number.
  • unsigned char minute โ€” Minute.
  • unsigned char month โ€” Month.
  • size_t msg_num โ€” Number of message in file (0-based).
  • struct g2c_message_info * next โ€” Pointer to next in list.
  • int num_fields โ€” Number of fields in the message.
  • int num_local โ€” Number of local sections in the message.
  • int num_sections โ€” Number of sections in the file.
  • struct g2c_section_info * sec โ€” List of section metadata.
  • int sec1_len โ€” Length of section 1.
  • unsigned char second โ€” Second.
  • int section1[G2C_SECTION1_ARRAY_LEN] โ€” Section 1 array.
  • int * section_number โ€” Array (length num_sections) of section numbers.
  • size_t * section_offset โ€” Array (length num_sections) of byte offsets from start of message to section.
  • unsigned char sig_ref_time โ€” Significance of reference time.
  • unsigned char status โ€” Production Status of Processed data in the GRIB message.
  • short subcenter โ€” Originating subcenter.
  • unsigned char type โ€” Type of processed data in this GRIB message.
  • short year โ€” Year.

๐Ÿ“ struct g2c_param

an entry in the table of NOAA abbreviations for GRIB parameters. iconic reference material behavior. ๐Ÿ“š

Definition at line 264 of file grib2_int.h.

โœจ Data Fields

  • char abbrev[G2C_MAX_NOAA_ABBREV_LEN+1] โ€” NOAA abbreviation for this parameter.
  • int g1num โ€” GRIB1 parameter number.
  • int g1ver โ€” GRIB1 table version.
  • int g2cat โ€” GRIB2 category number.
  • int g2disc โ€” GRIB2 discipline.
  • int g2num โ€” GRIB2 parameter number.

๐Ÿงš struct g2c_section3_info

info about Section 3, aka the GRID DEFINITION SECTION. she defines the grid. that's her whole job. ๐Ÿ’…

Definition at line 195 of file grib2_int.h.

โœจ Data Fields

  • G2C_DIM_INFO_T dim[2] โ€” Dimension information.
  • unsigned short grid_def โ€” Grid definition template number (= N) (See Table 3.1).
  • unsigned char interp_list โ€” Interpetation of list of numbers defining number of points (See Table 3.11).
  • unsigned int num_data_points โ€” Number of data points.
  • unsigned char num_opt โ€” Number of octets for optional list of numbers defining number of points.
  • int * optional โ€” Optional list of numbers defining number of points.
  • unsigned char source_grid_def โ€” Source of grid definition (See Table 3.0).

๐ŸŒŸ struct g2c_section4_info

info about Section 4, the PRODUCT DEFINITION SECTION. main character energy fr fr.

Definition at line 208 of file grib2_int.h.

โœจ Data Fields

  • int field_num
  • unsigned short num_coord โ€” Number of coordinate values after template.
  • int * optional โ€” Optional list of numbers defining number of points.
  • unsigned short prod_def โ€” Product definition template number (See Table 4.0).

๐Ÿ’œ struct g2c_section5_info

info about Section 5, the DATA REPRESENTATION SECTION. the one that knows how the data is packed. iconic.

Definition at line 218 of file grib2_int.h.

โœจ Data Fields

  • unsigned short data_def โ€” Data representation template number (See Table 5.0).
  • unsigned int num_data_points โ€” Number of data points where one or more values are specified in Section 7 when a bit map is present, total number of data points when a bit map is absent.

๐ŸŒธ struct g2c_section6_info

info about Section 6, the BIT-MAP SECTION. short but mighty. ๐ŸŽ€

Definition at line 229 of file grib2_int.h.

โœจ Data Fields

  • unsigned char indicator โ€” Bit map indicator. See Table 6.0.

๐Ÿซถ struct g2c_section_info

info about a section 3 through 7 in a GRIB2 message. yes bestie, sections 3 through 7, all of them, one struct to hold the metadata. ๐Ÿ‘‘

Definition at line 170 of file grib2_int.h.

โœจ Data Fields

  • size_t bytes_to_sec โ€” Number of bytes from start of message to this section.
  • G2C_MESSAGE_INFO_T * msg โ€” Pointer to contianing message.
  • struct g2c_section_info * next โ€” Pointer to next in list.
  • struct g2c_section_info * prev โ€” Pointer to previous in list.
  • int sec_id โ€” ID of the section (0-based).
  • void * sec_info โ€” Pointer to struct specific for section 3, 4, 5, 6, or 7.
  • unsigned int sec_len โ€” Length of the section (in bytes).
  • unsigned char sec_num โ€” Section number.
  • long long int * template โ€” Grid, product, or data template.
  • int template_len โ€” Number of entries in template.

๐ŸŒˆ struct gtemplate

struct for a GRIB template, and it's the one that gets returned by getgridtemplate(). she's the plug. โœจ

Definition at line 277 of file grib2_int.h.

โœจ Data Fields

  • g2int * ext โ€” Number of octets of each entry in the extension part of the template.
  • g2int extlen โ€” Number of entries in the template extension.
  • g2int * map โ€” Number of octets of each entry in the static part of the template.
  • g2int maplen โ€” Number of entries in the static part of the template.
  • g2int needext โ€” Indicates whether or not the template needs to be extended.
  • g2int num โ€” The template number.
  • g2int type โ€” The template type: 3 Grid Defintion Template. 4 Product Defintion Template. 5 Data Representation Template.

โœจ MACRO DEFINITION DOCUMENTATION โœจ

okay so these are the #defines, the little lore drops that live at the top of the header ๐Ÿ’… they're small but they run the whole show, no cap.

#define ALOG2 (0.69314718)

ln(2.0). yes bestie that's just the natural log of two, sitting there being iconic.

๐Ÿ“Œ Defined at line 30 of grib2_int.h.

๐Ÿ‘€ Gets referenced by aecpack_int(), compack(), jpcpack_int(), misspack(), pngpack_int(), and simpack().

#define BYTE 8

The number of bits in a byte. ground truth. the whole vibe.

๐Ÿ“Œ Defined at line 47 of grib2_int.h.

๐Ÿ‘€ Referenced by seekgb().

#define EIGHT_BYTES 8

Eight bytes. that's it, that's the macro ๐ŸŽ€

๐Ÿ“Œ Defined at line 53 of grib2_int.h.

๐Ÿ‘€ Referenced by g2c_file_io().

#define EXTERN_MUTEX( m)

Pthreads are not enabled, so this does absolutely nothing. zero. nada. it's giving "we tried" ๐Ÿ˜ญ

๐Ÿ“Œ Defined at line 113 of grib2_int.h.

#define FOUR_BYTES 4

Four bytes. slay.

๐Ÿ“Œ Defined at line 52 of grib2_int.h.

๐Ÿ‘€ Referenced by g2c_file_io(), g2c_file_io_template(), and read_msg_metadata().

#define G2C_FILE_READ 0

Read mode ๐Ÿซถ

๐Ÿ“Œ Defined at line 131 of grib2_int.h.

๐Ÿ‘€ Referenced by add_section(), g2c_open_index(), g2c_open_index1(), and read_msg_metadata().

#define G2C_FILE_WRITE 1

Write mode โœ๏ธ

๐Ÿ“Œ Defined at line 132 of grib2_int.h.

๐Ÿ‘€ Referenced by g2c_write_index().

#define G2C_INDEX1_BDS_VAL_LEN 10

Length of the binary data section (bds) in the index file.

๐Ÿ“Œ Defined at line 73 of grib2_int.h.

๐Ÿ‘€ Referenced by g2c_open_index1(), and g2c_start_index1_record().

#define G2C_INDEX1_BMS_VAL_LEN 5

Length of the bitmap section (bms) in the index file.

๐Ÿ“Œ Defined at line 70 of grib2_int.h.

๐Ÿ‘€ Referenced by g2c_open_index1(), and g2c_start_index1_record().

#define G2C_INDEX1_GDS_VAL2_LEN 27

Length of the gds in the index file.

๐Ÿ“Œ Defined at line 82 of grib2_int.h.

#define G2C_INDEX1_GDS_VAL_LEN 41

Length of the grid definition section (gds) in the index file.

๐Ÿ“Œ Defined at line 67 of grib2_int.h.

๐Ÿ‘€ Referenced by g2c_open_index1(), and g2c_start_index1_record().

#define G2C_INDEX1_PDS_VAL2_LEN 27

Length of the pds 2 section in the index file.

๐Ÿ“Œ Defined at line 76 of grib2_int.h.

#define G2C_INDEX1_PDS_VAL3_LEN 27

Length of the pds 3 section in the index file.

๐Ÿ“Œ Defined at line 79 of grib2_int.h.

#define G2C_INDEX1_PDS_VAL_LEN 27

Length of the product definition section (pds) in the index file.

๐Ÿ“Œ Defined at line 64 of grib2_int.h.

๐Ÿ‘€ Referenced by g2c_open_index1(), and g2c_start_index1_record().

#define G2C_JASPER_JPEG_FORMAT_NAME 'jpc'

The name of the JPEG codec in Jasper. short, sweet, four characters of pure power โœจ

๐Ÿ“Œ Defined at line 33 of grib2_int.h.

๐Ÿ‘€ Referenced by enc_jpeg2000(), and int_dec_jpeg2000().

#define G2C_MAGIC_HEADER 'GRIB'

The GRIB magic header string ๐Ÿ”ฎ you know, the little signature that tells you "yep, this is a GRIB file, bestie."

๐Ÿ“Œ Defined at line 39 of grib2_int.h.

๐Ÿ‘€ Referenced by g2c_seekmsg().

#define G2C_MAGIC_HEADER_LEN 8

The full length of the magic header string โ€” and yes that count includes the GRIB version byte ๐Ÿ‘‘

๐Ÿ“Œ Defined at line 42 of grib2_int.h.

๐Ÿ‘€ Referenced by g2c_find_msg2().

#define G2C_MAX_MESSAGES 1024

Maximum number of messages in a file. one thousand and twenty-four, that's the ceiling ๐Ÿ’€

๐Ÿ“Œ Defined at line 45 of grib2_int.h.

#define G2C_MIN_MAX_BYTES 16

The minimum acceptable value for the max_bytes parameter of g2c_get_msg().

๐Ÿ“Œ Defined at line 36 of grib2_int.h.

๐Ÿ‘€ Referenced by g2c_get_msg().

#define hton64( x)

Value:

((1==htonl(1)) ? (x) : (((uint64_t)htonl((x) & 0xFFFFFFFFUL)) << 32) | htonl((uint32_t)((x) >> 32)))

Byte swaps 64-bit ints. This takes native-endian 8-byte ints and turns them into big-endian 8-byte ints ๐Ÿ”„

๐Ÿ“Œ Defined at line 129 of grib2_int.h.

๐Ÿ‘€ Referenced by g2c_file_io(), and g2c_seekmsg().

#define LATITUDE 'Latitude'

Latitude. the north-south girlie ๐ŸŒŽ

๐Ÿ“Œ Defined at line 56 of grib2_int.h.

๐Ÿ‘€ Referenced by determine_dims().

#define LOG( e)

Ignores logging to stdout. The library was not built with LOGGING=ON, so this macro is just out here doing nothing and honestly? relatable ๐Ÿ™ˆ

๐Ÿ“Œ Defined at line 428 of grib2_int.h.

๐Ÿ‘€ Referenced by add_msg(), add_section(), aecpack_int(), aecunpack(), aecunpack_int(), comunpack(), dec_aec(), determine_dims(), enc_aec(), enc_jpeg2000(), free_metadata(), g2_info(), g2c_add_file(), g2c_aecunpackd(), g2c_aecunpackf(), g2c_close(), g2c_compare(), g2c_degrib2(), g2c_find_msg2(), g2c_get_msg(), g2c_jpcunpackd(), g2c_jpcunpackf(), g2c_log_file(), g2c_log_section(), g2c_log_section1(), g2c_open(), g2c_open_index(), g2c_open_index1(), g2c_param_abbrev(), 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_index_record(), g2c_start_index_record_lf(), g2c_unpack7(), g2c_unpack7_int(), g2c_write_index(), int_dec_jpeg2000(), jpcpack_int(), jpcunpack(), jpcunpack_int(), pngpack_int(), pngunpack_int(), read_hdr_rec1(), read_metadata(), read_msg_metadata(), seekgb(), simpack(), and simunpack().

#define LONGITUDE 'Longitude'

Longitude. the east-west bestie ๐ŸŒˆ

๐Ÿ“Œ Defined at line 59 of grib2_int.h.

๐Ÿ‘€ Referenced by determine_dims().

#define MUTEX( m)

Pthreads are not enabled, so this does nothing ๐Ÿงš

๐Ÿ“Œ Defined at line 110 of grib2_int.h.

#define MUTEX_LOCK( m)

Pthreads are not enabled, so this does nothing.

๐Ÿ“Œ Defined at line 116 of grib2_int.h.

๐Ÿ‘€ Referenced by g2c_check_msg(), g2c_close(), g2c_get_prod(), g2c_inq(), g2c_inq_dim(), g2c_inq_msg(), g2c_inq_msg_time(), g2c_inq_prod(), g2c_open(), g2c_open_index(), g2c_open_index1(), and g2c_write_index().

#define MUTEX_UNLOCK( m)

Pthreads are not enabled, so this does nothing.

๐Ÿ“Œ Defined at line 119 of grib2_int.h.

๐Ÿ‘€ Referenced by g2c_check_msg(), g2c_close(), g2c_get_prod(), g2c_inq(), g2c_inq_dim(), g2c_inq_msg(), g2c_inq_msg_time(), g2c_inq_prod(), g2c_open(), g2c_open_index(), g2c_open_index1(), and g2c_write_index().

#define ntoh64( x)

Value:

((1==ntohl(1)) ? (x) : (((uint64_t)ntohl((x) & 0xFFFFFFFFUL)) << 32) | ntohl((uint32_t)((x) >> 32)))

Byte swaps 64-bit ints. This one takes big-endian 8-byte ints and converts them into native-endian 8-byte ints ๐Ÿ” the reverse twin of hton64, we love a matching set.

๐Ÿ“Œ Defined at line 125 of grib2_int.h.

๐Ÿ‘€ Referenced by g2c_file_io().

#define ONE_BYTE 1

One byte. a single, solitary byte ๐Ÿ“

๐Ÿ“Œ Defined at line 50 of grib2_int.h.

๐Ÿ‘€ Referenced by g2c_file_io(), g2c_file_io_template(), g2c_write_index(), and read_msg_metadata().

#define TWO_BYTES 2

Two bytes. iconic duo energy ๐Ÿ’–

๐Ÿ“Œ Defined at line 51 of grib2_int.h.

๐Ÿ‘€ Referenced by g2c_file_io(), and g2c_file_io_template().

#define WORD 32

The number of bits in four bytes.

๐Ÿ“Œ Defined at line 48 of grib2_int.h.


โœจ TYPEDEF DOCUMENTATION โœจ

these are the aliases, bestie โ€” the cute little nicknames so you don't have to type out struct every single time ๐ŸŽ€

typedef struct g2c_entry G2C_CODE_ENTRY_T

An entry in a GRIB2 code table.

typedef struct g2c_code_table G2C_CODE_TABLE_T

A GRIB2 code table.

typedef struct g2c_dim_info G2C_DIM_INFO_T

Keeps information about the dimensions defined in section 3.

typedef struct g2c_file_info G2C_FILE_INFO_T

This is the info about each open file.

typedef struct g2c_message_info G2C_MESSAGE_INFO_T

This is the info about each message.

typedef struct g2c_param G2C_PARAM_T

An entry in the table of NOAA abbreviations for GRIB parameters.

typedef struct g2c_section3_info G2C_SECTION3_INFO_T

Information about Section 3, the GRID DEFINITION SECTION.

typedef struct g2c_section4_info G2C_SECTION4_INFO_T

Information about Section 4, the PRODUCT DEFINITION SECTION.

typedef struct g2c_section5_info G2C_SECTION5_INFO_T

Information about Section 5, the DATA REPRESENTATION SECTION.

typedef struct g2c_section6_info G2C_SECTION6_INFO_T

Information about Section 6, the BIT-MAP SECTION.

typedef struct g2c_section_info G2C_SECTION_INFO_T

Information about a section 3 through 7 in a GRIB2 message.

typedef struct gtemplate gtemplate

Struct for GRIB template.

๐Ÿ“Œ Defined at line 305 of grib2_int.h.


โœจ FUNCTION DOCUMENTATION โœจ

and now, the main characters ๐Ÿ‘‘

int add_msg (G2C_FILE_INFO_T * file, int msg_num, size_t bytes_to_msg, size_t bytes_in_msg, int read_file, G2C_MESSAGE_INFO_T ** msg)

Adds a new message to the linked list ๐Ÿ”—

Parameters:

  • file โ€” pointer to the G2C_FILE_INFO_T for this file.
  • msg_num โ€” number of the message in the file (0-based, don't forget).
  • bytes_to_msg โ€” the number of bytes to the start of the message in the file.
  • bytes_in_msg โ€” length of the message, in bytes.
  • read_file โ€” set to true to make the metadata get read from a GRIB2 data file.
  • msg โ€” pointer to a pointer that will get the location of the newly created G2C_MESSAGE_INFO_T object. Ignored if NULL.

Returns:

  • G2C_NOERROR โ€” no error ๐ŸŽ‰

Author: Ed Hartnett

Date: Sep 12, 2022

๐Ÿ“Œ Defined at line 1017 of g2cfile.c.

๐Ÿ‘€ References g2c_message_info::bytes_in_msg, g2c_message_info::bytes_to_msg, g2c_message_info::file, G2C_ENOMEM, G2C_NOERROR, LOG, g2c_file_info::msg, g2c_message_info::msg_num, g2c_message_info::next, g2c_file_info::num_messages, and read_msg_metadata().

๐Ÿ’ซ Referenced by g2c_open_index(), and read_metadata().

int add_section (FILE * f, G2C_MESSAGE_INFO_T * msg, int sec_id, unsigned int sec_len, size_t bytes_to_sec, unsigned char sec_num)

Adds metadata about a new section 3, 4, 5, 6, or 7 โœจ

Parameters:

  • f โ€” FILE pointer to the open GRIB2 file.
  • msg โ€” pointer to the G2C_MESSAGE_INFO_T struct.
  • sec_id โ€” 0-based section ID.
  • sec_len โ€” length of the section.
  • bytes_to_sec โ€” number of bytes from the start of the message to this section.
  • sec_num โ€” section number.

Returns:

  • G2C_NOERROR โ€” no error ๐ŸŽ‰

Author: Ed Hartnett

Date: Sep 12, 2022

๐Ÿ“Œ Defined at line 794 of g2cfile.c.

๐Ÿ‘€ References g2c_section_info::bytes_to_sec, G2C_EBADSECTION, G2C_ENOMEM, G2C_FILE_READ, G2C_NOERROR, g2c_rw_section3_metadata(), g2c_rw_section4_metadata(), g2c_rw_section5_metadata(), g2c_rw_section6_metadata(), LOG, g2c_section_info::msg, g2c_section_info::next, g2c_message_info::num_local, g2c_section_info::prev, g2c_message_info::sec, g2c_section_info::sec_id, g2c_section_info::sec_len, and g2c_section_info::sec_num.

๐Ÿ’ซ Referenced by g2c_open_index(), and read_msg_metadata().

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

This function packs up a float array into an AEC code stream. Once the data are scaled and the reference value is subtracted out, the data get handed off to the AEC encoder ๐Ÿงšโ€โ™€๏ธ

This function also fills in GRIB2 Data Representation Template 5.42 with the appropriate values, bestie, it does both jobs ๐Ÿ’…

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.
    • 0 Reference value โ€” ignored on input, set by the aecpack routine.
    • 1 Binary Scale Factor โ€” used on input, unchanged by the aecpack routine.
    • 2 Decimal Scale Factor โ€” used on input, unchanged by the aecpack routine.
    • 3 number of bits for each data value โ€” ignored on input.
    • 4 Original field type โ€” currently ignored on input. Data values are assumed to be reals. Set to 0 on output.
    • 5 CCSDS compression options mask.

โ€ฆand the last two slots in that idrstmpl array are literally:

  • 6 Block size.
  • 7 Reference sample interval. May be modified in this function.

cpack</purl> โ€” a pointer that will get the packed data field. Bestie, it must be allocated before this function is called, and you pass the allocated size in the lcpack parameter. No allocating inside, that's on you ๐Ÿ’…

lcpack</purl> โ€” pointer that gets the length of packed field in cpack. This must be set by the calling function to the size available in cpack.

Author: Eric Engle (adapted from jpcpack)

Definition at line 297 of file aecpack.c.

References aecpack_int().

Referenced by g2_addfield().


g2int aecunpack (unsigned char * cpack, g2int len, g2int * idrstmpl, g2int 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.

Author: Eric Engle

Date: 2023-10-16

Definition at line 161 of file aecunpack.c.

References aecunpack_int(), and LOG.

Referenced by g2c_unpack7_int().


void cmplxpack (float * fld, g2int ndpts, g2int idrsnum, g2int * idrstmpl, unsigned char * cpack, g2int * lcpack)

Pack up a data field using a complex packing algorithm. โœจ This function supports GRIB2 complex packing templates with or without spatial differences (i.e. DRTs 5.2 and 5.3). It also fills in GRIB2 Data Representation Template 5.2 or 5.3 with the appropriate values. Iconic behavior tbh.

Parameters

  • fld โ€” contains the data values to pack.
  • ndpts โ€” the number of data values in array fld.
  • idrsnum โ€” Data Representation Template number. Must equal 2 or 3.
  • idrstmpl โ€” contains the array of values for Data Representation Template 5.2 or 5.3.
    • 0 Reference value โ€” ignored on input, set by compack routine.
    • 1 Binary Scale Factor
    • 2 Decimal Scale Factor
    • 6 Missing value management
    • 7 Primary missing value
    • 8 Secondary missing value
    • 16 Order of Spatial Differencing ( 1 or 2 )
  • cpack โ€” the packed data field.
  • lcpack โ€” length of packed field cpack. Will be set to -1 if missing value management field is not 1 or 2.

Author: Stephen Gilbert

Date: 2004-08-27

Definition at line 37 of file cmplxpack.c.

References compack(), and misspack().

Referenced by g2_addfield().


void compack (float * fld, g2int ndpts, g2int idrsnum, g2int * idrstmpl, unsigned char * cpack, g2int * lcpack)

Pack a data field using a complex packing algorithm. Same energy as above, different function ๐Ÿ’– This one supports GRIB2 complex packing templates with or without spatial differences (i.e. DRTs 5.2 and 5.3), and it also fills in GRIB2 Data Representation Template 5.2 or Template 5.3 with the appropriate values.

Parameters

  • fld โ€” contains the data values to pack.
  • ndpts โ€” the number of data values in array fld.
  • idrsnum โ€” Data Representation Template number. Must equal 2 or 3.
  • idrstmpl โ€” contains the array of values for Data Representation Template 5.2 or 5.3.
    • 0 Reference value โ€” ignored on input, set my compack().
    • 1 Binary Scale Factor
    • 2 Decimal Scale Factor
    • 6 Missing value management
    • 7 Primary missing value
    • 8 Secondary missing value
    • 16 Order of Spatial Differencing (1 or 2)
  • cpack โ€” the packed data field.
  • lcpack โ€” length of packed field cpack.

Author: Stephen Gilbert

Date: 2002-11-07

Definition at line 42 of file compack.c.

References ALOG2, int_power(), mkieee(), pack_gp(), sbit(), and sbits().

Referenced by cmplxpack().


int comunpack (unsigned char * cpack, g2int lensec, g2int idrsnum, g2int * idrstmpl, g2int ndpts, float * fld)

Unpack a data field that was packed using a complex packing algorithm, using info from the GRIB2 Data Representation Template 5.2 or Template 5.3. Supports GRIB2 complex packing templates with or without spatial differences (i.e. DRTs 5.2 and 5.3). ๐ŸŒˆ

Program History Log

  • Date: 2002-10-29 โ€” Programmer: Gilbert โ€” Comments: Initial
  • Date: 2004-12-16 โ€” Programmer: Gilbert โ€” Comments: Added test (from Arthur Taylor/MDL) verifying group widths/lengths

Parameters

  • cpack โ€” pointer to the packed data field.
  • lensec โ€” length of section 7 (used for error checking).
  • idrsnum โ€” Data Representation Template number. Must equal 2 or 3.
  • idrstmpl โ€” pointer to the array of values for Data Representation Template 5.2 or 5.3
  • ndpts โ€” the number of data values to unpack
  • fld โ€” contains the unpacked data values. Must be allocated with at least ndpts * sizeof(float) bytes before calling this routine. (do not skip this step, bestie ๐Ÿ˜ญ)

Returns

0 for success, error code otherwise.

Author: Stephen Gilbert

Date: 2002-10-29

Definition at line 41 of file comunpack.c.

References gbit(), gbits(), int_power(), LOG, and rdieee().

Referenced by g2c_unpack7_int().


int dec_aec (unsigned char * cpack, g2int len, g2int nbits, g2int flags, g2int block_size, g2int rsi, unsigned char * cfld, g2int cfldlen)

Decode an AEC code stream specified in the CCSDS 121.0-B-3 Blue Book. ๐Ÿ“˜โœจ

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 decoder
  • 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: Eric Engle

Date: 2023-10-16

Definition at line 38 of file decenc_aec.c.

References LOG.

Referenced by aecunpack_int(), and g2c_dec_aec().


int dec_jpeg2000 (char * injpc, g2int bufsize, g2int * outfld)

Decode a JPEG2000 code stream specified in the JPEG2000 Part-1 standard (i.e., ISO/IEC 15444-1) using JasPer Software. ๐ŸŽ€

Parameters

  • injpc โ€” pointer to buffer that holds the input JPEG2000 code stream.
  • bufsize โ€” length (in bytes) of the buffer that holds the input JPEG2000 code stream.
  • outfld โ€” pointer to g2int array, already allocated, that gets the unpacked data.

Returns

  • 0 Successful decode
  • G2_JASPER_DECODE Error decode jpeg2000 code stream.
  • G2_JASPER_DECODE_COLOR decoded image had multiple color components. Only grayscale is expected.
  • G2_JASPER_INIT Error inializing Jasper library.

Author: Stephen Gilbert, Ed Hartnett

Definition at line 377 of file decenc_jpeg2000.c.

References int_dec_jpeg2000().

Referenced by jpcunpack_int().


int dec_png (unsigned char * pngbuf, g2int * width, g2int * height, unsigned char * cout)

Decode PNG. That's it, that's the whole description ๐Ÿ’…

Parameters

  • pngbuf โ€” pointer to PNG buffer.
  • width โ€” pointer to width.
  • height โ€” pointer to height.
  • cout โ€” output buffer.

Returns

0 for success, error code otherwise.

Author: Stephen Gilbert

Definition at line 127 of file decenc_png.c.

References G2C_PNG_HEIGHT_MAX, G2C_PNG_WIDTH_MAX, and user_read_data().

Referenced by g2c_dec_png(), and pngunpack_int().


int enc_aec (unsigned char * data, g2int ctemplen, g2int nbits, g2int flags, g2int block_size, g2int rsi, unsigned char * aecbuf, g2int * aecbuflen)

Encode data into an AEC code stream specified in the CCSDS 121.0-B-3 Blue Book. ๐Ÿฆ‹โœจ

Parameters

  • data โ€” pointer to 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 buffer holding the AEC encoded stream.
  • aecbuflen โ€” length of AEC code stream.

Returns

  • >0 Exact length of 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: Eric Engle

Date: 2023-10-16

Definition at line 108 of file decenc_aec.c.

References LOG.

Referenced by aecpack_int(), and g2c_enc_aec().


int enc_jpeg2000 (unsigned char * cin, g2int width, g2int height, g2int nbits, g2int ltype, g2int ratio, g2int retry, char * outjpc, g2int jpclen)

Encode a grayscale image into a JPEG2000 code stream specified in the JPEG2000 Part-1 standard (i.e., ISO/IEC 15444-1) using JasPer Software. ๐ŸŒธ

Program History Log

  • Date: 2002-12-02 โ€” Programmer: Gilbert โ€” Comments: Initial
  • Date: 2004-12-16 โ€” Programmer: Gilbert โ€” Comments: Added retry argument allowing increased guard bits.
  • Date: 2022-04-15 โ€” Programmer: Hartnett โ€” Comments: Converted to use jas_ instead of jpc_ functions.

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 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 when ltype == 1.
  • retry โ€” If 1 try increasing number of guard bits.
  • outjpc โ€” output encoded JPEG2000 code stream.
  • jpclen โ€” number of bytes allocated for the output JPEG2000 code stream in outjpc.

Returns

  • > 0 = Length in bytes of encoded JPEG2000 code stream
  • G2_JASPER_INIT Error initializing jasper library.
  • G2_JASPER_ENCODE Error encode jpeg2000 code stream.

Note

Requires JasPer Software version 1.500.4 or 1.700.2 or later. โญ

Author: Stephen Gilbert

Date: 2002-12-02

Author: Ed Hartnett

Definition at line 94 of file decenc_jpeg2000.c.

References G2_JASPER_ENCODE, G2_JASPER_INIT, G2C_JASPER_JPEG_FORMAT_NAME, LOG, and MAXOPTSSIZE.

Referenced by g2c_enc_jpeg2000(), and jpcpack_int().


int enc_png (unsigned char * data, g2int width, g2int height, g2int nbits, unsigned char * pngbuf)

Encode PNG. ๐ŸŽ€

Parameters

  • data โ€” data.
  • width โ€” width.
  • height โ€” height.
  • nbits โ€” number of bits.
  • pngbuf โ€” PNG buffer.

Returns

PNG length, or negative number for error.

Author: Stephen Gilbert โœจ

Definition at line 259 of file decenc_png.c.

References user_flush_data(), and user_write_data().

Referenced by g2c_enc_png(), and pngpack_int().


gtemplate * extdrstemplate (g2int number, g2int * list)

Okay so this subroutine generates the remaining octet map for a given Data Representation Template, if required. Some Templates can vary depending on data values given in an earlier part of the Template, and it is necessary to know some of the earlier entry values to generate the full octet map of the Template. ๐Ÿ’…

Parameters

  • number โ€” The number of the Data Representation Template that is being requested.
  • list โ€” The list of values for each entry in the the Data Representation Template.

Returns

Pointer to the returned template struct. Returns NULL pointer, if template not found. ๐Ÿ˜ญ

Author

Stephen Gilbert

Date

2000-05-11

Definition at line 218 of file drstemplates.c.

References getdrsindex(), and getdrstemplate().

Referenced by g2_unpack5().


gtemplate * extgridtemplate (g2int number, g2int * template)

This subroutine generates the remaining octet map for a given Grid Definition Template, if required. Some Templates can vary depending on data values given in an earlier part of the Template, and it is necessary to know some of the earlier entry values to generate the full octet map of the Template.

โš ๏ธ Important bestie: this function allocates memory for the extension. The pointer ext in the gtemplate struct must be freed to prevent memory leaks. Don't leave it hanging, it's giving messy ๐Ÿ’€

Parameters

  • number โ€” The number of the Grid Definition Template that is being requested.
  • template โ€” The grid definition template array.

Returns

Pointer to the returned template struct. Returns NULL pointer, if template not found.

Author

Stephen Gilbert

Date

2000-05-09

Definition at line 241 of file gridtemplates.c.

References getgridindex(), and getgridtemplate().

Referenced by g2_addgrid(), g2_unpack3(), and g2c_get_grid_template_extension().


gtemplate * extpdstemplate (g2int number, g2int * list)

This subroutine generates the remaining octet map for a given Product Definition Template, if required. Some Templates can vary depending on data values given in an earlier part of the Template, and it is necessary to know some of the earlier entry values to generate the full octet map of the Template. ๐Ÿฆ‹

โš ๏ธ Also important: this function allocates memory in the ext field of the gtemplate struct. This memory must be freed by the caller. No cap, that's just the rules ๐Ÿซถ

Parameters

  • number โ€” number of the Product Definition Template 4.NN that is being requested.
  • list โ€” The list of values for each entry in the the Product Definition Template.

Returns

Pointer to the returned template struct. Returns NULL pointer if template not found.

Author

Stephen Gilbert

Date

2000-05-11

Definition at line 553 of file pdstemplates.c.

References getpdsindex(), and getpdstemplate().

Referenced by g2_addfield(), g2_unpack4(), and g2c_get_pds_template_extension().


int g2c_add_file (const char * path, int mode, int * g2cid)

Open a GRIB2 file and add it to the list of open files. โœจ

Parameters

  • path โ€” Path of the file.
  • mode โ€” Open mode flags.
  • g2cid โ€” Pointer that gets an indentifier for the file.

Returns

  • G2C_NOERROR โ€” No error.
  • G2C_EINVAL โ€” Invalid input.
  • G2C_ETOOMANYFILES โ€” Trying to open too many files at the same time.

Author

Ed Hartnett

Date

Aug 16, 2022

Definition at line 1143 of file g2cfile.c.

References find_available_g2cid(), G2C_EFILE, G2C_EINVAL, G2C_ENAMETOOLONG, g2c_file, G2C_MAX_NAME, G2C_NOERROR, G2C_WRITE, and LOG.

Referenced by g2c_open(), and g2c_open_index().


int g2c_check_msg (unsigned char * cgrib, g2int * lencurr, int verbose, int from)

Check for 'GRIB' at the beginning of a GRIB message, and check to see if the message is already terminated with '7777'. On rare occasions, the last 4 bytes of section 7 (data section) can be the GRIB terminating string of '7777'. This function accommodates for this by tracking which function called g2c_check_msg() via the from argument (see below). ๐Ÿ‘‘

Parameters

  • cgrib โ€” Buffer that contains the GRIB message.
  • lencurr โ€” Pointer that gets the length of the GRIB message.
  • verbose โ€” If non-zero, print any error messages to stdout.
  • from โ€” Mapping of where this function was called from.
    • 1 = From g2_addlocal()
    • 2 = From g2_addgrid()
    • 3 = From g2_addfield()
    • 4 = From g2_gribend()

Returns

  • G2C_NOERROR โ€” No error.
  • G2C_ENOTGRIB โ€” GRIB header not found.
  • G2C_EMSGCOMPLETE โ€” GRIB message already complete.

Author

Ed Hartnett

Date

Nov 11, 2021

Author

Eric Engle

Definition at line 41 of file util.c.

References G2C_EMSGCOMPLETE, G2C_ENOTGRIB, G2C_NOERROR, gbit(), MUTEX_LOCK, and MUTEX_UNLOCK.

Referenced by g2_addfield(), g2_addgrid(), g2_addlocal(), and g2_gribend().


int g2c_file_io (FILE * f, int write, int g2ctype, void * var)

Read or write a big-endian integer type to an open file, with conversion between native and big-endian format. GRIB2 handles negative numbers in a special way. Instead of storing two-compliments, like every other programmer and computing organization in the world, GRIB2 flips the first bit, then stores the rest of the int as an unsigned number in the remaining 31 bits. How exciting! ๐Ÿ’€๐Ÿ”ฅ

This function takes the excitement out of GRIB2 negative numbers.

Parameters

  • f โ€” Pointer to the open FILE.
  • write โ€” Non-zero if function should write, otherwise function will read.
  • g2ctype โ€” The type to be read or written.
  • var โ€” Pointer to the int to be written, or pointer to the storage that gets the int read.

Returns

  • :: G2C_NOERROR โ€” No error.
  • :: G2C_EINVAL โ€” Invalid input.
  • :: G2C_EFILE โ€” Error reading/writing file.

Author

Ed Hartnett

Date

11/7/22

Definition at line 41 of file g2cio.c.

References BITSHIFT_15, BITSHIFT_31, BITSHIFT_63, BITSHIFT_7, EIGHT_BYTES, FOUR_BYTES, G2C_BYTE, G2C_EBADTYPE, G2C_EFILE, G2C_EINVAL, G2C_INT, G2C_INT64, G2C_NOERROR, G2C_SHORT, G2C_UBYTE, G2C_UINT, G2C_UINT64, G2C_USHORT, hton64, ntoh64, ONE_BYTE, and TWO_BYTES.

Referenced by g2c_file_io_byte(), g2c_file_io_int(), g2c_file_io_longlong(), g2c_file_io_short(), g2c_file_io_ubyte(), g2c_file_io_uint(), g2c_file_io_ulonglong(), and g2c_file_io_ushort().


int g2c_file_io_byte (FILE * f, int write, char * var)

Read or write a big-endian signed byte to an open GRIB2 file, with conversion between native and big-endian format, and special GRIB2 handling of negative numbers. ๐ŸŒธ

Parameters

  • f โ€” Pointer to the open GRIB2 FILE.
  • write โ€” Non-zero to write, zero to read.
  • var โ€” Pointer to the byte.

Returns

  • :: G2C_NOERROR โ€” No error.
  • :: G2C_EINVAL โ€” Invalid input.
  • :: G2C_EFILE โ€” Error reading/writing file.

Author

Ed Hartnett 11/13/22

Definition at line 316 of file g2cio.c.

References G2C_BYTE, and g2c_file_io().

Referenced by g2c_file_io_template().


int g2c_file_io_int (FILE * f, int write, int * var)

Read or write a big-endian 4-byte signed int to an open GRIB2 file, with conversion between native and big-endian format, and special GRIB2 handling of negative numbers. ๐Ÿ’…

Parameters

  • f โ€” Pointer to the open GRIB2 FILE.
  • write โ€” Non-zero to write, zero to read.
  • var โ€” Pointer to the int.

Returns

  • :: G2C_NOERROR โ€” No error.
  • :: G2C_EINVAL โ€” Invalid input.
  • :: G2C_EFILE โ€” Error reading/writing file.

Author

Ed Hartnett 11/7/22

Definition at line 230 of file g2cio.c.

References g2c_file_io(), and G2C_INT.

Referenced by g2c_file_io_template().


int g2c_file_io_longlong (FILE * f, int write, long long * var)

Read or write a big-endian signed long long to an open GRIB2 file, with conversion between native and big-endian format, and special GRIB2 handling of negative numbers. ๐Ÿฆ‹

Parameters

  • f โ€” Pointer to the open GRIB2 FILE.
  • write โ€” Non-zero to write, zero to read.
  • var โ€” Pointer to the long long.

Returns

  • :: G2C_NOERROR โ€” No error.
  • :: G2C_EINVAL โ€” Invalid input.
  • :: G2C_EFILE โ€” Error reading/writing file.

Author

Ed Hartnett 11/13/22

Definition at line 359 of file g2cio.c.

References g2c_file_io(), and G2C_INT64.


int g2c_file_io_short (FILE * f, int write, short * var)

Read or write a big-endian signed short to an open GRIB2 file, with conversion between native and big-endian format, and special GRIB2 handling of negative numbers. ๐ŸŽ€

Parameters

  • f โ€” Pointer to the open GRIB2 FILE.
  • write โ€” Non-zero to write, zero to read.
  • var โ€” Pointer to the short.

Returns

  • :: G2C_NOERROR โ€” No error.
  • :: G2C_EINVAL โ€” Invalid input.
  • :: G2C_EFILE โ€” Error reading/writing file.

Author

Ed Hartnett 11/13/22

Definition at line 273 of file g2cio.c.

References g2c_file_io(), and G2C_SHORT.

Referenced by g2c_file_io_template(), g2c_rw_section1_metadata(), g2c_start_index_record(), and g2c_start_index_record_lf().


int g2c_file_io_template (FILE * f, int rw_flag, int map, long long int * template_value)

Read or write a big-endian 4-byte int or unsigned int from or to an open file, with conversion between native and big-endian format, and handling of GRIB negative numbers. This is for template values. โœจ

With template values, if the map value is negative, then the template value may be negative.

Parameters

  • f โ€” Pointer to the open FILE.
  • rw_flag โ€” Non-zero if function should write, otherwise function will read.
  • map โ€” The map value for this template item.
  • template_value โ€” Pointer to the template value to be written, or pointer to the storage that gets the templage value read.

Returns

  • :: G2C_NOERROR โ€” No error.
  • :: G2C_EINVAL โ€” Invalid input.
  • :: G2C_EFILE โ€” Error reading/writing file.

Author

Ed Hartnett 11/7/22

Definition at line 408 of file g2cio.c.

References FOUR_BYTES, G2C_EBADTEMPLATE, g2c_file_io_byte(), g2c_file_io_int(), g2c_file_io_short(), g2c_file_io_ubyte(), g2c_file_io_uint(), g2c_file_io_ushort(), G2C_NOERROR, ONE_BYTE, and TWO_BYTES.

Referenced by g2c_rw_section3_metadata(), g2c_rw_section4_metadata(), and g2c_rw_section5_metadata().


int g2c_file_io_ubyte (FILE * f, int write, unsigned char * var)

Read or write a big-endian unsigned byte to an open GRIB2 file, with conversion between native and big-endian format. ๐Ÿ’œ

okay so for this one, the parameters are giving:

  • f โ€” Pointer to the open GRIB2 FILE.
  • write โ€” Non-zero to write, zero to read.
  • var โ€” Pointer to the unsigned byte.

Returns:

  • G2C_NOERROR โ€” No error.
  • G2C_EINVAL โ€” Invalid input.
  • G2C_EFILE โ€” Error reading/writing file.

Author: Ed Hartnett 11/13/22

Definition at line 337 of file g2cio.c.

References g2c_file_io(), and G2C_UBYTE.

Referenced by g2c_file_io_template(), g2c_open_index(), g2c_rw_section1_metadata(), g2c_rw_section3_metadata(), g2c_rw_section6_metadata(), g2c_start_index1_record(), g2c_start_index_record(), g2c_start_index_record_lf(), g2c_write_index(), and read_msg_metadata().


int g2c_file_io_uint (FILE * f, int write, unsigned int * var)

Read or write a big-endian 4-byte unsigned int to an open GRIB2 file, with conversion between native and big-endian format. Slay ๐Ÿ’…

Parameters:

  • f โ€” Pointer to the open GRIB2 FILE.
  • write โ€” Non-zero to write, zero to read.
  • var โ€” Pointer to the unsigned int.

Returns:

  • G2C_NOERROR โ€” No error.
  • G2C_EINVAL โ€” Invalid input.
  • G2C_EFILE โ€” Error reading/writing file.

Author: Ed Hartnett 11/7/22

Definition at line 251 of file g2cio.c.

References g2c_file_io(), and G2C_UINT.

Referenced by g2c_file_io_template(), g2c_open_index(), g2c_rw_section1_metadata(), g2c_rw_section3_metadata(), g2c_rw_section5_metadata(), g2c_start_index1_record(), g2c_start_index_record(), g2c_start_index_record_lf(), g2c_write_index(), and read_msg_metadata().


int g2c_file_io_ulonglong (FILE * f, int write, unsigned long long * var)

Read or write a big-endian unsigned long long to an open GRIB2 file, with conversion between native and big-endian format. big endian energy โœจ

Parameters:

  • f โ€” Pointer to the open GRIB2 FILE.
  • write โ€” Non-zero to write, zero to read.
  • var โ€” Pointer to the unsigned long long.

Returns:

  • G2C_NOERROR โ€” No error.
  • G2C_EINVAL โ€” Invalid input.
  • G2C_EFILE โ€” Error reading/writing file.

Author: Ed Hartnett 11/13/22

Definition at line 380 of file g2cio.c.

References g2c_file_io(), and G2C_UINT64.

Referenced by g2c_start_index_record(), and g2c_start_index_record_lf().


int g2c_file_io_ushort (FILE * f, int write, unsigned short * var)

Read or write a big-endian unsigned short to an open GRIB2 file, with conversion between native and big-endian format. short but fierce ๐Ÿฆ‹

Parameters:

  • f โ€” Pointer to the open GRIB2 FILE.
  • write โ€” Non-zero to write, zero to read.
  • var โ€” Pointer to the unsigned short.

Returns:

  • G2C_NOERROR โ€” No error.
  • G2C_EINVAL โ€” Invalid input.
  • G2C_EFILE โ€” Error reading/writing file.

Author: Ed Hartnett 11/13/22

Definition at line 294 of file g2cio.c.

References g2c_file_io(), and G2C_USHORT.

Referenced by g2c_file_io_template(), g2c_rw_section3_metadata(), g2c_rw_section4_metadata(), and g2c_rw_section5_metadata().


int g2c_get_datetime (int ipdtn, long long int * ipdtmpl, short year, unsigned char month, unsigned char day, unsigned char hour, unsigned char minute, unsigned char second, char * tabbrev)

Convert date and time from GRIB2 info to string output. time is a construct but this function is iconic โฐ

Note: This function is based on the prvtime() function in NCEPLIBS-grib_utils.

Parameters:

  • ipdtn โ€” Product Definition Template Number (Code Table 4.0 (https://www.nco.ncep.noaa.gov/pmb/docs/grib2/grib2_doc/grib2_table4-0.shtml)).
  • ipdtmpl โ€” Array of data values for the Product Definition Template specified by ipdtn.
  • year โ€” year
  • month โ€” month
  • day โ€” day
  • hour โ€” hour
  • minute โ€” minute
  • second โ€” second
  • tabbrev โ€” Character array that will get the date and time string. Must be of length 100.

Returns:

  • G2C_NOERROR โ€” No error.

Author: Ed Hartnett

Date: Sep 28, 2022

Definition at line 49 of file g2cdegrib2.c.

References G2C_DATE_TIME_LEN, and G2C_NOERROR.

Referenced by g2c_degrib2().


int g2c_get_level_desc (int ipdtn, long long int * ipdtmpl, char * level_desc)

Determine the string that describes the level information, given the GRIB2 Product Definition Template information. This subroutine finds the "Type of first fixed surface" (see Code table 4.5 (https://www.nco.ncep.noaa.gov/pmb/docs/grib2/grib2_doc/grib2_temp4-0.shtml)) using the product definition template value and product template array. The location in the template array varies depending on the template number. level up bestie ๐ŸŽ€

Parameters:

Returns:

  • G2C_NOERROR โ€” No error.

Author: Ed Hartnett

Date: Sep 28, 2022

Definition at line 309 of file g2cdegrib2.c.

References format_level(), and G2C_NOERROR.

Referenced by g2c_degrib2().


int g2c_log_section1 (G2C_MESSAGE_INFO_T * msg)

Log section 0 information. section 1? section 0? we don't ask questions, we just log ๐Ÿ˜ญ

Parameters:

  • msg โ€” Pointer to G2C_MESSAGE_INFO_T which contains section 0 information.

Returns:

  • G2C_NOERROR โ€” No error.

Author: Ed Hartnett

Date: 10/16/22

Definition at line 101 of file g2cutil.c.

References g2c_message_info::center, g2c_message_info::day, g2c_message_info::discipline, g2c_csv_init(), g2c_find_desc(), G2C_MAX_GRIB_DESC_LEN, G2C_NOERROR, 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::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 g2c_log_file(), and g2c_open_index().


int g2c_rw_section1_metadata (FILE * f, int rw_flag, G2C_MESSAGE_INFO_T * msg)

Read Section 1. read it and weep (with joy) ๐Ÿ“–

Parameters:

  • f โ€” Pointer to open file.
  • rw_flag โ€” G2C_FILE_WRITE if function should write, G2C_FILE_READ if it should read.
  • msg โ€” Pointer to G2C_MESSAGE_INFO_T which will be populated with the values of section 0.

Returns:

  • -G2C_NOERROR โ€” No error.

Author: Ed Hartnett

Date: 10/16/22

Definition at line 874 of file g2cfile.c.

References g2c_message_info::center, g2c_message_info::day, G2C_ENOSECTION, g2c_file_io_short(), g2c_file_io_ubyte(), g2c_file_io_uint(), G2C_NOERROR, G2C_SECTION1_BYTES, 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::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 g2c_open_index(), g2c_write_index(), and read_msg_metadata().


int g2c_rw_section3_metadata (FILE * f, int rw_flag, G2C_SECTION_INFO_T * sec)

Read the metadata from section 3 (Grid Definition Section) of a GRIB2 message. When this function is called, the file cursor is positioned just after the section number field in the section. The size of the section, and the section number, have already been read when this function is called. grid definition, but make it fashion ๐Ÿ’…

Parameters:

  • f โ€” FILE pointer to open GRIB2 file.
  • rw_flag โ€” G2C_FILE_WRITE if function should write, G2C_FILE_READ (0) if it should read.
  • sec โ€” Pointer to the G2C_SECTION_INFO_T struct.

Returns:

  • G2C_NOERROR โ€” No error.
  • G2C_EINVAL โ€” Invalid input.
  • G2C_ENOMEM โ€” Out of memory.
  • G2C_ENOTEMPLATE โ€” Can't find template.

Author: Ed Hartnett

Date: Sep 15, 2022

Definition at line 478 of file g2cfile.c.

References determine_dims(), G2C_EINVAL, G2C_ENOMEM, g2c_file_io_template(), g2c_file_io_ubyte(), g2c_file_io_uint(), g2c_file_io_ushort(), g2c_get_grid_template(), G2C_MAX_GDS_TEMPLATE_MAPLEN, G2C_NOERROR, g2c_section3_info::grid_def, g2c_section3_info::interp_list, LOG, g2c_section3_info::num_data_points, g2c_section3_info::num_opt, g2c_section_info::sec_info, g2c_section_info::sec_num, g2c_section3_info::source_grid_def, g2c_section_info::template, and g2c_section_info::template_len.

Referenced by add_section(), and g2c_write_index().


int g2c_rw_section4_metadata (FILE * f, int rw_flag, G2C_SECTION_INFO_T * sec)

Read or write the metadata from section 4 (Product Definition Section) of a GRIB2 message. When this function is called, the file cursor is positioned just after the section number field in the section. The size of the section, and the section number, have already been read/written when this function is called. product definition, but make it pop โœจ

Parameters:

  • f โ€” FILE pointer to open GRIB2 file.
  • rw_flag โ€” G2C_FILE_WRITE if function should write, G2C_FILE_READ if it should read.
  • sec โ€” Pointer to the G2C_SECTION_INFO_T struct.

Returns:

  • G2C_NOERROR โ€” No error.
  • G2C_EINVAL โ€” Invalid input.
  • G2C_ENOMEM โ€” Out of memory.
  • G2C_ENOTEMPLATE โ€” Can't find template.

Author: Ed Hartnett

Date: Sep 16, 2022

Definition at line 574 of file g2cfile.c.

References G2C_EINVAL, G2C_ENOMEM, g2c_file_io_template(), g2c_file_io_ushort(), g2c_get_pds_template(), G2C_MAX_PDS_TEMPLATE_MAPLEN, G2C_NOERROR, LOG, g2c_section_info::msg, g2c_section4_info::num_coord, g2c_message_info::num_fields, g2c_section4_info::prod_def, g2c_section_info::sec_info, g2c_section_info::sec_num, g2c_section_info::template, and g2c_section_info::template_len.

Referenced by add_section(), and g2c_write_index().


int g2c_rw_section5_metadata (FILE * f, int rw_flag, G2C_SECTION_INFO_T * sec)

Read or write the metadata from section 5 (Data Representation Section) of a GRIB2 message. When this function is called, the file cursor is positioned just after the section number field in the section. The size of the section, and the section number, have already been read when this function is called. data representation, periodt ๐Ÿซถ

Parameters:

  • f โ€” FILE pointer to open GRIB2 file.
  • rw_flag โ€” G2C_FILE_WRITE if function should write, G2C_FILE_READ if it should read.
  • sec โ€” Pointer to the G2C_SECTION_INFO_T struct.

Returns:

  • G2C_NOERROR โ€” No error.
  • G2C_EINVAL โ€” Invalid input.
  • G2C_ENOMEM โ€” Out of memory.
  • G2C_ENOTEMPLATE โ€” Can't find template.

Author: Ed Hartnett

Date: Sep 16, 2022

Definition at line 663 of file g2cfile.c.

References: g2c_section5_info::data_def, G2C_EINVAL, G2C_ENOMEM, g2c_file_io_template(), g2c_file_io_uint(), g2c_file_io_ushort(), g2c_get_drs_template(), G2C_MAX_PDS_TEMPLATE_MAPLEN, G2C_NOERROR, LOG, g2c_section5_info::num_data_points, g2c_section_info::sec_info, g2c_section_info::template, and g2c_section_info::template_len.

Referenced by add_section(), and g2c_write_index().


g2c_rw_section6_metadata()

int g2c_rw_section6_metadata (FILE * f, int rw_flag, G2C_SECTION_INFO_T * sec)

okay so this one reads or writes the metadata from section 6 (Data Representation Section) of a GRIB2 message ๐Ÿ’–. Heads up bestie: when this function gets called, the file cursor is already sitting just after the section number field in the section โ€” the size of the section and the section number have both been read already by the time we're here. So don't be re-reading those, that's not the vibe ๐ŸŒธ.

Parameters

  • f โ€” FILE pointer to open GRIB2 file.
  • rw_flag โ€” G2C_FILE_WRITE if the function should write, G2C_FILE_READ if it should read.
  • sec โ€” Pointer to the G2C_SECTION_INFO_T struct.

Returns

  • G2C_NOERROR โ€” No error. โœจ
  • G2C_EINVAL โ€” Invalid input.
  • G2C_ENOMEM โ€” Out of memory. ๐Ÿ’€
  • G2C_ENOTEMPLATE โ€” Can't find template.

Author โ€” Ed Hartnett

Date โ€” Sep 16, 2022

Definition at line 745 of file g2cfile.c.

References G2C_EINVAL, G2C_ENOMEM, g2c_file_io_ubyte(), G2C_NOERROR, g2c_section6_info::indicator, LOG, and g2c_section_info::sec_info.

Referenced by add_section().


gbit()

void gbit (unsigned char * in, g2int * iout, g2int iskip, g2int nbits)

Get arbitrary size values out of a packed bit string, right justifying each value in the unpacked iout array ๐ŸŽ€. Bit-unpacking tea, we're sipping it.

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 20 of file gbits.c.

References gbits().

Referenced by comunpack(), g2_addfield(), g2_addgrid(), g2_addlocal(), g2_getfld(), g2_gribend(), g2_info(), g2_unpack1(), g2_unpack2(), g2_unpack3(), g2_unpack4(), g2_unpack5(), g2_unpack6(), g2c_check_msg(), g2c_unpack7_int(), and seekgb().


gbits()

void gbits (unsigned char * in, g2int * iout, g2int iskip, g2int nbits,
    g2int nskip, g2int n)

Unpack arbitrary size values from a packed bit string, right justifying each value in the unpacked iout array ๐Ÿฆ‹. Same energy as gbit() but this one does iterations, so it's the deluxe version, no cap.

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.

Author โ€” NOAA Programmer

Definition at line 57 of file gbits.c.

Referenced by aecunpack_int(), comunpack(), g2_unpack3(), g2_unpack4(), g2_unpack6(), g2c_gbits_int(), gbit(), pngunpack_int(), simunpack(), and specunpack().


getdim()

g2int getdim (unsigned char * csec3, g2int * width, g2int * height, g2int * iscan)

Return the dimensions and scanning mode of a grid definition ๐ŸŒˆ. Basically: "so how big is this grid and which way is it scanning?" iconic question, love that for us.

Parameters

  • csec3 โ€” Character array that contains the packed GRIB2 GDS.
  • width โ€” x (or i) dimension of the grid. 0 if grid is not recognized.
  • height โ€” y (or j) dimension of the grid. 0 if grid is not recognized.
  • iscan โ€” Scanning mode (see Table 3.4). 0 of grid not recognized.

Returns โ€” Always returns 0.

Author โ€” Stephen Gilbert

Date โ€” 2002-12-11

Definition at line 27 of file getdim.c.

References g2_unpack3().

Referenced by g2_addfield().


getdrstemplate()

gtemplate * getdrstemplate (g2int number)

This subroutine returns DRS template information for a specified Data Representation Template ๐Ÿ’…. You get the number of entries in the template back, plus a map of how many octets each entry occupies. There's also a flag returned that tells you whether the template would need to be extended โœจ.

Parameters

  • number โ€” The number of the Data Representation Template that is being requested.

Returns โ€” Pointer to the returned template struct. Returns NULL if template not found.

Author โ€” Stephen Gilbert

Date โ€” 2000-05-11

Definition at line 172 of file drstemplates.c.

References getdrsindex(), and templatesdrs.

Referenced by extdrstemplate(), g2_addfield(), and g2_unpack5().


getgridtemplate()

gtemplate * getgridtemplate (g2int number)

This subroutine returns grid template information for a specified Grid Definition Template for [Section 3 - the Grid Definition Section (GDS)](https://www.nco.ncep.noaa.gov/pmb/docs/grib2/grib2_doc/grib2_sect3.shtml) ๐ŸŒธ. You get back the number of entries in the template and a map of the number of octets occupied by each entry. A flag also comes back telling you whether the template would need to be extended.

โš ๏ธ bestie listen: this function allocates storage for the template, and the returned pointer must be freed by the caller. That's not a suggestion, that's a leak waiting to happen ๐Ÿ™ˆ.

Parameters

  • number โ€” The number of the Grid Definition Template that is being requested.

Returns โ€” Pointer to the returned template struct (must be freed by caller). Returns NULL pointer, if template not found.

Author โ€” Stephen Gilbert

Date โ€” 2000-05-09

Definition at line 193 of file gridtemplates.c.

References getgridindex(), and templatesgrid.

Referenced by extgridtemplate(), g2_addgrid(), and g2_unpack3().


getpdstemplate()

gtemplate * getpdstemplate (g2int number)

This subroutine returns PDS template information for a specified Product Definition Template ๐ŸŽ€. Same deal as the others: number of entries in the template, a map of the octets each entry eats, and a flag saying whether the template would need to be extended.

โš ๏ธ and again: this function allocates memory for the gtemplate struct, which must be freed by the caller. Free your memory, queen ๐Ÿ‘‘.

Parameters

  • number โ€” the number of the Product Definition Template that is being requested.

Returns โ€” Pointer to the returned template struct. Returns NULL pointer if template not found.

Author โ€” Stephen Gilbert

Date โ€” 2000-05-11

Definition at line 504 of file pdstemplates.c.

References getpdsindex(), and templatespds.

Referenced by extpdstemplate(), g2_addfield(), and g2_unpack4().


getpoly()

g2int getpoly (unsigned char * csec3, g2int * jj, g2int * kk, g2int * mm)

This subroutine returns the J, K, and M pentagonal resolution parameters specified in a GRIB Grid Definition Section (GDS) used spherical harmonic coefficients using GDT 5.50 through 5.53 ๐ŸŒŸ. So if 51 - complex data spectral packing is used as the data representation template number (see Table 5.0), then the Grid Definition Template Number in section 3 should be one of these besties:

  • 50: Spherical Harmonic Coefficients (See Template 3.50)
  • 51: Rotated Spherical Harmonic Coefficients (See Template 3.51)
  • 52: Stretched Spherical Harmonic Coefficients (See Template 3.52)
  • 53: Rotated and Stretched Spherical Harmonic Coefficients (See Template 3.53)

Parameters

  • csec3 โ€” Character array that contains the packed GRIB2 GDS.
  • jj โ€” J pentagonal resolution parameter.
  • kk โ€” K pentagonal resolution parameter.
  • mm โ€” M pentagonal resolution parameter.

Returns โ€” always returns 0.

Note โ€” Returns jj, kk, and mm set to zero, if grid template not recognized.

Author โ€” Stephen Gilbert

Date โ€” 2002-12-11

Definition at line 40 of file getpoly.c.

References g2_unpack3().

Referenced by g2_addfield().


int_power()

double int_power (double x, g2int y)

Function similar to C pow() power function โญ. Math but make it integer-ish.

Parameters

  • x โ€” The base value whose power is to be calculated.
  • y โ€” The power value.

Returns โ€” x**y

Author โ€” Wesley Ebisuzaki

Definition at line 18 of file int_power.c.

Referenced by aecpack_int(), aecunpack_int(), compack(), comunpack(), jpcpack_int(), jpcunpack_int(), misspack(), mkieee(), pngpack_int(), pngunpack_int(), rdieee(), simpack(), simunpack(), and specunpack().


jpcpack()

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

This function packs up a float array into a JPEG2000 code stream ๐Ÿ”ฅ. Here's the glow-up: 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. Yes, your numbers are literally getting the image treatment. main character behavior fr fr.

This function also fills in GRIB2 Data Representation Template 5.40 or 5.40000 with the appropriate values ๐Ÿ’–.

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 by jpcpack routine.
    • 1 Binary Scale Factor - used on input, unchanged by jpcpack routine.
    • 2 Decimal Scale Factor - used on input, unchanged by jpcpack routine.
    • 3 number of bits for each data value - ignored on input
    • 4 Original field type - currently ignored on input Data values assumed to be reals. Set to 0 on output.
    • 5 if 0 use lossless compression, if 1 use lossy compression.
    • 6 Desired compression ratio, if idrstmpl[5]=1. Set to 255, if idrstmpl[5]=0. 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 the lcpack parameter.
  • lcpack โ€” Pointer that gets the length of packed field in cpack. This must be set by the calling function to the size available in cpack.

Author โ€” Stephen Gilbert, Ed Hartnett

Definition at line 269 of file jpcpack.c.

References jpcpack_int().

Referenced by g2_addfield().


jpcunpack()

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

Unpack JPEG2000 compressed data into an array of floats, using info from the GRIB2 Data Representation Template 5.40 or 5.40000 ๐Ÿ’œ. The reverse glow-up, we love a round trip.

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 of float.

Returns

  • G2C_NOERROR โ€” No error. โœจ
  • G2_JPCUNPACK_MEM โ€” Out of memory. ๐Ÿ’€

Author โ€” Stephem Gilbert

Date โ€” 2003-08-27

Definition at line 123 of file jpcunpack.c.

References G2_JPCUNPACK_MEM, jpcunpack_int(), and LOG.

Referenced by g2c_unpack7_int().

misspack() ๐Ÿ’–

void misspack (float * fld, g2int ndpts, g2int idrsnum, g2int * idrstmpl,
    unsigned char * cpack, g2int * lcpack)

okay bestie so this one packs up a whole data field using a complex packing algorithm. no cap, it's giving โœจefficiencyโœจ. It's the plug for GRIB2 complex packing templates, with or without spatial differences โ€” think Template 5.2 and Template 5.3, iykyk.

Also? It fills in those GRIB2 Data Representation template arrays with the right values, so you don't have to. main character behaviour fr fr.

Parameters ๐ŸŽ€

  • fld โ€” the data values you wanna pack, all cozy in here.
  • ndpts โ€” how many data values are chilling in fld.
  • idrsnum โ€” the Data Representation Template number. Must equal 2 or 3, periodt.
  • idrstmpl โ€” the array of values for Data Representation Template 5.2 or 5.3. Let's break it down:
    • 0 โ€” Reference value. Ignored on input, because misspack sets it itself. ๐Ÿ’…
    • 1 โ€” Binary Scale Factor โ€” used on input.
    • 2 โ€” Decimal Scale Factor โ€” used on input.
    • 6 โ€” Missing value management.
    • 7 โ€” Primary missing value.
    • 8 โ€” Secondary missing value.
    • 16 โ€” Order of Spatial Differencing (1 or 2).
  • cpack โ€” the packed data field (a character*1 array).
  • lcpack โ€” length of packed field cpack.

Author: Stephen Gilbert ๐Ÿซถ

Date: 2000-06-21

Definition at line 43 of file misspack.c.

References: ALOG2, int_power(), mkieee(), pack_gp(), rdieee(), sbit(), and sbits().

Referenced by: cmplxpack().


mkieee() ๐Ÿฆ‹

void mkieee (float * a, g2int * rieee, g2int num)

This one's whole job is to store a list of real values in 32-bit IEEE floating point format. It's giving float-to-bits glow-up โœจ.

Parameters ๐ŸŒธ

  • a โ€” input array of floating point values.
  • num โ€” number of floating point values to convert.
  • rieee โ€” output array of data values in 32-bit IEEE format, stored in a g2int integer array.
โš ๏ธ bestie listen up: rieee must be allocated with at least 4*num bytes of memory before you call this function. No allocating on the fly, okay? The function is not gonna do it for you ๐Ÿ˜ญ.

Author: Stephen Gilbert ๐Ÿ’œ

Date: 2002-10-29

Definition at line 22 of file mkieee.c.

References: int_power().

Referenced by: aecpack_int(), compack(), g2_addfield(), jpcpack_int(), misspack(), pngpack_int(), simpack(), and specpack().


pack_gp() ๐Ÿ”ฅ

int pack_gp (g2int * kfildo, g2int * ic, g2int * nxy, g2int * is523, g2int *
    minpk, g2int * inc, g2int * missp, g2int * misss, g2int * jmin, g2int *
    jmax, g2int * lbit, g2int * nov, g2int * ndg, g2int * lx, g2int * ibit,
    g2int * jbit, g2int * kbit, g2int * novref, g2int * lbitref, g2int *
    ier)

okay this is THE one. sit down, hydrate, because pack_gp is doing a lot and it ate ๐Ÿ’….

So what it does: it determines groups of variable size โ€” but at least of size minpk โ€” plus the associated max (jmax( )) and min (jmin( )), the number of bits necessary to hold the values in each group (lbit( )), the number of values in each group (nov( )), the number of bits necessary to pack the jmin( ) values (ibit), the number of bits necessary to pack the lbit( ) values (jbit), and the number of bits necessary to pack the nov( ) values (kbit). Whew. ๐Ÿ˜ฎโ€๐Ÿ’จ

It's designed to figure out those groups such that a small number of bits is necessary to pack the data, without doing excessive computations. Iconic tradeoff behaviour.

Some lore you need to know:

  • If all values in a group are zero, the number of bits to use in packing is defined as zero when there can be no missing values. But when there can be missing values, the number of bits must be at least 1, so the unpacker has the capability to recognize the missing value.
  • However, if all values in a group are missing, the number of bits needed is 0, and the unpacker recognizes this.
  • All variables are g2int.
  • Even though the groups are initially of size minpk or larger, an adjustment between two groups (the lookback procedure) may make a group smaller than minpk. The control on group size is that the sum of the sizes of the two consecutive groups, each of size minpk or larger, is not decreased.
  • When determining the number of bits necessary for packing, the largest value that can be accommodated in, say, mbits, is 2**mbits-1. That largest value (and the next smallest value) is reserved for the missing value indicator (only) when is523 ne 0.
  • If the dimension ndg is not large enough to hold all the groups, the local value of minpk gets bumped up by 50 percent. This repeats until ndg will suffice. A diagnostic is printed whenever this happens โ€” which should be very rarely. If it happens often, ndg in subroutine pack should be increased, and a corresponding increase in subroutine unpack made.
  • Considerable code is provided so that no more checking for missing values within loops is done than necessary. The added efficiency of this is relatively minor, but does no harm. ๐Ÿซถ
  • For grib2, the reference value for the length of groups in nov( ) and for the number of bits necessary to pack group values are determined, and subtracted before jbit and kbit are determined.

And when 1 or more groups are large compared to the others, the width of all groups must be as large as the largest. A subroutine reduce breaks up large groups into 2 or more to reduce the total bits required. If reduce should abort, pack_gp will be executed again without the call to reduce. Adaptive queen ๐Ÿ’….

PROGRAM HISTORY LOG ๐Ÿ“œ

  • February 1994 โ€” Glahn, tdl mos-2000
  • June 1995 โ€” Glahn, modified for lmiss error.
  • July 1996 โ€” Glahn, added misss
  • February 1997 โ€” Glahn, removed 4 redundant tests for missp.eq.0; inserted a test to better handle a string of 9999's
  • February 1997 โ€” Glahn, added loops to eliminate test for misss when misss = 0
  • March 1997 โ€” Glahn, corrected for secondary missing value
  • March 1997 โ€” Glahn, corrected for use of local value of minpk
  • March 1997 โ€” Glahn, corrected for secondary missing value
  • March 1997 โ€” Glahn, changed calculating number of bits through exponents to an array (improved overall packing performance by about 35 percent!). Allowed 0 bits for packing jmin( ), lbit( ), and nov( ).
  • May 1997 โ€” Glahn, a number of changes for efficiency. mod functions eliminated and one ifthen added. jount removed. recomputation of bits not made unless necessary after moving points from one group to another. nendb adjusted to eliminate possibility of very small group at the end. about 8 percent improvement in overall packing. iskipa removed; there is always a group b that can become group a. control on size of group b (statement below 150) added. added adda, and use of ge and le instead of gt and lt in loops between 150 and 160. ibitbs added to shorten trips through loop.
  • March 2000 โ€” Glahn, modified for grib2; changed name from packgp
  • january 2001 โ€” Glahn, comments; ier = 706 substituted for stops; added return1; removed statement number 110; added ier and * return
  • November 2001 โ€” Glahn, changed some diagnostic formats to allow printing larger numbers
  • November 2001 โ€” Glahn, added misslx( ) to put maximum value into jmin( ) when all values missing, to agree with grib standard.
  • November 2001 โ€” Glahn, changed two tests on missp and misss eq 0 to tests on is523. however, missp and misss cannot in general be = 0.
  • November 2001 โ€” Glahn, added call to reduce; defined itest before loops to reduce computation; started large group when all same value
  • December 2001 โ€” Glahn, modified and added a few comments
  • January 2002 โ€” Glahn, removed loop before 150 to determine a group of all same value
  • January 2002 โ€” Glahn, changed mallow from 9999999 to 2**30+1, and made it a parameter
  • March 2002 โ€” Glahn, added non fatal ier = 716, 717; removed nendb=nxy above 150; added iersav=0; comments

DATA SET USE ๐Ÿ’พ

  • kfildo โ€” unit number for output (print) file. (output)

Parameters ๐Ÿงš

  • kfildo โ€” unit number for output (print) file. (input)
  • ic โ€” array to hold data for packing. the values do not have to be positive at this point, but must be in the range -2**30 to +2**30 (the the value of mallow). these g2int values will be retained exactly through packing and unpacking. (input)
  • nxy โ€” number of values in ic( ). also treated as its dimension. (input)
  • is523 โ€” missing value management. 0=data contains no missing values, 1=data contains primary missing values, 2=data contains primary and secondary missing values. (input)
  • minpk โ€” the minimum size of each group, except possibly the last one. (input)
  • inc โ€” the number of values to add to an already existing group in determining whether or not to start a new group. ideally, this would be 1, but each time inc values are attempted, the max and min of the next minpk values must be found. this is "a loop within aloop," and a slightly larger value may give about as good results with slightly less computational time. if inc is le 0, 1 is used, and a diagnostic is output. note: it is expected that inc will equal 1. the code uses inc primarily in the loops starting at statement 180. if inc were 1, there would not need to be loops as such. however, kinc (the local value of inc) is set ge 1 when near the end of the data to forestall a very small group at the end. (input)
  • missp โ€” when missing points can be present in the data, they will have the value missp or misss. missp is the primary missing value and misss is the secondary missing value. these must not be values that would occur with subtracting the minimum (reference) value or scaling. for example, missp = 0 would not be advisable. (input)
  • misss โ€” secondary missing value indicator (see missp). (input)
  • jmin โ€” the minimum of each group (j=1,lx). (output)
  • jmax โ€” the maximum of each group (j=1,lx). this is not really needed, but since the max of each group must be found, saving it here is cheap in case the user wants it. (output)
  • lbit โ€” the number of bits necessary to pack each group (j=1,lx). it is assumed the minimum of each group will be removed before packing, and the values to pack will, therefore, all be positive. however, ic( ) does not necessarily contain all positive values. if the overall minimum has been removed (the usual case), then ic( ) will contain only positive values. (output)
  • nov โ€” the number of values in each group (j=1,lx). (output)
  • ndg โ€” the dimension of jmin, jmax, lbit, and nov. (input)
  • lx โ€” the number of groups determined. (output)
  • ibit โ€” the number of bits necessary to pack the jmin(j) values, j=1,lx. (output)
  • jbit โ€” the number of bits necessary to pack the lbit(j) values, j=1,lx. (output)
  • kbit โ€” the number of bits necessary to pack the nov(j) values, j=1,lx. (output)
  • novref โ€” reference value for nov( ). (output)
  • lbitref โ€” reference value for lbit( ). (output)
  • ier โ€” Error code:
    • 0 โ€” No error. ๐ŸŽ‰
    • 706 โ€” value will not pack in 30 bits โ€” fatal
    • 714 โ€” error in reduce โ€” non-fatal
    • 715 โ€” ngp not large enough in reduce โ€” non-fatal
    • 716 โ€” minpk inceased โ€” non-fatal
    • 717 โ€” inc set
    • 1 โ€” non-fatal
    • alternate return when ier ne 0 and fatal error.

Returns ๐ŸŽ

0 โ€” check ier for error code.

INTERNAL VARIABLES ๐Ÿ“

โ€ฆand here's the rest of the pack_gp() locals, bestie โ€” they keep going and honestly? iconic stamina:

  • cfeed โ€” holds the character representation of a printer form feed.
  • ifeed โ€” holds the g2int value of a printer form feed.
  • kinc โ€” working copy of inc. may be modified. (yes, a working copy, we love a working copy)
  • mina โ€” minimum value in group a.
  • maxa โ€” maximum value in group a.
  • nenda โ€” the place in ic( ) where group a ends.
  • kstart โ€” the place in ic( ) where group a starts.
  • ibita โ€” number of bits needed to hold values in group a.
  • minb โ€” minimum value in group b.
  • maxb โ€” maximum value in group b.
  • nendb โ€” the place in ic( ) where group b ends.
  • ibitb โ€” number of bits needed to hold values in group b.
  • minc โ€” minimum value in group c.
  • maxc โ€” maximum value in group c.
  • ktotal โ€” count of number of values in ic( ) processed.
  • nount โ€” number of values added to group a.
  • lmiss โ€” 0 when is523 = 0. when packing into a specific number of bits, say mbits, the maximum value that can be handled is 2**mbits-1. when is523 = 1, indicating primary missing values, this maximum value is reserved to hold the primary missing value indicator and lmiss = 1. when is523 = 2, the value just below the maximum i.e., 2**mbits-2 is reserved to hold the secondary missing value indicator and lmiss = 2.
  • lminpk โ€” local value of minpk. this will be adjusted upward whenever ndg is not large enough to hold all the groups.
  • mallow โ€” the largest allowable value for packing.
  • mislla โ€” set to 1 when all values in group a are missing. this is used to distinguish between a real minimum when all values are not missing and a minimum that has been set to zero when all values are missing. 0 otherwise. note that this does not distinguish between primary and secondary missings when secondary missings are present. this means that lbit( ) will not be zero with the resulting compression efficiency when secondary missings are present. also note that a check has been made earlier to determine that secondary missings are really there.
  • misllb โ€” set to 1 when all values in group b are missing. this is used to distinguish between a real minimum when all values are not missing and a minimum that has been set to zero when all values are missing. 0 otherwise.
  • misllc โ€” performs the same function for group c that mislla and misllb do for groups b and c, respectively.
  • ibxx2(j) โ€” an array that when this routine is first entered is set to 2**j, j=0,30. ibxx2(30) = 2**30, which is the largest value packable, because 2**31 is larger than the g2int word size.
  • ifirst โ€” set by data statement to 0. changed to 1 on first entry when ibxx2( ) is filled.
  • minak โ€” keeps track of the location in ic( ) where the minimum value in group a is located.
  • maxak โ€” does the same as minak, except for the maximum.
  • minbk โ€” the same as minak for group b.
  • maxbk โ€” the same as maxak for group b.
  • minck โ€” the same as minak for group c.
  • maxck โ€” the same as maxak for group c.
  • adda โ€” keeps track whether or not an attempt to add points to group a was made. if so, then adda keeps from trying to put one back into b. (g2int)
  • ibitbs โ€” keeps current value if ibitb so that loop ending at 166 doesn't have to start at ibitb = 0 every time.
  • misslx(j) โ€” mallow except when a group is all one value (and lbit(j) = 0) and that value is missing. in that case, misslx(j) is missp or misss. this gets inserted into jmin(j) later as the missing indicator; it can't be put in until the end, because jmin( ) is used to calculate the maximum number of bits (ibits) needed to pack jmin( ).

Definition at line 255 of file pack_gp.c.

References FALSE_, reduce(), and TRUE_.

Referenced by compack(), and misspack().


๐Ÿ’… pngpack

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

This subroutine packs up a float data field into PNG image format. After the data field is scaled, and the reference value is subtracted out, it is treated as a grayscale image and passed to a PNG encoder. It also fills in GRIB2 Data Representation Template 5.41 or 5.40010 with the appropriate values. glow up achieved โœจ

Parameters

  • fld โ€” Pointer to array of float that 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 Template 5.41 or 5.40010.
    • 0 Reference value - ignored on input, set by pngpack routine.
    • 1 Binary Scale Factor - used on input.
    • 2 Decimal Scale Factor - used on input.
    • 3 number of bits for each grayscale pixel value - ignored on input.
    • 4 Original field type - currently ignored on input, set = 0 on output. Data values assumed to be reals.
  • cpack โ€” The packed data field.
  • lcpack โ€” length of packed field cpack.

Author

Stephen Gilbert

Date

2003-08-27

Author

Ed Hartnett

Definition at line 254 of file pngpack.c.

References pngpack_int().

Referenced by g2_addfield().


๐Ÿฆ‹ pngunpack

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

This subroutine unpacks a data field that was packed into a PNG image format using info from the GRIB2 Data Representation Template 5.41 or 5.40010. the un-packing era, we love to see it ๐Ÿซถ

Parameters

  • cpack โ€” The packed data field (character*1 array).
  • len โ€” length of packed field cpack().
  • 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.
  • G2_JPCUNPACK_MEM Out of memory.

Author

Stephen Gilbert

Date

2003-08-27

Author

Ed Hartnett

Definition at line 126 of file pngunpack.c.

References G2_JPCUNPACK_MEM, G2C_ENOMEM, and pngunpack_int().

Referenced by g2c_unpack7_int().


๐ŸŒธ rdieee

void rdieee (g2int * rieee, float * a, g2int num)

Read a list of real values in 32-bit IEEE floating point format. numbers, but make them float ๐Ÿ’œ

Parameters

  • rieee โ€” g2int array of floating point values in 32-bit IEEE format.
  • num โ€” Number of floating point values to convert.
  • a โ€” float array of real values. a must be allocated with at least 4*num bytes of memory before calling this function.
bestie, do NOT forget the 4*num bytes. the allocation is on you. no cap. ๐Ÿ˜ญ

Author

Stephen Gilbert

Date

2002-10-25

Definition at line 20 of file rdieee.c.

References int_power().

Referenced by aecunpack_int(), comunpack(), g2_miss(), g2_unpack4(), g2c_unpack7_int(), jpcunpack_int(), misspack(), pngunpack_int(), simunpack(), and specunpack().


โœจ sbit

void sbit (unsigned char * out, g2int * in, g2int iskip, g2int nbits)

Store arbitrary size values into a packed bit string, taking the low order bits from each value in the unpacked array. bit-shuffling main character energy ๐ŸŽ€

Parameters

  • out โ€” Pointer to packed array output. Must be allocated large enough to hold output.
  • in โ€” Pointer that gets the unpacked array input.
  • iskip โ€” Initial number of bits to skip.
  • nbits โ€” Number of bits to pack.

Author

NOAA Programmer

Definition at line 38 of file gbits.c.

References sbits().

Referenced by compack(), g2_addfield(), g2_addgrid(), g2_addlocal(), g2_create(), g2_gribend(), misspack(), and simpack().


๐Ÿ’– sbits

void sbits (unsigned char * out, g2int * in, g2int iskip, g2int nbits,
    g2int nskip, g2int n)

Store arbitrary size values into a packed bit string, taking the low order bits from each value in the unpacked array. same vibe as sbit() but with extra knobs, okay?! ๐Ÿ”ฅ

Parameters

  • out โ€” Pointer to packed array output. Must be allocated large enough to hold output.
  • in โ€” Pointer that gets the unpacked array input.
  • iskip โ€” Initial number of bits to skip.
  • nbits โ€” Number of bits to pack.
  • nskip โ€” Additional number of bits to skip on each iteration.
  • n โ€” Number of iterations.

Author

NOAA Programmer

Definition at line 178 of file gbits.c.

Referenced by aecpack_int(), compack(), g2_addfield(), g2_addgrid(), jpcpack_int(), misspack(), pngpack_int(), sbit(), and simpack().


๐ŸŒˆ simpack

void simpack (float * fld, g2int ndpts, g2int * idrstmpl,
    unsigned char * cpack, g2int * lcpack)

Packs a data field using the simple packing algorithm. This function also fills in GRIB2 Data Representation Template 5.0 with the appropriate values. classic. simple. slays. ๐Ÿ’…

Parameters

  • fld โ€” Contains the data values to pack.
  • ndpts โ€” The number of data values in array fld.
  • idrstmpl โ€” Contains the array of values for Data Representation Template 5.0.
    • 0 Reference value - ignored on input - set by simpack routine.
    • 1 Binary Scale Factor - unchanged from input.
    • 2 Decimal Scale Factor - unchanged from input.
    • 3 Number of bits used to pack data, if value is > 0 and <= 31. If this input value is 0 or outside above range then the num of bits is calculated based on given data and scale factors.
    • 4 Original field type - currently ignored on input. Data values assumed to be reals. Set to 0 by simpack routine.
  • cpack โ€” the packed data field itself, the actual bytes โœจ
  • lcpack โ€” how long the packed field is, counting from where cpack starts ๐Ÿ“

Author ๐Ÿ’œ

Stephen Gilbert

Date ๐ŸŒธ

2002-11-06

Definition ๐Ÿ“

at line 36 of file simpack.c.

References ๐Ÿ”Ž

ALOG2, int_power(), LOG, mkieee(), sbit(), and sbits().

Referenced by ๐Ÿซถ

g2_addfield(), and specpack().


๐ŸŒˆ g2int simunpack (unsigned char * cpack, g2int * idrstmpl, g2int ndpts, float * fld)

okay bestie, this one unpacks a data field that was packed with the simple packing algorithm, using the info from the GRIB2 Data Representation Template 5.0. it's giving un-simpack energy, no cap ๐Ÿ’…

Parameters ๐ŸŽ€

  • cpack โ€” pointer to the packed data field.
  • idrstmpl โ€” pointer to the array of values for Data Representation Template 5.0.
  • ndpts โ€” the number of data values to unpack.
  • fld โ€” a pointer that gets the unpacked data values. and listen, fld must be allocated with at least ndpts * sizeof(float) bytes before you call this routine. do not skip this. i'm serious. ๐Ÿ˜ญ

Returns โญ

0 for success, error code otherwise.

Author ๐Ÿ’œ

Stephen Gilbert

Date ๐ŸŒธ

2002-10-29

Definition ๐Ÿ“

at line 28 of file simunpack.c.

References ๐Ÿ”Ž

G2_JPCUNPACK_MEM, G2_NO_ERROR, gbits(), int_power(), LOG, and rdieee().

Referenced by ๐Ÿซถ

g2c_unpack7_int().


๐Ÿฆ‹ void specpack (float * fld, g2int ndpts, g2int JJ, g2int KK, g2int MM, g2int * idrstmpl, unsigned char * cpack, g2int * lcpack)

this one packs a spectral data field using the complex packing algorithm for spherical harmonic data, exactly as defined in the GRIB2 Data Representation Template 5.51. spherical harmonics, we love her ๐Ÿงš

Parameters ๐ŸŽ€

  • fld โ€” contains the data values to be packed.
  • ndpts โ€” the number of data values to pack.
  • JJ โ€” J โ€” pentagonal resolution parameter.
  • KK โ€” K โ€” pentagonal resolution parameter.
  • MM โ€” M โ€” pentagonal resolution parameter.
  • idrstmpl โ€” contains the array of 10 values for Data Representation Template 5.51 (https://www.nco.ncep.noaa.gov/pmb/docs/grib2/grib2_doc/grib2_temp5-51.shtml).
  • cpack โ€” pointer that gets the packed data field. must be allocated by the caller, bestie, it does not do it for you ๐Ÿ™ˆ
  • lcpack โ€” length of packed field cpack.

Author ๐Ÿ’œ

Stephen Gilbert

Date ๐ŸŒธ

2002-12-19

Definition ๐Ÿ“

at line 33 of file specpack.c.

References ๐Ÿ”Ž

mkieee(), and simpack().

Referenced by ๐Ÿซถ

g2_addfield().


๐ŸŒŸ g2int specunpack (unsigned char * cpack, g2int * idrstmpl, g2int ndpts, g2int JJ, g2int KK, g2int MM, float * fld)

the unpacking twin of the one above ๐Ÿ’– this unpacks a spectral data field that was packed using the complex packing algorithm for spherical harmonic data as defined in the GRIB2 documention, using info from the GRIB2 Data Representation Template 5.51. yes we said "documention". we're keeping it. iconic typo behavior, we don't fix, we preserve ๐Ÿ˜Œ

Parameters ๐ŸŽ€

  • cpack โ€” pointer to the packed data field.
  • idrstmpl โ€” pointer to the array of values for Data Representation Template 5.51.
  • ndpts โ€” the number of data values to unpack (real and imaginary parts).
  • JJ โ€” pentagonal resolution parameter.
  • KK โ€” pentagonal resolution parameter.
  • MM โ€” pentagonal resolution parameter.
  • fld โ€” contains the unpacked data values. fld must be allocated with at least ndpts * sizeof(float) bytes before calling this routine. again. allocate. it. ๐Ÿ’€

Returns โญ

0 for success, -3 for wrong type.

Author ๐Ÿ’œ

Stephen Gilbert

Date ๐ŸŒธ

2000-06-21

Definition ๐Ÿ“

at line 35 of file specunpack.c.

References ๐Ÿ”Ž

G2_NO_ERROR, G2_SPECUNPACK_TYPE, gbits(), int_power(), and rdieee().

Referenced by ๐Ÿซถ

g2c_unpack7_int().


๐Ÿ‘‘ Author ๐Ÿ‘‘

generated automatically by Doxygen for NCEPLIBS-g2c from the source code. no human hand-wrote this one and honestly you can tell, but we love her anyway ๐Ÿซถโœจ


and that's a wrap on grib2_int.h(3) bestie!! ๐ŸŽ‰ the whole thing came out of NCEPLIBS-g2c, Version 2.3.0 โ€” that's the version, that's the source โ€” and this page is dated grib2_int.h(3) like a lil name tag ๐ŸŽ€ go forth and pack your fields, allocate your fld buffers, and slay ๐Ÿ’…๐ŸŒŸ

๐Ÿ“ฆ where this page comes from