pro update_sxt_co_index, outfil=outfil, nocopy=nocopy
;+
; Name: UPDATE_SXT_CO_INDEX
; PURPOSE: edit the index.html file to insert the title of the newest nugget.
; CALLING SEQUENCE: update_sxt_co_index, outfil=outfil
; OPTIONAL INPUT KEYWORD: outfil- specify the output, without which
; index.html is modified.
; SIDE EFFECT: unless nocopy is set, the newest nugget is copied
; to SXTweekly.html.
; HISTORY: written, 17-Mar-01, NVN
; debugged, 20-Apr-2001, NVN
;-
cmonth=['-Jan-','-Feb-','-Mar-','-Apr-','-May-','-Jun-','-Jul-', $
'-Aug-','-Sep-','-Oct-','-Nov-','-Dec-']
spawn,'pwd',pwd0
print,'Your present working directory is ',pwd0
print,'Change directory to /home/www/sxt_co, but you will be back at ',pwd0
cd,'/home/www/sxt_co'
; cd,'/net/notung/usr/people/nitta/idlpro/sxt_co_dummy'
file=find_file('index.html')
sz0=size(file)
if sz0(0) ne 1 then begin
print,'index.html does not exist or is not unique.'
print,'size(find_file(''index.html''))=',sz
print,'Please restore the index.html file. I am not doing anything now.'
return
endif
pex=anytim2ex(!stime)
dummy='index_'+string(pex(6),format='(i4.4)')+ $
string(pex(5),format='(i2.2)')+string(pex(4),format='(i2.2)')
cmd='/bin/cp -p index.html '+dummy
spawn,cmd
print,'index.html copied to a temporary file '+dummy
infil=find_newest_nugget()
sz=size(infil)
if sz(1) ne 7 then begin
print,'no newest nugget obtained'
return
endif
print,'the newest nugget = ',infil(0)
year=strmid(infil(0),0,2)
day=strmid(infil(0),4,2)
fmtt=day+cmonth(fix(strmid(infil(0),2,2))-1)+year
y=rd_tfile(infil)
ny=n_elements(y)
h1ex=intarr(ny)
b1ex=intarr(ny)
for i=0,ny-1 do h1ex(i)=strpos(y(i),'
')
for i=0,ny-1 do b1ex(i)=strpos(y(i),'
')
jj=where(h1ex ne -1,nj)
if nj ne 2 then print,'# of not 2'
kk=where(b1ex ne -1,nk)
if nk ne 2 then print,'# of
not 2'
z=arr2str(y(jj(1)+1:kk(1)-1))
sc0=strpos(z,'')
sc2=strpos(z,'')
titl=strmid(z,sc0+9,(sc2-1-(sc0+9)))
print,'title of the newest nugget = ',titl
yy=rd_tfile(file)
szy=size(yy)
nyy=n_elements(yy)
ftab=intarr(nyy)
for i=0,nyy-1 do ftab(i)=strpos(yy(i),'')
ll=where(ftab ne -1, nll)
if nll eq 0 then begin
print,'There is no in the file.'
return
endif
yprev=yy(ll(0)+2)
sday0=strpos(yprev,'"')
prevy=strmid(yprev,sday0(0)+1,2)
prevm=strmid(yprev,sday0(0)+3,2)
prevd=strmid(yprev,sday0(0)+5,2)
prevt=prevd+cmonth(fix(prevm)-1)+prevy
; the most recent date in index.html is compared with the date of
; the nugget. if the latter is not 7 days after the former,
; then index.html will not be updated.
delt=int2secarr(fmtt,prevt)/86400L
if delt ne 7L then begin
print,'The newest nugget is ',delt,' (not 7) days after the current nugget.'
print,'Therefore, index.html is not updated."
goto, cops
endif
t0=''
t1=''+fmtt+': | '
t2=''+titl+' | '
t3='
'
yyy=strarr(nyy+4)
yyy(0:ll(0))=yy(0:ll(0))
yyy(ll(0)+1)=t0
yyy(ll(0)+2)=t1
yyy(ll(0)+3)=t2
yyy(ll(0)+4)=t3
yyy(ll(0)+5:nyy+4-1)=yy(ll(0)+1:nyy-1)
if n_elements(outfil) ne 1 then outfil=file(0)
print,'The file '+outfil+' is going to be changed.'
openw,lun,outfil,/get_lun
for i=0,nyy+4-1 do printf,lun,yyy(i)
close,lun
print,'The information on the newest nugget inserted."
cops:
print,infil(0),' is being copied to SXTweekly.html, if it is Saturday or later.'
cmd='/bin/cp -p '+infil(0)+' SXTweekly.html'
; only after Saturday of the week of the nugget
if int2secarr(fmtt,!stime)/86400. lt -1.0 then spawn,cmd
; fmtt is friday
wid0=anytim2weekid(addtime(fmtt,delt=3.*60.*24.),/str) ; next week's wid
wid=strmid(wid0,0,5)
womfil=find_file('/home/sxt_co/wom_rep/table_plan.'+wid(0))
szw=size(womfil)
if szw(0) eq 1 then begin
cd,'/home/www/sxt_co/'+strmid(infil(0),0,6)+'/'
cmdw='/bin/cp -p '+womfil+' .'
spawn,cmdw
print,'Wom report for week '+wid+' copied to '+strmid(infil(0),0,6)
plan2html,'table_plan.'+wid(0)
print,'HTML version of wom report created.'
endif else begin
print,'No wom file for week '+wid+' found.'
endelse
print,'everything went smoothly.'
print,'Therefore, a copy of the old index.html '+dummy+' will be erased.'
cd,'/home/www/sxt_co'
cmdlast='/bin/rm '+dummy
spawn,cmdlast
cd,pwd0(0)
return
end