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

[netCDF #PAM-528913]: nc_open handle values



> Hi Ed,
> 
> Thanks for the reply and the explanation. The number of files opened
> issue maybe a red herring, but came about as a number of our scientists
> opened large numbers of files a number of times when working on climate
> science.
> 
> The real reason it is a problem is that the ncid does not appear to be
> re-used within the same session so even if you where opening /closing
> one file you can only do it 32767 times. One would assume a server using
> the library would be opening lots of files within one process lifetime
> and would run into this limit.
> 
> Is there some special call to the library to reset the ncid so that it
> can be reused?
> 

Howdy Andrew!

I see that you are correct. The file number is never reset, and so keeps 
climbing until eventually the ncid wraps to a negative number.

But is that bad? Everything still works, correct? For example, I have just 
added this test:
   printf("testing opening of many files...");
    {
       int i, ncid;

       for (i = 0; i < 32768; i++) 
       {
          if (nc_open(FILE_NAME, NC_NOWRITE, &ncid)) ERR_RET;
          if (nc_close(ncid)) ERR_RET;
       }
       if (nc_create(FILE_NAME, 0, &ncid)) ERR_RET;
       if (nc_def_var(ncid, "blah", NC_CHAR, 0, NULL, NULL)) ERR;
       if (nc_close(ncid)) ERR_RET;
       printf("last ncid: %d\n", ncid);
    }
    SUMMARIZE_ERR;

The output:

Testing NetCDF-4 with user-supplied sample file.
testing creation of sample file...ok.
testing opening of many files...last ncid: -2147287040
ok.
*** Tests successful!

And when I look at the file I created, which had a negative ncid, everything 
looks fine.

However, just for the sake of neatness, I had changed the library to reset the 
file number to 0 when all files are closed. 

This change will appear in the next snapshot release.

Thanks,

Ed


Ticket Details
===================
Ticket ID: PAM-528913
Department: Support netCDF
Priority: Normal
Status: Closed