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

Re: Problem with netcdf-3.1a



On Oct 4,  6:28pm, Harvey DAVIES wrote:
> Subject: Problem with netcdf-3.1a
> Glenn,
>
> It's after 6pm on Friday & I still hav'nt managed to track down a bug in
> my new version of FAN I have spent the best part of a week on!!
> I'm not happy :-(
>
> The first call to nc_open gives an absurdly large value for ncid.
> I suspect either overwriting or netcdf isn't getting initialised properly.
> How is this initialisation done?  i.e. how does it know this is the 1st call
> & what function does it?
>
> I tried following very simple program
>
> main(
> int argc,
> char *argv[])
> {
>     int         rc;                     /* return code */
>     int         i;
>
>     rc = nc_open("T.nc", 0, &i);
>     printf("rc=%d, ncid=%d\n", rc, i);
>
>     return 0;
> }
>
> & was surprised to get output:
>
> rc=0, ncid=3
>
> I expected ncid=0.  Is this OK?
>
> Help me please before I go completely crazy!!!
> Harvey
>-- End of excerpt from Harvey DAVIES

You don't say which version of netcdf you are using, but
judgeing from the code and the "problem statement", I'll assume
you are using netcdf-3.

Why do you believe that the ncid's start at zero? Because of experience or
because of specification?  In the second paragraph of Chapter 5 "Files" in
the user's guide it says:

" ... referred to by a netCDF ID, which is small nonnegative integer ...
A netCDF ID is much like a file descriptor in C ..."

What you are running into is that in version 3, the netCDF id _is_ the
C file descriptor. That's why the first one you get is 3, 0 is stdin, 1 stdout,
2 stderr, 3 the first user opened descriptor. (If you ran in purify, the
first one you would get is something like 6.)

The point is that you can't count on the value of the number, only that it
is some "small nonnegative integer".

Hope this doesn't hose up your program too badly.

-glenn