subroutine stats_main implicit none if (timee < tstatstart) return if (.not. rk3step==3) return if(.not.(lstatsdump .or. ltreedump)) return if (.not. lstatsprepared) call stats_prepare ! For one-timestep diagnostics with dump intervals no larger than dt, ! treat the just-completed step as a valid first sample immediately ! instead of waiting for a second call to statsdump. if (tsamplep == 0. .and. tsample <= dt) tsamplep = dt if (tstatsdumpp == 0. .and. tsample <= dt) tstatsdumpp = dt if (tsamplep >= tsample) then ! at every stats sampling instance tstatsdumppi = 1./tstatsdumpp if(lstatsdump) then call stats_interpolate_and_sgs_vel if (ltempeq) call stats_interpolate_and_sgs_temp if (lmoist) call stats_interpolate_and_sgs_moist if (ltempeq) call stats_calculate_air_temperature if (lrh) call stats_calculate_relative_humidity end if if(ltavg3d .or. lytdump .or. lydump) then if (nsv>0) call stats_interpolate_and_sgs_scalar end if if(lstatstavgdump) then call stats_compute_tavg_vel if (ltdump .or. ltkslicedump) call stats_compute_tavg_pedestrian_wind if (ltempeq) call stats_compute_tavg_temp if (lmoist) call stats_compute_tavg_moist if (lrh) call stats_compute_tavg_relative_humidity end if if(ltavg3d .or. lytdump) then if (nsv>0) call stats_compute_tavg_scalar end if if(ltavg3d) then if ((lchem) .and. (nsv>2)) call stats_compute_tavg_PSS end if if(lxydump) then call stats_compute_xyavg_vel if (ltempeq) call stats_compute_xyavg_temp if (lmoist) call stats_compute_xyavg_moist if (lrh) call stats_compute_xyavg_relative_humidity if (myid==0) then call writestat_nc(ncidxy, 'time', timee, nrecxy, .true.) call stats_write_xyavg_vel if (ltempeq) call stats_write_xyavg_temp if (lmoist) call stats_write_xyavg_moist if (lrh) call stats_write_xyavg_relative_humidity end if end if if(lydump) then call stats_compute_yavg_vel if (ltempeq) call stats_compute_yavg_temp if (lmoist) call stats_compute_yavg_moist if (lrh) call stats_compute_yavg_relative_humidity if (nsv>0) call stats_compute_yavg_scalar if (myidy==0) then call writestat_nc(ncidy, 'time', timee, nrecy, .true.) call stats_write_yavg_vel if (ltempeq) call stats_write_yavg_temp if (lmoist) call stats_write_yavg_moist if (lrh) call stats_write_yavg_relative_humidity if (nsv>0) call stats_write_yavg_scalar end if end if if(ltreedump) then call stats_compute_tree_vel if (ltempeq) call stats_compute_tree_temp if (lmoist) call stats_compute_tree_moist if (nsv>0) call stats_compute_tree_scalar end if tsamplep = dt else tsamplep = tsamplep + dt endif if ( (lstatstavgdump .or. ltreedump) & .and. tstatsdumpp >= tstatsdump ) then ! at every stats dump time instance dumpcount = dumpcount + 1 if (myid==0) then write(*,*) "---------------------------------" write(*,*) "Writing time average statistics" write(*,*) "stats dump count ::: ", dumpcount write(*,*) "timee ::: ", timee write(*,*) "---------------------------------" end if if(ltdump) then if (myidy == 0) call writestat_nc(ncidt, 'time', timee, nrect, .true.) call stats_write_tavg end if if (ltislicedump) call stats_write_tavg_islice if (ltjslicedump) call stats_write_tavg_jslice if (ltkslicedump) call stats_write_tavg_kslice if(lxytdump) then call stats_compute_xytavg_vel if (ltempeq) call stats_compute_xytavg_temp if (lmoist) call stats_compute_xytavg_moist if (lrh) call stats_compute_xytavg_relative_humidity if (myid==0) then call writestat_nc(ncidxyt, 'time', timee, nrecxyt, .true.) call stats_write_xytavg_vel if (ltempeq) call stats_write_xytavg_temp if (lmoist) call stats_write_xytavg_moist if (lrh) call stats_write_xytavg_relative_humidity end if end if if(lytdump) then call stats_compute_ytavg_vel if (ltempeq) call stats_compute_ytavg_temp if (lmoist) call stats_compute_ytavg_moist if (lrh) call stats_compute_ytavg_relative_humidity if (nsv>0) call stats_compute_ytavg_scalar if (myidy==0) then call writestat_nc(ncidyt, 'time', timee, nrecyt, .true.) call stats_write_ytavg_vel if (ltempeq) call stats_write_ytavg_temp if (lmoist) call stats_write_ytavg_moist if (lrh) call stats_write_ytavg_relative_humidity if (nsv>0) call stats_write_ytavg_scalar end if end if if(ltreedump) then if (myidy == 0) call writestat_nc(ncidtree, 'time', timee, nrectree, .true.) call stats_write_tree_vel if (ltempeq) call stats_write_tree_temp if (lmoist) call stats_write_tree_moist if (nsv>0) call stats_write_tree_scalar end if tstatsdumpp = dt tsamplep = dt if(tstatsgap>0.) then ! next averaging window starts after the gap, at tstatstart + tstatsgap ! relative to this dump (see stats_init); the current step does not ! belong to it, so the accumulation counters start from zero. tstatstart = tstatstart + tstatsdump + tstatsgap tstatsdumpp = 0. tsamplep = 0. !! note that if tstatsgap is used, stats_xy and stats_y will also be not written during the gap duration as the entire stats_main is skipped for the duration of the gap. end if if(lstatstavgdump) then call stats_reset_tavg_vel if (ltdump .or. ltkslicedump) call stats_reset_tavg_pedestrian_wind if (ltempeq) call stats_reset_tavg_temp if (lmoist) call stats_reset_tavg_moist if (lrh) call stats_reset_tavg_relative_humidity end if if(ltavg3d .or. lytdump) then if (nsv>0) call stats_reset_tavg_scalar end if if(ltavg3d) then if ((lchem) .and. (nsv>2)) call stats_reset_tavg_PSS end if if (ltreedump) then call stats_reset_tree_vel if (ltempeq) call stats_reset_tree_temp if (lmoist) call stats_reset_tree_moist if (nsv>0) call stats_reset_tree_scalar end if else tstatsdumpp = tstatsdumpp + dt endif end subroutine stats_main