#!/bin/bash -x
#
# TODO
# ====
#
# use doidldoc.sh for assistant outputs
#
# surveiller gdl pour voir l'apparition de resolve_all dans les version > 0.9rc4
#
# - fplod 20100511T133249Z dedale.locean-ipsl.upmc.fr (Linux)
#    * working with fl :
# % Error: RESOLVE_ALL: can not resolve: function ADAPT_HIST_EQUAL
#
# EVOLUTIONS
# ==========
#
# $Id$
#
# - fplod 20100205T104058Z aedon.locean-ipsl.upmc.fr (Darwin)
#
#   * fix hyperlink path errors
#   * do not anymore transfert tools and temporary files on download/
#
#     already existing files have been removed manually on
#     saxo@forge:~/download/xmldoc/
#
# - fplod 20100125T112917Z aedon.locean-ipsl.upmc.fr (Darwin)
#
#   * complete doidldoc.sh calling sequence
#
# - fplod 20091112T101551Z zeus.locean-ipsl.upmc.fr (Linux)
#
#   * add check on doidldoc.sh status
#
# - fplod 20091112T091437Z aedon.locean-ipsl.upmc.fr (Darwin)
#
#   * define idl_dir (ref = idl6.4 on zeus)
#   * use doidldoc.sh for HTML outputs
#
# fplod 2008-04-28T08:40:23Z aedon.locean-ipsl.upmc.fr (Darwin)
# add wiki update
# fplod 2008-04-16T12:23:44Z aedon.locean-ipsl.upmc.fr (Darwin)
# add wiki production
# fplod 2008-04-16T09:02:45Z aedon.locean-ipsl.upmc.fr (Darwin)
# html files produced from DocBook files are now produced using makefile
# instead of makehtml.sh
# fplod 2007-08-21T09:29:04Z aedon.locean-ipsl.upmc.fr (Darwin)
# follow changes of calling sequence of pro2href.sh
# add call to pro2href.sh for replacement of <proidl>...</proidl>
# fplod 2007-06-26T14:33:12Z aedon.locean-ipsl.upmc.fr (Darwin)
# copy listings.css in idldoc_assistant_output
# fplod 2007-03-20T15:10:29Z aedon.locean-ipsl.upmc.fr (Darwin)
# . replace <pro>ginette</pro> by a sequence like
# <a href="./ginette.html">ginette</a> in idldoc html and assistant outputs
# . encapsulate example content in <pre> </pre> in idldoc assistant outputs
# smasson Fri Sep 22 17:28:10 CEST 2006
# check that the number of existing html files for each .pro file is 2!
# fplod 2006-09-21T14:55:09Z aedon.locean-ipsl.upmc.fr (Darwin)
# remove css in idldoc html output (/embed)
# entraine modif de modification de css pour nonproportional font ++ anglais
# fixe is replace by pre and no more css modification
# bug in idldoc html output file idldoc-categories.html
# http://www.w3.org/TR/xhtml1/DTD/xhtml-transitional.dtd
# au lieu de
# http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd
# ++ prévenir l'auteur
# fplod 2006-09-21T13:05:32Z aedon.locean-ipsl.upmc.fr (Darwin)
# add an svn id in idldoc-lib.adb after </profile>
# fplod 2006-09-20T16:34:38Z aedon.locean-ipsl.upmc.fr (Darwin)
# suppress ?format=raw
# fplod 2006-09-20T15:30:15Z aedon.locean-ipsl.upmc.fr (Darwin)
# add copy of html files under xmldoc and idldoc_html_output on
# saxo@forge.ipsl.jussieu.fr:/ipsl/forge/projets/saxo/download/
# see dodocdownload
# fplod 2006-09-20T11:05:23Z aedon.locean-ipsl.upmc.fr (Darwin)
# correction to really suppress date in idldoc assistant outputs (font
# instaed of div in html output)
# fplod 2006-09-18T13:25:12Z aedon.locean-ipsl.upmc.fr (Darwin)
# add status checking after makehtml.sh
# smasson Fri Sep 15 10:42:01 CEST 2006
# merge idldoc html and idldoc assistant
# smasson Thu Sep 14 15:19:23 CEST 2006
# add the revision number in the name of SAXO_SRC_*.tar.gz
# smasson Wed Sep 13 14:18:02 CEST 2006
# add the directory-overview.html from dir-files.html in idldoc_html_output
# fplod 2006-09-07T08:09:47Z aedon.locean-ipsl.upmc.fr (Darwin)
# main is rename to websaxo
# fplod 2006-09-05T15:39:47Z aedon.locean-ipsl.upmc.fr (Darwin)
# add Source link in idldoc html output
# snlod/fplod 2006-08-25T08:30:36Z electre.locean-ipsl.upmc.fr (Darwin)
# add for idldoc assistant
# fplod 2006-08-17T09:19:06Z aedon.locean-ipsl.upmc.fr (Darwin)
# add transformation after idldoc to force non-proportional font
# on bloc delimited by
#  <fixe>
#  </fixe>
# in .pro files (with modification of css)
# !! do not replace \ by \\ inside this block
# !! replace \ by an other character is a good idea
# cf. example in ToBeReviewed/TRIANGULATION/definetri.pro
# fplod 2006-07-21T08:23:52Z aedon.locean-ipsl.upmc.fr (Darwin)
# add mini_notice production
# fplod 2006-07-11T08:26:05Z aedon.locean-ipsl.upmc.fr (Darwin)
# commented tidy in dohtml section is moved in makehtml
# fplod 2006-07-10T08:22:53Z aedon.locean-ipsl.upmc.fr (Darwin)
# ajout de  white-space: pre; dans la css pour file_comments
# fplod 2006-07-04T13:09:19Z aedon.locean-ipsl.upmc.fr (Darwin)
# for idldoc html output
# because preformat option doesn't seem to work well
# replace
# div class="value"
# by
# div class="preformat"
# fplod 2006-06-19T08:46:39Z aedon.locean-ipsl.upmc.fr (Darwin)
# for idldoc html output
#. replace
#     -e 's/\(href=".*\)\(\.html\)\("\)/\1\2?format=raw\3/g' \
#     -e 's/\(href=".*\)\(\.html\)\(#.*"\)/\1\2?format=raw\3/g' \
#     -e 's/\(src=".*\)\(\.html\)\("\)/\1\2?format=raw\3/g' \
# by
# -e 's@\(href="[^.]*[^h]*[^t]*[^m]*[^l]*[^"]*\)\(\.html\)\("\)@\1\2?format=raw\3@g' \
# -e 's@\(href="[^.]*[^h]*[^t]*[^m]*[^l]*[^"]*\)\(\.html\)\(#.*"\)@\1\2?format=raw\3@g' \
#-e 's@\(src="[^.]*[^h]*[^t]*[^m]*[^l]*[^"]*\)\(\.html\)\("\)@\1\2?format=raw\3@g'
# in order to be able to add ?format=raw several time on one line
# . suppress .html in line like
# a parameter from the routine ./ReadWrite/idl-NetCDF/ncdf_read.html
# in files idldoc-index*.html
# fplod 2006-06-14T12:41:37Z aedon.locean-ipsl.upmc.fr (Darwin)
# add embed parameter idldoc instructions to try to fix ticket#17
# fplod 2006-06-07T12:11:50Z aedon.locean-ipsl.upmc.fr (Darwin)
# add g option in ?format=raw sed transformation in order to fix
# link on top of idldoc like directory-overview.html
# fplod 2006-06-07T10:57:35Z aedon.locean-ipsl.upmc.fr (Darwin)
# add ?format=raw in idldoc production for frames
# fplod 2006-06-07T08:14:15Z aedon.locean-ipsl.upmc.fr (Darwin)
# add action for idldochtml
# fplod 2006-06-02T14:28:30Z aedon.locean-ipsl.upmc.fr (Darwin)
# modification to produce tar files in /tmp/saxo_${$} when dotar=1
# modification to copy tar files on http://forge.ipsl.jussieu.fr/saxo/download/
# when doforge=1
# produce tar files in /tmp/saxo_${$} when dotar=1
#set -x
set -u
#
# define idl_dir
# reference is idl 64 on zeus.locean-ipsl.upmc.fr
idl_dir=/usr/local_linux/idl/idl_6.4/idl/
# reference gdl on aedon.locean-ipsl.upmc.fr
idl_dir=/opt/local/bin/
# reference fl on dedale.locean-ipsl.upmc.fr
idl_dir=/usr/temp/fplod/fl/fl_0.79a/bin/
#
docompileall=0
dohtml=0
dowiki=0
dooldtest=0
doidlwavedoc=0
doidldoc=0
doTARsrc=0
doTARdata=0
doforge=0
doSRClocean=0
doDTAlocean=0
doSRCipsl=0
doDTAipsl=0
doSRCidris=0
doDTAidris=0
dodocdownload=0
dowikiupdate=0
#
case $( whoami ) in
    smasson)
        lgforge=smasson
    ;;
    floseb)
        lgforge=smasson
    ;;
    *)
        lgforge=saxo
    ;;
