FUNCTION getkfiles, aj1, hour1, aj2, hour2
common DP_LOG
common DP_DATA
corresfile_path=getenv('ROOT_RPWS')+'pro/corres_year_directory'
datapath=getenv('NAS_RPWS')
workpath=getenv('ROOT_RPWS')
dir_ext=strarr(4)
end_log=ptr_new()
dir_ext[0]='_001_090'
dir_ext[1]='_091_180'
dir_ext[2]='_181_270'
dir_ext[3]='_271_366'
command="wget --http-user=casrpws --http-passwd=uiowa -m -nd -P "
webpath=' "http://cassini.physics.uiowa.edu/~wsk/cas/daspage/cas_data/'
pdfchange=0
openr, unit, corresfile_path, /get_lun
linesnb=file_lines(corresfile_path)
print, linesnb
corres1=strarr(linesnb)
corres=strarr(3, linesnb)
readf, unit, corres1
for i=0, linesnb-1 do begin
corres[*, i]=strsplit(corres1[i], " ", /extract)
endfor
free_lun, unit
day=aj1
hour=hour1
while day lt aj2 or (day eq aj2 and hour lt hour2) do begin
dayhour=day+hour*0.01d
indcorres=where(dayhour ge double(strtrim(corres[1, *], 2)) and dayhour le double(strtrim(corres[2, *], 2)), count)
if count eq 0 then begin
indcorres=0
endif
webdir=corres[0, indcorres]
year=long(day/1000)
ddday=day-year*1000
hourstr=string(format='(".",i2.2)', hour)
kfound=0
kfilename='K'+strtrim(string(day), 2)+hourstr
period = make_dir_tab(year,ddday,year,ddday)
pathto = datapath+(*period)(0)
if (not file_test(pathto)) then begin
file_mkdir, pathto
endif
pathto=pathto+'/k/'
if (not file_test(pathto)) then begin
file_mkdir, pathto
endif
if (not file_test(pathto+kfilename)) then begin
spawn, command+pathto+webpath+webdir+kfilename+'"'
info=file_info(pathto+kfilename)
if (not info.exists) then begin
widget_control, dp_log_txt, set_value=kfilename+': this file cannot be found', /append
endif else begin
if (info.size eq 0) then begin
widget_control, dp_log_txt, /append, $
set_value=kfilename+': the size of this file is 0. It is not copied.'
file_delete, pathto+kfilename
endif else begin
widget_control, dp_log_txt, /append, $
set_value=kfilename+': this file has been retrieved.'
kfound=kfound+1
if ptr_valid(period) then ptr_free, period
period=make_dir_tab(year, ddday, year,ddday)
make_directory, *period, datapath
if ((not widget_info(dp_n1_but, /button_set)) and $
(file_test(strmid(pathto, 0, strlen(pathto)-2)+'n1/R'+strmid(kfilename, 1, 8)+'*'))) then begin
widget_control, dp_log_txt, /append, $
set_value='The N1 file R'+strmid(kfilename, 1, 10)+' is created'
make_n1_files, day, hour, day, hour+1
pdfchange=1
endif
if ((not widget_info(dp_n2_but, /button_set)) and $
(file_test(strmid(pathto, 0, strlen(pathto)-2)+'n2/P'+strmid(kfilename, 1, 8)+'*'))) then begin
widget_control, dp_log_txt, /append, $
set_value='The N2 file P'+strmid(kfilename, 1, 10)+' is created'
make_n2_files, day, hour, day, hour+1
pdfchange=1
endif
pdfchange=1
endelse
endelse
endif else begin
spawn, command+workpath+webpath+webdir+kfilename+'"'
info=file_info(workpath+kfilename)
if (not info.exists) then begin
file_delete, pathto+kfilename
widget_control, dp_log_txt, /append, $
set_value=kfilename+': this file cannot be found but it had already been retrieved. It has been deleted'
kfound=kfound+1
endif else begin
if (info.size eq 0) then begin
widget_control, dp_log_txt, /append, $
set_value=kfilename+': the size of the new version of this file is 0. It is not copied and the first version is deleted'
file_delete, workpath+kfilename
file_delete, pathto+kfilename
endif else begin
timework=info.mtime
timedata=(file_info(pathto+kfilename)).mtime
if timework gt timedata then begin
pdfchange=1
widget_control, dp_log_txt, /append, $
set_value=kfilename+': the new version of this file has been retrieved.'
kfound=kfound+1
period=make_dir_tab(year, ddday, year,ddday)
make_directory, *period, datapath
file_move, workpath+kfilename, pathto+kfilename, /noexpand_path, /overwrite
if ((not widget_info(dp_n1_but, /button_set)) and $
(file_test(strmid(pathto, 0, strlen(pathto)-2)+'n1/R'+strmid(kfilename, 1, 10)))) then begin
widget_control, dp_log_txt, /append, $
set_value='The N1 file R'+strmid(kfilename, 1, 10)+' is redone'
h1=long(strtrim(strmid(kfilename, 9, 2), 2))
make_n1_files, day, h1, day, h1+1
endif
if ((not widget_info(dp_n2_but, /button_set)) and $
(file_test(strmid(pathto, 0, strlen(pathto)-2)+'n2/P'+strmid(kfilename, 1, 10)))) then begin
widget_control, dp_log_txt, /append, $
set_value='The N2 file P'+strmid(kfilename, 1, 10)+' is redone'
h1=long(strtrim(strmid(kfilename, 9, 2), 2))
make_n2_files, day, h1, day, h1+1
endif
endif else begin
file_delete,workpath+kfilename
widget_control, dp_log_txt, /append, $
set_value=kfilename+': this file has already been retrieved.'
kfound=kfound+1
endelse
endelse
endelse
endelse
hour=hour+1
if hour eq 24 then begin
if (pdfchange and (not widget_info(dp_pdf_but, /button_set)) and $
(file_test(strmid(pathto, 0, strlen(pathto)-2)+'pdf/'+ $
strmid(kfilename, 1, 7)+'.pdf'))) then begin
widget_control, dp_log_txt, /append, $
set_value='The pdf and lis files must be redone for the day '+strmid(kfilename, 1, 7)
period=make_dir_tab(year, ddday, year, ddday)
make_directory, *period, datapath
summary, day, day, nblocks=1, /print_ps
widget_control, dp_log_txt, /append, $
set_value=strmid(kfilename, 1, 7)+': the pdf file is printed'
if (ptr_valid(end_log)) then begin
l=(size(*end_log))[1]+1
tmp=strarr(l)
endif else begin
l=1
tmp=strarr(1)
endelse
tmp[l-1]=strmid(kfilename, 1, 7)+'.pdf has been printed'
ptr_free, end_log
end_log=ptr_new(tmp)
endif
pdfchange=0
if (file_test(strmid(pathto, 0, strlen(pathto)-2)+'pdf/'+Strmid(kfilename, 1, 7)+'.pdf') $
and (kfound eq 0)) then begin
file_delete, strmid(pathto, 0, strlen(pathto)-2)+'pdf/'+strmid(kfilename, 1, 7)+'.pdf'
widget_control, dp_log_txt, /append, set_value=strmid(kfilename, 1, 7)+ $
'.pdf: this pdf file has been deleted because there is no k file for this day anymore'
endif
hour=0
day=day+1
if ddday eq 366 then begin
day=(year+1)*1000l+1l
endif
endif
endwhile
if ptr_valid(period) then ptr_free, period
ptr_free, end_log
return, 1
end