This archive contains answers to questions sent to Unidata support through mid-2025. Note that the archive is no longer being updated. We provide the archive for reference; many of the answers presented here remain technically correct, even if somewhat outdated. For the most up-to-date information on the use of NSF Unidata software and data services, please consult the Software Documentation first.
Mary, > To: address@hidden > From: address@hidden (Mary Haley) > Subject: Question about NCOPN's behavior > Organization: UCAR/NCAR/SCD > Keywords: 199701161959.MAA20955 In the above message you wrote: > I just built and installed Version 2.43 of netCDF on all of NCAR's > Crays using f90. A user pointed out to me that previously, if she > tried to open a netCDF file that didn't exist, she would get an ierr > of -1 ("ierr" being the last argument of NCOPN). Now, it's returning > 0. > > I wrote a little Fortran test program where I just open and close > a netCDF file. The first file I open does indeed exist, and the > second file I open doesn't. Here's the program: > > character*8 filename > integer ncid, ierr > filename = 'test.nc' > C > C 'test.nc' does exist. > C > print *,'trying to open test.nc' > ncid = ncopn(filename,0,ierr) > print *,'ncid = ', ncid > print *,'ierr = ', ierr > call ncclos(ncid,ierr) > > C > C 'test.n' doesn't exist. > C > filename = 'test.n' > print *,'trying to open test.n' > ncid = ncopn(filename,0,ierr) > print *,'ncid = ', ncid > print *,'ierr = ', ierr > call ncclos(ncid,ierr) > stop > end > > > When I run this on a J90, here's the output: > > trying to open test.nc > ncid = 0 > ierr = 0 > trying to open test.n > Unable to open file: test.n > Error Explanation: > ncid = -1 > ierr = 0 > ncclose: -1 is not a valid cdfid > > > Note that "ierr" is '0' in both cases, even though in the second case > the file doesn't exist. > > I ran this same program on an SGI, using the same version of netCDF, > and here are the results: > > chiquita[15] ./a.out > trying to open test.nc > ncid = 0 > ierr = 0 > trying to open test.n > ncopen: filename "test.n": No such file or directory > > > So, apparently it quits right after trying to open the non-existent > file and doesn't reach the second set of print statements. > > My question is, what should the correct behavior be? As you use it, the netCDF library should print an error message and then abort the program. > It seems to me > it's doing the right thing on the SGI by quitting after it fails on > the file open. That's correct. > If so, then is this a potential bug on the Cray? Or > could this be something to do with the fact I'm using f90? It's a bug in the netCDF library on a CRAY MPP system: the netCDF global variable `ncerr' isn't getting set to NC_SYSERR when a file open failure occurs on a CRAY MPP system. I've enclosed a patch that should fix the problem. You should apply the patch to the file `xdrffio.c' in the `libsrc/' subdirectory. Please let me know if this helps. -------- Steve Emmerson <address@hidden> --------Begin patch to xdrffio.c Index: xdrffio.c =================================================================== RCS file: /upc/share/CVS/netcdf/libsrc/xdrffio.c,v retrieving revision 2.7 diff -c -r2.7 xdrffio.c *** 2.7 1996/06/27 19:38:48 --- xdrffio.c 1997/01/16 23:02:45 *************** *** 358,363 **** --- 358,364 ---- strlen(_fdc_errlist[stat.sw_error - 5000])); write(2,mess2,1); /* end of line */ /* nc_serror("filename \"%s\"", path) ; */ + ncerr = NC_SYSERR; return (-1); }