Skip Menu |

This queue is for tickets about the PDL-NetCDF CPAN distribution.

Report information
The Basics
Id: 67776
Status: open
Priority: 0/
Queue: PDL-NetCDF

People
Owner: Nobody in particular
Requestors: gfu [...] sigmaspace.com
Cc:
AdminCc:

Bug Information
Severity: (no value)
Broken in: (no value)
Fixed in: (no value)



Subject: NetCDF - Cannot write _FillValue attribute
Date: Tue, 26 Apr 2011 16:46:24 -0400
To: <bug-PDL-NetCDF [...] rt.cpan.org>
From: Gary Fu <gfu [...] sigmaspace.com>
Hi, I'm using NetCDF version 4.07 with NetCDF4 support. In the example below, I tried to write the '_FillValue' attribute to a variable. It works if I open the file with the default format (NC_FORMAT_CLASSIC), but it fails if I use the format NC_FORMAT_NETCDF4_CLASSIC. Is this a bug or a feature that I don't know about it. Thanks, Gary 4:39pm 840 gfu@sigma-113:~/modaps/modis2netcdf$ uname -a Linux sigma-113.hbsss.local 2.6.18-164.el5 #1 SMP Thu Sep 3 03:28:30 EDT 2009 x86_64 x86_64 x86_64 GNU/Linux 4:38pm 838 gfu@sigma-113:~/modaps/modis2netcdf$ perl -e 'use PDL::NetCDF; print "$PDL::NetCDF::VERSION\n"' 4.07 4:38pm 839 gfu@sigma-113:~/modaps/modis2netcdf$ perl -e 'use PDL::NetCDF; print "NetCDF4\n" if (PDL::NetCDF::isNetcdf4)' NetCDF4 --------------------------------------------------------------------------------- #! /usr/local/bin/perl -w use strict; use PDL; use PDL::NetCDF; my ($nc_file) = @ARGV; #my $nc = PDL::NetCDF->new ($nc_file, {REVERSE_DIMS => 1}); #my $nc = PDL::NetCDF->new ($nc_file, {NC_FORMAT=>PDL::NetCDF::NC_FORMAT_CLASSIC}); my $nc = PDL::NetCDF->new ($nc_file, {NC_FORMAT=>PDL::NetCDF::NC_FORMAT_NETCDF4_CLASSIC}); my $sds_name = 'Longitude'; my @dim_names = ('X', 'Y'); my $data = float zeros(100,100); $nc->put ($sds_name, \@dim_names, $data); my $attr_name = '_FillValue'; my $attr_val = float pdl [999.]; $nc->putatt ($attr_val, $attr_name, $sds_name); $nc->close(); --------------------------------------------------------------------------------------- 4:30pm 830 gfu@sigma-113:~/modaps/modis2netcdf$ t.pl x.nc putatt: Cannot put PDL attribute -- NetCDF: Attempt to define fill value when data already exists. at t.pl line 24
Hi Gary, this is unfortunately a change in the underlying netcdf-C library, where changes to _FillValue no longer work in 'redefine' mode, and PDL::NetCDF writes all attributes in 'redefine'-mode. A quickfix might be to use missing-value instead of _FillValue. This should, but is not supported by all netcdf-readers (it is by PDL::NetCDF). Otherwise, I think about a way of setting _FillValue on variable-creation (i.e. first put/putslice). Heiko Am Di 26. Apr 2011, 16:51:09, gfu@sigmaspace.com schrieb: Show quoted text
> Hi, > > I'm using NetCDF version 4.07 with NetCDF4 support. > In the example below, I tried to write the '_FillValue' attribute to > a > variable. It works if I open the file with the default format > (NC_FORMAT_CLASSIC), but it fails if I use the format > NC_FORMAT_NETCDF4_CLASSIC. Is this a bug or a feature that I don't > know > about it. > > Thanks, > Gary > > 4:39pm 840 gfu@sigma-113:~/modaps/modis2netcdf$ uname -a > Linux sigma-113.hbsss.local 2.6.18-164.el5 #1 SMP Thu Sep 3 03:28:30 > EDT > 2009 x86_64 x86_64 x86_64 GNU/Linux > > 4:38pm 838 gfu@sigma-113:~/modaps/modis2netcdf$ perl -e 'use > PDL::NetCDF; print "$PDL::NetCDF::VERSION\n"' > 4.07 > 4:38pm 839 gfu@sigma-113:~/modaps/modis2netcdf$ perl -e 'use > PDL::NetCDF; print "NetCDF4\n" if (PDL::NetCDF::isNetcdf4)' > NetCDF4 > > --------------------------------------------------------------------------------- > #! /usr/local/bin/perl -w > > use strict; > > use PDL; > use PDL::NetCDF; > > my ($nc_file) = @ARGV; > > #my $nc = PDL::NetCDF->new ($nc_file, {REVERSE_DIMS => 1}); > #my $nc = PDL::NetCDF->new ($nc_file, > {NC_FORMAT=>PDL::NetCDF::NC_FORMAT_CLASSIC}); > my $nc = PDL::NetCDF->new ($nc_file, > {NC_FORMAT=>PDL::NetCDF::NC_FORMAT_NETCDF4_CLASSIC}); > > my $sds_name = 'Longitude'; > > my @dim_names = ('X', 'Y'); > > my $data = float zeros(100,100); > $nc->put ($sds_name, \@dim_names, $data); > > my $attr_name = '_FillValue'; > my $attr_val = float pdl [999.]; > $nc->putatt ($attr_val, $attr_name, $sds_name); > > $nc->close(); > > --------------------------------------------------------------------------------------- > 4:30pm 830 gfu@sigma-113:~/modaps/modis2netcdf$ t.pl x.nc > putatt: Cannot put PDL attribute -- NetCDF: Attempt to define fill > value when data already exists. at t.pl line 24
Hei, attached module (preliminary 4.21) allows for setting the _FillValue during the first 'put/putslice' command. Heiko
Subject: PDL-NetCDF-4.21.tar.gz
Download PDL-NetCDF-4.21.tar.gz
application/x-gzip 33.8k

Message body not shown because it is not plain text.