stats_init Subroutine

public subroutine stats_init()

Arguments

None

Calls

proc~~stats_init~~CallsGraph proc~stats_init stats_init mpi_abort mpi_abort proc~stats_init->mpi_abort proc~ncinfo ncinfo proc~stats_init->proc~ncinfo proc~stats_validate_slice_inputs stats_validate_slice_inputs proc~stats_init->proc~stats_validate_slice_inputs

Called by

proc~~stats_init~~CalledByGraph proc~stats_init stats_init program~udales uDALES program~udales->proc~stats_init

Source Code

    subroutine stats_init
      implicit none
      integer :: nperiod
      real    :: tperiod

      ltavgslice = ltislicedump .or. ltjslicedump .or. ltkslicedump
      ltavg3d    = ltdump .or. ltavgslice
      lstatsdump = ltavg3d .or. lxytdump .or. lxydump .or. lytdump .or. lydump
      lstatstavgdump = ltavg3d .or. lxytdump .or. lytdump
      lrh = ltempeq .and. lmoist

      ! the time-averaged slices reuse the plane positions of the instantaneous slices
      call stats_validate_slice_inputs(ltislicedump, nislice, islice, 'islice')
      call stats_validate_slice_inputs(ltjslicedump, njslice, jslice, 'jslice')
      call stats_validate_slice_inputs(ltkslicedump, nkslice, kslice, 'kslice')
      
      if(.not.(lstatsdump .or. ltreedump)) return

      ! With tstatsgap > 0 the time-averaged statistics follow a fixed, absolute
      ! schedule: dumps at tstatstart + n*(tstatsdump + tstatsgap), n = 1, 2, ...,
      ! each averaging the tstatsdump seconds that precede it (gap first, averaging
      ! window last). E.g. tstatstart = 21600, tstatsdump = 900, tstatsgap = 13500
      ! gives 15-min means ending exactly at t = 36000, 50400, 64800, ...
      ! The schedule is anchored to absolute time, so a warm-started run keeps the
      ! same dump instants: tstatstart is advanced here to the first averaging
      ! window that (at least half) lies after the restart time btime.
      if (tstatsgap > 0.) then
        tperiod    = tstatsdump + tstatsgap
        tstatstart = tstatstart + tstatsgap          ! start of the first averaging window
        if (btime > tstatstart) then
          nperiod    = floor((btime - tstatstart)/tperiod)
          tstatstart = tstatstart + nperiod*tperiod  ! window containing or preceding btime
          if (tstatstart + 0.5*tstatsdump < btime) tstatstart = tstatstart + tperiod
        end if
        if (myid==0) write(*,'(a,f12.2,a,f12.2)') &
          ' stats: tstatsgap > 0, first averaging window starts at t = ', tstatstart, &
          ', first dump at t = ', tstatstart + tstatsdump
      end if

      if( (lstatstavgdump .or. ltreedump) &
          .and. runtime + btime <= tstatstart + tstatsdump ) then
        if(myid==0) then
          write(*,*) "ERROR: no time-averaged statistics file will be written as runtime + btime <= tstatstart + tstatsdump. &
                      &Note that runtime + btime must be greater than tstatstart + tstatsdump for writing time-averaged statistics files."
          write(*,*) "You have used runtime = ", runtime, ", btime = ", btime, ", tstatstart = ", tstatstart, ", and &
                     &tstatsdump = ", tstatsdump
          write(*,*) "Either correct the time settings or change all time-averaged stats writing flags to false."
          !abort every rank: a bare STOP inside a rank-0 guard leaves the other ranks alive until walltime
          call MPI_ABORT(MPI_COMM_WORLD, 1, mpierr)
        end if
      end if
      
      xdim = ie-ib+1
      ydim = je-jb+1
      zdim = ke-kb+1
      tsamplep = 0.
      tstatsdumpp = 0.
      dumpcount = 0
      call ncinfo(timeVar( 1,:), 'time', 'Time', 's', 'time')
    end subroutine stats_init