forums.silverfrost.com Forum Index forums.silverfrost.com
Welcome to the Silverfrost forums
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

How to interrupt computation on a ClearWin+ program?

 
Post new topic   Reply to topic    forums.silverfrost.com Forum Index -> ClearWin+
View previous topic :: View next topic  
Author Message
rudnei



Joined: 29 Dec 2011
Posts: 31

PostPosted: Tue Oct 31, 2017 3:30 pm    Post subject: How to interrupt computation on a ClearWin+ program? Reply with quote

Hi,

I need some help here. I am developing a program that does 2-D computational fluid dynamics simulations using FTN95 and ClearWin+.

The computational routine is started as a call-back function to a user-selected menu item (created with %mn). This computational routine displays information (velocity, pressure, temperature, heat, etc) on a %gr graphics area.

Now I want to allow the user to interrupt this routine at any time. Ideally I would want it to be done by
a) pressing the ESC key, but
b) would settle for key+mouse button combination (say CTRL+MIDDLEBUTTON).

Inside the computational routine I would place some calls to

yield_program_control@(Y_TEMPORARILY)

and then process the events above (a or b). The second I know how to do it since I already have the %gr area opened with FULL_MOUSE_INPUT and there's a call-back function to deal with the mouse events. But how can I interrupt using the ESC key?

Many thanks in advance!

Cheers
Rudnei
Back to top
View user's profile Send private message
DanRRight



Joined: 10 Mar 2008
Posts: 1846
Location: South Pole, Antarctica

PostPosted: Tue Oct 31, 2017 4:34 pm    Post subject: Reply with quote

I know couple methods to run-pause-stop code which allow to do in parallel other things like realtime graphics and opening other menu items with working code doing other things.

One method is simple and almost perfect, but is not 100% reliable, while the second is 100% reliable but a bit too tricky to make a short demo out of my head, i am not quite getting its trick so i quickly forget it. I use both and will shortly describe them here. Now i am running out of time to search details but when time will allow i may find the demos.

Method 1. The GUI could be pretty complex and have hundreds callback for doing different things. If you will start all of callback functions with the Permit_another_callback@ then things go OK unless you by mistake hit the button several times too fast. Then this button will stop reacting. Rarely happening. And the amount of times another callbacks are permitted could be millions, no problems here. You can use buttons and radiobuttons and also in parallel the accelerator keys, by some reason they sometimes work when other fail. This method was promoted by Paul.

Method 2 needs short sample to show it. You create as usual the buttons (Run, Pause, Stop) with callback functions but the trick is to interrupt the source code of your GUI with additional subroutine which will have small part of the same GUI. This subroutine has to create window which will be permanently open during the run. All that looks like impossible even to comprehend but with the Clearwin this somehow works. Additional window can do nothing useful or do passively something like displaying elapsed CPU time, some menus etc. This method described me John Appleyard from Polyhedron two decades ago and it is the most bulletproof as it never failed in its everyday torture. If urgent, you can ask him

I published small reproducers of two or even three of such methods few times in this forum in the past, so you can search this forum using my name and keywords "Permit_another_callback@", "Appleyard", "Run-Pause-Stop", "multitasking" etc
Back to top
View user's profile Send private message
PaulLaidler
Site Admin


Joined: 21 Feb 2005
Posts: 5422
Location: Salford, UK

PostPosted: Tue Oct 31, 2017 5:39 pm    Post subject: Reply with quote

Something like this might work...

Code:
WINAPP
PROGRAM test
LOGICAL more
COMMON more
INTEGER,EXTERNAL:: cb
INTEGER ctrl
more = .TRUE.
iw = winio@("%ww[topmost]&")
iw = winio@("%^tt[Stop]&",cb)
iw = winio@("%lw",ctrl)
CALL calculate()
END PROGRAM test

SUBROUTINE calculate()
INCLUDE <windows.ins>
LOGICAL more
COMMON more
DO WHILE(more)
  PRINT*, "Calculating..."
  CALL sleep1@(1.0) !Replace this with your calculation
  CALL yield_program_control@(Y_TEMPORARILY)
ENDDO
PRINT*, "Calculation stopped..."
END SUBROUTINE

INTEGER FUNCTION cb()
LOGICAL more
COMMON more
more = .FALSE.
cb = 0
END FUNCTION
Back to top
View user's profile Send private message
rudnei



Joined: 29 Dec 2011
Posts: 31

PostPosted: Tue Oct 31, 2017 10:09 pm    Post subject: Reply with quote

Many thanks for your suggestions, very helpful!
Back to top
View user's profile Send private message
rudnei



Joined: 29 Dec 2011
Posts: 31

PostPosted: Tue Oct 31, 2017 10:09 pm    Post subject: Reply with quote

Many thanks for your suggestions, very helpful!
Cheers
Rudnei
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    forums.silverfrost.com Forum Index -> ClearWin+ All times are GMT + 1 Hour
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group