NCEPLIBS-g2c  1.7.0
gridtemplates.c File Reference

Returns grid template information for a specified Grid Definition Template for Section 3 - the Grid Definition Section (GDS). More...

#include <stdlib.h>
#include "grib2_int.h"

Go to the source code of this file.

Macros

#define MAXGRIDMAPLEN   200
 Maximum template map length. More...
 
#define MAXGRIDTEMP   31
 Maximum number of templates. More...
 

Functions

gtemplateextgridtemplate (g2int number, g2int *list)
 This subroutine generates the remaining octet map for a given Grid Definition Template, if required. More...
 
static g2int getgridindex (g2int number)
 This function returns the index of specified Grid Definition Template in array templates for [Section 3 - the Grid Definition Section (GDS)](https://www.nco.ncep.noaa.gov/pmb/docs/grib2/grib2_doc/grib2_sect3.shtml). More...
 
gtemplategetgridtemplate (g2int number)
 This subroutine returns grid template information for a specified Grid Definition Template for [Section 3 - the Grid Definition Section (GDS)](https://www.nco.ncep.noaa.gov/pmb/docs/grib2/grib2_doc/grib2_sect3.shtml). More...
 

Variables

static const struct gridtemplate templatesgrid [MAXGRIDTEMP]
 Templates grid. More...
 

Detailed Description

Returns grid template information for a specified Grid Definition Template for Section 3 - the Grid Definition Section (GDS).

Each Template has three parts:

  1. The number of entries in the template (mapgridlen).
  2. A map of the template (mapgrid), which contains the number of octets in which to pack each of the template values.
  3. A logical value (needext) that indicates whether the Template needs to be extended.

In some cases the number of entries in a template can vary depending upon values specified in the "static" part of the template. (See Template 3.120 as an example).

Note
Array mapgrid contains the number of octets in which the corresponding template values will be stored. A negative value in mapgrid is used to indicate that the corresponding template entry can contain negative values. This information is used later when packing (or unpacking) the template data values. Negative data values in GRIB are stored with the left most bit set to one, and a negative number of octets value in mapgrid indicates that this possibility should be considered. The number of octets used to store the data value in this case would be the absolute value of the negative value in mapgrid.

Program History Log

Date Programmer Comments
2001-06-28 Gilbert Initial
2007-08-16 Vuong Added GDT 3.204 Curvilinear Orthogonal Grid
2008-07-08 Vuong Added GDT 3.32768 Rotate Lat/Lon E-grid (Arakawa)
2009-01-14 Vuong Changed structure name template to gtemplate
2010-05-11 Vuong Added GDT 3.32769 Rotate Lat/Lon Non-E Staggered grid (Arakawa)
2013-08-06 Vuong Added GDT 3.4, 3.5, 3.12, 3.101, 3.140
Author
Stephen Gilbert
Date
2001-06-28

Definition in file gridtemplates.c.

Macro Definition Documentation

◆ MAXGRIDMAPLEN

#define MAXGRIDMAPLEN   200

Maximum template map length.

Definition at line 43 of file gridtemplates.c.

◆ MAXGRIDTEMP

#define MAXGRIDTEMP   31

Maximum number of templates.

Definition at line 42 of file gridtemplates.c.

Function Documentation

◆ extgridtemplate()

gtemplate* extgridtemplate ( g2int  number,
g2int list 
)

This subroutine generates the remaining octet map for a given Grid Definition Template, if required.

Some Templates can vary depending on data values given in an earlier part of the Template, and it is necessary to know some of the earlier entry values to generate the full octet map of the Template.

This function allocates memory for the extension. The pointer ext in the gtemplate struct must be freed to prevent memory leaks.

Parameters
numberThe number of the Grid Definition Template that is being requested.
listThe list of values for each entry in the Grid Definition Template.
Returns
Pointer to the returned template struct. Returns NULL pointer, if template not found.
Author
Stephen Gilbert
Date
2000-05-09

Definition at line 229 of file gridtemplates.c.

References getgridindex(), and getgridtemplate().

Referenced by g2_addgrid(), and g2_unpack3().

◆ getgridindex()

static g2int getgridindex ( g2int  number)
static

This function returns the index of specified Grid Definition Template in array templates for [Section 3 - the Grid Definition Section (GDS)](https://www.nco.ncep.noaa.gov/pmb/docs/grib2/grib2_doc/grib2_sect3.shtml).

Parameters
numberThe number of the Grid Definition Template being requested.
Returns
Index of the Grid Definition Template(GDT) in array templates, if template exists. -1, otherwise.
Author
Stephen Gilbert
Date
2001-06-28

Definition at line 142 of file gridtemplates.c.

References MAXGRIDTEMP, and templatesgrid.

Referenced by extgridtemplate(), and getgridtemplate().

◆ getgridtemplate()

gtemplate* getgridtemplate ( g2int  number)

This subroutine returns grid template information for a specified Grid Definition Template for [Section 3 - the Grid Definition Section (GDS)](https://www.nco.ncep.noaa.gov/pmb/docs/grib2/grib2_doc/grib2_sect3.shtml).

The number of entries in the template is returned along with a map of the number of octets occupied by each entry. Also, a flag is returned to indicate whether the template would need to be extended.

This function allocates storage for the template. The returned pointer must be freed by the caller.

Parameters
numberThe number of the Grid Definition Template that is being requested.
Returns
Pointer to the returned template struct (must be freed by caller). Returns NULL pointer, if template not found.
Author
Stephen Gilbert
Date
2000-05-09

Definition at line 180 of file gridtemplates.c.

References getgridindex(), and templatesgrid.

Referenced by extgridtemplate(), g2_addgrid(), and g2_unpack3().

Variable Documentation

◆ templatesgrid

const struct gridtemplate templatesgrid[MAXGRIDTEMP]
static

Templates grid.

Definition at line 59 of file gridtemplates.c.

Referenced by getgridindex(), and getgridtemplate().