NCEPLIBS-g2c
1.7.0
|
Header file with internal function prototypes NCEPLIBS-g2c library. More...
Go to the source code of this file.
Data Structures | |
struct | gtemplate |
Struct for GRIB template. More... | |
Macros | |
#define | ALOG2 (0.69314718) |
ln(2.0) More... | |
#define | G2C_JASPER_JPEG_FORMAT_NAME "jpc" |
Name of JPEG codec in Jasper. More... | |
#define | LOG(e) |
Ignore logging to stdout. More... | |
Typedefs | |
typedef struct gtemplate | gtemplate |
Struct for GRIB template. More... | |
Functions | |
void | cmplxpack (float *fld, g2int ndpts, g2int idrsnum, g2int *idrstmpl, unsigned char *cpack, g2int *lcpack) |
This subroutine packs up a data field using a complex packing algorithm as defined in the GRIB2 documention. More... | |
void | compack (float *fld, g2int ndpts, g2int idrsnum, g2int *idrstmpl, unsigned char *cpack, g2int *lcpack) |
This subroutine packs up a data field using a complex packing algorithm as defined in the GRIB2 documention. More... | |
int | comunpack (unsigned char *cpack, g2int lensec, g2int idrsnum, g2int *idrstmpl, g2int ndpts, float *fld) |
This subroutine unpacks a data field that was packed using a complex packing algorithm as defined in the GRIB2 documention, using info from the GRIB2 Data Representation Template 5.2 or Template 5.3. More... | |
int | dec_jpeg2000 (char *injpc, g2int bufsize, g2int *outfld) |
This Function decodes a JPEG2000 code stream specified in the JPEG2000 Part-1 standard (i.e., ISO/IEC 15444-1) using JasPer Software. More... | |
int | dec_png (unsigned char *pngbuf, g2int *width, g2int *height, unsigned char *cout) |
Decode PNG. More... | |
int | enc_jpeg2000 (unsigned char *cin, g2int width, g2int height, g2int nbits, g2int ltype, g2int ratio, g2int retry, char *outjpc, g2int jpclen) |
This Function encodes a grayscale image into a JPEG2000 code stream specified in the JPEG2000 Part-1 standard (i.e., ISO/IEC 15444-1) using JasPer Software. More... | |
int | enc_png (unsigned char *data, g2int width, g2int height, g2int nbits, unsigned char *pngbuf) |
Encode PNG. More... | |
gtemplate * | extdrstemplate (g2int number, g2int *list) |
This subroutine generates the remaining octet map for a given Data Representation Template, if required. More... | |
gtemplate * | extgridtemplate (g2int number, g2int *list) |
This subroutine generates the remaining octet map for a given Grid Definition Template, if required. More... | |
gtemplate * | extpdstemplate (g2int number, g2int *list) |
This subroutine generates the remaining octet map for a given Product Definition Template, if required. More... | |
int | g2c_check_msg (unsigned char *cgrib, g2int *lencurr, int verbose) |
Check for 'GRIB' at the beginning of a GRIB message, and check to see if the message is already terminated with '7777'. More... | |
void | gbit (unsigned char *in, g2int *iout, g2int iskip, g2int nbits) |
Get bits - unpack bits: Extract arbitrary size values from a packed bit string, right justifying each value in the unpacked iout array. More... | |
void | gbits (unsigned char *in, g2int *iout, g2int iskip, g2int nbits, g2int nskip, g2int n) |
Get bits - unpack bits: Extract arbitrary size values from a packed bit string, right justifying each value in the unpacked iout array. More... | |
g2int | getdim (unsigned char *csec3, g2int *width, g2int *height, g2int *iscan) |
This subroutine returns the dimensions and scanning mode of a grid definition packed in GRIB2 Grid Definition Section 3 format. More... | |
gtemplate * | getdrstemplate (g2int number) |
This subroutine returns DRS template information for a specified Data Representation Template. More... | |
gtemplate * | getgridtemplate (g2int number) |
This subroutine returns grid template information for a specified Grid Definition Template for [Section 3 - the Grid Definition Section (GDS)](https://www.nco.ncep.noaa.gov/pmb/docs/grib2/grib2_doc/grib2_sect3.shtml). More... | |
gtemplate * | getpdstemplate (g2int number) |
This subroutine returns PDS template information for a specified Product Definition Template. More... | |
g2int | getpoly (unsigned char *csec3, g2int *jj, g2int *kk, g2int *mm) |
This subroutine returns the J, K, and M pentagonal resolution parameters specified in a GRIB Grid Definition Section (GDS) used spherical harmonic coefficients using GDT 5.50 through 5.53. More... | |
double | int_power (double x, g2int y) |
Function similar to C pow() power function. More... | |
void | jpcpack (float *fld, g2int width, g2int height, g2int *idrstmpl, unsigned char *cpack, g2int *lcpack) |
This subroutine packs up a data field into a JPEG2000 code stream. More... | |
g2int | jpcunpack (unsigned char *cpack, g2int len, g2int *idrstmpl, g2int ndpts, float *fld) |
Unpack JPEG2000 compressed data into an array of floats, using info from the GRIB2 Data Representation Template 5.40 or 5.40000. More... | |
void | misspack (float *fld, g2int ndpts, g2int idrsnum, g2int *idrstmpl, unsigned char *cpack, g2int *lcpack) |
This function packs up a data field using a complex packing algorithm as defined in the GRIB2 documention. More... | |
void | mkieee (float *a, g2int *rieee, g2int num) |
This subroutine stores a list of real values in 32-bit IEEE floating point format. More... | |
int | pack_gp (g2int *kfildo, g2int *ic, g2int *nxy, g2int *is523, g2int *minpk, g2int *inc, g2int *missp, g2int *misss, g2int *jmin, g2int *jmax, g2int *lbit, g2int *nov, g2int *ndg, g2int *lx, g2int *ibit, g2int *jbit, g2int *kbit, g2int *novref, g2int *lbitref, g2int *ier) |
Determines groups of variable size, but at least of size minpk, the associated max (jmax( )) and min (jmin( )), the number of bits necessary to hold the values in each group (lbit( )), the number of values in each group (nov( )), the number of bits necessary to pack the jmin( ) values (ibit), the number of bits necessary to pack the lbit( ) values (jbit), and the number of bits necessary to pack the nov( ) values (kbit). More... | |
void | pngpack (float *fld, g2int width, g2int height, g2int *idrstmpl, unsigned char *cpack, g2int *lcpack) |
This subroutine packs up a float data field into PNG image format. More... | |
g2int | pngunpack (unsigned char *cpack, g2int len, g2int *idrstmpl, g2int ndpts, float *fld) |
This subroutine unpacks a data field that was packed into a PNG image format using info from the GRIB2 Data Representation Template 5.41 or 5.40010. More... | |
void | rdieee (g2int *rieee, float *a, g2int num) |
This subroutine reads a list of real values in 32-bit IEEE floating point format. More... | |
void | sbit (unsigned char *out, g2int *in, g2int iskip, g2int nbits) |
Store bits - put arbitrary size values into a packed bit string, taking the low order bits from each value in the unpacked array. More... | |
void | sbits (unsigned char *out, g2int *in, g2int iskip, g2int nbits, g2int nskip, g2int n) |
Store bits - put arbitrary size values into a packed bit string, taking the low order bits from each value in the unpacked array. More... | |
void | simpack (float *fld, g2int ndpts, g2int *idrstmpl, unsigned char *cpack, g2int *lcpack) |
This subroutine packs up a data field using the simple packing algorithm as defined in the GRIB2 documention. More... | |
g2int | simunpack (unsigned char *cpack, g2int *idrstmpl, g2int ndpts, float *fld) |
This subroutine unpacks a data field that was packed using a simple packing algorithm as defined in the GRIB2 documention, using info from the GRIB2 Data Representation Template 5.0. More... | |
void | specpack (float *fld, g2int ndpts, g2int JJ, g2int KK, g2int MM, g2int *idrstmpl, unsigned char *cpack, g2int *lcpack) |
This subroutine packs a spectral data field using the complex packing algorithm for spherical harmonic data as defined in the GRIB2 Data Representation Template 5.51. More... | |
g2int | specunpack (unsigned char *cpack, g2int *idrstmpl, g2int ndpts, g2int JJ, g2int KK, g2int MM, float *fld) |
This subroutine unpacks a spectral data field that was packed using the complex packing algorithm for spherical harmonic data as defined in the GRIB2 documention, using info from the GRIB2 Data Representation Template 5.51. More... | |
Header file with internal function prototypes NCEPLIBS-g2c library.
Date | Programmer | Comments |
---|---|---|
2021-11-08 | Ed Hartnett | Initial |
Definition in file grib2_int.h.
struct gtemplate |
Struct for GRIB template.
Definition at line 28 of file grib2_int.h.
Data Fields | ||
---|---|---|
g2int * | ext | Number of octets of each entry in the extension part of the template. |
g2int | extlen | Number of entries in the template extension. |
g2int * | map | Number of octets of each entry in the static part of the template. |
g2int | maplen | Number of entries in the static part of the template. |
g2int | needext | Indicates whether or not the template needs to be extended. |
g2int | num | The template number. |
g2int | type |
The template type: 3 Grid Defintion Template. 4 Product Defintion Template. 5 Data Representation Template. |
#define ALOG2 (0.69314718) |
ln(2.0)
Definition at line 21 of file grib2_int.h.
#define G2C_JASPER_JPEG_FORMAT_NAME "jpc" |
Name of JPEG codec in Jasper.
Definition at line 23 of file grib2_int.h.
#define LOG | ( | e | ) |
Ignore logging to stdout.
Library was not built with LOGGING=ON.
Definition at line 138 of file grib2_int.h.
Struct for GRIB template.
Definition at line 56 of file grib2_int.h.
void cmplxpack | ( | float * | fld, |
g2int | ndpts, | ||
g2int | idrsnum, | ||
g2int * | idrstmpl, | ||
unsigned char * | cpack, | ||
g2int * | lcpack | ||
) |
This subroutine packs up a data field using a complex packing algorithm as defined in the GRIB2 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.
fld | Contains the data values to pack. |
ndpts | The number of data values in array fld |
idrsnum | Data Representation Template number. Must equal 2 or 3. |
idrstmpl | Contains the array of values for Data Representation Template 5.2 or 5.3
|
cpack | The packed data field. |
lcpack | length of packed field cpack. Will be set to -1 if missing value management field is not 1 or 2. |
Definition at line 36 of file cmplxpack.c.
References compack(), and misspack().
Referenced by g2_addfield().
void compack | ( | float * | fld, |
g2int | ndpts, | ||
g2int | idrsnum, | ||
g2int * | idrstmpl, | ||
unsigned char * | cpack, | ||
g2int * | lcpack | ||
) |
This subroutine packs up a data field using a complex packing algorithm as defined in the GRIB2 documention.
It supports GRIB2 complex packing templates with or without spatial differences (i.e. DRTs 5.2 and 5.3). It also fills in GRIB2 Data Representation Template 5.2 or Template 5.3 with the appropriate values.
fld | Contains the data values to pack. |
ndpts | The number of data values in array fld. |
idrsnum | Data Representation Template number. Must equal 2 or 3. |
idrstmpl | Contains the array of values for Data Representation Template 5.2 or 5.3.
|
cpack | The packed data field. |
lcpack | length of packed field cpack. |
Definition at line 42 of file compack.c.
References ALOG2, int_power(), mkieee(), pack_gp(), sbit(), and sbits().
Referenced by cmplxpack().
int comunpack | ( | unsigned char * | cpack, |
g2int | lensec, | ||
g2int | idrsnum, | ||
g2int * | idrstmpl, | ||
g2int | ndpts, | ||
float * | fld | ||
) |
This subroutine unpacks a data field that was packed using a complex packing algorithm as defined in the GRIB2 documention, using info from the GRIB2 Data Representation Template 5.2 or Template 5.3.
Supports GRIB2 complex packing templates with or without spatial differences (i.e. DRTs 5.2 and 5.3).
Date | Programmer | Comments |
---|---|---|
2002-10-29 | Gilbert | Initial |
2004-12-16 | Gilbert | Added test (from Arthur Taylor/MDL) verifying group widths/lengths |
cpack | pointer to the packed data field. |
lensec | length of section 7 (used for error checking). |
idrsnum | Data Representation Template number. Must equal 2 or 3. |
idrstmpl | pointer to the array of values for Data Representation Template 5.2 or 5.3 |
ndpts | The number of data values to unpack |
fld | Contains the unpacked data values. Must be allocated with at least ndpts * sizeof(float) bytes before calling this routine. |
Definition at line 42 of file comunpack.c.
References gbit(), gbits(), int_power(), and rdieee().
Referenced by g2_unpack7().
This Function decodes a JPEG2000 code stream specified in the JPEG2000 Part-1 standard (i.e., ISO/IEC 15444-1) using JasPer Software.
Date | Programmer | Comments |
---|---|---|
2002-12-02 | Gilbert | Initial |
2022-04-15 | Hartnett | Converted to use jas_ instead of jpc_ functions. |
injpc | Input JPEG2000 code stream. |
bufsize | Length (in bytes) of the input JPEG2000 code stream. |
outfld | Output matrix of grayscale image values. |
Definition at line 38 of file dec_jpeg2000.c.
References G2_JASPER_DECODE, G2_JASPER_DECODE_COLOR, G2_JASPER_INIT, and G2C_JASPER_JPEG_FORMAT_NAME.
Referenced by jpcunpack_int().
Decode PNG.
pngbuf | Pointer to PNG buffer. |
width | Pointer to width. |
height | Pointer to height. |
cout | Output buffer. |
Definition at line 61 of file dec_png.c.
References user_read_data().
Referenced by pngunpack_int().
int enc_jpeg2000 | ( | unsigned char * | cin, |
g2int | width, | ||
g2int | height, | ||
g2int | nbits, | ||
g2int | ltype, | ||
g2int | ratio, | ||
g2int | retry, | ||
char * | outjpc, | ||
g2int | jpclen | ||
) |
This Function encodes a grayscale image into a JPEG2000 code stream specified in the JPEG2000 Part-1 standard (i.e., ISO/IEC 15444-1) using JasPer Software.
Date | Programmer | Comments |
---|---|---|
2002-12-02 | Gilbert | Initial |
2004-12-16 | Gilbert | Added retry argument allowing increased guard bits. |
2022-04-15 | Hartnett | Converted to use jas_ instead of jpc_ functions. |
cin | Packed matrix of Grayscale image values to encode. |
width | width of image. |
height | height of image. |
nbits | depth (in bits) of image. i.e number of bits used to hold each data value. |
ltype | indicator of lossless or lossy compression.
|
ratio | target compression ratio. (ratio:1) Used only when ltype == 1. |
retry | If 1 try increasing number of guard bits. |
outjpc | Output encoded JPEG2000 code stream. |
jpclen | Number of bytes allocated for the output JPEG2000 code stream in outjpc. |
Definition at line 51 of file enc_jpeg2000.c.
References G2_JASPER_ENCODE, G2_JASPER_INIT, G2C_JASPER_JPEG_FORMAT_NAME, and MAXOPTSSIZE.
Referenced by jpcpack_int().
int enc_png | ( | unsigned char * | data, |
g2int | width, | ||
g2int | height, | ||
g2int | nbits, | ||
unsigned char * | pngbuf | ||
) |
Encode PNG.
data | data. |
width | width. |
height | height. |
nbits | number of bits. |
pngbuf | PNG buffer. |
Definition at line 75 of file enc_png.c.
References user_flush_data(), and user_write_data().
Referenced by pngpack_int().
This subroutine generates the remaining octet map for a given Data Representation Template, if required.
Some Templates can vary depending on data values given in an earlier part of the Template, and it is necessary to know some of the earlier entry values to generate the full octet map of the Template.
number | The number of the Data Representation Template that is being requested. |
list | The list of values for each entry in the the Data Representation Template. |
Definition at line 212 of file drstemplates.c.
References getdrsindex(), and getdrstemplate().
Referenced by g2_unpack5().
This subroutine generates the remaining octet map for a given Grid Definition Template, if required.
Some Templates can vary depending on data values given in an earlier part of the Template, and it is necessary to know some of the earlier entry values to generate the full octet map of the Template.
This function allocates memory for the extension. The pointer ext in the gtemplate struct must be freed to prevent memory leaks.
number | The number of the Grid Definition Template that is being requested. |
list | The list of values for each entry in the Grid Definition Template. |
Definition at line 229 of file gridtemplates.c.
References getgridindex(), and getgridtemplate().
Referenced by g2_addgrid(), and g2_unpack3().
This subroutine generates the remaining octet map for a given Product Definition Template, if required.
Some Templates can vary depending on data values given in an earlier part of the Template, and it is necessary to know some of the earlier entry values to generate the full octet map of the Template.
This function allocates memory in the ext field of the gtemplate struct. This memory must be freed by the caller.
number | number of the Product Definition Template 4.NN that is being requested. |
list | The list of values for each entry in the the Product Definition Template. |
Definition at line 329 of file pdstemplates.c.
References getpdsindex(), and getpdstemplate().
Referenced by g2_addfield(), and g2_unpack4().
int g2c_check_msg | ( | unsigned char * | cgrib, |
g2int * | lencurr, | ||
int | verbose | ||
) |
Check for 'GRIB' at the beginning of a GRIB message, and check to see if the message is already terminated with '7777'.
cgrib | Buffer that contains the GRIB message. |
lencurr | Pointer that gets the length of the GRIB message. |
verbose | If non-zero, print any error messages to stdout. |
Definition at line 26 of file util.c.
References G2C_MSG_COMPLETE, G2C_NO_ERROR, G2C_NOT_GRIB, and gbit().
Referenced by g2_addfield(), g2_addgrid(), g2_addlocal(), and g2_gribend().
Get bits - unpack bits: Extract arbitrary size values from a packed bit string, right justifying each value in the unpacked iout array.
in | pointer to character array input. |
iout | pointer to unpacked array output. |
iskip | initial number of bits to skip. |
nbits | number of bits to take. |
Definition at line 20 of file gbits.c.
References gbits().
Referenced by comunpack(), g2_addfield(), g2_addgrid(), g2_addlocal(), g2_getfld(), g2_gribend(), g2_info(), g2_unpack1(), g2_unpack2(), g2_unpack3(), g2_unpack4(), g2_unpack5(), g2_unpack6(), g2_unpack7(), g2c_check_msg(), and seekgb().
Get bits - unpack bits: Extract arbitrary size values from a packed bit string, right justifying each value in the unpacked iout array.
in | Pointer to character array input. |
iout | Pointer to unpacked array output. |
iskip | Initial number of bits to skip. |
nbits | Number of bits to take. |
nskip | Additional number of bits to skip on each iteration. |
n | Number of iterations. |
Definition at line 57 of file gbits.c.
Referenced by comunpack(), g2_unpack3(), g2_unpack4(), g2_unpack6(), gbit(), pngunpack_int(), simunpack(), and specunpack().
This subroutine returns the dimensions and scanning mode of a grid definition packed in GRIB2 Grid Definition Section 3 format.
csec3 | Character array that contains the packed GRIB2 GDS. |
width | x (or i) dimension of the grid. 0 if grid is not recognized. |
height | y (or j) dimension of the grid. 0 if grid is not recognized. |
iscan | Scanning mode (see Table 3.4). 0 of grid not recognized. |
Definition at line 29 of file getdim.c.
References g2_unpack3().
Referenced by g2_addfield().
This subroutine returns DRS template information for a specified Data Representation Template.
The number of entries in the template is returned along with a map of the number of octets occupied by each entry. Also, a flag is returned to indicate whether the template would need to be extended.
number | The number of the Data Representation Template that is being requested. |
Definition at line 166 of file drstemplates.c.
References getdrsindex(), and templatesdrs.
Referenced by extdrstemplate(), g2_addfield(), and g2_unpack5().
This subroutine returns grid template information for a specified Grid Definition Template for [Section 3 - the Grid Definition Section (GDS)](https://www.nco.ncep.noaa.gov/pmb/docs/grib2/grib2_doc/grib2_sect3.shtml).
The number of entries in the template is returned along with a map of the number of octets occupied by each entry. Also, a flag is returned to indicate whether the template would need to be extended.
This function allocates storage for the template. The returned pointer must be freed by the caller.
number | The number of the Grid Definition Template that is being requested. |
Definition at line 180 of file gridtemplates.c.
References getgridindex(), and templatesgrid.
Referenced by extgridtemplate(), g2_addgrid(), and g2_unpack3().
This subroutine returns PDS template information for a specified Product Definition Template.
The number of entries in the template is returned along with a map of the number of octets occupied by each entry. Also, a flag is returned to indicate whether the template would need to be extended.
This function allocates memory for the gtemplate struct, which must be freed by the caller.
number | the number of the Product Definition Template that is being requested. |
Definition at line 281 of file pdstemplates.c.
References getpdsindex(), and templatespds.
Referenced by extpdstemplate(), g2_addfield(), and g2_unpack4().
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.
If 51 - complex data spectral packing is used as the data representation template number (see Table 5.0), then the Grid Definition Template Number in section 3 should be one of:
csec3 | Character array that contains the packed GRIB2 GDS. |
jj | J pentagonal resolution parameter. |
kk | K pentagonal resolution parameter. |
mm | M pentagonal resolution parameter. |
Definition at line 40 of file getpoly.c.
References g2_unpack3().
Referenced by g2_addfield().
double int_power | ( | double | x, |
g2int | y | ||
) |
Function similar to C pow() power function.
x | The base value whose power is to be calculated. |
y | The power value. |
Definition at line 18 of file int_power.c.
Referenced by compack(), comunpack(), jpcpack_int(), jpcunpack_int(), misspack(), mkieee(), pngpack_int(), pngunpack_int(), rdieee(), simpack(), simunpack(), and specunpack().
void jpcpack | ( | float * | fld, |
g2int | width, | ||
g2int | height, | ||
g2int * | idrstmpl, | ||
unsigned char * | cpack, | ||
g2int * | lcpack | ||
) |
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.
fld | Pointer to the float or double data values to pack. |
width | The number of points in the x direction. |
height | The number of points in the y direction. |
idrstmpl | Contains the array of values for Data Representation Template Table 5.40 or 5.40000.
|
cpack | A pointer that will get the packed data field. Must be allocated before this function is called. Pass the allocated size in the lcpack parameter. |
lcpack | Pointer that gets the length of packed field in cpack. This must be set by the calling function to the size available in cpack. |
Definition at line 253 of file jpcpack.c.
Referenced by g2_addfield().
Unpack JPEG2000 compressed data into an array of floats, using info from the GRIB2 Data Representation Template 5.40 or 5.40000.
cpack | The packed data. |
len | The length of the packed data. |
idrstmpl | Pointer to array of values for Data Representation Template 5.40 or 5.40000. |
ndpts | The number of data values to unpack. |
fld | A pointer that gets the unpacked data values as an array of float. |
Definition at line 108 of file jpcunpack.c.
Referenced by g2_unpack7().
void misspack | ( | float * | fld, |
g2int | ndpts, | ||
g2int | idrsnum, | ||
g2int * | idrstmpl, | ||
unsigned char * | cpack, | ||
g2int * | lcpack | ||
) |
This function packs up a data field using a complex packing algorithm as defined in the GRIB2 documention.
It supports GRIB2 complex packing templates with or without spatial differences (See Template 5.2 and Template 5.3).
This function fills in GRIB2 Data Representation template arrays with the appropriate values.
fld | Contains the data values to pack |
ndpts | The number of data values in array fld |
idrsnum | Data Representation Template number. Must equal 2 or 3. |
idrstmpl | Contains the array of values for Data Representation Template 5.2 or 5.3.
|
cpack | The packed data field (character*1 array). |
lcpack | length of packed field cpack. |
Definition at line 42 of file misspack.c.
References ALOG2, int_power(), mkieee(), pack_gp(), rdieee(), sbit(), and sbits().
Referenced by cmplxpack().
This subroutine stores a list of real values in 32-bit IEEE floating point format.
a | Input array of floating point values. |
num | Number of floating point values to convert. |
rieee | Output array of data values in 32-bit IEEE format stored in g2int integer array. rieee must be allocated with at least 4*num bytes of memory before calling this function. |
Definition at line 22 of file mkieee.c.
References int_power().
Referenced by compack(), g2_addfield(), jpcpack_int(), misspack(), pngpack_int(), simpack(), and specpack().
int pack_gp | ( | g2int * | kfildo, |
g2int * | ic, | ||
g2int * | nxy, | ||
g2int * | is523, | ||
g2int * | minpk, | ||
g2int * | inc, | ||
g2int * | missp, | ||
g2int * | misss, | ||
g2int * | jmin, | ||
g2int * | jmax, | ||
g2int * | lbit, | ||
g2int * | nov, | ||
g2int * | ndg, | ||
g2int * | lx, | ||
g2int * | ibit, | ||
g2int * | jbit, | ||
g2int * | kbit, | ||
g2int * | novref, | ||
g2int * | lbitref, | ||
g2int * | ier | ||
) |
Determines groups of variable size, but at least of size minpk, the associated max (jmax( )) and min (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 g2int. Even though the groups are initially of size minpk or larger, an adjustment between two groups (the lookback procedure) may make a group smaller than minpk. The control on group size is that the sum of the sizes of the two consecutive groups, each of size minpk or larger, is not decreased. When determining the number of bits necessary for packing, the largest value that can be accommodated in, say, mbits, is 2**mbits-1; this largest value (and the next smallest value) is reserved for the missing value indicator (only) when is523 ne 0. If the dimension ndg is not large enough to hold all the groups, the local value of minpk is increased by 50 percent. This is repeated until ndg will suffice. A diagnostic is printed whenever this happens, which should be very rarely. If it happens often, ndg in subroutine pack should be increased and a corresponding increase in subroutine unpack made. Considerable code is provided so that no more checking for missing values within loops is done than necessary; the added efficiency of this is relatively minor, but does no harm. For grib2, the reference value for the length of groups in nov( ) and for the number of bits necessary to pack group values are determined, and subtracted before jbit and kbit are determined.
When 1 or more groups are large compared to the others, the width of all groups must be as large as the largest. A subroutine reduce breaks up large groups into 2 or more to reduce total bits required. If reduce should abort, pack_gp will be executed again without the call to reduce.
PROGRAM HISTORY LOG:
DATA SET USE
kfildo | unit number for output (print) file. (input) |
ic | array to hold data for packing. the values do not have to be positive at this point, but must be in the range -2**30 to +2**30 (the the value of mallow). these g2int values will be retained exactly through packing and unpacking. (input) |
nxy | number of values in ic( ). also treated as its dimension. (input) |
is523 | missing value management 0=data contains no missing values 1=data contains primary missing values 2=data contains primary and secondary missing values (input) |
minpk | the minimum size of each group, except possibly the last one. (input) |
inc | the number of values to add to an already existing group in determining whether or not to start a new group. ideally, this would be 1, but each time inc values are attempted, the max and min of the next minpk values must be found. this is "a loop within a loop," and a slightly larger value may give about as good results with slightly less computational time. if inc is le 0, 1 is used, and a diagnostic is output. note: it is expected that inc will equal 1. the code uses inc primarily in the loops starting at statement 180. if inc were 1, there would not need to be loops as such. however, kinc (the local value of inc) is set ge 1 when near the end of the data to forestall a very small group at the end. (input) |
missp | when missing points can be present in the data, they will have the value missp or misss. missp is the primary missing value and misss is the secondary missing value . these must not be values that would occur with subtracting the minimum (reference) value or scaling. for example, missp = 0 would not be advisable. (input) |
misss | secondary missing value indicator (see missp). (input) |
jmin | the minimum of each group (j=1,lx). (output) |
jmax | the maximum of each group (j=1,lx). this is not really needed, but since the max of each group must be found, saving it here is cheap in case the user wants it. (output) |
lbit | the number of bits necessary to pack each group (j=1,lx). it is assumed the minimum of each group will be removed before packing, and the values to pack will, therefore, all be positive. however, ic( ) does not necessarily contain all positive values. if the overall minimum has been removed (the usual case), then ic( ) will contain only positive values. (output) |
nov | the number of values in each group (j=1,lx). (output) |
ndg | the dimension of jmin, jmax, lbit, and nov. (input) |
lx | the number of groups determined. (output) |
ibit | the number of bits necessary to pack the jmin(j) values, j=1,lx. (output) |
jbit | the number of bits necessary to pack the lbit(j) values, j=1,lx. (output) |
kbit | the number of bits necessary to pack the nov(j) values, j=1,lx. (output) |
novref | reference value for nov( ). (output) |
lbitref | reference value for lbit( ). (output) |
ier | Error code
|
INTERNAL VARIABLES
cfeed = contains the character representation of a printer form feed. ifeed = contains the g2int 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 g2int 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. (g2int) ibitbs = keeps current value if ibitb so that loop ending at 166 doesn't have to start at ibitb = 0 every time. misslx(j) = mallow except when a group is all one value (and lbit(j) = 0) and that value is missing. in that case, misslx(j) is missp or misss. this gets inserted into jmin(j) later as the missing indicator; it can't be put in until the end, because jmin( ) is used to calculate the maximum number of bits (ibits) needed to pack jmin( ).
Definition at line 255 of file pack_gp.c.
References FALSE_, reduce(), and TRUE_.
Referenced by compack(), and misspack().
void pngpack | ( | float * | fld, |
g2int | width, | ||
g2int | height, | ||
g2int * | idrstmpl, | ||
unsigned char * | cpack, | ||
g2int * | lcpack | ||
) |
This subroutine packs up a float data field into PNG image format.
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.
fld | Pointer to array of float that contains the data values to pack. |
width | Number of points in the x direction. |
height | Number of points in the y direction. |
idrstmpl | Contains the array of values for Data Representation Template 5.41 or 5.40010.
|
cpack | The packed data field. |
lcpack | length of packed field cpack. |
Definition at line 224 of file pngpack.c.
Referenced by g2_addfield().
This subroutine unpacks a data field that was packed into a PNG image format using info from the GRIB2 Data Representation Template 5.41 or 5.40010.
cpack | The packed data field (character*1 array). |
len | length of packed field cpack(). |
idrstmpl | Pointer to array of values for Data Representation Template 5.41 or 5.40010. |
ndpts | The number of data values to unpack. |
fld | Contains the unpacked data values. |
Definition at line 105 of file pngunpack.c.
Referenced by g2_unpack7().
This subroutine reads a list of real values in 32-bit IEEE floating point format.
rieee | g2int array of floating point values in 32-bit IEEE format. |
num | Number of floating point values to convert. |
a | float array of real values. a must be allocated with at least 4*num bytes of memory before calling this function. |
Definition at line 21 of file rdieee.c.
References int_power().
Referenced by comunpack(), g2_miss(), g2_unpack4(), g2_unpack7(), jpcunpack_int(), misspack(), pngunpack_int(), simunpack(), and specunpack().
Store bits - put arbitrary size values into a packed bit string, taking the low order bits from each value in the unpacked array.
out | Pointer to packed array output. Must be allocated large enough to hold output. |
in | Pointer to unpacked array input. |
iskip | Initial number of bits to skip. |
nbits | Number of bits to pack. |
Definition at line 38 of file gbits.c.
References sbits().
Referenced by compack(), g2_addfield(), g2_addgrid(), g2_addlocal(), g2_create(), g2_gribend(), misspack(), and simpack().
Store bits - put arbitrary size values into a packed bit string, taking the low order bits from each value in the unpacked array.
out | Pointer to packed array output. Must be allocated large enough to hold output. |
in | Pointer to unpacked array input. |
iskip | Initial number of bits to skip. |
nbits | Number of bits to pack. |
nskip | Additional number of bits to skip on each iteration. |
n | Number of iterations. |
Definition at line 114 of file gbits.c.
Referenced by compack(), g2_addfield(), g2_addgrid(), jpcpack_int(), misspack(), pngpack_int(), sbit(), and simpack().
This subroutine packs up a data field using the simple packing algorithm as defined in the GRIB2 documention.
It also fills in GRIB2 Data Representation Template 5.0 with the appropriate values.
fld | Contains the data values to pack. |
ndpts | The number of data values in array fld. |
idrstmpl | Contains the array of values for [Data Representation Template 5.0](https://www.nco.ncep.noaa.gov/pmb/docs/grib2/grib2_doc/grib2_temp5-0.shtml).
|
cpack | The packed data field |
lcpack | length of packed field starting at cpack. |
Definition at line 34 of file simpack.c.
References ALOG2, int_power(), mkieee(), sbit(), and sbits().
Referenced by g2_addfield(), and specpack().
This subroutine unpacks a data field that was packed using a simple packing algorithm as defined in the GRIB2 documention, using info from the GRIB2 Data Representation Template 5.0.
cpack | pointer to the packed data field. |
idrstmpl | pointer to the array of values for Data Representation Template 5.0. |
ndpts | The number of data values to unpack. |
fld | Contains the unpacked data values. fld must be `* allocated with at least ndpts * sizeof(float) bytes before calling this routine. |
Definition at line 26 of file simunpack.c.
References G2_JPCUNPACK_MEM, G2_NO_ERROR, gbits(), int_power(), and rdieee().
Referenced by g2_unpack7().
void specpack | ( | float * | fld, |
g2int | ndpts, | ||
g2int | JJ, | ||
g2int | KK, | ||
g2int | MM, | ||
g2int * | idrstmpl, | ||
unsigned char * | cpack, | ||
g2int * | lcpack | ||
) |
This subroutine packs a spectral data field using the complex packing algorithm for spherical harmonic data as defined in the GRIB2 Data Representation Template 5.51.
fld | Contains the data values to be packed. |
ndpts | The number of data values to pack. |
JJ | J - pentagonal resolution parameter. |
KK | K - pentagonal resolution parameter. |
MM | M - pentagonal resolution parameter. |
idrstmpl | Contains the array of 10 values for [Data Representation Template 5.51](https://www.nco.ncep.noaa.gov/pmb/docs/grib2/grib2_doc/grib2_temp5-51.shtml). |
cpack | Pointer that gets the packed data field. Must be allocated by caller. |
lcpack | length of packed field cpack. |
Definition at line 33 of file specpack.c.
References mkieee(), and simpack().
Referenced by g2_addfield().
g2int specunpack | ( | unsigned char * | cpack, |
g2int * | idrstmpl, | ||
g2int | ndpts, | ||
g2int | JJ, | ||
g2int | KK, | ||
g2int | MM, | ||
float * | fld | ||
) |
This subroutine unpacks a spectral data field that was packed using the complex packing algorithm for spherical harmonic data as defined in the GRIB2 documention, using info from the GRIB2 Data Representation Template 5.51.
cpack | pointer to the packed data field. |
idrstmpl | pointer to the array of values for Data Representation Template 5.51. |
ndpts | The number of data values to unpack (real and imaginary parts). |
JJ | pentagonal resolution parameter. |
KK | pentagonal resolution parameter. |
MM | pentagonal resolution parameter. |
fld | Contains the unpacked data values. fld must be allocated with at least ndpts * sizeof(float) bytes before calling this routine. |
Definition at line 35 of file specunpack.c.
References G2_NO_ERROR, G2_SPECUNPACK_TYPE, gbits(), int_power(), and rdieee().
Referenced by g2_unpack7().