#!/bin/bash
# fplod 2006-05-31T10:34:18Z aedon.locean-ipsl.upmc.fr (Darwin)
# . add creation of all_plots.html using firststeps.html
# . remplace ~/SAXO_RD/SRC/Documentation/xmldoc/figpng by ./figpng/
# we suppose that this shell script is launched when we are in 
# <working space of saxo>/SRC/Documentation/xmldoc/
#
set -u
#
case "${1}" in
   getsaxo)
      # ndate is the date in the file SAXO_RD_*.tar.gz
      ndate=$( echo ~/SAXO_RD/SAXO_RD_*.tar.gz )
      ndate=${ndate##*_}
      ndate=${ndate%.tar.gz}
      # ndate2 is the date in the file TestsData_*.tar.gz
      ndate2=$( echo ~/IDL/TestsData_*.tar.gz )
      ndate2=${ndate2##*_}
      ndate2=${ndate2%.tar.gz}
   ;;
   *)
      echo "iii : no ndate determination needed"
   ;;
esac

# figures lists
cd ./figpng

#
figsplt_lev=""
for i in tst_plt_lev_[0-9][0-9].png
do
  figsplt_lev="${figsplt_lev} \<ulink url=\"figpng\/${i}?format=raw\"\>\&showfig\;\<\/ulink\>"
done
figspltz_lev=""
for i in tst_pltz_lev_[0-9][0-9].png
do
  figspltz_lev="${figspltz_lev} \<ulink url=\"figpng\/${i}?format=raw\"\>\&showfig\;\<\/ulink\>"
done
figspltt_lev=""
for i in tst_pltt_lev_[0-9][0-9].png
do
  figspltt_lev="${figspltt_lev} \<ulink url=\"figpng\/${i}?format=raw\"\>\&showfig\;\<\/ulink\>"
done
#
figsplt_orca2=""
for i in tst_plt_orca2_[0-9][0-9].png
do
  figsplt_orca2="${figsplt_orca2} \<ulink url=\"figpng\/${i}?format=raw\"\>\&showfig\;\<\/ulink\>"
done
figspltz_orca2=""
for i in tst_pltz_orca2_[0-9][0-9].png
do
  figspltz_orca2="${figspltz_orca2} \<ulink url=\"figpng\/${i}?format=raw\"\>\&showfig\;\<\/ulink\>"
done
figspltt_orca2=""
for i in tst_pltt_orca2_[0-9][0-9].png
do
  figspltt_orca2="${figspltt_orca2} \<ulink url=\"figpng\/${i}?format=raw\"\>\&showfig\;\<\/ulink\>"
done
#
figsplt_orca05=""
for i in tst_plt_orca05_[0-9][0-9].png
do
  figsplt_orca05="${figsplt_orca05} \<ulink url=\"figpng\/${i}?format=raw\"\>\&showfig\;\<\/ulink\>"
done
figspltz_orca05=""
for i in tst_pltz_orca05_[0-9][0-9].png
do
  figspltz_orca05="${figspltz_orca05} \<ulink url=\"figpng\/${i}?format=raw\"\>\&showfig\;\<\/ulink\>"
done
figspltt_orca05=""
for i in tst_pltt_orca05_[0-9][0-9].png
do
  figspltt_orca05="${figspltt_orca05} \<ulink url=\"figpng\/${i}?format=raw\"\>\&showfig\;\<\/ulink\>"
done
##
#
figsplt_lev_stride=""
for i in tst_plt_lev_stride_[0-9][0-9].png
do
  figsplt_lev_stride="${figsplt_lev_stride} \<ulink url=\"figpng\/${i}?format=raw\"\>\&showfig\;\<\/ulink\>"
done
figspltz_lev_stride=""
for i in tst_pltz_lev_stride_[0-9][0-9].png
do
  figspltz_lev_stride="${figspltz_lev_stride} \<ulink url=\"figpng\/${i}?format=raw\"\>\&showfig\;\<\/ulink\>"
done
figspltt_lev_stride=""
for i in tst_pltt_lev_stride_[0-9][0-9].png
do
  figspltt_lev_stride="${figspltt_lev_stride} \<ulink url=\"figpng\/${i}?format=raw\"\>\&showfig\;\<\/ulink\>"
done
#
figsplt_orca2_stride=""
for i in tst_plt_orca2_stride_[0-9][0-9].png
do
  figsplt_orca2_stride="${figsplt_orca2_stride} \<ulink url=\"figpng\/${i}?format=raw\"\>\&showfig\;\<\/ulink\>"
done
figspltz_orca2_stride=""
for i in tst_pltz_orca2_stride_[0-9][0-9].png
do
  figspltz_orca2_stride="${figspltz_orca2_stride} \<ulink url=\"figpng\/${i}?format=raw\"\>\&showfig\;\<\/ulink\>"
done
figspltt_orca2_stride=""
for i in tst_pltt_orca2_stride_[0-9][0-9].png
do
  figspltt_orca2_stride="${figspltt_orca2_stride} \<ulink url=\"figpng\/${i}?format=raw\"\>\&showfig\;\<\/ulink\>"
done
#
figsplt_orca05_stride=""
for i in tst_plt_orca05_stride_[0-9][0-9].png
do
  figsplt_orca05_stride="${figsplt_orca05_stride} \<ulink url=\"figpng\/${i}?format=raw\"\>\&showfig\;\<\/ulink\>"
done
figspltz_orca05_stride=""
for i in tst_pltz_orca05_stride_[0-9][0-9].png
do
  figspltz_orca05_stride="${figspltz_orca05_stride} \<ulink url=\"figpng\/${i}?format=raw\"\>\&showfig\;\<\/ulink\>"
done
figspltt_orca05_stride=""
for i in tst_pltt_orca05_stride_[0-9][0-9].png
do
  figspltt_orca05_stride="${figspltt_orca05_stride} \<ulink url=\"figpng\/${i}?format=raw\"\>\&showfig\;\<\/ulink\>"
done
##
cd .. # ie <working space of saxo>/SRC/Documentation/xmldoc

case "${1}" in
   firststeps)
      sed -e s/"\&figsplt_lev\;"/"${figsplt_lev}"/g \
          -e s/"\&figsplt_orca2\;"/"${figsplt_orca2}"/g \
          -e s/"\&figsplt_orca05\;"/"${figsplt_orca05}"/g \
          -e s/"\&figspltz_lev\;"/"${figspltz_lev}"/g \
          -e s/"\&figspltz_orca2\;"/"${figspltz_orca2}"/g \
          -e s/"\&figspltz_orca05\;"/"${figspltz_orca05}"/g \
          -e s/"\&figspltt_lev\;"/"${figspltt_lev}"/g \
          -e s/"\&figspltt_orca2\;"/"${figspltt_orca2}"/g \
          -e s/"\&figspltt_orca05\;"/"${figspltt_orca05}"/g \
          -e s/"\&figsplt_lev_stride\;"/"${figsplt_lev_stride}"/g \
          -e s/"\&figsplt_orca2_stride\;"/"${figsplt_orca2_stride}"/g \
          -e s/"\&figsplt_orca05_stride\;"/"${figsplt_orca05_stride}"/g \
          -e s/"\&figspltz_lev_stride\;"/"${figspltz_lev_stride}"/g \
          -e s/"\&figspltz_orca2_stride\;"/"${figspltz_orca2_stride}"/g \
          -e s/"\&figspltz_orca05_stride\;"/"${figspltz_orca05_stride}"/g \
          -e s/"\&figspltt_lev_stride\;"/"${figspltt_lev_stride}"/g \
          -e s/"\&figspltt_orca2_stride\;"/"${figspltt_orca2_stride}"/g \
          -e s/"\&figspltt_orca05_stride\;"/"${figspltt_orca05_stride}"/g \
          ${1}.xml > ${1}_${$}.xml 
   ;;
   getsaxo)
      szsrc=$( ls -lh ~/SAXO_RD/SRC/SAXO_RD_${ndate}.tar.gz | awk '{print $5}' )
      szdata=$( ls -lh ~/IDL/TestsData_${ndate2}.tar.gz | awk '{print $5}' )
      sed -e s/"\&date\;"/${ndate}/g \
          -e s/"\&date2\;"/${ndate2}/g \
          -e s/"\&szsrc\;"/${szsrc}/g \
          -e s/"\&szdata\;"/${szdata}/g \
          ${1}.xml > ${1}_${$}.xml 
   ;;
   *)
      cp ${1}.xml ${1}_${$}.xml 
      echo "iii : no xml transformation needed"
   ;;
