#! /bin/tcsh -f

set idir  = "plots"

set file  = residual_rvs.html
set title = "MODIS/Terra Residual Scan Dependence"
set prods = "nLw_412 nLw_443 nLw_488 nLw_531 nLw_551 nLw_667 nLw_678 taua eps"

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><h2>Date</h2></td>" >> $file
foreach p ($prods)    
    echo "<td align=center><h2>$p</h2></td>" >> $file
end
echo "</tr>" >> $file


foreach f (${idir}/*nLw_412_scan.gif) 

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

    echo $y $d

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

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

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

set file  = residual_rvs_perdet.html
set title = "MODIS/Terra Residual Scan Dependence"
set prods = "nLw_412 nLw_443 nLw_488 nLw_531 nLw_551 nLw_667 nLw_678 taua eps"

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><h2>Date</h2></td>" >> $file
foreach p ($prods)    
    echo "<td align=center><h2>$p</h2></td>" >> $file
end
echo "</tr>" >> $file


foreach f (${idir}/*nLw_412_scan_perdet.gif) 

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

    echo $y $d

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

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

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

set file  = residual_det.html
set title = "MODIS/Terra Residual Detector Dependence"
set prods = "nLw_412 nLw_443 nLw_488 nLw_531 nLw_551 nLw_667 nLw_678 eps taua"

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><h2>Date</b></h2>" >> $file
foreach p ($prods)    
    echo "<td align=center><h2>$p</h2></td>" >> $file
end
echo "</tr>" >> $file


foreach f (${idir}/*nLw_412_det.gif) 

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

    echo $y $d

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

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

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

set file  = residual_det_pix.html
set title = "MODIS/Terra Residual Detector Dependence"
set prods = "nLw_412 nLw_443 nLw_488 nLw_531 nLw_551 nLw_667 nLw_678 eps taua"

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><h2>Case</h2></td>" >> $file
foreach p ($prods)
    echo "<td align=center><h2>$p</h2></td>" >> $file
end
echo "</tr>" >> $file

foreach pre (`ls ${idir}/*nLw_412_det_p100_p200.gif | cut -d_ -f1-2`)

  foreach pix (p100_p200 p626_p726 p939_p1039 p1154_p1254)

    set f = `ls ${pre}_nLw_412_det_${pix}.gif`
    set x = `basename $f | cut -d. -f1`
    set y = `basename $x | cut -c2-5`
    set d = `basename $x | cut -c6-8`

    echo $y $d $pix

    set p1 = `echo $pix | cut -d_ -f1 | cut -dp -f2`
    set p2 = `echo $pix | cut -d_ -f2 | cut -dp -f2`

    echo "<tr>" >> $file
    echo "<td><b>$y $d<br>pixels:${p1}-${p2}</b></td>" >> $file

    foreach p ($prods)
        set pf   = `echo $f | sed "s/nLw_412/$p/g"`
        set pftn = `echo $pf | cut -d. -f1`.small.gif
        echo "<td><a href=${pf}><img src=${pftn}></a></td>" >> $file
    end
    echo "</tr>" >> $file

  end

  echo "<tr>" >> $file
  echo "<td> <br>  <br> <br> </td>" >> $file
  echo "</tr>" >> $file

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

exit 0



