#!/bin/csh

set id1 = $1
set id2 = $2
set tid = ${id2}_${id1}
set prods = `ls plots/*deep*repeat.png | cut -d_ -f3 | cut -d. -f1 | sort | uniq`
set regions = "global"
set sen1 = "`../scripts/get_sensor.csh $id1`"
set sen2 = "`../scripts/get_sensor.csh $id2`"
set sens = "${sen2}-vs-${sen1}"

foreach r ($regions)
  set rname = "`../scripts/get_subname.csh $r`"
  if ($r == "global") then
    set subsets = "deep olig meso eutr"
  endif
  if ($r == "regional") then
    set subsets = "Hawaii"
  endif
  if ($r == "zonal") then
    set subsets = "AtlN55 PacN45 PacN35 PacN25 PacN15 PacEqu PacS15 PacS25 PacS35 PacS45 AtlS55"
  endif
  foreach p ($prods)
    set ofile = "comp_${r}_${p}_repeat.html"
    set pname = "`../scripts/get_subname.csh $p`"
    echo "<html>" > ${ofile}
    echo "" >> ${ofile}
    echo "<head>" >> ${ofile}
    echo "<title>$tid $r $p repeat</title>" >> ${ofile}
    echo "</head>" >> ${ofile}
    echo "" >> ${ofile}
    echo "<CENTER>" >> ${ofile}
    echo "" >> ${ofile}
    echo "<body>" >> ${ofile}
    echo "<h1>$sens ($tid)</h1>" >> ${ofile}
    echo "<h1>$rname $pname Annual Repeatability</h1>" >> ${ofile}
    echo "Derived from Common Level-3 Bins<br>" >> ${ofile}
    echo "<p>" >> ${ofile}
    echo "<TABLE width="100%">" >> ${ofile}
    echo "<TBODY>" >> ${ofile}
    foreach s ($subsets)
      set sname = "`../scripts/get_subname.csh $s`"
      echo "<TR>" >> ${ofile}
      echo "<TD align="CENTER"><B>$sen1 ($id1) $sname Subset</B></TD>" >> ${ofile}
      echo "<TD align="CENTER"><B>$sen2 ($id2) $sname Subset</B></TD>" >> ${ofile}
      echo "</TR>" >> ${ofile}
      echo "<TR>" >> ${ofile}
      echo "<TD align=CENTER><a href=plots/${id1}_${s}_${p}_repeat.png> <IMG src=plots/${id1}_${s}_${p}_repeat.small.png></TD>" >> ${ofile}
      echo "<TD align=CENTER><a href=plots/${id2}_${s}_${p}_repeat.png> <IMG src=plots/${id2}_${s}_${p}_repeat.small.png></TD>" >> ${ofile}
      echo "</TR>" >> ${ofile}
    end
    echo "</TBODY>" >> ${ofile}
    echo "</TABLE>" >> ${ofile}
    echo "" >> ${ofile}
  end
end

echo "<hr>" >> ${ofile}
echo "" >> ${ofile}
echo "</CENTER>" >> ${ofile}
    echo "<address><a href=mailto:bryan.a.franz@nasa.gov>Bryan A. Franz</a></address>" >> ${ofile}
echo "</BODY>" >> ${ofile}
echo "</HTML>" >> ${ofile}
