comp.lang.idl-pvwave archive
Messages from Usenet group comp.lang.idl-pvwave, compiled by Paulo Penteado

Home » Public Forums » archive » Re: how to interrupt in IDL for windows ?
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Switch to threaded view of this topic Create a new topic Submit Reply
Re: how to interrupt in IDL for windows ? [message #34836] Wed, 23 April 2003 14:55
Craig Markwardt is currently offline  Craig Markwardt
Messages: 1869
Registered: November 1996
Senior Member
Kristian Kjaer <Kristian.Kjaer@Risoe.DK> writes:
>
> I am using Craig Markwardt's nice MPFITFUN. Usually it converges fast
> but sometimes by mistake I let it loose with the wrong start parameters,
> too many free parameters, and a large number of allowed iterations. Then
> I can only sit and wait for my IDL prompt to come back, or kill the
> whole process and loose some of my work.
>

I think if you use the /ITERSTOP keyword to any of the MPFIT
functions, then it will check for control-G and break out of the
fitting loop. Why control-G? I'm an Emacs user...

If you want to make it into a widget with a "stop" button, then you
probably want to use the ITERPROC. Here is an example of how to set
up a small window (INFO.TLB is the top level base of the whole
application):

geom = widget_info(info.tlb, /geometry)
xpos = geom.xoffset + geom.xsize/2 - 100
ypos = geom.yoffset + geom.ysize/2 - 50

tlb = widget_base(title='Fitting Status', row=1, xoffset=xpos, yoffset=ypos)
stopbut = widget_button(tlb, value='STOP')
col = widget_base(tlb, column=1)
stat1line = widget_label(col, value=' Iteration: ', /align_left)
stat2line = widget_label(col, value='Chi-square: ', /align_left)
stat3line = widget_label(col, value=' DOF: ', /align_left)
statline = [stat1line, stat2line, stat3line]

;; Render the status widget
widget_control, tlb, /realize

;; Perform the fit - put your own fitting routine here
p1 = mpfitfun('clockfit_model', t1, dt1, dt2, p0, parinfo=pi, yfit=mdl1, $
functargs={partitions: part, clockset: fs, parttype: ptype}, $
iterproc='clockfit_iterproc', status=status, $
iterargs={stopbut:stopbut, statline: statline})

;; Safely destroy the widget
if widget_info(tlb, /valid_id) then begin
widget_control, tlb, /destroy
endif


And listed below is the CLOCKFIT_ITERPROC routine which updates the
display and traps any clicks on the STOP button.

Craig



pro clockfit_iterproc, fcn, p, iter, fnorm, dof=dof, $
stopbut=stopbut, statline=statline, _EXTRA=extra

;; Be sure there are widgets available to interact with
if n_elements(stopbut) EQ 0 OR n_elements(statline) EQ 0 then return
if widget_info(stopbut, /valid_id) EQ 0 OR $
widget_info(statline(0), /valid_id) EQ 0 then return

;; Adjust the text values
widget_control, statline(0), $
set_value=string(iter, format='(" Iteration: ",I0)')
if fnorm GT 1d6 then fmt = 'E10.4' else fmt = 'D8.1'
widget_control, statline(1), $
set_value=string(fnorm, format='("Chi-square: ",'+fmt+')')
widget_control, statline(2), $
set_value=string(dof, format='(" DOF: ",I0)')

;; Check the widget stop button. If not pressed, then return
event = widget_event(/nowait, stopbut)
evname = tag_names(event, /structure_name)
if evname EQ '' OR event.id EQ 0 then return

;; If the widget stop button was pressed, then cancel the fit and
;; return
if evname EQ 'WIDGET_BUTTON' AND event.select then begin
widget_control, statline(0), set_value=''
widget_control, statline(1), set_value=' Fitting Cancelled'
widget_control, statline(2), set_value=''

event1 = widget_event(/nowait, stopbut)
wait, 2 ;; Pause for dramatic effect

widget_control, event.top, /destroy
common mpfit_error, mperr
mperr = -1
endif

return
end



--
------------------------------------------------------------ --------------
Craig B. Markwardt, Ph.D. EMAIL: craigmnet@cow.physics.wisc.edu
Astrophysics, IDL, Finance, Derivatives | Remove "net" for better response
------------------------------------------------------------ --------------
Re: how to interrupt in IDL for windows ? [message #34845 is a reply to message #34836] Wed, 23 April 2003 08:56 Go to previous message
David Fanning is currently offline  David Fanning
Messages: 11724
Registered: August 2001
Senior Member
Kristian Kjaer (Kristian.Kjaer@Risoe.DK) writes:

> Failing that, does anyone have a widget stop button that could be
> queried inside loops and appropriately reacted on?

My progress bar can be easily modified to do that:

http://www.dfanning.com/programs/progressbar__define.pro

Cheers,

David
--
David W. Fanning, Ph.D.
Fanning Software Consulting, Inc.
Phone: 970-221-0438, E-mail: david@dfanning.com
Coyote's Guide to IDL Programming: http://www.dfanning.com/
Toll-Free IDL Book Orders: 1-888-461-0155
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: Genetic algorithms and curve fitting
Next Topic: Re: Convert IDL code to HTML with color chromacoding for webpage / printing

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ] [ PDF ]

Current Time: Sun Oct 12 11:12:21 PDT 2025

Total time taken to generate the page: 2.00072 seconds