Re: perl interface problem, plus ncdump oddity

On Tue, Sep 16, 2003 at 11:20:13AM -0400, Jason Thaxter wrote:
> I've found two odd problems with NetCDF tools recently.  I suspect they are
> related to compiler and perl versions, but I don't really know.
> 
> 1) ----------------------------------------------------
> 
> The Perl interface issue involves values retrieved by NetCDF::recget.  The
> variable is a scalar of type BYTE.  Perl always thinks it has a zero (0), even

I figured out this particular problem; the perl-netcdf library does not appear
to be misbehaving at all, though it does things that might trap an unwary -
and at least in this case, fairly wary - perl programmer.

Variables of the NetCDF::BYTE type cannot be immediately used as perl
variables.  They will end up looking like "^A" or "^@" or something else when
you try to use them as strings; worse, if you look at them as numbers, they
will always appear to be zero.

Suppose that $value is an actual single value retrieved from
attget/varget/recget.  To use a NetCDF::BYTE properly, do this

        $value =  unpack('C',$value);

I put this trick into a wrapper module I've written around NetCDF, called
GoMOOS::NetCDF.  There are a number of other tricks there, too - initializing
arrays before passing them to NetCDF functions, retrieving variables by names
instead of index number, etc.  I wouldn't say it's complete or flawless; it's
a little inconsistent about return values, and it's probably more useful for
taking a record-oriented view than a variable-oriented view, and it's totally
useless for writing NetCDF files.

Nevertheless, anyone using perl-netcdf may find it useful and so I've
attached it to this message.  If the attachment doesn't make it through
majordomo onto the list, feel free to e-mail me for a copy.

Thanks,
Jason

-- 
----------------------------------------------
Jason Thaxter
GoMOOS, P.O. Box 4919, Portland, ME 04112-4919
Office Location: 1 Canal Plaza, 7th Floor
Office: 207.773.0423
Fax:    207.773.8672
Email:  thaxter@xxxxxxxxxx
------------www.gomoos.org--------------------

Attachment: NetCDF.pm
Description: Perl program

  • 2003 messages navigation, sorted by:
    1. Thread
    2. Subject
    3. Author
    4. Date
    5. ↑ Table Of Contents
  • Search the netcdfgroup archives: