;======================================================================= ; NAME : linefit (procedure) ; PURPOSE : ; make fitting of spectral line by 4-th polinomial ; and get line the center and intensity ; CATEGORY : ; idl/lib/nkr ; CALLING SEQUENCE : ; linefit, prof, x0, z0, xint=xint, width=width ; INPUTS : ; prof : line profile array ; OPTIONAL INPUT PARAMETERS : ; none ; KEYWORD PARAMETERS : ; xint : x-interval, [x1,x2], to look for absorption line ; width : apporoximate line width for fiitting ; polinomial fit is made for the interval width/2 ; continuum is obtained outside width. ; default=12 ; OUTPUTS : ; x0 : line center position ; z0 : line center intensity ; COMMON BLOCKS : none ; SIDE EFFECTS : none ; RESTRICTIONS : none ; PROCEDURE : ; ; MODIFICATION HISTORY : ; K.I. '92/11/07 ;---------------------------------------------------------------------- function nearestindex,array,value ; return i at which the value of array(i) is the nearest to the 'value' diff=abs(array-value) index=where(diff eq min(diff)) return,index(0) end ;----------------------------------------------------------------------- pro linefit, prof, x0, z0, xint=xint, width=width, ver=ver, kk=kk if n_elements(xint) eq 2 then begin x1=xint(0) x2=xint(1) prof1=prof(x1:x2) endif else begin x1=0 x2=n_elements(prof)-1 prof1=prof endelse if not keyword_set(width) then width=12 if not keyword_set(kk) then kk=4 ; order of polinomial z00=min(prof1,x00) if x00-width/4 lt 0 or x00+width/4 ge n_elements(prof1) then begin print,'cannot make line fitting!!' x0=-1 & z0=0 return endif z=prof1(x00-width/4:x00+width/4) ii=indgen(width/4+width/4+1) coeff=transpose(poly_fit(ii,z,kk)) aa=fltarr(kk) for i=0,kk-1 do aa(i)=coeff(i+1)*(i+1) zroots,aa,root reindex=where(imaginary(root) eq 0) ; index where roots are real reroot=float(root(reindex)) value=where(z eq min(z)) xc0=reroot(nearestindex(reroot,value(0))) ; xc0 is counted from left side of the fitting range x0=float(x00-width/4)+xc0+x1 ; x0 is counted from left side of the image z0=total(coeff*xc0^indgen(n_elements(coeff))) if keyword_set(ver) then begin fit=fltarr(width/4+width/4+1) for i=0,width/4+width/4 do $ fit(i)=total(coeff*(xc0-width/4+i)^indgen(n_elements(coeff))) plot,prof1 oplot,ii+x00-width/4,fit,psym=4 endif end