diff --git a/src/libmtime.f90 b/src/libmtime.f90 index b762fee12899caa8bd9922611cc5bd49e2ea586d..be34111f81f066ed25e27ef6025a47c6a492907e 100644 --- a/src/libmtime.f90 +++ b/src/libmtime.f90 @@ -3392,6 +3392,7 @@ module mtime_print_by_callback !> @endcond DOXYGEN_IGNORE_THIS ! interface finish_mtime + module procedure finish_mtime_plain module procedure finish_mtime_datetime module procedure finish_mtime_timedelta end interface finish_mtime @@ -3464,6 +3465,17 @@ contains finish_message => finish_procedure end subroutine register_finish_mtime_procedure !> + !! @brief Calling this procedure make mtime issuing an error message and finish. + !! + !! @param[in] leading_text the leading information, eg. the caller + !! @param[in] message_text the message text provided + !! + SUBROUTINE finish_mtime_plain(leading_text, message_text) + character(len=*), intent(in) :: leading_text + character(len=*), intent(in) :: message_text + CALL finish_message(TRIM(leading_text), TRIM(message_text)) + END SUBROUTINE finish_mtime_plain + !> !! @brief Print a datetime with associated text information by the provided callback function and finish program. !! Can be used via the generic finish_mtime subroutine. !! diff --git a/src/libmtime_hl.f90 b/src/libmtime_hl.f90 index 928e6133bedf1a57f2c990de1615b01ec5dc46c4..4b65b8ffe920c0b9dbf3185f9c98ed122520ccb1 100644 --- a/src/libmtime_hl.f90 +++ b/src/libmtime_hl.f90 @@ -11,7 +11,6 @@ module mtime_hl use mtime - use error_handling implicit none @@ -90,12 +89,22 @@ module mtime_hl module procedure t_timedelta_assign_ms end interface t_timedelta - !> Error info type: mtime error - type, extends(t_error_info) :: t_mtime_error - end type t_mtime_error contains + !___________________________________________________________________________ + ! auxiliary routine: handle error code. + SUBROUTINE handle_errno(errno, routine_str) + INTEGER, INTENT(IN) :: errno + CHARACTER(LEN=*), INTENT(IN) :: routine_str + CHARACTER(len=max_mtime_error_str_len) :: error_str + IF (errno /= no_error) THEN + CALL mtime_strerror(errno, error_str) + CALL finish_mtime(routine_str, error_str) + END IF + END SUBROUTINE handle_errno + + !___________________________________________________________________________ ! datetime section: ! @@ -105,7 +114,9 @@ contains class(t_datetime), intent(out) :: to class(t_datetime), intent(in) :: from type(datetime), pointer :: dt_tmp - dt_tmp => newdatetime(from%dt) + INTEGER :: errno + dt_tmp => newdatetime(from%dt, errno) + CALL handle_errno(errno, __FILE__//"__LINE__") to%dt = dt_tmp call deallocatedatetime(dt_tmp) end subroutine assign_t_datetime @@ -115,7 +126,9 @@ contains type(t_datetime) function t_datetime_assign_string(dt_string) character(len=*), intent(in) :: dt_string type(datetime), pointer :: dt_tmp - dt_tmp => newdatetime(dt_string) + INTEGER :: errno + dt_tmp => newdatetime(dt_string, errno) + CALL handle_errno(errno, __FILE__//"__LINE__") t_datetime_assign_string%dt = dt_tmp call deallocatedatetime(dt_tmp) end function t_datetime_assign_string @@ -130,47 +143,31 @@ contains ! Convert t_datetime object to string. ! - function t_datetime_to_string(this, opt_error) + function t_datetime_to_string(this) character(len=max_datetime_str_len) :: t_datetime_to_string - type(t_error), intent(out), optional :: opt_error class (t_datetime) :: this type(datetime), pointer :: dt_tmp integer :: errno - character(len=max_error_str_len) :: error_str - dt_tmp => newdatetime(this%dt) - if (present(opt_error)) then - call datetimetostring(dt_tmp, t_datetime_to_string, errno) - if (errno /= 0) then - call mtime_strerror(errno, error_str) - call create_error(opt_error, t_mtime_error(error_str)) - end if - else - call datetimetostring(dt_tmp, t_datetime_to_string) - end if - call deallocatedatetime(dt_tmp) + dt_tmp => newdatetime(this%dt, errno) + CALL handle_errno(errno, __FILE__//"__LINE__") + CALL datetimetostring(dt_tmp, t_datetime_to_string, errno) + CALL handle_errno(errno, __FILE__//"__LINE__") + CALL deallocatedatetime(dt_tmp) end function t_datetime_to_string ! Convert t_datetime object to string. ! - function t_datetime_to_posix_string(this, format_string, opt_error) + function t_datetime_to_posix_string(this, format_string) character(len=max_datetime_str_len) :: t_datetime_to_posix_string character(len=*), intent(in) :: format_string - type(t_error), intent(out), optional :: opt_error class (t_datetime) :: this type(datetime), pointer :: dt_tmp integer :: errno - character(len=max_error_str_len) :: error_str - dt_tmp => newdatetime(this%dt) - if (present(opt_error)) then - call datetimetoposixstring(dt_tmp, t_datetime_to_posix_string, format_string, errno) - if (errno /= 0) then - call mtime_strerror(errno, error_str) - call create_error(opt_error, t_mtime_error(error_str)) - end if - else - call datetimetostring(dt_tmp, t_datetime_to_posix_string) - end if - call deallocatedatetime(dt_tmp) + dt_tmp => newdatetime(this%dt, errno) + CALL handle_errno(errno, __FILE__//"__LINE__") + CALL datetimetoposixstring(dt_tmp, t_datetime_to_posix_string, format_string, errno) + CALL handle_errno(errno, __FILE__//"__LINE__") + CALL deallocatedatetime(dt_tmp) end function t_datetime_to_posix_string ! Addition of time interval to datetime object. @@ -179,10 +176,13 @@ contains type (t_datetime) :: dt_td_sum class (t_datetime), intent(in) :: this class (t_timedelta), intent(in) :: td - type(datetime), pointer :: dt_tmp - type(timedelta), pointer :: td_tmp - dt_tmp => newDatetime(this%dt) - td_tmp => newTimedelta(td%td) + type(datetime), pointer :: dt_tmp + type(timedelta), pointer :: td_tmp + INTEGER :: errno + dt_tmp => newDatetime(this%dt, errno) + CALL handle_errno(errno, __FILE__//"__LINE__") + td_tmp => newTimedelta(td%td, errno) + CALL handle_errno(errno, __FILE__//"__LINE__") dt_tmp = dt_tmp + td_tmp dt_td_sum%dt = dt_tmp call deallocateDatetime(dt_tmp) @@ -195,10 +195,13 @@ contains type (t_datetime) :: dt_td_sum class (t_datetime), intent(in) :: this class (t_timedelta), intent(in) :: td - type(datetime), pointer :: dt_tmp - type(timedelta), pointer :: td_tmp - dt_tmp => newDatetime(this%dt) - td_tmp => newTimedelta(td%td) + type(datetime), pointer :: dt_tmp + type(timedelta), pointer :: td_tmp + INTEGER :: errno + dt_tmp => newDatetime(this%dt, errno) + CALL handle_errno(errno, __FILE__//"__LINE__") + td_tmp => newTimedelta(td%td, errno) + CALL handle_errno(errno, __FILE__//"__LINE__") if (td_tmp%sign == "+") then td_tmp%sign = "-" else @@ -264,9 +267,11 @@ contains ! subroutine assign_t_timedelta(to, from) class(t_timedelta), intent(out) :: to - class(t_timedelta), intent(in) :: from - type(timedelta), pointer :: td_tmp - td_tmp => newTimedelta(from%td) + class(t_timedelta), intent(in) :: from + type(timedelta), pointer :: td_tmp + INTEGER :: errno + td_tmp => newTimedelta(from%td, errno) + CALL handle_errno(errno, __FILE__//"__LINE__") to%td = td_tmp to%td%sign = td_tmp%sign call deallocateTimedelta(td_tmp) @@ -275,9 +280,11 @@ contains ! constructor for timedelta string ! type(t_timedelta) function t_timedelta_assign_string(td_string) - character(len=*), intent(in) :: td_string - type(timedelta), pointer :: td_tmp - td_tmp => newtimedelta(td_string) + character(len=*), intent(in) :: td_string + type(timedelta), pointer :: td_tmp + INTEGER :: errno + td_tmp => newtimedelta(td_string, errno) + CALL handle_errno(errno, __FILE__//"__LINE__") t_timedelta_assign_string%td = td_tmp t_timedelta_assign_string%td%sign = td_tmp%sign call deallocatetimedelta(td_tmp) @@ -286,11 +293,14 @@ contains ! constructor for integer milliseconds (integer) ! type(t_timedelta) function t_timedelta_assign_ms(td_ms) - integer, intent(in) :: td_ms - type(timedelta), pointer :: td_tmp + integer, intent(in) :: td_ms + type(timedelta), pointer :: td_tmp character(len=max_timedelta_str_len) :: td_string - call getptstringfromms(int(td_ms,i8), td_string) - td_tmp => newtimedelta(td_string) + INTEGER :: errno + CALL getptstringfromms(INT(td_ms,i8), td_string, errno) + CALL handle_errno(errno, __FILE__//"__LINE__") + td_tmp => newtimedelta(td_string, errno) + CALL handle_errno(errno, __FILE__//"__LINE__") t_timedelta_assign_ms%td = td_tmp t_timedelta_assign_ms%td%sign = td_tmp%sign call deallocatetimedelta(td_tmp) @@ -298,23 +308,15 @@ contains ! Convert t_timedelta object to string. ! - function t_timedelta_to_string(this, opt_error) + function t_timedelta_to_string(this) character(len=max_timedelta_str_len) :: t_timedelta_to_string class (t_timedelta) :: this - type(t_error), intent(out), optional :: opt_error type(timedelta), pointer :: td_tmp INTEGER :: errno - character(len=max_error_str_len) :: error_str - td_tmp => newtimedelta(this%td) - if (present(opt_error)) then - call timedeltatostring(td_tmp, t_timedelta_to_string, errno) - if (errno /= 0) then - call mtime_strerror(errno, error_str) - call create_error(opt_error, t_mtime_error(error_str)) - end if - else - call timedeltatostring(td_tmp, t_timedelta_to_string) - end if + td_tmp => newtimedelta(this%td, errno) + CALL handle_errno(errno, __FILE__//"__LINE__") + CALL timedeltatostring(td_tmp, t_timedelta_to_string, errno) + CALL handle_errno(errno, __FILE__//"__LINE__") call deallocatetimedelta(td_tmp) end function t_timedelta_to_string