Re: NetCDF/PERL and strings (or CHARs is you prefer)

On Fri, 12 Nov 1999, Steve Diggs wrote:

Robb,

I got your name from Steve Emmerson at Unidata.

My problem, I'm sure is a common one.  I'm not new to either NetCDF or
Perl, but I've only been using the Perl/NetCDF interface for a few days.
I'm having issues with the way that NetCDF treats string data.

For instance, I might have an array of scalars that looks like this:

@atmospheric_conditions = qw ( cloudy sunny fog rain );
@count_ac = ($#atmospheric_conditions);

This is close to my actual problem, so if I decide to write this arrayof
atmospeheric conditions to a NetCDF file, I would do the following:

my @start = (0);
my $varid_ac   = NetCDF::vardef($ncid, 'ATM_COND', NetCDF::CHAR, $dimid);

# .. then I leave define mode and write the data out

NetCDF::varput($ncid, $varid_ac, \@start, \@count_ac,
        \@atmospheric_conditions);

I will only get back: 'clo' (the 1st 3 chars from the 1st element of the
array above).  What's the deal?  How on earth do I encode variable length
strings in Perl arrays into NetCDF CHAR arrays?

Steve,

NetCDF doesn't handle variable length strings, you need to pad all strings
with nulls. The cdl files define the variable type and scope for all the
writes. If you download the decoders package and look at the netCDF perl
decoders as examples.  I will also send an attachment example.


Better yet, if I give
this outout NetCDF data set to someone unfamiliar with the data, what
gyrations do they have to go through in NetCDF/Perl to extract the values
correctly?

It would be better if you wrote the extraction process using NetCDF perl
or the NetCDF library. This package is not the easiest to use but once you
have some working examples then it make sense.

Robb...



I'm sure that you've answered this question before, so a solid example or
really good documentation would be sufficient.  BTW, where isn't it
apparent in the NetCDF-Perl documentation that the weirdness above happens
and what to do about it?

thanks,
-sd

p.s. I'll send you a piece of code that illustrates this behaviour in my
next message to you.

--
--------------------------------------------------------------------
Steve Diggs                                     Voice: (858)534-1108
Scripps Institution of Oceanography             FAX  : (858)534-7383
WOCE Hydrographic Program Office/STS            EMAIL: sdiggs@xxxxxxxx
9500 Gilman Drive                               WWW  : whpo.ucsd.edu
La Jolla, CA 92093-0214
--------------------------------------------------------------------


==============================================================================
Robb Kambic                                Unidata Program Center
Software Engineer III                      Univ. Corp for Atmospheric Research
rkambic@xxxxxxxxxxxxxxxx                   WWW: http://www.unidata.ucar.edu/
==============================================================================