pro thm_clip_moment, tplotnames=tplotnames, trange=trange
compile_opt idl2, hidden
if undefined(tplotnames) then return
tr = timerange(trange)
for i=0, n_elements(tplotnames)-1 do begin
time_clip, tplotnames[i], min(tr), max(tr), /replace, error=tr_err
if tr_err then del_data, tplotnames[i]
endfor
end
pro thm_transform_moment, coord, quantity, trange=trange, probe=probe, $
prefix=prefix, suffix=suffix, $
state_loaded=state_loaded
compile_opt idl2, hidden
q = quantity[0] eq '*' ? ['flux','eflux','velocity']:quantity
types = where( stregex(q, '(flux|eflux|velocity)',/bool) eq 1, ct)
if ct gt 0 then begin
tplotnames = tnames()
searchstring = '('+strjoin( prefix+q[types]+suffix,'|')+')'
valid = where( stregex(tplotnames, searchstring,/bool) eq 1, ct)
if ~keyword_set(state_loaded) then begin
thm_load_state, probe=probe, /get_support_data, trange=trange
endif
cotrans_names = tplotnames[valid]
thm_cotrans, cotrans_names, out_coord = coord, $
use_spinaxis_correction=1, use_spinphase_correction=1
endif
end
pro thm_store_moment,time,dens,flux,mflux,eflux,mag,prefix = prefix, suffix=sfx,mass=mass, $
raw=raw, quantity=quantity, tplotnames=tplotnames, $
probe=probe,use_eclipse_corrections=use_eclipse_corrections
compile_opt idl2, hidden
if use_eclipse_corrections GT 0 then begin
thm_autoload_spinmodel,probe=probe,trange=minmax(time)
smp=spinmodel_get_ptr(probe,use_eclipse_corrections=use_eclipse_corrections)
spinmodel_interp_t,model=smp,time=time,eclipse_delta_phi=delta_phi
edp_idx=where(delta_phi NE 0.0, edp_count)
if (edp_count NE 0) then begin
dprint,"Nonzero eclipse delta_phi corrections found."
correct_delta_phi_vector,delta_phi=delta_phi,xyz_in=flux
correct_delta_phi_vector,delta_phi=delta_phi,xyz_in=eflux
correct_delta_phi_tensor,tens=mflux,delta_phi=delta_phi
endif
endif
for j=0,n_elements(quantity)-1 do begin
case quantity[j] of
'density': begin
store_data,prefix+'density'+sfx, data={x:time, y:dens}, dlim={ysubtitle:'[#/cm3]',data_att:{units:'#/cm3'}}
tplotnames = array_concat(prefix+'density'+sfx,tplotnames)
end
'flux': begin
store_data,prefix+'flux'+sfx, data={x:time, y:flux}, dlim={colors:'bgr',ysubtitle:'[#/cm2/s]',data_att:{units:'#/cm2/s',coord_sys:'dsl'}}
tplotnames = array_concat(prefix+'flux'+sfx,tplotnames)
end
'mftens': begin
store_data,prefix+'mftens'+sfx, data={x:time, y:mflux},dlim={colors:'bgrmcy',ysubtitle:'[eV/cm3]',data_att:{units:'eV/cm3',coord_sys:'dsl'}}
tplotnames = array_concat(prefix+'mftens'+sfx,tplotnames)
end
'eflux': begin
store_data,prefix+'eflux'+sfx, data={x:time, y:eflux} ,dlim={colors:'bgr',ysubtitle:'[eV/cm2/s]',data_att:{units:'eV/cm2/s',coord_sys:'dsl'}}
tplotnames = array_concat(prefix+'eflux'+sfx,tplotnames)
end
'*': begin
store_data,prefix+'density'+sfx, data={x:time, y:dens}, dlim={ysubtitle:'[#/cm3]',data_att:{units:'#/cm3'}}
store_data,prefix+'flux'+sfx, data={x:time, y:flux} ,dlim={colors:'bgr',ysubtitle:'[#/s/cm2]',data_att:{units:'#/s/cm2',coord_sys:'dsl'}}
store_data,prefix+'mftens'+sfx, data={x:time, y:mflux},dlim={colors:'bgrmcy',ysubtitle:'[eV/cm3]',data_att:{units:'eV/cm3',coord_sys:'dsl'}}
store_data,prefix+'eflux'+sfx, data={x:time, y:eflux} ,dlim={colors:'bgr',ysubtitle:'[eV/cm2/s]',data_att:{units:'eV/cm2/s',coord_sys:'dsl'}}
tplotnames = array_concat(prefix+['density','flux','mftens','eflux']+sfx,tplotnames)
end
else:
endcase
if not keyword_set(raw) then begin
vel = flux/[dens,dens,dens]/1e5
if quantity[j] eq 'velocity' || quantity[j] eq '*' then begin
store_data,prefix+'velocity'+sfx, data={x:time, y:vel }, $
dlim={colors:'bgrmcy',labels:['Vx','Vy','Vz'],ysubtitle:'[km/s]',data_att:{coord_sys:'dsl'}}
tplotnames = array_concat(prefix+'velocity'+sfx,tplotnames)
endif
pressure = mflux
pressure[*,0] -= mass * flux[*,0]*flux[*,0]/dens/1e10
pressure[*,1] -= mass * flux[*,1]*flux[*,1]/dens/1e10
pressure[*,2] -= mass * flux[*,2]*flux[*,2]/dens/1e5/1e5
pressure[*,3] -= mass * flux[*,0]*flux[*,1]/dens/1e5/1e5
pressure[*,4] -= mass * flux[*,0]*flux[*,2]/dens/1e5/1e5
pressure[*,5] -= mass * flux[*,1]*flux[*,2]/dens/1e5/1e5
if quantity[j] eq 'ptens' || quantity[j] eq '*' then begin
press_labels=['Pxx','Pyy','Pzz','Pxy','Pxz','Pyz']
store_data,prefix+'ptens'+sfx, data={x:time, y:pressure }, $
dlim={colors:'bgrmcy',labels:press_labels,constant:0.,ysubtitle:'[eV/cc]'}
tplotnames = array_concat(prefix+'ptens'+sfx,tplotnames)
endif
ptot = total(pressure[*,0:2],2)/3
if quantity[j] eq 'ptot' || quantity[j] eq '*' then begin
store_data,prefix+'ptot'+sfx, data={x:time, y:ptot }
tplotnames = array_concat(prefix+'ptot'+sfx,tplotnames)
endif
endif
if keyword_set(mag) then begin
map3x3 = [[0,3,4],[3,1,5],[4,5,2]]
mapt = [0,4,8,1,2,5]
n = n_elements(time)
ptens_mag = fltarr(n,6)
vel_mag = fltarr(n,3)
vxz = [1,0,0.]
for i=0L,n-1 do begin
rot = rot_mat(reform(mag[i,*]),vxz)
pt = reform(pressure[i,map3x3],3,3)
magpt3x3 = invert(rot) # (pt # rot)
ptens_mag[i,*] = magpt3x3[mapt]
vm = reform(vel[i,*]) # rot
vel_mag[i,*] = vm
endfor
store_data,prefix+'velocity_mag',data={x:time,y:vel_mag} ,dlim={colors:'bgr',labels:['Vperp1','Vperp2','Vpar'],ysubtitle:'[km/s]',data_att:{units:'km/s',coord_sys:'mfa'}}
store_data,prefix+'ptens_mag',data={x:time,y:ptens_mag},dlim={colors:'bgrmcy',labels:['Pperp1','Pperp2','Ppar','','',''],ysubtitle:'[eV/cc]',data_att:{units:'eV/cm3'}}
store_data,prefix+'t3_mag',data={x:time,y:ptens_mag[*,0:2]/[dens,dens,dens]},dlim={colors:'bgrmcy',labels:['Tperp1','Tperp2','Tpar'],ysubtitle:'[eV]',data_att:{units:'eV'}}
store_data,prefix+'mag',data={x:time,y:mag},dlim={colors:'bgr',ysubtitle:'[nT]'}
tplotnames = array_concat(prefix+['velocity_mag','ptens_mag','t3_mag','mag'],tplotnames)
endif
endfor
end
pro thm_load_mom_cal_array,time,momraw,scpotraw,qf,shft,$
iesa_sweep, iesa_sweep_time, eesa_sweep, eesa_sweep_time, $
iesa_solarwind_flag, eesa_solarwind_flag, $
iesa_config, iesa_config_time,eesa_config, eesa_config_time, $
isst_config, isst_config_time,esst_config, esst_config_time, $
iesa_solarwind_time, eesa_solarwind_time, $
probe=probe,caldata=caldata, coord=coord, $
verbose=verbose,raw=raw,comptest=comptest, datatype=datatype, $
use_eclipse_corrections=use_eclipse_corrections, suffix = suffix, $
tplotnames=tplotnames
compile_opt idl2, hidden
caldata = thm_read_mom_cal_file(cal_file = cal_file,probe=probe)
dprint,dlevel=2,verbose=!themis.verbose,'THEMIS moment calibration file: ',cal_file
dprint,dlevel=4,verbose=!themis.verbose,caldata,phelp=3
dprint,dlevel=3,phelp=3,qf
dprint,dlevel=3,phelp=3,shft
if keyword_set(raw) then begin
sfx='_raw'
caldata.mom_scale = 1.
caldata.scpot_scale[*] = 1.
endif else if(keyword_set(suffix)) then begin
sfx = suffix
endif else sfx = ''
if keyword_set(comptest) then begin
sfx+='_cmptest'
momraw = momraw and 'ffff0000'xl
momraw = momraw or '00008000'xl
endif
one = replicate(1.d,n_elements(time))
bad = where((qf and 'c'x) ne 0,nbad)
if nbad gt 0 then one[bad] = !values.f_nan
nt = n_elements(time)
thx = 'th'+probe
instrs= 'p'+['ei','ee','si','se'] +'m'
me = 510998.918d/299792d^2
mi = 1836*me
mass=[mi,me,mi,me]
s2_cluge = [3,0,3,0]
totmom_flag = 1 && ~keyword_set(raw)
if keyword_set(totmom_flag) then begin
n_e_tot = 0
nv_e_tot = 0
nvv_e_tot = 0
nvvv_e_tot = 0
n_i_tot = 0
nv_i_tot = 0
nvv_i_tot = 0
nvvv_i_tot = 0
endif
mag = data_cut(thx+'_fgs',time)
if(n_elements(mag) eq 1 && mag[0] eq 0) then mag = data_cut(thx+'_fgs_dsl',time)
cal_params = dblarr([dimen(caldata.mom_scale),2])
cal_params[*,*,0] = caldata.mom_scale
cal_params[*,*,1] = caldata.mom_scale_sw1
for i=0,3 do begin
s2 = ishft(shft,(i-3)*4) and 7
instr = instrs[i]
ion = (i and 1) eq 0
if (i eq 2) || (i eq 3) then begin
geom = replicate(!values.f_nan,n_elements(time))
geom[*] = 1.
w_open = where( (qf and '0f00'x) eq '0A00'x , nw_open )
if nw_open gt 0 then geom[w_open] = 1.
w_clsd = where( (qf and '0f00'x) eq '0500'x , nw_clsd )
if nw_clsd gt 0 then geom[w_clsd] = 1./64
if (nw_open + nw_clsd) ne n_elements(geom) then begin
dprint,'Attenuator flags are ambiguous for ' + strtrim(n_elements(geom) - nw_open - nw_clsd,2) + ' samples.'
endif
endif else begin
esa_cal = get_thm_esa_cal(time= time,sc=probe,ion=ion)
geom= esa_cal.rel_gf * esa_cal.geom_factor / 0.00153000 * 1.5
endelse
if keyword_set(raw) then s2=0
dprint,dlevel=3,instrs[i],' shift=',s2[0]
if i eq 0 && ptr_valid(iesa_solarwind_flag) && ptr_valid(iesa_solarwind_time) then begin
sw_flags = 0 > round(interpol(*iesa_solarwind_flag,*iesa_solarwind_time,time)) < 1
endif else if i eq 1 && ptr_valid(eesa_solarwind_flag) && ptr_valid(eesa_solarwind_time) then begin
sw_flags = 0 > round(interpol(*eesa_solarwind_flag,*eesa_solarwind_time,time)) < 1
endif else begin
sw_flags = dblarr((dimen(momraw))[0])
endelse
dens = ulong(momraw[*,0,i]) * cal_params[0,i,sw_flags] * one * 2.^s2 / geom
flux = fltarr(nt,3)
for m = 0,2 do flux[*,m] = momraw[*,1+m,i] * cal_params[1+m,i,sw_flags] * one * 2.^s2 / geom
mflux = fltarr(nt,6)
for m = 0,5 do mflux[*,m] = momraw[*,4+m,i] * cal_params[4+m,i,sw_flags] * one * 2.^s2 /geom
eflux = fltarr(nt,3)
for m = 0,2 do eflux[*,m] = momraw[*,10+m,i] * cal_params[10+m,i,sw_flags] * one * 2.^s2 /geom * 1e5
if not keyword_set(raw) then begin
if keyword_set(totmom_flag) then begin
if i and 1 eq 1 then begin
n_e_tot += dens
nv_e_tot += flux
nvv_e_tot += mflux
nvvv_e_tot += eflux
endif else begin
n_i_tot += dens
nv_i_tot += flux
nvv_i_tot += mflux
nvvv_i_tot += eflux
endelse
endif
endif
if keyword_set(datatype) then begin
dt_ind = where(strmid(datatype,0,4) eq instr, n)
if (n_elements(n) gt 0) &&((n eq 0)) then continue
endif
if(n_elements(n) gt 0) then begin
quantity = strarr(n)
for j=0,n-1 do begin
qu = (strsplit(datatype[dt_ind[j]], '_', /extract))
if(n_elements(qu) gt 1) then quantity[j] = qu[1] else quantity[j] = '*'
endfor
star = where(quantity eq '*', nstar)
if(nstar gt 0) then quantity = '*'
endif else quantity = '*'
thm_store_moment,time,dens,flux,mflux,eflux,mag,prefix = thx+'_'+instr+'_', $
suffix=sfx,mass=mass[i],raw=raw, quantity=quantity, tplotnames=tplotnames, $
probe=probe, use_eclipse_corrections=use_eclipse_corrections
if keyword_set(coord) then begin
thm_transform_moment, coord, quantity, probe=probe, trange=trange, $
prefix=thx+'_'+instr+'_',suffix=sfx, $
state_loaded=state_loaded
endif
endfor
if 1 then begin
if not keyword_set(raw) && totmom_flag then begin
thm_store_moment,time,n_i_tot,nv_i_tot,nvv_i_tot,nvvv_i_tot,mag,$
prefix = thx+'_'+'ptim_', suffix=sfx,mass=mass[0],raw=raw, quantity='*',$
probe=probe, use_eclipse_corrections=use_eclipse_corrections, $
tplotnames=tplotnames
thm_store_moment,time,n_e_tot,nv_e_tot,nvv_e_tot,nvvv_e_tot,mag,$
prefix = thx+'_'+'ptem_', suffix=sfx,mass=mass[1],raw=raw, quantity='*',$
probe=probe, use_eclipse_corrections=use_eclipse_corrections, $
tplotnames=tplotnames
endif
endif
scpot = scpotraw*caldata.scpot_scale
if keyword_set(datatype) then begin
if where(strmid(datatype,0,8) eq 'pxxm_pot') ne -1 then begin
store_data,thx+'_pxxm_pot'+sfx,data={x:time, y:scpot },dlimit={ysubtitle:'[Volts]'}
tplotnames = array_concat(thx+'_pxxm_pot'+sfx,tplotnames)
endif
if where(strmid(datatype,0,7) eq 'pxxm_qf') ne -1 then begin
store_data,thx+'_pxxm_qf'+sfx,data={x:time, y:qf}, dlimit={tplot_routine:'bitplot'}
tplotnames = array_concat(thx+'_pxxm_qf'+sfx,tplotnames)
endif
if where(strmid(datatype,0,9) eq 'pxxm_shft') ne -1 then begin
store_data,thx+'_pxxm_shft'+sfx,data={x:time, y:shft}, dlimit={tplot_routine:'bitplot'}
tplotnames = array_concat(thx+'_pxxm_shft'+sfx,tplotnames)
endif
endif else begin
store_data,thx+'_pxxm_pot'+sfx,data={x:time, y:scpot },dlimit={ysubtitle:'[Volts]'}
store_data,thx+'_pxxm_qf'+sfx,data={x:time, y:qf}, dlimit={tplot_routine:'bitplot'}
store_data,thx+'_pxxm_shft'+sfx,data={x:time, y:shft}, dlimit={tplot_routine:'bitplot'}
tplotnames = array_concat(thx+['_pxxm_pot','_pxxm_qf','_pxxm_shft']+sfx,tplotnames)
endelse
if(ptr_valid(iesa_sweep) && ptr_valid(iesa_sweep_time)) then begin
store_data, thx+'_iesa_sweep'+sfx, data = {x:*iesa_sweep_time, y:*iesa_sweep}, dlimit={tplot_routine:'bitplot'}
tplotnames = array_concat(thx+'_iesa_sweep'+sfx,tplotnames)
endif
if(ptr_valid(eesa_sweep) && ptr_valid(eesa_sweep_time)) then begin
store_data, thx+'_eesa_sweep'+sfx, data = {x:*eesa_sweep_time, y:*eesa_sweep}, dlimit={tplot_routine:'bitplot'}
tplotnames = array_concat(thx+'_eesa_sweep'+sfx,tplotnames)
endif
if(ptr_valid(iesa_solarwind_flag) && ptr_valid(iesa_solarwind_time)) then begin
store_data, thx+'_iesa_solarwind_flag'+sfx, data = {x:*iesa_solarwind_time, y:*iesa_solarwind_flag}
tplotnames = array_concat(thx+'_iesa_solarwind_flag'+sfx,tplotnames)
endif
if(ptr_valid(eesa_solarwind_flag) && ptr_valid(eesa_solarwind_time)) then begin
store_data, thx+'_eesa_solarwind_flag'+sfx, data = {x:*eesa_solarwind_time, y:*eesa_solarwind_flag}
tplotnames = array_concat(thx+'_eesa_solarwind_flag'+sfx,tplotnames)
endif
if(ptr_valid(iesa_config) && ptr_valid(iesa_config_time)) then begin
store_data, thx+'_iesa_config'+sfx, data = {x:*iesa_config_time, y:*iesa_config}
tplotnames = array_concat( thx+'_iesa_config'+sfx,tplotnames)
endif
if(ptr_valid(eesa_config) && ptr_valid(eesa_config_time)) then begin
store_data, thx+'_eesa_config'+sfx, data = {x:*eesa_config_time, y:*eesa_config}
tplotnames = array_concat(thx+'_eesa_config'+sfx,tplotnames)
endif
if(ptr_valid(isst_config) && ptr_valid(isst_config_time)) then begin
store_data, thx+'_isst_config'+sfx, data = {x:*isst_config_time, y:*isst_config}
tplotnames = array_concat(thx+'_isst_config'+sfx,tplotnames)
endif
if(ptr_valid(esst_config) && ptr_valid(esst_config_time)) then begin
store_data, thx+'_esst_config'+sfx, data = {x:*esst_config_time, y:*esst_config}
tplotnames = array_concat(thx+'_esst_config'+sfx,tplotnames)
endif
end
pro thm_load_mom, probe = probe, datatype = datatype, trange = trange, all = all, $
level = level, verbose = verbose, downloadonly = downloadonly, $
varnames = varnames, valid_names = valid_names, raw = raw, $
comptest = comptest, suffix = suffix, coord = coord, $
source_options = source, type = type, $
progobj = progobj, files = files, no_time_clip = no_time_clip, $
true_dsl = true_dsl, use_eclipse_corrections = use_eclipse_corrections, $
dead_time_correct = dead_time_correct
compile_opt idl2
thm_init
thm_load_esa_cal
vprobes = ['a','b','c','d','e']
vlevels = ['l1','l2']
deflevel = 'l1'
if n_elements(probe) eq 1 then if probe eq 'f' then vprobes=[vprobes,'f']
if not keyword_set(probe) then probe=vprobes
probes = thm_check_valid_name(strlowcase(probe), vprobes, /include_all)
lvl = thm_valid_input(level,'Level',vinputs=strjoin(vlevels, ' '), $
definput=deflevel, format="('l', I1)", verbose=0)
if lvl eq '' then return
if lvl eq 'l2' and keyword_set(type) then begin
dprint,dlevel=0,"Type keyword not valid for level 2 data."
return
endif
if keyword_set(type) && ~keyword_set(raw) then begin
if strcompress(/remove_all, strlowcase(type)) Eq 'raw' then raw = 1b else raw = 0b
endif
if arg_present(files) then begin
file_list_flag = 1
endif else begin
file_list_flag = 0
endelse
if (lvl eq 'l2') or (lvl eq 'l1' and keyword_set(valid_names)) then begin
thm_load_mom_l2, probe = probe, datatype = datatype, $
trange = trange, level = lvl, verbose = verbose, $
downloadonly = downloadonly, valid_names = valid_names, $
source_options = source_options, progobj = progobj, files = files, $
suffix = suffix, no_time_clip = no_time_clip
return
endif
if keyword_set(valid_names) then begin
probe = vprobes
dprint, string(strjoin(probe, ','), $
format = '( "Valid probes:",X,A,".")')
datatype = vdatatypes
dprint, string(strjoin(datatype, ','), $
format = '( "Valid '+lvl+' datatypes:",X,A,".")')
level = vlevels
dprint, string(strjoin(level, ','), format = '( "Valid levels:",X,A,".")')
return
endif
if keyword_set(datatype) then begin
datatype=strlowcase(datatype)
endif
if keyword_set(datatype) && n_elements(datatype) eq 1 then begin
dtest = strlowcase(strcompress(/remove_all, datatype))
if(dtest eq '*' or dtest eq 'all' or dtest eq 'mom') then datatype = 0
endif
if not keyword_set(source) then source = !themis
if not keyword_set(verbose) then verbose = source.verbose
if (n_elements(true_dsl) GT 0) then begin
dprint,dlevel=1,'true_dsl keyword no longer required.'
dprint,dlevel=1,'Setting use_eclipse_corrections=2 to use fully corrected eclipse spin model.'
use_eclipse_corrections=2
endif
if n_elements(use_eclipse_corrections) LT 1 then begin
use_eclipse_corrections=0
dprint,dlevel=2,'Defaulting to use_eclipse_corrections=0 (no eclipse spin model corrections).'
endif
if (use_eclipse_corrections EQ 1) then begin
dprint,dlevel=1,'Caution: partial eclipse corrections requested. use_eclipse_corrections=2 for full corrections (when available).'
endif
addmaster=0
for s=0,n_elements(probes)-1 do begin
thx = 'th'+ probes[s]
pathformat = thx+'/'+lvl+'/mom/YYYY/'+thx+'_'+lvl+'_mom_YYYYMMDD_v01.cdf'
dprint,dlevel=3,'pathformat: ',pathformat,verbose=verbose
relpathnames = file_dailynames(file_format=pathformat,trange=trange,addmaster=addmaster)
files = file_retrieve(relpathnames, _extra=source)
if file_list_flag then begin
if n_elements(file_list) eq 0 then begin
file_list = [files]
endif else begin
file_list = [file_list,files]
endelse
endif
if keyword_set(downloadonly) then continue
suf=''
suf='_raw'
if 1 then begin
cdfi = cdf_load_vars(files,varnames=varnames2,verbose=verbose,/all)
if not keyword_set(cdfi) then continue
vns = cdfi.vars.name
time = cdfi.vars[where(vns eq thx+'_mom_time')].dataptr
mom = cdfi.vars[where(vns eq thx+'_mom')].dataptr
qf = cdfi.vars[where(vns eq thx+'_mom_qf')].dataptr
pot = cdfi.vars[where(vns eq thx+'_mom_pot')].dataptr
hed = cdfi.vars[where(vns eq thx+'_mom_hed')].dataptr
hed_time = cdfi.vars[where(vns eq thx+'_mom_hed_time')].dataptr
iesa_sweep = cdfi.vars[where(vns eq thx+'_mom_iesa_sweep')].dataptr
iesa_sweep_time = cdfi.vars[where(vns eq thx+'_mom_iesa_sweep_time')].dataptr
eesa_sweep = cdfi.vars[where(vns eq thx+'_mom_eesa_sweep')].dataptr
eesa_sweep_time = cdfi.vars[where(vns eq thx+'_mom_eesa_sweep_time')].dataptr
iesa_solarwind_flag = cdfi.vars[where(vns eq thx+'_mom_iesa_solarwind_flag')].dataptr
eesa_solarwind_flag = cdfi.vars[where(vns eq thx+'_mom_eesa_solarwind_flag')].dataptr
iesa_solarwind_time = cdfi.vars[where(vns eq thx+'_mom_iesa_solarwind_flag_time')].dataptr
eesa_solarwind_time = cdfi.vars[where(vns eq thx+'_mom_eesa_solarwind_flag_time')].dataptr
iesa_config = cdfi.vars[where(vns eq thx+'_mom_iesa_config')].dataptr
iesa_config_time = cdfi.vars[where(vns eq thx+'_mom_iesa_config_time')].dataptr
eesa_config = cdfi.vars[where(vns eq thx+'_mom_eesa_config')].dataptr
eesa_config_time = cdfi.vars[where(vns eq thx+'_mom_eesa_config_time')].dataptr
isst_config = cdfi.vars[where(vns eq thx+'_mom_isst_config')].dataptr
isst_config_time = cdfi.vars[where(vns eq thx+'_mom_isst_config_time')].dataptr
esst_config = cdfi.vars[where(vns eq thx+'_mom_esst_config')].dataptr
esst_config_time = cdfi.vars[where(vns eq thx+'_mom_esst_config_time')].dataptr
If(ptr_valid(eesa_sweep_time) && ptr_valid(eesa_solarwind_time)) Then Begin
If(n_elements(*eesa_sweep_time) Ne n_elements(*eesa_solarwind_time)) Then Begin
tsw = *eesa_solarwind_time
x = where(tsw[1:*] Eq tsw[0:n_elements(tsw)-2])
If(x[0] Ne -1) Then Begin
fsw = *eesa_solarwind_flag
ntsw = n_elements(tsw)
keep_flag = bytarr(ntsw)+1b
keep_flag[x] = 0b
fsw[x+1] = 1
ok = where(keep_flag Eq 1)
If(ok[0] Ne -1) Then Begin
tsw = tsw[ok] & fsw = fsw[ok]
ptr_free, eesa_solarwind_time
eesa_solarwind_time = ptr_new(temporary(tsw))
ptr_free, eesa_solarwind_flag
eesa_solarwind_flag = ptr_new(temporary(fsw))
Endif Else dprint, 'No non-duplicate OK times for EESA SWflag'
Endif Else dprint, 'Sweep time and SWflag time mismatch, but no duplicate times'
Endif
Endif
if(ptr_valid(time) eq 0 or ptr_valid(mom) eq 0 $
or ptr_valid(qf) eq 0 or ptr_valid(pot) eq 0 $
or ptr_valid(hed) eq 0 or ptr_valid(hed_time) eq 0) then begin
dprint,dlevel=1,'Invalid data found in file(s): ' + files,verbose=verbose
dprint,dlevel=1,'Skipping probe.' ,verbose=verbose
continue
endif
shft_index = round(interp(findgen(n_elements(*hed_time)) ,*hed_time, *time))
shft = (*hed)[*,14 ]+ 256u* (*hed)[*,15]
shft = shft[shft_index]
thm_load_mom_cal_array,*time,*mom,*pot,*qf,shft,$
iesa_sweep,iesa_sweep_time,eesa_sweep,eesa_sweep_time, $
iesa_solarwind_flag, eesa_solarwind_flag, probe = probes[s], $
iesa_config, iesa_config_time, eesa_config, eesa_config_time,$
isst_config, isst_config_time, esst_config, esst_config_time,$
iesa_solarwind_time, eesa_solarwind_time, coord=coord, $
raw = raw, verbose = verbose, comptest = comptest, datatype = datatype, $
use_eclipse_corrections=use_eclipse_corrections, suffix = suffix, $
tplotnames=tplotnames
tplot_ptrs = ptr_extract(tnames(/dataquant))
unused_ptrs = ptr_extract(cdfi,except=tplot_ptrs)
ptr_free,unused_ptrs
endif else begin
message," Don't do this!"
endelse
If(keyword_set(dead_time_correct)) Then Begin
thm_apply_esa_mom_dtc, probe = probes[s], trange = trange, in_suffix = suffix
Endif
endfor
if file_list_flag && n_elements(file_list) ne 0 then begin
files=file_list
endif
if ~keyword_set(no_time_clip) then begin
thm_clip_moment, tplotnames=tplotnames, trange=trange
endif
end