---
name: "g2_gribend.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_gribend.c"
---

# g2\_gribend.c(3)

Finalize a GRIB2 message after all grids and fields have been added.

## NAME

g2\_gribend.c - Finalize a GRIB2 message after all grids and fields have been added.

## SYNOPSIS

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

### Functions

**g2int** **g2\_gribend** (unsigned char \*cgrib)\
 Finalize a GRIB2 message after all grids and fields have been added.

## Detailed Description

Finalize a GRIB2 message after all grids and fields have been added.

**Author**

Stephen Gilbert

**Date**

2002-10-31

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

## Function Documentation

### g2int g2\_gribend (unsigned char \* cgrib)

Finalize a GRIB2 message after all grids and fields have been added. This function adds the End Section ('7777') to the end of the GRIB message and calculates the length and stores it in the appropriate place in Section 0. This routine is used with routines **g2\_create()**, **g2\_addlocal()**, **g2\_addgrid()**, and **g2\_addfield()** to create a complete GRIB2 message.

**Parameters**

*cgrib* Char array containing all the data sections added be previous calls to **g2\_create()**, **g2\_addlocal()**, **g2\_addgrid()**, and **g2\_addfield()**. After function is called, contains the finalized GRIB2 message.

**Returns**

- •

  \> 0 Length of the final GRIB2 message in bytes.

- •

  **G2\_GRIBEND\_MSG\_INIT** GRIB message was not initialized - call **g2\_create()** first.

- •

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

- •

  **G2\_BAD\_SEC** Previous Section was not 7.

**Note**

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

**Author**

Stephen Gilbert

**Date**

2002-10-31

Definition at line **40** of file **g2\_gribend.c**.

References **G2\_ADD\_MSG\_COMPLETE**, **G2\_ADD\_MSG\_INIT**, **G2\_BAD\_SEC**, **G2\_BAD\_SEC\_COUNTS**, **g2c\_check\_msg()**, **G2C\_EMSGCOMPLETE**, **G2C\_ENOTGRIB**, **gbit()**, and **sbit()**.

## Author

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