Re: How to halt a running program without losing data?



It isn't fair to imply that any program in the scientific/engineering
arena ought to be able to decide for itself in all circumstances when
its task is done, by reaching some convergence criterion or running out
of iterations. Nor is it fair to say that changing variables normally
is done only when debugging. The software is merely a calculation tool
assisting the user, and the need or desire to interact with it, by
unsolicited interrupt (usually from the keyboard) depends on the nature
of the application and how the user makes use of it. It is entirely
reasonable to envision an application that allows the user to monitor
progress of calculations, pause it to ask for intermediate results, and
even make changes to parameters of the calculations based on what is
seen before continuing. Such dialog with the user via the keyboard of
course can be programmed into the application, but triggering the
dialog requires that the application be able to ask at appropriate
places in its calculations: "has the user signalled that he wishes to
interact?"

I can say for certain that such an application is conceivable, because
this is the nature of a chemical process simulator. In the case of the
simulator I developed, the Escape key is used for signalling, first
under DOS and currently under Windows. The interactive mode extends the
utility of the software greatly. It lets the user explore changes in
the process parameters. Since development of the real process, or at
least the model of it, involves debugging at the application level, the
interactive mode lets the user interact on demand.

The OP doesn't want simply to kill the run; that is done easily via the
OS. It is the means of posting a signal to the application that is
sought. The solution is outside the standard, as has been noted, and
will be OS-dependent. In my case, I used the Lahey-provided service
routine provided with the 16-bit F77L and with the 32-bit EM32 back in
the 1980s for DOS. For Windows (Lahey LF95), I put together a routine
that used an API call to see of the Escape key has been pressed. The
simulator periodically calls the routine to see if it should begin
dialog with the user or just continue calculations. I posted source for
it the routine in the "code repository on the Lahey web site.


Ron Shepard wrote:
> In article <1121086174.215125.289690@xxxxxxxxxxxxxxxxxxxxxxxxxxxx>,
> "Random Programmer" <nonexistent2032@xxxxxxxxxxx> wrote:
>
> >
> > Is there a Fortran command to get the program to pause if say Ctrl-C is
> > hit and ask the user for a halt confirmation?....snip
>
> I think your question is not clear. The "programmer" already has
> the control to stop a program in various ways. He could check the
> iteration count, he could check for numerical convergence, he could
> periodically prompt the user to determine whether to continue, he
> could periodically read data from an external file, and so on.
>
............snip.
>
> As far as changing variables in some external way, that is usually
> something only done when the code is run under control of a
> debugger. .....snip
>
> $.02 -Ron Shepard

.


Quantcast