function mvn_pfp_file_next_revision, filename,ndigits, extension=extension
if not keyword_set(ndigits) then ndigits = 2
if not keyword_set(extension) then extension = '.'
nfilename = filename
n = n_elements(filename)
for i=0l,n-1 do begin
f = filename[i]
pos = strpos(/reverse_search,f,extension)
if pos lt ndigits then continue
revstr = strmid(f,pos-ndigits,ndigits)
printdat,revstr
revnum = fix(revstr)
format = string(format='("(i0",i1,")")',ndigits)
nextrev = string(format=format,revnum+1)
strput, f,nextrev,pos-ndigits
nfilename[i] = f
endfor
return,nfilename
end
function mvn_pfp_file_retrieve,pathname,trange=trange,verbose=verbose, source=src,files=files, $
last_version=last_version,valid_only=valid_only,no_update=no_update,create_dir=create_dir,pos_start=pos_start, $
remote_kp_cdf=remote_kp_cdf,insitu_kp_cdf=insitu_kp_cdf, $
daily_names=daily_names,hourly_names=hourly_names,resolution = res,shiftres=shiftres, $
no_server=no_server,user_pass=user_pass,L0=L0,recent=recent, $
DPU=DPU,ATLO=ATLO,RT=RT,pformat=pformat,realtime=realtime,no_download=no_download,name=name
tstart = systime(1)
if keyword_set(recent) then trange = systime(1) - [recent,0] * 86400d
if keyword_set(L0) || ~keyword_set(pathname) then begin
pathname = 'maven/data/sci/pfp/l0_all/YYYY/MM/mvn_pfp_all_l0_YYYYMMDD_v???.dat'
daily_names=1
last_version =1
endif
if keyword_set(insitu_kp_cdf) then begin
pathname = 'maven/data/sci/kp/insitu/sample_insitu_kp/mvn_pfp_l2_keyparam_YYYYMMDD_v??_r??.cdf'
daily_names = 1
last_version=1
endif
if keyword_set(remote_kp_cdf) then begin
pathname = 'maven/kp/remote/sample_iuvs_kp/mvn_rs_kp_YYYYMMDDThh????_v???_r???.cdf'
hourly_names = 1
last_version=1
valid_only=1
endif
if not keyword_set(shiftres) then shiftres =0
if keyword_set(daily_names) then begin
res = round(24*3600L * daily_names)
sres= round(24*3600L * shiftres)
endif
if keyword_set(hourly_names) then begin
res = round(3600L * hourly_names)
sres= round(3600L * shiftres)
endif
source = mvn_file_source(src,verbose=verbose,user_pass=user_pass,no_server=no_server,valid_only=valid_only,last_version=last_version,no_update=no_update)
pos_start = strlen(source.local_data_dir)
dprint,dlevel=5,verbose=verbose,phelp=1,source
if ~keyword_set(RT) then begin
if ~keyword_set(files) then begin
if keyword_set(res) then begin
tr = timerange(trange)
str = (tr-sres)/res
dtr = (ceil(str[1]) - floor(str[0]) ) > 1
times = res * (floor(str[0]) + lindgen(dtr))+sres
pathnames = time_string(times,tformat=pathname)
pathnames = pathnames[uniq(pathnames)]
endif else pathnames = pathname
if keyword_set(create_dir) then begin
files = source.local_data_dir + pathnames
file_mkdir2,file_dirname( files ),_extra=source
return,files
endif
files = file_retrieve(pathnames,_extra=source)
dprint,dlevel=4,verbose=verbose,systime(1)-tstart,' seconds to retrieve ',n_elements(files),' files'
endif
return,files
endif
if keyword_set(RT) then name = 'RTC-CB'
serverdir = source.remote_data_dir
localdir = source.local_data_dir
if not keyword_set(trange) then trange= systime(1)
if not keyword_set(pformat) then begin
if keyword_set(L0) then name='L0'
if keyword_set(ATLO) then begin
name = 'ATLO'
if keyword_set(L0) then name='ATLO-L0'
endif
if keyword_set(DPU) then name='DPU'
if keyword_set(realtime) then name = 'RT'
if 0 then begin
localdir = '~/RealTime/'
serverdir = ''
pformat= 'CMNBLK_*.dat'
endif
if not keyword_set(name) then begin
if time_double(trange[0]) lt time_double('2012-12-1') then name = 'DPU' else name = 'ATLO'
endif
case name of
'DPU' : pformat='maven/prelaunch/dpu/prelaunch/FM/????????_??????_*/commonBlock_*.dat'
'ATLO' : pformat='maven/prelaunch/dpu/prelaunch/live/flight/Split_At_*/initial/common_block.dat'
'ATLO-L0' : pformat='maven/data/sci/pfp/ATLO/mvn_ATLO_pfp_all_l0_????????_v?.dat'
'RT' : pformat='maven/prelaunch/sep/prelaunch_tests/realtime/CMNBLK_*.dat'
'RT-L0' : pformat='maven/prelaunch/dpu/prelaunch/ATLO/*_atlo_l0.dat'
'RTC-L0' : pformat='maven/ITF/CruisePhase_SOCRealtime_LevelZero/20??????_??????_cruise_l0.dat'
'RTC-CB' : pformat='maven/ITF/CruisePhase_SOCRealtime_SplitFiles/Split_At_20??????_??????/initial/common_block.dat'
else : message,'Error'
endcase
endif
dprint,dlevel=2,verbose=verbose,/phelp,pformat
if keyword_set(no_server) then serverdir=''
files = file_search_plus(localdir,pformat,trange=trange,verbose=verbose,serverdir=serverdir,no_download=no_download)
dprint,dlevel=2,verbose=verbose,/phelp,files
return,files
end