---
name: "g2_unpack7.c"
section: "3"
platform: "linux"
package: "libg2c-dev"
version: "2.1.0-2"
release: "Debian 13 (Trixie)"
platforms: ["linux"]
url: "https://new.carta.tech/g2_unpack7.c"
---

# g2\_unpack7.c(3)

Unpack Section 7 (Data Section) of a GRIB2 message.

## NAME

g2\_unpack7.c - Unpack Section 7 (Data Section) of a GRIB2 message.

## SYNOPSIS

`#include 'grib2_int.h'`\
 `#include <memory.h>`\
 `#include <string.h>`\

### Functions

**g2int** **g2\_unpack7** (unsigned char \*cgrib, **g2int** \*iofst, **g2int** igdsnum, **g2int** \*igdstmpl, **g2int** idrsnum, **g2int** \*idrstmpl, **g2int** ndpts, float \*\*fld)\
 This subroutine unpacks Section 7 (Data Section) of a GRIB2 message.  int **g2c\_unpack7** (unsigned char \*cgrib, int igdsnum, int gds\_tmpl\_len, long long int \*gdstmpl, int idrsnum, int drs\_tmpl\_len, long long int \*drstmpl, int ndpts, float \*fld)\
 This subroutine unpacks Section 7 (Data Section) of a GRIB2 message.  static **g2int** **g2c\_unpack7\_int** (unsigned char \*cgrib, **g2int** \*iofst, **g2int** igdsnum, **g2int** \*igdstmpl, **g2int** idrsnum, **g2int** \*idrstmpl, **g2int** ndpts, int v1, float \*\*fld)\
 Unpacks Section 7 (Data Section) of a GRIB2 message.

## Detailed Description

Unpack Section 7 (Data Section) of a GRIB2 message.

**Author**

Stephen Gilbert

**Date**

2002-10-31

### 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.    2022-10-04   Hartnett   Added **g2c\_unpack7()**.    2023-10-16   Engle   Added support for DRT 5.42, AEC compression.

Definition in file **g2\_unpack7.c**.

## Function Documentation

### g2int g2\_unpack7 (unsigned char \* cgrib, g2int \* iofst, g2int igdsnum, g2int \* igdstmpl, g2int idrsnum, g2int \* idrstmpl, g2int ndpts, float \*\* fld)

This subroutine unpacks Section 7 (Data Section) of a GRIB2 message. This function is maintained for backward compatibility. Users may wish to use the newer **g2c\_unpack7()** function instead.

**Parameters**

*cgrib* char array containing Section 7 of the GRIB2 message \
 *iofst* Pointer to a bit offset of the beginning of Section 7 in cgrib. This is updated by this function to reflect the data read in this function. After this function is successfully called, the value pointed to by iofst will be the number of bits to the end of section 7 in cbuf. \
 *igdsnum* Grid Definition Template Number (see Code Table 3.0). (Only used for DRS Template 5.51.) \
 *igdstmpl* Pointer to an integer array containing the data values for the specified Grid Definition Template (N=igdsnum). Each element of this integer array contains an entry (in the order specified) of Grid Definition Template 3.N. (Only used for DRS Template 5.51). \
 *idrsnum* Data Representation Template Number (see Code Table 5.0). \
 *idrstmpl* Pointer to an integer array containing the data values for the specified Data Representation Template (N=idrsnum). Each element of this integer array contains an entry (in the order specified) of Data Representation Template 5.N \
 *ndpts* Number of data points to be unpacked and returned. \
 *fld* Pointer to a float pointer which gets a pointer to an array allocated by this function to hold the unpacked data. This memory must be freed by the caller.

**Returns**

- •

  **G2\_NO\_ERROR** No error.

- •

  **G2\_UNPACK\_BAD\_SEC** Array passed had incorrect section number.

- •

  **G2\_UNPACK7\_BAD\_DRT** Unrecognized Data Representation Template.

- •

  **G2\_UNPACK7\_WRONG\_GDT** need one of GDT 3.50 through 3.53 to decode DRT 5.51

- •

  **G2\_UNPACK\_NO\_MEM** Memory allocation error.

- •

  **G2\_UNPACK7\_CORRUPT\_SEC** Corrupt section 7.

**Author**

Stephen Gilbert

**Date**

2002-10-31

Definition at line **214** of file **g2\_unpack7.c**.

References **g2c\_unpack7\_int()**.

Referenced by **g2\_getfld()**.

### int g2c\_unpack7 (unsigned char \* cgrib, int igdsnum, int gds\_tmpl\_len, long long int \* gdstmpl, int idrsnum, int drs\_tmpl\_len, long long int \* drstmpl, int ndpts, float \* fld)

This subroutine unpacks Section 7 (Data Section) of a GRIB2 message. This function is the newer version of **g2\_unpack7()**.

**Parameters**

