NCEPLIBS-g2c  1.8.0
g2_getfld.c File Reference

Return all the metadata, template values, Bit-map (if applicable), and the unpacked data for a given data field. More...

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

Go to the source code of this file.

Functions

g2int g2_getfld (unsigned char *cgrib, g2int ifldnum, g2int unpack, g2int expand, gribfield **gfld)
 This subroutine returns all the metadata, template values, bit-map (if applicable), and the unpacked data for a given data field. More...
 

Detailed Description

Return all the metadata, template values, Bit-map (if applicable), and the unpacked data for a given data field.

Author
Stephen Gilbert
Date
2002-10-28

Definition in file g2_getfld.c.

Function Documentation

◆ g2_getfld()

g2int g2_getfld ( unsigned char *  cgrib,
g2int  ifldnum,
g2int  unpack,
g2int  expand,
gribfield **  gfld 
)

This subroutine returns all the metadata, template values, bit-map (if applicable), and the unpacked data for a given data field.

All of the information returned is stored in a gribfield structure, which is defined in file grib2.h. Users of this routine will need to include grib2.h in their source code that calls this 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.

Program History Log

Date Programmer Comments
2002-10-28 Gilbert Initial
2013-08-08 Vuong Free up memory in array igds - free(igds)
Parameters
cgribCharacter pointer to the GRIB2 message.
ifldnumSpecifies which field in the GRIB2 message to return. The first field is number 1, Fortran style.
unpackBoolean value indicating whether to unpack bitmap/data field.
  • 1 unpack bitmap (if present) and data values.
  • 0 do not unpack bitmap and data values.
expandBoolean value indicating whether the data points should be expanded to the correspond grid, if a bit-map is present. This argument is ignored if unpack == 0 OR if the returned field does not contain a bit-map.
  • 1 if possible, expand data field to grid, inserting zero values at gridpoints that are bitmapped out. (SEE REMARKS2)
  • 0 do not expand data field, leaving it an array of consecutive data points for each "1" in the bitmap.
gfldpointer to structure gribfield containing all decoded data for the data field.
Returns
Note
Struct gribfield is allocated by this routine and it also contains pointers to many arrays of data that were allocated during decoding. Users are encouraged to free up this memory, when it is no longer needed, by an explicit call to routine g2_free().

Example:

#include "grib2.h"
gribfield *gfld;
ret=g2_getfld(cgrib,1,1,1,&gfld);
...
g2_free(gfld);
g2int g2_getfld(unsigned char *cgrib, g2int ifldnum, g2int unpack, g2int expand, gribfield **gfld)
This subroutine returns all the metadata, template values, bit-map (if applicable),...
Definition: g2_getfld.c:91
Header file for NCEPLIBS-g2c library.
Struct for GRIB field.
Definition: grib2.h:47

Routine g2_info() can be used to first determine how many data fields exist in a given GRIB message.

Note
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 would be set to 0 (false), regardless of the value of input argument expand.
Author
Stephen Gilbert
Date
2002-10-28

Definition at line 91 of file g2_getfld.c.

References gribfield::bmap, gribfield::coord_list, gribfield::discipline, gribfield::expanded, gribfield::fld, g2_free(), G2_GETFLD_BAD_END, G2_GETFLD_BAD_SEC1, G2_GETFLD_BAD_SEC2, G2_GETFLD_BAD_SEC3, G2_GETFLD_BAD_SEC4, G2_GETFLD_BAD_SEC5, G2_GETFLD_BAD_SEC6, G2_GETFLD_BAD_SEC7, G2_GETFLD_GRIB_VERSION, G2_GETFLD_INVAL, G2_GETFLD_INVAL_SEC, G2_GETFLD_NO_BITMAP, G2_GETFLD_NO_GRIB, G2_GETFLD_WRONG_END, G2_GETFLD_WRONG_NFLDS, G2_NO_ERROR, g2_unpack1(), g2_unpack2(), g2_unpack3(), g2_unpack4(), g2_unpack5(), g2_unpack6(), g2_unpack7(), gbit(), gribfield::griddef, gribfield::ibmap, gribfield::idrtlen, gribfield::idrtmpl, gribfield::idrtnum, gribfield::idsect, gribfield::idsectlen, gribfield::ifldnum, gribfield::igdtlen, gribfield::igdtmpl, gribfield::igdtnum, gribfield::interp_opt, gribfield::ipdtlen, gribfield::ipdtmpl, gribfield::ipdtnum, gribfield::list_opt, gribfield::local, gribfield::locallen, gribfield::ndpts, gribfield::ngrdpts, gribfield::num_coord, gribfield::num_opt, gribfield::numoct_opt, gribfield::unpacked, and gribfield::version.