esac
#
if [ ${lgforge} != smasson ]
then
    doSRClocean=0
    doDTAlocean=0
    doSRCipsl=0
    doDTAipsl=0
    doSRCidris=0
    doDTAidris=0
fi
#
# get the date in a nice format
#
ndate=`date +%Y%m%d`
# memorize current directory
# should be <working space>/SRC/Documentation/xmldoc
memopwd=$(pwd)/
application="FL"
#
#------------------------------------------------------------------
if [ ${docompileall} -eq 1 ]
then
    case ${application} in
       'idl')
           cat << EOF > /tmp/compileall${$}.pro
.reset_session
;
!path = expand_path('+' + '../..') + ':' + expand_path('+' + !dir)
resolve_all, resolve_either='def_myuniquetmpdir', skip_routines = ['xxx2ps','trends', 'label_gmt']
resolve_all, resolve_either = 'find', skip_routines = ['xxx2ps','trends', 'label_gmt']
def_myuniquetmpdir
oldcm = find('oldcm_empty')
;oldcm = find('oldcm_full')
oldcm = oldcm[0]
@cm_general
file_copy, oldcm, myuniquetmpdir + 'oldcm_used.pro', /overwrite
!path = myuniquetmpdir + ':' + !path
IF !journal NE 0 THEN journal
journal, myuniquetmpdir + 'cm_demomode_used.pro'
journal
path_cache, /rebuild
;
resolve_all, resolve_either='keep_compatibility', skip_routines = ['xxx2ps','trends', 'label_gmt']
;
EOF
        ;;
        FL)
            cat <<EOF > /tmp/compileall${$}.pro
