[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: using netcdf API in fortran



Dov Kruger <address@hidden> writes:

> Ed,
>
>
> I am doing some new code and would like to do it better.
>
> Whenever something fails, I'd like to know and get a reasonable error
> message. I am currently doing this manually by writing a subroutine that
> I pass the status code and a message, and if it's nonzero, I terminate
> and print out the message so I know which line failed.
>
> I'd prefer if there's a way to setup a handler in fortran, and say print
> out the reason code whenever there is a failure. It's also pretty
> important to know which line, because if we are generating 10-20
> variables, it's not very convenient to know that one of them just
> failed.
>
> Here's an example:
> call checkstatus(nf_put_vara_real(cdfid, whbdryid, 
>      $        bdryind, bdrysize whbdry), 'writing wh')
>
> thanks, 
> Dov
>
>

Howdy Dov!

Sorry, I'm not very much up on fortran programming. 

Do you know that the netCDF functions return an error code, and that
you can print out an associated string with nf_strerror function? See:

http://www.unidata.ucar.edu/software/netcdf/docs/netcdf-f77/Error-Handling.html

As for how you can get a line number, I use the C pre-processor (since
I program in C) and it includes the __LINE__ and __FILE__ macros, so
that I can create a macro that handles errors and prints out the line
number and file. But I have no idea how to do it in fortran, unless
one chooses to use the C preprocessor on fortran code (which is
actually done in part of the netCDF build.)

Whether you want to add a pre-processing step, or whether there is a
fortran pre-processor that you would prefer, is up to you.

Good luck!

Ed
-- 
Ed Hartnett  -- address@hidden