#! /bin/csh -f

# Read a config file and generate a table of JSOC data series
#
# config file is set in "in" argument
# output is html table in file set by "out=" argument
#
# e.g. make_html.csh in=series_list out=keylists.html

set in=series_list
set outfinal=keylists.html
set out=WORKING_keylists.html

while ($# > 0)
echo try $1
  if ($1 =~ in=*) then
    set $1
  else if ($1 =~ out=*) then
    set $1
  else
   echo Unknown argument $1
  endif
shift
end

cat >$out <<!
<html>
<body>
<table width="800" border="2" cellspacing="1" >
<TR align="center">
<TH width="6%" rowspan="2"><B>Processing Level</B></TH>
<TH width="15%" colspan="2" align="center"><B>JSOC dataseries</B></TH>
<TH width="15%" colspan="2" align="center"><B>Keywords</B></TH>
<TH width="30%" colspan="3" ><B>Contents Summary</B></TH>
<TH width="34%" rowspan="2" ><B>Description</B></TH>
</TR>
<TR>
<TH width="5%"><B> Project Name</B></TH>
<TH width="10%"><B> Data Name</B></TH>
<TH width="5%"><B>Prime Keys</B></TH>
<TH width="10%"><B>Keylist</B></TH>
<TH width="10%"><B>Records</B></TH>
<TH width="10%"><B>First</B></TH>
<TH width="10%"><B>Last</B></TH>
</TR>
!

set LEVEL
set SERIES
set PROJECT

set LINE=1
while ($LINE > 0)
  set CONF = `head --lines=$LINE $in | tail -1`
  if ($CONF[1] == \#) then
    # ignore comments
  else if ($CONF == END) then
    set LINE=-1
  else if ($CONF =~ LEVEL=*) then
    set $CONF
  else if ($CONF =~ PROJECT=*) then
    set $CONF
  else if ($CONF =~ SERIES=*) then
    set $CONF
    echo "<TR>" >> $out
    echo "<TD>$LEVEL</TD>" >>$out
    make_row.csh $PROJECT.$SERIES >>$out
    echo "</TR>" >>$out
  else
    echo Unknown Config Command $CONF
  endif
  @ LINE = $LINE + 1
  end
 
echo "<TR align="center"><TD colspan="9"><I> updated " >>$out
date +" %a %e %B %Y at %r" >>$out
echo "</I></TR>" >>$out

cat >>$out <<!
</TABLE>
</BODY>
</HTML>
!

mv $out $outfinal
