NCEPLIBS-g2c
1.6.4
|
Header file for NCEPLIBS-g2c library. More...
#include <stdio.h>
#include <stdint.h>
Go to the source code of this file.
Data Structures | |
struct | gribfield |
Struct for GRIB field. More... | |
struct | gtemplate |
Struct for GRIB template. More... | |
Macros | |
#define | G2_VERSION "g2clib-1.6.4" |
Current version of NCEPLIBS-g2c library. More... | |
Typedefs | |
typedef float | g2float |
Float type. More... | |
typedef int64_t | g2int |
Long integer type. More... | |
typedef uint64_t | g2intu |
Unsigned long integer type. More... | |
typedef struct gribfield | gribfield |
Struct for GRIB field. More... | |
typedef struct gtemplate | gtemplate |
Struct for GRIB template. More... | |
Functions | |
void | compack (g2float *, g2int, g2int, g2int *, unsigned char *, g2int *) |
This subroutine packs up a data field using a complex packing algorithm as defined in the GRIB2 documention. More... | |
gtemplate * | extdrstemplate (g2int, g2int *) |
This subroutine generates the remaining octet map for a given Data Representation Template, if required. More... | |
gtemplate * | extgridtemplate (g2int, g2int *) |
This subroutine generates the remaining octet map for a given Grid Definition Template, if required. More... | |
gtemplate * | extpdstemplate (g2int, g2int *) |
This subroutine generates the remaining octet map for a given Product Definition Template, if required. More... | |
g2int | g2_addfield (unsigned char *, g2int, g2int *, g2float *, g2int, g2int, g2int *, g2float *, g2int, g2int, g2int *) |
This routine packs up Sections 4 through 7 for a given field and adds them to a GRIB2 message. More... | |
g2int | g2_addgrid (unsigned char *, g2int *, g2int *, g2int *, g2int) |
This routine packs up a Grid Definition Section (Section 3) and adds it to a GRIB2 message. More... | |
g2int | g2_addlocal (unsigned char *, unsigned char *, g2int) |
This routine adds a Local Use Section (Section 2) to a GRIB2 message. More... | |
g2int | g2_create (unsigned char *, g2int *, g2int *) |
This routine initializes a new GRIB2 message and packs GRIB2 sections 0 (Indicator Section) and 1 (Identification Section). More... | |
void | g2_free (gribfield *) |
This routine frees up memory that was allocated for struct gribfield. More... | |
g2int | g2_getfld (unsigned char *, g2int, g2int, g2int, gribfield **) |
This subroutine returns all the metadata, template values, bit-map (if applicable), and the unpacked data for a given data field. More... | |
g2int | g2_gribend (unsigned char *) |
This routine finalizes a GRIB2 message after all grids and fields have been added. More... | |
g2int | g2_info (unsigned char *, g2int *, g2int *, g2int *, g2int *) |
This subroutine searches through a GRIB2 message and returns the number of gridded fields found in the message and the number (and maximum size) of Local Use Sections. More... | |
g2int | g2_unpack1 (unsigned char *, g2int *, g2int **, g2int *) |
This subroutine unpacks Section 1 - Identification Section as defined in GRIB Edition 2. More... | |
g2int | g2_unpack3 (unsigned char *, g2int *, g2int **, g2int **, g2int *, g2int **, g2int *) |
This routine unpacks Section 3 (Grid Definition Section) as defined in GRIB Edition 2. More... | |
g2int | g2_unpack4 (unsigned char *, g2int *, g2int *, g2int **, g2int *, g2float **, g2int *) |
This subroutine unpacks Section 4 (Product Definition Section) as defined in GRIB Edition 2. More... | |
g2int | g2_unpack5 (unsigned char *, g2int *, g2int *, g2int *, g2int **, g2int *) |
This subroutine unpacks Section 5 (Data Representation Section) as defined in GRIB Edition 2. More... | |
g2int | g2_unpack6 (unsigned char *, g2int *, g2int, g2int *, g2int **) |
This subroutine unpacks Section 6 (Bit-Map Section) as defined in GRIB Edition 2. More... | |
g2int | g2_unpack7 (unsigned char *, g2int *, g2int, g2int *, g2int, g2int *, g2int, g2float **) |
This subroutine unpacks Section 7 (Data Section) as defined in GRIB Edition 2. More... | |
void | gbit (unsigned char *, g2int *, g2int, g2int) |
Get bits - unpack bits: Extract arbitrary size values from a packed bit string, right justifying each value in the unpacked iout array. More... | |
void | gbits (unsigned char *, g2int *, g2int, g2int, g2int, g2int) |
Get bits - unpack bits: Extract arbitrary size values from a packed bit string, right justifying each value in the unpacked iout array. More... | |
gtemplate * | getdrstemplate (g2int) |
This subroutine returns DRS template information for a specified Data Representation Template. More... | |
gtemplate * | getgridtemplate (g2int) |
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). More... | |
gtemplate * | getpdstemplate (g2int) |
This subroutine returns PDS template information for a specified Product Definition Template. More... | |
double | int_power (double, g2int) |
Function similar to C pow() power function. More... | |
void | misspack (g2float *, g2int, g2int, g2int *, unsigned char *, g2int *) |
This subroutine packs up a data field using a complex packing algorithm as defined in the GRIB2 documention. More... | |
void | mkieee (g2float *, g2int *, g2int) |
This subroutine stores a list of real values in 32-bit IEEE floating point format. More... | |
int | pack_gp (g2int *, g2int *, g2int *, g2int *, g2int *, g2int *, g2int *, g2int *, g2int *, g2int *, g2int *, g2int *, g2int *, g2int *, g2int *, g2int *, g2int *, g2int *, g2int *, g2int *) |
Determines groups of variable size, but at least of size minpk, the associated max (jmax( )) and min (jmin( )), the number of bits necessary to hold the values in each group (lbit( )), the number of values in each group (nov( )), the number of bits necessary to pack the jmin( ) values (ibit), the number of bits necessary to pack the lbit( ) values (jbit), and the number of bits necessary to pack the nov( ) values (kbit). More... | |
void | rdieee (g2int *, g2float *, g2int) |
This subroutine reads a list of real values in 32-bit IEEE floating point format. More... | |
void | sbit (unsigned char *, g2int *, g2int, g2int) |
Store bits - put arbitrary size values into a packed bit string, taking the low order bits from each value in the unpacked array. More... | |
void | sbits (unsigned char *, g2int *, g2int, g2int, g2int, g2int) |
Store bits - put arbitrary size values into a packed bit string, taking the low order bits from each value in the unpacked array. More... | |
void | seekgb (FILE *, g2int, g2int, g2int *, g2int *) |
This subprogram searches a file for the next GRIB Message. More... | |
void | simpack (g2float *, g2int, g2int *, unsigned char *, g2int *) |
This subroutine packs up a data field using the simple packing algorithm as defined in the GRIB2 documention. More... | |
Header file for NCEPLIBS-g2c library.
Date | Programmer | Comments |
---|---|---|
2002-10-25 | Gilbert | Initial |
2009-01-14 | Vuong | Changed struct template to gtemplate |
Definition in file grib2.h.
struct gribfield |
Data Fields | ||
---|---|---|
g2int * | bmap |
Integer array containing decoded bitmap, if ibmap=0 or ibap=254. Otherwise NULL. |
g2float * | coord_list | Array containing floating point values intended to document the vertical discretisation associated to model data on hybrid coordinate vertical levels (part of Section 4). |
g2int | discipline | Message Discipline (see Table 0.0). |
g2int | expanded |
Logical value indicating whether the data field was expanded to the grid in the case where a bit-map is present. If true, the data points in fld match the grid points and zeros were inserted at grid points where data was bit-mapped out. If false, the data values in ld were not expanded to the grid and are just a consecutive array of data points corresponding to each value of "1" in bmap. |
g2float * | fld | Array of ndpts unpacked data points. |
g2int | griddef |
Source of grid definition (see Table 3.0).
|
g2int | ibmap |
Bitmap indicator (see Table 6.0).
|
g2int | idrtlen | Number of elements in idrtmpl. |
g2int * | idrtmpl | Contains the data values for the Data Representation Template specified by idrtnum. |
g2int | idrtnum | Data Representation Template Number (see Table 5.0). |
g2int * | idsect |
Contains the entries in the Identification Section (Section 1).
|
g2int | idsectlen | Number of elements in idsect. |
g2int | ifldnum | Field number within GRIB message. |
g2int | igdtlen |
Number of elements in igdtmpl - i.e. number of entries in Grid Defintion Template. |
g2int * | igdtmpl | Contains the data values for the Grid Definition Template specified by igdtnum. |
g2int | igdtnum | Grid Definition Template Number (See Table 3.1). |
g2int | interp_opt |
Interpretation of list for optional points definition. (See Table 3.11). |
g2int | ipdtlen |
Number of elements in ipdtmpl - i.e. number of entries in Product Defintion Template. |
g2int * | ipdtmpl | Contains the data values for the Product Definition Template specified by ipdtnum. |
g2int | ipdtnum | Product Definition Template Number (see Table 4.0). |
g2int * | list_opt |
(Used if numoct_opt .ne. 0) This array contains the number of grid points contained in each row (or column) (part of Section 3). NULL if numoct_opt = 0. |
unsigned char * | local | Pointer to character array containing contents of Local Section 2, if included. |
g2int | locallen | Length of array local. |
g2int | ndpts | Number of data points unpacked and returned. |
g2int | ngrdpts | Number of grid points in the defined grid. |
g2int | num_coord | Number of values in array coord_list. |
g2int | num_opt |
(Used if numoct_opt .ne. 0) The number of entries in array ideflist - i.e. number of rows (or columns) for which optional grid points are defined. This value is set to zero, if numoct_opt=0. |
g2int | numoct_opt |
Number of octets needed for each additional grid points definition. Used to define number of points in each row (or column) for non-regular grids. = 0, if using regular grid. |
g2int | unpacked |
Logical value indicating whether the bitmap and data values were unpacked. If false, bmap and fld pointers are NULL. |
g2int | version | GRIB edition number (2). |
struct gtemplate |
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. |
#define G2_VERSION "g2clib-1.6.4" |
void compack | ( | g2float * | 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 documention.
It 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 Template 5.3 with the appropriate values.
fld | Contains the data values to pack. |
ndpts | The number of data values in array fld. |
idrsnum | Data Representation Template number. Must equal 2 or 3. |
idrstmpl | Contains the array of values for Data Representation Template 5.2 or 5.3.
|
cpack | The packed data field. |
lcpack | length of packed field cpack. |
Definition at line 42 of file compack.c.
References int_power(), mkieee(), pack_gp(), sbit(), and sbits().
Referenced by cmplxpack().
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.
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. |
Definition at line 110 of file drstemplates.c.
References getdrsindex(), and getdrstemplate().
Referenced by g2_unpack5().
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.
This function allocates memory for the extension. The pointer ext in the gtemplate struct must be freed to prevent memory leaks.
number | The number of the Grid Definition Template that is being requested. |
list | The list of values for each entry in the Grid Definition Template. |
Definition at line 124 of file gridtemplates.c.
References getgridindex(), and getgridtemplate().
Referenced by g2_addgrid(), and g2_unpack3().
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.
This function allocates memory in the ext field of the gtemplate struct. This memory must be freed by the caller.
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. |
Definition at line 121 of file pdstemplates.c.
References getpdsindex(), and getpdstemplate().
Referenced by g2_addfield(), and g2_unpack4().
g2int g2_addfield | ( | unsigned char * | cgrib, |
g2int | ipdsnum, | ||
g2int * | ipdstmpl, | ||
g2float * | coordlist, | ||
g2int | numcoord, | ||
g2int | idrsnum, | ||
g2int * | idrstmpl, | ||
g2float * | fld, | ||
g2int | ngrdpts, | ||
g2int | ibmap, | ||
g2int * | bmap | ||
) |
This routine packs up Sections 4 through 7 for a given field and adds them to a GRIB2 message.
They are Product Definition Section, Data Representation Section, Bit-Map Section and Data Section, respectively.
This routine is used with routines g2_create(), g2_addlocal(), g2_addgrid(), and g2_gribend() to create a complete GRIB2 message. Function g2_create() must be called first to initialize a new GRIB2 message. Function g2_addgrid() must be called after g2_create() and before this routine to add the appropriate grid description to the GRIB2 message. A call to g2_gribend() is required to complete GRIB2 message after all fields have been added.
Date | Programmer | Comments |
---|---|---|
2002-11-05 | Gilbert | Initial |
2002-12-23 | Gilbert | Added complex spherical harmonic packing |
2003-08-27 | Gilbert | Added support for new templates using PNG and JPEG2000 algorithms/templates. |
2004-11-29 | Gilbert | JPEG2000 now can use WMO Template 5.40 PNG can use WMO Template 5.41. Added packing algorithm check. |
2005-05-10 | Gilbert | Imposed minimum size on cpack. |
2009-01-14 | Vuong | Changed structure name template to gtemplate |
cgrib | Char array that contains the GRIB2 message to which sections 4 through 7 should be added. Must be allocated large enough to store the entire GRIB2 message. |
ipdsnum | Product Definition Template Number (see Code Table 4.0). |
ipdstmpl | Contains the data values for the Product Definition Template specified by ipdsnum. |
coordlist | Array containg floating point values intended to document the vertical discretisation associated to model data on hybrid coordinate vertical levels. |
numcoord | number of values in array coordlist. |
idrsnum | Data Representation Template Number (see Code Table 5.0). |
idrstmpl | The data values for the Data Representation Template specified by idrsnum. Note that some values in this template (eg. reference values, number of bits, etc...) may be changed by the data packing algorithms. Use this to specify scaling factors and order of spatial differencing, if desired. |
fld | Array of data points to pack. |
ngrdpts | Number of data points in grid. i.e. size of fld and bmap. |
ibmap | Bitmap indicator (see Code Table 6.0)
|
bmap | Integer array containing bitmap to be added (if ibmap = 0). |
Definition at line 106 of file g2_addfield.c.
References cmplxpack(), gtemplate::ext, gtemplate::extlen, extpdstemplate(), gbit(), getdim(), getdrstemplate(), getpdstemplate(), getpoly(), jpcpack(), gtemplate::map, gtemplate::maplen, mkieee(), gtemplate::needext, pngpack(), sbit(), sbits(), simpack(), and specpack().
g2int g2_addgrid | ( | unsigned char * | cgrib, |
g2int * | igds, | ||
g2int * | igdstmpl, | ||
g2int * | ideflist, | ||
g2int | idefnum | ||
) |
This routine packs up a Grid Definition Section (Section 3) and adds it to a GRIB2 message.
It is used with routines g2_create(), g2_addlocal(), g2_addfield(), and g2_gribend() to create a complete GRIB2 message. g2_create() must be called first to initialize a new GRIB2 message.
Date | Programmer | Comments |
---|---|---|
2002-11-01 | Gilbert | Initial. |
2009-01-14 | Vuong | Changed structure name template to gtemplate |
cgrib | Char array that contains the GRIB2 message to which section should be added. Must be allocated large enough to store the entire GRIB2 message. |
igds | Contains information needed for GRIB Grid Definition Section 3. Must be dimensioned >= 5.
|
igdstmpl | Contains the data values for the specified Grid Definition Template (igds[4]). Each element of this integer array contains an entry (in the order specified) of Grid Defintion Template. |
ideflist | (Used if igds[2] != 0) This array contains the number of grid points contained in each row (or column). |
idefnum | (Used if igds[2] != 0) The number of entries in array ideflist. i.e. number of rows (or columns) for which optional grid points are defined. |
Definition at line 66 of file g2_addgrid.c.
References gtemplate::ext, extgridtemplate(), gtemplate::extlen, gbit(), getgridtemplate(), gtemplate::map, gtemplate::maplen, gtemplate::needext, sbit(), and sbits().
This routine adds a Local Use Section (Section 2) to a GRIB2 message.
It is used with routines g2_create(), g2_addgrid(), g2_addfield(), and g2_gribend() to create a complete GRIB2 message. g2_create() must be called first to initialize a new GRIB2 message.
cgrib | Char array that contains the GRIB2 message to which section 2 should be added. Must be allocated large enough to store the entire GRIB2 message. |
csec2 | Character array containing information to be added in Section 2. |
lcsec2 | Number of bytes of character array csec2 to be added to Section 2. |
Definition at line 37 of file g2_addlocal.c.
This routine initializes a new GRIB2 message and packs GRIB2 sections 0 (Indicator Section) and 1 (Identification Section).
This routine is used with routines g2_addlocal(), g2_addgrid(), g2_addfield(), and g2_gribend() to create a complete GRIB2 message. g2_create() must be called first to initialize a new GRIB2 message. A call to g2_gribend() is required to complete GRIB2 message after all fields have been added.
[in] | cgrib | Character array to contain the GRIB2 message. Must be allocated large enough to store the entire GRIB2 message. |
[in] | listsec0 | Contains information needed for GRIB Indicator Section 0. Must be dimensioned >= 2.
|
[in] | listsec1 | Contains information needed for GRIB Identification Section 1. Must be dimensioned >= 13.
|
This routine is intended for use with routines g2_addlocal(), g2_addgrid(), g2_addfield(), and g2_gribend() to create a complete GRIB2 message.
Definition at line 63 of file g2_create.c.
References LENSEC0, MAPSEC1LEN, and sbit().
void g2_free | ( | gribfield * | gfld | ) |
This routine frees up memory that was allocated for struct gribfield.
gfld | pointer to gribfield structure (defined in include file grib2.h) returned from routine g2_getfld(). |
Definition at line 24 of file g2_free.c.
References gribfield::bmap, gribfield::coord_list, gribfield::fld, gribfield::idrtmpl, gribfield::idsect, gribfield::igdtmpl, gribfield::ipdtmpl, gribfield::list_opt, and gribfield::local.
g2int g2_getfld | ( | unsigned char * | cgrib, |
g2int | ifldnum, | ||
g2int | unpack, | ||
g2int | expand, | ||
gribfield ** | gfld | ||
) |
This subroutine returns all the metadata, template values, bit-map (if applicable), and the unpacked data for a given data field.
All of the information returned is stored in a gribfield structure, which is defined in file grib2.h. Users of this routine will need to include grib2.h in their source code that calls this routine.
Since there can be multiple data fields packed into a GRIB2 message, the calling routine indicates which field is being requested with the ifldnum argument.
Date | Programmer | Comments |
---|---|---|
2002-10-28 | Gilbert | Initial |
2013-08-08 | Vuong | Free up memory in array igds - free(igds) |
cgrib | Character pointer to the GRIB2 message. |
ifldnum | Specifies which field in the GRIB2 message to return. The first field is number 1, Fortran style. |
unpack | Boolean value indicating whether to unpack bitmap/data field.
|
expand | Boolean value indicating whether the data points should be expanded to the correspond grid, if a bit-map is present. This argument is ignored if unpack == 0 OR if the returned field does not contain a bit-map.
|
gfld | pointer to structure gribfield containing all decoded data for the data field. |
Routine g2_info() can be used to first determine how many data fields exist in a given GRIB message.
Definition at line 102 of file g2_getfld.c.
References gribfield::bmap, gribfield::coord_list, gribfield::discipline, gribfield::expanded, gribfield::fld, g2_unpack1(), g2_unpack2(), g2_unpack3(), g2_unpack4(), g2_unpack5(), g2_unpack6(), g2_unpack7(), gbit(), gribfield::griddef, gribfield::ibmap, gribfield::idrtlen, gribfield::idrtmpl, gribfield::idrtnum, gribfield::idsect, gribfield::idsectlen, gribfield::ifldnum, gribfield::igdtlen, gribfield::igdtmpl, gribfield::igdtnum, gribfield::interp_opt, gribfield::ipdtlen, gribfield::ipdtmpl, gribfield::ipdtnum, gribfield::list_opt, gribfield::local, gribfield::locallen, gribfield::ndpts, gribfield::ngrdpts, gribfield::num_coord, gribfield::num_opt, gribfield::numoct_opt, gribfield::unpacked, and gribfield::version.
g2int g2_gribend | ( | unsigned char * | cgrib | ) |
This routine finalizes a GRIB2 message after all grids and fields have been added.
It adds the End Section ("7777") to the end of the GRIB message and calculates the length and stores it in the appropriate place in Section 0. This routine is used with routines g2_create(), g2_addlocal(), g2_addgrid(), and g2_addfield() to create a complete GRIB2 message.
cgrib | Char array containing all the data sections added be previous calls to g2_create(), g2_addlocal(), g2_addgrid(), and g2_addfield(). After function is called, contains the finalized GRIB2 message. |
Definition at line 35 of file g2_gribend.c.
g2int g2_info | ( | unsigned char * | cgrib, |
g2int * | listsec0, | ||
g2int * | listsec1, | ||
g2int * | numfields, | ||
g2int * | numlocal | ||
) |
This subroutine searches through a GRIB2 message and returns the number of gridded fields found in the message and the number (and maximum size) of Local Use Sections.
Also various checks are performed to see if the message is a valid GRIB2 message.
cgrib | Character pointer to the GRIB2 message. |
listsec0 | pointer to an array containing information decoded from GRIB Indicator Section 0. Must be allocated with >= 3 elements.
|
listsec1 | Pointer to an array containing information read from GRIB Identification Section 1. Must be allocated with >= 13 elements.
|
numfields | The number of gridded fields found in the GRIB message. That is, the number of occurences of Sections 4 - 7. |
numlocal | The number of Local Use Sections ( Section 2 ) found in the GRIB message. |
Definition at line 67 of file g2_info.c.
References gbit().
This subroutine unpacks Section 1 - Identification Section as defined in GRIB Edition 2.
cgrib | char array containing Section 1 of the GRIB2 message. |
iofst | Bit offset for the beginning of Section 1 in cgrib. |
ids | Pointer that gets an array which contians the information read from Section 1, the Identification section. This array is allocated by this function, and must be freed by caller (using g2_free()).
|
idslen | Number of elements in ids. |
Definition at line 55 of file g2_unpack1.c.
g2int g2_unpack3 | ( | unsigned char * | cgrib, |
g2int * | iofst, | ||
g2int ** | igds, | ||
g2int ** | igdstmpl, | ||
g2int * | mapgridlen, | ||
g2int ** | ideflist, | ||
g2int * | idefnum | ||
) |
This routine unpacks Section 3 (Grid Definition Section) as defined in GRIB Edition 2.
Date | Programmer | Comments |
---|---|---|
2002-10-31 | Gilbert | Initial |
2009-01-14 | Vuong | Changed structure name template to gtemplate |
cgrib | Char array ontaining Section 3 of the GRIB2 message. |
iofst | Bit offset for the beginning of Section 3 in cgrib. |
igds | Contains information read from the appropriate GRIB Grid Definition Section 3 for the field being returned.
|
igdstmpl | Pointer to integer array containing the data values for the Grid Definition Template specified by igds[4]. |
mapgridlen | Number of elements in igdstmpl. i.e. number of entries in Grid Defintion Template specified by igds[4]. |
ideflist | (Used if igds[2] .ne. 0) Pointer to integer array containing the number of grid points contained in each row (or column). |
idefnum | (Used if igds[2] .ne. 0) The number of entries in array ideflist - i.e. number of rows (or columns) for which optional grid points are defined. |
Definition at line 57 of file g2_unpack3.c.
g2int g2_unpack4 | ( | unsigned char * | cgrib, |
g2int * | iofst, | ||
g2int * | ipdsnum, | ||
g2int ** | ipdstmpl, | ||
g2int * | mappdslen, | ||
g2float ** | coordlist, | ||
g2int * | numcoord | ||
) |
This subroutine unpacks Section 4 (Product Definition Section) as defined in GRIB Edition 2.
Date | Programmer | Comments |
---|---|---|
2002-10-31 | Gilbert | Initial |
2009-01-14 | Vuong | Changed structure name template to gtemplate |
cgrib | Array containing Section 4 of the GRIB2 message. |
iofst | Bit offset of the beginning of Section 4 in cgrib. Returned with updated bit offset. |
ipdsnum | Product Definition Template Number (see Table 4.0). |
ipdstmpl | Pointer that gets an integer array containing the data values for the Product Definition Template specified by ipdsnum. |
mappdslen | Number of elements in ipdstmpl - i.e. number of entries in Product Defintion Template specified by ipdsnum. |
coordlist | Pointer that gets an array containing floating point values intended to document the vertical discretisation associated to model data on hybrid coordinate vertical levels. |
numcoord | number of values in array coordlist. |
Definition at line 45 of file g2_unpack4.c.
g2int g2_unpack5 | ( | unsigned char * | cgrib, |
g2int * | iofst, | ||
g2int * | ndpts, | ||
g2int * | idrsnum, | ||
g2int ** | idrstmpl, | ||
g2int * | mapdrslen | ||
) |
This subroutine unpacks Section 5 (Data Representation Section) as defined in GRIB Edition 2.
Date | Programmer | Comments |
---|---|---|
2002-10-31 | Gilbert | Initial |
2009-01-14 | Vuong | Changed structure name template to gtemplate |
cgrib | char array containing Section 5 of the GRIB2 message. |
iofst | Bit offset for the beginning of Section 5 in cgrib. Returned with bit offset at the end of Section 5. |
ndpts | Number of data points unpacked and returned. |
idrsnum | Data Representation Template Number (see Code Table 5.0). |
idrstmpl | Pointer to an integer array containing the data values for the specified Data Representation Template (N=idrsnum). Each element of this integer array contains an entry (in the order specified) of Data Representation Template 5.N. |
mapdrslen- | Number of elements in idrstmpl. i.e. number of entries in Data Representation Template 5.N (N=idrsnum). |
Definition at line 42 of file g2_unpack5.c.
g2int g2_unpack6 | ( | unsigned char * | cgrib, |
g2int * | iofst, | ||
g2int | ngpts, | ||
g2int * | ibmap, | ||
g2int ** | bmap | ||
) |
This subroutine unpacks Section 6 (Bit-Map Section) as defined in GRIB Edition 2.
cgrib | char array containing Section 6 of the GRIB2 message. |
iofst | Bit offset of the beginning of Section 6 in cgrib. |
ngpts | Number of grid points specified in the bit-map |
ibmap | Bitmap indicator (see Code Table 6.0)
|
bmap | Pointer to an integer array containing decoded bitmap. (if ibmap=0) |
Definition at line 33 of file g2_unpack6.c.
g2int g2_unpack7 | ( | unsigned char * | cgrib, |
g2int * | iofst, | ||
g2int | igdsnum, | ||
g2int * | igdstmpl, | ||
g2int | idrsnum, | ||
g2int * | idrstmpl, | ||
g2int | ndpts, | ||
g2float ** | fld | ||
) |
This subroutine unpacks Section 7 (Data Section) as defined in GRIB Edition 2.
Date | Programmer | Comments |
---|---|---|
2002-10-31 | Gilbert | Initial |
2002-12-20 | Gilbert | Added GDT info to arguments and added 5.51 processing. |
2003-08-29 | Gilbert | New templates using PNG and JPEG2000 algorithms/templates. |
2004-11-29 | Gilbert | JPEG2000 now allowed to use WMO Template 5.40 PNG allowed to use 5.41 |
2004-12-16 | Taylor | Added check on comunpack return code. |
2008-12-23 | Wesley | Initialize Number of data points unpacked |
cgrib | char array containing Section 7 of the GRIB2 message |
iofst | Bit offset of the beginning of Section 7 in cgrib. |
igdsnum | Grid Definition Template Number (see Code Table 3.0) (Only used for DRS Template 5.51) |
igdstmpl | Pointer to an integer array containing the data values for the specified Grid Definition Template (N=igdsnum). Each element of this integer array contains an entry (in the order specified) of Grid Definition Template 3.N. (Only used for DRS Template 5.51). |
idrsnum | Data Representation Template Number (see Code Table 5.0) |
idrstmpl | Pointer to an integer array containing the data values for the specified Data Representation Template (N=idrsnum). Each element of this integer array contains an entry (in the order specified) of Data Representation Template 5.N |
ndpts | Number of data points unpacked and returned. |
fld | Pointer to a float array containing the unpacked data field. |
Definition at line 65 of file g2_unpack7.c.
Get bits - unpack bits: Extract arbitrary size values from a packed bit string, right justifying each value in the unpacked iout array.
in | pointer to character array input. |
iout | pointer to unpacked array output. |
iskip | initial number of bits to skip. |
nbyte | number of bits to take. |
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(), g2_unpack7(), and seekgb().
Get bits - unpack bits: Extract arbitrary size values from a packed bit string, right justifying each value in the unpacked iout array.
in | Pointer to character array input. |
iout | Pointer to unpacked array output. |
iskip | Initial number of bits to skip. |
nbyte | Number of bits to take. |
nskip | Additional number of bits to skip on each iteration. |
n | Number of iterations. |
Definition at line 57 of file gbits.c.
Referenced by comunpack(), g2_unpack3(), g2_unpack4(), g2_unpack6(), gbit(), pngunpack(), simunpack(), and specunpack().
This subroutine returns DRS template information for a specified Data Representation Template.
The number of entries in the template is returned along with a map of the number of octets occupied by each entry. Also, a flag is returned to indicate whether the template would need to be extended.
number | The number of the Data Representation Template that is being requested. |
Definition at line 64 of file drstemplates.c.
References getdrsindex(), drstemplate::mapdrslen, drstemplate::needext, drstemplate::template_num, and templatesdrs.
Referenced by extdrstemplate(), g2_addfield(), and g2_unpack5().
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).
The number of entries in the template is returned along with a map of the number of octets occupied by each entry. Also, a flag is returned to indicate whether the template would need to be extended.
This function allocates storage for the template. The returned pointer must be freed by the caller.
number | The number of the Grid Definition Template that is being requested. |
Definition at line 75 of file gridtemplates.c.
References getgridindex(), gridtemplate::mapgridlen, gridtemplate::needext, gridtemplate::template_num, and templatesgrid.
Referenced by extgridtemplate(), g2_addgrid(), and g2_unpack3().
This subroutine returns PDS template information for a specified Product Definition Template.
The number of entries in the template is returned along with a map of the number of octets occupied by each entry. Also, a flag is returned to indicate whether the template would need to be extended.
This function allocates memory for the gtemplate struct, which must be freed by the caller.
number | the number of the Product Definition Template that is being requested. |
Definition at line 73 of file pdstemplates.c.
References getpdsindex(), pdstemplate::mappdslen, pdstemplate::needext, pdstemplate::template_num, and templatespds.
Referenced by extpdstemplate(), g2_addfield(), and g2_unpack4().
double int_power | ( | double | x, |
g2int | y | ||
) |
Function similar to C pow() power function.
x | The base value whose power is to be calculated. |
y | The power value. |
Definition at line 17 of file int_power.c.
Referenced by compack(), comunpack(), jpcpack(), jpcunpack(), misspack(), mkieee(), pngpack(), pngunpack(), rdieee(), simpack(), simunpack(), and specunpack().
void misspack | ( | g2float * | 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 documention.
It 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 Template 5.3 with the appropriate values. This version assumes that Missing Value Management is being used and that 1 or 2 missing values appear in the data.
fld | Contains the data values to pack |
ndpts | The number of data values in array fld |
idrsnum | Data Representation Template number 5.N Must equal 2 or 3. |
idrstmpl | Contains the array of values for Data Representation Template 5.2 or 5.3.
|
cpack | The packed data field (character*1 array). |
lcpack | length of packed field cpack. |
Definition at line 43 of file misspack.c.
References int_power(), mkieee(), pack_gp(), rdieee(), sbit(), and sbits().
Referenced by cmplxpack().
This subroutine stores a list of real values in 32-bit IEEE floating point format.
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 g2int integer array. rieee must be allocated with at least 4*num bytes of memory before calling this function. |
Definition at line 21 of file mkieee.c.
References int_power().
Referenced by compack(), g2_addfield(), jpcpack(), misspack(), pngpack(), simpack(), and specpack().
int pack_gp | ( | integer * | kfildo, |
integer * | ic, | ||
integer * | nxy, | ||
integer * | is523, | ||
integer * | minpk, | ||
integer * | inc, | ||
integer * | missp, | ||
integer * | misss, | ||
integer * | jmin, | ||
integer * | jmax, | ||
integer * | lbit, | ||
integer * | nov, | ||
integer * | ndg, | ||
integer * | lx, | ||
integer * | ibit, | ||
integer * | jbit, | ||
integer * | kbit, | ||
integer * | novref, | ||
integer * | lbitref, | ||
integer * | ier | ||
) |
Determines groups of variable size, but at least of size minpk, the associated max (jmax( )) and min (jmin( )), the number of bits necessary to hold the values in each group (lbit( )), the number of values in each group (nov( )), the number of bits necessary to pack the jmin( ) values (ibit), the number of bits necessary to pack the lbit( ) values (jbit), and the number of bits necessary to pack the nov( ) values (kbit).
The routine is designed to determine the groups such that a small number of bits is necessary to pack the data without excessive computations. If all values in the group are zero, the number of bits to use in packing is defined as zero when there can be no missing values; when there can be missing values, the number of bits must be at least 1 to have 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 integer. Even though the groups are initially of size minpk or larger, an adjustment between two groups (the lookback procedure) may make a group smaller than minpk. The control on group size is that the sum of the sizes of the two consecutive groups, each of size minpk or larger, is not decreased. When determining the number of bits necessary for packing, the largest value that can be accommodated in, say, mbits, is 2**mbits-1; this largest value (and the next smallest value) is reserved for the missing value indicator (only) when is523 ne 0. If the dimension ndg is not large enough to hold all the groups, the local value of minpk is increased by 50 percent. This is repeated until ndg will suffice. A diagnostic is printed whenever this happens, which should be very rarely. If it happens often, ndg in subroutine pack should be increased and a corresponding increase in subroutine unpack made. Considerable code is provided so that no more checking for missing values within loops is done than necessary; the added efficiency of this is relatively minor, but does no harm. For grib2, the reference value for the length of groups in nov( ) and for the number of bits necessary to pack group values are determined, and subtracted before jbit and kbit are determined.
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 total bits required. If reduce should abort, pack_gp will be executed again without the call to reduce.
PROGRAM HISTORY LOG:
DATA SET USE
kfildo | unit number for output (print) file. (input) |
ic | array to hold data for packing. the values do not have to be positive at this point, but must be in the range -2**30 to +2**30 (the the value of mallow). these integer values will be retained exactly through packing and unpacking. (input) |
nxy | number of values in ic( ). also treated as its dimension. (input) |
is523 | missing value management 0=data contains no missing values 1=data contains primary missing values 2=data contains primary and secondary missing values (input) |
minpk | the minimum size of each group, except possibly the last one. (input) |
inc | the number of values to add to an already existing group in determining whether or not to start a new group. ideally, this would be 1, but each time inc values are attempted, the max and min of the next minpk values must be found. this is "a loop within a loop," and a slightly larger value may give about as good results with slightly less computational time. if inc is le 0, 1 is used, and a diagnostic is output. note: it is expected that inc will equal 1. the code uses inc primarily in the loops starting at statement 180. if inc were 1, there would not need to be loops as such. however, kinc (the local value of inc) is set ge 1 when near the end of the data to forestall a very small group at the end. (input) |
missp | when missing points can be present in the data, they will have the value missp or misss. missp is the primary missing value and misss is the secondary missing value . these must not be values that would occur with subtracting the minimum (reference) value or scaling. for example, missp = 0 would not be advisable. (input) |
misss | secondary missing value indicator (see missp). (input) |
jmin | the minimum of each group (j=1,lx). (output) |
jmax | the maximum of each group (j=1,lx). this is not really needed, but since the max of each group must be found, saving it here is cheap in case the user wants it. (output) |
lbit | the number of bits necessary to pack each group (j=1,lx). it is assumed the minimum of each group will be removed before packing, and the values to pack will, therefore, all be positive. however, ic( ) does not necessarily contain all positive values. if the overall minimum has been removed (the usual case), then ic( ) will contain only positive values. (output) |
nov | the number of values in each group (j=1,lx). (output) |
ndg | the dimension of jmin, jmax, lbit, and nov. (input) |
lx | the number of groups determined. (output) |
ibit | the number of bits necessary to pack the jmin(j) values, j=1,lx. (output) |
jbit | the number of bits necessary to pack the lbit(j) values, j=1,lx. (output) |
kbit | the number of bits necessary to pack the nov(j) values, j=1,lx. (output) |
novref | reference value for nov( ). (output) |
lbitref | reference value for lbit( ). (output) |
ier | Error code
|
INTERNAL VARIABLES
cfeed = contains the character representation of a printer form feed. ifeed = contains the integer value of a printer form feed. kinc = working copy of inc. may be modified. mina = minimum value in group a. maxa = maximum value in group a. nenda = the place in ic( ) where group a ends. kstart = the place in ic( ) where group a starts. ibita = number of bits needed to hold values in group a. minb = minimum value in group b. maxb = maximum value in group b. nendb = the place in ic( ) where group b ends. ibitb = number of bits needed to hold values in group b. minc = minimum value in group c. maxc = maximum value in group c. ktotal = count of number of values in ic( ) processed. nount = number of values added to group a. lmiss = 0 when is523 = 0. when packing into a specific number of bits, say mbits, the maximum value that can be handled is 2**mbits-1. when is523 = 1, indicating primary missing values, this maximum value is reserved to hold the primary missing value indicator and lmiss = 1. when is523 = 2, the value just below the maximum i.e., 2**mbits-2 is reserved to hold the secondary missing value indicator and lmiss = 2. lminpk = local value of minpk. this will be adjusted upward whenever ndg is not large enough to hold all the groups. mallow = the largest allowable value for packing. mislla = set to 1 when all values in group a are missing. this is used to distinguish between a real minimum when all values are not missing and a minimum that has been set to zero when all values are missing. 0 otherwise. note that this does not distinguish between primary and secondary missings when secondary missings are present. this means that lbit( ) will not be zero with the resulting compression efficiency when secondary missings are present. also note that a check has been made earlier to determine that secondary missings are really there. misllb = set to 1 when all values in group b are missing. this is used to distinguish between a real minimum when all values are not missing and a minimum that has been set to zero when all values are missing. 0 otherwise. misllc = performs the same function for group c that mislla and misllb do for groups b and c, respectively. ibxx2(j) = an array that when this routine is first entered is set to 2**j, j=0,30. ibxx2(30) = 2**30, which is the largest value packable, because 2**31 is larger than the integer word size. ifirst = set by data statement to 0. changed to 1 on first entry when ibxx2( ) is filled. minak = keeps track of the location in ic( ) where the minimum value in group a is located. maxak = does the same as minak, except for the maximum. minbk = the same as minak for group b. maxbk = the same as maxak for group b. minck = the same as minak for group c. maxck = the same as maxak for group c. adda = keeps track whether or not an attempt to add points to group a was made. if so, then adda keeps from trying to put one back into b. (logical) ibitbs = keeps current value if ibitb so that loop ending at 166 doesn't have to start at ibitb = 0 every time. misslx(j) = mallow except when a group is all one value (and lbit(j) = 0) and that value is missing. in that case, misslx(j) is missp or misss. this gets inserted into jmin(j) later as the missing indicator; it can't be put in until the end, because jmin( ) is used to calculate the maximum number of bits (ibits) needed to pack jmin( ).
Definition at line 256 of file pack_gp.c.
References FALSE_, reduce(), and TRUE_.
Referenced by compack(), and misspack().
This subroutine reads a list of real values in 32-bit IEEE floating point format.
rieee | g2int array of floating point values in 32-bit IEEE format. |
num | Number of floating point values to convert. |
a | float array of real values. a must be allocated with at least 4*num bytes of memory before calling this function. |
Definition at line 20 of file rdieee.c.
References int_power().
Referenced by comunpack(), g2_miss(), g2_unpack4(), g2_unpack7(), jpcunpack(), misspack(), pngunpack(), simunpack(), and specunpack().
Store bits - put arbitrary size values into a packed bit string, taking the low order bits from each value in the unpacked array.
out | Pointer to packed array output. Must be allocated large enough to hold output. |
in | Pointer to unpacked array input. |
iskip | Initial number of bits to skip. |
nbyte | Number of bits to pack. |
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().
Store bits - put arbitrary size values into a packed bit string, taking the low order bits from each value in the unpacked array.
out | Pointer to packed array output. Must be allocated large enough to hold output. |
in | Pointer to unpacked array input. |
iskip | Initial number of bits to skip. |
nbyte | Number of bits to pack. |
nskip | Additional number of bits to skip on each iteration. |
n | Number of iterations. |
Definition at line 114 of file gbits.c.
Referenced by compack(), g2_addfield(), g2_addgrid(), jpcpack(), misspack(), pngpack(), sbit(), and simpack().
This subprogram searches a file for the next GRIB Message.
The search is done starting at byte offset iseek of the file referenced by lugb for mseek bytes at a time. If found, the starting position and length of the message are returned in lskip and lgrib, respectively. The search is terminated when an EOF or I/O error is encountered.
PROGRAM HISTORY LOG:
lugb | FILE pointer for the file to search. File must be opened before this routine is called. |
iseek | number of bytes in the file to skip before search. |
mseek | number of bytes to search at a time. |
lskip | number of bytes to skip from the beggining of the file to where the GRIB message starts. |
lgrib | number of bytes in message (set to 0, if no message found). |
Definition at line 32 of file seekgb.c.
References gbit().
void simpack | ( | g2float * | 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 documention.
It also fills in GRIB2 Data Representation Template 5.0 with the appropriate values.
fld | Contains the data values to pack. |
ndpts | The number of data values in array fld. |
idrstmpl | Contains the array of values for [Data Representation Template 5.0](https://www.nco.ncep.noaa.gov/pmb/docs/grib2/grib2_doc/grib2_temp5-0.shtml).
|
cpack | The packed data field |
lcpack | length of packed field starting at cpack. |