NCEPLIBS-g2c  1.6.4
g2_unpack7.c File Reference

Unpack Section 7 (Data Section) as defined in GRIB Edition 2. More...

#include <stdio.h>
#include <stdlib.h>
#include <memory.h>
#include <string.h>
#include "grib2.h"

Go to the source code of this file.

Functions

int comunpack (unsigned char *, g2int, g2int, g2int *, g2int, g2float *)
 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...
 
g2int g2_unpack7 (unsigned char *cgrib, g2int *iofst, g2int igdsnum, g2int *igdstmpl, g2int idrsnum, g2int *idrstmpl, g2int ndpts, g2float **fld)
 This subroutine unpacks Section 7 (Data Section) as defined in GRIB Edition 2. More...
 
g2int jpcunpack (unsigned char *, g2int, g2int *, g2int, g2float *)
 This subroutine unpacks a data field that was packed into a JPEG2000 code stream using info from the GRIB2 Data Representation Template 5.40 or 5.40000. More...
 
g2int pngunpack (unsigned char *, g2int, g2int *, g2int, g2float *)
 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...
 
g2int simunpack (unsigned char *, g2int *, g2int, g2float *)
 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...
 
g2int specunpack (unsigned char *, g2int *, g2int, g2int, g2int, g2int, g2float *)
 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...
 

Detailed Description

Unpack Section 7 (Data Section) as defined in GRIB Edition 2.

Author
Stephen Gilbert
Date
2002-10-31

Definition in file g2_unpack7.c.

Function Documentation

◆ comunpack()

int comunpack ( unsigned char *  cpack,
g2int  lensec,
g2int  idrsnum,
g2int idrstmpl,
g2int  ndpts,
g2float 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).

Program History Log

Date Programmer Comments
2002-10-29 Gilbert Initial
2004-12-16 Gilbert Added test (from Arthur Taylor/MDL) verifying group widths/lengths
Parameters
cpackpointer to the packed data field.
lenseclength of section 7 (used for error checking).
idrsnumData Representation Template number. Must equal 2 or 3.
idrstmplpointer to the array of values for Data Representation Template 5.2 or 5.3
ndptsThe number of data values to unpack
fldContains the unpacked data values. Must be allocated with at least ndpts * sizeof(g2float) bytes before calling this routine.
Returns
0 for success, error code otherwise.
Author
Stephen Gilbert
Date
2002-10-29

Definition at line 42 of file comunpack.c.

References gbit(), gbits(), int_power(), and rdieee().

Referenced by g2_unpack7().

◆ g2_unpack7()

g2int g2_unpack7 ( unsigned char *  cgrib,
g2int iofst,
g2int  igdsnum,
g2int igdstmpl,
g2int  idrsnum,
g2int idrstmpl,
g2int  ndpts,
g2float **  fld 
)

This subroutine unpacks Section 7 (Data Section) as defined in GRIB Edition 2.

Program History Log

Date Programmer Comments
2002-10-31 Gilbert Initial
2002-12-20 Gilbert Added GDT info to arguments and added 5.51 processing.
2003-08-29 Gilbert New templates using PNG and JPEG2000 algorithms/templates.
2004-11-29 Gilbert JPEG2000 now allowed to use WMO Template 5.40 PNG allowed to use 5.41
2004-12-16 Taylor Added check on comunpack return code.
2008-12-23 Wesley Initialize Number of data points unpacked
Parameters
cgribchar array containing Section 7 of the GRIB2 message
iofstBit offset of the beginning of Section 7 in cgrib.
igdsnumGrid Definition Template Number (see Code Table 3.0) (Only used for DRS Template 5.51)
igdstmplPointer 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).
idrsnumData Representation Template Number (see Code Table 5.0)
idrstmplPointer 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
ndptsNumber of data points unpacked and returned.
fldPointer to a float array containing the unpacked data field.
Returns
  • 0 no error
  • 2 Not section 7
  • 4 Unrecognized Data Representation Template
  • 5 need one of GDT 3.50 through 3.53 to decode DRT 5.51
  • 6 memory allocation error
  • 7 corrupt section 7.
Author
Stephen Gilbert
Date
2002-10-31

Definition at line 65 of file g2_unpack7.c.

References comunpack(), gbit(), jpcunpack(), pngunpack(), rdieee(), simunpack(), and specunpack().

Referenced by g2_getfld().

◆ jpcunpack()

g2int jpcunpack ( unsigned char *  cpack,
g2int  len,
g2int idrstmpl,
g2int  ndpts,
g2float fld 
)

This subroutine unpacks a data field that was packed into a JPEG2000 code stream using info from the GRIB2 Data Representation Template 5.40 or 5.40000.

Parameters
cpackThe packed data field (character*1 array).
lenlength of packed field cpack.
idrstmplPointer to array of values for Data Representation Template 5.40 or 5.40000.
ndptsThe number of data values to unpack.
fldContains the unpacked data values.
Returns
0 for success, 1 for memory allocation error.
Author
Stephem Gilbert
Date
2003-08-27

Definition at line 31 of file jpcunpack.c.

References dec_jpeg2000(), int_power(), and rdieee().

Referenced by g2_unpack7().

◆ pngunpack()

g2int pngunpack ( unsigned char *  cpack,
g2int  len,
g2int idrstmpl,
g2int  ndpts,
g2float 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.

Parameters
cpackThe packed data field (character*1 array).
lenlength of packed field cpack().
idrstmplPointer to array of values for Data Representation Template 5.41 or 5.40010.
ndptsThe number of data values to unpack.
fldContains the unpacked data values.
Returns
0 for success, 1 for memory allocation error.
Author
Stephen Gilbert
Date
2003-08-27

Definition at line 30 of file pngunpack.c.

References dec_png(), gbits(), int_power(), and rdieee().

Referenced by g2_unpack7().

◆ simunpack()

g2int simunpack ( unsigned char *  cpack,
g2int idrstmpl,
g2int  ndpts,
g2float 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.

Parameters
cpackpointer to the packed data field.
idrstmplpointer to the array of values for Data Representation Template 5.0.
ndptsThe number of data values to unpack.
fldContains the unpacked data values. fld must be `* allocated with at least ndpts * sizeof(g2float) bytes before calling this routine.
Returns
0 for success, error code otherwise.
Author
Stephen Gilbert
Date
2002-10-29

Definition at line 26 of file simunpack.c.

References gbits(), int_power(), and rdieee().

Referenced by g2_unpack7().

◆ specunpack()

g2int specunpack ( unsigned char *  cpack,
g2int idrstmpl,
g2int  ndpts,
g2int  JJ,
g2int  KK,
g2int  MM,
g2float 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.

Parameters
cpackpointer to the packed data field.
idrstmplpointer to the array of values for Data Representation Template 5.51.
ndptsThe number of data values to unpack (real and imaginary parts).
JJpentagonal resolution parameter.
KKpentagonal resolution parameter.
MMpentagonal resolution parameter.
fldContains the unpacked data values. fld must be allocated with at least ndpts * sizeof(g2float) bytes before calling this routine.
Returns
0 for success, -3 for wrong type.
Author
Stephen Gilbert
Date
2000-06-21

Definition at line 35 of file specunpack.c.

References gbits(), int_power(), and rdieee().

Referenced by g2_unpack7().