;+ ;FUNCTION: vp_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. ; energy/charge analyzer, require positive energy if keyword_set(ms) then mass_amu = ms mass = dat.mass*mass_amu ; the following kluge is only for the electrostatic attenuator ; it assumes the beam is centered on an anode and accounts for energy-angle response variation across an anode ; for beams centered on an anode, the offset is ~3 deg, for beams centered between anodes the offset is -3 deg ; this could be improved by using apid ca to determine where the beam is centered if (dat.att_ind eq 1 or dat.att_ind eq 3) then offset=3. else offset=0. v = (2.*energy/mass)^.5 ; km/s note - mass=mass/charge, energy=energy/charge, charge cancels if dat2.apid eq 'ca' then begin phi = total(reform(dat.phi,16,4,16),2)/4. sth = sin(phi/!radeg) endif else sth = sin((dat.theta+offset)/!radeg) vp = v*sth ; km/s vperp = total(vp*((data-bkg)>0.))/total((data-bkg)>0.) return, vperp ; km/s end