21 #include <arpa/inet.h>
30 #define ALOG2 (0.69314718)
33 #define G2C_JASPER_JPEG_FORMAT_NAME "jpc"
36 #define G2C_MIN_MAX_BYTES 16
39 #define G2C_MAGIC_HEADER "GRIB"
42 #define G2C_MAGIC_HEADER_LEN 8
45 #define G2C_MAX_MESSAGES 1024
56 #define LATITUDE "Latitude"
59 #define LONGITUDE "Longitude"
64 #define G2C_INDEX1_PDS_VAL_LEN 27
67 #define G2C_INDEX1_GDS_VAL_LEN 41
70 #define G2C_INDEX1_BMS_VAL_LEN 5
73 #define G2C_INDEX1_BDS_VAL_LEN 10
76 #define G2C_INDEX1_PDS_VAL2_LEN 27
79 #define G2C_INDEX1_PDS_VAL3_LEN 27
82 #define G2C_INDEX1_GDS_VAL2_LEN 27
88 #define MUTEX(m) pthread_mutex_t m = PTHREAD_MUTEX_INITIALIZER;
91 #define EXTERN_MUTEX(m) extern pthread_mutex_t m;
94 #define MUTEX_LOCK(m) \
96 pthread_mutex_lock(&m); \
100 #define MUTEX_UNLOCK(m) \
102 pthread_mutex_unlock(&m); \
111 #define EXTERN_MUTEX(m)
114 #define MUTEX_LOCK(m)
117 #define MUTEX_UNLOCK(m)
123 #define ntoh64(y) (((uint64_t)ntohl(y)) << WORD | ntohl(y >> WORD))
127 #define hton64(y) (((uint64_t)htonl(y)) << WORD | htonl(y >> WORD))
129 #define G2C_FILE_READ 0
130 #define G2C_FILE_WRITE 1
178 long long int *
template;
319 int g2c_get_datetime(
int ipdtn,
long long int *ipdtmpl,
short year,
unsigned char month,
unsigned char day,
320 unsigned char hour,
unsigned char minute,
unsigned char second,
char *tabbrev);
325 unsigned char *cpack,
g2int *lcpack);
329 unsigned char *cpack,
g2int *lcpack);
333 unsigned char *cpack,
g2int *lcpack);
335 unsigned char *cpack,
g2int *lcpack);
338 g2int *idrstmpl,
unsigned char *cpack,
g2int *lcpack);
344 unsigned char *pngbuf);
346 unsigned char *cout);
348 unsigned char *cpack,
g2int *lcpack);
356 unsigned char *cpack,
g2int *lcpack);
361 unsigned char *cpack,
g2int *lcpack);
388 int g2c_file_io(FILE *f,
int write,
int g2ctype,
void *var);
400 int g2c_add_file(
const char *path,
int mode,
int *g2cid);
418 void g2_log(
int severity,
const char *fmt, ...);
421 #define LOG(e) g2_log e
Header file for NCEPLIBS-g2c library.
#define G2C_MAX_GRIB_TITLE_LEN
Maximum length of code table title.
#define G2C_MAX_GRIB_DESC_LEN
Maximum length of code description.
#define G2C_MAX_NAME
Maximum length of a name.
#define G2C_MAX_GRIB_STATUS_LEN
Maximum length of code status.
#define G2C_MAX_GRIB_CODE_LEN
Maximum length of code.
#define G2C_SECTION1_ARRAY_LEN
Length of section 1 array.
int64_t g2int
Long integer type.
#define G2C_MAX_NOAA_ABBREV_LEN
Maximum length of a NOAA abbreviation of a parameter.
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 Representatio...
int bytes_to_local
Number of bytes in the message before the (first) local section.
struct g2c_section3_info G2C_SECTION3_INFO_T
Information about Section 3 GRID DEFINITION SECTION.
struct g2c_code_table G2C_CODE_TABLE_T
A GRIB2 code table.
void cmplxpack(float *fld, g2int ndpts, g2int idrsnum, g2int *idrstmpl, unsigned char *cpack, g2int *lcpack)
This subroutine packs up a data field using a complex packing algorithm as defined in the GRIB2 docum...
int enc_png(unsigned char *data, g2int width, g2int height, g2int nbits, unsigned char *pngbuf)
Encode PNG.
gtemplate * extgridtemplate(g2int number, g2int *list)
This subroutine generates the remaining octet map for a given Grid Definition Template,...
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 b...
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.
void mkieee(float *a, g2int *rieee, g2int num)
This subroutine stores a list of real values in 32-bit IEEE floating point format.
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-...
struct g2c_section_info * next
Pointer to next in list.
struct g2c_section_info * sec
List of section metadata.
int g1ver
GRIB1 table version.
void gbit(unsigned char *in, g2int *iout, g2int iskip, g2int nbits)
Get bits - unpack bits: Extract arbitrary size values from a packed bit string, right justifying each...
struct gtemplate gtemplate
Struct for GRIB template.
size_t len
Length of dimension.
short subcenter
Originating subcenter.
int sec_id
ID of the section (0-based).
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 GRIB...
unsigned char master_version
GRIB master tables version number.
struct g2c_file_info G2C_FILE_INFO_T
This is the information about each open file.
gtemplate * extdrstemplate(g2int number, g2int *list)
This subroutine generates the remaining octet map for a given Data Representation Template,...
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 betwee...
int g1num
GRIB1 parameter number.
g2int * ext
Number of octets of each entry in the extension part of the template.
void gbits(unsigned char *in, g2int *iout, g2int iskip, g2int nbits, g2int nskip, g2int n)
Get bits - unpack bits: Extract arbitrary size values from a packed bit string, right justifying each...
int g2c_check_msg(unsigned char *cgrib, g2int *lencurr, int verbose)
Check for 'GRIB' at the beginning of a GRIB message, and check to see if the message is already termi...
size_t * section_offset
Array (length num_sections) of byte offsets from start of message to section.
unsigned char type
Type of processed data in this GRIB message.
int * section_number
Array (length num_sections) of section numbers.
unsigned short grid_def
Grid definition template number (= N) (See Table 3.1).
int dec_png(unsigned char *pngbuf, g2int *width, g2int *height, unsigned char *cout)
Decode PNG.
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 Tem...
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 a...
int num_sections
Number of sections in the file.
unsigned char minute
Minute.
unsigned int num_data_points
Number of data points.
size_t num_messages
Number of messages in the file.
int g2c_log_section1(G2C_MESSAGE_INFO_T *msg)
Log section 0 information.
unsigned short num_coord
Number of coordinate values after template.
struct g2c_dim_info G2C_DIM_INFO_T
Keep information about dimensions defined in section 3.
int enc_aec(unsigned char *data, g2int ctemplen, g2int nbits, g2int flags, g2int block_size, g2int rsi, unsigned char *aecbuf, g2int *aecbuflen)
This Function encodes data into an AEC code stream specified in the CCSDS 121.0-B-3 Blue Book.
int num_local
Number of local sections in the message.
unsigned char sig_ref_time
Significance of reference time.
int bytes_to_data
Number of bytes in the message to the (first) data section.
struct g2c_section_info G2C_SECTION_INFO_T
Information about a section 3 through 7 in a GRIB2 message.
unsigned char num_opt
Number of octets for optional list of numbers defining number of points.
gtemplate * extpdstemplate(g2int number, g2int *list)
This subroutine generates the remaining octet map for a given Product Definition Template,...
int g2cat
GRIB2 category number.
int * optional
Optional list of numbers defining number of points.
unsigned char discipline
Discipline from section 0.
double int_power(double x, g2int y)
Function similar to C pow() power function.
struct g2c_param G2C_PARAM_T
An entry in the table of NOAA abbreviations for GRIB parameters.
g2int extlen
Number of entries in the template extension.
unsigned char interp_list
Interpetation of list of numbers defining number of points (See Table 3.11).
int g2c_rw_section6_metadata(FILE *f, int rw_flag, G2C_SECTION_INFO_T *sec)
Read or write the metadata from section 6 (Data Representation Section) of a GRIB2 message.
struct g2c_section5_info G2C_SECTION5_INFO_T
Information about Section 5 DATA REPRESENTATION SECTION.
size_t bytes_in_msg
Number of bytes in this message.
struct g2c_section_info * prev
Pointer to previous in list.
int num_fields
Number of fields in the message.
struct g2c_section4_info G2C_SECTION4_INFO_T
Information about Section 4 PRODUCT DEFINITION SECTION.
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-endia...
g2int * map
Number of octets of each entry in the static part of the template.
unsigned char sec_num
Section number.
g2int needext
Indicates whether or not the template needs to be extended.
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,...
void sbits(unsigned char *out, g2int *in, g2int iskip, g2int nbits, g2int nskip, g2int n)
Store bits - put arbitrary size values into a packed bit string, taking the low order bits from each ...
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...
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)
Add new message to linked list.
void * sec_info
Pointer to struct specific for section 3, 4, 5, 6, or 7.
g2int num
The template number.
float * value
Array of dimension values.
unsigned char indicator
Bit map indicator.
struct g2c_message_info G2C_MESSAGE_INFO_T
This is the information about each message.
unsigned int sec_len
Length of the section (in bytes).
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)
Add metadata about a new section 3, 4, 5, 6, or 7.
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 Templat...
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 Def...
void misspack(float *fld, g2int ndpts, g2int idrsnum, g2int *idrstmpl, unsigned char *cpack, g2int *lcpack)
This function packs up a data field using a complex packing algorithm as defined in the GRIB2 documen...
size_t bytes_to_sec
Number of bytes from start of message to this section.
unsigned char status
Production Status of Processed data in the GRIB message.
g2int getdim(unsigned char *csec3, g2int *width, g2int *height, g2int *iscan)
This subroutine returns the dimensions and scanning mode of a grid definition packed in GRIB2 Grid De...
int pack_gp(g2int *kfildo, g2int *ic, g2int *nxy, g2int *is523, g2int *minpk, g2int *inc, g2int *missp, g2int *misss, g2int *jmin, g2int *jmax, g2int *lbit, g2int *nov, g2int *ndg, g2int *lx, g2int *ibit, g2int *jbit, g2int *kbit, g2int *novref, g2int *lbitref, g2int *ier)
Determines groups of variable size, but at least of size minpk, the associated max (jmax( )) and min ...
G2C_MESSAGE_INFO_T * msg
Information about each message in the file.
int comunpack(unsigned char *cpack, g2int lensec, g2int idrsnum, g2int *idrstmpl, g2int ndpts, float *fld)
This subroutine unpacks a data field that was packed using a complex packing algorithm as defined in ...
void specpack(float *fld, g2int ndpts, g2int JJ, g2int KK, g2int MM, g2int *idrstmpl, unsigned char *cpack, g2int *lcpack)
This subroutine packs a spectral data field using the complex packing algorithm for spherical harmoni...
unsigned char second
Second.
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.
void simpack(float *fld, g2int ndpts, g2int *idrstmpl, unsigned char *cpack, g2int *lcpack)
This subroutine packs up a data field using the simple packing algorithm as defined in the GRIB2 docu...
FILE * f
FILE pointer to open file.
unsigned char source_grid_def
Source of grid definition (See Table 3.0).
int template_len
Number of entries in template.
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.
unsigned char local_version
Version number of GRIB local tables used to augment Master Tables.
void compack(float *fld, g2int ndpts, g2int idrsnum, g2int *idrstmpl, unsigned char *cpack, g2int *lcpack)
This subroutine packs up a data field using a complex packing algorithm as defined in the GRIB2 docum...
g2int specunpack(unsigned char *cpack, g2int *idrstmpl, g2int ndpts, g2int JJ, g2int KK, g2int MM, float *fld)
This subroutine unpacks a spectral data field that was packed using the complex packing algorithm for...
gtemplate * getdrstemplate(g2int number)
This subroutine returns DRS template information for a specified Data Representation Template.
gtemplate * getpdstemplate(g2int number)
This subroutine returns PDS template information for a specified Product Definition Template.
int section1[G2C_SECTION1_ARRAY_LEN]
Section 1 array.
g2int type
The template type: 3 Grid Defintion Template.
struct g2c_entry G2C_CODE_ENTRY_T
An entry in a GRIB2 code table.
int g2disc
GRIB2 discipline.
int dec_aec(unsigned char *cpack, g2int len, g2int nbits, g2int flags, g2int block_size, g2int rsi, unsigned char *cfld, g2int cfldlen)
This Function decodes an AEC code stream specified in the CCSDS 121.0-B-3 Blue Book.
unsigned char month
Month.
size_t msg_num
Number of message in file (0-based).
int g2c_rw_section1_metadata(FILE *f, int rw_flag, G2C_MESSAGE_INFO_T *msg)
Read Section 1.
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 bi...
int bytes_to_bms
Number of bytes in the message to the bitmap section.
g2int maplen
Number of entries in the static part of the template.
unsigned short data_def
Data representation template number (See Table 5.0).
int dec_jpeg2000(char *injpc, g2int bufsize, g2int *outfld)
This Function decodes a JPEG2000 code stream specified in the JPEG2000 Part-1 standard (i....
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...
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.
int g2c_add_file(const char *path, int mode, int *g2cid)
Open a GRIB2 file and add it to the list of open files.
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 ...
size_t bytes_to_msg
Number of bytes to skip in the file, to get to this message.
g2int simunpack(unsigned char *cpack, g2int *idrstmpl, g2int ndpts, float *fld)
This subroutine unpacks a data field that was packed using a simple packing algorithm as defined in t...
struct g2c_section6_info G2C_SECTION6_INFO_T
Information about Section 6 BIT-MAP SECTION.
int sec1_len
Length of section 1.
int enc_jpeg2000(unsigned char *cin, g2int width, g2int height, g2int nbits, g2int ltype, g2int ratio, g2int retry, char *outjpc, g2int jpclen)
This Function encodes a grayscale image into a JPEG2000 code stream specified in the JPEG2000 Part-1 ...
void rdieee(g2int *rieee, float *a, g2int num)
This subroutine reads a list of real values in 32-bit IEEE floating point format.
gtemplate * getgridtemplate(g2int number)
This subroutine returns grid template information for a specified Grid Definition Template for [Secti...
int g2num
GRIB2 parameter number.
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.
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.
struct g2c_message_info * next
Pointer to next in list.
void sbit(unsigned char *out, g2int *in, g2int iskip, g2int nbits)
Store bits - put arbitrary size values into a packed bit string, taking the low order bits from each ...
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 an...
G2C_MESSAGE_INFO_T * msg
Pointer to contianing message.
void aecpack(float *fld, g2int width, g2int height, g2int *idrstmpl, unsigned char *cpack, g2int *lcpack)
This function packs up a float array into a AEC code stream.
short center
Originating center.
int * optional
Optional list of numbers defining number of points.
struct g2c_file_info * file
Pointer to containing file.
unsigned short prod_def
Product definition template number (See Table 4.0).
Keep information about dimensions defined in section 3.
An entry in a GRIB2 code table.
This is the information about each open file.
This is the information about each message.
An entry in the table of NOAA abbreviations for GRIB parameters.
Information about Section 3 GRID DEFINITION SECTION.
Information about Section 4 PRODUCT DEFINITION SECTION.
Information about Section 5 DATA REPRESENTATION SECTION.
Information about Section 6 BIT-MAP SECTION.
Information about a section 3 through 7 in a GRIB2 message.
Struct for GRIB template, returned by getgridtemplate().