You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
(1) variable1 == variable2 (they could be array sizes)
(2) a variable >= value (for example an array index being positive)
(3) a variable <= value (within an array bound)
(4) low <= variable <= high
(5) variable1 <= variable2
Could stdlib have specific assertion subroutines for these common cases? Probably someone has already coded them for their own use. For example for (5) I have
subroutine assert_le(n1,n2,name1,name2,procedure)
! print an error message and stop if n1 > n2
integer , intent(in) :: n1,n2
character (len=*), intent(in) :: procedure ! name of program unit where assertion is made
character (len=*), intent(in) :: name1,name2 ! variable names
if (n1 > n2) then
write (*,"(a,2(1x,a),' =',2(1x,i0),a)") "in " // trim(procedure) // ",", &
trim(name1),trim(name2),n1,n2," need " // trim(name1) // " <= " // trim(name2) // ", STOPPING"
error stop
end if
end subroutine assert_le
invoked with code such as
call assert_le(ntrain,n,"ntrain","n","main")
There is #72 "Implement standard assert subroutine and associated macros", but a general assert subroutine testing a condition will give a less informative message.
The text was updated successfully, but these errors were encountered:
awvwgk
added
the
topic: utilities
containers, strings, files, OS/environment integration, unit testing, assertions, logging, ...
label
Sep 18, 2021
In my codes I often want to check whether
(1) variable1 == variable2 (they could be array sizes)
(2) a variable >= value (for example an array index being positive)
(3) a variable <= value (within an array bound)
(4) low <= variable <= high
(5) variable1 <= variable2
Could stdlib have specific assertion subroutines for these common cases? Probably someone has already coded them for their own use. For example for (5) I have
invoked with code such as
call assert_le(ntrain,n,"ntrain","n","main")
There is #72 "Implement standard assert subroutine and associated macros", but a general assert subroutine testing a condition will give a less informative message.
The text was updated successfully, but these errors were encountered: