[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: How to check if a file is indeed a NetCDF file?
- To: Paul van Delst <paul.vandelst(at)ssec.wisc.edu>
- Subject: Re: How to check if a file is indeed a NetCDF file?
- From: Liam Gumley <Liam.Gumley(at)ssec.wisc.edu>
- Date: Mon, 19 Apr 1999 10:45:53 -0500
- Newsgroups: comp.lang.idl-pvwave
- Organization: Space Science and Engineering Center, University of Wisconsin-Madison
- References: <371B38CD.7CE2DB3B@ssec.wisc.edu>
- Xref: news.doit.wisc.edu comp.lang.idl-pvwave:14410
Paul van Delst wrote:
> In trying to read NetCDF data files in IDL, I've discovered that the
> NCDF_OPEN crashes on me if the file I ask it to open is not a nCDF file.
> It crashes somewhat gracefully in that it tells me that NCDF_OPEN
> couldn't open the file and the error # is 19. Does anyone out there know
> how to use the IDL NCDF library to determine whether or not a file is in
> NetCDF format? The fact that the most obvious solution (i.e. NCDF_OPEN
> *returns* an error # rather than falling in a heap) doesn't work like I
> would expect doesn't make me too hopeful.
How about this (styled along the lines of HDF_ISHDF)?
FUNCTION NCDF_ISNCDF, FILENAME
;- Set return values
false = 0B
true = 1B
;- Establish error handler
catch, error_status
if error_status ne 0 then begin
catch, /cancel
return, false
endif
;- Try opening the file
cdfid = ncdf_open( filename )
;- If we get this far, open must have worked
ncdf_close, cdfid
catch, /cancel
return, true
END
Then it's just a matter of:
if not ncdf_isncdf( filename ) then begin
help, filename
message, 'FILENAME is not in NetCDF format'
endif
cdfid = ncdf_open( filename )
Cheers,
Liam.
---
Liam E. Gumley
Space Science and Engineering Center, UW-Madison
http://cimss.ssec.wisc.edu/~gumley