#!/bin/bash




# pas de . dans outfilename!!
# outfilename doit correspondre au nom de ce script
outfilename_root="diag_TROP_thetao-MERCATOR_GLORYS2V3_ORCA025"

scriptname=`basename "$0" | cut -d'.' -f1`

if [ "${scriptname}" != ${outfilename_root} ]; then
   printf "\n\n\n\n   outfilename(${outfilename_root})  != scriptname(${scriptname}) => exit\n\n\n\n"; exit
fi

#################################################################################
for depth in "1m" "36m" "78m" "108m"
do

outfilename=`echo ${outfilename_root} | sed -e "s/thetao/thetao_${depth}/"`
outfilename="${outfilename}.xhtml"

titre_H1="Biais thetao ${depth} - GLORYS2V3_ORCA025 (simulations TROP)"
titre_H2=""

# Header
bookmarks="${titre_H1}"
stylesheet1="./css/chris.css"
stylesheet1_title="feuille de style CHRIS"

imgdir1="./images/thetao-MERCATOR_GLORYS2V3_ORCA025"

img_ext_nemo="2003-2007_thetao_${depth}-GLORYS2V3_ORCA025_2003-2007_R20130808_gridT.png"
img_ext_now="1989-2009_thetao_${depth}-GLORYS2V3_ORCA025_1993-2009_R20130808_gridT.png"

exp_list_trop075_nemo="\
tr075_quik \
tr075_erainocrt \
tr075n_quik \
tr075n_erainocrt \
tr075n_newflx \
tr075n_n02nogm"

exp_list_trop025_nemo="\
tr025_quikubs \
tr025n_gm01 \
tr025_quiktau \
tr025_quik \
tr025_erainocrt \
tr025n_gm00" 

exp_list_trop12_nemo="\
tr12_quik \
tr12_erainocrt \
tr12n_n03 \
tr12n_n02"

exp_list_trop075_now="\
tr075_cpl12L60_sol093 \
tr075_cpl12L60_sol094 \
tr075now_44L60_sol099obcokalb3zhao3nn \
tr075now_12L60_sol094obcokalb3 \
tr075now_11L60m_swrad04"

exp_list_trop025_now="\
tr025_cpl12L60_sol094"


#exp_list="${exp_list_all} ${exp_list_trop075_now} ${exp_list_trop075_nemo} ${exp_list_trop025_nemo} ${exp_list_trop12_nemo}"
 



#===============================================================================
# Header
cat >  ${outfilename}   <<  EOD
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html><html xmlns="http://www.w3.org/1999/xhtml">

  <head>
    <title>${bookmarks}</title>
    <link type="text/css" rel="stylesheet" href="${stylesheet1}" title="${stylesheet1_title}" />
    
  <meta charset="UTF-8" /></head>



EOD


# Javascript  (open Windows)
cat >>  ${outfilename}   <<  EOD
<!--========================================================================-->
<!--                      Javascript (Open Windows)                         -->
<!--========================================================================-->
  <script type="text/javascript">
    // initialise the visibility check
    function affCache(idDiv) {
    var div = document.getElementById(idDiv);
    if (div.style.display == "none")
    div.style.display = "";
    else
    div.style.display = "none";
    }

    // Chargement images dans window.open
    function ChargeImage1(img1) {
    window.open(img1,img1,'width=1700, height=1000, status=no').focus();return false;
    }
  </script>


EOD




cat >>  ${outfilename}   <<  EOD
<!--========================================================================-->
<!--                              BODY                                      -->
<!--========================================================================-->
  <body>        
    <h1>${titre_H1}</h1>
    <h2>${titre_H2}</h2>

<!--========================================================================-->
<!--                              TABLE                                     -->
<!--========================================================================-->
<table>
  <tbody>

  <tr> 
EOD


#===============================================================================
exp_list="${exp_list_trop075_nemo}"; img_ext=${img_ext_nemo}
#===============================================================================
for exp in ${exp_list}; do
   cat >>  ${outfilename}   <<  EOD
    <td align="center" rowspan="1" colspan="1"><span class="stabilo2">${exp}</span></td>
