This archive contains answers to questions sent to Unidata support through mid-2025. Note that the archive is no longer being updated. We provide the archive for reference; many of the answers presented here remain technically correct, even if somewhat outdated. For the most up-to-date information on the use of NSF Unidata software and data services, please consult the Software Documentation first.
Bill, > From: "William R Moninger" <address@hidden> > Subject: problem with perl netCDF > Organization: NOAA/FSL > Keywords: 200008161736.e7GHaON16062 netCDF Perl The above message contained the following: > Hello, > > I am trying to do a NetCDF::varget, and this works fine unless I provide > an argument to my perl script. > > The problematic script is below. I can provide the netCDF file (which > is short) if you wish. Offhand, I don't see anything wrong. Would you please send me an ncdump(1) of the netCDF file. > I'll appreciate any help you can provide. > > -Bill > > This script generates a segmentation fault in the varget call: > > #!/usr/local/perl5/bin/perl -T > > #redirect stderr to stdout so we can see err msgs on the web > $|=1; #force flush of buffers after each print > open (STDERR, ">&STDOUT") || die "can't dup stdout ($!)\n"; > > use strict; > use NetCDF; > NetCDF::opts(2); # NC_VERBOSE = 2 > my $n_hours = $ARGV[0] || 1; > #$n_hours = 1; # NO ERROR IF THIS LINE IS UN-COMMENTED > print "n_hrs is $n_hours\n"; > my $endSecs = time() - 3600; > print "Args are @ARGV\n"; > my $startSecs = $endSecs - 3600*$n_hours; > > my $secs = $startSecs; > my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = > gmtime($secs); > #get pirep file for this hour > $year %=100; > $mon++; > my $filename = sprintf("pireps/%02d%02d%02d%02d00.ncf", > $year,$mon,$mday,$hour); > print "file is $filename\n"; > my $ncid=-1; > no strict; > my $read_mode = NetCDF::READ; > use strict; > $ncid = NetCDF::open("$filename",$read_mode); > if($ncid != -1) { > my $dname="xxxxxxxxxxxxxxxxxxx"; > my $dlen=-1; > NetCDF::diminq($ncid,0,$dname,$dlen); > my $n_pireps = $dlen; > print "Opened $filename with $n_pireps pireps\n"; > my $date_id = NetCDF::varid($ncid,"date"); > my @n_to_read = ($n_pireps); > my @start_read = (0); > my @dates = (); > print "got here\n"; > NetCDF::varget($ncid,$date_id,\@start_read, > \@n_to_read,\@dates); > print "dates are @dates\n"; > NetCDF::close($ncid); > } > > -- > William R. Moninger NOAA, Forecast Systems Laboratory > tel: 303-497-6435 email: address@hidden > fax: 303-497-3329 http://www-frd.fsl.noaa.gov/~moninger/ Regards, Steve Emmerson <http://www.unidata.ucar.edu>