NAME

PDL::IO::Grib - Grib file utilities for perl

SYNOPSIS

use PDL;
use PDL::IO::Grib;

$gh = new PDL::IO::Grib;
$gh->readgrib("filename" [, $readdata]);
$gh->getfield("fieldname");
  

DESCRIPTION

Grib.pm allows the user to read files in the grib FORM FM 92-IX Ext. GRIB Edition 1 - it may not read all possible grib format combinations.

Grib::new

Grib::new creates a GribHandle, which is a reference to a newly created data structure. If it receives any parameters, they are passed to Grib::readgrib; if readgrib fails, the GribHandle object is destroyed. Otherwise, it is returned to the caller.

Grib::readgrib

Grib::readgrib accepts a GribHandle plus one or two parameters. With one parameter, it reads grib header information for all variables in the specified grib file. With two parameters, the first parameter is a filename, and the second parameter indicates that all of the data in the file should be read and decoded.

Grib::getfield

Grib::getfield accepts one parameter which is either the 5 field identifier for grib variables (pds[6]:pds[1]:pds[7]:pds[8]:pds[9] as defined in the grib format definition) or a variable name associated with that identifier as defined in the file .gribtables and returns the name and data field for that variable. Grib::getfield will check to see if the data has already been read into memory and will only read the file when this is not the case. The data field is returned as a PDL piddle or an array of PDL piddles where the identifier matchs more than one field.

Grib::showinventory

Grib::showinventory prints a list of variables found in the open file and names associated with them from the .gribtables file.

get_grib1_date()

Returns the initialization date from a grib file in the form yyyymmddhh. Takes either the file name or a valid Grib handle as an input argument.

.gribtables

The .gribtables file is searched for first in the working directory then in the user's home directory. The format is rather simple - anything following a # sign is a comment otherwise a

name:pds[6]:pds[1]:pds[7]:pds[8]:pds[9]

is expected where name can be anything as long as it begins with an alpha character and does not containb{:} and the pds[#] refers to the element number in the pds sector of the grib file. Fields 8 and 9 are optional in the file and if not found all of the records which match fields 6 1 7 will be combined into a single 3d dataset by getfield, unless the name passed in get field is modified by :pds[8]:pds[9] (or simply :pds[9]) which can be used to get a slice of what would otherwise be a 3d variable.

So suppose the file .gribtables contains the entry

T_PG:11:2:100

to specify 3d temperature on a pressure grid, then to get the 500mb pressure you would do

$t500 = $gh->getfield ("T_PG:500");

Author

Jim Edwards <jedwards@inmet.gov.br>