.reset_session
;
!path = expand_path('+' + '../..') + ':' + expand_path('+' + !path)
resolve_all
def_myuniquetmpdir
oldcm = find('oldcm_empty')
;oldcm = find('oldcm_full')
oldcm = oldcm[0]
@cm_general
file_copy, oldcm, myuniquetmpdir + 'oldcm_used.pro', /overwrite
!path = myuniquetmpdir + ':' + !path
IF !journal NE 0 THEN journal
journal, myuniquetmpdir + 'cm_demomode_used.pro'
journal
path_cache, /rebuild
;
resolve_all, resolve_either='keep_compatibility', skip_routines = ['xxx2ps','trends', 'label_gmt']
;
EOF
        ;;
        GDL)
        ;;
        *)
            echo "eee : unknown application"
            exit 1
        ;;
    esac
    #
    for i in $( find ${memopwd}/../.. -name "*.pro" | grep -iv label_gmt  | grep -iv report )
    do
        # does it contains pro or function ?
        egrep -iq '^ *	*(pro|function)' ${i}
        if [ ${?} -eq 0 ]
        then
            echo "print, '$( basename ${i} .pro ) :'" >> /tmp/compileall${$}.pro
            echo "resolve_all, resolve_either = '$( basename ${i} .pro )', skip_routines = ['xxx2ps','trends', 'label_gmt', 'report']" >> /tmp/compileall${$}.pro
        fi
    done
    echo "exit" >> /tmp/compileall${$}.pro
    IDL_STARTUP=/tmp/compileall${$}.pro
    #++   ${idl_dir}/bin/idl &> /tmp/compileallerr_${$}
    #++   ${idl_dir}/gdl &> /tmp/compileallerr_${$}
    ${idl_dir}/fl
    ${idl_dir}/fl &> /tmp/compileallerr_${$}

    echo
    echo
    grep -i "error" /tmp/compileallerr_${$}
    # grep -q "Compilation error(s)" /tmp/compileallerr_${$}
    if [ ${?} -ne 0 ]
    then
        echo "ALL SAXO files are OK..."
        rm -f /tmp/compileallerr_${$} /tmp/compileall${$}.pro
    else
        grep "Compilation error(s)" /tmp/compileallerr_${$}
        echo "eee : see /tmp/compileallerr_${$}"
        more /tmp/compileallerr_${$}
        exit 1
    fi
    echo
    echo
