In short, my application appears to be miscalculating when to create new files, such that too many time steps are placed in the first file. This then causes a crash under certain restart conditions because the restarted model expects a different number of output files than had been created by the initial run.
I have tracked down *what* is going wrong, but not quite the *why* of it.
In ROMS/Nonlinear/output.F:
I've marked executed lines with a + as it applies to the first time this code is called (iic = 1, ntstart = 1, nrrec = 0, nHIS=1008, ndefHIS=10080). The "! KK:" comments indicate the values on this first call in my application.
Code: Select all
!
! Create output history NetCDF file or prepare existing file to
! append new data to it. Also, notice that it is possible to
! create several files during a single model run.
!
+ IF (LdefHIS(ng)) THEN
+ IF (ndefHIS(ng).gt.0) THEN
+ IF (idefHIS(ng).lt.0) THEN
+ idefHIS(ng)=((ntstart(ng)-1)/ndefHIS(ng))*ndefHIS(ng) ! KK: idefHIS(ng) = 0
+ IF (idefHIS(ng).lt.iic(ng)-1) THEN
- idefHIS(ng)=idefHIS(ng)+ndefHIS(ng)
+ END IF
+ END IF
+ IF ((nrrec(ng).ne.0).and.(iic(ng).eq.ntstart(ng))) THEN
- IF ((iic(ng)-1).eq.idefHIS(ng)) THEN
- HIS(ng)%load=0 ! restart, reset counter
- Ldefine=.FALSE. ! finished file, delay
- ELSE ! creation of next file
- Ldefine=.TRUE.
- NewFile=.FALSE. ! unfinished file, inquire
- END IF ! content for appending
- idefHIS(ng)=idefHIS(ng)+nHIS(ng) ! restart offset
+ ELSE IF ((iic(ng)-1).eq.idefHIS(ng)) THEN
+ idefHIS(ng)=idefHIS(ng)+ndefHIS(ng) ! KK: idefHIS(ng) = 10080
+ IF (nHIS(ng).ne.ndefHIS(ng).and.iic(ng).eq.ntstart(ng)) THEN
+ idefHIS(ng)=idefHIS(ng)+nHIS(ng) ! multiple record offset ! KK: idefHIS(ng) = 11088
+ END IF
+ Ldefine=.TRUE.
+ NewFile=.TRUE.
+ ELSE
- Ldefine=.FALSE.
+ END IF
...
+ IF (Ldefine) THEN
...
- ifile=(iic(ng)-1)/ndefHIS(ng)+1
...
However, this does not match when the value of ifile increases; that occurs, as expected, between steps 10080 and 10081 (ndefHIS and ndefHIS+1). The file-creation index and ifile-switching index continue to be offset from each other by nHIS for the rest of the simulation. So if I stop and then restart a simulation between steps 10080 and 11088 (or between any ndefHIS*x+[0 nHIS] interval), the restart crashes (see error below).
It seems the quick fix here would be to comment out the "! multiple record offset" line, which seems to be the culprit in incorrectly shifting the first idefHIS value. But I assume this line was there for a reason, and I might be breaking something. Can anyone clarify whether that reason applies to a forward nonlinear model simulation? This seems too obvious an error for me to be the first one to encounter it... but then the logic in this section seems much more complicated than I would expect, so perhaps I'm misunderstanding something?
In case it helps, I also added a bunch of extra print statements to my standard output to double-check what was going on. Here are the last few time steps of the initial run, stopping as I requested after step 10944:
Code: Select all
10943 1990-03-31 23:50:00.00 2.368000E-03 2.111055E+04 2.111055E+04 1.062594E+16
(174,025,30) 8.967006E-02 0.000000E+00 5.323323E+00 5.439568E+00
LdefHIS = T idefHIS = 11088 iic = 10944 ndefHIS = 10080 nrrec = 0 ntstart = 1 Ldefine = F ifile = 2
10944 1990-04-01 00:00:00.00 2.343951E-03 2.111048E+04 2.111048E+04 1.062592E+16
(174,025,30) 6.630270E-02 0.000000E+00 4.540270E+00 5.565688E+00
LdefHIS = T idefHIS = 11088 iic = 10945 ndefHIS = 10080 nrrec = 0 ntstart = 1 Ldefine = F ifile = 2
And here is the printout (and error) seen on restart:
Code: Select all
TIME-STEP YYYY-MM-DD hh:mm:ss.ss KINETIC_ENRG POTEN_ENRG TOTAL_ENRG NET_VOLUME
C => (i,j,k) Cu Cv Cw Max Speed
10944 1990-04-01 00:00:00.00 2.343942E-03 2.111048E+04 2.111048E+04 1.062592E+16
(170,025,30) 1.730109E-01 2.271564E-01 0.000000E+00 5.565688E+00
LdefHIS = T idefHIS = 21168 iic = 10945 ndefHIS = 10080 nrrec = -1 ntstart = 10945 Ldefine = T ifile = 2
NewFile = F
DEF_HIS - inquiring history file, Grid 01: bgcdebug_phys/Out/bgcdebug_phys_his_00002.nc
Found Error: 02 Line: 8458 Source: ROMS/Modules/mod_netcdf.F, netcdf_open
NETCDF_OPEN - unable to open existing NetCDF file:
bgcdebug_phys/Out/bgcdebug_phys_his_00002.nc
call from: ROMS/Utility/def_his.F
No such file or directory