Contact: zeng  @  zegraph.com     Last update: 8 May 2008

GRIB Library

The grib library has three functions for decoding data in format of GRIB-1, GRIB-2, or DGRB (Japanese Domestric Grid Binary format). GRIB-1 code is borrowed from wgrib.c and GRIB-2 code from NCEP library.

Function Parameter Type Remark
g2unpack(fname[, fsec0, fsec1, fsec2, fsec3, fsec4, fsec5, fsec6, fsec7]) strings

Unpacks GRIB2 data. The fname must be a GRIB file name and the optional parameters of fsec0 to fsec7 must be callback function names. Those functions will be called when a corresponding section message is found:

  • fsec0 -> To be called with a code in Code Table 0.0 of GRIB2 specification.
  • fsec1 -> To be called with three inputs: a integer pointer (C/C++ int) to message data, the number of data, and bytes of a integer datum. The pointer contains decoded Section-1 messages (octets 6-21).
  • fsec2 -> To be called with the same type of inputs as those of fcec1. The pointer contains decoded local section data.
  • fsec3 -> To be called with three sets of integer pointers adn integers similar to those of fsec1. The first pointer contains decoded Section-3 message (octets 6-14); the second contains decoded Grid Definition Template data; and the third (may be empty) contains grid points for each row for irregular grid.
  • fsec4 -> To be called with a integer for Product Definition Template Number (Code Table 4.0) and two sets of integer pointers and integers similar to those of fsec1. The first pointer contains decoded Product Definition Template data and the second contains decoded floating point values intended to document the vertical discretisation associated to model data on hybrid coordinate vertical levels.
  • fsec5 -> To be called with integer for Data Representation Template Number (Code Table 5.0) and one set of float pointer and integers similar to those of fsec7. The pointer contains floating point values of Data Representation Template.
  • fsec7 -> To be called with three inputs: a float (C/C++ float) pointer to decoded binary data, the number of data, and bytes of a float datum. The pointer contains decoded binary data.
g1unpack(fname[, fsec1, fsec2, fsec3, fsec4]) strings Unpacks GRIB1 data. The fname must be a GRIB file name and the optional parameters of fsec1 to fsec4 must be callback function names (the functions will be called when a corresponding section message is found):
  • fsec1 -> To be called with three inputs: an unsigned char pointer to raw Section-1 message data, the number of data, and bytes of a integer datum.
  • fsec2 -> To be called with the same type of inputs as those of fsec1.
  • fsec3 -> To be called with the same type of inputs as those of fsec1.
  • fsec4 -> To be called with three inputs: a float pointer to decoded binary data, the number of data, and bytes of a float datum.
dgunpack(fname[, func]); strings The fname must be a DGRB file name and the optional func must be a callback function name. The function will be called with six inputs: integer pointer to DGRB message, number of data, and bytes of a datum; and float pointer to decoded binary data, number of data, and bytes of a float datum
qregular(src, region, dst) user, integer, user Converts data on quasi-regular (thinned latitude/longitude) grids to regular grids. The src is a float-type pointer to 3447 data; the region code is from 37 to 44; and the dst is float-type pointer to 73x73 data.

Example-1

load("grib.dll");
g2unpack("grid_file_name");
g2unpack("grid_file_name", "fsec0", "fsec1", "fsec2", "fsec3", "fsec4", "fsec5", "fsec6", "fsec7");

function fsec0(tid)
{
    csv("sec0", tid);
}

function fsec1(ptr, n, e)
{
    csv("sec1", ptr, n, e);
}

function fsec2(ptr, n, e)
{
    csv("sec2", ptr, n, e);
}

function fsec3(ptr1, n1, e1, ptr2, n2, e2, ptr3, n3, e3)
{
    csv("sec3", ptr1, n1, e1, ptr2, n2, e2, ptr3, n3, e3);
}

function fsec4(tid, ptr1, n1, e1, ptr2, n2, e2)
{
    csv("sec4", tid, ptr1, n1, e1, ptr2, n2, e2);
}

function fsec5(tid, ptr, n, e)
{
    csv("sec5", tid, ptr, n, e);
}

function fsec6(tid, ptr, n, e)
{
    csv("sec6", tid, ptr, n, e);
}

function fsec7(ptr, n, e)
{
    csv("sec7", ptr, n, e);
}

Example-2

load("grib.dll");
g1unpack("grid_file_name");
g1unpack("grid_file_name", "fsec1", "fsec2", "fsec3", "fsec4");

function fsec1(ptr, n, e)
{
    csv("sec1", ptr, n, e);
}

function fsec2(ptr, n, e)
{
    csv("sec2", ptr, n, e);
}

function fsec3(ptr, n, e)
{
    csv("sec3", ptr, n, e);
}

function fsec4(ptr, n, e)
{
    csv("sec4", ptr, n, e);
}

Example-3

load("grib.dll");
dgunpack("grid_file_name");
dgunpack("grid_file_name", "callback");

function callback(ptr1, n1, e1, ptr2, n2, e2)
{
    csv(ptr1, n1, e1, ptr2, n2, e2);
}