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

# g2cdegrib2.c(3)

Write summary output to a file, as is done by utility grb2index.

## NAME

g2cdegrib2.c - Write summary output to a file, as is done by utility grb2index.

## SYNOPSIS

`#include 'grib2_int.h'`\
 `#include <math.h>`\
 `#include <stdarg.h>`\

### Macros

\#define **G2C\_DATE\_TIME\_LEN**   25\
 Size of the date/time string.  #define **G2C\_MAX\_TYPE\_OF\_FIXED\_SURFACE\_LEN**   40\
 Maximum length of 'Type of first fixed surface' string.

### Functions

static int **format\_level** (char \*cbuf, int ival, int scale)\
 Format the level string for degrib2 output.  int **g2c\_degrib2** (int g2cid, const char \*fileout)\
 Write a summary file like the degrib2 utility.  int **g2c\_get\_datetime** (int ipdtn, long long int \*ipdtmpl, short year, unsigned char month, unsigned char day, unsigned char hour, unsigned char minute, unsigned char second, char \*tabbrev)\
 Convert date and time from GRIB2 info to string output.  int **g2c\_get\_level\_desc** (int ipdtn, long long int \*ipdtmpl, char \*level\_desc)\
 Determine the string that describes the level information, given the GRIB2 Product Definition Template information.

### Variables

**G2C\_FILE\_INFO\_T** **g2c\_file** \[**G2C\_MAX\_FILES**+1\]\
 Global file information.  **G2C\_CODE\_TABLE\_T** \* **g2c\_table**\
 Pointer to the list of code tables.

## Detailed Description

Write summary output to a file, as is done by utility grb2index.

**Author**

Ed Hartnett

**Date**

Sep 17, 2022

Definition in file **g2cdegrib2.c**.

## Macro Definition Documentation

### #define G2C\_DATE\_TIME\_LEN 25

Size of the date/time string.

Definition at line **21** of file **g2cdegrib2.c**.

### #define G2C\_MAX\_TYPE\_OF\_FIXED\_SURFACE\_LEN 40

Maximum length of 'Type of first fixed surface' string.

Definition at line **19** of file **g2cdegrib2.c**.

## Function Documentation

### static int format\_level (char \* cbuf, int ival, int scale)` [static]`

Format the level string for degrib2 output.

**Parameters**

*cbuf* Character buffer of length 11 which will get the formatted level description. \
 *ival* Integer value which may need scaling. \
 *scale* Scaling factor information.

**Returns**

- •

  **G2C\_NOERROR** No error.

**Author**

Ed Hartnett

**Date**

11/16/22

Definition at line **254** of file **g2cdegrib2.c**.

References **G2C\_NOERROR**.

Referenced by **g2c\_get\_level\_desc()**.

### int g2c\_degrib2 (int g2cid, const char \* fileout)

Write a summary file like the degrib2 utility.

**Parameters**

*g2cid* Indentifier for the file, returned by **g2c\_open()** or g2c\_create(). \
 *fileout* Path of output file. Any existing file of this name will be overwritten.

**Returns**

- •

  **G2C\_NOERROR** No error.

- •

  **G2C\_EINVAL** Invalid parameters.

- •

  **G2C\_EFILE** File I/O error.

**Author**

Ed Hartnett

**Date**

Sep 17, 2022

Definition at line **634** of file **g2cdegrib2.c**.

