I can supply you with my version of some bits of code I use in a %gr menu based graphics window. The parts are:
- A menu option to set an interrupt.
- the called interrupt routine which resets the stop routines
- The routine which allows interupts to be tested
- sample code using and testing for interrupts
Basically for my approach, there are 2 parts:
- setting the interupt to be allowed
- testing for and responding to the interupt.
the main running program loop must test for an interupt to have occurred ( at regular intervals, not too often and not to infrequent ) and then return to the menu after it occurs and is recognised.
The interupt can also be enabled from a mouse click, such as
if (reason.eq.'MOUSE_LEFT_CLICK') then ! left click to stop
run_flag = .false.
call window_update@ (run_flag)
run_flag and quit_on are duplicate variables for testing ( legacy code! )
There are probably other ways to do this, but this works for me, no guarantees !!
Good luck
The code bits are:
!
! Part of the menu system to enable interrupt
i = winio@ ('%ca@&', caption)
i = winio@ ('%`^gr[grey, rgb_colours, full_mouse_input]&', &
w_width, w_depth, w_handle, mouse_back_func)
..
i = winio@ ('%mn[&Interupt]&', on_stop, detect_interupt_func)
..
i = winio@ ('%mn[&Help]', on_run, Help_func)
!
! end of menu routine
integer4 function detect_interupt_func()
!
! Called when user interupts the program in the menu
! run_flag & quiton are reset
include <JDC_menu.ins> ! contains run_flag, on_run, on_stop etc
include 'quitcm.ins' ! contains quit_on
integer4 i
!
i = winio@ ('%si? Interrupt has been selected&')
i = winio@ ('%nl%cn%bt[OK]')
!
if (i > 0) then
run_flag = .false.
quit_on = .true.
call window_update@ (run_flag)
call window_update@ (quiton)
write (98,'(a)') 'Interrupt detected'
end if
!
detect_interupt_func = 1
end function detect_interupt_func
subroutine user_look
!
! Temporary suspension of program to enable update of interupt
! this should be equivalent to QUITEST
! it should be only called in wobble mode
include <clearwin.ins>
call temporary_yield@
return
end subroutine user_look
! Part of the code in the part of the program which draws and tests for interupt
!
! Before drawing loop starts, enable interupt
on_run = 0 ! turn off normal menu
on_stop = 1 ! turn on interrupt menu
run_flag = .true. ! program run is enabled
quit_on = .false. ! quit interrupt enabled
call window_update@ (on_run)
call window_update@ (on_stop)
call window_update@ (run_flag)
call window_update@ (quiton)
!
call permit_another_callback@
!
! now cycle through each screen display
!
num = cycles_per_minute ! run for 60 seconds
DO k = 0, num
CALL elapse_second (CPUS) ! start of display
!
call user_look ! look for user interupt
!
IF (QUITON) then
call screen_report ('QUITON recognised')
EXIT
end if
if (.not.run_flag) then
call screen_report ('run_flag recognised')
EXIT
end if
!
! display this screen
...