#!/bin/csh

cd $1
echo "<html>" > index.html
echo "<center>" >> index.html
echo "<h1>Mission Averaged Statistics By Region</h1>" >> index.html
echo "</center>" >> index.html

echo "<table align="center" border=2>" >> index.html

set files = `ls -1 *.txt | grep global; ls -1 *.txt | grep deep; ls -1 *.txt | grep _olig; ls -1 *.txt | grep meso; ls -1 *.txt | grep eutr; ls -1 *.txt | grep Hawaii; ls -1 *.txt | grep NPG; ls -1 *.txt | grep SPG; ls -1 *.txt | grep SIO; ls -1 *.txt | grep AtlNE; ls -1 *.txt | grep AtlN55; ls -1 *.txt | grep PacN | sort -r; ls -1 *.txt | grep PacEqu; ls -1 *.txt | grep PacS; ls -1 *.txt | grep "^nh"; ls -1 *.txt | grep "^eq"; ls -1 *.txt | grep "^sh"`

echo $files

foreach f ($files) 

  set rid = `echo $f | cut -d_ -f3`
  set t1  = `echo $f | cut -d_ -f2`
  set t2  = `echo $f | cut -d_ -f1`
  set reg = `../../scripts/get_subname.csh $rid`

  echo "<tr>" >> index.html 
  echo "<td colspan=7 align="center"><a href=$f><b><br>$reg<br><br></b></a></td>" >> index.html 
  echo "</tr>" >> index.html 

  echo "<tr>" >> index.html 
  echo "<td></td>" >> index.html 
  echo "<td colspan=2><b>$t1</b></td>" >> index.html 
  echo "<td colspan=2><b>$t2</b></td>" >> index.html 
  echo "<td colspan=2><b>${t2}/${t1}</b></td>" >> index.html 
  echo "</tr>" >> index.html 

  echo "<tr>" >> index.html 
  echo "<td><b>Prod</b></td>" >> index.html 
  echo "<td><b>Mean</b></td>" >> index.html 
  echo "<td><b>Std Dev</b></td>" >> index.html 
  echo "<td><b>Mean</b></td>" >> index.html 
  echo "<td><b>Std Dev</b></td>" >> index.html 
  echo "<td><b>Mean</b></td>" >> index.html 
  echo "<td><b>Std Dev</b></td>" >> index.html 
  echo "</tr>" >> index.html 

  foreach line ("`cat $f | tail -n +6`")
     set prod  = `echo $line | cut -d" " -f1`
     set mean1 = `echo $line | cut -d" " -f2`
     set stdv1 = `echo $line | cut -d" " -f3`
     set mean2 = `echo $line | cut -d" " -f4`
     set stdv2 = `echo $line | cut -d" " -f5`
     set mean3 = `echo $line | cut -d" " -f6`
     set stdv3 = `echo $line | cut -d" " -f7`
     echo "<tr>" >> index.html 
     echo "<td><b>$prod</b></td>" >> index.html 
     echo "<td><b>$mean1</b></td>" >> index.html 
     echo "<td><b>$stdv1</b></td>" >> index.html 
     echo "<td><b>$mean2</b></td>" >> index.html 
     echo "<td><b>$stdv2</b></td>" >> index.html 
     echo "<td><b>$mean3</b></td>" >> index.html 
     echo "<td><b>$stdv3</b></td>" >> index.html 
     echo "</tr>" >> index.html 
  end  
end
echo "</table>" >> index.html
echo "</html>" >> index.html
exit 0
