---
name: "g2_addgrid.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_addgrid.c"
---

# g2\_addgrid.c(3)

Pack a Grid Definition Section (Section 3) and adds it to a GRIB2 message.

## NAME

g2\_addgrid.c - Pack a Grid Definition Section (Section 3) and adds it to a GRIB2 message.

## SYNOPSIS

`#include 'grib2_int.h'`\
 `#include <stdio.h>`\
 `#include <stdlib.h>`\

### Functions

**g2int** **g2\_addgrid** (unsigned char \*cgrib, **g2int** \*igds, **g2int** \*igdstmpl, **g2int** \*ideflist, **g2int** idefnum)\
 Packs a `Grid Definition Section (Section 3)` and adds it to a GRIB2 message.

## Detailed Description

Pack a Grid Definition Section (Section 3) and adds it to a GRIB2 message.

**Author**

Stephen Gilbeert

**Date**

2002-11-01

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

## Function Documentation

### g2int g2\_addgrid (unsigned char \* cgrib, g2int \* igds, g2int \* igdstmpl, g2int \* ideflist, g2int idefnum)

Packs a `Grid Definition Section (Section 3)` and adds it to a GRIB2 message. This function is used with routines **g2\_create()**, **g2\_addlocal()**, **g2\_addfield()**, and **g2\_gribend()** to create a complete GRIB2 message. **g2\_create()** must be called first to initialize a new GRIB2 message.

**Parameters**

*cgrib* Char array that contains the GRIB2 message to which section should be added. Must be allocated large enough to store the entire GRIB2 message. \
 *igds* Contains information needed for GRIB Grid Definition Section 3. Must be dimensioned \>= 5.

- •

  igds\[0\] Source of grid definition (see `Code Table 3.0`).

- •

  igds\[1\] Number of grid points in the defined grid.

- •

  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.

- •

  igds\[3\] Interpretation of list for optional points definition. (See `Code Table 3.11`).

- •

  igds\[4\] Grid Definition Template Number (See `Code Table 3.1`).

*igdstmpl* Contains the data values for the specified Grid Definition Template (igds\[4\]). Each element of this integer array contains an entry (in the order specified) of Grid Defintion Template. \
 *ideflist* (Used if igds\[2\] != 0) This array contains the number of grid points contained in each row (or column). \
 *idefnum* (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.

**Returns**

- •

  \> 0 Current size of updated GRIB2 message

- •

  **G2\_ADD\_MSG\_INIT** GRIB message was not initialized. Need to call routine gribcreate first.

- •

  **G2\_ADD\_MSG\_COMPLETE** GRIB message already complete. Cannot add new section.

- •

  **G2\_BAD\_SEC\_COUNTS** Sum of Section byte counts doesn't add to total byte count

- •

  **G2\_BAD\_SEC** Previous Section was not 1, 2 or 7.

- •

  **G2\_ADDGRID\_BAD\_GDT** Could not find requested Grid Definition Template.

**Note**

The Grid Def Section (Section 3) can only follow Section 1, 2 or Section 7 in a GRIB2 message.

**Author**

Stephen Gilbeert

**Date**

2002-11-01

Definition at line **66** of file **g2\_addgrid.c**.

References **gtemplate::ext**, **extgridtemplate()**, **gtemplate::extlen**, **G2\_ADD\_MSG\_COMPLETE**, **G2\_ADD\_MSG\_INIT**, **G2\_ADDGRID\_BAD\_GDT**, **G2\_BAD\_SEC**, **G2\_BAD\_SEC\_COUNTS**, **g2c\_check\_msg()**, **G2C\_EMSGCOMPLETE**, **G2C\_ENOTGRIB**, **gbit()**, **getgridtemplate()**, **gtemplate::map**, **gtemplate::maplen**, **gtemplate::needext**, **sbit()**, and **sbits()**.

## Author

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