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

[netCDFPerl #UIB-497429]: varget problems



Alex,

> Full Name: Alex THEPAUT
> Email Address: address@hidden
> Organization: Capgemini
> Package Version:
> Operating System: Solaris/Linux
> Hardware:
> Description of problem: Hello,
> 
> I want to read variable values in a NetCdf file. I use the following script :
> 
> $l_file = NetCDF::open("$LATEST_DIRECTORY/$l_directory/$p_file", NOWRITE);
> $l_varId = NetCDF::varid($l_file, "LONGITUDE");
> NetCDF::varinq($l_file, $l_varId, \$l_name, \$l_datatype, \$l_dimCount, 
> \@l_dimIds, \$l_atts);
> 
> $l_dimSizes[$l_dimCount - 1] = undef;
> NetCDF::diminq($l_file, $l_dimIds[0], \$l_name, \$l_dimSizes[0]);
> NetCDF::varget($l_file, $l_varId, [0], [$l_dimSizes[0]], \@l_fileValues);
> 
> foreach $l_value (@l_fileValues)
> {
> print "Value $l_fileValues[$l_value]\n";
> }
> 
> The values I get are :
> 
> Value 0.992666661739349
> Value 0.992666661739349
> Value 0.992666661739349
> Value 0.992666661739349
> Value 0.484833329916
> Value -0.00499999988824129
> 
> But in the file, they are :
> LONGITUDE = 0.9926667, 0.4848333, -0.005, -0.5225, 1.254, 2.887333 ;
> 
> When I do the same with the variables LATITUDE or TIME, the returned values 
> are blank. In the file they are as follows :
> LATITUDE = 71.082, 71.38717, 71.69417, 72.0075, 72.30666, 72.6185 ;
> TIME = 22418.0970833333, 22418.2295833333, 22418.3539236111, 
> 22418.4977430556, 22418.717337963, 22418.913587963 ;
> 
> Could you help me ?

I assume the LONGITUDE variable is one-dimensional. Tell me if this is 
incorrect.

The NetCDF::varget() call, the "count" argument ([$l_dimSizes[0]]) appears to 
be a one-element, one-dimensional vector (which is correct) but with a value of 
"undef" -- which is probably not what you want. Get the size of the relevant 
dimension via the call

    NetCDF::diminq($l_file, $l_dimIds[0], \$l_name, \$l_size)

and then use that size to get the variable's values:

    NetCDF::varget($l_file, $l_varId, [0], [$l_size], \@l_fileValues);

> Best regards
> 
> Alex THEPAUT

Regards,
Steve Emmerson

Ticket Details
===================
Ticket ID: UIB-497429
Department: Support netCDF Perl
Priority: Normal
Status: Closed