esac
#
CLASSPATH="$CLASSPATH:\
/sw/share/java/saxon/saxon.jar:\
/sw/share/xml/xsl/docbook-xsl/extensions/saxon653.jar"
export CLASSPATH
#java  com.icl.saxon.StyleSheet  \
#    -o ${1}.html ${1}.xml  \
#    /sw/share/xml/xsl/docbook-xsl/html/docbook.xsl  \
#    use.extensions=1 section.autolabel=1 html.stylesheet="saxo.css" css.decoration=1
#
#    callout.graphics.path="/sw/share/xml/xsl/docbook-xsl/images/callouts/"

java  com.icl.saxon.StyleSheet -o ${1}.html ${1}_${$}.xml  \
    /sw/share/xml/xsl/docbook-xsl/html/docbook.xsl  \
   section.autolabel=1 html.stylesheet="saxo.css" css.decoration=1

case "${1}" in
   firststeps)
      java  com.icl.saxon.StyleSheet -o all_plots_${$}.xml ${1}_${$}.xml  \
      all_plots_docbook.xsl
      java com.icl.saxon.StyleSheet -o all_plots.html all_plots_${$}.xml  \
      /sw/share/xml/xsl/docbook-xsl/html/docbook.xsl  \
      section.autolabel=1 html.stylesheet="saxo.css" css.decoration=1
      rm -f all_plots_${$}.xml
   ;;
esac
rm -f ${1}_${$}.xml
