function sum_gauss, x, coef, gaussarray=garr on_error,2 ;Return to sender if broken ;;; How many elements in x-array? npix = n_elements(x) ;;; How many coefficients and Gaussians? sz = size(coef, /dimen) npar = sz[0] ngau = sz[1] ;;; Fan out abscissa values xarr = rebin(x, npix, ngau) ;;; Fan out parameters amp = rebin(coef[0,*], npix, ngau) cen = rebin(coef[1,*], npix, ngau) sig = rebin(coef[2,*], npix, ngau) ;;; Some advanced mathematical techniques garr = amp*exp(-(xarr-cen)^2/(2.*sig^2)) ;;; To add an offset or not to add an offset, that is the question. if npar gt 3 then begin garr = rebin(coef[3,*], npix, ngau) + garr endif ;;; Moosh them together and return to sender return, total(garr, 2) end