#!/bin/csh -f

set data_source = /data/cora5/lund/VortexWake/Viper/Output
set case_master = Fra04_OGE_B744
#set template_dir = $HOME/public_html/templates
set template_dir = $cwd/templates

set plot_size_x = 540
set plot_size_y = 378

set title = 'VORTEX WAKE INVERSE MODELING RESULTS'

# read the cases to display and plots to generate

# the following lines do not work since blank spaces in the titles fool
# the set command.  The much more elaborate code below gets around the
# problem by setting the string arrays element by element.

set cases      = `cat cases.list`
set plots      = `cat plots.list`
set plot_title = `cat plot_titles.list`
set case_title = ($cases)

# create a link to the plot files

if(! -e data) ln -s $data_source data

# build main index page

cat $template_dir/index.html | sed "s/title goes here/$title/" > \
index.html

# build main menu

cat $template_dir/case_menu.head > menu.html

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

cat $template_dir/generic.tail >> menu.html


# build main page

cat $template_dir/main.html | \
   sed "s\title goes here\$title\" > main.html

# build case pages

set n=0
foreach case ($cases)
   @ n ++
   cat $template_dir/case_page.head | \
       sed "s/title goes here/${case_master}_$case/"  > $case.html
   set m=1
   while ($m <= $#plots)
#     echo \<br\> >> $case.html
     set fname = ${case_master}_${case}_${plots[$m]}.png
     echo \<img src=\"data/$fname\" >> $case.html
     echo  alt=\"$plot_title[$m]\" width=\"$plot_size_x\" height=\"$plot_size_y\"\> >> $case.html
     @ m ++
     if ($m <= $#plots) then
        set fname = ${case_master}_${case}_${plots[$m]}.png
        @ m ++
        echo ' '  >> $case.html
        echo \<img src=\"data/$fname\" >> $case.html
        echo  alt=\"$plot_title[$m]\" width=\"$plot_size_x\" height=\"$plot_size_y\"\> >> \
              $case.html
     endif
     echo ' '  >> $case.html
   end
   cat $template_dir/generic.tail >> $case.html
end
