NCEPLIBS-g2  3.5.0
g2gf.F90 File Reference

Subroutines to write and get a field and free memmory from grib_mod::gribfield. More...

Go to the source code of this file.

Functions/Subroutines

subroutine gf_free (gfld)
 Free memory that was used to store array values in derived type grib_mod::gribfield. More...
 
subroutine gf_getfld (cgrib, lcgrib, ifldnum, unpack, expand, gfld, ierr)
 Return the Grid Definition, and Product Definition for a given data field. More...
 
subroutine putgb2 (lugb, gfld, iret)
 Pack a field into a grib2 message and write that message to a file. More...
 

Detailed Description

Subroutines to write and get a field and free memmory from grib_mod::gribfield.

Author
Edward Hartnett
Date
Mar 6, 2024

Definition in file g2gf.F90.

Function/Subroutine Documentation

◆ gf_free()

subroutine gf_free ( type(gribfield gfld)

Free memory that was used to store array values in derived type grib_mod::gribfield.

Parameters
gfldderived type grib_mod::gribfield.
Author
Stephen Gilbert
Date
2000-05-26

Definition at line 584 of file g2gf.F90.

Referenced by getgb2i2(), getgb2p2(), and gf_getfld().

◆ gf_getfld()

subroutine gf_getfld ( character(len = 1), dimension(lcgrib), intent(in)  cgrib,
integer, intent(in)  lcgrib,
integer, intent(in)  ifldnum,
logical, intent(in)  unpack,
logical, intent(in)  expand,
type(gribfield), intent(out)  gfld,
integer, intent(out)  ierr 
)

Return the Grid Definition, and Product Definition for a given data field.

All of the information returned is stored in a derived type variable, gfld. Gfld is of type grib_mod::gribfield, which is defined in gribmod.F90; users of this routine will need to include the line "USE GRIB_MOD" in their calling routine.

Since there can be multiple data fields packed into a GRIB2 message, the calling routine indicates which field is being requested with the ifldnum argument.

Parameters
[in]cgribCharacter array that contains the GRIB2 message.
[in]lcgribLength (in bytes) of GRIB message array cgrib.
[in]ifldnumSpecifies which field in the GRIB2 message to return.
[in]unpackLogical value indicating whether to unpack bitmap/data. .true. = unpack bitmap and data values; .false. = do not unpack bitmap and data values.
[in]expandBoolean value indicating whether the data points should be expanded to the correspond grid, if a bit-map is present.
  • 1 if possible, expand data field to grid, inserting zero values at gridpoints that are bitmapped out.
  • 0 do not expand data field, leaving it an array of consecutive data points for each "1" in the bitmap. This argument is ignored if unpack == 0 OR if the returned field does not contain a bit-map.
[out]gfldderived type grib_mod::gribfield.
[out]ierrError return code.
  • 0 no error.
  • 1 Beginning characters "GRIB" not found.
  • 2 GRIB message is not Edition 2.
  • 3 The data field request number was not positive.
  • 4 End string "7777" found, but not where expected.
  • 5 End string "7777" not found at end of message.
  • 6 GRIB message did not contain the requested number of data fields.
  • 7 End string "7777" not found at end of message.
  • 9 Data Representation Template 5.NN not yet implemented.
  • 10 Error unpacking Section 3.
  • 11 Error unpacking Section 4.
  • 12 Error unpacking Section 5.
  • 13 Error unpacking Section 6.
  • 14 Error unpacking Section 7.
  • 17 Previous bitmap specified, but none exists.
Note
Note that derived type grib_mod::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(). Subroutine gb_info() can be used to first determine how many data fields exist in a given GRIB message.

It may not always be possible to expand a bit-mapped data field. If a pre-defined bit-map is used and not included in the GRIB2 message itself, this routine would not have the necessary information to expand the data. In this case, gfld%expanded would be set to 0 (false), regardless of the value of input argument expand.

Author
Stephen Gilbert
Date
2000-05-26

Definition at line 210 of file g2gf.F90.

References g2_gbytec(), gf_free(), gf_unpack1(), gf_unpack2(), gf_unpack3(), gf_unpack4(), gf_unpack5(), gf_unpack6(), and gf_unpack7().

◆ putgb2()

subroutine putgb2 ( integer, intent(in)  lugb,
type(gribfield), intent(in)  gfld,
integer, intent(out)  iret 
)

Pack a field into a grib2 message and write that message to a file.

The information to be packed into the grib field is stored in a derived type variable, gfld. gfld is of type grib_mod::gribfield, which is defined in module grib_mod, so users of this routine will need to include the line "use grib_mod" in their calling routine. Each component of the gribfield type is described in the input argument list section below.

Note
Derived type gribfield contains pointers to many arrays of data (See grib_mod::gribfield). The memory for these arrays is allocated when the values in the arrays are set. Users must 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 baopenw() before calling this routine.
[in]gfldderived type grib_mod::gribfield.
[out]iretinteger return code
  • 0 No error.
  • 2 Memory allocation error.
  • 10 No Section 1 info available.
  • 11 No Grid Definition Template info available.
  • 12 Missing some required data field info.
Author
Stephen Gilbert
Date
2002-04-22

Definition at line 34 of file g2gf.F90.

References addfield(), addgrid(), addlocal(), gribcreate(), and gribend().