function myfwhm,xaxis,yaxis,whole_curve=whole_curve,invert=invert $ ,yzero=yzero,yhm=yhm,roi=roi,fwhm_roi=fwhm_roi,hp_pts=hp_pts $ ,psym=psym,line_pts=line_pts,nohighlight=nohighlight $ ,h_color=h_color,h_thick=h_thick,nolabel=nolabel,manual=manual $ ,units=units,charsize=charsize,l_header=l_header,l_color=l_color, $ label=label,l_pos=l_pos,l_format=l_format,noplot=noplot ;+ ; NAME: MYFWHM ; PURPOSE: ; Measure the full-width-half-max of a region of curve that ; has been previously plotted. ; CATEGORY: ; CALLING SEQUENCE: ; Result=myfwhm(xaxis,yaxis) ; INPUTS: ; xaxis = the x axis variable which has been plotted. ; yaxis = the y axis variable which has been plotted. ; OPTIONAL INPUT PARAMETERS: ; KEYWORD PARAMETERS: ; whole_curve = set to disable interactive selection of the ; region of interest (roi) and default the calculation ; to the whole curve. ; yzero = the zero point level. If not specified, the zero ; point level is determined from endpoints of the ; digitized region of interest of the curve. ; yhm = the value at which the full-width is computed. ; Allowable range is 0. to 1. If not specified, ; .5 is used. ; invert = set to get width of 'absorption line' rather ; than 'emission line'. ; nohighlight = set to inhibit highlighting the region of ; interest. ; h_color = the color index for highlighting the region of ; interest. Default is 7 (Yellow). ; h_thick = the thickness for highlighting the region ; of interest. ; nolabel = set to inhibit labelling fwhm. ; manual = set to disable automatic location selection ; for labels. ; l_header = string specifying the label header. Default=''. ; l_color = color index for the label. ; l_format = IDL format string for label (eg. '(f4.2)'). ; units = string specifying units along x axis. ; charsize = size of label text. ; psym = psym ; noplot = set to inhibit plotting the curve at all; valid ; when /whole_curve is set. ; ; OUTPUTS: Result = the full-with-half-max of the region of interest ; of the curve, in x-axis data units. ; OPTIONAL OUTPUT PARAMETERS: ; roi=the subscripts of the digitized region of interest. ; fwhm_roi = the subscripts of the region between the fwhm points ; and the max (min) of the function. ; hp_pts = data coordinates of the half-power points. ; line_pts = a 4-element array containing the coordinates of ; the line drawn on the plot: [x0,x1,y0,y1] ; label = the label for the plot. ; l_pos = a two element array containing the x,y coordinates ; of the label, in data coords. ; ; COMMON BLOCKS: ; none. ; SIDE EFFECTS: ; TEK_COLOR is used to load in the tektronix colors. ; The region of interest of the curve is highlighted. ; The fwhm is labelled. ; RESTRICTIONS: ; The data must be plotted prior to calling FWHM. ; PROCEDURE: ; The user is asked to digitize the endpoints of the ; region of interest with the mouse. The region is ; highlighted, and the fwhm is labelled. ; MODIFICATION HISTORY: ; D. L. Windt, AT&T Bell Laboratories, November 1989 ; D. P. Steele, U. of Calgary, November 1992 from fwhm.pro ;- on_error,0 if n_params() ne 2 then message,'usage: result=myfwhm(x,y)' ; get the region of interest... if keyword_set(h_color) eq 0 then h_color=7 if keyword_set(h_thick) eq 0 then h_thick=!p.thick if keyword_set(psym) eq 0 then psym=!p.psym IF NOT KEYWORD_SET(whole_curve) THEN BEGIN roi=get_roi(xaxis,yaxis,nohighlight=keyword_set(nohighlight), $ h_color=h_color,h_thick=h_thick,psym=psym) xroi=float(xaxis(roi)) yroi=float(yaxis(roi)) ENDIF ELSE BEGIN roi=LINDGEN(N_ELEMENTS(xaxis)) xroi=FLOAT(xaxis) yroi=FLOAT(yaxis) ENDELSE n_roi=n_elements(roi) ; get number of elements in roi. ; get zero point and 'half-max' point... if n_elements(yzero) eq 0 then yzero=.5*(yroi(0)+yroi(n_roi-1)) if n_elements(yhm) eq 1 then yhm=(yhm>0.)<1. else yhm=.5 if keyword_set(invert) then begin ; look at inverted fwhm. ymin=min(yroi) ; get min. ymax=yzero ; get max. fwhm_roi=where(yroi le ymax-yhm*(ymax-ymin)) endif else begin ; look at 'normal' fwhm. ymax=max(yroi) ; get max. ymin=yzero ; get min. fwhm_roi=where(yroi ge (yhm*(ymax-ymin)+ymin)) endelse n=fwhm_roi(n_elements(fwhm_roi)-1)-fwhm_roi(0)+1 fwhm_roi=findgen(n)+fwhm_roi(0) ; get fwhm in data coordinates. n_froi=n_elements(fwhm_roi) ; number of points in fwhm roi. ; fwhm=n_froi*(max(xaxis)-min(xaxis))/n_elements(xaxis) ; in data coords. ; Do linear interpolation to get more exact FWHM p1=(ymin+(ymax-ymin)*yhm-yroi(fwhm_roi(0)-1))* $ (xroi(fwhm_roi(0))-xroi(fwhm_roi(0)-1))/ $ (yroi(fwhm_roi(0))-yroi(fwhm_roi(0)-1))+xroi(fwhm_roi(0)-1) p2=(ymin+(ymax-ymin)*yhm-yroi(fwhm_roi(n_froi-1)))* $ (xroi(fwhm_roi(n_froi-1)+1)-xroi(fwhm_roi(n_froi-1)))/ $ (yroi(fwhm_roi(n_froi-1)+1)-yroi(fwhm_roi(n_froi-1)))+ $ xroi(fwhm_roi(n_froi-1)) myfwhm=p2-p1 hp_pts=[p1,p2] if keyword_set(nolabel) eq 0 then begin ; label the line... if keyword_set(l_color) eq 0 then l_color=!P.COLOR if keyword_set(l_header) eq 0 then l_header='' if keyword_set(units) eq 0 then units='' if keyword_set(charsize) eq 0 then charsize=1 > !p.charsize ; plot a line across the roi... x1=xroi(fwhm_roi(0)) & x2=xroi(fwhm_roi(n_froi-1)) if keyword_set(invert) then y1=ymax-yhm*(ymax-ymin) $ else y1=yhm*(ymax-ymin)+ymin line_pts=[x1,x2,y1,y1] IF NOT KEYWORD_SET(noplot) THEN plots,[x1,x2],[y1,y1],color=l_color ; make label... if keyword_set(l_format) eq 0 then $ label=l_header+strtrim(string(myfwhm),2)+' '+units $ else label=l_header+strtrim(string(myfwhm,format=l_format),2)+' '+units ; make label position and place the label... IF NOT KEYWORD_SET(noplot) THEN BEGIN if keyword_set(manual) then begin make_arrow,label,x=xpos,y=ypos,color=l_color,size=charsize l_pos=[xpos,ypos] endif else begin l_pos=[.1*(x2-x1)+x2,y1] xyouts,l_pos(0),l_pos(1),label,color=l_color,size=charsize endelse ENDIF endif fwhm_roi=roi(0)+fwhm_roi return,myfwhm end