fi
#------------------------------------------------------------------
if [ ${dohtml} -eq 1 ]
then
    #
    # redo the HTML files
    #
    cd ${memopwd}
    make clean
    make html
fi
#------------------------------------------------------------------
if [ ${dowiki} -eq 1 ]
then
    #
    # redo the WIKI files
    #
    cd ${memopwd}
    make clean
    make tracwiki
fi
#------------------------------------------------------------------
if [ ${dooldtest} -eq 1 ]
then
    # make the old test
    #
    cd ${memopwd}/../../Tests/
    ./makeold.sh
    exit 0
fi
#------------------------------------------------------------------
if  [ ${doidlwavedoc} -eq 1 ]
then
    #
    # redo idlwave doc
    #
    cd ${memopwd}/../..
    Documentation/idlwave_catalog -v -f saxo
    exit 0
fi
#------------------------------------------------------------------
if  [ ${doidldoc} -eq 1 ]
then
    #
    # build HTML idldoc outputs
    ${SAXO_DIR}/SRC/Documentation/xmldoc/doidldoc.sh \
    -i ../.. -t "SAXO Documentation" \
    -o ../idldoc_html_output/
    -idl_dir ${idl_dir}
    -e pro -r ../idldoc_html_output/ \
    -e proidl -r /usr/local_linux/idl/idl_6.4/idl/help/online_help
    doidldoc_html=${?}
    if [ ${doidldoc_html} -ne 0 ]
    then
        echo "eee : pb with doidldoc html"
        exit 1
    fi
    #
    # build a idl file to launch idldoc
    output=../idldoc_assistant_output/
    log="/tmp/idldocassistant_${$}.log"
    pro="/tmp/idldocassistant_${$}.pro"
    cat <<EOF > ${pro}
