Jim Edwards

NAME

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

SYNOPSIS

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

       $gh = new PDL::IO::Grib;
       $gh->readgrib("filename");
       $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. The Grib format has 4 sections (PDS, GDS, BMS, BDS), two of which (GDS, BMS) are optional. Each field of a section is described in the definition by an offset in bytes from the beginning of the section and a length. The contents of each field can vary widely according to the center of origin of the data. This decoder reads the entire section into a PDL and only decodes fields on request, it has a default decoding method and allows the user to define methods not known to this decoder. So for example, the first 3 bytes of the PDS section describes the length of that section, each of the next 10 bytes can be decoded as unsigned integers. Bytes 11 and 12 may be two seperate integers or one two-byte integer depending on the value of byte 10. It gets worse from there...

FUNCTIONS

new

PDL::IO::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 Grib Object and a filename. It reads grib header information for all variables in the specified grib file.

Grib::getfield

Grib::getfield accepts one parameter which is either the 5 field identifier for grib variables (pds octets 9:4:10:11:12 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 can be returned as a 2 or 3 Dimensional PDL piddle or an array of PDL piddles where the identifier matchs more than one field. If an array or a 3D piddle is returned it is sorted from the largest value to the smallest value of octets 11:12. getfield uses wantarray to return what you ask for.

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.

anyfield

  $gh->anyfield(); returns a reference to an arbitrary field of gh

.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[9]:pds[4]:pds[10]:pds[11]:pds[12]

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 octet number in the pds sector of the grib file. Fields 11 and 12 are optional in the file and if not found all of the records which match fields 9 4 10 will be combined into a single 3d dataset by getfield

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>




Hosting generously
sponsored by Bytemark