The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

  PDL::IO::Grib::Field - Field tools for Grib files

SYNOPSIS

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

       $gh = new PDL::IO::Grib;
       $gh->readgrib("filename");
       $gh->getfield("fieldname");
       $f = $gh->anyfield();

DESCRIPTION

Field.pm gives you access to the individual fields of a Grib file. Here is the code that attempts to decipher each of the sections associated with the format. All of the data is read into PDLs (one for each section) and it only deciphers those pdls on demand. It only knows how to decipher a small subset of the possibilities at this time, but should allow the developer to write and test new or local decipher methods easily. Of course if you write a new method and can cleanly merge it with whats working please feel free to send it back to me.

FUNCTIONS

new

PDL::IO::Grib::Field new creates a new Field structure hash and if passed an open file handle reads the next grib record into that structure. It reads each of the sections into a PDL.

name

$f->name('fred') assigns the name fred to field, $name = $f->name(); retreves the name of $f if it has one. Initial names are read from Gribtables.pm

id

  It takes 5 fields to uniquely identify a grib variable we concatinate these
  fields return them, Grib.pm uses this to identify each variable

initialize

Should only be called from new - reads a Grib record from a file handle

read_section

read_section is an internal subroutine to read a record section from a grib file it expects a file handle and an optional flag to tell it that the bds section is being read. We only read the first 16 bytes of the bds.

pds_has_octet12

Returns true if pds octet 10 indicates that octet 11 is one byte and octet 12 is a seperate field, returns 0 otherwise

pds_attribute

$f->pds_attribute($num) returns the value of the PDS field which begins at octet $num. You really need to have the Grib document (http://www.wmo.ch/web/www/reports/Guide-binary-2.html) in hand to use these things. If this function recognizes that a value beginning at octet $num spans several octets and really takes another form, it decodes and returns that value. The default is to return the unsigned integer value of the byte at that octet. In a few cases it recognizes that no value exists for a given octet and returns undef.

gds_attribute

see the pds_attribute description

bms_attribute

see the pds_attribute description

bds_attribute

see the pds_attribute description

section_dump

section_dump returns a string which includes the entire contents of the specified section, except in the case of the BDS where it only includes the first 16 bytes. It is a little braindead - if I know that octet 42 is really a list of 21 float values I return a pdl of 21 values from octet 42 but I also return octets 43 - 126 as well.

PDL::packint3

Given an integer value this packs it into a 3 byte PDL. The optional signed flag causes a signed pack.

PDL::unpackint3

Given a PDL of 3 bytes unpacks into a integer, if the signed flag is on the highest bit indicates sign of the output value.

PDL::packint2

Packs the integer passed in $val into a two byte pdl optionally setting the signed flag if the signed option is defined.

PDL::unpackint2

Given a PDL of 2 bytes unpacks into a integer, if the signed flag is on the highest bit indicates sign of the output value.

Given a PDL of length $cnt unpacks into a integer.

gds_vertical_parameters

Function to decode the vertical parameter field if present. Convenience function, could be done with gds_attribute directly.

read_data

Decode the data section of a grib record. Currently only handles grid point simple packing, but should be able to handle any number of bits per value.

write_bds

Write the bds section and encoded data to a filehandle (fh), recomputes the data minimum and scale value before packing.

write

Write a complete grib record.