subroutine rkmsg_r1(ier,srname,nrec,comm,flag)
!
! Part of rksuite_90 v1.0 (Aug 1994)
! software for initial value problems in ODEs
!
! Authors: R.W. Brankin (NAG Ltd., Oxford, England)
! I. Gladwell (Math Dept., SMU, Dallas, TX, USA)
! see main doc for contact details
!
integer, intent(in) :: ier, nrec
integer, intent(out), optional :: flag
character(len=*), intent(in) :: srname
type(rk_comm_real_1d), intent(inout) :: comm
!
logical :: ok, on, range_call
!
integer, parameter :: fatal=911, catastrophe=912, just_fine=1
logical, parameter :: tell=.false.
!
! Check where the call came from - if it is an indirect call from
! RANGE_INTEGRATE the run is not STOPped.
!
range_call = (srname=="RESET_T_END" .or. srname=="STEP_INTEGRATE" .or. &
srname=="INTERPOLATE") .and. comm%use_range
!
! Check if can continue with integrator.
!
ok = (srname=="STEP_INTEGRATE" .or. srname=="RANGE_INTEGRATE") .and. &
(ier==2 .or. ier==3 .or. ier==4)
!
! Check if program termination has been overridden.
!
on = get_stop_on_fatal_r1(comm)
!
if ((comm%print_message.and.ier>just_fine) .or. ier>=fatal) then
write (comm%outch,"(/a)") " **"
write (comm%outch,"(a)") comm%rec(1:nrec)
if (ier>=fatal) then
write (comm%outch,"(a/a,a,a/a/)") &
" **",&
" ** Catastrophic error detected in ", srname, ".",&
" **"
if ((.not.range_call.and.on.and.ier==fatal) .or. ier==catastrophe) then
write (comm%outch,"(a/a/a)") &
" **",&
" ** Execution of your program is being terminated.",&
" **"
stop
end if
else
if (ok) then
write (comm%outch,"(a/a,a,a,i2,a/a/a)") &
" **", &
" ** Warning from routine ", srname, " with flag set ",ier, ".",&
" ** You can continue integrating this problem.",&
" **"
else
write (comm%outch,"(a/a,a,a,i2,a/a/a)") &
" **", &
" ** Warning from routine ", srname, " with flag set ",ier, ".", &
" ** You cannot continue integrating this problem.", &
" **"
end if
if (.not.present(flag)) then
write (comm%outch,"(a/a/a)") &
" **",&
" ** Execution of your program is being terminated.",&
" **"
stop
end if
end if
end if
!
if (present(flag)) flag = ier
comm%rec(nrec+1:10) = " "
!
! Save the status of the routine associated with SRNAME
!
call set_saved_state_r1(srname,ier,comm)
!
! Indicate that a catastrophic error has been detected
!
!call set_saved_fatal_r1(comm,ier >= catastrophe)
!
end subroutine rkmsg_r1