PRO spint, e, djde, je, avge, j,dbg=dbg ; include j as optional output n = N_ELEMENTS( djde) ; First create dE array dE=FLTARR(n) dE(0)=e(0) - e(1) dE(1:n-2)=0.5*(e(0:n-3)-e(2:n-1)) dE(n-1)=e(n-2) - e(n-1) ; Then creating moments is a snap dj=djde*dE ; number fluxes in E channels j=TOTAL(dj) ; integral number flux je=TOTAL(dj*e) ; integral energy flux avge = je/j ; mean energy je = je*1.6022e-12 ; conversion to erg/cm2 s (sr) from eV/cm2 s (sr) IF e(0) LT 500.0 THEN je = je*1000 ; e in keV, not eV IF KEYWORD_SET(dbg) THEN STOP RETURN END