;+ ;FUNCTION: j_4d(dat,ENERGY=en,ERANGE=er,EBINS=ebins,ANGLE=an,ARANGE=ar,BINS=bins,MASS=ms,m_int=mi,q=q,mincnt=mincnt) ;INPUT: ; dat: structure, 4d data structure filled by themis routines mvn_sta_c6.pro, mvn_sta_d0.pro, etc. ;KEYWORDS ; ENERGY: fltarr(2), optional, min,max energy range for integration ; ERANGE: fltarr(2), optional, min,max energy bin numbers for integration ; EBINS: bytarr(na), optional, energy bins array for integration ; 0,1=exclude,include, ; na = dat.nenergy ; ANGLE: fltarr(2,2), optional, angle range for integration ; theta min,max (0,0),(1,0) -901. & mass=dat.mass*dat.mass_arr ; the minus 0.1 helps account for straggling at low mass endelse ;if keyword_set(mincnt) then if total(data) lt mincnt then return,flux if keyword_set(mincnt) then if total(data-bkg) lt mincnt then return, flux if total(data-bkg) lt 1 then return, flux dat.cnts=data dat.bkg=bkg dat = conv_units(dat,"df") ; Use distribution function data=dat.data Const = 2./mass/mass*1e5 charge=dat.charge if keyword_set(q) then charge=q energy=(dat.energy+charge*dat.sc_pot/abs(charge))>0. ; energy/charge analyzer, require positive energy if dat.nbins eq 1 then begin ; assume you want the omni-directional flux and put it in the x-direction if keyword_set(ms) then return,total(Const*denergy*(energy)*data) else return,total(Const*denergy*(energy)*data,1) endif else begin flux3dx = total(total(Const*denergy*(energy)*data*(dtheta/2.+cos(2*theta)*sin(dtheta)/2.)*(2.*sin(dphi/2.)*cos(phi)),1),1) flux3dy = total(total(Const*denergy*(energy)*data*(dtheta/2.+cos(2*theta)*sin(dtheta)/2.)*(2.*sin(dphi/2.)*sin(phi)),1),1) flux3dz = total(total(Const*denergy*(energy)*data*(2.*sin(theta)*cos(theta)*sin(dtheta/2.)*cos(dtheta/2.))*dphi,1),1) endelse if keyword_set(ms) then begin flux3dx = total(flux3dx) flux3dy = total(flux3dy) flux3dz = total(flux3dz) endif ; units are 1/cm^2-s return, transpose([[flux3dx],[flux3dy],[flux3dz]]) end