function maxcurve, itimes, data, var, STARTCOL = startcol, $ STARTROW = startrow, NCOLS = ncols, NROWS = nrows, $ FITORDER = fitorder, FITRANGE = fitrange if n_params() lt 3 then begin print, 'function - maxcurve = maxcurve(itimes, data, var '+ $ '[, STARTCOL = startcol,' print, ' STARTROW = startrow, NCOLS = ncols,' print, ' NROWS = nrows, FITORDER = fitorder,' print, ' FITRANGE = fitrange])' return, -1 endif ; Define default values. size = size(data) if not keyword_set(startcol) then startcol = 0 if not keyword_set(startrow) then startrow = 0 if not keyword_set(ncols) then ncols = size[1] if not keyword_set(nrows) then nrows = size[2] if not keyword_set(fitorder) then fitorder = 3 if not keyword_set(fitrange) then fitrange = [min(data), max(data)] ; Plot curves and let user specify the bending point. maxcurve = fltarr(ncols, nrows) for i = startcol, ncols+startcol-1 do $ for j = startrow, nrows+startrow-1 do begin w = where((data[i, j, *] ge fitrange[0]) and $ (data[i, j, *] le fitrange[1])) coeff = poly_fit1d(reform(data[i,j,w]),reform(data[i,j,w]/itimes[w]), $ fitorder,yerr=sqrt(reform(var[i,j,w])/itimes[w]^2), $ yfit=datafit, /silent) ;plot, data[i, j, *], poly(data[i, j, *], coeff), /xs, /ys, $ ; yrange = [min(data[i, j, *]/itimes), max(data[i, j, *]/itimes)] plot,data[i,j,w],datafit,/xs,/ys oploterr,data[i,j,*],data[i,j,*]/itimes[*],sqrt(var[i,j,*]/itimes[*]^2),1 ;plots, [fitrange[0], fitrange[0]], [min(data[i, j, *]/itimes), $ ; max(data[i, j, *]/itimes)], /data ;plots, [fitrange[1], fitrange[1]], [min(data[i, j, *]/itimes), $ ; max(data[i, j, *]/itimes)], /data cursor, x, y, /up, /data maxcurve[i, j] = abs(2*coeff[2]+6*coeff[3]*x) endfor return, maxcurve end