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

NAME

PDL::NetCDF - Interface NetCDF files to PDL objects.

Perl extension to allow interface to NetCDF portable binary gridded files via PDL objects.

SYNOPSIS

  # This is the 'traditional' interface for reading and writing NetCDF from/into PDLs:

  use PDL;
  use PDL::NetCDF qw(/^nc/ /^NC_/);
  $ncid   = nccreate('file.nc', NC_CLOBBER);
  $dim1id = ncdimdef($ncid, 'Dim1', 3);
  $var1id = ncvardef($ncid, 'Var1', NC_FLOAT, [$dim1id]);
  ncendef($ncid);
  ncvarput($ncid, $var1id, [0], [3], float [0..2]);
  ncclose($ncid);

  ...

  $ncid  = ncopen('file.nc', NC_RDWR);
  $dimid = ncdimid($ncid, 'Dim1');
  $varid = ncvarid($ncid, 'Var1');
  $p1    = ncvarget($ncid, $varid, [0], [3]); 
   
  print $p1; # This is a PDL object of type float
  # yields [0, 1, 2]


  # This is the object oriented interface (for reading only):

  use PDL;
  use PDL::NetCDF;
  $obj = NetCDF::PDL->new ('file.nc');

  $p1  = $obj->get('Var1');
  print $p1;
  # yields [0, 1, 2]

  $dimsize = $obj->dimsize('dimname');

  # This attribute will be a PDL or a string depending on its NetCDF type.
  $attribute = $obj->getatt('attname', 'varname');

  # One can also get global attributes using:
  $global_attribute = $obj->getatt('attname');


  For (much) more information on NetCDF, see 

  http://www.unidata.ucar.edu/packages/netcdf/index.html
  
  Also see the test file, test.pl in this distribution.

DESCRIPTION

This is the PDL interface to the Unidata NetCDF library. It is largely a copy of the original netcdf-perl (available through Unidata at http://www.unidata.ucar.edu/packages/netcdf/index.html).

The NetCDF standard allows N-dimensional binary data to be efficiently stored, annotated and exchanged between many platforms.

The original interface has been left largely intact (see the netcdf users manual, available at the above URL for more information. The manual documents the C interface, but the perl interface is almost identical) except for two functions:

ncvarget (get a hyperslab of data) and ncvarput (put a hyperslab of data).

These two have been modified to receive and deliver PDL objects. (The originals returned one-dimensional perl lists, which was quite inefficient for large data sets. The flattening of N dimensional data was also irksome).

This version of the PDL interface also offers an object-oriented read-only interface to NetCDF. One must still write NetCDF files using the old style interface, but reading of NetCDF files is considerably simplified.

Use the function:

PDL::NetCDF->new ('file.nc')

to create a NetCDF file object. Then use

$obj->get('varname') $obj->getatt ('attname', 'varname')

to get variables or attributes into PDLs.

AUTHOR

Doug Hunt, dhunt@ucar.edu for the PDL version. Steve Emmerson (UCAR UniData) for the original version

SEE ALSO

perl(1), netcdf(3).