---
name: "g2_create.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_create.c"
---

# g2\_create.c(3)

Initialize a new GRIB2 message and pack GRIB2 sections 0 (Indicator Section) and 1 (Identification Section).

## NAME

g2\_create.c - Initialize a new GRIB2 message and pack GRIB2 sections 0 (Indicator Section) and 1 (Identification Section).

## SYNOPSIS

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

### Macros

\#define **LENSEC0**   16\
 Length of GRIB Section 0.  #define **MAPSEC1LEN**   13\
 Length of Map Section 1.

### Functions

**g2int** **g2\_create** (unsigned char \*cgrib, **g2int** \*listsec0, **g2int** \*listsec1)\
 Initialize a new GRIB2 message and pack GRIB2 `Section 0 (Indicator Section)` and `Section 1 (Identification Section)`.

## Detailed Description

Initialize a new GRIB2 message and pack GRIB2 sections 0 (Indicator Section) and 1 (Identification Section).

**Author**

Stephen Gilbert

**Date**

2002-10-31

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

## Macro Definition Documentation

### #define LENSEC0 16

Length of GRIB Section 0.

Definition at line **11** of file **g2\_create.c**.

### #define MAPSEC1LEN 13

Length of Map Section 1.

Definition at line **10** of file **g2\_create.c**.

## Function Documentation

### g2int g2\_create (unsigned char \* cgrib, g2int \* listsec0, g2int \* listsec1)

Initialize a new GRIB2 message and pack GRIB2 `Section 0 (Indicator Section)` and `Section 1 (Identification Section)`. This routine is used with routines **g2\_addlocal()**, **g2\_addgrid()**, **g2\_addfield()**, and **g2\_gribend()** to create a complete GRIB2 message. **g2\_create()** must be called first to initialize a new GRIB2 message. A call to **g2\_gribend()** is required to complete GRIB2 message after all fields have been added.

**Parameters**

*cgrib* Character array to contain the GRIB2 message. Must be allocated large enough to store the entire GRIB2 message. \
 *listsec0* Contains information needed for GRIB Indicator Section 0. Must be dimensioned \>= 2.

- •

  listsec0\[0\] Discipline-GRIB Master Table Number (\[Code Table 0.0\] (https://www.nco.ncep.noaa.gov/pmb/docs/grib2/grib2\_doc/grib2\_table0-0.shtml)).

- •

  listsec0\[1\] GRIB Edition Number (currently 2).

*listsec1* Contains information needed for GRIB Identification Section 1. Must be dimensioned \>= 13.

- •

  listsec1\[0\] Id of orginating centre (\[Table 0\] (https://www.nco.ncep.noaa.gov/pmb/docs/on388/table0.html)).

- •

  listsec1\[1\] Id of orginating sub-centre (\[Table C\] (https://www.nco.ncep.noaa.gov/pmb/docs/on388/tablec.html)).

- •

  listsec1\[2\] GRIB Master Tables Version Number (\[Table 1.0\] (https://www.nco.ncep.noaa.gov/pmb/docs/grib2/grib2\_doc/grib2\_table1-0.shtml)).

- •

  listsec1\[3\] GRIB Local Tables Version Number (\[Table 1.1\] (https://www.nco.ncep.noaa.gov/pmb/docs/grib2/grib2\_doc/grib2\_table1-1.shtml)).

- •

  listsec1\[4\] Significance of Reference Time (\[Table 1.2\] (https://www.nco.ncep.noaa.gov/pmb/docs/grib2/grib2\_doc/grib2\_table1-2.shtml))

- •

  listsec1\[5\] Reference Time - Year (4 digits)

- •

  listsec1\[6\] Reference Time - Month

- •

  listsec1\[7\] Reference Time - Day

- •

  listsec1\[8\] Reference Time - Hour

- •

  listsec1\[9\] Reference Time - Minute

- •

  listsec1\[10\] Reference Time - Second

- •

  listsec1\[11\] Production status of data (\[Table 1.3\] (https://www.nco.ncep.noaa.gov/pmb/docs/grib2/grib2\_doc/grib2\_table1-3.shtml)).

- •

  listsec1\[12\] Type of processed data (\[Table 1.4\] (https://www.nco.ncep.noaa.gov/pmb/docs/grib2/grib2\_doc/grib2\_table1-4.shtml)).

**Returns**

- •

  \> 0 Current size of new GRIB2 message

- •

  **G2\_CREATE\_GRIB\_VERSION** Tried to use for version other than GRIB Edition 2

This routine is intended for use with routines **g2\_addlocal()**, **g2\_addgrid()**, **g2\_addfield()**, and **g2\_gribend()** to create a complete GRIB2 message.

**Author**

Stephen Gilbeert

**Date**

2002-10-31

Definition at line **68** of file **g2\_create.c**.

References **G2\_CREATE\_GRIB\_VERSION**, **LENSEC0**, **MAPSEC1LEN**, and **sbit()**.

## Author

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