NCEPLIBS-g2  3.5.0
g2create.F90 File Reference

Subroutines to create a GRIB2 message. More...

Go to the source code of this file.

Functions/Subroutines

subroutine addfield (cgrib, lcgrib, ipdsnum, ipdstmpl, ipdstmplen, coordlist, numcoord, idrsnum, idrstmpl, idrstmplen, fld, ngrdpts, ibmap, bmap, ierr)
 Pack up Sections 4 through 7 for a field and add them to a GRIB2 message. More...
 
subroutine addgrid (cgrib, lcgrib, igds, igdstmpl, igdstmplen, ideflist, idefnum, ierr)
 Add a Grid Definition Section (Section 3) to a GRIB2 message. More...
 
subroutine addlocal (cgrib, lcgrib, csec2, lcsec2, ierr)
 Add a Local Use Section (Section 2) to a GRIB2 message. More...
 
subroutine gribcreate (cgrib, lcgrib, listsec0, listsec1, ierr)
 Initialize a new GRIB2 message and pack GRIB2 sections 0 (Indicator) and 1 (Identification). More...
 
subroutine gribend (cgrib, lcgrib, lengrib, ierr)
 Finalize a GRIB2 message after all grids and fields have been added. More...
 

Detailed Description

Subroutines to create a GRIB2 message.

Author
Ed Hartnett
Date
Mar 5, 2024

Definition in file g2create.F90.

Function/Subroutine Documentation

◆ addfield()

subroutine addfield ( character(len=1), dimension(lcgrib), intent(inout)  cgrib,
integer, intent(in)  lcgrib,
integer, intent(in)  ipdsnum,
integer, dimension(*), intent(in)  ipdstmpl,
integer, intent(in)  ipdstmplen,
real, dimension(numcoord), intent(in)  coordlist,
integer, intent(in)  numcoord,
integer, intent(in)  idrsnum,
integer, dimension(*), intent(inout)  idrstmpl,
integer, intent(in)  idrstmplen,
real, dimension(ngrdpts), intent(in), target  fld,
integer, intent(in)  ngrdpts,
integer, intent(in)  ibmap,
logical*1, dimension(ngrdpts), intent(in)  bmap,
integer, intent(out)  ierr 
)

Pack up Sections 4 through 7 for a field and add them to a GRIB2 message.

They are the Product Definition Section, Data Representation Section, Bit-Map Section and Data Sections.

This routine is used with routines gribcreate(), addlocal(), addgrid(), and gribend() to create a complete GRIB2 message. Subroutine gribcreate() must be called first to initialize a new GRIB2 message. Subroutine addgrid() must be called after gribcreate() and before this routine to add the appropriate grid description to the GRIB2 message. A call to gribend() is required to complete GRIB2 message after all fields have been added.

Parameters
[in,out]cgribCharacter array to contain the GRIB2 message.
[in]lcgribMaximum length (bytes) of array cgrib.
[in]ipdsnumProduct Definition Template Number (see Code Table 4.0).
[in]ipdstmplContains the data values for the Product Definition Template specified by ipdsnum.
[in]ipdstmplenMax dimension of ipdstmpl.
[out]coordlistArray containg floating point values intended to document the vertical discretisation associated to model data on hybrid coordinate vertical levels (part of Section 4).
[in]numcoord- number of values in array coordlist.
[in]idrsnum- Data Representation Template Number (see Code Table 5.0).
[in]idrstmplContains the data values for the Data Representation Template specified by idrsnum. Note that some values in this template (eg. reference values, number of bits, etc...) may be changed by the data packing algorithms. Use this to specify scaling factors and order of spatial differencing, if desired.
[in]idrstmplenMax dimension of idrstmpl. This must be at least as large as the length of the selected PDS template.
[in]fldArray of data points to pack.
[out]ngrdptsNumber of data points in grid. i.e. size of fld and bmap.
[out]ibmapBitmap indicator (see Code Table 6.0).
  • 0 bitmap applies and is included in Section 6.
  • 1-253 Predefined bitmap applies
  • 254 Previously defined bitmap applies to this field
  • 255 Bit map does not apply to this product.
[out]bmapLogical*1 array containing bitmap to be added (if ibmap=0 or ibmap=254).
[out]ierrError return code.
  • 0 no error.
  • 1 GRIB message was not initialized. Need to call routine gribcreate first.
  • 2 GRIB message already complete. Cannot add new section.
  • 3 Sum of Section byte counts does not add to total byte count.
  • 4 Previous Section was not 3 or 7.
  • 5 Could not find requested Product Definition Template.
  • 6 Section 3 (GDS) not previously defined in message.
  • 7 Tried to use unsupported Data Representationi Template.
  • 8 Specified use of a previously defined bitmap, but one does not exist in the GRIB message.
  • 9 GDT of one of 5.50 through 5.53 required to pack using DRT 5.51.
  • 10 Error packing data field.
Author
Stephen Gilbert
Date
2000-05-02

Definition at line 196 of file g2create.F90.

References cmplxpack(), pdstemplates::extpdstemplate(), g2_gbytec1(), g2_sbytec(), g2_sbytec1(), g2_sbytesc(), g2_sbytescr(), getdim(), drstemplates::getdrstemplate(), pdstemplates::getpdstemplate(), getpoly(), jpcpack(), mkieee(), pngpack(), simpack(), and specpack().

Referenced by putgb2().

◆ addgrid()

subroutine addgrid ( character(len = 1), dimension(lcgrib), intent(inout)  cgrib,
integer, intent(in)  lcgrib,
integer, dimension(*), intent(in)  igds,
integer, dimension(*), intent(in)  igdstmpl,
integer, intent(in)  igdstmplen,
integer, dimension(idefnum), intent(in)  ideflist,
integer, intent(in)  idefnum,
integer, intent(out)  ierr 
)

Add a Grid Definition Section (Section 3) to a GRIB2 message.

This routine is used with routines gribcreate(), addlocal(), addfield(), and gribend() to create a complete GRIB2 message.

Parameters
[in,out]cgribCharacter array to contain the GRIB2 message.
[in]lcgribMaximum length (bytes) of array cgrib.
[in]igdsContains information needed for GRIB Grid Definition Section 3. Must be dimensioned >= 5.
  • igds(1) Source of grid definition (see Code Table 3.0).
  • igds(2) Number of grid points in the defined grid.
  • igds(3) 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(4) Interpretation of list for optional points definition. (See Code Table 3.11).
  • igds(5) Grid Definition Template Number (See Code Table 3.1).
[in]igdstmplContains the data values for the Grid Definition Template specified by igds(5). This should have the length of mapgridlen of the selected grid template.
[in]igdstmplenMax dimension of igdstmpl. This must be at least as large as the mapgridlen of the chosen template.
[in]ideflist(Used if igds(3) .ne. 0). This array contains the number of grid points contained in each row (or column).
[in]idefnumThe number of entries in array ideflist. This is the number of rows (or columns) for which optional grid points are defined.
[out]ierrError return code.
  • 0 no error.
  • 1 GRIB message was not initialized. Need to call routine gribcreate first.
  • 2 GRIB message already complete. Cannot add new section.
  • 3 Sum of Section byte counts doesn't add to total byte count.
  • 4 Previous Section was not 1, 2 or 7.
  • 5 Could not find requested Grid Definition Template.
Author
Stephen Gilbert
Date
2000-05-01

Definition at line 659 of file g2create.F90.

References gridtemplates::extgridtemplate(), g2_gbytec1(), g2_sbytec(), g2_sbytec1(), g2_sbytesc(), and gridtemplates::getgridtemplate().

Referenced by putgb2().

◆ addlocal()

subroutine addlocal ( character(len = 1), dimension(lcgrib), intent(inout)  cgrib,
integer, intent(in)  lcgrib,
character(len = 1), dimension(lcsec2), intent(in)  csec2,
integer, intent(in)  lcsec2,
integer, intent(out)  ierr 
)

Add a Local Use Section (Section 2) to a GRIB2 message.

This routine is used with routines gribcreate(), addlocal(), addfield(), and gribend() to create a complete GRIB2 message. Subroutine gribcreate must be called first to initialize a new GRIB2 message.

