#!/bin/csh

set id1   = $1
set id2   = $2
set ofile = $3
set prods = `ls hplots/*deep* | cut -d_ -f5-7 | cut -d. -f1 | sort | uniq`
set dates = `ls hplots/*deep* | cut -d"/" -f2 | cut -c 5-11 | sort | uniq`
set sens1 = "`../scripts/get_sensor.csh $id1`"
set sens2 = "`../scripts/get_sensor.csh $id2`"

echo $ofile

echo "<html>" > ${ofile}
echo "" >> ${ofile}
echo "<head>" >> ${ofile}
echo "    <title>Comparative Histograms for $sens1($id1) and $sens2($id2)</title>" >> ${ofile}
echo "  </head>" >> ${ofile}
echo "" >> ${ofile}
echo "<CENTER>" >> ${ofile}
echo "" >> ${ofile}
echo "  <body>" >> ${ofile}
echo "    <h1>Comparative Histograms for $sens1($id1) and $sens2($id2)</h1>" >> ${ofile}
echo "    <h2>Global Subsets</h2>" >> ${ofile}
echo "    Derived from Binned Level-3<br>" >> ${ofile}
echo "<p>" >> ${ofile}
echo "<TABLE width="100%" border=2>" >> ${ofile}
echo "  <TBODY>" >> ${ofile}

  foreach d ($dates)

    echo "<TR>" >> ${ofile}
      echo "<TD align="CENTER" colspan=5><h2>$d</h2></TD>" >> ${ofile}
    echo "</TR>" >> ${ofile}

    echo "<TR>" >> ${ofile}
      echo "<TD align="CENTER"><B>Product</B></TD>" >> ${ofile}
      echo "<TD align="CENTER"><B>Deep-Water Trend</B></TD>" >> ${ofile}
      echo "<TD align="CENTER"><B>Oligotrophic Trend</B></TD>" >> ${ofile}
      echo "<TD align="CENTER"><B>Mesotrophic Trend</B></TD>" >> ${ofile}
      echo "<TD align="CENTER"><B>Eutrophic Trend</B></TD>" >> ${ofile}
    echo "</TR>" >> ${ofile}

    foreach p ($prods) 

    set id = "hist${d}_${id2}_${id1}"

    echo "<TR>" >> ${ofile}
      echo "<TD align=Center><b>${p}<b></TD>" >> ${ofile}
      echo "<TD align=CENTER><a href=hplots/${id}_deep_${p}.png><IMG src=hplots/${id}_deep_${p}.small.png></TD>" >> ${ofile}
      echo "<TD align=CENTER><a href=hplots/${id}_olig_${p}.png><IMG src=hplots/${id}_olig_${p}.small.png></TD>" >> ${ofile}
      echo "<TD align=CENTER><a href=hplots/${id}_meso_${p}.png><IMG src=hplots/${id}_meso_${p}.small.png></TD>" >> ${ofile}
      echo "<TD align=CENTER><a href=hplots/${id}_eutr_${p}.png><IMG src=hplots/${id}_eutr_${p}.small.png></TD>" >> ${ofile}
    echo "</TR>" >> ${ofile}

  end
end

echo "</TBODY>" >> ${ofile}
echo "</TABLE>" >> ${ofile}

echo "" >> ${ofile}
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}
