Routine that checks whether an integer variable lies within the desired range author: P J Knight, CCFE, Culham Science Centre outfile : input integer : Fortran output unit identifier cvar : input string : name of variable varval : input integer : value of variable min_value : input integer : minimum allowed value of variable max_value : input integer : maximum allowed value of variable This routine checks whether an integer variable lies within the range predetermined by the user, and reports an error and stops if it doesn't. None
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
character(len=*), | intent(in) | :: | cvar | |||
integer, | intent(in) | :: | varval | |||
integer, | intent(in) | :: | min_value | |||
integer, | intent(in) | :: | max_value |
subroutine check_range_int(cvar,varval,min_value,max_value)
!! Routine that checks whether an integer variable lies within
!! the desired range
!! author: P J Knight, CCFE, Culham Science Centre
!! outfile : input integer : Fortran output unit identifier
!! cvar : input string : name of variable
!! varval : input integer : value of variable
!! min_value : input integer : minimum allowed value of variable
!! max_value : input integer : maximum allowed value of variable
!! This routine checks whether an integer variable lies within
!! the range predetermined by the user, and reports an error
!! and stops if it doesn't.
!! None
!
! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
implicit none
! Arguments
character(len=*), intent(in) :: cvar
integer, intent(in) :: varval,min_value,max_value
! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
if (min_value > max_value) then
write(outfile,*) 'Illegal relative values of min_value and max_value'
write(outfile,*) 'for variable ',cvar
write(*,*) 'Illegal relative values of min_value and max_value'
write(*,*) 'for variable ',cvar
error = .True.
end if
if ((varval < min_value).or.(varval > max_value)) then
write(outfile,*) cvar,' lies outside its allowed range :'
write(outfile,*) 'Minimum value = ',min_value
write(outfile,*) 'Maximum value = ',max_value
write(outfile,*) ' Actual value = ',varval
write(*,*) cvar,' lies outside its allowed range :'
write(*,*) 'Minimum value = ',min_value
write(*,*) 'Maximum value = ',max_value
write(*,*) ' Actual value = ',varval
error = .True.
end if
end subroutine check_range_int