The Local Use Section (Section 2) can only follow Section 1 or Section 7 in a GRIB2 message.

Parameters
[in,out]cgribCharacter array to contain the GRIB2 message.
[in]lcgribMaximum length (bytes) of array cgrib.
[in]csec2Character array containing information to be added to Section 2.
[in]lcsec2Number of bytes of character array csec2 to be added to Section 2.
[out]ierrError return code.
  • 0 no error
  • 1 GRIB message was not initialized. Need to call routine gribcreate first.
  • 2 GRIB message already complete. Cannot add new section.
  • 3 Sum of Section byte counts doesn't add to total byte count.
  • 4 Previous Section was not 1 or 7.
Author
Stephen Gilbert
Date
2000-05-01

Definition at line 873 of file g2create.F90.

References g2_gbytec1(), and g2_sbytec1().

Referenced by putgb2().

◆ gribcreate()

subroutine gribcreate ( character(len = 1), dimension(lcgrib), intent(inout)  cgrib,
integer, intent(in)  lcgrib,
integer, dimension(*), intent(in)  listsec0,
integer, dimension(*), intent(in)  listsec1,
integer, intent(out)  ierr 
)

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

This routine is used with routines addlocal(), addgrid(), addfield(), and gribend() to create a complete GRIB2 message. Subroutine gribcreate() must be called first to initialize a new GRIB2 message. Also, a call to gribend() is required to complete GRIB2 message after all fields have been added.

Parameters
[in,out]cgribCharacter array to contain the GRIB2 message.
[in]lcgribMaximum Length (in bytes) of array cgrib.
[in]listsec0Contains information needed for GRIB Indicator Section 0. Must be dimensioned >= 2.
  • listsec0(1) Discipline-GRIB Master Table Number (Code Table 0.0).
  • listsec0(2) GRIB Edition Number (currently 2)
[in]listsec1Contains information needed for GRIB Identification Section 1. Must be dimensioned >= 13.
  • listsec1(1) Id of orginating centre (Table 0).
  • listsec1(2) Id of orginating sub-centre (Table C).
  • listsec1(3) GRIB Master Tables Version Number (Table 1.0).
  • listsec1(4) GRIB Local Tables Version Number (Table 1.1).
  • listsec1(5) Significance of Reference Time (Table 1.2)
  • listsec1(6) Reference Time - Year (4 digits)
  • listsec1(7) Reference Time - Month
  • listsec1(8) Reference Time - Day
  • listsec1(9) Reference Time - Hour
  • listsec1(10) Reference Time - Minute
  • listsec1(11) Reference Time - Second
  • listsec1(12) Production status of data (Table 1.3).
  • listsec1(13) Type of processed data (Table 1.4).
[out]ierrError return code.
  • 0 no error
  • 1 Tried to use for version other than GRIB Edition 2
Note
This routine is intended for use with routines addlocal(), addgrid(), addfield(), and gribend() to create a complete GRIB2 message.
Author
Stephen Gilbert
Date
2000-04-28

Definition at line 53 of file g2create.F90.

References g2_sbytec(), and g2_sbytec1().

Referenced by putgb2().

◆ gribend()

subroutine gribend ( character(len = 1), dimension(lcgrib), intent(inout)  cgrib,
integer, intent(in)  lcgrib,
integer, intent(out)  lengrib,
integer, intent(out)  ierr 
)

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

This subroutine 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 gribcreate(), addlocal(), addgrid(), and addfield() to create a complete GRIB2 message.

Parameters
[in,out]cgribCharacter array to contain the GRIB2 message.
[in]lcgribMaximum Length (in bytes) of array cgrib.
[out]lengribLength of the final GRIB2 message in bytes.
[out]ierrError return code.
  • 0 no error.
  • 1 GRIB message was not initialized - call routine gribcreate() first.
  • 2 GRIB message already complete.
  • 3 Sum of Section byte counts doesn't add to total byte count.
  • 4 Previous Section was not 7.
Author
Stephen Gilbert
Date
2000-05-02

Definition at line 979 of file g2create.F90.

References g2_gbytec1(), and g2_sbytec1().

Referenced by putgb2().