1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68
|
module procedure_26_mod_1
implicit none
private
public :: error_type
type :: error_type
integer :: stat = 0
character(len=:), allocatable :: message
end type error_type
end module procedure_26_mod_1
module procedure_26_mod_2
use procedure_26_mod_1, only: error_type
implicit none
private
public :: check
interface check
module procedure :: check_stat
module procedure :: check_logical
end interface check
contains
subroutine check_stat(error, stat, message)
type(error_type), allocatable, intent(out) :: error
integer, intent(in) :: stat
character(len=*), intent(in), optional :: message
if (stat /= 0) then
allocate(error)
error%stat = stat
if (present(message)) error%message = message
end if
end subroutine check_stat
subroutine check_logical(error, expression, message)
type(error_type), allocatable, intent(out) :: error
logical, intent(in) :: expression
character(len=*), intent(in), optional :: message
if (.not. expression) then
allocate(error)
error%stat = 1
if (present(message)) error%message = message
end if
end subroutine check_logical
end module procedure_26_mod_2
program procedure_26
use procedure_26_mod_1, only: error_type
use procedure_26_mod_2, only: check
implicit none
type(error_type), allocatable :: error
integer, pointer :: ptr => null()
call check(error, .not.associated(ptr), "Pointer should not be associated")
if (allocated(error)) then
error stop "Test failed: "//trim(error%message)
else
print *, "Test passed"
end if
end program procedure_26
|