NOTICE: This version of the NSF Unidata web site (archive.unidata.ucar.edu) is no longer being updated.
Current content can be found at unidata.ucar.edu.
To learn about what's going on, see About the Archive Site.
Hi Brice:I think your script should work (it should add on the the existing netCDF file) if you just make a couple of changes:
use strict; # make perl strict use warnings; # add useful warnings use PDL; use PDL::NetCDF; use Fcntl; # Define O_RDWR and other constants # Do not need PDL::Char my $nc = PDL::NetCDF->new("testnc.nc", {MODE => O_RDWR, REVERSE_DIMS=>1}); my $data = pdl [1,2,3]; $nc->put('time_nominal', ['recNum'], $data); $nc->close(); Regards, Doug Hunt UCAR - COSMIC, Tel. (303) 497-2611 On Wed, 15 Jul 2009, Brice Lambi wrote:
Hello, I'm trying to update some older code to use PDL::NetCDF but I'm having problems writing to existing nc files. For example, if we have a simple cdl file: netcdf testme { dimensions: recNum = UNLIMITED ; variables: int time_nominal( recNum ) ; time_nominal:long_name = "time nominal"; time_nominal:_FillValue = -99999; time_nominal:units = "seconds since 1970-01-01 00 UTC"; :title = "test cdl"; :version = 1.1; } and we run ncgen: ncgen -o testnc.nc testme.cdl Then we try to open the file with a perl script using PDL::NetCDF and write to it: use PDL; use PDL::NetCDF; use PDL::Char; my $nc = PDL::NetCDF->new("testnc.nc", {MODE=>O_RDWR|REVERSE_DIMS=>1}); my $data = pdl [1,2,3]; $nc->put('time_nominal', ['recNum'], $data); $nc->close(); This is the error I see: Cannot write read-only netCDF file testnc.nc at ./testme.pl line 9 But if I first delete the file that I created with ncgen and run the same code again it will run successfully and this is the output from ncdump: netcdf testnc { dimensions: recNum = 3 ; variables: double time_nominal(recNum) ; data: time_nominal = 1, 2, 3 ; } But then if I run this code one more time (without deleting the file) I will get the error again. Is there something else I can do to tell PDL::NetCDF to write to the existing file, even though my MODE is O_RDWR? Or is this a known issue? Thanks, Brice Lambi _______________________________________________ netcdfgroup mailing list netcdfgroup@xxxxxxxxxxxxxxxx For list information or to unsubscribe, visit: http://www.unidata.ucar.edu/mailing_lists/
netcdfgroup
archives: