NCEPLIBS-g2c  1.8.0
g2_addfield.c File Reference

Pack up Sections 4 through 7 for a given field and adds them to a GRIB2 message. More...

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

Go to the source code of this file.

Functions

g2int g2_addfield (unsigned char *cgrib, g2int ipdsnum, g2int *ipdstmpl, float *coordlist, g2int numcoord, g2int idrsnum, g2int *idrstmpl, float *fld, g2int ngrdpts, g2int ibmap, g2int *bmap)
 This routine packs up Sections 4 through 7 for a given field and adds them to a GRIB2 message. More...
 

Detailed Description

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

Author
Stephen Gilbert
Date
2002-11-05

Definition in file g2_addfield.c.

Function Documentation

◆ g2_addfield()

g2int g2_addfield ( unsigned char *  cgrib,
g2int  ipdsnum,
g2int ipdstmpl,
float *  coordlist,
g2int  numcoord,
g2int  idrsnum,
g2int idrstmpl,
float *  fld,
g2int  ngrdpts,
g2int  ibmap,
g2int bmap 
)

This routine packs up Sections 4 through 7 for a given field and adds them to a GRIB2 message.

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

This routine is used with routines g2_create(), g2_addlocal(), g2_addgrid(), and g2_gribend() to create a complete GRIB2 message. Function g2_create() must be called first to initialize a new GRIB2 message. Function g2_addgrid() must be called after g2_create() and before this routine to add the appropriate grid description to the GRIB2 message. A call to g2_gribend() is required to complete GRIB2 message after all fields have been added.

Program History Log

Date Programmer Comments
2002-11-05 Gilbert Initial
2002-12-23 Gilbert Added complex spherical harmonic packing
2003-08-27 Gilbert Added support for new templates using PNG and JPEG2000 algorithms/templates.
2004-11-29 Gilbert JPEG2000 now can use WMO Template 5.40 PNG can use WMO Template 5.41. Added packing algorithm check.
2005-05-10 Gilbert Imposed minimum size on cpack.
2009-01-14 Vuong Changed structure name template to gtemplate
2023-09-08 Engle Added support for new template, 5.42, using CCSDS compression (libaec).
Parameters
cgribChar array that contains the GRIB2 message to which sections 4 through 7 should be added. Must be allocated large enough to store the entire GRIB2 message.
ipdsnumProduct Definition Template Number (see Code Table 4.0).
ipdstmplContains the data values for the Product Definition Template specified by ipdsnum.
coordlistArray containg floating point values intended to document the vertical discretisation associated to model data on hybrid coordinate vertical levels.
numcoordnumber of values in array coordlist.
idrsnumData Representation Template Number (see Code Table 5.0).
idrstmplThe 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.
fldArray of data points to pack.
ngrdptsNumber of data points in grid. i.e. size of fld and bmap.
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.
bmapInteger array containing bitmap to be added (if ibmap = 0).
Returns
Note
Note that the Sections 4 through 7 can only follow Section 3 or Section 7 in a GRIB2 message.
Author
Stephen Gilbert
Date
2002-11-05

Definition at line 99 of file g2_addfield.c.

References aecpack(), cmplxpack(), gtemplate::ext, gtemplate::extlen, extpdstemplate(), G2_ADD_MSG_COMPLETE, G2_ADD_MSG_INIT, G2_ADDFIELD_BAD_BITMAP, G2_ADDFIELD_BAD_DRT, G2_ADDFIELD_BAD_GDS, G2_ADDFIELD_BAD_GDT, G2_ADDFIELD_BAD_PDT, G2_ADDFIELD_ERR, G2_BAD_SEC, G2_BAD_SEC_COUNTS, g2c_check_msg(), G2C_EMSGCOMPLETE, G2C_ENOTGRIB, gbit(), getdim(), getdrstemplate(), getpdstemplate(), getpoly(), jpcpack(), gtemplate::map, gtemplate::maplen, mkieee(), gtemplate::needext, pngpack(), sbit(), sbits(), simpack(), and specpack().