Back to Philip's IMMA page.
IMMA.pm
IMMA.pm is a Perl module allowing IMMA records to be used by Perl scripts. It provides methods for reading and writing IMMA files and for manipulating IMMA records.IMMA records are objects with the usual Perl properties. Data values are accessible through the object. I.e. if the object is $record ($record = new IMMA;) the observation year is stored as $record->{YR}, the sea-surface temperature is $record->{SST}, and the wet-bulb temperature indicator is $record->{WBTI}. The elements available are those listed in the IMMA documentation, but note that they are not all guaranteed to be available: if the record has no SST given, $record->{SST} will be undefined.
Methods
- new: Create a new IMMA object
Usage: $record = new IMMA;
All the data are initially undefined. - imma_read: read in an IMMA record from a file (class method)
Usage: $record = imma_read(\*DIN) or die "Couldn't read in IMMA data";
where DIN is a filehandle for an IMMA file (open(DIN,"file.imma");). This method is exported by default. - read: read in an IMMA record from a file (instance method)
Usage: $record->read(\*DIN) or die "Couldn't read in IMMA data";
where DIN is a filehandle for an IMMA file (open(DIN,"file.imma");) - write: write_out an IMMA record to a file (instance method)
Usage: $record->write(\*DOUT) or die "Couldn't output IMMA data";
where DOUT is a filehandle for an IMMA file (open(DOUT,">file.imma");)
Examples
The following example reads in all IMMA fields from the file "old.imma", selects all the records with a known SST and where the latitude is greater than 0 and the longitude is between -70 and 10 (in the North Atlantic) and writes them out to the file "new.imma".
use IMMA;
open(DIN,"old.imma");
open(DOUT,">new.imma");
while($record = imma_read(\*DIN)) {
if(defined($record->{SST}) &&
defined($record->{LAT}) && $record->{LAT}>0 &&
defined($record->{LON}) && $record->{LON}>=-70 && $record->{LON}<=10) {
$record->write(\*DOUT);
}
}