;+ ; NAME: ; fMaxLoc ; PURPOSE: (one line) ; Returns the location of the maximum in a 1-D array ; DESCRIPTION: ; This function returns finds the maximum point in a 1-D array, then fits ; a parabola to the maximum and its left and right neighbors. The center of ; the parabola is assumed to be the fractional location of the maximum. ; NOTICE that this function is useless if the FWHM is small compared to a pixel. ; CATEGORY: ; Spectral extraction ; CALLING SEQUENCE: ; fMax = fMaxLoc(v) ; INPUTS: ; myVec - Input 1-D array. ; OPTIONAL INPUT PARAMETERS: ; KEYWORD PARAMETERS: ; OUTPUTS: ; fMax - the location of the maximum ; COMMON BLOCKS: ; SIDE EFFECTS: ; RESTRICTIONS: ; PROCEDURE: ; MODIFICATION HISTORY: ; Written June 6, 1996, Eliot Young, NASA Ames Research Center ; Modified June 22, 1999, Jason Cook & Leslie Young, BU. ; Found y1=0, y3=0, and arrWidth bugs. ; Modified Dec 21, 1999, Leslie Young, SwRI. ; Found bracketing bug ;- function fMaxLoc,v sz = size(v) arrLen = sz(1) arrWidth = sz(2) xVals = findgen(3) yVals = fltarr(3) xVals = xVals - 1.0 ;Should be [-1., 0., 1.] maxVal = max(v, imax) ; for i = 0,2 do begin &$ ; yVals(i) = v((arrLen + imax + xVals(i)) MOD arrLen) &$ ; endfor ; if imax-1 lt 0 then y1=0 if imax-1 lt 0 then begin &$ Beforeimax=((arrLen + imax - 1) MOD arrLen) &$ y1=v(Beforeimax) &$ endif if imax-1 ge 0 then begin &$ y1=v(imax-1) &$ endif y2=v(imax) ; if imax+1 gt arrWidth-1 then y3=0 if imax+1 gt arrLen-1 then begin &$ Afterimax=((arrLen + imax + 1) MOD arrLen) &$ y3=v(Afterimax) &$ endif ; if imax+1 le arrWidth-1 then begin &$ if imax+1 le arrLen-1 then begin &$ y3=v(imax+1) &$ endif ; x=-[(y3-y1)/2]/(y1+y3-2*y2) x=-((y3-y1)/2.)/(y1+y3-2.*y2) ; LAY 1999 ; coefs = poly_fit(xVals, yVals, 2, n) ; fMax = -0.5 * coefs(1)/coefs(2) + imax fmax=x+imax ; print, "fmaxloc happened", y1, y2, y3 return,fMax end