.TH "g2_addfield.c" 3 "Tue May 3 2022" "Version 1.6.4" "NCEPLIBS-g2c" \" -*- nroff -*- .ad l .nh .SH NAME g2_addfield.c \- Pack up Sections 4 through 7 for a given field and adds them to a GRIB2 message\&. .SH SYNOPSIS .br .PP \fC#include \fP .br \fC#include \fP .br \fC#include 'grib2\&.h'\fP .br .SS "Functions" .in +1c .ti -1c .RI "void \fBcmplxpack\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 "\fBg2int\fP \fBg2_addfield\fP (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)" .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 \fBgetdim\fP (unsigned char *, \fBg2int\fP *, \fBg2int\fP *, \fBg2int\fP *)" .br .RI "This subroutine returns the dimensions and scanning mode of a grid definition packed in GRIB2 Grid Definition Section 3 format\&. " .ti -1c .RI "\fBg2int\fP \fBgetpoly\fP (unsigned char *, \fBg2int\fP *, \fBg2int\fP *, \fBg2int\fP *)" .br .RI "This subroutine returns the J, K, and M pentagonal resolution parameters specified in a GRIB Grid Definition Section (GDS) used spherical harmonic coefficients using GDT 5\&.50 through 5\&.53\&. " .ti -1c .RI "void \fBjpcpack\fP (\fBg2float\fP *, \fBg2int\fP, \fBg2int\fP, \fBg2int\fP *, unsigned char *, \fBg2int\fP *)" .br .RI "This subroutine packs up a data field into a JPEG2000 code stream\&. " .ti -1c .RI "void \fBpngpack\fP (\fBg2float\fP *, \fBg2int\fP, \fBg2int\fP, \fBg2int\fP *, unsigned char *, \fBg2int\fP *)" .br .RI "This subroutine packs up a data field into PNG image format\&. " .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\&. " .ti -1c .RI "void \fBspecpack\fP (\fBg2float\fP *, \fBg2int\fP, \fBg2int\fP, \fBg2int\fP, \fBg2int\fP, \fBg2int\fP *, unsigned char *, \fBg2int\fP *)" .br .RI "This subroutine packs a spectral data field using the complex packing algorithm for spherical harmonic data as defined in the GRIB2 Data Representation Template 5\&.51\&. " .in -1c .SH "Detailed Description" .PP Pack up Sections 4 through 7 for a given field and adds them to a GRIB2 message\&. .PP \fBAuthor\fP .RS 4 Stephen Gilbert .RE .PP \fBDate\fP .RS 4 2002-11-05 .RE .PP .PP Definition in file \fBg2_addfield\&.c\fP\&. .SH "Function Documentation" .PP .SS "void cmplxpack (\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 .IP "\(bu" 2 0 Reference value - ignored on input, set by compack routine\&. .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 .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 2004-08-27 .RE .PP .PP Definition at line 33 of file cmplxpack\&.c\&. .PP References compack(), and misspack()\&. .PP Referenced by g2_addfield()\&. .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 getdim (unsigned char * csec3, \fBg2int\fP * width, \fBg2int\fP * height, \fBg2int\fP * iscan)" .PP This subroutine returns the dimensions and scanning mode of a grid definition packed in GRIB2 Grid Definition Section 3 format\&. .PP \fBParameters\fP .RS 4 \fIcsec3\fP Character array that contains the packed GRIB2 GDS\&. .br \fIwidth\fP x (or i) dimension of the grid\&. 0 of grid not recognized\&. .br \fIheight\fP y (or j) dimension of the grid\&. 0 of grid not recognized\&. .br \fIiscan\fP Scanning mode (see Code Table 3\&.4)\&. 0 of grid not recognized\&. .RE .PP \fBReturns\fP .RS 4 Always returns 0\&. .RE .PP \fBAuthor\fP .RS 4 Stephen Gilbert .RE .PP \fBDate\fP .RS 4 2002-12-11 .RE .PP .PP Definition at line 30 of file getdim\&.c\&. .PP References g2_unpack3()\&. .PP Referenced by g2_addfield()\&. .SS "\fBg2int\fP getpoly (unsigned char * csec3, \fBg2int\fP * jj, \fBg2int\fP * kk, \fBg2int\fP * mm)" .PP This subroutine returns the J, K, and M pentagonal resolution parameters specified in a GRIB Grid Definition Section (GDS) used spherical harmonic coefficients using GDT 5\&.50 through 5\&.53\&. .PP \fBParameters\fP .RS 4 \fIcsec3\fP Character array that contains the packed GRIB2 GDS\&. .br \fIjj\fP J - pentagonal resolution parameter\&. .br \fIkk\fP K - pentagonal resolution parameter\&. .br \fImm\fP M - pentagonal resolution parameter\&. .RE .PP \fBReturns\fP .RS 4 0 for success, error code otherwise\&. .RE .PP \fBNote\fP .RS 4 Returns jj, kk, and mm set to zero, if grid template not recognized\&. .RE .PP \fBAuthor\fP .RS 4 Stephen Gilbert .RE .PP \fBDate\fP .RS 4 2002-12-11 .RE .PP .PP Definition at line 32 of file getpoly\&.c\&. .PP References g2_unpack3()\&. .PP Referenced by g2_addfield()\&. .SS "void jpcpack (\fBg2float\fP * fld, \fBg2int\fP width, \fBg2int\fP height, \fBg2int\fP * idrstmpl, unsigned char * cpack, \fBg2int\fP * lcpack)" .PP This subroutine packs up a data field into a JPEG2000 code stream\&. After the data field is scaled, and the reference value is subtracted out, it is treated as a grayscale image and passed to a JPEG2000 encoder\&. It also fills in GRIB2 Data Representation Template 5\&.40 or 5\&.40000 with the appropriate values\&. .PP PROGRAM HISTORY LOG: .IP "\(bu" 2 2003-08-17 Gilbert .IP "\(bu" 2 2004-11-92 Gilbert - Fixed bug encountered when packing a near constant field\&. .IP "\(bu" 2 2004-07-19 Gilbert - Added check on whether the jpeg2000 encoding was successful\&. If not, try again with different encoder options\&. .IP "\(bu" 2 2005-05-10 Gilbert - Imposed minimum size on cpack, used to hold encoded bit string\&. .PP .PP \fBParameters\fP .RS 4 \fIfld\fP Contains the data values to pack\&. .br \fIwidth\fP number of points in the x direction\&. .br \fIheight\fP number of points in the y direction\&. .br \fIidrstmpl\fP Contains the array of values for Data Representation Template 5\&.40 or 5\&.40000\&. .IP "\(bu" 2 0 Reference value - ignored on input, set by jpcpack routine\&. .IP "\(bu" 2 1 Binary Scale Factor - used on input, unchanged by jpcpack routine\&. .IP "\(bu" 2 2 Decimal Scale Factor - used on input, unchanged by jpcpack routine\&. .IP "\(bu" 2 3 number of bits for each data value - ignored on input .IP "\(bu" 2 4 Original field type - currently ignored on input Data values assumed to be reals\&. Set to 0 on output\&. .IP "\(bu" 2 5 if 0 use lossless compression, if 1 use lossy compression\&. .IP "\(bu" 2 6 Desired compression ratio, if idrstmpl[5]=1\&. Set to 255, if idrstmpl[5]=0\&. .PP .br \fIcpack\fP The packed data field\&. .br \fIlcpack\fP length of packed field in cpack\&. .RE .PP \fBAuthor\fP .RS 4 Stephen Gilbert .RE .PP \fBDate\fP .RS 4 2003-08-17 .RE .PP .PP Definition at line 49 of file jpcpack\&.c\&. .PP References enc_jpeg2000(), int_power(), mkieee(), and sbits()\&. .PP Referenced by g2_addfield()\&. .SS "void pngpack (\fBg2float\fP * fld, \fBg2int\fP width, \fBg2int\fP height, \fBg2int\fP * idrstmpl, unsigned char * cpack, \fBg2int\fP * lcpack)" .PP This subroutine packs up a data field into PNG image format\&. After the data field is scaled, and the reference value is subtracted out, it is treated as a grayscale image and passed to a PNG encoder\&. It also fills in GRIB2 Data Representation Template 5\&.41 or 5\&.40010 with the appropriate values\&. .PP \fBParameters\fP .RS 4 \fIfld\fP Contains the data values to pack\&. .br \fIwidth\fP number of points in the x direction\&. .br \fIheight\fP number of points in the y direction\&. .br \fIidrstmpl\fP Contains the array of values for Data Representation Template 5\&.41 or 5\&.40010\&. .IP "\(bu" 2 0 Reference value - ignored on input, set by pngpack routine\&. .IP "\(bu" 2 1 Binary Scale Factor - used on input\&. .IP "\(bu" 2 2 Decimal Scale Factor - used on input\&. .IP "\(bu" 2 3 number of bits for each grayscale pixel value - ignored on input\&. .IP "\(bu" 2 4 Original field type - currently ignored on input, set = 0 on output\&. Data values assumed to be reals\&. .PP .br \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 2003-08-27 .RE .PP .PP Definition at line 34 of file pngpack\&.c\&. .PP References enc_png(), int_power(), mkieee(), and sbits()\&. .PP Referenced by g2_addfield()\&. .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\&. .PP References int_power(), mkieee(), sbit(), and sbits()\&. .PP Referenced by g2_addfield(), and specpack()\&. .SS "void specpack (\fBg2float\fP * fld, \fBg2int\fP ndpts, \fBg2int\fP JJ, \fBg2int\fP KK, \fBg2int\fP MM, \fBg2int\fP * idrstmpl, unsigned char * cpack, \fBg2int\fP * lcpack)" .PP This subroutine packs a spectral data field using the complex packing algorithm for spherical harmonic data as defined in the GRIB2 Data Representation Template 5\&.51\&. .PP \fBParameters\fP .RS 4 \fIfld\fP Contains the packed data values\&. .br \fIndpts\fP The number of data values to pack\&. .br \fIJJ\fP J - pentagonal resolution parameter\&. .br \fIKK\fP K - pentagonal resolution parameter\&. .br \fIMM\fP M - pentagonal resolution parameter\&. .br \fIidrstmpl\fP Contains the array of values for Data Representation Template 5\&.51\&. .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 2002-12-19 .RE .PP .PP Definition at line 26 of file specpack\&.c\&. .PP References int_power(), mkieee(), and simpack()\&. .PP Referenced by g2_addfield()\&. .SH "Author" .PP Generated automatically by Doxygen for NCEPLIBS-g2c from the source code\&.