grib2_int.h(3)
๐ 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 afloatarray 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 Template5.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 Template5.2or Template5.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 signedintto 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 signedlong longto 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 signedshortto 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-byteintorunsigned intfrom 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-byteunsigned intto 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-endianunsigned long longto 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-endianunsigned shortto 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 unpackedioutarray โจ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 unpackedioutarray ๐ซถ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 theJ,K, andMpentagonal resolution parameters specified in a GRIB Grid Definition Section (GDS) used for spherical harmonic coefficients using GDT5.50through5.53๐ฎdouble int_power (double x, g2int y)โ a function similar to C'spow()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 afloatarray 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 Template5.40or5.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 sizeminpk; 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 thejmin( )values (ibit); the number of bits necessary to pack thelbit( )values (jbit); and the number of bits necessary to pack thenov( )values (kbit) ๐งvoid pngpack (float *fld, g2int width, g2int height, g2int *idrstmpl, unsigned char *cpack, g2int *lcpack)โ this subroutine packs up afloatdata 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 Template5.41or5.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 * entrystruct g2c_code_table * nextchar 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 * nextchar 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_numunsigned 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_Tfor 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_Tobject. Ignored ifNULL.
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 โ
FILEpointer to the open GRIB2 file. - msg โ pointer to the
G2C_MESSAGE_INFO_Tstruct. - 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
aecpackroutine. - 1 Binary Scale Factor โ used on input, unchanged by the
aecpackroutine. - 2 Decimal Scale Factor โ used on input, unchanged by the
aecpackroutine. - 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.
- 0 Reference value โ ignored on input, set by the
โฆ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_NOERRORNo 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 arrayfld.idrsnumโ Data Representation Template number. Must equal2or3.idrstmplโ contains the array of values for Data Representation Template5.2or5.3.0Reference value โ ignored on input, set by compack routine.1Binary Scale Factor2Decimal Scale Factor6Missing value management7Primary missing value8Secondary missing value16Order of Spatial Differencing (1or2)
cpackโ the packed data field.lcpackโ length of packed fieldcpack. Will be set to-1if missing value management field is not1or2.
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 arrayfld.idrsnumโ Data Representation Template number. Must equal2or3.idrstmplโ contains the array of values for Data Representation Template5.2or5.3.0Reference value โ ignored on input, set mycompack().1Binary Scale Factor2Decimal Scale Factor6Missing value management7Primary missing value8Secondary missing value16Order of Spatial Differencing (1or2)
cpackโ the packed data field.lcpackโ length of packed fieldcpack.
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 equal2or3.idrstmplโ pointer to the array of values for Data Representation Template5.2or5.3ndptsโ the number of data values to unpackfldโ contains the unpacked data values. Must be allocated with at leastndpts * 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
>0Length of data from AEC decoder0Successful decode (AEC_OK)-1AEC_CONF_ERROR-2AEC_STREAM_ERROR-3AEC_DATA_ERROR-4AEC_MEM_ERROR-5AEC_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 tog2intarray, already allocated, that gets the unpacked data.
Returns
0Successful decodeG2_JASPER_DECODEError decode jpeg2000 code stream.G2_JASPER_DECODE_COLORdecoded image had multiple color components. Only grayscale is expected.G2_JASPER_INITError 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
>0Exact length of AEC encoded data.0Successful decode (AEC_OK)-1AEC_CONF_ERROR-2AEC_STREAM_ERROR-3AEC_DATA_ERROR-4AEC_MEM_ERROR-5AEC_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 whenltype == 1.retryโ If1try increasing number of guard bits.outjpcโ output encoded JPEG2000 code stream.jpclenโ number of bytes allocated for the output JPEG2000 code stream inoutjpc.
Returns
> 0= Length in bytes of encoded JPEG2000 code streamG2_JASPER_INITError initializing jasper library.G2_JASPER_ENCODEError 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 pointerextin thegtemplatestruct 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 theextfield of thegtemplatestruct. 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= Fromg2_addlocal()2= Fromg2_addgrid()3= Fromg2_addfield()4= Fromg2_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 openFILE.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 GRIB2FILE.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 GRIB2FILE.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 GRIB2FILE.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 GRIB2FILE.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 openFILE.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 GRIB2FILE.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 GRIB2FILE.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 GRIB2FILE.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 GRIB2FILE.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 byipdtn.yearโ yearmonthโ monthdayโ dayhourโ hourminuteโ minutesecondโ secondtabbrevโ 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:
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 byipdtn.level_descโ Character array which gets the string describing the level. Must be of length 40.
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 toG2C_MESSAGE_INFO_Twhich 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_WRITEif function should write,G2C_FILE_READif it should read.msgโ Pointer toG2C_MESSAGE_INFO_Twhich 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โFILEpointer to open GRIB2 file.rw_flagโG2C_FILE_WRITEif function should write,G2C_FILE_READ(0) if it should read.secโ Pointer to theG2C_SECTION_INFO_Tstruct.
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โFILEpointer to open GRIB2 file.rw_flagโG2C_FILE_WRITEif function should write,G2C_FILE_READif it should read.secโ Pointer to theG2C_SECTION_INFO_Tstruct.
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โFILEpointer to open GRIB2 file.rw_flagโG2C_FILE_WRITEif function should write,G2C_FILE_READif it should read.secโ Pointer to theG2C_SECTION_INFO_Tstruct.
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_WRITEif the function should write,G2C_FILE_READif it should read.secโ Pointer to theG2C_SECTION_INFO_Tstruct.
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
jpcpackroutine. - 1 Binary Scale Factor - used on input, unchanged by
jpcpackroutine. - 2 Decimal Scale Factor - used on input, unchanged by
jpcpackroutine. - 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, ifidrstmpl[5]=0. May be modified in this function.
- 0 Reference value - ignored on input, set by
cpackโ A pointer that will get the packed data field. Must be allocated before this function is called. Pass the allocated size in thelcpackparameter.lcpackโ Pointer that gets the length of packed field incpack. This must be set by the calling function to the size available incpack.
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 infld.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
misspacksets 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).
- 0 โ Reference value. Ignored on input, because
cpackโ the packed data field (acharacter*1array).lcpackโ length of packed fieldcpack.
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 ag2intinteger array.
โ ๏ธ bestie listen up:rieeemust be allocated with at least4*numbytes 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
minpkor larger, an adjustment between two groups (the lookback procedure) may make a group smaller thanminpk. The control on group size is that the sum of the sizes of the two consecutive groups, each of sizeminpkor larger, is not decreased. - When determining the number of bits necessary for packing, the largest value that can be accommodated in, say,
mbits, is2**mbits-1. That largest value (and the next smallest value) is reserved for the missing value indicator (only) whenis523 ne 0. - If the dimension
ndgis not large enough to hold all the groups, the local value ofminpkgets bumped up by 50 percent. This repeats untilndgwill suffice. A diagnostic is printed whenever this happens โ which should be very rarely. If it happens often,ndgin subroutinepackshould be increased, and a corresponding increase in subroutineunpackmade. - 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 beforejbitandkbitare 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
missswhenmisss = 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( ), andnov( ). - May 1997 โ Glahn, a number of changes for efficiency. mod functions eliminated and one ifthen added.
jountremoved. recomputation of bits not made unless necessary after moving points from one group to another.nendbadjusted to eliminate possibility of very small group at the end. about 8 percent improvement in overall packing.iskiparemoved; there is always a group b that can become group a. control on size of group b (statement below 150) added. addedadda, and use of ge and le instead of gt and lt in loops between 150 and 160.ibitbsadded to shorten trips through loop. - March 2000 โ Glahn, modified for grib2; changed name from
packgp - january 2001 โ Glahn, comments;
ier = 706substituted for stops; addedreturn1; removed statement number 110; addedierand*return - November 2001 โ Glahn, changed some diagnostic formats to allow printing larger numbers
- November 2001 โ Glahn, added
misslx( )to put maximum value intojmin( )when all values missing, to agree with grib standard. - November 2001 โ Glahn, changed two tests on
misspandmisss eq 0to tests onis523. however,misspandmissscannot in general be= 0. - November 2001 โ Glahn, added call to
reduce; defineditestbefore 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
mallowfrom9999999to2**30+1, and made it a parameter - March 2002 โ Glahn, added non fatal
ier = 716,717; removednendb=nxyabove 150; addediersav=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**30to+2**30(the the value ofmallow). theseg2intvalues will be retained exactly through packing and unpacking. (input)nxyโ number of values inic( ). 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 be1, but each timeincvalues are attempted, the max and min of the nextminpkvalues 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. ifincis le 0,1is used, and a diagnostic is output. note: it is expected thatincwill equal1. the code usesincprimarily in the loops starting at statement 180. ifincwere1, there would not need to be loops as such. however,kinc(the local value ofinc) 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 valuemisspormisss.misspis the primary missing value andmisssis the secondary missing value. these must not be values that would occur with subtracting the minimum (reference) value or scaling. for example,missp = 0would not be advisable. (input)misssโ secondary missing value indicator (seemissp). (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), thenic( )will contain only positive values. (output)novโ the number of values in each group (j=1,lx). (output)ndgโ the dimension ofjmin,jmax,lbit, andnov. (input)lxโ the number of groups determined. (output)ibitโ the number of bits necessary to pack thejmin(j)values, j=1,lx. (output)jbitโ the number of bits necessary to pack thelbit(j)values, j=1,lx. (output)kbitโ the number of bits necessary to pack thenov(j)values, j=1,lx. (output)novrefโ reference value fornov( ). (output)lbitrefโ reference value forlbit( ). (output)ierโ Error code:- 0 โ No error. ๐
- 706 โ value will not pack in 30 bits โ fatal
- 714 โ error in
reduceโ non-fatal - 715 โ
ngpnot large enough inreduceโ non-fatal - 716 โ
minpkinceased โ non-fatal - 717 โ
incset - 1 โ non-fatal
- alternate return when
ier ne 0and 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 theg2intvalue of a printer form feed.kincโ working copy ofinc. 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 inic( )where group a ends.kstartโ the place inic( )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 inic( )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 inic( )processed.nountโ number of values added to group a.lmissโ0whenis523 = 0. when packing into a specific number of bits, say mbits, the maximum value that can be handled is2**mbits-1. whenis523 = 1, indicating primary missing values, this maximum value is reserved to hold the primary missing value indicator andlmiss = 1. whenis523 = 2, the value just below the maximum i.e.,2**mbits-2is reserved to hold the secondary missing value indicator andlmiss = 2.lminpkโ local value ofminpk. this will be adjusted upward wheneverndgis not large enough to hold all the groups.mallowโ the largest allowable value for packing.misllaโ set to1when 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.0otherwise. note that this does not distinguish between primary and secondary missings when secondary missings are present. this means thatlbit( )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 to1when 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.0otherwise.misllcโ performs the same function for group c thatmisllaandmisllbdo for groups b and c, respectively.ibxx2(j)โ an array that when this routine is first entered is set to2**j,j=0,30.ibxx2(30) = 2**30, which is the largest value packable, because2**31is larger than theg2intword size.ifirstโ set by data statement to0. changed to1on first entry whenibxx2( )is filled.minakโ keeps track of the location inic( )where the minimum value in group a is located.maxakโ does the same asminak, except for the maximum.minbkโ the same asminakfor group b.maxbkโ the same asmaxakfor group b.minckโ the same asminakfor group c.maxckโ the same asmaxakfor group c.addaโ keeps track whether or not an attempt to add points to group a was made. if so, thenaddakeeps from trying to put one back into b. (g2int)ibitbsโ keeps current value ifibitbso that loop ending at 166 doesn't have to start atibitb = 0every time.misslx(j)โmallowexcept when a group is all one value (andlbit(j) = 0) and that value is missing. in that case,misslx(j)ismisspormisss. this gets inserted intojmin(j)later as the missing indicator; it can't be put in until the end, becausejmin( )is used to calculate the maximum number of bits (ibits) needed to packjmin( ).
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 offloatthat contains the data values to pack.widthโ Number of points in the x direction.heightโ Number of points in the y direction.idrstmplโ Contains the array of values for Data Representation Template5.41or5.40010.0Reference value - ignored on input, set bypngpackroutine.1Binary Scale Factor - used on input.2Decimal Scale Factor - used on input.3number of bits for each grayscale pixel value - ignored on input.4Original field type - currently ignored on input, set =0on output. Data values assumed to be reals.
cpackโ The packed data field.lcpackโ length of packed fieldcpack.
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*1array).lenโ length of packed fieldcpack().idrstmplโ Pointer to array of values for Data Representation Template5.41or5.40010.ndptsโ The number of data values to unpack.fldโ Contains the unpacked data values.
Returns
G2C_NOERRORNo error.G2_JPCUNPACK_MEMOut 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โg2intarray of floating point values in 32-bit IEEE format.numโ Number of floating point values to convert.aโfloatarray of real values.amust be allocated with at least4*numbytes 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 arrayfld.idrstmplโ Contains the array of values for Data Representation Template5.0.0Reference value - ignored on input - set bysimpackroutine.1Binary Scale Factor - unchanged from input.2Decimal Scale Factor - unchanged from input.3Number of bits used to pack data, if value is> 0and<= 31. If this input value is0or outside above range then the num of bits is calculated based on given data and scale factors.4Original field type - currently ignored on input. Data values assumed to be reals. Set to0bysimpackroutine.
cpackโ the packed data field itself, the actual bytes โจlcpackโ how long the packed field is, counting from wherecpackstarts ๐
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,fldmust be allocated with at leastndpts * 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 of10values 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 fieldcpack.
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.fldmust be allocated with at leastndpts * 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
- ubuntu resolute: libg2c-dev 2.3.0-4 ยท LGPL-3.0-only
- ubuntu stonking: libg2c-dev 2.3.0-7 ยท LGPL-3.0-only
- ๐ girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms