#!/bin/csh

set dir = $1
set id1 = $2
set top = `pwd`

set sen1 = "`../scripts/get_sensor.csh $id1`"
set sennam = "${sen1}(${id1})"
set testid = $id1

set file  = "${dir}/index.html"
set title = "${sen1} Residual Scan Dependence"

cd $dir
set prods = `ls -1 *.small.png | cut -d_ -f3-4 | sed "s/_scan//g" | sed "s/.small.png//g" | sort | uniq`
set prefs = `ls -1 *.small.png | cut -d_ -f1-2 | sort | uniq`
cd $top

echo "<html>" > $file
echo "<head>" >> $file
echo "<title>$title</title>" >> $file
echo "</head>" >> $file
echo "<center>" >> $file
echo "<body>" >> $file
echo "<h1>$title</h1>" >> $file

echo "<table>" >> $file

echo "<tr>" >> $file
echo "<td><b>Date</b></td>" >> $file
foreach p ($prods)
    echo "<td align=center><b>$p</b></td>" >> $file
end
echo "</tr>" >> $file


foreach f ($prefs) 

    set x = `echo $f | cut -d_ -f1`
    set y = `echo $x | cut -c2-5`
    set d = `echo $x | cut -c6-8`

    echo $y $d

    echo "<tr>" >> $file
    echo "<td><b>$y $d</b></td>" >> $file

    foreach p ($prods)
        set pftn = `basename ${dir}/?${y}${d}_*_${p}_scan*.small.png`
        set pf   = `echo $pftn | cut -d. -f1`.png
        echo "<td><a href=${pf}><img src=${pftn}></a></td>" >> $file
    end
    echo "</tr>" >> $file

end
echo "</table>" >> $file
