;+ ;FUNCTION: nb_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) -900),*]=0. data[((mind+nne)<(n_e-1)):(n_e-1),*]=0. endif endif ; the following limits the energy range to a few bins around the peak for cruise phase solar wind measurements if dat.nmass eq 1 then begin if dat.time lt time_double('14-10-1') then begin maxcnt = max(data,mind) data[0:(mind-nne>0)]=0. data[((mind+nne)<(n_e-1)):(n_e-1)]=0. endif endif if dat.nmass gt 1 then begin if keyword_set(mi) then begin dat.mass_arr[*]=mi & mass=dat.mass*dat.mass_arr endif else begin dat.mass_arr[*]=round(dat.mass_arr-.1)>1. & mass=dat.mass*dat.mass_arr ; the minus 0.1 helps account for straggling at low mass endelse endif else mass = dat.mass if keyword_set(mincnt) then if total(data) lt mincnt then return,0 dat.data=data dat = conv_units(dat,"df") ; Use distribution function data=dat.data Const = (mass)^(-1.5)*(2.)^(.5) 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 keyword_set(ms) then begin density = total(Const*denergy*(energy^(.5))*data*2.*cos(theta)*sin(dtheta/2.)*dphi) endif else begin density = total(Const*denergy*(energy^(.5))*data*2.*cos(theta)*sin(dtheta/2.)*dphi,1) endelse return, density end