ROMS attempts to close un-named files

Bug reports, work arounds and fixes

Moderators: arango, robertson

Post Reply
Message
Author
User avatar
m.hadfield
Posts: 521
Joined: Tue Jul 01, 2003 4:12 am
Location: NIWA

ROMS attempts to close un-named files

#1 Unread post by m.hadfield »

This is arguably not a bug, rather than an opportunity for user error.

When I updated to the latest version of the code, with the new, quick-save file functionality and ran an existing case I got

Code: Select all

 NETCDF_CLOSE - error during closing of file, ncid =   0
                file:
                call from:  close_out, close_io.F
To cut a long story short, this arose because I did not have an entry for QCKNAME in my input file. (It took me a while to figure this out: the fact that the file name is missing above should have been a clue.)

The code that triggered this error is at lines 177-180 of ROMS/Utility/close_io.F

Code: Select all

        IF (QCK(ng)%ncid.ne.-1) THEN
          CALL netcdf_close (ng, iNLM, QCK(ng)%ncid)
        END IF
The value of -1 should have been loaded into QCK(ng)%ncid in the load_s1d function, which is called at line 2812-2815 of ROMS/Utility/read_phypar.F

Code: Select all

            CASE ('QCKNAME')
              label='QCK - nonlinear model quicksave fields'
              Npts=load_s1d(Nval, Cval, Cdim, line, label, igrid,       &
     &                      Nfiles, QCK)
However that was never called, because no value was provided for QCKNAME. Instead QCK(ng)%ncid had the value of 0, which is presumably what it was assigned when QCK(ng) was allocated.

So, first and foremost, users should always provide names for every different type of file that ROMS can read or write, even if they don't intend to use them. (That way, error messages associated with that file type will show an informative file name rather than a blank.)

But could the code be a bit more tolerant when this is not done? How about the following (and similarly for the other file types):

Code: Select all

        IF (QCK(ng)%ncid.gt.0) THEN
          CALL netcdf_close (ng, iNLM, QCK(ng)%ncid)
        END IF
I am assuming that the netCDF ID for an open file in the Fortran interface is guaranteed to be positive, which I think is true.

thoar

Re: ROMS attempts to close un-named files

#2 Unread post by thoar »

I ran into the same thing, which has been fixed with ticket 706.

It might be useful for the code to specify default filenames ('QCKNAME_not_specified', for example).
However, since there is new logic that prevents this error, it may be overkill.

User avatar
m.hadfield
Posts: 521
Joined: Tue Jul 01, 2003 4:12 am
Location: NIWA

Re: ROMS attempts to close un-named files

#3 Unread post by m.hadfield »

That was quick!

Thanks for the info.

User avatar
arango
Site Admin
Posts: 1367
Joined: Wed Feb 26, 2003 4:41 pm
Location: DMCS, Rutgers University
Contact:

Re: ROMS attempts to close un-named files

#4 Unread post by arango »

Yes, please update. The error is due to the lack of the QCKNAME keyword in ocean.in. Notice that in :arrow: ticket 706 the field for NetCDF file ID, XXX%ncid=-1, is initialized to close state in all the I/O structure arrays. This will allow to run newest ROMS version with old input ocean.in scripts.

Post Reply