[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: directing control after program interruption




"D. Mattes" <dmattes@u.washington.edu> writes:

> hello IDL power users:  i have a long minimization process running under
> IDL.  i would like the user to be able to interrupt the process at any
> time.  once the user interrupts by typing ctrl-c, i would like to direct
> program control to a different part of the routine.  the only way i know
> to resume the program run is the .continue executive command, but that
> just continues on with the next statement, whereas i would like to branch 
> to the end of the routine.  is there a system variable that is set when a
> user interrupts program flow?  or does this fall into exception handling?

I do not think IDL is capable of what you are asking.  On the other
hand, you can check for another control character to use for a
termination criterium.  The GET_KBRD() function will poll the keyboard
without pausing, so you can do this periodically (i.e., every
iteration).  Unfortunately, it will consume the keyboard buffer
contents, but that's the price you pay.

Here is how I do it in MPFIT, which looks for control-G ( = ASCII 7):

      k = get_kbrd(0)
      if k EQ string(byte(7)) then begin
          message, 'WARNING: minimization not complete', /info
          print, 'Do you want to terminate this procedure? (y/n)', $
            format='(A,$)'
          k = ''
          read, k
          if strupcase(strmid(k,0,1)) EQ 'Y' then begin
              message, 'WARNING: Procedure is terminating.', /info
              mperr = -1
          endif
      endif

MPFIT is a least squares fitter available here:

  http://cow.physics.wisc.edu/~craigm/idl/idl.html

Good luck!
Craig


-- 
--------------------------------------------------------------------------
Craig B. Markwardt, Ph.D.         EMAIL:    craigmnet@cow.physics.wisc.edu
Astrophysics, IDL, Finance, Derivatives | Remove "net" for better response
--------------------------------------------------------------------------