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, > To: address@hidden > From: "William C. Mattison" <address@hidden> > Subject: perl netCDF problem. > Organization: NOAA/NWS > Keywords: 199907191509.JAA17058 In the above message, you wrote: > I'm having trouble with a perl script calling one of netCDF's perl api's. > Here's the script: > ------------------------------------------------------------------------------- > #!/opt/perl5/bin/perl > use NetCDF; > > #prompt for file path. > print "\nEnter name of netCDF metar file:\n"; > chop ( $file_path = <STDIN> ); > > #open file. > $ncid = 0; > $ncid = NetCDF::open ( $file_path , 0 ); > @stride = ( 1 , 1 ); > @imap = 0; > @dim_ids = ( 0 , 0 ); > $status = 0; > > foreach $report_number ( 0 .. 10 ) > { > > $index[0] = $report_number; > $start[0] = $report_number; > $count[0] = 1; > > $index[1] = 0; > $index[2] = 0; > $var_id = 0; > $var_id = NetCDF::varid ( $ncid , "wmoId" ); > $wmoId = 0; > $status = NetCDF::varget1 ( $ncid , $var_id , $index[0] , $wmoId ); > print "wmoId = $wmoId\n"; > > $var_id = NetCDF::varid ( $ncid , "stationName" ); > $cdummy = ""; > $ndims = 0; > $type = NetCDF::LONG; > $idummy = 0; > $status = NetCDF::varinq ( $ncid , $var_id , $cdummy , $type , $ndims , > @dim_ids , $idummy ); > $len = 0; > $status = NetCDF::diminq ( $ncid , $dim_ids[1] , $cdummy , $len ); > $start[1] = 0; > $start[2] = 0; > $count[1] = $len; > $count[2] = 0; > $stationName = ""; > $status = NetCDF::vargetg ( $ncid , $var_id , @start , @count , @stride , > @imap , $stationName ); > print "stationName = $stationName\n"; > > }; > > $status = NetCDF::close ( $ncid ); > ------------------------------------------------------------------------------- > and here's the output: > ------------------------------------------------------------------------------- > > Enter name of netCDF metar file: > 19990716_1200 > wmoId = -2147483647 > Usage: NetCDF::varinq(ncid, varid, name, datatype, ndims, dimids, natts) at > meta > r.perl line 36, <STDIN> chunk 1. > ------------------------------------------------------------------------------- > I and the best perl person here have racked our brains out on this one, and > we're stuck. Can you help us "polish our perly"? > > Thank-you in advance for your help. > > Bill Mattison (address@hidden) I'd like to see an ncdump(1) of the netCDF file in question. Would you please send me the output from the following command: ncdump -h 19990716_1200 -------- Steve Emmerson <http://www.unidata.ucar.edu>