

PRO eis_mapper_year_index, outdir=outdir

;+
; NAME:
;     EIS_MAPPER_YEAR_INDEX
;
; PURPOSE:
;     Creates an index html giving links to each year of the EIS
;     mission. The routine also re-writes each of the calendar files,
;     inserting a link to the new index file.
;
; CATEGORY:
;     Hinode/EIS; mapper.
;
; CALLING SEQUENCE:
;     EIS_MAPPER_YEAR_INDEX
;
; INPUTS:
;     None.
;
; OPTIONAL INPUTS:
;     Outdir:  Specifies the directory where the mapper files are
;              written. If not specified then $EIS_MAPPER is used. 
;
; OUTPUTS:
;     Creates the file $EIS_MAPPER/html/index.html that contains a
;     list of the years for which EIS Mapper data are available. Each
;     year links to a calendar file for that year. Note that the
;     routine also re-writes each of the calendar files, inserting a
;     link to the new index file.
;
; CALLS:
;     EIS_MAPPER_YEAR
;
; EXAMPLE:
;     IDL> eis_mapper_year_index
;
; MODIFICATION HISTORY:
;     Ver.1, 09-Jan-2020, Peter Young
;     Ver.2, 24-Mar-2020, Peter Young
;       Modified to work with the new EIS Mapper format; renamed to
;       eis_mapper_year_index.
;     Ver.3, 31-Mar-2020, Peter Young
;       Added /no_processing in call to eis_mapper_year.
;     Ver.4, 06-Apr-2020, Peter Young
;       Added ruled line at top of webpage.
;-

eis_mapper_dir=getenv('EIS_MAPPER')

IF n_elements(outdir) NE 0 THEN BEGIN
  chck=file_search(outdir,count=count)
  IF count EQ 0 THEN file_mkdir,outdir
ENDIF ELSE BEGIN 
  IF eis_mapper_dir EQ '' THEN BEGIN
    print,'% EIS_MAPPER_YEAR_INDEX: the $EIS_MAPPER environment variable is not defined.'
    return
  ENDIF ELSE BEGIN
    outdir=eis_mapper_dir
  ENDELSE
ENDELSE
htmldir=concat_dir(outdir,'html')
outfile=concat_dir(htmldir,'index.html')


jd=systime(/julian,/utc)
caldat,jd,m,d,curr_year

openw,lout,outfile,/get_lun

printf,lout,'<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd">'
printf,lout,'<html><head>'
printf,lout,'<title>EIS Mapper Summary</title>'
printf,lout,'</head><body style="background-color: rgb(255, 255, 255);" vlink="#cc33cc">'
printf,lout,'<center>'
printf,lout,'<table summary="" border="0" cellpadding="0" cellspacing="0" width="700">'
printf,lout,'<tbody><tr><td height="30"><br></td></tr>'
printf,lout,'<tr><td align="left"><hr>'
printf,lout,'<h1>EIS Mapper Summary</h1>'
printf,lout,'<hr>'

printf,lout,'<p>'
FOR i=2006,curr_year DO BEGIN
  chckdir=concat_dir(htmldir,trim(i))
  chckfile=concat_dir(chckdir,'index.html')
  chck=file_info(chckfile)
  IF chck.exists EQ 1 THEN BEGIN
    printf,lout,'<a href='+trim(i)+'/index.html>'+trim(i)+'</a><br>'
  ENDIF 
ENDFOR 
printf,lout,'<p>'

printf,lout,'<hr>'
printf,lout,'<p><i>Page maintained by Dr Peter R Young.</i> </p>'
printf,lout,'</td></tr></tbody>'
printf,lout,'</table></center>'
printf,lout,'</body></html>'

free_lun,lout

; Now go through all of the years and re-write the calendar files,
; inserting the link to the index file. I'm using
; /no_processing as otherwise the routine will try to write html files
; for every day (if they don't already exist).
;
FOR i=2006,curr_year DO BEGIN
  eis_mapper_year,i,outdir=outdir,/no_processing
ENDFOR 

print,'% EIS_MAPPER_YEAR_INDEX: The file '+outfile+' has been written.'

END
