[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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



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?  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?

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: address@hidden
9500 Gilman Drive                               WWW  : whpo.ucsd.edu
La Jolla, CA 92093-0214
--------------------------------------------------------------------