.TH "grib2.h" 3 "Fri Jun 3 2022" "Version 1.6.4" "NCEPLIBS-g2c" \" -*- nroff -*- .ad l .nh .SH NAME grib2.h \- Header file for NCEPLIBS-g2c library\&. .SH SYNOPSIS .br .PP \fC#include \fP .br \fC#include \fP .br .SS "Data Structures" .in +1c .ti -1c .RI "struct \fBgribfield\fP" .br .RI "Struct for GRIB field\&. " .ti -1c .RI "struct \fBgtemplate\fP" .br .RI "Struct for GRIB template\&. " .in -1c .SS "Macros" .in +1c .ti -1c .RI "#define \fBG2_VERSION\fP 'g2clib\-1\&.6\&.4'" .br .RI "Current version of NCEPLIBS-g2c library\&. " .in -1c .SS "Typedefs" .in +1c .ti -1c .RI "typedef float \fBg2float\fP" .br .RI "Float type\&. " .ti -1c .RI "typedef int64_t \fBg2int\fP" .br .RI "Long integer type\&. " .ti -1c .RI "typedef uint64_t \fBg2intu\fP" .br .RI "Unsigned long integer type\&. " .ti -1c .RI "typedef struct \fBgribfield\fP \fBgribfield\fP" .br .RI "Struct for GRIB field\&. " .ti -1c .RI "typedef struct \fBgtemplate\fP \fBgtemplate\fP" .br .RI "Struct for GRIB template\&. " .in -1c .SS "Functions" .in +1c .ti -1c .RI "void \fBcompack\fP (\fBg2float\fP *, \fBg2int\fP, \fBg2int\fP, \fBg2int\fP *, unsigned char *, \fBg2int\fP *)" .br .RI "This subroutine packs up a data field using a complex packing algorithm as defined in the GRIB2 documention\&. " .ti -1c .RI "\fBgtemplate\fP * \fBextdrstemplate\fP (\fBg2int\fP, \fBg2int\fP *)" .br .RI "This subroutine generates the remaining octet map for a given Data Representation Template, if required\&. " .ti -1c .RI "\fBgtemplate\fP * \fBextgridtemplate\fP (\fBg2int\fP, \fBg2int\fP *)" .br .RI "This subroutine generates the remaining octet map for a given Grid Definition Template, if required\&. " .ti -1c .RI "\fBgtemplate\fP * \fBextpdstemplate\fP (\fBg2int\fP, \fBg2int\fP *)" .br .RI "This subroutine generates the remaining octet map for a given Product Definition Template, if required\&. " .ti -1c .RI "\fBg2int\fP \fBg2_addfield\fP (unsigned char *, \fBg2int\fP, \fBg2int\fP *, \fBg2float\fP *, \fBg2int\fP, \fBg2int\fP, \fBg2int\fP *, \fBg2float\fP *, \fBg2int\fP, \fBg2int\fP, \fBg2int\fP *)" .br .RI "This routine packs up Sections 4 through 7 for a given field and adds them to a GRIB2 message\&. " .ti -1c .RI "\fBg2int\fP \fBg2_addgrid\fP (unsigned char *, \fBg2int\fP *, \fBg2int\fP *, \fBg2int\fP *, \fBg2int\fP)" .br .RI "This routine packs up a Grid Definition Section (Section 3) and adds it to a GRIB2 message\&. " .ti -1c .RI "\fBg2int\fP \fBg2_addlocal\fP (unsigned char *, unsigned char *, \fBg2int\fP)" .br .RI "This routine adds a Local Use Section (Section 2) to a GRIB2 message\&. " .ti -1c .RI "\fBg2int\fP \fBg2_create\fP (unsigned char *, \fBg2int\fP *, \fBg2int\fP *)" .br .RI "This routine initializes a new GRIB2 message and packs GRIB2 sections 0 (Indicator Section) and 1 (Identification Section)\&. " .ti -1c .RI "void \fBg2_free\fP (\fBgribfield\fP *)" .br .RI "This routine frees up memory that was allocated for struct gribfield\&. " .ti -1c .RI "\fBg2int\fP \fBg2_getfld\fP (unsigned char *, \fBg2int\fP, \fBg2int\fP, \fBg2int\fP, \fBgribfield\fP **)" .br .RI "This subroutine returns all the metadata, template values, Bit-map (if applicable), and the unpacked data for a given data field\&. " .ti -1c .RI "\fBg2int\fP \fBg2_gribend\fP (unsigned char *)" .br .RI "This routine finalizes a GRIB2 message after all grids and fields have been added\&. " .ti -1c .RI "\fBg2int\fP \fBg2_info\fP (unsigned char *, \fBg2int\fP *, \fBg2int\fP *, \fBg2int\fP *, \fBg2int\fP *)" .br .RI "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\&. " .ti -1c .RI "\fBg2int\fP \fBg2_unpack1\fP (unsigned char *, \fBg2int\fP *, \fBg2int\fP **, \fBg2int\fP *)" .br .RI "This subroutine unpacks Section 1 (Identification Section) as defined in GRIB Edition 2\&. " .ti -1c .RI "\fBg2int\fP \fBg2_unpack3\fP (unsigned char *, \fBg2int\fP *, \fBg2int\fP **, \fBg2int\fP **, \fBg2int\fP *, \fBg2int\fP **, \fBg2int\fP *)" .br .RI "This routine unpacks Section 3 (Grid Definition Section) as defined in GRIB Edition 2\&. " .ti -1c .RI "\fBg2int\fP \fBg2_unpack4\fP (unsigned char *, \fBg2int\fP *, \fBg2int\fP *, \fBg2int\fP **, \fBg2int\fP *, \fBg2float\fP **, \fBg2int\fP *)" .br .RI "This subroutine unpacks Section 4 (Product Definition Section) as defined in GRIB Edition 2\&. " .ti -1c .RI "\fBg2int\fP \fBg2_unpack5\fP (unsigned char *, \fBg2int\fP *, \fBg2int\fP *, \fBg2int\fP *, \fBg2int\fP **, \fBg2int\fP *)" .br .RI "This subroutine unpacks Section 5 (Data Representation Section) as defined in GRIB Edition 2\&. " .ti -1c .RI "\fBg2int\fP \fBg2_unpack6\fP (unsigned char *, \fBg2int\fP *, \fBg2int\fP, \fBg2int\fP *, \fBg2int\fP **)" .br .RI "This subroutine unpacks Section 6 (Bit-Map Section) as defined in GRIB Edition 2\&. " .ti -1c .RI "\fBg2int\fP \fBg2_unpack7\fP (unsigned char *, \fBg2int\fP *, \fBg2int\fP, \fBg2int\fP *, \fBg2int\fP, \fBg2int\fP *, \fBg2int\fP, \fBg2float\fP **)" .br .RI "This subroutine unpacks Section 7 (Data Section) as defined in GRIB Edition 2\&. " .ti -1c .RI "void \fBgbit\fP (unsigned char *, \fBg2int\fP *, \fBg2int\fP, \fBg2int\fP)" .br .RI "Get bits - unpack bits: Extract arbitrary size values from a packed bit string, right justifying each value in the unpacked iout array\&. " .ti -1c .RI "void \fBgbits\fP (unsigned char *, \fBg2int\fP *, \fBg2int\fP, \fBg2int\fP, \fBg2int\fP, \fBg2int\fP)" .br .RI "Get bits - unpack bits: Extract arbitrary size values from a packed bit string, right justifying each value in the unpacked iout array\&. " .ti -1c .RI "\fBgtemplate\fP * \fBgetdrstemplate\fP (\fBg2int\fP)" .br .RI "This subroutine returns DRS template information for a specified Data Representation Template 5\&.NN\&. " .ti -1c .RI "\fBgtemplate\fP * \fBgetgridtemplate\fP (\fBg2int\fP)" .br .RI "This subroutine returns grid template information for a specified Grid Definition Template 3\&.NN\&. " .ti -1c .RI "\fBgtemplate\fP * \fBgetpdstemplate\fP (\fBg2int\fP)" .br .RI "This subroutine returns PDS template information for a specified Product Definition Template 4\&.NN\&. " .ti -1c .RI "double \fBint_power\fP (double, \fBg2int\fP)" .br .RI "Function similar to C pow() power function\&. " .ti -1c .RI "void \fBmisspack\fP (\fBg2float\fP *, \fBg2int\fP, \fBg2int\fP, \fBg2int\fP *, unsigned char *, \fBg2int\fP *)" .br .RI "This subroutine packs up a data field using a complex packing algorithm as defined in the GRIB2 documention\&. " .ti -1c .RI "void \fBmkieee\fP (\fBg2float\fP *, \fBg2int\fP *, \fBg2int\fP)" .br .RI "This subroutine stores a list of real values in 32-bit IEEE floating point format\&. " .ti -1c .RI "int \fBpack_gp\fP (\fBg2int\fP *, \fBg2int\fP *, \fBg2int\fP *, \fBg2int\fP *, \fBg2int\fP *, \fBg2int\fP *, \fBg2int\fP *, \fBg2int\fP *, \fBg2int\fP *, \fBg2int\fP *, \fBg2int\fP *, \fBg2int\fP *, \fBg2int\fP *, \fBg2int\fP *, \fBg2int\fP *, \fBg2int\fP *, \fBg2int\fP *, \fBg2int\fP *, \fBg2int\fP *, \fBg2int\fP *)" .br .RI "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)\&. " .ti -1c .RI "void \fBrdieee\fP (\fBg2int\fP *, \fBg2float\fP *, \fBg2int\fP)" .br .RI "This subroutine reads a list of real values in 32-bit IEEE floating point format\&. " .ti -1c .RI "void \fBsbit\fP (unsigned char *, \fBg2int\fP *, \fBg2int\fP, \fBg2int\fP)" .br .RI "Store bits - put arbitrary size values into a packed bit string, taking the low order bits from each value in the unpacked array\&. " .ti -1c .RI "void \fBsbits\fP (unsigned char *, \fBg2int\fP *, \fBg2int\fP, \fBg2int\fP, \fBg2int\fP, \fBg2int\fP)" .br .RI "Store bits - put arbitrary size values into a packed bit string, taking the low order bits from each value in the unpacked array\&. " .ti -1c .RI "void \fBseekgb\fP (FILE *, \fBg2int\fP, \fBg2int\fP, \fBg2int\fP *, \fBg2int\fP *)" .br .RI "This subprogram searches a file for the next GRIB Message\&. " .ti -1c .RI "void \fBsimpack\fP (\fBg2float\fP *, \fBg2int\fP, \fBg2int\fP *, unsigned char *, \fBg2int\fP *)" .br .RI "This subroutine packs up a data field using the simple packing algorithm as defined in the GRIB2 documention\&. " .in -1c .SH "Detailed Description" .PP Header file for NCEPLIBS-g2c library\&. PROGRAM HISTORY LOG: .IP "\(bu" 2 2002-10-25 Gilbert .IP "\(bu" 2 2009-01-14 Vuong Changed struct template to gtemplate .PP Each element of structure gribfield is defined as: .PP .nf gribfield gfld; gfld->version = GRIB edition number ( currently 2 ) gfld->discipline = Message Discipline ( see Code Table 0\&.0 ) gfld->idsect = Contains the entries in the Identification Section ( Section 1 ) This element is a pointer to an array that holds the data\&. gfld->idsect[0] = Identification of originating Centre ( see Common Code Table C-1 ) 7 - US National Weather Service gfld->idsect[1] = Identification of originating Sub-centre gfld->idsect[2] = GRIB Master Tables Version Number ( see Code Table 1\&.0 ) 0 - Experimental 1 - Initial operational version number gfld->idsect[3] = GRIB Local Tables Version Number ( see Code Table 1\&.1 ) 0 - Local tables not used 1-254 - Number of local tables version used gfld->idsect[4] = Significance of Reference Time (Code Table 1\&.2) 0 - Analysis 1 - Start of forecast 2 - Verifying time of forecast 3 - Observation time gfld->idsect[5] = Year ( 4 digits ) gfld->idsect[6] = Month gfld->idsect[7) = Day gfld->idsect[8] = Hour gfld->idsect[9] = Minute gfld->idsect[10] = Second gfld->idsect[11] = Production status of processed data ( see Code Table 1\&.3 ) 0 - Operational products 1 - Operational test products 2 - Research products 3 - Re-analysis products gfld->idsect[12] = Type of processed data ( see Code Table 1\&.4 ) 0 - Analysis products 1 - Forecast products 2 - Analysis and forecast products 3 - Control forecast products 4 - Perturbed forecast products 5 - Control and perturbed forecast products 6 - Processed satellite observations 7 - Processed radar observations gfld->idsectlen = Number of elements in gfld->idsect[]\&. gfld->local = Pointer to character array containing contents of Local Section 2, if included gfld->locallen = length of array gfld->local[] gfld->ifldnum = field number within GRIB message gfld->griddef = Source of grid definition (see Code Table 3\&.0) 0 - Specified in Code table 3\&.1 1 - Predetermined grid Defined by originating centre gfld->ngrdpts = Number of grid points in the defined grid\&. gfld->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\&. gfld->interp_opt = Interpretation of list for optional points definition\&. (Code Table 3\&.11) gfld->igdtnum = Grid Definition Template Number (Code Table 3\&.1) gfld->igdtmpl = Contains the data values for the specified Grid Definition Template ( NN=gfld->igdtnum )\&. Each element of this integer array contains an entry (in the order specified) of Grid Defintion Template 3\&.NN This element is a pointer to an array that holds the data\&. gfld->igdtlen = Number of elements in gfld->igdtmpl[]\&. i\&.e\&. number of entries in Grid Defintion Template 3\&.NN ( NN=gfld->igdtnum )\&. gfld->list_opt = (Used if gfld->numoct_opt \&.ne\&. 0) This array contains the number of grid points contained in each row ( or column )\&. (part of Section 3) This element is a pointer to an array that holds the data\&. This pointer is nullified if gfld->numoct_opt=0\&. gfld->num_opt = (Used if gfld->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 gfld->numoct_opt=0\&. gfdl->ipdtnum = Product Definition Template Number (see Code Table 4\&.0) gfld->ipdtmpl = Contains the data values for the specified Product Definition Template ( N=gfdl->ipdtnum )\&. Each element of this integer array contains an entry (in the order specified) of Product Defintion Template 4\&.N\&. This element is a pointer to an array that holds the data\&. gfld->ipdtlen = Number of elements in gfld->ipdtmpl[]\&. i\&.e\&. number of entries in Product Defintion Template 4\&.N ( N=gfdl->ipdtnum )\&. gfld->coord_list = Real array containing floating point values intended to document the vertical discretisation associated to model data on hybrid coordinate vertical levels\&. (part of Section 4) This element is a pointer to an array that holds the data\&. gfld->num_coord = number of values in array gfld->coord_list[]\&. gfld->ndpts = Number of data points unpacked and returned\&. gfld->idrtnum = Data Representation Template Number ( see Code Table 5\&.0) gfld->idrtmpl = Contains the data values for the specified Data Representation Template ( N=gfld->idrtnum )\&. Each element of this integer array contains an entry (in the order specified) of Product Defintion Template 5\&.N\&. This element is a pointer to an array that holds the data\&. gfld->idrtlen = Number of elements in gfld->idrtmpl[]\&. i\&.e\&. number of entries in Data Representation Template 5\&.N ( N=gfld->idrtnum )\&. gfld->unpacked = logical value indicating whether the bitmap and data values were unpacked\&. If false, gfld->bmap and gfld->fld pointers are nullified\&. gfld->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 gfld->fld match the grid points and zeros were inserted at grid points where data was bit-mapped out\&. If false, the data values in gfld->fld were not expanded to the grid and are just a consecutive array of data points corresponding to each value of '1' in gfld->bmap\&. gfld->ibmap = Bitmap indicator ( see Code Table 6\&.0 ) 0 = bitmap applies and is included in Section 6\&. 1-253 = Predefined bitmap applies 254 = Previously defined bitmap applies to this field 255 = Bit map does not apply to this product\&. gfld->bmap = integer array containing decoded bitmap, if gfld->ibmap=0 or gfld->ibap=254\&. Otherwise nullified\&. This element is a pointer to an array that holds the data\&. gfld->fld = Array of gfld->ndpts unpacked data points\&. This element is a pointer to an array that holds the data\&. .fi .PP .PP .PP \fBAuthor\fP .RS 4 Stephen Gilbert .RE .PP \fBDate\fP .RS 4 2002-10-25 .RE .PP .PP Definition in file \fBgrib2\&.h\fP\&. .SH "Data Type Documentation" .PP .SH "struct gribfield" .PP Struct for GRIB field\&. .PP Definition at line 186 of file grib2\&.h\&. .PP \fBData Fields:\fP .RS 4 \fBg2int\fP * \fIbmap\fP .br .PP \fBg2float\fP * \fIcoord_list\fP .br .PP \fBg2int\fP \fIdiscipline\fP .br .PP \fBg2int\fP \fIexpanded\fP .br .PP \fBg2float\fP * \fIfld\fP .br .PP \fBg2int\fP \fIgriddef\fP .br .PP \fBg2int\fP \fIibmap\fP .br .PP \fBg2int\fP \fIidrtlen\fP .br .PP \fBg2int\fP * \fIidrtmpl\fP .br .PP \fBg2int\fP \fIidrtnum\fP .br .PP \fBg2int\fP * \fIidsect\fP .br .PP \fBg2int\fP \fIidsectlen\fP .br .PP \fBg2int\fP \fIifldnum\fP .br .PP \fBg2int\fP \fIigdtlen\fP .br .PP \fBg2int\fP * \fIigdtmpl\fP .br .PP \fBg2int\fP \fIigdtnum\fP .br .PP \fBg2int\fP \fIinterp_opt\fP .br .PP \fBg2int\fP \fIipdtlen\fP .br .PP \fBg2int\fP * \fIipdtmpl\fP .br .PP \fBg2int\fP \fIipdtnum\fP .br .PP \fBg2int\fP * \fIlist_opt\fP .br .PP unsigned char * \fIlocal\fP .br .PP \fBg2int\fP \fIlocallen\fP .br .PP \fBg2int\fP \fIndpts\fP .br .PP \fBg2int\fP \fIngrdpts\fP .br .PP \fBg2int\fP \fInum_coord\fP .br .PP \fBg2int\fP \fInum_opt\fP .br .PP \fBg2int\fP \fInumoct_opt\fP .br .PP \fBg2int\fP \fIunpacked\fP .br .PP \fBg2int\fP \fIversion\fP .br .PP .RE .PP .SH "struct gtemplate" .PP Struct for GRIB template\&. .PP Definition at line 165 of file grib2\&.h\&. .PP \fBData Fields:\fP .RS 4 \fBg2int\fP * \fIext\fP num of octets of each entry in the extension .br part of the template\&. .br .br .PP \fBg2int\fP \fIextlen\fP number of entries in the template extension\&. .br .br .PP \fBg2int\fP * \fImap\fP num of octets of each entry in the .br static part of the template\&. .br .br .PP \fBg2int\fP \fImaplen\fP number of entries in the static part .br of the template\&. .br .br .PP \fBg2int\fP \fIneedext\fP indicates whether or not the template needs .br to be extended\&. .br .br .PP \fBg2int\fP \fInum\fP template number\&. .br .br .PP \fBg2int\fP \fItype\fP 3=Grid Defintion Template\&. 4=Product Defintion Template\&. 5=Data Representation Template\&. .br .PP .RE .PP .SH "Macro Definition Documentation" .PP .SS "#define G2_VERSION 'g2clib\-1\&.6\&.4'" .PP Current version of NCEPLIBS-g2c library\&. .PP Definition at line 156 of file grib2\&.h\&. .SH "Typedef Documentation" .PP .SS "typedef float \fBg2float\fP" .PP Float type\&. .PP Definition at line 160 of file grib2\&.h\&. .SS "typedef int64_t \fBg2int\fP" .PP Long integer type\&. .PP Definition at line 158 of file grib2\&.h\&. .SS "typedef uint64_t \fBg2intu\fP" .PP Unsigned long integer type\&. .PP Definition at line 159 of file grib2\&.h\&. .SS "typedef struct \fBgribfield\fP \fBgribfield\fP" .PP Struct for GRIB field\&. .PP Definition at line 160 of file grib2\&.h\&. .SS "typedef struct \fBgtemplate\fP \fBgtemplate\fP" .PP Struct for GRIB template\&. .PP Definition at line 160 of file grib2\&.h\&. .SH "Function Documentation" .PP .SS "void compack (\fBg2float\fP * fld, \fBg2int\fP ndpts, \fBg2int\fP idrsnum, \fBg2int\fP * idrstmpl, unsigned char * cpack, \fBg2int\fP * lcpack)" .PP 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 5\&.3 with the appropriate values\&. .PP \fBParameters\fP .RS 4 \fIfld\fP Contains the data values to pack .br \fIndpts\fP The number of data values in array fld .br \fIidrsnum\fP Data Representation Template number 5\&.N Must equal 2 or 3\&. .br \fIidrstmpl\fP Contains the array of values for Data Representation Template 5\&.2 or 5\&.3\&. .RE .PP .IP "\(bu" 2 0 Reference value - ignored on input, set my \fBcompack()\fP\&. .IP "\(bu" 2 1 Binary Scale Factor .IP "\(bu" 2 2 Decimal Scale Factor .IP "\(bu" 2 6 Missing value management .IP "\(bu" 2 7 Primary missing value .IP "\(bu" 2 8 Secondary missing value .IP "\(bu" 2 16 Order of Spatial Differencing ( 1 or 2 ) .PP \fBParameters\fP .RS 4 \fIcpack\fP The packed data field .br \fIlcpack\fP length of packed field cpack\&. .RE .PP \fBAuthor\fP .RS 4 Stephen Gilbert .RE .PP \fBDate\fP .RS 4 2002-11-07 .RE .PP .PP .PP Definition at line 39 of file compack\&.c\&. .PP References int_power(), mkieee(), pack_gp(), sbit(), and sbits()\&. .PP Referenced by cmplxpack()\&. .SS "\fBgtemplate\fP* extdrstemplate (\fBg2int\fP number, \fBg2int\fP * list)" .PP 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\&. .PP PROGRAM HISTORY LOG: .IP "\(bu" 2 2000-05-11 Gilbert .IP "\(bu" 2 2009-01-14 Vuong Changed structure name template to gtemplate .PP .PP \fBParameters\fP .RS 4 \fInumber\fP NN, indicating the number of the Data Representation Template 5\&.NN that is being requested\&. .br \fIlist\fP The list of values for each entry in the the Data Representation Template 5\&.NN\&. .RE .PP \fBReturns\fP .RS 4 Pointer to the returned template struct\&. Returns NULL pointer, if template not found\&. .RE .PP \fBAuthor\fP .RS 4 Stephen Gilbert .RE .PP \fBDate\fP .RS 4 2000-05-11 .RE .PP .PP Definition at line 104 of file drstemplates\&.c\&. .PP References getdrsindex(), and getdrstemplate()\&. .PP Referenced by g2_unpack5()\&. .SS "\fBgtemplate\fP* extgridtemplate (\fBg2int\fP number, \fBg2int\fP * list)" .PP 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\&. .PP PROGRAM HISTORY LOG: .IP "\(bu" 2 2000-05-09 Gilbert .IP "\(bu" 2 2008-07-08 Vuong Added GDT 3\&.32768 Rotate Lat/Lon E-grid (Arakawa) .IP "\(bu" 2 2009-01-14 Vuong Changed structure name template to gtemplate .IP "\(bu" 2 2010-05-11 Vuong Added GDT 3\&.32769 Rotate Lat/Lon Non-E Staggered grid (Arakawa) .IP "\(bu" 2 2013-08-06 Vuong Added GDT 3\&.4,3\&.5,3\&.12,3\&.101,3\&.140 .PP .PP \fBParameters\fP .RS 4 \fInumber\fP NN, indicating the number of the Grid Definition Template 3\&.NN that is being requested\&. .br \fIlist\fP The list of values for each entry in the Grid Definition Template\&. .RE .PP \fBReturns\fP .RS 4 Pointer to the returned template struct\&. Returns NULL pointer, if template not found\&. .RE .PP \fBAuthor\fP .RS 4 Stephen Gilbert .RE .PP \fBDate\fP .RS 4 2000-05-09 .RE .PP .PP Definition at line 119 of file gridtemplates\&.c\&. .PP References getgridindex(), and getgridtemplate()\&. .PP Referenced by g2_addgrid(), and g2_unpack3()\&. .SS "\fBgtemplate\fP* extpdstemplate (\fBg2int\fP number, \fBg2int\fP * list)" .PP 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\&. .PP \fBParameters\fP .RS 4 \fInumber\fP NN, indicating the number of the Product Definition Template 4\&.NN that is being requested\&. .br \fIlist\fP The list of values for each entry in the the Product Definition Template 4\&.NN\&. .RE .PP \fBReturns\fP .RS 4 Pointer to the returned template struct\&. Returns NULL pointer, if template not found\&. .RE .PP \fBAuthor\fP .RS 4 Stephen Gilbert .RE .PP \fBDate\fP .RS 4 2000-05-11 .RE .PP .PP Definition at line 108 of file pdstemplates\&.c\&. .PP References getpdsindex(), and getpdstemplate()\&. .PP Referenced by g2_addfield(), and g2_unpack4()\&. .SS "\fBg2int\fP g2_addfield (unsigned char * cgrib, \fBg2int\fP ipdsnum, \fBg2int\fP * ipdstmpl, \fBg2float\fP * coordlist, \fBg2int\fP numcoord, \fBg2int\fP idrsnum, \fBg2int\fP * idrstmpl, \fBg2float\fP * fld, \fBg2int\fP ngrdpts, \fBg2int\fP ibmap, \fBg2int\fP * bmap)" .PP 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\&. .PP This routine is used with routines \fBg2_create()\fP, \fBg2_addlocal()\fP, \fBg2_addgrid()\fP, and \fBg2_gribend()\fP to create a complete GRIB2 message\&. \fBg2_create()\fP must be called first to initialize a new GRIB2 message\&. Also, routine \fBg2_addgrid()\fP must be called after \fBg2_create()\fP and before this routine to add the appropriate grid description to the GRIB2 message\&. Also, a call to \fBg2_gribend()\fP is required to complete GRIB2 message after all fields have been added\&. .PP PROGRAM HISTORY LOG: .IP "\(bu" 2 2002-11-05 Gilbert .IP "\(bu" 2 2002-12-23 Gilbert - Added complex spherical harmonic packing .IP "\(bu" 2 2003-08-27 Gilbert - Added support for new templates using PNG and JPEG2000 algorithms/templates\&. .IP "\(bu" 2 2004-11-29 Gilbert - JPEG2000 now allowed to use WMO Template no\&. 5\&.40 PNG now allowed to use WMO Template no\&. 5\&.41 .IP " \(bu" 4 Added check to determine if packing algorithm failed\&. .PP .IP "\(bu" 2 2005-05-10 Gilbert - Imposed minimum size on cpack, used to hold encoded bit string\&. .IP "\(bu" 2 2009-01-14 Vuong Changed structure name template to gtemplate .PP .PP \fBParameters\fP .RS 4 \fIcgrib\fP 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\&. .br \fIipdsnum\fP Product Definition Template Number (see Code Table 4\&.0)\&. .br \fIipdstmpl\fP Contains the data values for the specified Product Definition Template (N=ipdsnum)\&. Each element of this integer array contains an entry (in the order specified) of Product Defintion Template 4\&.N\&. .br \fIcoordlist\fP Array containg floating point values intended to document the vertical discretisation associated to model data on hybrid coordinate vertical levels\&. .br \fInumcoord\fP number of values in array coordlist\&. .br \fIidrsnum\fP Data Representation Template Number (see Code Table 5\&.0)\&. .br \fIidrstmpl\fP Contains 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\&. 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\&. .br \fIfld\fP Array of data points to pack\&. .br \fIngrdpts-\fP Number of data points in grid\&. i\&.e\&. size of fld and bmap\&. .br \fIibmap\fP - Bitmap indicator (see Code Table 6\&.0) .IP "\(bu" 2 0 = bitmap applies and is included in Section 6\&. .IP "\(bu" 2 1-253 = Predefined bitmap applies\&. .IP "\(bu" 2 254 = Previously defined bitmap applies to this field\&. .IP "\(bu" 2 255 = Bit map does not apply to this product\&. .PP .br \fIbmap\fP Integer array containing bitmap to be added\&. (if ibmap=0)\&. .RE .PP \fBReturns\fP .RS 4 .IP "\(bu" 2 > 0 Current size of updated GRIB2 message .IP "\(bu" 2 -1 GRIB message was not initialized\&. Need to call routine \fBg2_create()\fP first\&. .IP "\(bu" 2 -2 GRIB message already complete\&. Cannot add new section\&. .IP "\(bu" 2 -3 Sum of Section byte counts doesn't add to total byte count\&. .IP "\(bu" 2 -4 Previous Section was not 3 or 7\&. .IP "\(bu" 2 -5 Could not find requested Product Definition Template\&. .IP "\(bu" 2 -6 Section 3 (GDS) not previously defined in message\&. .IP "\(bu" 2 -7 Tried to use unsupported Data Representationi Template\&. .IP "\(bu" 2 -8 Specified use of a previously defined bitmap, but one does not exist in the GRIB message\&. .IP "\(bu" 2 -9 GDT of one of 5\&.50 through 5\&.53 required to pack field using DRT 5\&.51\&. .IP "\(bu" 2 -10 Error packing data field\&. .PP .RE .PP \fBNote\fP .RS 4 Note that the Sections 4 through 7 can only follow Section 3 or Section 7 in a GRIB2 message\&. .RE .PP \fBAuthor\fP .RS 4 Stephen Gilbert .RE .PP \fBDate\fP .RS 4 2002-11-05 .RE .PP .PP Definition at line 103 of file g2_addfield\&.c\&. .PP 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()\&. .SS "\fBg2int\fP g2_addgrid (unsigned char * cgrib, \fBg2int\fP * igds, \fBg2int\fP * igdstmpl, \fBg2int\fP * ideflist, \fBg2int\fP idefnum)" .PP This routine packs up a Grid Definition Section (Section 3) and adds it to a GRIB2 message\&. It is used with routines \fBg2_create()\fP, \fBg2_addlocal()\fP, \fBg2_addfield()\fP, and \fBg2_gribend()\fP to create a complete GRIB2 message\&. \fBg2_create()\fP must be called first to initialize a new GRIB2 message\&. .PP \fBParameters\fP .RS 4 \fIcgrib\fP Char array that contains the GRIB2 message to which section should be added\&. Must be allocated large enough to store the entire GRIB2 message\&. .br \fIigds\fP Contains information needed for GRIB Grid Definition Section 3\&. Must be dimensioned >= 5\&. .IP "\(bu" 2 igds[0] Source of grid definition (see Code Table 3\&.0) .IP "\(bu" 2 igds[1] Number of grid points in the defined grid\&. .IP "\(bu" 2 igds[2] 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\&. .IP "\(bu" 2 igds[3] Interpretation of list for optional points definition\&. (Code Table 3\&.11) .IP "\(bu" 2 igds[4] Grid Definition Template Number (Code Table 3\&.1) .PP .br \fIigdstmpl\fP Contains the data values for the specified Grid Definition Template (NN=igds[4])\&. Each element of this integer array contains an entry (in the order specified) of Grid Defintion Template 3\&.NN .br \fIideflist\fP (Used if igds[2] != 0) This array contains the number of grid points contained in each row (or column)\&. .br \fIidefnum\fP (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\&. .RE .PP \fBReturns\fP .RS 4 .IP "\(bu" 2 > 0 Current size of updated GRIB2 message .IP "\(bu" 2 -1 GRIB message was not initialized\&. Need to call routine gribcreate first\&. .IP "\(bu" 2 -2 GRIB message already complete\&. Cannot add new section\&. .IP "\(bu" 2 -3 Sum of Section byte counts doesn't add to total byte count .IP "\(bu" 2 -4 Previous Section was not 1, 2 or 7\&. .IP "\(bu" 2 -5 Could not find requested Grid Definition Template\&. .PP .RE .PP \fBNote\fP .RS 4 The Grid Def Section ( Section 3 ) can only follow Section 1, 2 or Section 7 in a GRIB2 message\&. .RE .PP PROGRAM HISTORY LOG .IP "\(bu" 2 2002-11-01 Gilbert .IP "\(bu" 2 2009-01-14 Vuong Changed structure name template to gtemplate .PP .PP \fBAuthor\fP .RS 4 Stephen Gilbeert .RE .PP \fBDate\fP .RS 4 2002-11-01 .RE .PP .PP Definition at line 60 of file g2_addgrid\&.c\&. .PP References gtemplate::ext, extgridtemplate(), gtemplate::extlen, gbit(), getgridtemplate(), gtemplate::map, gtemplate::maplen, gtemplate::needext, sbit(), and sbits()\&. .SS "\fBg2int\fP g2_addlocal (unsigned char * cgrib, unsigned char * csec2, \fBg2int\fP lcsec2)" .PP This routine adds a Local Use Section (Section 2) to a GRIB2 message\&. It is used with routines \fBg2_create()\fP, \fBg2_addgrid()\fP, \fBg2_addfield()\fP, and \fBg2_gribend()\fP to create a complete GRIB2 message\&. \fBg2_create()\fP must be called first to initialize a new GRIB2 message\&. .PP \fBParameters\fP .RS 4 \fIcgrib\fP 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\&. .br \fIcsec2\fP Character array containing information to be added in Section 2\&. .br \fIlcsec2\fP Number of bytes of character array csec2 to be added to Section 2\&. .RE .PP \fBReturns\fP .RS 4 > 0 = Current size of updated GRIB2 message\&. .IP "\(bu" 2 -1 GRIB message was not initialized\&. Need to call routine gribcreate first\&. .IP "\(bu" 2 -2 GRIB message already complete\&. Cannot add new section\&. .IP "\(bu" 2 -3 Sum of Section byte counts doesn't add to total byte count .IP "\(bu" 2 -4 Previous Section was not 1 or 7\&. .PP .RE .PP \fBNote\fP .RS 4 The Local Use Section (Section 2) can only follow Section 1 or Section 7 in a GRIB2 message\&. .RE .PP \fBAuthor\fP .RS 4 Stephen Gilbeert .RE .PP \fBDate\fP .RS 4 2002-11-01 .RE .PP .PP Definition at line 37 of file g2_addlocal\&.c\&. .PP References gbit(), and sbit()\&. .SS "\fBg2int\fP g2_create (unsigned char * cgrib, \fBg2int\fP * listsec0, \fBg2int\fP * listsec1)" .PP This routine initializes a new GRIB2 message and packs GRIB2 sections 0 (Indicator Section) and 1 (Identification Section)\&. This routine is used with routines \fBg2_addlocal()\fP, \fBg2_addgrid()\fP, \fBg2_addfield()\fP, and \fBg2_gribend()\fP to create a complete GRIB2 message\&. \fBg2_create()\fP must be called first to initialize a new GRIB2 message\&. Also, a call to \fBg2_gribend()\fP is required to complete GRIB2 message after all fields have been added\&. .PP \fBParameters\fP .RS 4 \fIcgrib\fP Character array to contain the GRIB2 message\&. Must be allocated large enough to store the entire GRIB2 message\&. .br \fIlistsec0\fP Contains information needed for GRIB Indicator Section 0\&. Must be dimensioned >= 2\&. .IP "\(bu" 2 listsec0[0]=Discipline-GRIB Master Table Number (see Code Table 0\&.0) .IP "\(bu" 2 listsec0[1]=GRIB Edition Number (currently 2) .PP .br \fIlistsec1\fP Contains information needed for GRIB Identification Section 1\&. Must be dimensioned >= 13\&. .IP "\(bu" 2 listsec1[0] Id of orginating centre (Common Code Table C-1) .IP "\(bu" 2 listsec1[1] Id of orginating sub-centre (local table) .IP "\(bu" 2 listsec1[2] GRIB Master Tables Version Number (Code Table 1\&.0) .IP "\(bu" 2 listsec1[3] GRIB Local Tables Version Number (Code Table 1\&.1) .IP "\(bu" 2 listsec1[4] Significance of Reference Time (Code Table 1\&.2) .IP "\(bu" 2 listsec1[5] Reference Time - Year (4 digits) .IP "\(bu" 2 listsec1[6] Reference Time - Month .IP "\(bu" 2 listsec1[7] Reference Time - Day .IP "\(bu" 2 listsec1[8] Reference Time - Hour .IP "\(bu" 2 listsec1[9] Reference Time - Minute .IP "\(bu" 2 listsec1[10] Reference Time - Second .IP "\(bu" 2 listsec1[11] Production status of data (Code Table 1\&.3) .IP "\(bu" 2 listsec1[12] Type of processed data (Code Table 1\&.4) .PP .RE .PP \fBReturns\fP .RS 4 - > 0 Current size of new GRIB2 message .IP "\(bu" 2 -1 Tried to use for version other than GRIB Edition 2 .PP .RE .PP This routine is intended for use with routines \fBg2_addlocal()\fP, \fBg2_addgrid()\fP, \fBg2_addfield()\fP, and \fBg2_gribend()\fP to create a complete GRIB2 message\&. .PP \fBAuthor\fP .RS 4 Stephen Gilbeert .RE .PP \fBDate\fP .RS 4 2002-10-31 .RE .PP .PP Definition at line 52 of file g2_create\&.c\&. .PP References MAPSEC1LEN, and sbit()\&. .SS "void g2_free (\fBgribfield\fP * gfld)" .PP This routine frees up memory that was allocated for struct gribfield\&. .PP \fBParameters\fP .RS 4 \fIgfld\fP pointer to gribfield structure (defined in include file \fBgrib2\&.h\fP) returned from routine \fBg2_getfld()\fP\&. .RE .PP \fBNote\fP .RS 4 This routine must be called to free up memory used by the decode routine, \fBg2_getfld()\fP, when user no longer needs to reference this data\&. .RE .PP \fBAuthor\fP .RS 4 Stephen Gilbeert .RE .PP \fBDate\fP .RS 4 2002-10-28 .RE .PP .PP Definition at line 24 of file g2_free\&.c\&. .SS "\fBg2int\fP g2_getfld (unsigned char * cgrib, \fBg2int\fP ifldnum, \fBg2int\fP unpack, \fBg2int\fP expand, \fBgribfield\fP ** gfld)" .PP 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 \fBgrib2\&.h\fP\&. Users of this routine will need to include \fBgrib2\&.h\fP in their source code that calls this routine\&. .PP 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\&. .PP PROGRAM HISTORY LOG: .IP "\(bu" 2 2002-10-28 Gilbert .IP "\(bu" 2 2013-08-08 Vuong Free up memory in array igds - free(igds) .PP .PP \fBParameters\fP .RS 4 \fIcgrib\fP Character pointer to the GRIB2 message\&. .br \fIifldnum\fP Specifies which field in the GRIB2 message to return\&. .br \fIunpack\fP Boolean value indicating whether to unpack bitmap/data field\&. .IP "\(bu" 2 1 unpack bitmap (if present) and data values\&. .IP "\(bu" 2 0 do not unpack bitmap and data values\&. .PP .br \fIexpand\fP 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\&. .IP "\(bu" 2 1 if possible, expand data field to grid, inserting zero values at gridpoints that are bitmapped out\&. (SEE REMARKS2) .IP "\(bu" 2 0 do not expand data field, leaving it an array of consecutive data points for each '1' in the bitmap\&. .PP .br \fIgfld\fP pointer to structure gribfield containing all decoded data for the data field\&. .RE .PP .PP .nf gfld->version = GRIB edition number ( currently 2 ) gfld->discipline = Message Discipline ( see Code Table 0\&.0 ) gfld->idsect = Contains the entries in the Identification Section ( Section 1 ) This element is a pointer to an array that holds the data\&. gfld->idsect[0] = Identification of originating Centre ( see Common Code Table C-1 ) 7 - US National Weather Service gfld->idsect[1] = Identification of originating Sub-centre gfld->idsect[2] = GRIB Master Tables Version Number ( see Code Table 1\&.0 ) 0 - Experimental 1 - Initial operational version number gfld->idsect[3] = GRIB Local Tables Version Number ( see Code Table 1\&.1 ) 0 - Local tables not used 1-254 - Number of local tables version used gfld->idsect[4] = Significance of Reference Time (Code Table 1\&.2) 0 - Analysis 1 - Start of forecast 2 - Verifying time of forecast 3 - Observation time gfld->idsect[5] = Year ( 4 digits ) gfld->idsect[6] = Month gfld->idsect[7) = Day gfld->idsect[8] = Hour gfld->idsect[9] = Minute gfld->idsect[10] = Second gfld->idsect[11] = Production status of processed data ( see Code Table 1\&.3 ) 0 - Operational products 1 - Operational test products 2 - Research products 3 - Re-analysis products gfld->idsect[12] = Type of processed data ( see Code Table 1\&.4 ) 0 - Analysis products 1 - Forecast products 2 - Analysis and forecast products 3 - Control forecast products 4 - Perturbed forecast products 5 - Control and perturbed forecast products 6 - Processed satellite observations 7 - Processed radar observations gfld->idsectlen = Number of elements in gfld->idsect[]\&. gfld->local = Pointer to character array containing contents of Local Section 2, if included gfld->locallen = length of array gfld->local[] gfld->ifldnum = field number within GRIB message gfld->griddef = Source of grid definition (see Code Table 3\&.0) 0 - Specified in Code table 3\&.1 1 - Predetermined grid Defined by originating centre gfld->ngrdpts = Number of grid points in the defined grid\&. gfld->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\&. gfld->interp_opt = Interpretation of list for optional points definition\&. (Code Table 3\&.11) gfld->igdtnum = Grid Definition Template Number (Code Table 3\&.1) gfld->igdtmpl = Contains the data values for the specified Grid Definition Template ( NN=gfld->igdtnum )\&. Each element of this integer array contains an entry (in the order specified) of Grid Defintion Template 3\&.NN This element is a pointer to an array that holds the data\&. gfld->igdtlen = Number of elements in gfld->igdtmpl[]\&. i\&.e\&. number of entries in Grid Defintion Template 3\&.NN ( NN=gfld->igdtnum )\&. gfld->list_opt = (Used if gfld->numoct_opt \&.ne\&. 0) This array contains the number of grid points contained in each row ( or column )\&. (part of Section 3) This element is a pointer to an array that holds the data\&. This pointer is nullified if gfld->numoct_opt=0\&. gfld->num_opt = (Used if gfld->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 gfld->numoct_opt=0\&. gfdl->ipdtnum = Product Definition Template Number(see Code Table 4\&.0) gfld->ipdtmpl = Contains the data values for the specified Product Definition Template ( N=gfdl->ipdtnum )\&. Each element of this integer array contains an entry (in the order specified) of Product Defintion Template 4\&.N\&. This element is a pointer to an array that holds the data\&. gfld->ipdtlen = Number of elements in gfld->ipdtmpl[]\&. i\&.e\&. number of entries in Product Defintion Template 4\&.N ( N=gfdl->ipdtnum )\&. gfld->coord_list = Real array containing floating point values intended to document the vertical discretisation associated to model data on hybrid coordinate vertical levels\&. (part of Section 4) This element is a pointer to an array that holds the data\&. gfld->num_coord = number of values in array gfld->coord_list[]\&. gfld->ndpts = Number of data points unpacked and returned\&. gfld->idrtnum = Data Representation Template Number ( see Code Table 5\&.0) gfld->idrtmpl = Contains the data values for the specified Data Representation Template ( N=gfld->idrtnum )\&. Each element of this integer array contains an entry (in the order specified) of Product Defintion Template 5\&.N\&. This element is a pointer to an array that holds the data\&. gfld->idrtlen = Number of elements in gfld->idrtmpl[]\&. i\&.e\&. number of entries in Data Representation Template 5\&.N ( N=gfld->idrtnum )\&. gfld->unpacked = logical value indicating whether the bitmap and data values were unpacked\&. If false, gfld->bmap and gfld->fld pointers are nullified\&. gfld->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 gfld->fld match the grid points and zeros were inserted at grid points where data was bit-mapped out\&. If false, the data values in gfld->fld were not expanded to the grid and are just a consecutive array of data points corresponding to each value of '1' in gfld->bmap\&. gfld->ibmap = Bitmap indicator ( see Code Table 6\&.0 ) 0 = bitmap applies and is included in Section 6\&. 1-253 = Predefined bitmap applies 254 = Previously defined bitmap applies to this field 255 = Bit map does not apply to this product\&. gfld->bmap = integer array containing decoded bitmap, if gfld->ibmap=0 or gfld->ibap=254\&. Otherwise nullified This element is a pointer to an array that holds the data\&. gfld->fld = Array of gfld->ndpts unpacked data points\&. This element is a pointer to an array that holds the data\&. .fi .PP .PP \fBReturns\fP .RS 4 .IP "\(bu" 2 0 no error .IP "\(bu" 2 1 Beginning characters 'GRIB' not found\&. .IP "\(bu" 2 2 GRIB message is not Edition 2\&. .IP "\(bu" 2 3 The data field request number was not positive\&. .IP "\(bu" 2 4 End string '7777' found, but not where expected\&. .IP "\(bu" 2 6 GRIB message did not contain the requested number of data fields\&. .IP "\(bu" 2 7 End string '7777' not found at end of message\&. .IP "\(bu" 2 8 Unrecognized Section encountered\&. .IP "\(bu" 2 9 Data Representation Template 5\&.NN not yet implemented\&. .IP "\(bu" 2 15 Error unpacking Section 1\&. .IP "\(bu" 2 16 Error unpacking Section 2\&. .IP "\(bu" 2 10 Error unpacking Section 3\&. .IP "\(bu" 2 11 Error unpacking Section 4\&. .IP "\(bu" 2 12 Error unpacking Section 5\&. .IP "\(bu" 2 13 Error unpacking Section 6\&. .IP "\(bu" 2 14 Error unpacking Section 7\&. .IP "\(bu" 2 17 Previous bitmap specified, yet none exists\&. .PP .RE .PP \fBNote\fP .RS 4 Struct gribfield is allocated by this routine and it also contains pointers to many arrays of data that were allocated during decoding\&. Users are encouraged to free up this memory, when it is no longer needed, by an explicit call to routine g2_free\&. .PP .nf EXAMPLE: .fi .PP .PP .nf #include "grib2\&.h" gribfield *gfld; ret=g2_getfld(cgrib,1,1,1,&gfld); \&.\&.\&. g2_free(gfld); .fi .PP .RE .PP Routine g2_info can be used to first determine how many data fields exist in a given GRIB message\&. .PP \fBNote\fP .RS 4 It may not always be possible to expand a bit-mapped data field\&. If a pre-defined bit-map is used and not included in the GRIB2 message itself, this routine would not have the necessary information to expand the data\&. In this case, gfld->expanded would would be set to 0 (false), regardless of the value of input argument expand\&. .RE .PP \fBAuthor\fP .RS 4 Stephen Gilbert .RE .PP \fBDate\fP .RS 4 2002-10-28 .RE .PP .PP Definition at line 237 of file g2_getfld\&.c\&. .PP References g2_unpack1(), g2_unpack2(), g2_unpack3(), g2_unpack4(), g2_unpack5(), g2_unpack6(), g2_unpack7(), and gbit()\&. .SS "\fBg2int\fP g2_gribend (unsigned char * cgrib)" .PP 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 \fBg2_create()\fP, \fBg2_addlocal()\fP, \fBg2_addgrid()\fP, and \fBg2_addfield()\fP to create a complete GRIB2 message\&. \fBg2_create()\fP must be called first to initialize a new GRIB2 message\&. .PP \fBParameters\fP .RS 4 \fIcgrib\fP 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\&. .RE .PP \fBReturns\fP .RS 4 .IP "\(bu" 2 > 0 = Length of the final GRIB2 message in bytes\&. .IP "\(bu" 2 -1 = GRIB message was not initialized\&. Need to call routine g2_create first\&. .IP "\(bu" 2 -2 = GRIB message already complete\&. .IP "\(bu" 2 -3 = Sum of Section byte counts doesn't add to total byte count .IP "\(bu" 2 -4 = Previous Section was not 7\&. .PP .RE .PP \fBNote\fP .RS 4 This routine is intended for use with routines \fBg2_create()\fP, \fBg2_addlocal()\fP, \fBg2_addgrid()\fP, and \fBg2_addfield()\fP to create a complete GRIB2 message\&. .RE .PP \fBAuthor\fP .RS 4 Stephen Gilbert .RE .PP \fBDate\fP .RS 4 2002-10-31 .RE .PP .PP Definition at line 36 of file g2_gribend\&.c\&. .PP References gbit(), and sbit()\&. .SS "\fBg2int\fP g2_info (unsigned char * cgrib, \fBg2int\fP * listsec0, \fBg2int\fP * listsec1, \fBg2int\fP * numfields, \fBg2int\fP * numlocal)" .PP 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\&. .PP \fBParameters\fP .RS 4 \fIcgrib\fP Character pointer to the GRIB2 message\&. .br \fIlistsec0\fP pointer to an array containing information decoded from GRIB Indicator Section 0\&. Must be allocated with >= 3 elements\&. .IP "\(bu" 2 listsec0[0] Discipline-GRIB Master Table Number (see Code Table 0\&.0)\&. .IP "\(bu" 2 listsec0[1] GRIB Edition Number (currently 2)\&. .IP "\(bu" 2 listsec0[2] Length of GRIB message\&. .PP .br \fIlistsec1\fP Pointer to an array containing information read from GRIB Identification Section 1\&. Must be allocated with >= 13 elements\&. .IP "\(bu" 2 listsec1[0] Id of orginating centre (Common Code Table C-1) .IP "\(bu" 2 listsec1[1] Id of orginating sub-centre (local table) .IP "\(bu" 2 listsec1[2] GRIB Master Tables Version Number (Code Table 1\&.0) .IP "\(bu" 2 listsec1[3] GRIB Local Tables Version Number .IP "\(bu" 2 listsec1[4] Significance of Reference Time (Code Table 1\&.1) .IP "\(bu" 2 listsec1[5] Reference Time - Year (4 digits) .IP "\(bu" 2 listsec1[6] Reference Time - Month .IP "\(bu" 2 listsec1[7] Reference Time - Day .IP "\(bu" 2 listsec1[8] Reference Time - Hour .IP "\(bu" 2 listsec1[9] Reference Time - Minute .IP "\(bu" 2 listsec1[10] Reference Time - Second .IP "\(bu" 2 listsec1[11] Production status of data (Code Table 1\&.2) .IP "\(bu" 2 listsec1[12] Type of processed data (Code Table 1\&.3) .PP .br \fInumfields\fP The number of gridded fields found in the GRIB message\&. That is, the number of occurences of Sections 4 - 7\&. .br \fInumlocal\fP The number of Local Use Sections ( Section 2 ) found in the GRIB message\&. .RE .PP \fBReturns\fP .RS 4 0 foe success, otherwise: .IP "\(bu" 2 1 Beginning characters 'GRIB' not found\&. .IP "\(bu" 2 2 GRIB message is not Edition 2\&. .IP "\(bu" 2 3 Could not find Section 1, where expected\&. .IP "\(bu" 2 4 End string '7777' found, but not where expected\&. .IP "\(bu" 2 5 End string '7777' not found at end of message\&. .IP "\(bu" 2 6 Invalid section number found\&. .PP .RE .PP \fBAuthor\fP .RS 4 Stephen Gilbeert .RE .PP \fBDate\fP .RS 4 2002-10-28 .RE .PP .PP Definition at line 59 of file g2_info\&.c\&. .PP References gbit()\&. .SS "\fBg2int\fP g2_unpack1 (unsigned char * cgrib, \fBg2int\fP * iofst, \fBg2int\fP ** ids, \fBg2int\fP * idslen)" .PP This subroutine unpacks Section 1 (Identification Section) as defined in GRIB Edition 2\&. .PP \fBParameters\fP .RS 4 \fIcgrib\fP char array containing Section 1 of the GRIB2 message\&. .br \fIiofst\fP Bit offset for the beginning of Section 1 in cgrib\&. .br \fIids\fP address of pointer to integer array containing information read from Section 1, the Identification section\&. .IP "\(bu" 2 ids[0] Identification of originating Centre (see Common Code Table C-1)\&. .IP "\(bu" 2 ids[1] Identification of originating Sub-centre\&. .IP "\(bu" 2 ids[2] GRIB Master Tables Version Number (see Code Table 1\&.0)\&. .IP "\(bu" 2 ids[3] GRIB Local Tables Version Number (see Code Table 1\&.1)\&. .IP "\(bu" 2 ids[4] Significance of Reference Time (Code Table 1\&.2) .IP "\(bu" 2 ids[5] Year ( 4 digits ) .IP "\(bu" 2 ids[6] Month .IP "\(bu" 2 ids[7] Day .IP "\(bu" 2 ids[8] Hour .IP "\(bu" 2 ids[9] Minute .IP "\(bu" 2 ids[10] Second .IP "\(bu" 2 ids[11] Production status of processed data (see Code Table 1\&.3)\&. .IP "\(bu" 2 ids[12] Type of processed data (see Code Table 1\&.4)\&. .PP .br \fIidslen\fP Number of elements in ids\&. .RE .PP \fBReturns\fP .RS 4 .IP "\(bu" 2 0 no error .IP "\(bu" 2 2 Array passed is not section 1 .IP "\(bu" 2 6 memory allocation error .PP .RE .PP \fBAuthor\fP .RS 4 Stephen Gilbert .RE .PP \fBDate\fP .RS 4 2002-10-29 .RE .PP .PP Definition at line 44 of file g2_unpack1\&.c\&. .SS "\fBg2int\fP g2_unpack3 (unsigned char * cgrib, \fBg2int\fP * iofst, \fBg2int\fP ** igds, \fBg2int\fP ** igdstmpl, \fBg2int\fP * mapgridlen, \fBg2int\fP ** ideflist, \fBg2int\fP * idefnum)" .PP This routine unpacks Section 3 (Grid Definition Section) as defined in GRIB Edition 2\&. PROGRAM HISTORY LOG: .IP "\(bu" 2 2002-10-31 Gilbert .IP "\(bu" 2 2009-01-14 Vuong Changed structure name template to gtemplate .PP .PP \fBParameters\fP .RS 4 \fIcgrib\fP Char array ontaining Section 3 of the GRIB2 message\&. .br \fIiofst\fP Bit offset for the beginning of Section 3 in cgrib\&. .br \fIigds\fP Contains information read from the appropriate GRIB Grid Definition Section 3 for the field being returned\&. .IP "\(bu" 2 igds[0] Source of grid definition (see Code Table 3\&.0) .IP "\(bu" 2 igds[1] Number of grid points in the defined grid\&. .IP "\(bu" 2 igds[2] 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\&. .IP "\(bu" 2 igds[3] Interpretation of list for optional points definition\&. (Code Table 3\&.11) .IP "\(bu" 2 igds[4] Grid Definition Template Number (Code Table 3\&.1)\&. .PP .br \fIigdstmpl\fP - Pointer to integer array containing the data values for the specified Grid Definition Template (NN=igds[4])\&. Each element of this integer array contains an entry (in the order specified) of Grid Defintion Template 3\&.NN .br \fImapgridlen-\fP Number of elements in igdstmpl[]\&. i\&.e\&. number of entries in Grid Defintion Template 3\&.NN (NN=igds[4])\&. .br \fIideflist\fP (Used if igds[2] \&.ne\&. 0) Pointer to integer array containing the number of grid points contained in each row ( or column )\&. (part of Section 3)\&. .br \fIidefnum\fP (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\&. .RE .PP \fBReturns\fP .RS 4 .IP "\(bu" 2 0 no error .IP "\(bu" 2 2 Not Section 3 .IP "\(bu" 2 5 'GRIB' message contains an undefined Grid Definition Template\&. .IP "\(bu" 2 6 memory allocation error .PP .RE .PP \fBAuthor\fP .RS 4 Stephen Gilbert .RE .PP \fBDate\fP .RS 4 2002-10-31 .RE .PP .PP Definition at line 53 of file g2_unpack3\&.c\&. .SS "\fBg2int\fP g2_unpack4 (unsigned char * cgrib, \fBg2int\fP * iofst, \fBg2int\fP * ipdsnum, \fBg2int\fP ** ipdstmpl, \fBg2int\fP * mappdslen, \fBg2float\fP ** coordlist, \fBg2int\fP * numcoord)" .PP This subroutine unpacks Section 4 (Product Definition Section) as defined in GRIB Edition 2\&. PROGRAM HISTORY LOG: .IP "\(bu" 2 2002-10-31 Gilbert .IP "\(bu" 2 2009-01-14 Vuong Changed structure name template to gtemplate .PP .PP \fBParameters\fP .RS 4 \fIcgrib\fP Char array containing Section 4 of the GRIB2 message\&. .br \fIiofst\fP Bit offset of the beginning of Section 4 in cgrib\&. Returned with updated bit offset\&. .br \fIipdsnum\fP Product Definition Template Number (see Code Table 4\&.0)\&. .br \fIipdstmpl\fP Pointer to integer array containing the data values for the specified Product Definition Template (N=ipdsnum)\&. Each element of this integer array contains an entry (in the order specified) of Product Defintion Template 4\&.N\&. .br \fImappdslen\fP Number of elements in ipdstmpl\&. i\&.e\&. number of entries in Product Defintion Template 4\&.N (N=ipdsnum)\&. .br \fIcoordlist\fP Pointer to real array containing floating point values intended to document the vertical discretisation associated to model data on hybrid coordinate vertical levels\&. (part of Section 4)\&. .br \fInumcoord\fP number of values in array coordlist\&. .RE .PP \fBReturns\fP .RS 4 .IP "\(bu" 2 0 no error .IP "\(bu" 2 2 Not section 4 .IP "\(bu" 2 5 'GRIB' message contains an undefined Product Definition Template\&. .IP "\(bu" 2 6 memory allocation error .PP .RE .PP \fBAuthor\fP .RS 4 Stephen Gilbert .RE .PP \fBDate\fP .RS 4 2002-10-31 .RE .PP .PP Definition at line 42 of file g2_unpack4\&.c\&. .SS "\fBg2int\fP g2_unpack5 (unsigned char * cgrib, \fBg2int\fP * iofst, \fBg2int\fP * ndpts, \fBg2int\fP * idrsnum, \fBg2int\fP ** idrstmpl, \fBg2int\fP * mapdrslen)" .PP This subroutine unpacks Section 5 (Data Representation Section) as defined in GRIB Edition 2\&. PROGRAM HISTORY LOG: .IP "\(bu" 2 2002-10-31 Gilbert .IP "\(bu" 2 2009-01-14 Vuong Changed structure name template to gtemplate .PP .PP \fBParameters\fP .RS 4 \fIcgrib\fP char array containing Section 5 of the GRIB2 message\&. .br \fIiofst\fP Bit offset for the beginning of Section 5 in cgrib\&. Returned with bit offset at the end of Section 5\&. .br \fIndpts\fP Number of data points unpacked and returned\&. .br \fIidrsnum\fP Data Representation Template Number (see Code Table 5\&.0)\&. .br \fIidrstmpl\fP 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\&. .br \fImapdrslen-\fP Number of elements in idrstmpl\&. i\&.e\&. number of entries in Data Representation Template 5\&.N (N=idrsnum)\&. .RE .PP \fBReturns\fP .RS 4 .IP "\(bu" 2 0 no error .IP "\(bu" 2 2 Not Section 5 .IP "\(bu" 2 6 memory allocation error .IP "\(bu" 2 7 'GRIB' message contains an undefined Data Representation Template\&. .PP .RE .PP \fBAuthor\fP .RS 4 Stephen Gilbert .RE .PP \fBDate\fP .RS 4 2002-10-31 .RE .PP .PP Definition at line 40 of file g2_unpack5\&.c\&. .SS "\fBg2int\fP g2_unpack6 (unsigned char * cgrib, \fBg2int\fP * iofst, \fBg2int\fP ngpts, \fBg2int\fP * ibmap, \fBg2int\fP ** bmap)" .PP This subroutine unpacks Section 6 (Bit-Map Section) as defined in GRIB Edition 2\&. .PP \fBParameters\fP .RS 4 \fIcgrib\fP char array containing Section 6 of the GRIB2 message\&. .br \fIiofst\fP Bit offset of the beginning of Section 6 in cgrib\&. .br \fIngpts\fP Number of grid points specified in the bit-map .br \fIibmap\fP Bitmap indicator (see Code Table 6\&.0) .IP "\(bu" 2 0 bitmap applies and is included in Section 6\&. .IP "\(bu" 2 1-253 Predefined bitmap applies .IP "\(bu" 2 254 Previously defined bitmap applies to this field .IP "\(bu" 2 255 Bit map does not apply to this product\&. .PP .br \fIbmap\fP Pointer to an integer array containing decoded bitmap\&. (if ibmap=0) .RE .PP \fBReturns\fP .RS 4 .IP "\(bu" 2 0 no error .IP "\(bu" 2 2 Not Section 6 .IP "\(bu" 2 4 Unrecognized pre-defined bit-map\&. .IP "\(bu" 2 6 memory allocation error .PP .RE .PP \fBAuthor\fP .RS 4 Stephen Gilbert .RE .PP \fBDate\fP .RS 4 2002-10-31 .RE .PP .PP Definition at line 33 of file g2_unpack6\&.c\&. .SS "\fBg2int\fP g2_unpack7 (unsigned char * cgrib, \fBg2int\fP * iofst, \fBg2int\fP igdsnum, \fBg2int\fP * igdstmpl, \fBg2int\fP idrsnum, \fBg2int\fP * idrstmpl, \fBg2int\fP ndpts, \fBg2float\fP ** fld)" .PP This subroutine unpacks Section 7 (Data Section) as defined in GRIB Edition 2\&. PROGRAM HISTORY LOG: .IP "\(bu" 2 2002-10-31 Gilbert .IP "\(bu" 2 2002-12-20 Gilbert - Added GDT info to arguments and added 5\&.51 processing\&. .IP "\(bu" 2 2003-08-29 Gilbert - Added support for new templates using PNG and JPEG2000 algorithms/templates\&. .IP "\(bu" 2 2004-11-29 Gilbert - JPEG2000 now allowed to use WMO Template no\&. 5\&.40 PNG now allowed to use WMO Template no\&. 5\&.41 .IP "\(bu" 2 2004-12-16 Taylor - Added check on comunpack return code\&. .IP "\(bu" 2 2008-12-23 Wesley - Initialize Number of data points unpacked .PP .PP \fBParameters\fP .RS 4 \fIcgrib\fP char array containing Section 7 of the GRIB2 message .br \fIiofst\fP Bit offset of the beginning of Section 7 in cgrib\&. .br \fIigdsnum\fP Grid Definition Template Number (see Code Table 3\&.0) (Only used for DRS Template 5\&.51) .br \fIigdstmpl\fP 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)\&. .br \fIidrsnum\fP Data Representation Template Number (see Code Table 5\&.0) .br \fIidrstmpl\fP 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 .br \fIndpts\fP Number of data points unpacked and returned\&. .br \fIfld\fP Pointer to a float array containing the unpacked data field\&. .RE .PP \fBReturns\fP .RS 4 .IP "\(bu" 2 0 no error .IP "\(bu" 2 2 Not section 7 .IP "\(bu" 2 4 Unrecognized Data Representation Template .IP "\(bu" 2 5 need one of GDT 3\&.50 through 3\&.53 to decode DRT 5\&.51 .IP "\(bu" 2 6 memory allocation error .IP "\(bu" 2 7 corrupt section 7\&. .PP .RE .PP \fBAuthor\fP .RS 4 Stephen Gilbert .RE .PP \fBDate\fP .RS 4 2002-10-31 .RE .PP .PP Definition at line 66 of file g2_unpack7\&.c\&. .SS "void gbit (unsigned char * in, \fBg2int\fP * iout, \fBg2int\fP iskip, \fBg2int\fP nbyte)" .PP Get bits - unpack bits: Extract arbitrary size values from a packed bit string, right justifying each value in the unpacked iout array\&. .PP \fBParameters\fP .RS 4 \fIin\fP pointer to character array input\&. .br \fIiout\fP pointer to unpacked array output\&. .br \fIiskip\fP initial number of bits to skip\&. .br \fInbyte\fP number of bits to take\&. .RE .PP \fBAuthor\fP .RS 4 NOAA Programmer .RE .PP .PP Definition at line 20 of file gbits\&.c\&. .PP References gbits()\&. .PP 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()\&. .SS "void gbits (unsigned char * in, \fBg2int\fP * iout, \fBg2int\fP iskip, \fBg2int\fP nbyte, \fBg2int\fP nskip, \fBg2int\fP n)" .PP Get bits - unpack bits: Extract arbitrary size values from a packed bit string, right justifying each value in the unpacked iout array\&. .PP \fBParameters\fP .RS 4 \fIin\fP pointer to character array input\&. .br \fIiout\fP pointer to unpacked array output\&. .br \fIiskip\fP initial number of bits to skip\&. .br \fInbyte\fP number of bits to take\&. .br \fInskip\fP additional number of bits to skip on each iteration\&. .br \fIn\fP number of iterations\&. .RE .PP \fBAuthor\fP .RS 4 NOAA Programmer .RE .PP .PP Definition at line 57 of file gbits\&.c\&. .PP Referenced by comunpack(), g2_unpack3(), g2_unpack4(), g2_unpack6(), gbit(), pngunpack(), simunpack(), and specunpack()\&. .SS "\fBgtemplate\fP* getdrstemplate (\fBg2int\fP number)" .PP This subroutine returns DRS template information for a specified Data Representation Template 5\&.NN\&. 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\&. .PP PROGRAM HISTORY LOG: .IP "\(bu" 2 2000-05-11 Gilbert .IP "\(bu" 2 2009-01-14 Vuong Changed structure name template to gtemplate .PP .PP \fBParameters\fP .RS 4 \fInumber\fP NN, indicating the number of the Data Representation Template 5\&.NN that is being requested\&. .RE .PP \fBReturns\fP .RS 4 Pointer to the returned template struct\&. Returns NULL pointer, if template not found\&. .RE .PP \fBAuthor\fP .RS 4 Stephen Gilbert .RE .PP \fBDate\fP .RS 4 2000-05-11 .RE .PP .PP Definition at line 57 of file drstemplates\&.c\&. .PP References getdrsindex(), drstemplate::mapdrslen, drstemplate::needext, drstemplate::template_num, and templatesdrs\&. .PP Referenced by extdrstemplate(), g2_addfield(), and g2_unpack5()\&. .SS "\fBgtemplate\fP* getgridtemplate (\fBg2int\fP number)" .PP This subroutine returns grid template information for a specified Grid Definition Template 3\&.NN\&. 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\&. .PP PROGRAM HISTORY LOG: .IP "\(bu" 2 2000-05-09 Gilbert .IP "\(bu" 2 2007-08-16 Vuong - Added GDT 3\&.204 Curvilinear Orthogonal Grid .IP "\(bu" 2 2008-07-08 Vuong - Added GDT 3\&.32768 Rotate Lat/Lon E-grid (Arakawa) .IP "\(bu" 2 2010-05-11 Vuong - Added GDT 3\&.32769 Rotate Lat/Lon Non-E Staggered grid (Arakawa) .IP "\(bu" 2 2009-01-14 Vuong - Changed structure name template to gtemplate .PP .PP \fBParameters\fP .RS 4 \fInumber\fP NN, indicating the number of the Grid Definition Template 3\&.NN that is being requested\&. .RE .PP \fBReturns\fP .RS 4 Pointer to the returned template struct\&. Returns NULL pointer, if template not found\&. .RE .PP \fBAuthor\fP .RS 4 Stephen Gilbert .RE .PP \fBDate\fP .RS 4 2000-05-09 .RE .PP .PP Definition at line 68 of file gridtemplates\&.c\&. .PP References getgridindex(), and templatesgrid\&. .PP Referenced by extgridtemplate(), g2_addgrid(), and g2_unpack3()\&. .SS "\fBgtemplate\fP* getpdstemplate (\fBg2int\fP number)" .PP This subroutine returns PDS template information for a specified Product Definition Template 4\&.NN\&. 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\&. .PP \fBParameters\fP .RS 4 \fInumber\fP NN, indicating the number of the Product Definition Template 4\&.NN that is being requested\&. .RE .PP \fBReturns\fP .RS 4 Pointer to the returned template struct\&. Returns NULL pointer, if template not found\&. .RE .PP \fBAuthor\fP .RS 4 Stephen Gilbert .RE .PP \fBDate\fP .RS 4 2000-05-11 .RE .PP .PP Definition at line 65 of file pdstemplates\&.c\&. .PP References getpdsindex(), and templatespds\&. .PP Referenced by extpdstemplate(), g2_addfield(), and g2_unpack4()\&. .SS "double int_power (double x, \fBg2int\fP y)" .PP Function similar to C pow() power function\&. .PP \fBParameters\fP .RS 4 \fIx\fP The base value whose power is to be calculated\&. .br \fIy\fP The power value\&. .RE .PP \fBReturns\fP .RS 4 x**y .RE .PP \fBAuthor\fP .RS 4 Wesley Ebisuzaki .RE .PP .PP Definition at line 17 of file int_power\&.c\&. .PP Referenced by compack(), comunpack(), jpcpack(), jpcunpack(), misspack(), mkieee(), pngpack(), pngunpack(), rdieee(), simpack(), simunpack(), specpack(), and specunpack()\&. .SS "void misspack (\fBg2float\fP * fld, \fBg2int\fP ndpts, \fBg2int\fP idrsnum, \fBg2int\fP * idrstmpl, unsigned char * cpack, \fBg2int\fP * lcpack)" .PP 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 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\&. .PP \fBParameters\fP .RS 4 \fIfld\fP Contains the data values to pack .br \fIndpts\fP The number of data values in array fld .br \fIidrsnum\fP Data Representation Template number 5\&.N Must equal 2 or 3\&. .br \fIidrstmpl\fP Contains the array of values for Data Representation Template 5\&.2 or 5\&.3\&. .IP "\(bu" 2 0 Reference value - ignored on input, set by misspack routine\&. .IP "\(bu" 2 1 Binary Scale Factor - used on input\&. .IP "\(bu" 2 2 Decimal Scale Factor- used on input\&. .IP "\(bu" 2 6 Missing value management\&. .IP "\(bu" 2 7 Primary missing value\&. .IP "\(bu" 2 8 Secondary missing value\&. .IP "\(bu" 2 16 Order of Spatial Differencing (1 or 2)\&. .PP .br \fIcpack\fP The packed data field (character*1 array)\&. .br \fIlcpack\fP length of packed field cpack\&. .RE .PP \fBAuthor\fP .RS 4 Stephen Gilbert .RE .PP \fBDate\fP .RS 4 2000-06-21 .RE .PP .PP Definition at line 38 of file misspack\&.c\&. .PP References int_power(), mkieee(), pack_gp(), rdieee(), sbit(), and sbits()\&. .PP Referenced by cmplxpack()\&. .SS "void mkieee (\fBg2float\fP * a, \fBg2int\fP * rieee, \fBg2int\fP num)" .PP This subroutine stores a list of real values in 32-bit IEEE floating point format\&. .PP \fBParameters\fP .RS 4 \fIa\fP Input array of floating point values\&. .br \fInum\fP Number of floating point values to convert\&. .br \fIrieee\fP 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\&. .RE .PP \fBAuthor\fP .RS 4 Stephen Gilbert .RE .PP \fBDate\fP .RS 4 2002-10-29 .RE .PP .PP Definition at line 21 of file mkieee\&.c\&. .PP References int_power()\&. .PP Referenced by compack(), g2_addfield(), jpcpack(), misspack(), pngpack(), simpack(), and specpack()\&. .SS "int pack_gp (\fBinteger\fP * kfildo, \fBinteger\fP * ic, \fBinteger\fP * nxy, \fBinteger\fP * is523, \fBinteger\fP * minpk, \fBinteger\fP * inc, \fBinteger\fP * missp, \fBinteger\fP * misss, \fBinteger\fP * jmin, \fBinteger\fP * jmax, \fBinteger\fP * lbit, \fBinteger\fP * nov, \fBinteger\fP * ndg, \fBinteger\fP * lx, \fBinteger\fP * ibit, \fBinteger\fP * jbit, \fBinteger\fP * kbit, \fBinteger\fP * novref, \fBinteger\fP * lbitref, \fBinteger\fP * ier)" .PP 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\&. .PP 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\&. .PP PROGRAM HISTORY LOG: .IP "\(bu" 2 February 1994 Glahn tdl mos-2000 .IP "\(bu" 2 June 1995 Glahn modified for lmiss error\&. .IP "\(bu" 2 July 1996 Glahn added misss .IP "\(bu" 2 February 1997 Glahn removed 4 redundant tests for missp\&.eq\&.0; inserted a test to better handle a string of 9999's .IP "\(bu" 2 February 1997 Glahn added loops to eliminate test for misss when misss = 0 .IP "\(bu" 2 March 1997 Glahn corrected for secondary missing value .IP "\(bu" 2 March 1997 Glahn corrected for use of local value of minpk .IP "\(bu" 2 March 1997 Glahn corrected for secondary missing value .IP "\(bu" 2 March 1997 Glahn changed calculating number of bits through exponents to an array (improved overall packing performance by about 35 percent!)\&. allowed 0 bits for packing jmin( ), lbit( ), and nov( )\&. .IP "\(bu" 2 May 1997 Glahn a number of changes for efficiency\&. mod functions eliminated and one ifthen added\&. jount removed\&. recomputation of bits not made unless necessary after moving points from one group to another\&. nendb adjusted to eliminate possibility of very small group at the end\&. about 8 percent improvement in overall packing\&. iskipa removed; there is always a group b that can become group a\&. control on size of group b (statement below 150) added\&. added adda, and use of ge and le instead of gt and lt in loops between 150 and 160\&. ibitbs added to shorten trips through loop\&. .IP "\(bu" 2 March 2000 Glahn modified for grib2; changed name from packgp .IP "\(bu" 2 january 2001 Glahn comments; ier = 706 substituted for stops; added return1; removed statement number 110; added ier and * return .IP "\(bu" 2 November 2001 Glahn changed some diagnostic formats to allow printing larger numbers .IP "\(bu" 2 November 2001 Glahn added misslx( ) to put maximum value into jmin( ) when all values missing to agree with grib standard\&. .IP "\(bu" 2 November 2001 Glahn changed two tests on missp and misss eq 0 to tests on is523\&. however, missp and misss cannot in general be = 0\&. .IP "\(bu" 2 November 2001 Glahn added call to reduce; defined itest before loops to reduce computation; started large group when all same value .IP "\(bu" 2 December 2001 Glahn modified and added a few comments .IP "\(bu" 2 January 2002 Glahn removed loop before 150 to determine a group of all same value .IP "\(bu" 2 January 2002 Glahn changed mallow from 9999999 to 2**30+1, and made it a parameter .IP "\(bu" 2 March 2002 Glahn added non fatal ier = 716, 717; removed nendb=nxy above 150; added iersav=0; comments .PP .PP DATA SET USE .IP "\(bu" 2 kfildo - unit number for output (print) file\&. (output) .PP .PP \fBParameters\fP .RS 4 \fIkfildo\fP unit number for output (print) file\&. (input) .br \fIic\fP 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) .br \fInxy\fP number of values in ic( )\&. also treated as its dimension\&. (input) .br \fIis523\fP missing value management 0=data contains no missing values 1=data contains primary missing values 2=data contains primary and secondary missing values (input) .br \fIminpk\fP the minimum size of each group, except possibly the last one\&. (input) .br \fIinc\fP 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) .br \fImissp\fP 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) .br \fImisss\fP secondary missing value indicator (see missp)\&. (input) .br \fIjmin\fP the minimum of each group (j=1,lx)\&. (output) .br \fIjmax\fP 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) .br \fIlbit\fP 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) .br \fInov\fP the number of values in each group (j=1,lx)\&. (output) .br \fIndg\fP the dimension of jmin, jmax, lbit, and nov\&. (input) .br \fIlx\fP the number of groups determined\&. (output) .br \fIibit\fP the number of bits necessary to pack the jmin(j) values, j=1,lx\&. (output) .br \fIjbit\fP the number of bits necessary to pack the lbit(j) values, j=1,lx\&. (output) .br \fIkbit\fP the number of bits necessary to pack the nov(j) values, j=1,lx\&. (output) .br \fInovref\fP reference value for nov( )\&. (output) .br \fIlbitref\fP reference value for lbit( )\&. (output) .br \fIier\fP Error code .IP "\(bu" 2 0 No error\&. .IP "\(bu" 2 706 value will not pack in 30 bits--fatal .IP "\(bu" 2 714 error in reduce--non-fatal .IP "\(bu" 2 715 ngp not large enough in reduce--non-fatal .IP "\(bu" 2 716 minpk inceased--non-fatal .IP "\(bu" 2 717 inc set .IP "\(bu" 2 1--non-fatal .IP "\(bu" 2 alternate return when ier ne 0 and fatal error\&. .PP .RE .PP \fBReturns\fP .RS 4 0 - check ier for error code\&. .PP .nf INTERNAL VARIABLES .fi .PP .PP .nf 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( )\&. .fi .PP .RE .PP .PP Definition at line 256 of file pack_gp\&.c\&. .PP References FALSE_, reduce(), and TRUE_\&. .PP Referenced by compack(), and misspack()\&. .SS "void rdieee (\fBg2int\fP * rieee, \fBg2float\fP * a, \fBg2int\fP num)" .PP This subroutine reads a list of real values in 32-bit IEEE floating point format\&. .PP \fBParameters\fP .RS 4 \fIrieee\fP g2int array of floating point values in 32-bit IEEE format\&. .br \fInum\fP Number of floating point values to convert\&. .br \fIa\fP float array of real values\&. a must be allocated with at least 4*num bytes of memory before calling this function\&. .RE .PP \fBAuthor\fP .RS 4 Stephen Gilbert .RE .PP \fBDate\fP .RS 4 2002-10-25 .RE .PP .PP Definition at line 20 of file rdieee\&.c\&. .PP References int_power()\&. .PP Referenced by comunpack(), g2_miss(), g2_unpack4(), g2_unpack7(), jpcunpack(), misspack(), pngunpack(), simunpack(), and specunpack()\&. .SS "void sbit (unsigned char * out, \fBg2int\fP * in, \fBg2int\fP iskip, \fBg2int\fP nbyte)" .PP Store bits - put arbitrary size values into a packed bit string, taking the low order bits from each value in the unpacked array\&. .PP \fBParameters\fP .RS 4 \fIout\fP pointer to packed array output\&. Must be allocated large enough to hold output\&. .br \fIin\fP pointer to unpacked array input\&. .br \fIiskip\fP initial number of bits to skip\&. .br \fInbyte\fP number of bits to pack\&. .RE .PP \fBAuthor\fP .RS 4 NOAA Programmer .RE .PP .PP Definition at line 38 of file gbits\&.c\&. .PP References sbits()\&. .PP Referenced by compack(), g2_addfield(), g2_addgrid(), g2_addlocal(), g2_create(), g2_gribend(), misspack(), and simpack()\&. .SS "void sbits (unsigned char * out, \fBg2int\fP * in, \fBg2int\fP iskip, \fBg2int\fP nbyte, \fBg2int\fP nskip, \fBg2int\fP n)" .PP Store bits - put arbitrary size values into a packed bit string, taking the low order bits from each value in the unpacked array\&. .PP \fBParameters\fP .RS 4 \fIout\fP pointer to packed array output\&. Must be allocated large enough to hold output\&. .br \fIin\fP pointer to unpacked array input\&. .br \fIiskip\fP initial number of bits to skip\&. .br \fInbyte\fP number of bits to pack\&. .br \fInskip\fP additional number of bits to skip on each iteration\&. .br \fIn\fP number of iterations\&. .RE .PP \fBAuthor\fP .RS 4 NOAA Programmer .RE .PP .PP Definition at line 110 of file gbits\&.c\&. .PP Referenced by compack(), g2_addfield(), g2_addgrid(), jpcpack(), misspack(), pngpack(), sbit(), and simpack()\&. .SS "void seekgb (FILE * lugb, \fBg2int\fP iseek, \fBg2int\fP mseek, \fBg2int\fP * lskip, \fBg2int\fP * lgrib)" .PP 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\&. .PP PROGRAM HISTORY LOG: .IP "\(bu" 2 2002-10-28 GILBERT Modified from Iredell's skgb subroutine .IP "\(bu" 2 2009-01-16 VUONG Changed lskip to 4 instead of sizof(g2int) .PP .PP \fBParameters\fP .RS 4 \fIlugb\fP FILE pointer for the file to search\&. File must be opened before this routine is called\&. .br \fIiseek\fP number of bytes in the file to skip before search\&. .br \fImseek\fP number of bytes to search at a time\&. .br \fIlskip\fP number of bytes to skip from the beggining of the file to where the GRIB message starts\&. .br \fIlgrib\fP number of bytes in message (set to 0, if no message found)\&. .RE .PP \fBAuthor\fP .RS 4 Stephen Gilbert .RE .PP \fBDate\fP .RS 4 2002-10-28 .RE .PP .PP Definition at line 32 of file seekgb\&.c\&. .PP References gbit()\&. .SS "void simpack (\fBg2float\fP * fld, \fBg2int\fP ndpts, \fBg2int\fP * idrstmpl, unsigned char * cpack, \fBg2int\fP * lcpack)" .PP 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\&. .PP \fBParameters\fP .RS 4 \fIfld\fP Contains the data values to pack\&. .br \fIndpts\fP The number of data values in array fld\&. .br \fIidrstmpl\fP Contains the array of values for Data Representation Template 5\&.0\&. .IP "\(bu" 2 0 Reference value - ignored on input - set by simpack routine\&. .IP "\(bu" 2 1 Binary Scale Factor - unchanged from input\&. .IP "\(bu" 2 2 Decimal Scale Factor - unchanged from input\&. .IP "\(bu" 2 3 Number of bits used to pack data, if value is > 0 and <= 31\&. If this input value is 0 or outside above range then the num of bits is calculated based on given data and scale factors\&. .IP "\(bu" 2 4 Original field type - currently ignored on input\&. Data values assumed to be reals\&. Set to 0 by simpack routine\&. .PP .br \fIcpack\fP The packed data field .br \fIlcpack\fP length of packed field starting at cpack\&. .RE .PP \fBAuthor\fP .RS 4 Stephen Gilbert .RE .PP \fBDate\fP .RS 4 2002-11-06 .RE .PP .PP Definition at line 32 of file simpack\&.c\&. .SH "Author" .PP Generated automatically by Doxygen for NCEPLIBS-g2c from the source code\&.