!path = expand_path('+' + '../idldoc/')
print,!path
idldoc,root="../../",title="SAXO Documentation Assistant", $
LOG_FILE="${log}", $
output="${output}", overview='../../overview', /statistics, /preformat, /embed, /assistant
exit
EOF
    # launch idl with the file built above
    IDL_STARTUP=${pro};${idl_dir}/bin/idl
    /bin/rm ${pro}
    # In order to do not have too many revision in svn, we modify some
    # lines produced by idldoc :
    # examples :
    # <!-- Generated by IDLdoc 2.0 on Wed Jun  7 10:25:28 2006 -->
    # will be replaced by
    # <!-- Generated by IDLdoc 2.0 -->
    # <p><font color="gray" size="-3">&nbsp;&nbsp;Produced by IDLdoc 2.0 on Wed Sep 13 16:32:10 2006.</font></p>
    # will be replaced by
    # <p><font color="gray" size="-3">&nbsp;&nbsp;Produced by IDLdoc 2.0</font></p>
    # <h2>Produced on Wed Jun  7 10:23:13 2006</h2>
    # will be delete
    # other lines will be deleted because the time is the time of checkout not
    # the time of revision.
    # the sequence of lines
    #<dl>
    #      <dt>Last modification:</dt>
    #       <dd>Fri Jun  2 11:46:24 2006</dd>
    #    </dl>
    # should also be removed ++ je ne sais pas dire en sed la ligne
    # suivant l'occurrence de Last modification
    # replace *_param_* in href attributes because anchors are badly written
    # with _keyword_
    #++ -e 's@\(href="#_.*\)\(_param_\)\(.*"\)@\1_keyword_\3@g' \ # ++ pb global
    #  ONLINE_HELP, book="../idldoc_assistant_output/idldoc-lib.adp", /full_path    # won't work
    # encapsulate example content in <pre> </pre> in idldoc assistant outputs
    # Examples section is supposed to start with <h3>Examples</h3>
    # and end is before <h3>Version history</h3>
    list_html=$(find ${output} -name "*.html")
    for file_html in ${list_html}
    do
        sed \
        -e "s/\(Generated by IDLdoc 2.0\)\( on .*\)\( -->\)/\1\3/" \
        -e "s/\(Produced by IDLdoc 2.0\)\( on .*\)\(\.<\/font>\)/\1\3/" \
        -e "/<h2>Produced on/d" \
        -e "/Last modification:/d" \
        -e "/<dd>... ... .* ..:..:.. ....<\/dd>/d" \
        -e '/href/s@_param_@_keyword_@g' \
        -e 's@<div class="value">@<div class="preformat">@' \
        -e 's/div\#file_comments {/div\#file_comments { white-space: pre;/' \
        -e 's@^ <fixe>@<pre>@' \
        -e 's@^ </fixe>@</pre>@' \
        -e "s@<h3>Examples</h3>@<h3>Examples</h3><pre>@" \
        -e "s@<h3>Version history</h3>@</pre><h3>Version history</h3>@" \
        ${file_html} > ${file_html}_modify
        mv ${file_html}_modify ${file_html}
    done
    # replace <pro>ginette</pro> by a sequence like
    # <a href="./ginette.html">ginette</a>
    ./pro2href.sh -i ${output} -r ${output} -e pro
    status=${?}
    if [ ${status} -ne 0 ]
    then
        echo "eee : pb during ./pro2href.sh for <pro>...</pro>"
        exit 1
    fi
    # replace <proidl>ginette</proidl> by a sequence like
    # <a href="./ginette.html">ginette</a>
    ./pro2href.sh -i ${output} -r ${idl_dir}/help/online_help -e proidl
    status=${?}
    if [ ${status} -ne 0 ]
    then
        echo "eee : pb during ./pro2href.sh for <proidl>...</proidl>"
        exit 1
    fi
    # add the directory-overview.html from dir-files.html in idldoc_html_output
    list_html=$(find ../idldoc_html_output -name dir-files.html)
    for file_html in ${list_html}
    do
        fout=../idldoc_assistant_output/${file_html#../idldoc_html_output/*}
        fout=${fout%/*}/directory-overview.html
        cp ${file_html} ${fout}
    done
    # copy listings.css (needed by directory-overview.html files)
    cp ../idldoc/resource/listings.css ${output}
    # add an id in idldoc-lib.adp
    cat << EOF > /tmp/adp_modification
<!-- \$Id\$ -->
EOF
    sed -e "/<\/profile>/r /tmp/adp_modification" \
    ../idldoc_assistant_output/idldoc-lib.adp > \
    ../idldoc_assistant_output/idldoc-lib.adp_${$}
    mv ../idldoc_assistant_output/idldoc-lib.adp_${$} \
    ../idldoc_assistant_output/idldoc-lib.adp
    rm /tmp/adp_modification
    echo "iii : you can see log file in ${log}"
    echo "iii : and look ${output}/idldoc-warnings.html#undoc"
    # check that the number of existing html files for each .pro file is 2!
    for i in $( find ../.. -name "*.pro" )
    do
        nhtml=$( find ../.. -name $( basename ${i} .pro ).html | wc -l )
        if [ ${nhtml} -ne 2 ]
        then
            echo "ERROR there is no 2 $( basename ${i} .pro ).html files"
            find ../.. -name $( basename ${i} .pro ).html
            echo
        fi
    done
fi
#------------------------------------------------------------------
if [ ${doTARsrc} -eq 1 ]
then
    rev=$( svn info | grep -i revision | awk '{print $NF}' )
    localtarbase=/tmp/savesaxo_${$}
    mkdir ${localtarbase}/
    # clean backup files : *~
    find ${memopwd}/../../.. -name "*~" -exec rm {} \;
    # prepare the source tar (without the svn...)
    #
    cd ${memopwd}/../../..
    tar czf ${localtarbase}/SAXO_SRC_${ndate}r${rev}.tar.gz --exclude .svn SRC
    #
    # informations
    echo "iii : following file may be copied on http://forge.ipsl.jussieu.fr/saxo/download/"
    ls -l ${localtarbase}
fi
#------------------------------------------------------------------
if [ ${doTARdata} -eq 1 ]
then
    localtarbase=/tmp/savesaxo_${$}
    mkdir ${localtarbase}/
    #
    # prepare the data tar (without the svn...)
    #
    cd ${memopwd}/../../..
    tar czf ${localtarbase}/SAXO_DATA_${ndate}.tar.gz  --exclude .svn DATA
    #
    # informations
    echo "iii : following file may be copied on http://forge.ipsl.jussieu.fr/saxo/download/"
    ls -l ${localtarbase}
fi
#------------------------------------------------------------------
if [ ${doforge} -eq 1 ]
then
    echo "iii : you will be asked ${lgforge}@forge.ipsl.jussieu.fr passwd two times"
    if [ ${doTARsrc} -ne 1 ]
    then
       localtarbase=${1}
    fi
    scp ${localtarbase}/SAXO_*.tar.gz ${lgforge}@forge.ipsl.jussieu.fr:/ipsl/forge/projets/saxo/download/
    echo "iii : do not forget to update getsaxo.html"
    echo "iii : \$ make ./getsaxo.html"
    echo "iii : do not forget to clean ${localtarbase}"
fi
#------------------------------------------------------------------
if [[ (${doDTAlocean} -eq 1) || (${doDTAipsl} -eq 1) ]]
then
    echo "iii : you will be asked ${lgforge}@forge.ipsl.jussieu.fr passwd"
    infodata=$(ssh ${lgforge}@forge.ipsl.jussieu.fr ls -lht /ipsl/forge/projets/saxo/download/SAXO_DATA_*.tar.gz | head -n 1)
    filedata=$(echo ${infodata} | awk '{print $NF}')
    filedata=$(basename ${filedata})
    cat <<EOF > job_data_$$
#!/bin/bash
cd SAXO_DIR
#
rm -rf DATA
wget http://forge.ipsl.jussieu.fr/saxo/download/${filedata}
gunzip ${filedata}
tar vxf $( basename ${filedata} .gz )
rm -f $( basename ${filedata} .gz )
#
chmod -R 755 *
exit
#
EOF
fi
#------------------------------------------------------------------
if [ ${doSRClocean} -eq 1 ]
then
    # update src on cerbere
    #
    echo "iii : update src on cerbere"
    ssh smasson@cratos.locean-ipsl.upmc.fr "svn update SAXO_DIR/SRC ; chmod -R 755 SAXO_DIR"
fi
#------------------------------------------------------------------
if [ ${doDTAlocean} -eq 1 ]
then
    # update data on cerbere
    echo "iii : update data on cerbere"
    scp job_data_$$ smasson@cerbere.locean-ipsl.upmc.fr:.
    ssh smasson@cratos.locean-ipsl.upmc.fr "chmod 755 job_data_$$ ; ./job_data_$$ ; rm -f job_data_$$"
fi
#------------------------------------------------------------------
if [ ${doSRCipsl} -eq 1 ]
then
    # update src on calcul2
    #
    echo "iii : update src on calcul2"
    ssh smlod@calcul2.ipsl.jussieu.fr "svn update SAXO_DIR/SRC ; chmod -R 755 SAXO_DIR"
fi
#------------------------------------------------------------------
if [ ${doDTAipsl} -eq 1 ]
then
    # update data on cook
    echo "iii : update data on cook"
    scp job_data_$$ smlod@cook.ipsl.jussieu.fr:.
    ssh smlod@cook.ipsl.jussieu.fr "chmod 755 job_data_$$ ; ./job_data_$$ ; rm -f job_data_$$"
fi
#------------------------------------------------------------------
if [ ${doSRCidris} -eq 1 ]
then
    # update src on ulam
    echo "iii : update src to ulam"
    ssh -t smasson@cerbere.locean-ipsl.upmc.fr ssh reee217@ulam.idris.fr "svn update SAXO_DIR/SRC ; chmod -R 755 SAXO_DIR"
fi
#------------------------------------------------------------------
if [ ${doDTAidris} -eq 1 ]
then
    # create the update script for ulam
    if [[ (${doDTAlocean} -eq 0) && (${doDTAipsl} -eq 0) ]]
    then
        echo "iii : you will be asked ${lgforge}@forge.ipsl.jussieu.fr passwd"
        infodata=$(ssh ${lgforge}@forge.ipsl.jussieu.fr ls -lht /ipsl/forge/projets/saxo/download/SAXO_DATA_*.tar.gz | head -n 1)
        filedata=$(echo ${infodata} | awk '{print $NF}')
        filedata=$(basename ${filedata})
    fi
    cat <<EOF > job_data_idris_$$
#!/bin/ksh
cd SAXO_DIR
#
rm -rf DATA
echo "iii : you will be asked ${lgforge}@forge.ipsl.jussieu.fr passwd"
scp ${lgforge}@forge.ipsl.jussieu.fr:/ipsl/forge/projets/saxo/download/${filedata} .
gunzip ${filedata}
tar vxf $( basename ${filedata} .gz )
rm -f $( basename ${filedata} .gz )
#
chmod -R 755 *
exit
#
EOF
    # update data on gaya
    echo "iii : update data to gaya"
    scp job_data_idris_$$ reee217@gaya.idris.fr:.
    ssh reee217@gaya.idris.fr "chmod 755 job_data_idris_$$ ; ./job_data_idris_$$ ; rm -f job_data_idris_$$"
fi
#------------------------------------------------------------------
if [ ${dodocdownload} -eq 1 ]
then
    echo "iii : you will be asked ${lgforge}@forge.ipsl.jussieu.fr passwd several times"
    #
    # copy files in a temporary directory
    mkdir /tmp/download_${$}/
    cp -rp ../xmldoc /tmp/download_${$}/
    cp -rp ../idldoc_html_output /tmp/download_${$}/
    #
    # remove tools files
    find /tmp/download_${$}/ -name ".svn" -exec rm -rf {} \; 2> /dev/null
    find /tmp/download_${$}/ -name "*.xml" -exec rm -rf {} \; 2> /dev/null
    find /tmp/download_${$}/ -name "*.xsl" -exec rm -rf {} \; 2> /dev/null
    find /tmp/download_${$}/ -name "*.sed" -exec rm -rf {} \; 2> /dev/null
    find /tmp/download_${$}/ -name "*.sh" -exec rm -rf {} \; 2> /dev/null
    find /tmp/download_${$}/ -name "makefile" -exec rm -rf {} \; 2> /dev/null
    find /tmp/download_${$}/ -name "*~" -exec rm -rf {} \; 2> /dev/null
    #
    # replace relative path
    # by http://forge.ipsl.jussieu.fr/saxo/browser/trunk/SRC/
    # on ulink lines containing some directories like ../../ToBeReviewed/ or ../../Tests/ or file like newheader.txt
    list_html=$(find /tmp/download_${$}/ -name "*.html")
    for file_html in ${list_html}
    do
        sed \
        -e "/Source code of a file/s+../.*/../+http://forge.ipsl.jussieu.fr/saxo/browser/trunk/SRC+g" \
        -e "/..\/..\/ToBeReviewed/s+../../+http://forge.ipsl.jussieu.fr/saxo/browser/trunk/SRC/+g" \
        -e "/..\/..\/Tests/s+../../+http://forge.ipsl.jussieu.fr/saxo/browser/trunk/SRC/+g"  \
        -e "/..\/..\/Calendar/s+../../+http://forge.ipsl.jussieu.fr/saxo/browser/trunk/SRC/+g" \
        -e "/..\/newheader/s+../../+http://forge.ipsl.jussieu.fr/saxo/browser/trunk/SRC/Documentation/+g" \
        ${file_html} > ${file_html}_${$}
        mv ${file_html}_${$} ${file_html}
    done
    echo
    echo "give SAXO password if asked"
    scp -rp /tmp/download_${$}/* saxo@forge.ipsl.jussieu.fr:/ipsl/forge/projets/saxo/download/
    rm -rf /tmp/download_${$}/
fi
#
# update wiki pages
if [ ${dowikiupdate} -eq 1 ]
then
    # uncomment this following line if you want to start from scratch
    # ssh saxo@forge.ipsl.jussieu.fr mkdir -p /tmp/saxo
    rsync -av --exclude=".DS_Store" --exclude=".svn" ./wiki/ saxo@forge.ipsl.jussieu.fr:/tmp/saxo
    ssh saxo@forge.ipsl.jussieu.fr trac-admin /ipsl/forge/projets/saxo/trac wiki load /tmp/saxo
    # uncomment this following line if you want to leave without any trace
    # ssh saxo@forge.ipsl.jussieu.fr rm -rf /tmp/saxo
fi
#------------------------------------------------------------------
#------------------------------------------------------------------
#
[ -f job_src_$$ ] && rm -f job_src_$$
[ -f job_data_$$ ] && rm -f job_data_$$
[ -f job_data_idris_$$ ] && rm -f job_data_idris_$$
#
exit
