#!/bin/csh

set title = 'STABLE BOUNDARY LAYER LES RESULTS FOR GABLS'

set cases = ( case003 \
              case004 \
              case005   )

set case_titles = ( '64^3; tke model with surface correction' \
                    '64^3; dynamic model with no surface correction' )
                    '64^3; dynamic model with surface correction' )

set plots = ( umax   \
              delta  \
              amonin \
              utau   \
              qstar  \
              u_mean \
              spiral \
              t_mean \
              stress \
              var    \
              tke    \
              t_flux \
              vis    \
              dif      )

set plot_titles = ( 'velocity maxima evolution'          \
                    'boundary layer thickness evolution' \
                    'Monin-Obukhov length evolution'     \
                    'friction velocity evolution'        \
                    'surface heat flux evolution'        \
                    'mean velocity'                      \
                    'Eckman spiral'                      \
                    'mean potential temperature'         \
                    'resolved turbulent shear stress'    \
                    'resolved turbulent normal stress'   \
                    'turbulent kinetic energy'           \
                    'turbulent heat flux'                \
                    'eddy viscosity'                     \
                    'eddy diffusivity'                     )


# build main index page

cat ~/public_html/templates/index.html | sed "s/title goes here/$title/" > \
index.html

# build main menu

cat ~/public_html/templates/case_menu.html > menu.html

set n=0
foreach case ($cases)
   @ n ++
   echo \<p\> >> menu.html
   echo \<a href=$case.html  target=2>$case_titles[$n]\</a\>\<br\> >> menu.html
   echo \<p\> >> menu.html
   echo ' ' >> menu.html
end

cat ~/public_html/templates/compare.fragment >> menu.html
cat ~/public_html/templates/generic.tail >> menu.html


# build case pages

set n=0
foreach case ($cases)
   @ n ++
   cat ~/public_html/templates/case_page.head | \
       sed "s/title goes here/$title/" | \
       sed s/subtitle goes here/$case_titles[n]/"  > $case.html
   set m=0
   foreach plot ($plots)
      @ m ++
      echo \<br\> >> $case.html
      echo \<img src=\"data/$case/$plot.jpeg\" >> $case.html
      echo  alt=\"$plot_titles[m]\" width=\"720\" height=\"504\"\> >> $case.html
      echo \<br\> >> $case.html
      echo ' '  >> $case.html
   end
   cat ~/public_html/templates/generic.tail >> $case.html
end


# move into the compare subdirectory

if(! -e compare ) mkdir compare
cd compare


# build compare main page

cat ~/public_html/templates/compare.html | \
   sed "s/title goes here/$compare_title/" > compare.html


# build compare menus

cat ~/public_html/templates/compare_menu.head > menu1.html
cat ~/public_html/templates/compare_menu.head > menu2.html

echo \<h2 align=\"center\"\>compare\</h2\> >> menu1.html
echo \<h2 align=\"center\"\>with\</h2\> >> menu2.html
echo ' ' >> menu1.html
echo ' ' >> menu2.html

set n=0
foreach case ($cases)
   @ n ++
   echo \<b\>$case_titles[$n]\</b\>\<br\> >> menu1.html
   echo \<b\>$case_titles[$n]\</b\>\<br\> >> menu2.html
   set m=0
   foreach plot ($plots)
      @ m ++
      echo \&nbsp\;  \<a href=\"$case.$plot.html\" target=\"view1_frame\"\> \
           $plot_titles[$m]\</a\>\<br\> >> menu1.html
      echo \&nbsp\;  \<a href=\"$case.$plot.html\" target=\"view1_frame\"\> \
           $plot_titles[$m]\</a\>\<br\> >> menu2.html
   end
   echo \<br\> >> menu1.html
   echo \<br\> >> menu2.html
   echo ' ' >> menu1.html
   echo ' ' >> menu2.html
end

cat ~/public_html/templates/generic.tail >> $case.html

# build individual plot frames for comparison

foreach case ($cases)
   foreach plot ($plots)
      if(-e ../data/$case/$plot.jpeg) then
        echo \<\!DOCTYPE html PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\"\> >          $case.$plot.html
        echo \<html\> >> $case.$plot.html
        echo \<head\> >> $case.$plot.html
        echo \<title\>$case $plot results\</title\> >> $case.$plot.html
        echo \<meta http-equiv=\"content-type\" >> $case.$plot.html
        echo ' 'content=\"text/html\; charset=ISO-8859-1\"\> >> $case.$plot.html
        echo \</head\> >> $case.$plot.html
        echo \<body bgcolor=\"\#ffffff\"\> >> $case.$plot.html
        echo \<div align=\"center\"\> >> $case.$plot.html
        echo \<img src=\"../data/$case/$plot.jpeg\" >> $case.$plot.html
        echo alt=\"$case $plot\" height=\"320\"\> >> $case.$plot.html
        echo \</div\> >> $case.$plot.html
        echo \</body\> >> $case.$plot.html
        echo \</html\> >> $case.$plot.html
      else
        cp ~/public_html/templates/blank.html $case.$plot.html
      endif
   end
end
