Re: catching netcdf error codes [message #38812 is a reply to message #38722] |
Sun, 28 March 2004 07:38  |
Kenneth P. Bowman
Messages: 585 Registered: May 2000
|
Senior Member |
|
|
In article <pn5960dosp9jukipt69tb9ku1h3g24eq7h@4ax.com>,
Benjamin Hornberger <hornberg@xray1.physics.sunysb.edu> wrote:
> Hi all,
>
> I don't know how to catch a netcdf error code. I want to write a
> function is_netcdf() which checks if a file is a netcdf file. For
> that, I use the ncdf_open() function. If the file is not a netcdf
> file, then I will get an error which I want to catch. The error sais
> "%NCDF_OPEN: Unable to open the file "...". (NC_ERROR=-51)".
>
> If I now check !error_state.code, it is -1088 and not -51. Which
> variable holds the "nc_error", how can I get that?
>
> Thanks for your help,
> Benjamin
>
RSI will have to answer that one, but I think the routine below works.
I haven't used CATCH before, so the experts can (and assuredly will)
point our where I have erred.
This function is not specific. It returns 0 if any kind of error
occurs (e.g., if the file does not exist).
Ken Bowman
FUNCTION IS_NETCDF, infile
;+
; Name:
; IS_NETCDF
; Purpose:
; Determine whether a file is a netCDF file.
; Calling sequence:
; ncdf = IS_NETCDF(infile)
; Inputs:
; infile : input file name
; Output:
; This function returns 1B if a file is a netCDF file, 0B otherwise.
; Keywords:
; None.
; Author and history:
; Kenneth P. Bowman. 2004-03-27.
;-
COMPILE_OPT IDL2 ;Set compile options
CATCH, error_status ;Establish error handler
IF (error_status NE 0) THEN BEGIN
CATCH, /CANCEL ;Cancel error handler
RETURN, 0B ;Return FALSE
ENDIF
id = NCDF_OPEN(infile) ;Attempt to open input file
NCDF_CLOSE, id ;Close file
RETURN, 1B ;Return TRUE
END
|
|
|