catching netcdf error codes [message #38722] |
Fri, 26 March 2004 12:48  |
Benjamin Hornberger
Messages: 258 Registered: March 2004
|
Senior Member |
|
|
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
|
|
|
Re: catching netcdf error codes [message #38778 is a reply to message #38722] |
Tue, 30 March 2004 02:39  |
R.Bauer
Messages: 1424 Registered: November 1998
|
Senior Member |
|
|
Mark Hadfield wrote:
> Reimar Bauer wrote:
>
>> Mark Hadfield wrote:
>>
>>> Reimar Bauer wrote:
>>>
>>>> You need only to check the first three bytes of the file. If it is
>>>> 'CDF'
>>>> then it is a netCDF file.
>>>
>>>
>>> Or possibly some other sort of file with 'CDF' in the first three bytes!
>>>
>>
>> Yes if you have one other. Do you have an example.
>
>
> No.
>
>> It works since a while for us.
>
>
> I'm just worried that it will fail to work when you least expect it.
>
> I like the idea of trying to open the file with NCDF_OPEN and catching
> any errors, because that directly answers the question: "can I open this
> file as netCDF?".
>
>
>
You are right, it could be better to do it this way because the internal
file format will be changed to HDF SD format by version 4 of netCDF.
I don't know when but then probably the string test of my routine stops
working.
Reimar
--
Reimar Bauer
Institut fuer Stratosphaerische Chemie (ICG-I)
Forschungszentrum Juelich
email: R.Bauer@fz-juelich.de
------------------------------------------------------------ -------
a IDL library at ForschungsZentrum Juelich
http://www.fz-juelich.de/icg/icg-i/idl_icglib/idl_lib_intro. html
============================================================ =======
|
|
|
Re: catching netcdf error codes [message #38786 is a reply to message #38722] |
Mon, 29 March 2004 21:27  |
Mark Hadfield
Messages: 783 Registered: May 1995
|
Senior Member |
|
|
Reimar Bauer wrote:
> Mark Hadfield wrote:
>
>> Reimar Bauer wrote:
>>
>>> You need only to check the first three bytes of the file. If it is 'CDF'
>>> then it is a netCDF file.
>>
>> Or possibly some other sort of file with 'CDF' in the first three bytes!
>>
>
> Yes if you have one other. Do you have an example.
No.
> It works since a while for us.
I'm just worried that it will fail to work when you least expect it.
I like the idea of trying to open the file with NCDF_OPEN and catching
any errors, because that directly answers the question: "can I open this
file as netCDF?".
--
Mark Hadfield "Ka puwaha te tai nei, Hoea tatou"
m.hadfield@niwa.co.nz
National Institute for Water and Atmospheric Research (NIWA)
|
|
|
Re: catching netcdf error codes [message #38800 is a reply to message #38722] |
Mon, 29 March 2004 07:56  |
R.Bauer
Messages: 1424 Registered: November 1998
|
Senior Member |
|
|
Mark Hadfield wrote:
> Reimar Bauer wrote:
>
>> You need only to check the first three bytes of the file. If it is 'CDF'
>> then it is a netCDF file.
>
>
> Or possibly some other sort of file with 'CDF' in the first three bytes!
>
Yes if you have one other. Do you have an example. It works since a
while for us.
Reimar
--
Reimar Bauer
Institut fuer Stratosphaerische Chemie (ICG-I)
Forschungszentrum Juelich
email: R.Bauer@fz-juelich.de
------------------------------------------------------------ -------
a IDL library at ForschungsZentrum Juelich
http://www.fz-juelich.de/icg/icg-i/idl_icglib/idl_lib_intro. html
============================================================ =======
|
|
|
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
|
|
|