pro thm_load_efi, probe = probe, datatype = datatype, trange = trange, $
level = level, verbose = verbose, downloadonly = downloadonly, $
no_download = no_download, type = type, coord = coord, varformat = varformat, $
cdf_data = cdf_data, get_support_data = get_support_data, $
varnames = varnames, valid_names = valid_names, files = files, $
relpathnames_all = relpathnames_all, $
suffix = suffix, progobj = progobj, test = test, $
no_time_clip = no_time_clip, $
use_eclipse_corrections = use_eclipse_corrections, $
onthefly_edc_offset = onthefly_edc_offset, $
_extra = _extra
if keyword_set(suffix) then begin
if n_elements(suffix) eq 1 then begin
suffix = strsplit(strlowcase(suffix), ' ', /extract)
endif else begin
suffix = strlowcase(suffix)
endelse
endif
if n_elements(use_eclipse_corrections) LT 1 then begin
use_eclipse_corrections = 0
end
thm_init
vb = size(verbose, /type) ne 0 ? verbose : !themis.verbose
if not keyword_set(suffix) then suffix=''
if arg_present(relpathnames_all) then begin
downloadonly=1
no_download=1
end
vl1datatypes = ['vaf', 'vap', 'vaw', 'vbf', 'vbp', 'vbw', $
'eff', 'efp', 'efw', 'eff_0', 'efp_0', 'efw_0', $
'eff_dot0', 'efp_dot0', 'efw_dot0', 'eff_e12_efs', 'eff_e34_efs' , $
'efp_e12_efs', 'efp_e34_efs', 'efw_e12_efs', 'efw_e34_efs', $
'eff_q_mag', 'eff_q_pha', 'efp_q_mag', 'efp_q_pha', $
'efw_q_mag', 'efw_q_pha']
vl1datafiles = strmid(vl1datatypes, 0, 3)
vl2datatypes = ['eff_dot0', 'efs_dot0', 'eff_q_mag', 'eff_q_pha', $
'efs_q_mag', 'efs_q_pha', 'eff_e12_efs', 'eff_e34_efs']
thm_load_proc_arg, sname=probe, datatype=datatype, proc_type=type, msg_out=msg_out, $
level=level, verbose=verbose, no_download=no_download, $
valid_names = valid_names, $
vsnames = 'a b c d e', $
type_sname = 'probe', $
vdatatypes = strjoin(vl1datatypes, ' '), $
file_vdatatypes = strjoin(vl1datafiles, ' '), $
vL2datatypes= strjoin(vl2datatypes, ' '), $
file_vL2datatypes= 'efi', $
vtypes='raw calibrated', deftype = 'calibrated', $
vlevels = 'l1 l2', $
deflevel = 'l1', $
osname=probes, odt=dts, olvl=lvls, $
oft=fts, ofdt=fdts, otyp = typ, $
load_params=!themis,$
my_themis=my_themis
nlvls = n_elements(lvls)
lvls = lvls[0]
ndts = n_elements(dts)
nfts = n_elements(fts)
nprobes = n_elements(probes)
if keyword_set(valid_names) then return
if nlvls*ndts*nfts*nprobes le 0 then return
if arg_present(cdf_data) && nlvls*ndts*nprobes gt 1 then begin
dprint, 'can only get cdf_data for a single datatype'
return
endif
if lvls[0] eq 'l1' then begin
if strmatch(typ, 'calibrated') then begin
if not keyword_set(get_support_data) then begin
get_support_data = 1
delete_support_data = 1
endif
endif
endif else begin
If(arg_present(cdf_data)) Then Begin
If(arg_present(relpathnames_all)) Then Begin
thm_load_efi_l2, probe = probe, datatype = datatype, trange = trange, $
level = level, verbose = verbose, downloadonly = downloadonly, $
no_download = no_download, coord = coord, varformat = varformat, $
varnames = varnames, valid_names = valid_names, files = files, $
relpathnames_all = relpathnames_all, cdf_data = cdf_data, $
suffix = suffix, progobj = progobj, test = test, $
no_time_clip = no_time_clip, msg_out=msg_l2, _extra = _extra
Endif Else Begin
thm_load_efi_l2, probe = probe, datatype = datatype, trange = trange, $
level = level, verbose = verbose, downloadonly = downloadonly, $
no_download = no_download, coord = coord, varformat = varformat, $
varnames = varnames, valid_names = valid_names, files = files, $
cdf_data = cdf_data, suffix = suffix, progobj = progobj, test = test, $
no_time_clip = no_time_clip, msg_out=msg_l2, _extra = _extra
Endelse
Endif Else Begin
If(arg_present(relpathnames_all)) Then Begin
thm_load_efi_l2, probe = probe, datatype = datatype, trange = trange, $
level = level, verbose = verbose, downloadonly = downloadonly, $
no_download = no_download, coord = coord, varformat = varformat, $
varnames = varnames, valid_names = valid_names, files = files, $
relpathnames_all = relpathnames_all, $
suffix = suffix, progobj = progobj, test = test, $
no_time_clip = no_time_clip, msg_out=msg_l2, _extra = _extra
Endif Else Begin
thm_load_efi_l2, probe = probe, datatype = datatype, trange = trange, $
level = level, verbose = verbose, downloadonly = downloadonly, $
no_download = no_download, coord = coord, varformat = varformat, $
varnames = varnames, valid_names = valid_names, files = files, $
suffix = suffix, progobj = progobj, test = test, $
no_time_clip = no_time_clip, msg_out=msg_l2, _extra = _extra
Endelse
Endelse
Return
endelse
if ~keyword_set(trange) then begin
trange=timerange()
endif
if keyword_set(trange) then begin
trangef = 1
tranged = minmax(time_double(trange))
tr = tranged + [-1800, 1800]
endif
for k = 0, nlvls-1 do $
for j = 0, nfts-1 do $
for i = 0, nprobes-1 do begin
probei = probes[i]
ftj = fts[j]
lvlk = lvls[k]
relpath = 'th'+probei+'/'+lvlk+'/'+ ftj+'/'
prefix = 'th'+probei+'_'+lvlk+'_'+ftj+'_'
dir = 'YYYY/'
ending = '_v01.cdf'
relpathnames = file_dailynames(relpath, prefix, ending, dir=dir, trange = trange,addmaster=addmaster)
if vb ge 7 then dprint, 'relpathnames : ', relpathnames
if arg_present(relpathnames_all) then begin
if i+j+k eq 0 then relpathnames_all = relpathnames else relpathnames_all = [relpathnames_all, relpathnames]
endif
files = file_retrieve(relpathnames, _extra=my_themis, progobj=progobj)
if keyword_set(downloadonly) then continue
if arg_present(cdf_data) then begin
cdf_data = cdf_load_vars(files,varnames=varnames, verbose=vb,/all)
return
endif
if ~keyword_set(varformat) then begin
if keyword_set(get_support_data) then $
varformat = 'th?_??? th?_???_hed th?_???_hed_ac' else varformat = 'th?_???'
endif
if keyword_set(vb) then dprint, transpose(['Loading...',files])
cdf2tplot, file=files, all=all, verbose=vb, varformat=varformat, tplotnames=tplotnames
if not keyword_set(suffix) then suffix = ''
if ~keyword_set(no_time_clip) && keyword_set(trange) && keyword_set(trangef) then begin
for l=0, n_elements(tplotnames)-1 do begin
if tplotnames[l] eq '' then continue
dprint, 'Clipping '+string(l)
time_clip, tplotnames[l], tr[0], tr[1], /replace, error=clip_err
if clip_err then begin
dprint, 'Unable to clip '+tplotnames[l]+' to requested time range. Data may be out of range.'
store_data, tplotnames[l], /del
if ~(~size(filtered_tplotnames, /type)) then filtered_tplotnames = [filtered_tplotnames, tplotnames[l]] else filtered_tplotnames = tplotnames[l]
endif
endfor
if keyword_set(filtered_tplotnames) then tplotnames = filtered_tplotnames
endif
for l=0, n_elements(tplotnames)-1 do begin
tplot_var = tplotnames[l]
get_data, tplot_var, data=d_str, limit=l_str, dlimit=dl_str
if size(/type,dl_str) eq 8 && dl_str.cdf.vatt.var_type eq 'data' then begin
if n_elements( suffix ) eq 1 then begin
tplot_var_raw = tplot_var+suffix[0]
in_suffix = suffix[0]
endif else tplot_var_raw = tplot_var
data_att = { data_type:'raw', coord_sys:'efi_sensor',units:'ADC'}
str_element, dl_str, 'data_att', data_att, /add
if strmatch( strlowcase( tplot_var), 'th'+probei+'_v??') then begin
colors = [ 1, 2, 3, 4, 5, 6]
labels = [ 'V1', 'V2', 'V3', 'V4', 'V5', 'V6']
endif
if strmatch( strlowcase( tplot_var), 'th'+probei+'_e??') then begin
colors = [ 2, 4, 6]
labels = [ 'e12', 'e34', 'e56']
endif
str_element, dl_str, 'colors', colors, /add
str_element, dl_str, 'labels', labels, /add
str_element, dl_str, 'labflag', 1, /add
str_element, dl_str, 'ytitle', string( tplot_var_raw, 'ADC', format='(A,"!C!C[",A,"]")'), /add
store_data, delete=tplot_var
store_data, 'veryunusualprefixtempfoo_'+tplot_var_raw, data=d_str, limit=l_str, dlimit=dl_str
etype=strmid(tplot_var,4)
endif
endfor
endfor
if keyword_set(downloadonly) then return
if keyword_set(typ) && typ eq 'calibrated' && ~arg_present(relpathnames_all) then begin
thm_cal_efi, probe=probes, datatype=dts, coord=coord, in_suffix = in_suffix, $
out_suffix = suffix, test=test, stored_tnames = stored_tnames,$
use_eclipse_corrections=use_eclipse_corrections, $
onthefly_edc_offset = onthefly_edc_offset, _extra = _extra
endif
if ~(~size(stored_tnames, /type)) then stored_tnames = stored_tnames[uniq(stored_tnames, sort(stored_tnames))] else stored_tnames = ''
tempnames= tnames('veryunusualprefixtempfoo_*')
w=where(strlen(dts) eq 3)
if w[0] ne -1 then primary_dts= dts[w] else primary_dts = ''
if tempnames[0] ne '' && primary_dts[0] ne '' then begin
for i= 0, n_elements(tempnames)-1 do begin
requested = 0b
for j = 0, n_elements( suffix )-1 do begin
if (where(strmid(tempnames[i], 2+strlen( suffix[j] ), 3, /reverse_offset) eq primary_dts))[0] ne -1 then requested = 1
endfor
if requested then begin
case 1 of
(where( strmid(tempnames[i], 25) eq stored_tnames ))[0] eq -1: begin
if tnames(strmid(tempnames[i], 25)) ne '' then store_data, strmid(tempnames[i], 25), /del
store_data, tempnames[i], newname= strmid(tempnames[i], 25)
end
else: store_data, tempnames[i], /delete
endcase
endif
endfor
endif
tempnames= tnames('veryunusualprefixtempfoo_*')
if tempnames[0] ne '' then store_data, tempnames, /delete
if not keyword_set(no_time_clip) and n_elements(stored_tnames) ge 1 and keyword_set(trange) then begin
for i=0, n_elements(stored_tnames)-1 do begin
if stored_tnames[i] eq '' then continue
time_clip, stored_tnames[i], tranged[0], tranged[1], /replace, error=clip_err
if clip_err then begin
dprint, 'THM_LOAD_EFI: Unable to clip '+stored_tnames[i]+' to requested time range. Data may be out of range.'
store_data, stored_tnames[i], /del
endif
endfor
endif
if vb ge 8 && arg_present(relpathnames_all) then dprint, 'relpathnames_all: ', relpathnames_all
if keyword_set(delete_support_data) then begin
if not size(dts, /n_dim) gt 0 then dt = strsplit(dt, ' ', /extract)
for i = 0, n_elements(dt)-1L do begin
if tnames('th'+probe+'_'+dts[i]+'_hed') ne '' then del_data, 'th'+probe+'_'+dts[i]+'_hed'
endfor
endif
if keyword_set(msg_l2) then begin
msg_out = keyword_set(msg_out) ? [msg_out,msg_l2]:msg_l2
endif
if keyword_set(msg_out) then begin
for i=0, n_elements(msg_out)-1 do begin
if msg_out[i] ne '' then dprint, dlevel=1, msg_out[i]
endfor
endif
end