	function wgtmax, yy, ipeak, width=width, threshold=thres, full=full

;+ 	Function returns coordinate (subscript) of weighted maximum
;	in the given 1-dimensional or 2-dimensional array.
;-

if n_params() lt 1 then message, 'Incorrect call'

Sz=size(yy)

if (Sz(0) lt 1) or (Sz(1) le 1) then message, 'Incorrect argument'

if n_elements(width) le 0 then auto=1 else auto=0
if n_elements(thres) le 0 then thres=0.2

N=Sz(1)
if Sz(0) eq 2 then Ny=Sz(2) else Ny=1

ipeak=(x=fltarr(Ny))
arg=findgen(N)


	for j=0, Ny-1 do begin

amax=max(yy(*,j),imax)

	if auto then begin
fw=fwhm(yy(*,j),i_peak=imax, full=keyword_set(full))
width=fix(2*fw)
	endif

k0=imax-width/2 > 0
k1=imax+width/2 < (N-1) > k0

ind=where(yy(k0:k1,j) ge thres*amax) > 0

kmin=ind(0)
kmax=ind(n_elements(ind)-1)

x(j)=total(arg*yy(k0:k1,j))/total(yy(k0:k1,j))+k0
ipeak(j)=imax

	endfor

if n_elements(x) eq 1 then x=x(0)

return, x

	end