*cgrib* char array containing Section 7 of the GRIB2 message \
 *igdsnum* Grid Definition Template Number (see Code Table 3.0). (Only used for DRS Template 5.51.) May be zero for other templates. \
 *gds\_tmpl\_len* Number of elements in the GDS template. \
 *gdstmpl* 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). May be NULL. \
 *idrsnum* Data Representation Template Number (see Code Table 5.0). \
 *drs\_tmpl\_len* Number of elements in the DRS template. \
 *drstmpl* Pointer to an integer array containing the data values for the specified Data Representation Template (N=idrsnum). Each element of this integer array contains an entry (in the order specified) of Data Representation Template 5.N \
 *ndpts* Number of data points to be unpacked and returned. \
 *fld* Pointer which the data. Memory must be allocated in advance by caller.

**Returns**

- •

  **G2\_NO\_ERROR** No error.

- •

  **G2\_UNPACK\_BAD\_SEC** Array passed had incorrect section number.

- •

  **G2\_UNPACK7\_BAD\_DRT** Unrecognized Data Representation Template.

- •

  **G2\_UNPACK7\_WRONG\_GDT** need one of GDT 3.50 through 3.53 to decode DRT 5.51

- •

  **G2\_UNPACK\_NO\_MEM** Memory allocation error.

- •

  **G2\_UNPACK7\_CORRUPT\_SEC** Corrupt section 7.

**Author**

Stephen Gilbert

**Date**

2002-10-31

Definition at line **259** of file **g2\_unpack7.c**.

References **G2C\_EINVAL**, **G2C\_ENOMEM**, **g2c\_unpack7\_int()**, and **LOG**.

Referenced by **g2c\_get\_prod()**.

### static g2int g2c\_unpack7\_int (unsigned char \* cgrib, g2int \* iofst, g2int igdsnum, g2int \* igdstmpl, g2int idrsnum, g2int \* idrstmpl, g2int ndpts, int v1, float \*\* fld)` [static]`

Unpacks Section 7 (Data Section) of a GRIB2 message. This function is the internal function called by both **g2\_unpack7()** and **g2c\_unpack7()**.

**Parameters**

*cgrib* char array containing Section 7 of the GRIB2 message \
 *iofst* Pointer to a bit offset of the beginning of Section 7 in cgrib. This is updated by this function to reflect the data read in this function. After this function is successfully called, the value pointed to by iofst will be the number of bits to the end of section 7 in cbuf. \
 *igdsnum* Grid Definition Template Number (see Code Table 3.0). (Only used for DRS Template 5.51. May be 0 for other templates.) \
 *igdstmpl* Pointer to an integer array containing the data values for the specified Grid Definition Template (N=igdsnum). Each element of this integer array contains an entry (in the order specified) of Grid Definition Template 3.N. (Only used for DRS Template 5.51, may be NULL for other templates). \
 *idrsnum* Data Representation Template Number (see Code Table 5.0). \
 *idrstmpl* Pointer to an integer array containing the data values for the specified Data Representation Template (N=idrsnum). Each element of this integer array contains an entry (in the order specified) of Data Representation Template 5.N \
 *ndpts* Number of data points to be unpacked and returned. \
 *v1* If non-zero, then act like the V1 G2C API. This includes:

- •

  printing error messages to stderr in the event of error.

- •

  returning V1 error codes.

*fld* Pointer to a float pointer which gets a pointer to an array allocated by this function to hold the unpacked data. This memory must be freed by the caller.

**Returns**

- •

  **G2\_NO\_ERROR** No error.

- •

  **G2\_UNPACK\_BAD\_SEC** Array passed had incorrect section number.

- •

  **G2\_UNPACK7\_BAD\_DRT** Unrecognized Data Representation Template.

- •

  **G2\_UNPACK7\_WRONG\_GDT** need one of GDT 3.50 through 3.53 to decode DRT 5.51

- •

  **G2\_UNPACK\_NO\_MEM** Memory allocation error.

- •

  **G2\_UNPACK7\_CORRUPT\_SEC** Corrupt section 7.

**Author**

Stephen Gilbert

**Date**

2002-10-31

Definition at line **67** of file **g2\_unpack7.c**.

References **aecunpack()**, **comunpack()**, **G2\_NO\_ERROR**, **G2\_UNPACK7\_BAD\_DRT**, **G2\_UNPACK7\_CORRUPT\_SEC**, **G2\_UNPACK7\_WRONG\_GDT**, **G2\_UNPACK\_BAD\_SEC**, **G2\_UNPACK\_NO\_MEM**, **gbit()**, **jpcunpack()**, **LOG**, **pngunpack()**, **rdieee()**, **simunpack()**, and **specunpack()**.

Referenced by **g2\_unpack7()**, and **g2c\_unpack7()**.

## Author

Generated automatically by Doxygen for NCEPLIBS-g2c from the source code.
