;+ ; NAME: find_fwXm ; ; PURPOSE: ; Find the full width at X*max. ; i.e. X = 0.5 for FWHM. ; ; INPUTS: ; KEYWORDS: ; /plot Make a convenient plot showing the curve and ; the points which are found ; OUTPUTS: ; ; HISTORY: ; Began 2005-05-04 14:24:42 by Marshall Perrin ; 2008-02-15 Added /plot option ;- function find_fwxm,array0,fraction, plot=plot, _extra=_extra, \$ locations=locations fa = finite(array0) if (total(~fa)) eq 0 then array=array0 else begin ; ignore NANs wfinite = where(fa, fct) if fct eq 0 then return, !values.f_nan ; nothing finite array=array0[where(fa)] skippednans=1 endelse sz = size(array) ; ignore maxes near the very edge max = max(array[5:sz[1]-5]) wmax = (where(array eq max))[0] if wmax eq 0 then bottom=0 else \$ bottom = find_closest(array[0:wmax-1],fraction*max) top = find_closest(array[wmax:*],fraction*max)+wmax ; Check whether there are further out points which are higher. if top lt sz[1]-4 then if total(array[top+1:*] gt fraction*max) gt 0 then begin print, "here" whigh = where(array[top+1:*] gt fraction*max) newstart = max(whigh)-3+(top+1) top = find_closest(array[newstart:*],fraction*max)+newstart endif locations = [bottom,top] if keyword_set(skippednans) then begin locations = (where(fa))[locations] endif if keyword_set(plot) then begin plot, array0, _extra=_extra ver, wmax, /lines ver, bottom, color=fsc_color('red') ver, top, color=fsc_color('red') hor, fraction*max, color=fsc_color('red') endif return,top-bottom+1 end