@mvn_swia_load_l2_data
pro mvn_swia_make_l2_data, startdate = startdate, days = days,version = version, revision = revision, type = type, l0_file_path = l0_file_path, opath = opath, kload = kload, oldcal = oldcal
compile_opt idl2
common mvn_swia_data
timespan, startdate, days
if keyword_set(kload) then mk = mvn_spice_kernels(/all,/load,/reset)
if not keyword_set(version) then version = '00'
if not keyword_set(revision) then revision = '00'
if not keyword_set(type) then type = 'svy'
if type eq 'arc' then archive = 1 else archive = 0
if type eq 'arc' then ftype = 'all' else ftype = 'svy'
if not keyword_set(opath) then opath = '/disks/data/maven/data/sci/swi/l2/'
if not keyword_set(l0_file_path) then l0_file_path = '/disks/data/maven/data/sci/pfp/l0/'
date = startdate
ct0 = 0.d
ft0 = 0.d
cat0 = 0.d
fat0 = 0.d
mt0 = 0.d
st0 = 0.d
newc = 0
newf = 0
newca= 0
newfa= 0
news = 0
newm = 0
for i = 0,days-1 do begin
date0 = strmid(time_string(date, format=6), 0, 8)
yyyy = strmid(date0, 0, 4)
mmmm = strmid(date0, 4, 2)
dddd = strmid(date0, 6, 2)
ppp = mvn_file_source()
filex = mvn_l0_db2file(date,l0_file_type = ftype,l0_file_path=l0_file_path)
if filex ne '' then mvn_swia_load_l0_data,filex,/tplot,/sync,qlevel = 0.0001, oldcal= oldcal
if n_elements(swics) gt 1 then begin
if swics[0].time_unix ne ct0 then begin
ct0 = swics[0].time_unix
newc = 1
endif else newc = 0
endif
if n_elements(swifs) gt 1 then begin
if swifs[0].time_unix ne ft0 then begin
ft0 = swifs[0].time_unix
newf = 1
endif else newf = 0
endif
if n_elements(swica) gt 1 then begin
if swica[0].time_unix ne cat0 then begin
cat0 = swica[0].time_unix
newca = 1
endif else newca = 0
endif
if n_elements(swifa) gt 1 then begin
if swifa[0].time_unix ne fat0 then begin
fat0 = swifa[0].time_unix
newfa = 1
endif else newfa = 0
endif
if type eq 'arc' then begin
newc = newca
newf = newfa
endif
if n_elements(swim) gt 1 then begin
if swim[0].time_unix ne mt0 then begin
mt0 = swim[0].time_unix
newm = 1
endif else newm = 0
endif
if n_elements(swis) gt 1 then begin
if swis[0].time_unix ne st0 then begin
st0 = swis[0].time_unix
news = 1
endif else news = 0
endif
if newc then mvn_swia_make_swic_cdf,archive = archive,data_version='v'+version+'r'+revision,file = opath+yyyy+'/'+mmmm+'/mvn_swi_l2_coarse'+type+'3d_'+yyyy+mmmm+dddd+'_v'+version+'_r'+revision+'.cdf'
if newf then mvn_swia_make_swif_cdf,archive = archive,data_version='v'+version+'r'+revision,file = opath+yyyy+'/'+mmmm+'/mvn_swi_l2_fine'+type+'3d_'+yyyy+mmmm+dddd+'_v'+version+'_r'+revision+'.cdf'
if type eq 'svy' then begin
if newm then mvn_swia_inst2mso
if news then mvn_swia_make_swis_cdf,data_version='v'+version+'r'+revision,file = opath+yyyy+'/'+mmmm+'/mvn_swi_l2_onboardsvyspec_'+yyyy+mmmm+dddd+'_v'+version+'_r'+revision+'.cdf'
if newm then mvn_swia_make_swim_cdf,data_version='v'+version+'r'+revision,file = opath+yyyy+'/'+mmmm+'/mvn_swi_l2_onboardsvymom_'+yyyy+mmmm+dddd+'_v'+version+'_r'+revision+'.cdf'
endif
date = time_string(time_double(date)+24.*3600)
endfor
end