References **g2c\_message\_info::bytes\_in\_msg**, **g2c\_message\_info::bytes\_to\_msg**, **g2c\_message\_info::center**, **g2c\_section5\_info::data\_def**, **g2c\_message\_info::day**, **g2c\_message\_info::discipline**, **G2C\_EBADID**, **G2C\_EFILE**, **G2C\_EINVAL**, **G2C\_ENOSECTION**, **G2C\_ERROR**, **g2c\_file**, **g2c\_get\_datetime()**, **g2c\_get\_level\_desc()**, **g2c\_get\_prod()**, **G2C\_MAX\_FILES**, **G2C\_MAX\_NOAA\_ABBREV\_LEN**, **G2C\_MAX\_TYPE\_OF\_FIXED\_SURFACE\_LEN**, **G2C\_NOERROR**, **g2c\_param\_abbrev()**, **g2c\_section3\_info::grid\_def**, **g2c\_message\_info::hour**, **g2c\_section6\_info::indicator**, **g2c\_section3\_info::interp\_list**, **g2c\_message\_info::local\_version**, **LOG**, **g2c\_message\_info::master\_version**, **g2c\_message\_info::minute**, **g2c\_message\_info::month**, **g2c\_section\_info::msg**, **g2c\_message\_info::msg\_num**, **g2c\_message\_info::next**, **g2c\_section\_info::next**, **g2c\_section4\_info::num\_coord**, **g2c\_section3\_info::num\_data\_points**, **g2c\_section5\_info::num\_data\_points**, **g2c\_message\_info::num\_fields**, **g2c\_message\_info::num\_local**, **g2c\_section3\_info::num\_opt**, **g2c\_section3\_info::optional**, **g2c\_section\_info::prev**, **g2c\_section4\_info::prod\_def**, **g2c\_message\_info::sec**, **g2c\_section\_info::sec\_info**, **g2c\_section\_info::sec\_len**, **g2c\_section\_info::sec\_num**, **g2c\_message\_info::second**, **g2c\_message\_info::sig\_ref\_time**, **g2c\_section3\_info::source\_grid\_def**, **g2c\_message\_info::status**, **g2c\_message\_info::subcenter**, **g2c\_section\_info::template**, **g2c\_section\_info::template\_len**, **g2c\_message\_info::type**, and **g2c\_message\_info::year**.

Referenced by **main()**.

### int g2c\_get\_datetime (int ipdtn, long long int \* ipdtmpl, short year, unsigned char month, unsigned char day, unsigned char hour, unsigned char minute, unsigned char second, char \* tabbrev)

Convert date and time from GRIB2 info to string output.

**Note**

This function is based on the prvtime() function in NCEPLIBS-grib\_utils.

**Parameters**

*ipdtn* Product Definition Template Number (\[Code Table 4.0\] (https://www.nco.ncep.noaa.gov/pmb/docs/grib2/grib2\_doc/grib2\_table4-0.shtml)). \
 *ipdtmpl* Array of data values for the Product Definition Template specified by ipdtn. \
 *year* year \
 *month* month \
 *day* day \
 *hour* hour \
 *minute* minute \
 *second* second \
 *tabbrev* Character array that will get the date and time string. Must be of length 100.

**Returns**

- •

  **G2C\_NOERROR** No error.

**Author**

Ed Hartnett

**Date**

Sep 28, 2022

Definition at line **49** of file **g2cdegrib2.c**.

References **G2C\_DATE\_TIME\_LEN**, and **G2C\_NOERROR**.

Referenced by **g2c\_degrib2()**.

### int g2c\_get\_level\_desc (int ipdtn, long long int \* ipdtmpl, char \* level\_desc)

Determine the string that describes the level information, given the GRIB2 Product Definition Template information. This subroutine finds the 'Type of first fixed surface' (see \[Code table 4.5\](https://www.nco.ncep.noaa.gov/pmb/docs/grib2/grib2\_doc/grib2\_temp4-0.shtml)) using the product definition template value and product template array. The location in the template array varies depending on the template number.

**Parameters**

*ipdtn* Product Definition Template Number (\[Code Table 4.0\] (https://www.nco.ncep.noaa.gov/pmb/docs/grib2/grib2\_doc/grib2\_table4-0.shtml)). \
 *ipdtmpl* Array of data values for the Product Definition Template specified by ipdtn. \
 *level\_desc* Character array which gets the string describing the level. Must be of length 40.

**Returns**

- •

  **G2C\_NOERROR** No error.

**Author**

Ed Hartnett

**Date**

Sep 28, 2022

Definition at line **309** of file **g2cdegrib2.c**.

References **format\_level()**, and **G2C\_NOERROR**.

Referenced by **g2c\_degrib2()**.

## Variable Documentation

### G2C\_FILE\_INFO\_T g2c\_file\[G2C\_MAX\_FILES+1\]` [extern]`

Global file information.

Definition at line **10** of file **g2cfile.c**.

Referenced by **g2c\_degrib2()**.

### G2C\_CODE\_TABLE\_T\* g2c\_table` [extern]`

Pointer to the list of code tables.

Definition at line **16** of file **g2ccsv.c**.

## Author

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