The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.

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

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

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::unpackint

Given a byte pdl and a cnt this function computes an integer representation for that (cnt) number of bytes. There are several 3 byte integers in Grib.

gds_vertical_parameters

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