Skip to content

Commit

Permalink
Fix start time for time series stats interval
Browse files Browse the repository at this point in the history
Before this merge, it was incorrectly assumed to be one time
step before the current time.  The correct interval depends on
the compute interval, which has now been made available in the
form of the `computeInterval`.
  • Loading branch information
xylar committed Oct 1, 2022
1 parent 1523108 commit ad10e1c
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -576,11 +576,12 @@ subroutine ocn_analysis_compute_startup(domain, err)!{{{

integer :: timeLevel, err_tmp

character (len=StrKIND) :: configName, timerName
character (len=StrKIND), pointer :: config_AM_output_stream
character (len=StrKIND) :: configName, alarmName, timerName
character (len=StrKIND), pointer :: config_AM_output_stream, config_AM_compute_interval
logical, pointer :: config_AM_enable, config_AM_write_on_startup, config_AM_compute_on_startup
type (mpas_pool_iterator_type) :: poolItr
integer :: nameLength
type (MPAS_TimeInterval_type) :: computeInterval

err = 0

Expand All @@ -605,8 +606,18 @@ subroutine ocn_analysis_compute_startup(domain, err)!{{{
#ifdef MPAS_DEBUG
call mpas_log_write( ' Computing AM ' // poolItr % memberName(1:nameLength))
#endif
configName = 'config_AM_' // poolItr % memberName(1:nameLength) // '_compute_interval'
call mpas_pool_get_config(domain % configs, configName, config_AM_compute_interval)
if ( config_AM_compute_interval == 'output_interval') then
computeInterval = MPAS_stream_mgr_get_stream_interval(domain % streamManager, &
streamID=config_AM_output_stream, direction=MPAS_STREAM_OUTPUT, ierr=err_tmp)
else
alarmName = poolItr % memberName(1:nameLength) // computeAlarmSuffix
computeInterval = mpas_alarm_interval(domain % clock, alarmName, ierr=err_tmp)
end if

call mpas_timer_start(timerName)
call ocn_compute_analysis_members(domain, timeLevel, poolItr % memberName, err_tmp)
call ocn_compute_analysis_members(domain, timeLevel, poolItr % memberName, computeInterval, err_tmp)
call mpas_timer_stop(timerName)
err = ior(err, err_tmp)
end if
Expand Down Expand Up @@ -789,6 +800,7 @@ subroutine ocn_analysis_compute(domain, err)!{{{
logical, pointer :: config_AM_enable
type (mpas_pool_iterator_type) :: poolItr
integer :: nameLength
type (MPAS_TimeInterval_type) :: computeInterval
err = 0
Expand Down Expand Up @@ -819,17 +831,20 @@ subroutine ocn_analysis_compute(domain, err)!{{{
#ifdef MPAS_DEBUG
call mpas_log_write( ' Computing AM ' // poolItr % memberName(1:nameLength))
#endif
computeInterval = MPAS_stream_mgr_get_stream_interval(domain % streamManager, streamID=config_AM_output_stream, &
direction=MPAS_STREAM_OUTPUT, ierr=err_tmp)
call mpas_timer_start(timerName)
call ocn_compute_analysis_members(domain, timeLevel, poolItr % memberName, err_tmp)
call ocn_compute_analysis_members(domain, timeLevel, poolItr % memberName, computeInterval, err_tmp)
call mpas_timer_stop(timerName)
end if
else if ( mpas_is_alarm_ringing(domain % clock, alarmName, ierr=err_tmp) ) then
call mpas_reset_clock_alarm(domain % clock, alarmName, ierr=err_tmp)
#ifdef MPAS_DEBUG
call mpas_log_write( ' Computing AM ' // poolItr % memberName(1:nameLength))
#endif
computeInterval = mpas_alarm_interval(domain % clock, alarmName, ierr=err_tmp)
call mpas_timer_start(timerName)
call ocn_compute_analysis_members(domain, timeLevel, poolItr % memberName, err_tmp)
call ocn_compute_analysis_members(domain, timeLevel, poolItr % memberName, computeInterval, err_tmp)
call mpas_timer_stop(timerName)
end if
end if
Expand Down Expand Up @@ -1319,11 +1334,12 @@ end subroutine ocn_precompute_analysis_members!}}}
!> This private routine calls the correct compute routine for each analysis member.
!
!-----------------------------------------------------------------------
subroutine ocn_compute_analysis_members(domain, timeLevel, analysisMemberName, iErr)!{{{
subroutine ocn_compute_analysis_members(domain, timeLevel, analysisMemberName, computeInterval, iErr)!{{{
type (domain_type), intent(inout) :: domain !< Input: Domain information
integer, intent(in) :: timeLevel !< Input: Time level to compute with in analysis member
character (len=*), intent(in) :: analysisMemberName !< Input: Name of analysis member
integer, intent(out) :: iErr !< Output: Error code
type (MPAS_TimeInterval_type), intent(in) :: computeInterval
integer :: nameLength, err_tmp
Expand Down Expand Up @@ -1396,22 +1412,22 @@ subroutine ocn_compute_analysis_members(domain, timeLevel, analysisMemberName, i
! time is last
else if ( analysisMemberName(1:nameLength) == 'timeSeriesStatsDaily' ) then
call ocn_compute_time_series_stats(domain, timeLevel, &
timeSeriesDailyTAG, err_tmp)
timeSeriesDailyTAG, computeInterval, err_tmp)
else if ( analysisMemberName(1:nameLength) == 'timeSeriesStatsMonthly' ) then
call ocn_compute_time_series_stats(domain, timeLevel, &
timeSeriesMonthlyTAG, err_tmp)
timeSeriesMonthlyTAG, computeInterval, err_tmp)
else if ( analysisMemberName(1:nameLength) == 'timeSeriesStatsClimatology' ) then
call ocn_compute_time_series_stats(domain, timeLevel, &
timeSeriesClimatologyTAG, err_tmp)
timeSeriesClimatologyTAG, computeInterval, err_tmp)
else if ( analysisMemberName(1:nameLength) == 'timeSeriesStatsCustom' ) then
call ocn_compute_time_series_stats(domain, timeLevel, &
timeSeriesCustomTAG, err_tmp)
timeSeriesCustomTAG, computeInterval, err_tmp)
else if ( analysisMemberName(1:nameLength) == 'timeSeriesStatsMonthlyMin' ) then
call ocn_compute_time_series_stats(domain, timeLevel, &
timeSeriesMonthlyMinTAG, err_tmp)
timeSeriesMonthlyMinTAG, computeInterval, err_tmp)
else if ( analysisMemberName(1:nameLength) == 'timeSeriesStatsMonthlyMax' ) then
call ocn_compute_time_series_stats(domain, timeLevel, &
timeSeriesMonthlyMaxTAG, err_tmp)
timeSeriesMonthlyMaxTAG, computeInterval, err_tmp)
end if
iErr = ior(iErr, err_tmp)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -304,10 +304,11 @@ end subroutine ocn_init_time_series_stats!}}}
!> This routine conducts all computation required for this
!> MPAS-Ocean analysis member.
!-----------------------------------------------------------------------
subroutine ocn_compute_time_series_stats(domain, timeLevel, instance, err)!{{{
subroutine ocn_compute_time_series_stats(domain, timeLevel, instance, computeInterval, err)!{{{
! input variables
character (len=StrKIND), intent(in) :: instance
integer, intent(in) :: timeLevel
type (MPAS_TimeInterval_type), intent(in) :: computeInterval

! input/output variables
type (domain_type), intent(inout) :: domain
Expand Down Expand Up @@ -343,7 +344,7 @@ subroutine ocn_compute_time_series_stats(domain, timeLevel, instance, err)!{{{
if (unset_xtime) then
end_intv = mpas_get_clock_time(domain % clock, MPAS_NOW, err)
call mpas_get_time(end_intv, dateTimeString=end_xtime, ierr=err)
start_intv = end_intv - mpas_get_clock_timestep(domain % clock, err)
start_intv = end_intv - computeInterval
call mpas_get_time(start_intv, dateTimeString=start_xtime, ierr=err)
call mpas_set_time(reference_time, dateTimeString=config_output_reference_time)
call mpas_get_timeInterval(start_intv - reference_time, dt=Time_bnds(1))
Expand Down

0 comments on commit ad10e1c

Please sign in to comment.