average file count logic

Bug reports, work arounds and fixes

Moderators: arango, robertson

Post Reply
Message
Author
cae
Posts: 36
Joined: Mon Jun 30, 2003 5:29 pm
Location: UC Santa Cruz

average file count logic

#1 Unread post by cae »

I am only 80% sure that this is a bug, but sufficiently sure that I thought I'd post it. I'm using ROMS version 1005.

In read_phypar.F, lines 3692-3698 read

Code: Select all

#ifdef AVERAGES
        IF ((nAVG(ng).gt.0).and.(ndefAVG(ng).gt.0)) THEN
          OutFiles=ntimes(ng)/ndefAVG(ng)
          CALL edit_file_struct (ng, OutFiles, AVG)
          AVG(ng)%load=0       ! because delayed creation of NetCDF file
        END IF                 ! due to time-aveeraging
#endif
If nAVG>0 and ndefAVG>0, but ntimes<ndefAVG, then OutFiles is set to 0. The subsequent call to edit_file_struct then allocates several sub-variables of AVG (e.g., AVG(ng)%files) as having length 0.

Later, in output.F, line 320 is

Code: Select all

            AVG(ng)%files(Fcount)=TRIM(AVG(ng)%name)
in which AVG(ng)%files(Fcount) is set to a string that has just been defined. The first time through this routine, Fcount is set to 1. Following this line are other references to index 1 of AVG subvariables that should have length 0. In my application, this yields a segfault.

I can eliminate the problem by ensuring that the number of AVG files is at least 1, adding the following small check after OutFiles has been defined:

Code: Select all

           IF (nAVG(ng).lt.ndefAVG(ng)) OutFiles=Outfiles+1
I have only confirmed this logic for the AVG file case, but similar arguments seem to apply to the other variables, and so I included the suggestions here.edits to read_phypar.F:

Code: Select all

!  If multiple output files, edit derived type structure to store the
!  information about all multi-files.
!
      DO ng=1,Ngrids
        IF ((nHIS(ng).gt.0).and.(ndefHIS(ng).gt.0)) THEN
          OutFiles=ntimes(ng)/ndefHIS(ng)
          IF (nHIS(ng).le.ndefHIS(ng)) OutFiles=Outfiles+1  ! because IC
          CALL edit_file_struct (ng, OutFiles, HIS)
        END IF
        IF ((nQCK(ng).gt.0).and.(ndefQCK(ng).gt.0)) THEN
          OutFiles=ntimes(ng)/ndefQCK(ng)
          IF (nQCK(ng).le.ndefQCK(ng)) OutFiles=Outfiles+1  ! because IC
          CALL edit_file_struct (ng, OutFiles, QCK)
        END IF
#ifdef ADJOINT
        IF ((nADJ(ng).gt.0).and.(ndefADJ(ng).gt.0)) THEN
          OutFiles=ntimes(ng)/ndefADJ(ng)
          IF (nADJ(ng).le.ndefADJ(ng)) OutFiles=Outfiles+1  ! because IC
          CALL edit_file_struct (ng, OutFiles, ADM)
        END IF
#endif
#ifdef AVERAGES
        IF ((nAVG(ng).gt.0).and.(ndefAVG(ng).gt.0)) THEN
          OutFiles=ntimes(ng)/ndefAVG(ng)
          IF (nAVG(ng).lt.ndefAVG(ng)) OutFiles=Outfiles+1
          CALL edit_file_struct (ng, OutFiles, AVG)
          AVG(ng)%load=0       ! because delayed creation of NetCDF file
        END IF                 ! due to time-aveeraging
#endif
#ifdef DIAGNOSTICS
        IF ((nDIA(ng).gt.0).and.(ndefDIA(ng).gt.0)) THEN
          OutFiles=ntimes(ng)/ndefDIA(ng)
          IF (nDIA(ng).lt.ndefDIA(ng)) OutFiles=Outfiles+1
          CALL edit_file_struct (ng, OutFiles, DIA)
          DIA(ng)%load=0       ! because delayed creation of NetCDF file
        END IF                 ! due to time-aveeraging
#endif
#if defined TANGENT || defined TL_IOMS
        IF ((nTLM(ng).gt.0).and.(ndefTLM(ng).gt.0)) THEN
          OutFiles=ntimes(ng)/ndefTLM(ng)
          IF (nTLM(ng).le.ndefTLM(ng)) OutFiles=Outfiles+1  ! because IC
          CALL edit_file_struct (ng, OutFiles, TLM)
        END IF
#endif
      END DO
The only reason I am not 100% sure of this issue is that I haven't been able to reproduce the segfault on the test upwelling problem, modified to try to reproduce this error. In the test problem, my compiler, with the DEBUG options set, seems to blaze past writing to this variable even with its allocated length of 0. Thus it's possible that my solution is not the correct one. Apologies if that's the case.

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

Re: average file count logic

#2 Unread post by arango »

I revised this logic recently. My assumption is that ndefAVG is an exact multiple (integer factor) of ntimes. If it is not the case, the file creation definition is changed. What values are you using that gives you OutFiles=0? The time averaged files are special because of its delayed creation. That's the reason why the load counter has to be zero during intialization. Your suggestion is to be like the history which iuncludes the initial condtitions. It is not the case of the time-averaged files (AVG and DIA).

cae
Posts: 36
Joined: Mon Jun 30, 2003 5:29 pm
Location: UC Santa Cruz

Re: average file count logic

#3 Unread post by cae »

Hi. Thanks for the reply.

I have a case that I'm debugging for other reasons and reduced NTIMES lower than it normally might be. In my case, I have

NTIMES == 1536
DT == 225.0d0
NAVG == 384
NDEFAVG == 11520

I only wanted the run to go 4 days, have daily average writes, and want new average files created every 30 days. Normally, NTIMES would be much larger, but it still should run acceptably (without a segmentation fault) with this configuration (I think).

In response to your comment about the HIS file logic: I did make a difference in the logic between the AVG file and files that have an initial condition (e.g., HIS, QCK, ADJ, and TLM):

Code: Select all

IF (nHIS(ng).le.ndefHIS(ng)) OutFiles=Outfiles+1  ! because IC
vs

Code: Select all

IF (nAVG(ng).lt.ndefAVG(ng)) OutFiles=Outfiles+1
So there still will be one less for the AVG (and DIA) files than for the others.

I'm not positive this logic for the fields with ICs is correct.

Thanks again for thinking about it.

Post Reply