Pro mvn_call_swe_l2gen, time_in = time_in, $
before_time = before_time, $
out_dir = out_dir, $
use_file4time = use_file4time, $
search_time_range = search_time_range, $
days_in = days_in, $
_extra = _extra
common temp_call_swe_l2gen, load_position
set_plot, 'z'
load_position = 'init'
catch, error_status
if error_status ne 0 then begin
print, '%MVN_CALL_SWE_L2GEN: Got Error Message'
help, /last_message, output = err_msg
For ll = 0, n_elements(err_msg)-1 Do print, err_msg[ll]
case load_position of
'init':begin
print, 'Problem with initialization'
goto, SKIP_ALL
end
'instrument':begin
print, '***************INSTRUMENT SKIPPED****************'
goto, SKIP_INSTR
End
'l2gen':Begin
print, '***************FILE SKIPPED****************'
goto, SKIP_FILE
end
else: goto, SKIP_ALL
endcase
endif
If(keyword_set(out_dir)) Then odir = out_dir Else odir = '/disks/data/maven/data/sci/'
instr = 'swe'
ninstr = n_elements(instr)
btime_set_from_file = 0b
times_of_procfiles = 0.0d0
If(keyword_set(time_in)) Then btime = time_double(time_in) Else Begin
If(~keyword_set(days_in)) Then Begin
timefile = file_search(odir+'swe/l2/most_recent_l0_processed.txt')
If(is_string(timefile[0])) Then Begin
openr, unit, timefile[0], /get_lun
btime = strarr(1)
readf, unit, btime
free_lun, unit
btime = time_double(btime[0])
btime_set_from_file = 1b
If(btime lt time_double('2013-10-13') Or btime Gt systime(/sec)+24.0*3600.0d0) Then Begin
dprint, 'bad input time?'
Return
Endif
Endif Else Begin
dprint, 'Missing Input time file?'
Return
Endelse
Endif
Endelse
For k = 0, ninstr-1 Do Begin
load_position = 'instrument'
instrk = instr[k]
If(keyword_set(days_in)) Then Begin
days = time_string(days_in)
timep_do = strmid(days, 0, 4)+strmid(days, 5, 2)+strmid(days, 8, 2)
Endif Else Begin
Case instrk Of
'swe': instr_dir = instrk
Else: instr_dir = instrk
Endcase
sdir = '/disks/data/maven/data/sci/pfp/l0/mvn_pfp_all_l0_*.dat'
pfile = file_search(sdir)
If(keyword_set(use_file4time)) Then Begin
timep = file_basename(pfile)
For i = 0L, n_elements(pfile)-1L Do Begin
ppp = strsplit(timep[i], '_', /extract)
the_date = where((strlen(ppp) Eq 8) And (strmid(ppp, 0, 1)) Eq '2', nthe_date)
If(nthe_date Eq 0) Then timep[i] = '' $
Else timep[i] = ppp[the_date]
Endfor
test_time = time_double(time_string(temporary(timep), /date_only))
Endif Else Begin
finfo = file_info(pfile)
test_time = finfo.mtime
Endelse
If(keyword_set(search_time_range)) Then Begin
atime_test = test_time GT time_double(search_time_range[0])
btime_test = test_time Lt time_double(search_time_range[1])
proc_file = where(atime_test Eq 1 And $
btime_test Eq 1, nproc)
Endif Else If(keyword_set(before_time)) Then Begin
proc_file = where(test_time Lt btime, nproc)
Endif Else Begin
proc_file = where(test_time GT btime, nproc)
Endelse
If(nproc Gt 0) Then Begin
timep = file_basename(pfile[proc_file])
If(btime_set_from_file) Then times_of_procfiles = test_time[proc_file]
For i = 0, nproc-1 Do Begin
ppp = strsplit(timep[i], '_', /extract)
the_date = where((strlen(ppp) Eq 8) And (strmid(ppp, 0, 1)) Eq '2', nthe_date)
If(nthe_date Eq 0) Then timep[i] = '' $
Else timep[i] = ppp[the_date]
Endfor
dummy = is_string(timep, timep_ok)
If(dummy Gt 0) Then Begin
ss_timep = bsort(timep_ok, timep_s)
timep_do = timep_s[uniq(timep_s)]
Endif Else timep_do = ''
Endif Else timep_do = ''
Endelse
If(is_string(timep_do) Eq 0) Then Begin
message, /info, 'No Files to process for Instrument: '+instrk
Endif Else Begin
nproc = n_elements(timep_do)
For i = 0, nproc-1 Do Begin
timei0 = timep_do[i]
timei = strmid(timei0, 0, 4)+$
'-'+strmid(timei0, 4, 2)+'-'+strmid(timei0, 6, 2)
If(time_double(timei) Lt time_double('2013-12-04')) Then Begin
dprint, 'Not processing: '+timei
Continue
Endif
yr = strmid(timei0, 0, 4)
mo = strmid(timei0, 4, 2)
filei_dir = odir+instrk+'/l2/'+yr+'/'+mo+'/'
If(is_string(file_search(filei_dir)) Eq 0) Then Begin
message, /info, 'Creating: '+filei_dir
file_mkdir, filei_dir
Endif
load_position = 'l2gen'
message, /info, 'PROCESSING: '+instrk+' FOR: '+timei
Case instrk Of
'swe': mvn_swe_l2gen, date = timei, directory = filei_dir, _extra=_extra
Else: mvn_swe_l2gen, date = timei, directory = filei_dir, _extra=_extra
Endcase
SKIP_FILE:
del_data, '*'
heap_gc
Endfor
SKIP_INSTR: load_position = 'instrument'
Endelse
Endfor
If(btime_set_from_file && times_of_procfiles[0] Gt 0) Then Begin
message, /info, 'Resetting last file time:'
timefile = file_search(odir+'swe/l2/most_recent_l0_processed.txt')
openw, unit, timefile, /get_lun
time_out = time_string(max(times_of_procfiles))
printf, unit, time_out
free_lun, unit
Endif
SKIP_ALL:
Return
End