EOD
done

cat >>  ${outfilename}   <<  EOD
  </tr><tr>
EOD

for exp in ${exp_list}; do
   img1="${imgdir1}/${exp}_${img_ext}"
   cat >>  ${outfilename}   <<  EOD
    <td><a href="javascript:;" onclick="ChargeImage1('${img1}');">
        <img class="image4" src='${img1}' /></a></td>
EOD
done
cat >>  ${outfilename}   <<  EOD
  </tr><tr>
EOD
#===============================================================================
exp_list="${exp_list_trop025_nemo}"; img_ext=${img_ext_nemo}
#===============================================================================
for exp in ${exp_list}; do
   cat >>  ${outfilename}   <<  EOD
    <td align="center" rowspan="1" colspan="1"><span class="stabilo2">${exp}</span></td>
EOD
done

cat >>  ${outfilename}   <<  EOD
  </tr><tr>
EOD

for exp in ${exp_list}; do
   img1="${imgdir1}/${exp}_${img_ext}"
   cat >>  ${outfilename}   <<  EOD
    <td><a href="javascript:;" onclick="ChargeImage1('${img1}');">
        <img class="image4" src='${img1}' /></a></td>
EOD
done
cat >>  ${outfilename}   <<  EOD
  </tr><tr>
EOD
#===============================================================================
exp_list="${exp_list_trop12_nemo}"; img_ext=${img_ext_nemo}
#===============================================================================
for exp in ${exp_list}; do
   cat >>  ${outfilename}   <<  EOD
    <td align="center" rowspan="1" colspan="1"><span class="stabilo2">${exp}</span></td>
EOD
done

cat >>  ${outfilename}   <<  EOD
  </tr><tr>
EOD

for exp in ${exp_list}; do
   img1="${imgdir1}/${exp}_${img_ext}"
   cat >>  ${outfilename}   <<  EOD
    <td><a href="javascript:;" onclick="ChargeImage1('${img1}');">
        <img class="image4" src='${img1}' /></a></td>
EOD
done
cat >>  ${outfilename}   <<  EOD
  </tr><tr>
EOD
#===============================================================================
exp_list="${exp_list_trop075_now}"; img_ext=${img_ext_now}
#===============================================================================
for exp in ${exp_list}; do
   cat >>  ${outfilename}   <<  EOD
    <td align="center" rowspan="1" colspan="1"><span class="stabilo2">${exp}</span></td>
EOD
done

cat >>  ${outfilename}   <<  EOD
  </tr><tr>
EOD

for exp in ${exp_list}; do
   img1="${imgdir1}/${exp}_${img_ext}"
   cat >>  ${outfilename}   <<  EOD
    <td><a href="javascript:;" onclick="ChargeImage1('${img1}');">
        <img class="image4" src='${img1}' /></a></td>
EOD
done
cat >>  ${outfilename}   <<  EOD
  </tr><tr>
EOD
#===============================================================================
exp_list="${exp_list_trop025_now}"; img_ext=${img_ext_now}
#===============================================================================
for exp in ${exp_list}; do
   cat >>  ${outfilename}   <<  EOD
    <td align="center" rowspan="1" colspan="1"><span class="stabilo2">${exp}</span></td>
EOD
done

cat >>  ${outfilename}   <<  EOD
  </tr><tr>
EOD

for exp in ${exp_list}; do
   img1="${imgdir1}/${exp}_${img_ext}"
   cat >>  ${outfilename}   <<  EOD
    <td><a href="javascript:;" onclick="ChargeImage1('${img1}');">
        <img class="image4" src='${img1}' /></a></td>
EOD
done
cat >>  ${outfilename}   <<  EOD
  </tr><tr>
EOD
#===============================================================================

cat >>  ${outfilename}   <<  EOD
  </tr>
EOD


cat >>  ${outfilename}   <<  EOD
  </tbody>
</table>
</body>
</html>
EOD

#################################################################################
done
