Subroutine to handle errors
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
integer, | intent(in) | :: | severity | Severity level of the error |
||
integer, | intent(in) | :: | err_type | Type of the error |
||
character(len=*), | intent(in) | :: | message | Optional message |
||
character(len=*), | intent(in) | :: | source_file | Source file where the problem occurred |
||
integer, | intent(in) | :: | line_num | Source line at which the error occurred |
subroutine handle_error(severity, err_type, message, source_file, line_num)
!> Severity level of the error
integer, intent(in) :: severity
!> Type of the error
integer, intent(in) :: err_type
!> Optional message
character(len=*), intent(in) :: message
!> Source file where the problem occurred
character(len=*), intent(in) :: source_file
!> Source line at which the error occurred
integer, intent(in) :: line_num
integer :: iounit
integer :: ios
character(len=50) :: filename
if (severity == SEVERITY_WARN) then
iounit = stderr
call print_warning(iounit, source_file, line_num)
else
write(filename, fmt=ERROR_FILE) process_id
open(newunit=iounit, file=filename, iostat=ios, status="new", action="write")
if ( ios /= 0 ) then
write(unit=stderr, fmt=*) "File system I/O problem - reverting to terminal output"
iounit = stderr
endif
call write_error_header(iounit, source_file, line_num)
endif
select case (err_type)
case (TYPE_MEM)
call handle_mem_error(iounit, message)
case (TYPE_INCORRECT_ARG)
call handle_inc_error(iounit, message)
case default
call handle_generic_error(iounit, message)
end select
if (iounit /= stderr) then
close(unit=iounit)
endif
if (severity == SEVERITY_FATAL) then
if (associated(custom_handler)) then
call custom_handler(err_type, message, source_file, line_num)
else
stop "MiMiC has stopped with an error! See MiMiC_error file(s) for details"
endif
endif
end subroutine handle_error