NCEPLIBS-g2  3.4.7
getgb2.F90 File Reference

Find and unpack a GRIB2 message in a file. More...

Go to the source code of this file.

Functions/Subroutines

subroutine getgb2 (LUGB, LUGI, J, JDISC, JIDS, JPDTN, JPDT, JGDTN, JGDT, UNPACK, K, GFLD, IRET)
 Find and unpack a GRIB2 message in a file. More...
 

Detailed Description

Find and unpack a GRIB2 message in a file.

Author
Mark Iredell
Date
1994-04-01

Definition in file getgb2.F90.

Function/Subroutine Documentation

◆ getgb2()

subroutine getgb2 ( integer, intent(in)  LUGB,
integer, intent(in)  LUGI,
integer, intent(in)  J,
integer, intent(in)  JDISC,
integer, dimension(*)  JIDS,
integer, intent(in)  JPDTN,
integer, dimension(*)  JPDT,
integer, intent(in)  JGDTN,
integer, dimension(*)  JGDT,
logical, intent(in)  UNPACK,
integer, intent(out)  K,
type(gribfield), intent(out)  GFLD,
integer, intent(out)  IRET 
)

Find and unpack a GRIB2 message in a file.

It reads a GRIB index file (or optionally the GRIB file itself) to get the index buffer (i.e. table of contents) for the GRIB file.

Find in the index buffer a reference to the GRIB field requested.

The GRIB field request specifies the number of fields to skip and the unpacked identification section, grid definition template and product defintion section parameters. (A requested parameter of -9999 means to allow any value of this parameter to be found.)

If the requested GRIB field is found, then it is read from the GRIB file and unpacked. Its number is returned along with the associated unpacked parameters. the bitmap (if any); the data values are unpacked only if argument unpack is set to true. If the GRIB field is not found, then the return code will be nonzero.

The decoded information for the selected GRIB field is returned in a derived type variable, gfld, which is of type grib_mod::gribfield. Users of this routine will need to include the line "use grib_mod" in their calling routine.

Derived type grib_mod::gribfield contains pointers to many arrays of data. Users must free this memory by calling gf_free().

This subroutine calls getidx(), which allocates memory and stores the resulting pointers in an array that is a Fortran "save" variable. The result is that the memory will not be freed by the library and cannot be reached by the caller. To free this memory call gf_finalize() after all library operations are complete.

Note
Specify an index file if feasible to increase speed. Do not engage the same logical unit from more than one processor. Note that derived type gribfield contains pointers to many arrays of data. The memory for these arrays is allocated when the values in the arrays are set, to help minimize problems with array overloading. Because of this users should free this memory, when it is no longer needed, by a call to subroutine gf_free().
Parameters
[in]LUGBinteger unit of the unblocked grib data file. File must be opened with baopen() or baopenr() before calling this routine.
[in]LUGIinteger unit of the unblocked grib index file. If nonzero, file must be opened with baopen() or baopenr() before calling this routine.
  • >0 read index from index file lugi, if index doesn"t already exist.
  • =0 to get index buffer from the grib file, if index doesn"t already exist.
  • <0 force reread of index from index file abs(lugi).
  • =lugb force regeneration of index from grib2 file lugb.
[in]Jinteger number of fields to skip (=0 to search from beginning)
[in]JDISCgrib2 discipline number of requested field (if = -1, accept any discipline see code table 0.0)
  • 0 meteorological products
  • 1 hydrological products
  • 2 land surface products
  • 3 space products
  • 10 oceanographic products
[in]JIDSinteger array of values in the identification section (=-9999 for wildcard)
  • JIDS(1) identification of originating centre (see common code table c-1)
  • JIDS(2) identification of originating sub-centre
  • JIDS(3) grib master tables version number (see code table 1.0) 0 experimental;1 initial operational version number.
  • JIDS(4) grib local tables version number (see code table 1.1) 0 local tables not used; 1-254 number of local tables version used.
  • JIDS(5) significance of reference time (code table 1.2) 0 analysis; 1 start of forecast; 2 verifying time of forecast; 3 observation time
  • JIDS(6) year (4 digits)
  • JIDS(7) month
  • JIDS(8) day
  • JIDS(9) hour
  • JIDS(10) minute
  • JIDS(11) second
  • JIDS(12) production status of processed data (see code table 1.3) 0 operational products; 1 operational test products; 2 research products; 3 re-analysis products.
  • JIDS(13) type of processed data (see code table 1.4) 0 analysis products; 1 forecast products; 2 analysis and forecast products; 3 control forecast products; 4 perturbed forecast products; 5 control and perturbed forecast products; 6 processed satellite observations; 7 processed radar observations.
[in]JPDTNinteger product definition template number (n) (if = -1, don't bother matching pdt - accept any)
[in]JPDTinteger array of values defining the product definition template 4.n of the field for which to search (=-9999 for wildcard)
[in]JGDTNinteger grid definition template number (m) (if = -1, don't bother matching gdt - accept any )
[in]JGDTinteger array of values defining the grid definition template 3.m of the field for which to search (=-9999 for wildcard)
[in]UNPACKlogical value indicating whether to unpack bitmap/data
  • .TRUE. unpack bitmap and data values
  • .FALSE. do not unpack bitmap and data values
[out]Kinteger field number unpacked
[out]GFLDderived type grib_mod::gribfield.
[out]IRETinteger return code
  • 0 all ok
  • 96 error reading index
  • 97 error reading grib file
  • 99 request not found
  • other gf_getfld grib2 unpacker return code
Author
Mark Iredell
Date
1994-04-01

Definition at line 112 of file getgb2.F90.

References getgb2l(), getgb2r(), getgb2s(), getidx(), and gf_free().