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
------------------------------------------------------------ --------------
|