I recently ran into some problems writing to an AVG file after restart, and was able to get past them after a few small changes to the code. The problems had to do with writing to the correct index in the existing AVG netcdf file, and with not being able to write the variable Huon_sand_01 (and presumably other Huon_sand_* and Hvom variables).
The last time in the restart file used for the model restart was before the last time in the AVG file, but rather than overwriting that last time in the AVG it added a new time index to the file with the same value as the last time index. The HIS file was being output at the same interval, and it correctly overwrote the last index (index 11, in this case) whereas the AVG file wrote a new index (12) that had the same time value as index 11. To address this I adapted DEF_AVG.F to be more like DEF_HIS.F, commenting out of the check whether nRST.eq.nAVG (it did not, so AVG.Rindex was being set to rec_size rather than figuring out the correct time) and adding the MIN() statement.
! IF (nRST(ng).eq.nAVG(ng)) THEN
IF (ndefAVG(ng).gt.0) THEN
AVG(ng)%Rindex=((ntstart(ng)-1)- &
& ndefAVG(ng)*((ntstart(ng)-1)/ndefAVG(ng)))/ &
& nAVG(ng)
ELSE
AVG(ng)%Rindex=(ntstart(ng)-1)/nAVG(ng)
END IF
! ELSE
AVG(ng)%Rindex=MIN(AVG(ng)%Rindex,rec_size) ! new
! AVG(ng)%Rindex=rec_size
! END IF
The other problem was with writing out Huon_sand_01 -- it would crash saying it could not find the variable in the AVG file. The restart ran fine writing out only other averages (not Huon and Hvom), and the Huon_sand_01 did exist in the AVG file. This was fixed by changing the loops where Aout(iHUTavg(itrc)) is defined to be over NT(ng) instead of NAT. There are 3 such loops -- previously 1 of the loops was over NT(ng), but the other 2 were over NAT.
The modified DEF_AVG.F is attached. Thanks to John Warner for coaching me through this, and any blame for mistakes goes all to me.
questions on DEF_AVG.F
questions on DEF_AVG.F
- Attachments
-
- def_avg.F
- (197.46 KiB) Downloaded 163 times