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

Re: perl netCDF problem: reading character variables



Bill,

>Date: Mon, 19 Jul 1999 19:55:37 GMT
>From: "William C. Mattison" <address@hidden>
>Organization: NOAA/NWS
>To: address@hidden
>Subject: perl netCDF problem.
>Keywords: 199907191509.JAA17058

In the above message, you wrote:

> Thank-you for the fix.  The backslash worked.

Great!

> Now I have another problem:
> the imap calling argument in the NetCDF::vargetg call.  I'm trying to get
> a single string out of an array of a few thousand 5-character strings.  The
> variable $report_number is the row of the array I want to get.  What should
> $imap[0] and $imap[1] be?
> 
> Bill.

I doubt that you need NetCDF::vargetg() because you're not doing
anything weird with the indexes (e.g. transposition); consequently,
NetCDF::varget() should suffice.  Try something like this:

    @stationNameArray = ("\0" x $maxStaNamLen);
    @start = ($report_number, 0);
    @count = (1, $maxStaNamLen)
    NetCDF::varget($ncid, $varid, \@start, \@count, \@stationNameArray);
    $stationName = "";
    for ($j = 0; $j < $maxStaNamLen; $j++) {
        $chr = chr($stationNameArray[$j]);
        last if( $chr eq "\0" || $chr eq "\\" ) ;
        $stationName .= $chr ;
    }

Note that NetCDF::varget() returns strings as arrays of characters---so 
they have to be reformed back into strings.

--------
Steve Emmerson   <http://www.unidata.ucar.edu>