@@ -543,20 +543,20 @@ subroutine mpas_add_clock_alarm(clock, alarmID, alarmTime, alarmTimeInterval, &
543543
544544 alarmPtr % isSet = .true.
545545 alarmPtr % ringTime = alarmTime
546+ if (present (alarmStartTime)) then
547+ alarmPtr % activeStartTime = alarmStartTime
548+ else
549+ alarmPtr % activeStartTime = mpas_get_clock_time(clock, MPAS_START_TIME)
550+ end if
551+ if (present (alarmStopTime)) then
552+ alarmPtr % activeStopTime = alarmStopTime
553+ else
554+ alarmPtr % activeStopTime = mpas_get_clock_time(clock, MPAS_STOP_TIME)
555+ end if
546556
547557 if (present (alarmTimeInterval)) then
548558 alarmPtr % isRecurring = .true.
549559 alarmPtr % ringTimeInterval = alarmTimeInterval
550- if (present (alarmStartTime)) then
551- alarmPtr % activeStartTime = alarmStartTime
552- else
553- alarmPtr % activeStartTime = mpas_get_clock_time(clock, MPAS_START_TIME)
554- end if
555- if (present (alarmStopTime)) then
556- alarmPtr % activeStopTime = alarmStopTime
557- else
558- alarmPtr % activeStopTime = mpas_get_clock_time(clock, MPAS_STOP_TIME)
559- end if
560560 if (clock % direction == MPAS_FORWARD) then
561561 alarmPtr % prevRingTime = alarmTime - alarmTimeInterval
562562 else
@@ -821,55 +821,57 @@ subroutine mpas_print_alarm(clock, alarmID, ierr)
821821 end subroutine mpas_print_alarm
822822
823823
824- !-----------------------------------------------------------------------
825- ! function mpas_is_alarm_active
826- !
827- !> \brief Determine if an alarm is currently active.
828- !> \author Andy Stokely
829- !> \date 10 / 01 / 2025
830- !> \details This function checks whether the current clock time falls
831- !> within the active start and stop times of the given alarm. If so,
832- !> it returns `.true. `. An optional error code may also be returned.
833- !-----------------------------------------------------------------------
834- logical function mpas_is_alarm_active (clock , alarm , time , ierr )
835- implicit none
836- type(MPAS_Clock_type), intent (in ) :: clock
837- type(MPAS_Alarm_type), pointer :: alarm
838- type(MPAS_Time_type), intent (in ) :: time
839- integer , intent (out ), optional :: ierr
840-
841- if (present (ierr)) ierr = 0
842-
843- mpas_is_alarm_active = (alarm % activeStartTime <= time &
844- .and. time <= alarm % activeStopTime)
845- end function mpas_is_alarm_active
846-
847-
848- !-----------------------------------------------------------------------
849- ! function mpas_prev_ring_in_window
850- !
851- !> \brief Check if the alarm’s previous ring was inside its window.
852- !> \author Andy Stokely
853- !> \date 10 / 01 / 2025
854- !> \details This function tests whether the alarm’s `prevRingTime`
855- !> occurred strictly within the defined start and stop times of the
856- !> alarm’s active window. The check uses an open interval:
857- !>
858- !> (start, stop )
859- !>
860- !> The boundaries themselves are excluded. If the previous ring time
861- !> lies inside this open interval, the function returns `.true. `.
862- !-----------------------------------------------------------------------
863- logical function mpas_prev_ring_in_window (alarm )
864- implicit none
865- type(MPAS_Alarm_type), pointer :: alarm
866-
867- mpas_prev_ring_in_window = (alarm % activeStartTime < alarm % prevRingTime &
868- .and. alarm % prevRingTime < alarm % activeStopTime)
869- end function mpas_prev_ring_in_window
870-
871-
872- logical function mpas_is_alarm_ringing (clock , alarmID , interval , ierr )
824+ !-----------------------------------------------------------------------
825+ ! function mpas_is_alarm_active
826+ !
827+ !> \brief Determine if an alarm is currently active.
828+ !> \author Andy Stokely
829+ !> \date 10 / 01 / 2025
830+ !> \details This function checks whether the provided time falls
831+ !> within the active start and stop times of the given alarm. If so,
832+ !> it returns `.true. `.
833+ !-----------------------------------------------------------------------
834+ logical function mpas_is_alarm_active (alarm , time )
835+
836+ implicit none
837+
838+ type(MPAS_Alarm_type), pointer :: alarm
839+ type(MPAS_Time_type), intent (in ) :: time
840+
841+ mpas_is_alarm_active = (alarm % activeStartTime <= time &
842+ .and. time <= alarm % activeStopTime)
843+
844+ end function mpas_is_alarm_active
845+
846+
847+ !-----------------------------------------------------------------------
848+ ! function mpas_prev_ring_in_window
849+ !
850+ !> \brief Check if the alarm’s previous ring was inside its window.
851+ !> \author Andy Stokely
852+ !> \date 10 / 01 / 2025
853+ !> \details This function tests whether the alarm’s `prevRingTime`
854+ !> occurred strictly within the defined start and stop times of the
855+ !> alarm’s active window. The check uses an open interval:
856+ !>
857+ !> (start, stop )
858+ !>
859+ !> The boundaries themselves are excluded. If the previous ring time
860+ !> lies inside this open interval, the function returns `.true. `.
861+ !-----------------------------------------------------------------------
862+ logical function mpas_prev_ring_in_window (alarm )
863+
864+ implicit none
865+
866+ type(MPAS_Alarm_type), pointer :: alarm
867+
868+ mpas_prev_ring_in_window = (alarm % activeStartTime < alarm % prevRingTime &
869+ .and. alarm % prevRingTime < alarm % activeStopTime)
870+
871+ end function mpas_prev_ring_in_window
872+
873+
874+ logical function mpas_is_alarm_ringing (clock , alarmID , interval , ierr )
873875
874876 implicit none
875877
@@ -940,10 +942,12 @@ logical function mpas_in_ringing_envelope(clock, alarmPtr, interval, ierr)
940942 integer , intent (out ), optional :: ierr
941943
942944 type (MPAS_Time_type) :: alarmNow
945+ type (MPAS_Time_type) :: currentTime
943946 type (MPAS_Time_type) :: alarmThreshold
944947
945- alarmNow = mpas_get_clock_time(clock, MPAS_NOW, ierr)
946- alarmThreshold = alarmPtr % ringTime
948+ currentTime = mpas_get_clock_time(clock, MPAS_NOW, ierr)
949+ alarmNow = currentTime
950+ alarmThreshold = alarmPtr % ringTime
947951
948952 mpas_in_ringing_envelope = .false.
949953
@@ -958,7 +962,7 @@ logical function mpas_in_ringing_envelope(clock, alarmPtr, interval, ierr)
958962 end if
959963
960964 if (alarmThreshold <= alarmNow) then
961- if (mpas_is_alarm_active(clock, alarmPtr, alarmNow, ierr ) &
965+ if (mpas_is_alarm_active(alarmPtr, currentTime ) &
962966 .or. mpas_prev_ring_in_window(alarmPtr)) then
963967 mpas_in_ringing_envelope = .true.
964968 end if
@@ -974,7 +978,7 @@ logical function mpas_in_ringing_envelope(clock, alarmPtr, interval, ierr)
974978 end if
975979
976980 if (alarmThreshold >= alarmNow) then
977- if (mpas_is_alarm_active(clock, alarmPtr, alarmNow, ierr ) &
981+ if (mpas_is_alarm_active(alarmPtr, currentTime ) &
978982 .or. mpas_prev_ring_in_window(alarmPtr)) then
979983 mpas_in_ringing_envelope = .true.
980984 end if
0 commit comments