2014-05-26 22:40:42 +02:00
|
|
|
BEGIN_PROVIDER [ logical, abort_all ]
|
|
|
|
implicit none
|
|
|
|
BEGIN_DOC
|
|
|
|
! If True, all the calculation is aborted
|
|
|
|
END_DOC
|
2014-10-14 17:30:30 +02:00
|
|
|
call trap_signals
|
2014-05-26 22:40:42 +02:00
|
|
|
abort_all = .False.
|
|
|
|
|
|
|
|
END_PROVIDER
|
|
|
|
|
|
|
|
BEGIN_PROVIDER [ logical, abort_here ]
|
|
|
|
implicit none
|
|
|
|
BEGIN_DOC
|
|
|
|
! If True, all the calculation is aborted
|
|
|
|
END_DOC
|
|
|
|
abort_here = abort_all
|
|
|
|
END_PROVIDER
|
|
|
|
|
|
|
|
subroutine trap_signals
|
|
|
|
implicit none
|
|
|
|
BEGIN_DOC
|
|
|
|
! What to do when a signal is caught. Here, trap Ctrl-C and call the control_C subroutine.
|
|
|
|
END_DOC
|
2014-07-14 17:10:50 +02:00
|
|
|
integer, external :: catch_signal
|
2015-03-26 23:38:40 +01:00
|
|
|
integer :: sigusr2, status
|
|
|
|
sigusr2 = 12
|
|
|
|
call signal (sigusr2, catch_signal,status)
|
2014-05-26 22:40:42 +02:00
|
|
|
end subroutine trap_signals
|
|
|
|
|
2014-07-14 17:10:50 +02:00
|
|
|
integer function catch_signal(signum)
|
2014-05-26 22:40:42 +02:00
|
|
|
implicit none
|
|
|
|
integer, intent(in) :: signum
|
|
|
|
BEGIN_DOC
|
|
|
|
! What to do on Ctrl-C. If two Ctrl-C are pressed within 1 sec, the calculation if aborted.
|
|
|
|
END_DOC
|
|
|
|
double precision, save :: last_time
|
|
|
|
double precision :: this_time
|
2014-07-14 17:10:50 +02:00
|
|
|
catch_signal = 0
|
2014-05-26 22:40:42 +02:00
|
|
|
call wall_time(this_time)
|
|
|
|
if (this_time - last_time < 1.d0) then
|
2014-07-14 17:10:50 +02:00
|
|
|
print *, 'Caught Signal ', signum
|
2014-05-26 22:40:42 +02:00
|
|
|
abort_all = .True.
|
|
|
|
endif
|
|
|
|
last_time = this_time
|
|
|
|
abort_here = .True.
|
2014-07-14 17:10:50 +02:00
|
|
|
end
|
2014-05-26 22:40:42 +02:00
|
|
|
|