7 use itm_types , itm_r8 => r8, itm_r4 => r4
16 logical,
save :: defaultdostop = .true.
17 integer,
save :: failcount = 0
18 integer,
save :: msgprefixlen = 0
19 character(256),
save :: msgprefix
32 subroutine assertfail( failmsg, doStop )
33 character(*),
intent(in),
optional :: failmsg
34 logical,
intent(in),
optional :: dostop
39 ldostop = defaultdostop
40 if ( present( dostop ) ) ldostop = dostop
42 if ( present( failmsg ) )
then
43 if ( msgprefixlen > 0 )
then
44 write (*,*)
'itm_assert: '//msgprefix(1:msgprefixlen)//
' '//failmsg
46 write (*,*)
'itm_assert: '//failmsg
49 if ( msgprefixlen > 0 )
then
50 write (*,*)
'itm_assert: '//msgprefix(1:msgprefixlen)
55 stop
"itm_assert: an assertion failed, stopping immediately."
57 failcount = failcount + 1
58 write(*,*)
"itm_assert: an assertion failed, continuing."
61 end subroutine assertfail
71 logical,
intent(in),
optional :: dostop
73 if ( present( dostop ) )
then
74 defaultdostop = dostop
77 defaultdostop = .true.
87 character(len=*),
intent(in),
optional :: prefix
89 if ( present( prefix ) )
then
90 msgprefixlen = min( len(prefix), len( msgprefix ) )
91 msgprefix(1:msgprefixlen) = prefix(1:msgprefixlen)
121 character(*),
intent(in),
optional :: failmsg
122 logical,
intent(in),
optional :: dostop
128 if ( present( dostop ) ) ldostop = dostop
130 if ( present( failmsg ) )
then
132 call
assert( failcount == 0, failmsg, ldostop )
135 call
assert( failcount == 0,
itmint2str( failcount )//
' assertions failed', ldostop )
161 subroutine assert( test, failmsg, doStop )
162 logical,
intent(in) :: test
163 character(*),
intent(in),
optional :: failmsg
164 logical,
intent(in),
optional :: dostop
166 if ( .not. test )
then
167 call assertfail( failmsg, dostop )
181 real(ITM_R8),
intent(in) :: x1, x2
182 character(*),
intent(in),
optional :: failmsg
183 logical,
intent(in),
optional :: dostop
188 if ( .not. ( ( ( x1 + 2 * spacing(
real( x1 ) ) ) >= x2 ) &
189 & .and. ( x1 - 2 * spacing( real( x1 ) ) ) <= x2 ) ) then
191 call assertfail( failmsg, dostop )