g2cindex.c(3)
π g2cindex.c β Library Functions Manual π
okay bestie, gather round, because we're about to get deep into g2cindex.c, and this one is lowkey a whole saga (it's giving "two-parter", so buckle up). It's a Library Functions Manual situation, and it's so much. Let's go. π¦
β¨ NAME β¨
g2cindex.c β write summary output to an index file, exactly like the utility grb2index does. no cap. π
πΈ SYNOPSIS πΈ
#include 'grib2_int.h'
#include <libgen.h>
#include <stdarg.h>
#include <time.h>
π Macros
#define G2C_INDEX_BASENAME_LEN 40β length of the basename in header record 2. π«Ά#define G2C_INDEX_BITMAP_BYTES 6β length of the bitmap section included in the index record.#define G2C_INDEX_DATE_STR_LEN 10β length of the date string in the index record. π#define G2C_INDEX_FIXED_LEN 44β length of the beginning of the index record.#define G2C_INDEX_FIXED_LEN_2 48β length of the beginning of the index record, but for the large files version. big girl energy. π#define G2C_INDEX_HEADER_LEN 81β length of the two header lines at the top of the index file.#define G2C_INDEX_STR1_LEN 7β length of thestr1string in the index record.#define G2C_INDEX_TIME_STR_LEN 8β length of the time string in the index record. β°
π Functions
EXTERN_MUTEX (m)β use an externally-defined mutex for thread-safety. (mutexes are the moment, fr fr π)int g2c_get_prod_sections (G2C_MESSAGE_INFO_T *msg, int fieldnum, G2C_SECTION_INFO_T **sec3, G2C_SECTION_INFO_T **sec4, G2C_SECTION_INFO_T **sec5, G2C_SECTION_INFO_T **sec6, G2C_SECTION_INFO_T **sec7)β hand it a pointer to a message plus a field number, and it hands you back pointers to all the relevant section structs for that product. β¨int g2c_open_index (const char *data_file, const char *index_file, int mode, int *g2cid)β open a GRIB2 file with the help of an index file.int g2c_open_index1 (const char *index_file)β open a GRIB1 index file and read the contents.int g2c_start_index1_record (FILE *f, int rw_flag, unsigned int *b2_msg, unsigned int *b2_pds, unsigned int *b2_gds, unsigned int *b2_bms, unsigned int *b2_bds, unsigned int *msglen, unsigned char *version, unsigned char *pds_val, unsigned char *gds_val, unsigned char *bms_val, unsigned char *bds_val, unsigned char *pds_val2, unsigned char *pds_val3, unsigned char *gds_val2)β read or write the start of a version 1 index record. πint g2c_start_index_record (FILE *f, int rw_flag, int *reclen, int *msg, int *local, int *gds, int *pds, int *drs, int *bms, int *data, size_t *msglen, unsigned char *version, unsigned char *discipline, short *fieldnum)β read or write the start of a version 2 index record.int g2c_start_index_record_lf (FILE *f, int rw_flag, int *reclen, size_t *msg, size_t *local, size_t *gds, size_t *pds, size_t *drs, size_t *bms, size_t *data, size_t *msglen, unsigned char *version, unsigned char *discipline, short *fieldnum)β read or write the start of a version 2 index record. (yes, again β this one's the "lf" twin π§)int g2c_write_index (int g2cid, int mode, const char *index_file)β create an index file from a GRIB2 file, just like the ones thegrb2indexutility makes. ate. πstatic int read_hdr_rec1 (FILE *f, int *ip, int *jp, int *kp, char *date_str, char *time_str)β read the header record that is apparently named after Steve Lord. π iconic origin story tbh.static int read_hdr_rec2 (FILE *f, int *skipp, int *total_lenp, int *num_recp, char *basename, int *index_version)β read the second header record of an index file.
π Variables
G2C_FILE_INFO_T g2c_file [G2C_MAX_FILES+1]β global file information. the whole vibe, stored globally. πΎ
π«Ά Detailed Description π«Ά
Write summary output to an index file, as is done by utility grb2index. that's the whole assignment bestie. β¨
Author
Ed Hartnett
Date
10/12/22
Definition in file g2cindex.c.
π Macro Definition Documentation π
#define G2C_INDEX_BASENAME_LEN 40
Length of the basename in header record 2.
Definition at line 20 of file g2cindex.c.
Referenced by g2c_open_index(), g2c_open_index1(), g2c_write_index(), and read_hdr_rec2().
#define G2C_INDEX_BITMAP_BYTES 6
Length of bitmap section included in the index record.
Definition at line 23 of file g2cindex.c.
Referenced by g2c_write_index().
#define G2C_INDEX_DATE_STR_LEN 10
Length of date string in index record.
Definition at line 32 of file g2cindex.c.
Referenced by g2c_open_index(), g2c_open_index1(), and read_hdr_rec1().
#define G2C_INDEX_FIXED_LEN 44
Length of beginning of index record.
Definition at line 26 of file g2cindex.c.
Referenced by g2c_write_index().
#define G2C_INDEX_FIXED_LEN_2 48
Length of beginning of index record for large files.
Definition at line 29 of file g2cindex.c.
Referenced by g2c_write_index().
#define G2C_INDEX_HEADER_LEN 81
Length of the two header lines at the top of the index file.
Definition at line 17 of file g2cindex.c.
Referenced by g2c_open_index(), g2c_open_index1(), g2c_write_index(), read_hdr_rec1(), and read_hdr_rec2().
#define G2C_INDEX_STR1_LEN 7
Length of str1 string in index record.
Definition at line 38 of file g2cindex.c.
Referenced by g2c_open_index(), and read_hdr_rec1().
#define G2C_INDEX_TIME_STR_LEN 8
Length of time string in index record.
Definition at line 35 of file g2cindex.c.
Referenced by g2c_open_index(), g2c_open_index1(), and read_hdr_rec1().
π Function Documentation π
π¦ EXTERN_MUTEX (m )
Use externally-defined mutex for thread-safety. periodt. π
πΈ int g2c_get_prod_sections (G2C_MESSAGE_INFO_T * msg, int fieldnum, G2C_SECTION_INFO_T ** sec3, G2C_SECTION_INFO_T ** sec4, G2C_SECTION_INFO_T ** sec5, G2C_SECTION_INFO_T ** sec6, G2C_SECTION_INFO_T ** sec7)
Given a pointer to a message, and a field number, return pointers to all relevant section structs for that product. Every product is defined in a section 4, and it has an associated section 3, 5, 6, and 7. it's giving "found family" but make it GRIB2 sections. π₯Ή
Parameters
msgβ pointer to aG2C_MESSAGE_INFO_Twith information about the message.fieldnumβ the field number (first field in message is0).sec3β pointer that gets a pointer to theG2C_SECTION_INFO_Tstruct for the section 3 associated with this product.sec4β pointer that gets a pointer to theG2C_SECTION_INFO_Tstruct for the section 4 associated with this product.sec5β pointer that gets a pointer to theG2C_SECTION_INFO_Tstruct for the section 5 associated with this product.sec6β pointer that gets a pointer to theG2C_SECTION_INFO_Tstruct for the section 6 associated with this product.NULLis returned if there is no section 6.sec7β pointer that gets a pointer to theG2C_SECTION_INFO_Tstruct for the section 7 associated with this product.
Note
This is an internal function and should not be called by users. bestie do NOT touch. π ββοΈ
Returns
G2C_NOERRORβ no error.G2C_EINVALβ invalid input.G2C_ENOSECTIONβ section not found.
Author
Ed Hartnett
Date
10/27/22
Definition at line 317 of file g2cindex.c.
References G2C_EINVAL, G2C_ENOSECTION, G2C_NOERROR, g2c_section_info::next, g2c_section_info::prev, g2c_message_info::sec, g2c_section_info::sec_info, and g2c_section_info::sec_num.
Referenced by g2c_write_index().
π int g2c_open_index (const char * data_file, const char * index_file, int mode, int * g2cid)
Open a GRIB2 file with the help of an index file. The index file β generated by the grb2index utility, or by the g2c_write_index() function β contains the byte offsets for the sections of each message in the GRIB2 file. When a GRIB2 file is opened with an index file, the library does not have to scan the file to locate all metadata. it's giving shortcut, it's giving efficiency, it's giving main character. β‘
Parameters
data_fileβ the name of the data file to which the index applies.index_fileβ the name that will be given to the index file. An existing file will be overwritten. π±modeβ open mode flags.g2cidβ pointer that gets theg2cidfor this file. Ignored ifNULL.
Returns
G2C_NOERRORβ no error.
Author
Ed Hartnett
Date
10/12/22
Definition at line 914 of file g2cindex.c.
References add_msg(), add_section(), g2c_message_info::bytes_to_bms, g2c_message_info::bytes_to_data, g2c_message_info::bytes_to_local, g2c_message_info::bytes_to_msg, g2c_message_info::discipline, g2c_add_file(), G2C_EBADSECTION, G2C_EFILE, G2C_EINVAL, G2C_ENAMETOOLONG, g2c_file, g2c_file_io_ubyte(), g2c_file_io_uint(), G2C_FILE_READ, G2C_INDEX_BASENAME_LEN, G2C_INDEX_DATE_STR_LEN, G2C_INDEX_HEADER_LEN, G2C_INDEX_STR1_LEN, G2C_INDEX_TIME_STR_LEN, g2c_log_section1(), G2C_MAX_NAME, G2C_NOERROR, g2c_rw_section1_metadata(), g2c_start_index_record(), g2c_start_index_record_lf(), LOG, g2c_message_info::master_version, MUTEX_LOCK, and MUTEX_UNLOCK.
Referenced by main().
π int g2c_open_index1 (const char * index_file)
Open a GRIB1 index file and read the contents. This function opens the GRIB2 index file and reads its metadata, and opens the accompanying GRIB2 file. (yes it says GRIB1 in the name and then talks about GRIB2, we don't make the rules π)
GRIB2 messages in the file are assigned a message ID, starting with 0 for the first message in the file.
Each product within a message is assigned a product ID, starting with 0 for the first product in the message.
Files opened with this function should be closed with a call g2c_close() to release resources. don't leave them hanging bestie, that's rude. π«Ά
Parameters
index_fileβ the name that will be given to the index file. An existing file will be overwritten. π
Returns
G2C_NOERRORβ no error.
Author
Ed Hartnett
Date
10/12/22
Definition at line 812 of file g2cindex.c.
References G2C_EFILE, G2C_EINVAL, G2C_FILE_READ, G2C_INDEX1_BDS_VAL_LEN, G2C_INDEX1_BMS_VAL_LEN, G2C_INDEX1_GDS_VAL_LEN, G2C_INDEX1_PDS_VAL_LEN, G2C_INDEX_BASENAME_LEN, G2C_INDEX_DATE_STR_LEN, G2C_INDEX_HEADER_LEN, G2C_INDEX_TIME_STR_LEN, G2C_NOERROR, g2c_start_index1_record(), LOG, MUTEX_LOCK, MUTEX_UNLOCK, read_hdr_rec1(), and read_hdr_rec2().
π
int g2c_start_index1_record (FILE * f, int rw_flag, unsigned int * b2_msg, unsigned int * b2_pds, unsigned int * b2_gds, unsigned int * b2_bms, unsigned int * b2_bds, unsigned int * msglen, unsigned char * version, unsigned char * pds_val, unsigned char * gds_val, unsigned char * bms_val, unsigned char * bds_val, unsigned char * pds_val2, unsigned char * pds_val3, unsigned char * gds_val2)
Read or write the start of a version 1 index record. For more detail on version 1 of the index format, see the grbindex documentation in the NCEPLIBS-grib_util. π
β¨ okay bestie, that's the end of part 1 β¨ β there's more coming, so don't go anywhere. π
okay so the params for this one are literally the blueprint, bestie β read them like your life depends on it (it doesn't, but still):
fβFILE *to open index file.rw_flagβTrueif function should write,falseif it should read.b2_msgβ Pointer that gets the bytes to skip in file beforemsg.b2_pdsβ Pointer that gets bytes to skip in message beforepds.b2_gdsβ Pointer that gets bytes to skip in message beforegds(0if nogds).b2_bmsβ Pointer that gets bytes to skip in message beforebms(0if nobms).b2_bdsβ Pointer that gets bytes to skip in message beforebds.msglenβ Pointer that gets bytes total in the message.versionβ Pointer that gets grib version number (always1for this function).pds_valβ Pointer that gets an array of27bytes of the product definition section (pds).gds_valβ Pointer that gets an array of41bytes of thegds.bms_valβ Pointer that gets an array of5bytes of thebms.bds_valβ Pointer that gets an array of10bytes, bytes41-100of thebds.pds_val2β Pointer that gets an array of59bytes41-100of thepds. Ignored if null.pds_val3β Pointer that gets an array of11bytes29-40of thepds. Ignored if null.gds_val2β Pointer that gets an array of135bytes43-178of thegds. Ignored if null.
Returns β the vibe check results, no cap:
G2C_NOERRORβ No error.G2C_EINVALβ Invalid input.G2C_EFILEβ File I/O error.
Author β Ed Hartnett 9/11/23
Definition at line 238 of file g2cindex.c.
References β G2C_EFILE, G2C_EINVAL, g2c_file_io_ubyte(), g2c_file_io_uint(), G2C_INDEX1_BDS_VAL_LEN, G2C_INDEX1_BMS_VAL_LEN, G2C_INDEX1_GDS_VAL_LEN, G2C_INDEX1_PDS_VAL_LEN, and G2C_NOERROR.
Referenced by g2c_open_index1().
π¦ g2c_start_index_record π¦
int g2c_start_index_record (FILE * f, int rw_flag, int * reclen, int * msg,
int * local, int * gds, int * pds, int * drs, int * bms, int * data,
size_t * msglen, unsigned char * version, unsigned char * discipline,
short * fieldnum)
Read or write the start of a version 2 index record. It's giving "index record opening ceremony" and honestly? Slay.
Parameters
fβFILE *to open index file.rw_flagβTrueif function should write,falseif it should read.reclenβ Pointer toreclen.msgβ Pointer tomsg.localβ Pointer tolocal.gdsβ Pointer togds.pdsβ Pointer topds.drsβ Pointer todrs.bmsβ Pointer tobms.dataβ Pointer todata.msglenβ Pointer tomsglen.versionβ Pointer toversion.disciplineβ Pointer todiscipline.fieldnumβ Pointer tofieldnum,0- based. (It is1-based in the index file.)
Returns
G2C_NOERRORβ No error.G2C_EINVALβ Invalid input.G2C_EFILEβ File I/O error.
Author β Ed Hartnett 10/26/22
Definition at line 70 of file g2cindex.c.
References β G2C_EINVAL, g2c_file_io_short(), g2c_file_io_ubyte(), g2c_file_io_uint(), g2c_file_io_ulonglong(), G2C_NOERROR, and LOG.
Referenced by g2c_open_index(), and g2c_write_index().
π g2c_start_index_record_lf π
int g2c_start_index_record_lf (FILE * f, int rw_flag, int * reclen, size_t * msg, size_t * local, size_t * gds, size_t * pds, size_t * drs, size_t * bms, size_t * data, size_t * msglen, unsigned char * version, unsigned char * discipline, short * fieldnum)
Read or write the start of a version 2 index record. Same energy, but with size_t and large-file energy. Obsessed.
Parameters
fβFILEpointer to open index file.rw_flagβTrueif function should write,falseif it should read.reclenβ Pointer toreclen, the length of the index record in bytes.msgβ Pointer to bytes to skip in file to reachmsg.localβ Pointer to bytes to skip in message to reachlocal.gdsβ Pointer to bytes to skip in message to reachgds.pdsβ Pointer to bytes to skip in message to reachpds.drsβ Pointer to bytes to skip in message to reachdrs.bmsβ Pointer to bytes to skip in message to reachbms.dataβ Pointer to bytes to skip in message to reachdata.msglenβ Pointer tomsglen.versionβ Pointer toversion.disciplineβ Pointer todiscipline.fieldnumβ Pointer tofieldnum,0- based. (It is1-based in the index file.)
Returns
G2C_NOERRORβ No error.G2C_EINVALβ Invalid input.G2C_EFILEβ File I/O error.
Author β Ed Hartnett 10/26/22
Definition at line 151 of file g2cindex.c.
References β G2C_EINVAL, g2c_file_io_short(), g2c_file_io_ubyte(), g2c_file_io_uint(), g2c_file_io_ulonglong(), G2C_NOERROR, and LOG.
Referenced by g2c_open_index(), and g2c_write_index().
π g2c_write_index π
int g2c_write_index (int g2cid, int mode, const char * index_file)
Create an index file from a GRIB2 file, just like those created by the grb2index utility. The index file starts with two header records:
81-byteheader with'gb2ix1'in columns42-47.81-byteheader with number of bytes to skip before index records, total length in bytes of the index records, number of index records, and grib file basename written in format('ix1form:',3i10,2x,a40).
Each following index record corresponds to a grib message and has the internal format:
byte 001 - 004length of index recordbyte 005 - 008bytes to skip in data file before grib messagebyte 009 - 012bytes to skip in message before lus (local use) (0, if none).byte 013 - 016bytes to skip in message before gdsbyte 017 - 020bytes to skip in message before pdsbyte 021 - 024bytes to skip in message before drsbyte 025 - 028bytes to skip in message before bmsbyte 029 - 032bytes to skip in message before data sectionbyte 033 - 040bytes total in the messagebyte 041 - 041grib version number (currently2)byte 042 - 042message disciplinebyte 043 - 044field number within grib2 message (1-based)byte 045 - iiidentification section (ids)byte ii+1- jjgrid definition section (gds)byte jj+1- kkproduct definition section (pds)byte kk+1- llthe data representation section (drs)byte ll+1-ll+6first 6 bytes of the bit map section (bms)
Parameters
g2cidβ File it for an open GRIB2 file, as returned byg2c_open().modeβ Mode flags. SetG2C_NOCLOBBERto avoid overwriting and existing file.index_fileβ The name that will be given to the index file. An existing file will be overwritten.
Returns
G2C_NOERRORβ No error.
Author β Ed Hartnett
Date β 10/12/22
Definition at line 431 of file g2cindex.c.
References β g2c_message_info::bytes_in_msg, g2c_message_info::bytes_to_local, g2c_message_info::bytes_to_msg, g2c_section_info::bytes_to_sec, g2c_message_info::discipline, g2c_file_info::f, g2c_message_info::file, G2C_EBADID, G2C_EFILE, G2C_EINVAL, g2c_file, g2c_file_io_ubyte(), g2c_file_io_uint(), G2C_FILE_WRITE, g2c_get_prod_sections(), G2C_INDEX_BASENAME_LEN, G2C_INDEX_BITMAP_BYTES, G2C_INDEX_FIXED_LEN, G2C_INDEX_FIXED_LEN_2, G2C_INDEX_HEADER_LEN, G2C_LARGE_FILE_INDEX, G2C_MAX_FILES, G2C_NOCLOBBER, G2C_NOERROR, g2c_rw_section1_metadata(), g2c_rw_section3_metadata(), g2c_rw_section4_metadata(), g2c_rw_section5_metadata(), g2c_start_index_record(), g2c_start_index_record_lf(), LOG, g2c_message_info::master_version, MUTEX_LOCK, MUTEX_UNLOCK, g2c_message_info::next, g2c_message_info::num_fields, ONE_BYTE, g2c_message_info::sec1_len, and g2c_section_info::sec_len.
Referenced by main().
π read_hdr_rec1 π
int read_hdr_rec1 (FILE * f, int * ip, int * jp, int * kp, char * date_str, char * time_str) [static]
Read the header record apparently named after Steve Lord. This function reads the first of two 81-byte header records of an index file. The Steve Lord of it all. Iconic.
Parameters
fβ Pointer to openFILE.ipβ Pointer that getsivalue. Ignored ifNULL.jpβ Pointer that getsjvalue. Ignored ifNULL.kpβ Pointer that getskvalue. Ignored ifNULL.date_strβ Pointer to char array of sizeG2C_INDEX_DATE_STR_LEN + 1which will get the date string from the header. Ignored ifNULL.time_strβ Pointer to char array of sizeG2C_INDEX_TIME_STR_LEN + 1which will get the time string from the header. Ignored ifNULL.
Returns β 0 for success, error code otherwise.
Author β Edward Hartnett
Date β 9/10/23
Definition at line 684 of file g2cindex.c.
References β G2C_EFILE, G2C_INDEX_DATE_STR_LEN, G2C_INDEX_HEADER_LEN, G2C_INDEX_STR1_LEN, G2C_INDEX_TIME_STR_LEN, G2C_NOERROR, and LOG.
Referenced by g2c_open_index1().
π read_hdr_rec2 π
int read_hdr_rec2 (FILE * f, int * skipp, int * total_lenp, int * num_recp, char * basename, int * index_version) [static]
Read the second header record of an index file. This function reads the second of two 81-byte header records of an index file. The sequel that actually ate, periodt.
Parameters
fβ Pointer to openFILE.skippβ Pointer that gets number of bytes to skip before index records. Ignored ifNULL.total_lenpβ Pointer that gets number of bytes in each index record. Ignored ifNULL.num_recpβ Pointer that gets number of index records in the file. Ignored ifNULL.basenameβ Pointer to char array of sizeG2C_INDEX_BASENAME_LEN + 1which will get the basename string from the second header record. Ignored ifNULL.index_versionβ The version of the index,1for legacy,2to allow for> 2 GBGRIB2 files.
Returns β 0 for success, error code otherwise.
Author β Edward Hartnett
Date β 9/10/23
Definition at line 753 of file g2cindex.c.
References β G2C_EFILE, G2C_INDEX_BASENAME_LEN, G2C_INDEX_HEADER_LEN, and G2C_NOERROR.
Referenced by g2c_open_index1().
πΈ Variable Documentation πΈ
G2C_FILE_INFO_T g2c_file[G2C_MAX_FILES+1] [extern]
Global file information.
Definition at line 10 of file g2cfile.c.
π«Ά Author π«Ά
Generated automatically by Doxygen for NCEPLIBS-g2c from the source code.
and that's the whole page, bestie π
this was NCEPLIBS-g2c version 2.3.0, page g2cindex.c(3) β generated by Doxygen, no cap, and it ate fr fr πβ¨
π¦ 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