;+ ; Fit a polynomial baseline from the contents of the primary data container [0] ; (continuum or line, depending on the GUIDE mode at the time) and ; optionally overplots that fit on top of the current plot. ; ;

This fits a set of orthogonal polynomials with a maximum order given by ; the !g.nfit value to the data values in the [0] data container. The range of ; channels to use is given by !g.regions and ; !g.nregion. The parameters of the fit are ; placed in to !g.polyfit and the polynomial is evaluated over all ; channels and that result is placed into the container at modelindex ; (see the comments for that keyword for more details), which is otherwise ; a copy of the header information in data container 0. ; ; @keyword nfit {in}{optional}{type=integer} The order of polynomial ; to fit. Defaults to !g.nfit. If set, then this also sets the value ; of !g.nfit. ; ; @keyword noshow {in}{optional}{type=boolean} If set, the result is ; not shown (overplotted). If the plotter is frozen, then nothing is ; overplotted even if this keyword is not set. ; ; @keyword modelindex {in}{optional}{type=integer} The index number to ; hold the fit evaluated at all channels (the model). If not set ; then no index will hold the model after this procedure is used. ; ; @keyword ok {in}{optional}{type=boolean} This is set to 1 on ; success and 0 on failure. ; ; @keyword color {in}{optional}{type=color} The color to use when ; overplotting the baseline fit. This defaults to the same default ; used by gbtoplot ; ; @examples ;

; ; fit, using the value of !g.nfit
; !g.nfit=3
; bshape
; ; Or specify an nfit here
; bshape,nfit=3
; ; You've done several bshapes and want to see just the most recent
; show
; bshape,/nofit
; 
; ; @uses dcbaseline ; @uses getbasemodel ; @uses data_valid ; @uses bmodel ; ; @version $Id: bshape.pro,v 1.7 2005/06/02 17:09:44 bgarwood Exp $ ;- pro bshape, nfit=nfit, noshow=noshow, modelindex=modelindex, ok=ok, color=color compile_opt idl2 ok = 0 npts = !g.line ? data_valid(!g.s[0]) : data_valid(!g.c[0]) if (npts lt 1) then begin message, 'no data in the primary data container', /info return endif if (n_elements(modelindex) eq 0) then modelindex=-1 maxindex = !g.line ? n_elements(!g.s) : n_elements(!g.c) if (modelindex gt maxindex) then begin message, 'requested model index does not exist', /info return endif if (n_elements(nfit) eq 0) then nfit = !g.nfit if ((nfit+1) gt n_elements(!g.polyfitrms)) then begin message, 'nfit is too large', /info return endif !g.nfit = nfit if (!g.line) then begin ok = dcbaseline(!g.s[0], nfit, !g.regions, !g.nregion, polyfit, polyrms) endif else begin ok = dcbaseline(!g.c[0], nfit, !g.regions, !g.nregion, polyfit, polyrms) endelse if (not ok) then begin message, 'there was a problem with the fit',/info return endif !g.polyfit[*,0:nfit] = polyfit !g.polyfitrms[0:nfit] = polyrms !g.nfit = nfit doshow = !g.frozen eq 0 and not keyword_set(noshow) if (modelindex ge 0) then begin bmodel,modelindex=modelindex,nfit=nfit if doshow then modelfit = getdata(modelindex) endif else begin if doshow then modelfit = getbasemodel(nfit=nfit) endelse if doshow then gbtoplot, modelfit, /chan, color=color ok = 1 end