Changeset 4849


Ignore:
Timestamp:
Mar 18, 2024, 5:53:12 PM (7 weeks ago)
Author:
abarral
Message:
 
File:
1 copied

Legend:

Unmodified
Added
Removed
  • BOL/script_install_new

    r4848 r4849  
    11#!/bin/bash
    2 
    3 #set -vx
     2set -eu  # error on command failure, and on unset variables
     3export LC_ALL=C  # standardize awk format
    44
    55###########################################################################
     
    3636###########################################################################
    3737
    38 echo install_lmdz.sh DEBUT `date`
    39 set -e
     38echo install_lmdz.sh DEBUT "$(date)"
    4039
    4140################################################################
     
    4847function myget { #1st and only argument should be file name
    4948    # Path on local computer where to look for the datafile
    50     if [ -f /u/lmdz/WWW/LMDZ/pub/$1 ] ; then
    51         \cp -f -p /u/lmdz/WWW/LMDZ/pub/$1 .
    52     elif [ -f ~/LMDZ/pub/$1 ] ; then
    53         \cp -f -p ~/LMDZ/pub/$1 .
     49    if [[ -f /u/lmdz/WWW/LMDZ/pub/$1 ]]; then
     50        \cp -f -p "/u/lmdz/WWW/LMDZ/pub/$1" .
     51    elif [[ -f ~/LMDZ/pub/$1 ]]; then
     52        \cp -f -p ~"/LMDZ/pub/$1" .
    5453    else
    55         wget --no-check-certificate -nv http://lmdz.lmd.jussieu.fr/pub/$1
     54        wget --no-check-certificate -nv "http://lmdz.lmd.jussieu.fr/pub/$1"
    5655        save_pub_locally=0
    57         if [ $save_pub_locally = 1 ] ; then # saving wget files on ~/LMDZ/pub
    58             dir=~/LMDZ/pub/`dirname $1` ; mkdir -p $dir
    59             cp -r `basename $1` $dir
     56        if [[ $save_pub_locally = 1 ]]; then # saving wget files on ~/LMDZ/pub
     57            dir=~"/LMDZ/pub/$(dirname "$1")"; mkdir -p "$dir"
     58            cp -r "$(basename "$1")" "$dir"
    6059        fi
    6160    fi
     
    6362
    6463# 04_2021 : tester si r4 marche encore !
    65 #real=r4
    66 real=r8
     64real="r8"  # ou "r4"
    6765
    6866
     
    7169#########################################################################
    7270svn=""
    73 #version=trunk
    74 version=20231022.trunk
     71version="20231022.trunk"
    7572
    7673getlmdzor=1
     
    8380pclinux=1
    8481pcmac=0 # default: not on a Mac
    85 compiler=gfortran
    86 if [ `gfortran -dumpversion | cut -d. -f1` -ge 10 ] ; then allow_arg_mismatch="-fallow-argument-mismatch" ; fi
     82compiler="gfortran"
     83if [[ $(gfortran -dumpversion | cut -d. -f1) -ge 10 ]]; then allow_arg_mismatch="-fallow-argument-mismatch"; fi
    8784SCM=0
    8885# surface/vegetation scheme treatment
     
    9188# - CMIP6: orchidee version used in CMIP exercise, rev 5661
    9289# - number: orchidee version number
    93 veget=NONE
     90veget="NONE"
    9491# choose the resolution for the bench runs
    9592# grid_resolution= 32x24x11 or 48x36x19 for tests (test without ORCHIDEE)
    9693#                  96x71x19  standard configuration
    97 grid_resolution=144x142x79
    98 grid_resolution=96x95x39
    99 grid_resolution=48x36x19
    100 grid_resolution=32x32x39
     94grid_resolution="144x142x79"
     95grid_resolution="96x95x39"
     96grid_resolution="48x36x19"
     97grid_resolution="32x32x39"
    10198# choose the physiq version you want to test
    10299#physiq=NPv6.0.14splith
    103 physiq=
     100physiq=""
    104101
    105102## parallel can take the values none/mpi/omp/mpi_omp
    106 parallel=mpi_omp
    107 parallel=none
    108 idris_acct=lmd
    109 trusting=testing
     103parallel="mpi_omp"
     104parallel="none"
     105idris_acct="lmd"
     106trusting="testing"
    110107OPT_GPROF=""
    111108OPT_MAKELMDZ=""
     
    117114
    118115## compile with oldrad/rrtm/ecrad radiatif code (Default=rrtm)
    119 rad=rrtm
     116rad="rrtm"
    120117
    121118## compile_with_fcm=1 : use makelmdz_fcm (1) or makelmdz (0)
    122119compile_with_fcm=1
    123120
    124 #Compilation with Cosp (cosp=NONE/v1/v2 ; default=NONE)
    125 cosp=NONE
     121#Compilation with Cosp (cosp=NONE/v1/v2; default=NONE)
     122cosp="NONE"
    126123opt_cosp=""
    127124
    128125# Check if on a Mac
    129 if [ `uname` = "Darwin" ]
    130 then
     126if [[ $(uname) = "Darwin" ]]; then
    131127    pcmac=1
    132128    export MAKE=make
    133129fi
    134 #echo "pcmac="$pcmac
    135130
    136131env_file=""
     132optim=""
    137133
    138134#########################################################################
     
    197193
    198194........fin
    199               exit ;;
    200         "-v") version=$2 ; shift ; shift ;;
    201         "-r") svn=$2 ; shift ; shift ;;
     195              exit 1;;
     196        "-v") version=$2; shift; shift;;
     197        "-r") svn=$2; shift; shift;;
    202198        "-compiler") compiler=$2
    203199                     case $compiler in
    204                          "gfortran"|"ifort"|"pgf90") compiler=$2 ; shift
    205                                                      shift ;;
     200                         "gfortran"|"ifort"|"pgf90") compiler=$2; shift
     201                                                     shift;;
    206202                         *) echo "Only gfortran , ifort or pgf90 for the " \
    207203                                 "compiler option"
    208                             exit
    209                      esac ;;
    210         "-d") grid_resolution=$2 ; shift ; shift ;;
    211         "-gprof") OPT_GPROF="-pg" ; shift ;;
    212         "-unstable"|"-testing") trusting=`echo $1 | cut -c2-`  ; shift ;;
     204                            exit 1
     205                     esac;;
     206        "-d") grid_resolution=$2; shift; shift;;
     207        "-gprof") OPT_GPROF="-pg"; shift;;
     208        "-unstable"|"-testing") trusting=$(echo "$1" | cut -c2-) ; shift;;
    213209        "-cosp") cosp=$2
    214210                 case $cosp in
    215                      "none"|"v1"|"v2") cosp=$2 ; shift ; shift ;;
    216                      *) echo Only none v1 v2 for cosp option ; exit
    217                  esac ;;
    218         "-nofcm") compile_with_fcm=0 ; echo This option will be reactivated soon '(promesse du 8dec2022)' ; exit 1 ;  shift ;;
    219         "-SCM") SCM=1 ; shift ;;
    220         "-opt_makelmdz") OPT_MAKELMDZ="$2" ; shift ; shift ;;
    221         "-rrtm") rrtm="$2"
    222                  if [ "$2" = "false" ] ; then
     211                     "none"|"v1"|"v2") cosp=$2; shift; shift;;
     212                     *) echo Only none v1 v2 for cosp option; exit 1
     213                 esac;;
     214        "-nofcm") compile_with_fcm=0; echo This option will be reactivated soon '(promesse du 8dec2022)'; exit 1;  shift;;
     215        "-SCM") SCM=1; shift;;
     216        "-opt_makelmdz") OPT_MAKELMDZ="$2"; shift; shift;;
     217        "-rrtm") if [[ $2 = "false" ]]; then
    223218                     rad="oldrad"
    224219                 else
    225220                     rad="rrtm"
    226221                 fi
    227                  shift ; shift ;;
     222                 shift; shift;;
    228223        "-rad") rad=$2
    229224                case $rad in
    230                     "oldrad"|"rrtm"|"ecrad") rad=$2 ; shift ; shift ;;
    231                     *) echo Only oldrad rrtm ecrad for rad option ; exit
    232                 esac ;;
     225                    "oldrad"|"rrtm"|"ecrad") rad=$2; shift; shift;;
     226                    *) echo "Only oldrad rrtm ecrad for rad option"; exit 1
     227                esac;;
    233228        "-parallel") parallel=$2
    234229                     case $parallel in
    235                          "none"|"mpi"|"omp"|"mpi_omp") parallel=$2 ; shift
    236                                                        shift ;;
    237                          *) echo Only none mpi omp mpi_omp for the parallel \
    238                                  option
    239                             exit
    240                      esac ;;
    241         "-bench") bench=$2 ; shift ; shift ;;
    242         "-debug") optim=-debug ; shift ;;
    243         "-name") MODEL=$2 ; shift ; shift ;;
    244         "-netcdf") netcdf=$2 ; shift ; shift ;;
    245         "-physiq") physiq=$2 ; shift ; shift ;;
    246         "-xios") with_xios="y" ; shift ;;
    247         "-env_file") env_file=$2 ; shift ; shift ;;
    248         "-veget") veget=$2 ; shift ; shift ;;
    249         *)  bash install_lmdz.sh -h ; exit
     230                         "none"|"mpi"|"omp"|"mpi_omp") parallel=$2; shift
     231                                                       shift;;
     232                         *) echo "Only none mpi omp mpi_omp for the parallel option"
     233                            exit 1
     234                     esac;;
     235        "-bench") bench=$2; shift; shift;;
     236        "-debug") optim=-debug; shift;;
     237        "-name") MODEL=$2; shift; shift;;
     238        "-netcdf") netcdf=$2; shift; shift;;
     239        "-physiq") physiq=$2; shift; shift;;
     240        "-xios") with_xios="y"; shift;;
     241        "-env_file") env_file=$2; shift; shift;;
     242        "-veget") veget=$2; shift; shift;;
     243        *)  bash install_lmdz.sh -h; exit 1
    250244    esac
    251245done
     
    256250#opt_rad=""
    257251#case $rad in
    258 #   rrtm) opt_rad="-rad rrtm" ;;
    259 #   ecrad) opt_rad="-rad ecrad" ;;
     252#   rrtm) opt_rad="-rad rrtm";;
     253#   ecrad) opt_rad="-rad ecrad";;
    260254#esac
    261255
     
    264258opt_cosp=""
    265259case $cosp in
    266     v1) opt_cosp="-cosp true" ;;
    267     v2) opt_cosp="-cospv2 true" ;;
     260    v1) opt_cosp="-cosp true";;
     261    v2) opt_cosp="-cospv2 true";;
    268262esac
    269263
    270264# Check on veget version
    271 #if [ "$veget" != 'NONE'  -a "$veget" != "CMIP6" -a "$veget" != +([0-9]) ] ; then
    272 if [ $veget != 'NONE'   -a $veget != "CMIP6" ] ; then
     265if [[ $veget != 'NONE' && $veget != "CMIP6" ]]; then
    273266    re='^[0-9]+$'
    274     if ! [[ $veget =~ $re ]] ; then
     267    if ! [[ $veget =~ $re ]]; then
    275268        echo 'Valeur de l option veget non valable'
    276         exit
     269        exit 1
    277270    fi
    278271fi
    279272
    280273#Define veget-related suffix for gcm name
    281 if [ "$veget" = 'NONE' ] ; then
     274if [[ $veget = 'NONE' ]]; then
    282275    suff_orc=''
    283276    #For use with tutorial, orchidee_rev is also defined (will be
     
    289282
    290283
    291 if [ $parallel = none ] ; then
     284if [[ $parallel = none ]]; then
    292285    sequential=1; suff_exe='_seq'
    293286else
     
    296289
    297290#Chemin pour placer le modele
    298 if [ "$MODEL" = "" ] ; then MODEL=./LMDZ$version$svn$optim ; fi
     291if [[ $MODEL = "" ]]; then MODEL=./LMDZ$version$svn$optim; fi
    299292
    300293
     
    302295
    303296
    304 if [ $compiler = g95 ] ; then echo g95 is not supported anymore ; exit ; fi
     297if [[ $compiler = g95 ]]; then echo g95 is not supported anymore; exit 1; fi
    305298
    306299################################################################
     
    308301################################################################
    309302
    310 hostname=`hostname`
    311 if [ "$pclinux" = 1 ] ; then o_ins_make="-t g95" ; else o_ins_make="" ; fi
     303hostname=$(hostname)
     304if [[ $pclinux = 1 ]]; then o_ins_make="-t g95"; else o_ins_make=""; fi
    312305
    313306case ${hostname:0:5} in
    314307
    315     jean-)   compiler="mpiifort" ;
    316              par_comp="mpiifort" ;
    317              o_ins_make="-t jeanzay" ;
    318              make=gmake ;
     308    jean-)   compiler="mpiifort";
     309             par_comp="mpiifort";
     310             o_ins_make="-t jeanzay";
     311             make=gmake;
    319312             module purge
    320              module load intel-compilers/19.0.4 ;
    321              #module load intel-mpi/19.0.4 ;
    322              #module load intel-mkl/19.0.4 ;
    323              module load hdf5/1.10.5-mpi ;
    324              module load netcdf/4.7.2-mpi ;
    325              module load netcdf-fortran/4.5.2-mpi ;
    326              module load subversion/1.9.7 ;
     313             module load intel-compilers/19.0.4;
     314             #module load intel-mpi/19.0.4;
     315             #module load intel-mkl/19.0.4;
     316             module load hdf5/1.10.5-mpi;
     317             module load netcdf/4.7.2-mpi;
     318             module load netcdf-fortran/4.5.2-mpi;
     319             module load subversion/1.9.7;
    327320             module load cmake
    328321             export NETCDF_LIBDIR=./
    329322             export NETCDFFORTRAN_INCDIR=./
    330323             export NETCDFFORTRAN_LIBDIR=./
    331              arch=X64_JEANZAY ;;
    332 
    333     cicla|camel)   compiler="gfortran" ;
     324             arch=X64_JEANZAY;;
     325
     326    cicla|camel)   compiler="gfortran";
    334327                   module purge
    335328                   module load gnu/10.2.0
     
    341334                   module load svn/1.14.0
    342335
    343                    if [ $parallel != none ] ; then
     336                   if [[ $parallel != none ]]; then
    344337                       root_mpi=/net/nfs/tools/meso-sl6/openmpi/4.0.5-gcc-10.2.0
    345                        path_mpi=$root_mpi/bin ;
    346                        par_comp=${path_mpi}/mpif90 ;
    347                        mpirun=${path_mpi}/mpirun ;
    348                    fi ;
    349                    arch=local ;
    350                    make=make ;
    351                    o_ins_make="-t g95" ;;
    352 
    353     *)       if [ $parallel = none -o -f /usr/bin/mpif90 ] ; then
    354                  path_mpi=`which mpif90 | sed -e s:/mpif90::` ;
    355                  if [ -d /usr/lib64/openmpi ] ; then
     338                       path_mpi=$root_mpi/bin;
     339                       par_comp=${path_mpi}/mpif90;
     340                       mpirun=${path_mpi}/mpirun;
     341                   fi;
     342                   arch="local" ;
     343                   make="make";
     344                   o_ins_make="-t g95";;
     345
     346    *)       if [[ $parallel = none || -f /usr/bin/mpif90 ]]; then
     347                 path_mpi=$(which mpif90 | sed -e s:/mpif90::);
     348                 if [[ -d /usr/lib64/openmpi ]]; then
    356349                     root_mpi="/usr/lib64/openmpi"
    357350                 else
     
    359352                 fi
    360353             else
    361                  echo "Cannot find mpif90" ;
    362                  if [ $parallel = none ] ; then exit ; fi ;
    363              fi ;
    364              if [ $parallel != none ] ; then
     354                 echo "Cannot find mpif90";
     355                 if [[ $parallel = none ]]; then exit 1; fi;
     356             fi;
     357             if [[ $parallel != none ]]; then
    365358                 root_mpi=$(which mpif90 | sed -e s:/bin/mpif90::)
    366359                 path_mpi=$(which mpif90 | sed -e s:/mpif90::)
    367360                 export LD_LIBRARY_PATH=${root_mpi}/lib:$LD_LIBRARY_PATH
    368361             fi
    369              par_comp=${path_mpi}/mpif90 ;
    370              mpirun=${path_mpi}/mpirun ;
    371              arch=local ;
    372              make=make ;
     362             par_comp=${path_mpi}/mpif90;
     363             mpirun=${path_mpi}/mpirun;
     364             arch="local" ;
     365             make="make";
    373366             o_ins_make="-t g95"
    374367esac
    375368
    376369# Flags for parallelism:
    377 if [ $parallel != none ] ; then
     370if [[ $parallel != none ]]; then
    378371    # MPI_LD are the flags needed for linking with MPI
    379372    MPI_LD="-L${root_mpi}/lib -lmpi"
    380     if [ "$compiler" = "gfortran" ] ; then
     373    if [[ "$compiler" = "gfortran" ]]; then
    381374        # MPI_FLAGS are the flags needed for compilation with MPI
    382375        MPI_FLAGS="-fcray-pointer"
     
    385378        # OMP_LD are the flags needed for linking with OpenMP
    386379        OMP_LD="-fopenmp"
    387     elif [ "$compiler" = "ifort" ] ; then
     380    elif [[ "$compiler" = "ifort" ]]; then
    388381        MPI_FLAGS=""
    389382        OMP_FLAGS="-openmp"
     
    404397#####################################################################
    405398
    406 if [ "$compiler" = "gfortran" ] ; then
     399if [[ "$compiler" = "gfortran" ]]; then
    407400    gfortran=gfortran
    408     gfortranv=`gfortran --version | \
    409    head -1 | awk ' { print $NF } ' | awk -F. ' { print $1 * 10 + $2 } '`
    410     if [ $gfortranv -le 43 ] ; then
    411         echo ERROR : Your gfortran compiler is too old
    412         echo 'Please choose a new one (ifort) and change the line'
    413         echo compiler=xxx
    414         echo in the install_lmdz.sh script and rerun it
    415         if [ `which gfortran44 | wc -w` -ne 0 ] ; then
     401    gfortranv=$(gfortran --version | \
     402   head -1 | awk ' { print $NF } ' | awk -F. ' { print $1 * 10 + $2 } ')
     403    if [[ $gfortranv -le 43 ]]; then
     404        \cat <<EOF
     405ERROR : Your gfortran compiler is too old
     406Please choose a new one (ifort) and change the line
     407compiler=xxx
     408in the install_lmdz.sh script and rerun it
     409EOF
     410        if [[ $(which gfortran44 | wc -w) -ne 0 ]]; then
    416411            gfortran=gfortran44
    417412        else
    418             echo gfotran trop vieux ; exit
     413            echo gfotran trop vieux; exit 1
    419414        fi
    420415    fi
     
    424419
    425420## if also compiling XIOS, parallel must be mpi_omp
    426 if [ "$with_xios" = "y" -a "$parallel" != "mpi_omp" ] ; then
     421if [[ "$with_xios" = "y" && "$parallel" != "mpi_omp" ]]; then
    427422    echo "Error, you must set -parallel mpi_omp if you want XIOS"
    428     exit
    429 fi
    430 
    431 if [ "$with_xios" = "y" ] ; then
     423    exit 1
     424fi
     425
     426if [[ "$with_xios" = "y" ]]; then
    432427    opt_makelmdz_xios="-io xios"
    433428fi
    434429
    435 if [ "$cosp" = "v2" -a "$with_xios" = "n" ] ; then
     430if [[ "$cosp" = "v2" && "$with_xios" = "n" ]]; then
    436431    echo "Error, Cospv2 cannot run without Xios"
    437     exit
     432    exit 1
    438433fi
    439434
     
    446441export F77=$compiler
    447442export CPPFLAGS=
    448 OPTIMNC=$OPTIM
     443OPTIMNC=""
    449444BASE_LD="$OPT_GPROF"
    450445OPTPREC="$OPT_GPROF"
    451446ARFLAGS="rs"
    452 if [ "`lsb_release -i -s`" = "Ubuntu" ] ; then
    453     if [ "`lsb_release -r -s | cut -d. -f1`" -ge 16 ] ; then
     447if [[ "$(lsb_release -i -s)" = "Ubuntu" ]]; then
     448    if [[ "$(lsb_release -r -s | cut -d. -f1)" -ge 16 ]]; then
    454449            ARFLAGS="rU"
    455450    fi
    456451fi
    457452
    458 if [ "$compiler" = "$gfortran" ] ; then
     453if [[ "$compiler" = "$gfortran" ]]; then
    459454   OPTIM="-O3 $allow_arg_mismatch"
    460455   OPTDEB="-g3 -Wall -fbounds-check -ffpe-trap=invalid,zero,overflow -O0 -fstack-protector-all -fbacktrace -finit-real=snan  $allow_arg_mismatch"
     
    462457   fmod='I '
    463458   OPTPREC="$OPTPREC -cpp -ffree-line-length-0"
    464    if [ $real = r8 ] ; then OPTPREC="$OPTPREC -fdefault-real-8 -DNC_DOUBLE" ; fi
     459   if [[ $real = r8 ]]; then OPTPREC="$OPTPREC -fdefault-real-8 -DNC_DOUBLE"; fi
    465460   export F90FLAGS=" -ffree-form $OPTIMNC"
    466461   export FFLAGS=" $OPTIMNC"
     
    469464   export fpp_flags="-P -C -traditional -ffreestanding"
    470465
    471 elif [ $compiler = mpif90 ] ; then
     466elif [[ $compiler = mpif90 ]]; then
    472467    OPTIM='-O3'
    473468    OPTDEB="-g3 -Wall -fbounds-check -ffpe-trap=invalid,zero,overflow -O0 -fstack-protector-all"
     
    475470    BASE_LD="$BASE_LD -lblas"
    476471    fmod='I '
    477     if [ $real = r8 ] ; then
     472    if [[ $real = r8 ]]; then
    478473        OPTPREC="$OPTPREC -fdefault-real-8 -DNC_DOUBLE -fcray-pointer"
    479474    fi
     
    483478    export CXX=g++
    484479
    485 elif [ $compiler = pgf90 ] ; then
     480elif [[ $compiler = pgf90 ]]; then
    486481    OPTIM='-O2 -Mipa -Munroll -Mnoframe -Mautoinline -Mcache_align'
    487482    OPTDEB='-g -Mdclchk -Mbounds -Mchkfpstk -Mchkptr -Minform=inform -Mstandard -Ktrap=fp -traceback'
    488483    OPTDEV='-g -Mbounds -Ktrap=fp -traceback'
    489484    fmod='module '
    490     if [ $real = r8 ] ; then OPTPREC="$OPTPREC -r8 -DNC_DOUBLE" ; fi
     485    if [[ $real = r8 ]]; then OPTPREC="$OPTPREC -r8 -DNC_DOUBLE"; fi
    491486    export CPPFLAGS="-DpgiFortran"
    492487    export CC=pgcc
     
    498493    compile_with_fcm=1
    499494
    500 elif [[ $compiler = ifort || $compiler = mpiifort ]] ; then
     495elif [[ $compiler = ifort || $compiler = mpiifort ]]; then
    501496    OPTIM="-O2 -fp-model strict -ip -align all "
    502497    OPTDEV="-p -g -O2 -traceback -fp-stack-check -ftrapuv -check"
    503498    OPTDEB="-g -no-ftz -traceback -ftrapuv -fp-stack-check -check"
    504499    fmod='module '
    505     if [ $real = r8 ] ; then OPTPREC="$OPTPREC -real-size 64 -DNC_DOUBLE" ; fi
     500    if [[ $real = r8 ]]; then OPTPREC="$OPTPREC -real-size 64 -DNC_DOUBLE"; fi
    506501    export CPP="icc -E"
    507502    export FFLAGS="-O2 -ip -fpic -mcmodel=large"
     
    515510    #compile_with_fcm=1
    516511else
    517     echo unexpected compiler $compiler ; exit
     512    echo "unexpected compiler $compiler"; exit 1
    518513fi
    519514
    520515OPTIMGCM="$OPTIM $OPTPREC"
    521516
    522 hostname=`hostname`
     517hostname=$(hostname)
    523518
    524519##########################################################################
    525520# If installing on known machines such as Jean-Zay at IDRIS,
    526521# don't check for available software and don't install netcdf
    527 if [ ${hostname:0:5} = jean- ] ; then
     522if [[ ${hostname:0:5} = jean- ]]; then
    528523    netcdf=0 # no need to recompile netcdf, alreday available
    529524    check_linux=0
     
    533528    compiler="mpiifort"
    534529    fmod='module '
    535     if [ $real = r8 ] ; then OPTPREC="$OPTPREC -i4 -r8 -DNC_DOUBLE" ; fi
     530    if [[ $real = r8 ]]; then OPTPREC="$OPTPREC -i4 -r8 -DNC_DOUBLE"; fi
    536531    OPTIM="-auto -align all -O2 -fp-model strict -xHost "
    537532    OPTIMGCM="$OPTIM $OPTPREC"
     
    540535
    541536
    542 mkdir -p $MODEL
    543 echo $MODEL
    544 MODEL=`( cd $MODEL ; pwd )` # to get absolute path, if necessary
    545 
    546 
    547 if [ "$check_linux" = 1 ] ; then
    548     echo '################################################################'
    549     echo   Check if required software is available
    550     echo '################################################################'
     537mkdir -p "$MODEL"
     538echo "$MODEL"
     539MODEL=$( cd "$MODEL"; pwd ) # to get absolute path, if necessary
     540
     541
     542if [[ "$check_linux" = 1 ]]; then
     543    echo "################################################################"
     544    echo "Check if required software is available"
     545    echo "################################################################"
    551546
    552547    #### Ehouarn: test if the required shell is available
    553     #### Maj FH-LF-AS 2021-04 : default=bash ; if bash missing, use ksh
     548    #### Maj FH-LF-AS 2021-04 : default=bash; if bash missing, use ksh
    554549    use_shell="bash" # default
    555     if [ "`which bash`" = "" ] ; then
    556         echo "no bash ; we will use ksh"
     550    if [[ $(which bash) = "" ]]; then
     551        echo "no bash; we will use ksh"
    557552        use_shell="ksh"
    558         if [ "`which ksh`" = "" ] ; then
     553        if [[ $(which ksh) = "" ]]; then
    559554            echo "bash (or ksh) needed!! Install it!"
    560             exit
    561         fi
    562     fi
    563 
    564     for logiciel in wget tar gzip make $compiler gcc cmake m4 c++ ; do
    565         if [ "`which $logiciel`" = "" ] ; then
    566             echo You must first install $logiciel on your system
    567             exit
     555            exit 1
     556        fi
     557    fi
     558
     559    for logiciel in wget tar gzip make $compiler gcc cmake m4 c++; do
     560        if [[ $(which $logiciel) = "" ]]; then
     561            echo "You must first install $logiciel on your system"
     562            exit 1
    568563        fi
    569564    done
    570565
    571     if [ $pclinux = 1 ] ; then
    572         cd $MODEL
     566    if [[ $pclinux = 1 ]]; then
     567        cd "$MODEL"
    573568        cat <<eod > tt.f90
    574569print*,'coucou'
    575570end
    576571eod
    577         $compiler tt.f90 -o a.out
     572        $compiler tt.f90 || a.out
    578573        ./a.out >| tt
    579         if [ "`cat tt | sed -e 's/ //g' `" != "coucou" ] ; then
    580             echo problem installing with compiler $compiler ; exit ; fi
     574        if [[ $(< tt sed -e 's/ //g' ) != "coucou" ]]; then
     575            echo "problem installing with compiler $compiler"; exit 1; fi
    581576        \rm tt a.out tt.f90
    582577    fi
     
    584579
    585580###########################################################################
    586 if [ $getlmdzor = 1 -a ! -d $MODEL/modipsl ] ; then
     581if [[ $getlmdzor = 1 && ! -d $MODEL/modipsl ]]; then
    587582###########################################################################
    588    echo '##########################################################'
    589    echo  Download a slightly modified version of  LMDZ
    590    echo '##########################################################'
    591    cd $MODEL
    592    getlog=`pwd`/get.log
    593    echo logfile : $getlog
    594    myget src_archives/$trusting/modipsl.$version.tar.gz >> get.log 2>&1
    595    echo install_lmdz.sh wget_OK `date`
    596    gunzip modipsl.$version.tar.gz >> get.log 2>&1
    597    tar xf modipsl.$version.tar >> get.log 2>&1
    598    \rm modipsl.$version.tar
     583   echo "##########################################################"
     584   echo "Download a slightly modified version of  LMDZ"
     585   echo "##########################################################"
     586   cd "$MODEL"
     587   getlog=$(pwd)/get.log
     588   echo logfile : "$getlog"
     589   myget "src_archives/$trusting/modipsl.$version.tar.gz" >> get.log 2>&1
     590   echo install_lmdz.sh wget_OK "$(date)"
     591   gunzip "modipsl.$version.tar.gz" >> get.log 2>&1
     592   tar xf "modipsl.$version.tar" >> get.log 2>&1
     593   \rm "modipsl.$version.tar"
    599594fi
    600595
     
    603598###########################################################################
    604599
    605 if [ $netcdf = 0 ] ; then
     600if [[ $netcdf = 0 ]]; then
    606601    ncdfdir=/usr
    607602
    608603else
    609     cd $MODEL
     604    cd "$MODEL"
    610605
    611606    case $compiler in
    612       gfortran) opt1="-compiler gnu" ; opt2="-CC gcc -FC gfortran -CXX g++" ;;
    613       ifort)  opt1="-compiler intel" ; opt2="-CC icc -FC ifort -CXX icpc" ;;
    614       pgf90)  opt1="-compiler pgf90" ; opt2="-CC pgcc -FC pgf90 -CXX pgCC" ;;
    615       *)      echo "unexpected compiler $compiler" for netcdf ; exit 1
     607      gfortran) opt1="-compiler gnu"; opt2="-CC gcc -FC gfortran -CXX g++";;
     608      ifort)  opt1="-compiler intel"; opt2="-CC icc -FC ifort -CXX icpc";;
     609      pgf90)  opt1="-compiler pgf90"; opt2="-CC pgcc -FC pgf90 -CXX pgCC";;
     610      *)      echo "unexpected compiler $compiler" for netcdf; exit 1
    616611    esac
    617612
     
    619614        n) script_install_netcdf=install_netcdf4_hdf5_seq.bash
    620615           ncdfdir=netcdf4_hdf5_seq
    621            opt_=$opt1 ;;
     616           opt_=$opt1;;
    622617        y) script_install_netcdf=install_netcdf4_hdf5.bash
    623618           ncdfdir=netcdf4_hdf5
    624            opt_="$opt2 -MPI $root_mpi" ;;
    625         *) echo with_xios=$with_xios, should be n or y ; exit 1
     619           opt_="$opt2 -MPI $root_mpi";;
     620        *) echo with_xios=$with_xios, should be n or y; exit 1
    626621    esac
    627     if [ $netcdf = 1 ] ; then
     622    if [[ $netcdf = 1 ]]; then
    628623       ncdfdir=$MODEL/$ncdfdir
    629624    else
    630        mkdir -p $netcdf ; ncdfdir=$netcdf/$ncdfdir
     625       mkdir -p $netcdf; ncdfdir=$netcdf/$ncdfdir
    631626    fi
    632627         
    633     echo Repertoire netcdf $ncdfdir
    634     if [ ! -d $ncdfdir ] ; then
    635         netcdflog=`pwd`/netcdf.log
    636         echo '----------------------------------------------------------'
    637         echo Compiling the Netcdf library
    638         echo '----------------------------------------------------------'
    639         echo log file : $netcdflog
    640         myget script_install/$script_install_netcdf >> $netcdflog 2>&1
     628    echo "Repertoire netcdf $ncdfdir"
     629    if [[ ! -d $ncdfdir ]]; then
     630        netcdflog=$(pwd)/netcdf.log
     631        echo "----------------------------------------------------------"
     632        echo "Compiling the Netcdf library"
     633        echo "----------------------------------------------------------"
     634        echo "log file : $netcdflog"
     635        myget script_install/$script_install_netcdf >> "$netcdflog" 2>&1
    641636        chmod u=rwx $script_install_netcdf
    642         ./$script_install_netcdf -prefix $ncdfdir $opt_ >> $netcdflog 2>&1
     637        # shellcheck disable=SC2086
     638        ./$script_install_netcdf -prefix "$ncdfdir" $opt_ >> "$netcdflog" 2>&1
    643639    fi
    644640
    645641    #----------------------------------------------------------------------------
    646642    # LF rajout d'une verrue, pour une raison non encore expliquee,
    647     # la librairie est parfois rangée dans lib64 et non dans lib
     643    # la librairie est parfois range dans lib64 et non dans lib
    648644    # par certains compilateurs
    649     if [ ! -e lib -a -d lib64 ] ; then ln -s lib64 lib; fi
     645    if [[ ! -e lib && -d lib64 ]]; then ln -s lib64 lib; fi
    650646    #----------------------------------------------------------------------------
    651647
    652     echo install_lmdz.sh netcdf_OK `date`
     648    echo install_lmdz.sh netcdf_OK "$(date)"
    653649
    654650fi
     
    660656EOF
    661657
    662 $compiler -I$ncdfdir/include test_netcdf90.f90 -L$ncdfdir/lib -lnetcdff \
    663           -lnetcdf -Wl,-rpath=$ncdfdir/lib && ./a.out
    664    
    665 if (($? == 0))
     658if $compiler -I"$ncdfdir"/include test_netcdf90.f90 -L"$ncdfdir"/lib -lnetcdff \
     659          -lnetcdf -Wl,-rpath="$ncdfdir"/lib && ./a.out
    666660then
    667661    rm test_netcdf90.f90 a.out
     
    677671fi
    678672
    679 #=========================================================================
    680673if [[ ! -f $MODEL/modipsl/lib/libioipsl.a ]]
    681674then
    682     if [ $ioipsl = 1 ] ; then
    683         #=====================================================================
    684         echo OK ioipsl=$ioipsl
    685         echo '##########################################################'
    686         echo 'Installing MODIPSL, the installation package manager for the '
    687         echo 'IPSL models and tools'
    688         echo '##########################################################'
    689         echo `date`
    690 
    691         cd $MODEL/modipsl
     675    if [[ $ioipsl = 1 ]]; then
     676        cat <<EOF
     677OK ioipsl=$ioipsl
     678##########################################################
     679Installing MODIPSL, the installation package manager for the
     680IPSL models and tools
     681##########################################################
     682$(date)
     683EOF
     684        cd "$MODEL/modipsl"
    692685        \rm -rf lib/*
    693686        cd util
    694687        cp AA_make.gdef AA_make.orig
    695688        F_C="$compiler -c "
    696         if [ "$compiler" = "$gfortran" -o "$compiler" = "mpif90" ]
     689        if [[ $compiler = "$gfortran" || $compiler = "mpif90" ]]
    697690        then
    698691            F_C="$compiler -c -cpp "
    699692        fi
    700         if [ "$compiler" = "pgf90" ] ; then F_C="$compiler -c -Mpreprocess" ; fi
     693        if [[ "$compiler" = "pgf90" ]]; then F_C="$compiler -c -Mpreprocess"; fi
    701694        sed -e 's/^\#.*.g95.*.\#.*.$/\#/' AA_make.gdef > tmp
    702695        sed -e "s:F_L = g95:F_L = $compiler:" \
     
    710703            tmp >| AA_make.gdef
    711704
    712         if [ $pcmac == 1 ]
     705        if [[ $pcmac == 1 ]]
    713706        then
    714707            cp AA_make.gdef tmp
     
    718711
    719712        # We use lines for g95 even for the other compilers to run ins_make
    720         if [ "$use_shell" = "ksh" ] ; then
    721             ./ins_make $o_ins_make
     713        if [[ "$use_shell" = "ksh" ]]; then
     714            ./ins_make "$o_ins_make"
    722715        else # bash
    723716            sed -e s:/bin/ksh:/bin/bash:g ins_make > ins_make.bash
    724             if [ "`grep jeanzay AA_make.gdef`" = "" ] ; then
     717            if [[ $(grep jeanzay AA_make.gdef) = "" ]]; then
    725718                # Bidouille pour compiler sur ada des vieux modipsl.tar
    726719                echo 'Warning jean-zay not in AA_make.gdef'
     
    730723
    731724            chmod u=rwx ins_make.bash
    732             ./ins_make.bash $o_ins_make
    733         fi # of if [ "$use_shell" = "ksh" ]
    734 
    735         echo install_lmdz.sh MODIPSL_OK `date`
    736 
    737         cd $MODEL/modipsl/modeles/IOIPSL/src
    738         ioipsllog=`pwd`/ioipsl.log
     725            ./ins_make.bash "$o_ins_make"
     726        fi # of if [[ "$use_shell" = "ksh" ]]
     727
     728        echo "install_lmdz.sh MODIPSL_OK $(date)"
     729
     730        cd "$MODEL/modipsl/modeles/IOIPSL/src"
     731        ioipsllog=$(pwd)/ioipsl.log
    739732        echo '##########################################################'
    740733        echo 'Compiling IOIPSL, the interface library with Netcdf'
    741734        echo '##########################################################'
    742         echo `date`
    743         echo log file : $ioipsllog
    744 
    745         if [ "$use_shell" = "bash" ] ; then
     735        echo "log file : $ioipsllog   $(date)"
     736
     737        if [[ "$use_shell" = "bash" ]]; then
    746738            cp Makefile Makefile.ksh
    747739            sed -e s:/bin/ksh:/bin/bash:g Makefile.ksh > Makefile
    748740        fi
    749         ### if [ "$pclinux" = 1 ] ; then
     741        ### if [[ "$pclinux" = 1 ]]; then
    750742        # Build IOIPSL modules and library
    751743        $make clean
    752         $make > $ioipsllog 2>&1
    753         if [ "$compiler" = "$gfortran" -o "$compiler" = "mpif90" ] ; then
     744        $make > "$ioipsllog" 2>&1
     745        if [[ $compiler = "$gfortran" || $compiler = "mpif90" ]]; then
    754746            # copy module files to lib
    755             cp -f *.mod ../../../lib
     747            cp -f -- *.mod ../../../lib
    756748        fi
    757749        # Build IOIPSL tools (ie: "rebuild", if present)
    758           # For IOIPSLv_2_2_2, "rebuild" files are in IOIPSL/tools
    759         rebuild_dir=""
    760         if [ -f $MODEL/modipsl/modeles/IOIPSL/tools/rebuild ] ; then
     750        # For IOIPSLv_2_2_2, "rebuild" files are in IOIPSL/tools
     751        rebuild_dir=""
     752        if [[ -f $MODEL/modipsl/modeles/IOIPSL/tools/rebuild ]]; then
    761753            rebuild_dir=$MODEL/modipsl/modeles/IOIPSL/tools
    762         elif [ -d $MODEL/modipsl/modeles/IOIPSL/rebuild ] ; then
     754        elif [[ -d $MODEL/modipsl/modeles/IOIPSL/rebuild ]]; then
    763755              rebuild_dir=$MODEL/modipsl/modeles/IOIPSL/rebuild
    764756        fi
    765         if [ $rebuild_dir != "" ] ; then
    766             cd $rebuild_dir     
     757        if [[ $rebuild_dir != "" ]]; then
     758            cd "$rebuild_dir"
    767759            # adapt Makefile & rebuild script if in bash
    768             if [ "$use_shell" = "bash" ] ; then
     760            if [[ "$use_shell" = "bash" ]]; then
    769761                cp Makefile Makefile.ksh
    770762                sed -e s:/bin/ksh:/bin/bash:g Makefile.ksh > Makefile
     
    775767            fi
    776768            $make clean
    777             $make > $ioipsllog 2>&1
    778         fi
    779         ### fi # of if [ "$pclinux" = 1 ] which is commented out
    780 
    781     else # of if [ $ioipsl = 1 ]
    782         if [ ${hostname:0:5} = jean- ] ; then
    783             cd $MODEL/modipsl
     769            $make > "$ioipsllog" 2>&1
     770        fi
     771        ### fi # of if [[ "$pclinux" = 1 ]] which is commented out
     772
     773    else # of if [[ $ioipsl = 1 ]]
     774        if [[ ${hostname:0:5} = jean- ]]; then
     775            cd "$MODEL/modipsl"
    784776            cd util
    785             if [ "`grep jeanzay AA_make.gdef`" = "" ] ; then
     777            if [[ $(grep jeanzay AA_make.gdef) = "" ]]; then
    786778                echo 'Warning jean-zay not in AA_make.gdef'
    787779                echo 'Think about updating'
    788780                exit 1
    789781            fi
    790             ./ins_make $o_ins_make
     782            ./ins_make "$o_ins_make"
    791783            # Compile IOIPSL on jean-zay
    792             cd $MODEL/modipsl/modeles/IOIPSL/src
     784            cd "$MODEL/modipsl/modeles/IOIPSL/src"
    793785            gmake > ioipsl.log
    794786            # For IOIPSLv_2_2_2, "rebuild" files are in IOIPSL/tools, so "gmake" in IOIPSL/tools is enough
    795787            # For IOIPSLv_2_2_5, "rebuild" files are in a separate IOIPSL/rebuild folder , while "tools" only contains "FCM"
    796             if [ -f $MODEL/modipsl/modeles/IOIPSL/tools/Makefile ] ; then
    797               cd $MODEL/modipsl/modeles/IOIPSL/tools
     788            if [[ -f $MODEL/modipsl/modeles/IOIPSL/tools/Makefile ]]; then
     789              cd "$MODEL/modipsl/modeles/IOIPSL/tools"
    798790              gmake > ioipsl.log
    799791            fi
    800             if [ -d $MODEL/modipsl/modeles/IOIPSL/rebuild ] ; then
    801               cd $MODEL/modipsl/modeles/IOIPSL/rebuild
     792            if [[ -d $MODEL/modipsl/modeles/IOIPSL/rebuild ]]; then
     793              cd "$MODEL/modipsl/modeles/IOIPSL/rebuild"
    802794              gmake > ioipsl.log
    803795            fi
    804796
    805797        fi
    806         echo install_lmdz.sh ioipsl_OK `date`
    807     fi # of if [ $ioipsl = 1 ]
     798        echo "install_lmdz.sh ioipsl_OK $(date)"
     799    fi # of if [[ $ioipsl = 1 ]]
    808800fi # of if [[ ! -f $MODEL/modipsl/lib/libioipsl.a ]]
    809801
    810802#=========================================================================
    811 if [ "$with_xios" = "y" ] ; then
     803if [[ "$with_xios" = "y" ]]; then
    812804    echo '##########################################################'
    813805    echo 'Compiling XIOS'
    814806    echo '##########################################################'
    815     cd $MODEL/modipsl/modeles
    816     xioslog=`pwd`/xios.log
     807    cd "$MODEL/modipsl/modeles"
     808    xioslog="$(pwd)/xios.log"
    817809    #wget http://www.lmd.jussieu.fr/~lmdz/Distrib/install_xios.bash
    818810    myget script_install/install_xios.bash
    819811    chmod u=rwx install_xios.bash
    820812# following will be recalculated later on once LMDZ is updated
    821 #    mysvn=`svnversion LMDZ | egrep -o "[0-9]+" 2>/dev/null`
    822     mysvn=`grep 'Revision: [0-9]' $MODEL/Read*.md | awk ' { print $2 } ' 2>/dev/null`
    823     if [ "$svn" != "" ] ; then mysvn=$svn ; fi
    824     echo mysvn $mysvn
    825 
    826     if [ ${hostname:0:5} = jean- ] ; then
    827         if [ $mysvn -ge 4619 ] ; then
     813#    mysvn=`svnversion LMDZ | egrep || "[0-9]+" 2>/dev/null`
     814    mysvn=$(grep 'Revision: [0-9]' "$MODEL"/Read*.md | awk ' { print $2 } ' 2>/dev/null)
     815    if [[ $svn != "" ]]; then mysvn=$svn; fi
     816    echo "mysvn $mysvn"
     817
     818    if [[ ${hostname:0:5} = jean- ]]; then
     819        if [[ $mysvn -ge 4619 ]]; then
    828820          svn co http://forge.ipsl.jussieu.fr/ioserver/svn/XIOS2/branches/xios-2.6 \
    829821            XIOS
     
    835827        svn update
    836828        cd ..
    837         echo "Compiling XIOS, start" `date` \
    838              "(it takes about 20 min on Jean-Zay)"
     829        echo "Compiling XIOS, start $(date) (it takes about 20 min on Jean-Zay)"
    839830        echo "log file: $xioslog"
    840831        ./make_xios --prod --arch $arch --job 4 > xios.log 2>&1
    841832    else
    842         ./install_xios.bash -prefix $MODEL/modipsl/modeles \
    843                             -netcdf ${ncdfdir} -hdf5 ${ncdfdir} \
    844                             -MPI $root_mpi -arch $arch > xios.log 2>&1
     833        ./install_xios.bash -prefix "$MODEL/modipsl/modeles" \
     834                            -netcdf "$ncdfdir" -hdf5 "$ncdfdir" \
     835                            -MPI "$root_mpi" -arch $arch > xios.log 2>&1
    845836    fi # of case Jean-Zay
    846     if [ -f XIOS/lib/libxios.a ] ; then
     837    if [[ -f XIOS/lib/libxios.a ]]; then
    847838        echo "XIOS library successfully generated"
    848         echo install_lmdz.sh XIOS_OK `date`
     839        echo install_lmdz.sh XIOS_OK "$(date)"
    849840    fi
    850841fi
     
    852843#============================================================================
    853844veget_version=false
    854 if [ "$veget" != 'NONE' ] ; then
    855     cd $MODEL/modipsl/modeles/ORCHIDEE
    856     set +e ; svn upgrade ; set -e
    857     if [ "$veget" = "CMIP6" ] ; then
     845if [[ "$veget" != 'NONE' ]]; then
     846    cd "$MODEL/modipsl/modeles/ORCHIDEE"
     847    set +e; svn upgrade; set -e
     848    if [[ "$veget" = "CMIP6" ]]; then
    858849        veget_version=orchidee2.0
    859850        orchidee_rev=6592
     
    861852        veget_version=orchidee2.1
    862853        orchidee_rev=$veget
    863         if [ $veget -lt 4465 ] ; then
     854        if [[ $veget -lt 4465 ]]; then
    864855            echo 'Stopping, ORCHIDEE version too old, script needs work on ' \
    865856                 'the CPP flags to pass to makelmdz'
     
    868859        set +e
    869860        # which branch is my version on?
    870         orcbranch=`svn log -v -q svn://forge.ipsl.jussieu.fr/orchidee/ -r $veget |grep ORCHIDEE |head -1| sed -e 's:ORCHIDEE/.*$:ORCHIDEE:' | awk '{print $2}'`
     861        orcbranch=$(svn log -v -q svn://forge.ipsl.jussieu.fr/orchidee/ -r "$veget" |grep ORCHIDEE |head -1| sed -e 's:ORCHIDEE/.*$:ORCHIDEE:' | awk '{print $2}')
    871862        # switch to that branch
    872863        echo IF YOU INSTALL ORCHIDEE THE VERY FIRST TIME, ASK for PASSWORD at \
    873864             orchidee-help@listes.ipsl.fr
    874         svn switch -r $veget --accept theirs-full \
    875             svn://forge.ipsl.jussieu.fr/orchidee/$orcbranch
    876         svn log -r $veget | grep  $veget
    877         if [  $? -gt 0 ] ; then
    878             echo 'Cannot update ORCHIDEE as not on the right branch for ' \
    879                  'ORCHIDEE'
    880             exit
     865        svn switch -r "$veget" --accept theirs-full "svn://forge.ipsl.jussieu.fr/orchidee/$orcbranch"
     866        if ! (svn log -r "$veget" | grep "$veget"); then
     867            echo 'Cannot update ORCHIDEE as not on the right branch for ORCHIDEE'
     868            exit 1
    881869        fi
    882870        set -e
    883         set +e ; svn update -r $veget ; set -e
     871        set +e; svn update -r "$veget"; set -e
    884872    fi
    885873    # Correctif suite debug Jean-Zay
    886874    sed -i -e 's/9010  FORMAT(A52,F17.14)/9010  FORMAT(A52,F20.14)/' \
    887875        src_stomate/stomate.f90
    888     opt_orc="-prod" ; if [ "$optim" = "-debug" ] ; then opt_orc="-debug" ; fi
    889 
    890     orchideelog=`pwd`/orchidee.log
     876    opt_orc="-prod"; if [[ "$optim" = "-debug" ]]; then opt_orc="-debug"; fi
     877
     878    orchideelog=$(pwd)/orchidee.log
    891879    echo '########################################################'
    892880    echo 'Compiling ORCHIDEE, the continental surface model '
    893881    echo '########################################################'
    894     echo Start of the first compilation of orchidee, in sequential mode: `date`
    895     echo log file : $orchideelog
    896 
    897     export ORCHPATH=`pwd`
     882    echo "Start of the first compilation of orchidee, in sequential mode: $(date)"
     883    echo "log file : $orchideelog"
     884
     885    ORCHPATH=$(pwd)
     886    export ORCHPATH=$ORCHPATH
    898887    xios_orchid="-noxios"
    899     if [ "$with_xios" = "y" ] ; then
     888    if [[ "$with_xios" = "y" ]]; then
    900889        xios_orchid="-xios"
    901890    fi
    902     if [ -d tools ] ; then
     891    if [[ -d tools ]]; then
    903892        ###################################################################
    904893        # Pour les experts qui voudraient changer de version d'orchidee.
     
    906895
    907896        # Correctif suite debug Jean-Zay
    908         if [ -f src_global/time.f90 ] ; then
     897        if [[ -f src_global/time.f90 ]]; then
    909898            sed -i -e 's/CALL tlen2itau/\!CALL tlen2itau/' src_global/time.f90
    910899        fi
    911900        ###################################################################
    912         if [ "$veget_version" == "false" ] ; then
     901        if [[ "$veget_version" == "false" ]]; then
    913902            veget_version=orchidee2.0
    914903        fi
    915904        cd arch
    916         sed -e s:"%COMPILER        .*.$":"%COMPILER            $compiler":1 \
    917             -e s:"%LINK            .*.$":"%LINK                $compiler":1 \
    918             -e s:"%FPP_FLAGS       .*.$":"%FPP_FLAGS           $fpp_flags":1 \
    919             -e s:"%PROD_FFLAGS     .*.$":"%PROD_FFLAGS         $OPTIM":1 \
    920             -e s:"%DEV_FFLAGS      .*.$":"%DEV_FFLAGS          $OPTDEV":1 \
    921             -e s:"%DEBUG_FFLAGS    .*.$":"%DEBUG_FFLAGS        $OPTDEB":1 \
    922             -e s:"%BASE_FFLAGS     .*.$":"%BASE_FFLAGS         $OPTPREC":1 \
    923             -e s:"%BASE_LD         .*.$":"%BASE_LD             $BASE_LD":1 \
    924             -e s:"%ARFLAGS         .*.$":"%ARFLAGS             $ARFLAGS":1 \
     905        sed -e s:"%COMPILER        .*.$:%COMPILER            $compiler":1 \
     906            -e s:"%LINK            .*.$:%LINK                $compiler":1 \
     907            -e s:"%FPP_FLAGS       .*.$:%FPP_FLAGS           $fpp_flags":1 \
     908            -e s:"%PROD_FFLAGS     .*.$:%PROD_FFLAGS         $OPTIM":1 \
     909            -e s:"%DEV_FFLAGS      .*.$:%DEV_FFLAGS          $OPTDEV":1 \
     910            -e s:"%DEBUG_FFLAGS    .*.$:%DEBUG_FFLAGS        $OPTDEB":1 \
     911            -e s:"%BASE_FFLAGS     .*.$:%BASE_FFLAGS         $OPTPREC":1 \
     912            -e s:"%BASE_LD         .*.$:%BASE_LD             $BASE_LD":1 \
     913            -e s:"%ARFLAGS         .*.$:%ARFLAGS             $ARFLAGS":1 \
    925914            arch-gfortran.fcm > arch-local.fcm
    926         echo "NETCDF_LIBDIR=\"-L${ncdfdir}/lib -lnetcdff -lnetcdf\"" \
    927              > arch-local.path
    928         echo "NETCDF_INCDIR=${ncdfdir}/include" >> arch-local.path
    929         echo "IOIPSL_INCDIR=$ORCHPATH/../../lib" >> arch-local.path
    930         echo "IOIPSL_LIBDIR=$ORCHPATH/../../lib" >> arch-local.path
    931         echo 'XIOS_INCDIR=${ORCHDIR}/../XIOS/inc' >> arch-local.path
    932         echo 'XIOS_LIBDIR="${ORCHDIR}/../XIOS/lib -lxios"' >> arch-local.path
     915        cat <<EOF > arch-local.path
     916NETCDF_LIBDIR="-L$ncdfdir/lib -lnetcdff -lnetcdf"
     917NETCDF_INCDIR="$ncdfdir/include"
     918IOIPSL_INCDIR="$ORCHPATH/../../lib"
     919IOIPSL_LIBDIR="$ORCHPATH/../../lib"
     920XIOS_INCDIR="\$ORCHDIR/../XIOS/inc"
     921XIOS_LIBDIR="\$ORCHDIR/../XIOS/lib -lxios"
     922EOF
    933923        cd ../
    934924
     
    936926             -arch $arch
    937927        ./makeorchidee_fcm -j 8 $xios_orchid $opt_orc -parallel none \
    938                            -arch $arch > $orchideelog 2>&1
     928                           -arch $arch > "$orchideelog" 2>&1
    939929        pwd
    940     else # of "if [ -d tools ]"
    941         if [ -d src_parallel ] ; then
     930    else # of "if [[ -d tools ]]"
     931        if [[ -d src_parallel ]]; then
    942932            liste_src="parallel parameters global stomate sechiba driver"
    943             if [ "$veget_version" == "false" ] ; then
     933            if [[ "$veget_version" == "false" ]]; then
    944934                veget_version=orchidee2.0
    945935            fi
    946936        fi
    947         for d in $liste_src ; do
     937        for d in $liste_src; do
    948938            src_d=src_$d
    949             echo src_d $src_d
    950             echo ls ; ls
    951             if [ ! -d $src_d ] ; then
    952                 echo Problem orchidee : no $src_d ; exit
     939            echo src_d "$src_d"
     940            echo ls; ls
     941            if [[ ! -d $src_d ]]; then
     942                echo "Problem orchidee : no $src_d"; exit 1
    953943            fi
    954             cd $src_d ; \rm -f *.mod make ; $make clean
    955             $make > $orchideelog 2>&1
    956             if [ "$compiler" = "$gfortran" -o "$compiler" = "mpif90" ] ; then
    957                 cp -f *.mod ../../../lib
     944            cd "$src_d"; \rm -f -- *.mod make; $make clean
     945            $make > "$orchideelog" 2>&1
     946            if [[ "$compiler" = "$gfortran" || "$compiler" = "mpif90" ]]; then
     947                cp -f -- *.mod ../../../lib
    958948            fi
    959949            cd ..
    960950        done
    961     fi # of "if [ -d tools ]"
    962     echo install_lmdz.sh orchidee_compil_seq_OK `date`
    963 fi # of if [ "$veget" != 'NONE' ]
     951    fi # of "if [[ -d tools ]]"
     952    echo "install_lmdz.sh orchidee_compil_seq_OK $(date)"
     953fi # of if [[ "$veget" != 'NONE' ]]
    964954
    965955
    966956#============================================================================
    967957# Ehouarn: the directory name LMDZ* depends on version/tar file...
    968 if [ -d $MODEL/modipsl/modeles/LMD* ] ; then
     958if [[ -d $MODEL/modipsl/modeles/LMD* ]]; then
    969959    echo '###############################################################'
    970960    echo 'Preparing LMDZ compilation : arch file, svn switch if needed...'
    971961    echo '###############################################################'
    972     cd $MODEL/modipsl/modeles/LMD*
    973     LMDZPATH=`pwd`
     962    cd "$MODEL/modipsl/modeles/"LMD*
     963    LMDZPATH=$(pwd)
    974964else
    975965    echo "ERROR: No LMD* directory !!!"
    976     exit
     966    exit 1
    977967fi
    978968
     
    984974
    985975
    986 cd $MODEL/modipsl/modeles/LMDZ*
    987 lmdzlog=`pwd`/lmdz.log
     976cd "$MODEL/modipsl/modeles"/LMDZ*
     977lmdzlog=$(pwd)/lmdz.log
    988978
    989979##################################################################
     
    991981##################################################################
    992982
    993 set +e ; svn upgrade ; set -e
    994 
    995 if [ "$svn" = "last" ] ; then svnopt="" ; else svnopt="-r $svn" ; fi
    996 if [ "$svn" != "" ] ; then
    997     set +e ; svn info | grep -q 'https:'
    998     if [ $? = 0 ] ; then
     983set +e; svn upgrade; set -e
     984
     985if [[ $svn = "last" ]]; then svnopt=""; else svnopt="-r $svn"; fi
     986if [[ $svn != "" ]]; then
     987    if set +e; svn info | grep -q 'https:'; then
    999988        svn switch --relocate https://svn.lmd.jussieu.fr/LMDZ \
    1000989            http://svn.lmd.jussieu.fr/LMDZ
    1001990    fi
    1002     svn update $svnopt
     991    svn update "$svnopt"
    1003992    set -e
    1004993fi
     
    10121001#---------------------------------------------------------------------
    10131002
    1014 set +e ; mysvn=`svnversion . | egrep -o "[0-9]+" 2>/dev/null` ; set -e
    1015 if [ "$mysvn" = "" ] ; then mysvn=`grep 'Revision: [0-9]' $MODEL/Read*.md | awk ' { print $2 } ' 2>/dev/null` ; fi
    1016 if [ "$mysvn" = "" ] ; then mysvn=4190 ; fi
    1017 
    1018 if [[ "$pclinux" = "1" && ! -f arch/arch-local.path ]] ; then
     1003set +e; mysvn=$(svnversion . | grep -E || "[0-9]+" 2>/dev/null); set -e
     1004if [[ "$mysvn" = "" ]]; then mysvn=$(grep 'Revision: [0-9]' "$MODEL"/Read*.md | awk ' { print $2 } ' 2>/dev/null); fi
     1005if [[ "$mysvn" = "" ]]; then mysvn=4190; fi
     1006
     1007if [[ "$pclinux" = "1" && ! -f arch/arch-local.path ]]; then
    10191008
    10201009    # create local 'arch' files (if on Linux PC):
     
    10221011    # arch-local.path file
    10231012    # test for version as arch.pth file changed format with rev 4426
    1024     if [ "$mysvn" -gt 4425 ] ; then
    1025       echo "NETCDF_LIBDIR=\"-L${ncdfdir}/lib \"" > arch-local.path
    1026       echo "NETCDF_LIB=\"-lnetcdff -lnetcdf\"" >> arch-local.path
    1027       echo "NETCDF_INCDIR=-I${ncdfdir}/include" >> arch-local.path
    1028       echo 'NETCDF95_INCDIR=-I$LMDGCM/../../include' >> arch-local.path
    1029       echo 'NETCDF95_LIBDIR=-L$LMDGCM/../../lib' >> arch-local.path
    1030       echo 'NETCDF95_LIB=-lnetcdf95' >> arch-local.path
    1031       echo 'IOIPSL_INCDIR=-I$LMDGCM/../../lib' >> arch-local.path
    1032       echo 'IOIPSL_LIBDIR=-L$LMDGCM/../../lib' >> arch-local.path
    1033       echo 'IOIPSL_LIB=-lioipsl' >> arch-local.path
    1034       echo 'XIOS_INCDIR=-I$LMDGCM/../XIOS/inc' >> arch-local.path
    1035       echo 'XIOS_LIBDIR=-L$LMDGCM/../XIOS/lib' >> arch-local.path
    1036       echo "XIOS_LIB=\"-lxios -lstdc++\"" >> arch-local.path
    1037       echo 'ORCH_INCDIR=-I$LMDGCM/../../lib' >> arch-local.path
    1038       echo 'ORCH_LIBDIR=-L$LMDGCM/../../lib' >> arch-local.path
     1013    if [[ "$mysvn" -gt 4425 ]]; then
     1014      cat <<EOF > arch-local.path
     1015NETCDF_LIBDIR="-L$ncdfdir/lib"
     1016NETCDF_LIB="-lnetcdff -lnetcdf\"
     1017NETCDF_INCDIR=-I$ncdfdir/include
     1018NETCDF95_INCDIR=-I\$LMDGCM/../../include
     1019NETCDF95_LIBDIR=-L\$LMDGCM/../../lib
     1020NETCDF95_LIB=-lnetcdf95
     1021IOIPSL_INCDIR=-I\$LMDGCM/../../lib
     1022IOIPSL_LIBDIR=-L\$LMDGCM/../../lib
     1023IOIPSL_LIB=-lioipsl
     1024XIOS_INCDIR=-I\$LMDGCM/../XIOS/inc
     1025XIOS_LIBDIR=-L\$LMDGCM/../XIOS/lib
     1026XIOS_LIB="-lxios -lstdc++"
     1027ORCH_INCDIR=-I\$LMDGCM/../../lib
     1028ORCH_LIBDIR=-L\$LMDGCM/../../lib
     1029EOF
    10391030    else
    1040       echo "NETCDF_LIBDIR=\"-L${ncdfdir}/lib -lnetcdff -lnetcdf\"" \
    1041          > arch-local.path
    1042       echo "NETCDF_INCDIR=-I${ncdfdir}/include" >> arch-local.path
    1043       echo 'NETCDF95_INCDIR=$LMDGCM/../../include' >> arch-local.path
    1044       echo 'NETCDF95_LIBDIR=$LMDGCM/../../lib' >> arch-local.path
    1045       echo 'IOIPSL_INCDIR=$LMDGCM/../../lib' >> arch-local.path
    1046       echo 'IOIPSL_LIBDIR=$LMDGCM/../../lib' >> arch-local.path
    1047       echo 'XIOS_INCDIR=$LMDGCM/../XIOS/inc' >> arch-local.path
    1048       echo 'XIOS_LIBDIR=$LMDGCM/../XIOS/lib' >> arch-local.path
    1049       echo 'ORCH_INCDIR=$LMDGCM/../../lib' >> arch-local.path
    1050       echo 'ORCH_LIBDIR=$LMDGCM/../../lib' >> arch-local.path
     1031      cat <<EOF > arch-local.path
     1032NETCDF_LIBDIR="-L$ncdfdir/lib -lnetcdff -lnetcdf"
     1033NETCDF_INCDIR=-I$ncdfdir/include
     1034NETCDF95_INCDIR=\$LMDGCM/../../include
     1035NETCDF95_LIBDIR=\$LMDGCM/../../lib
     1036IOIPSL_INCDIR=\$LMDGCM/../../lib
     1037IOIPSL_LIBDIR=\$LMDGCM/../../lib
     1038XIOS_INCDIR=\$LMDGCM/../XIOS/inc
     1039XIOS_LIBDIR=\$LMDGCM/../XIOS/lib
     1040ORCH_INCDIR=\$LMDGCM/../../lib
     1041ORCH_LIBDIR=\$LMDGCM/../../lib
     1042EOF
    10511043    fi
    10521044
    1053     if [ $pcmac == 1 ] ; then
     1045    if [[ $pcmac == 1 ]]; then
    10541046        BASE_LD="$BASE_LD -Wl,-rpath,${ncdfdir}/lib"
    10551047    else
     
    10581050    # Arch-local.fcm file (adapted from arch-linux-32bit.fcm)
    10591051
    1060     if [ $real = r8 ] ; then FPP_DEF=NC_DOUBLE ; else FPP_DEF="" ; fi
    1061     sed -e s:"%COMPILER        .*.$":"%COMPILER            $compiler":1 \
    1062         -e s:"%LINK            .*.$":"%LINK                $compiler":1 \
    1063         -e s:"%PROD_FFLAGS     .*.$":"%PROD_FFLAGS         $OPTIM":1 \
    1064         -e s:"%DEV_FFLAGS      .*.$":"%DEV_FFLAGS          $OPTDEV":1 \
    1065         -e s:"%DEBUG_FFLAGS    .*.$":"%DEBUG_FFLAGS        $OPTDEB":1 \
    1066         -e s:"%BASE_FFLAGS     .*.$":"%BASE_FFLAGS         $OPTPREC":1 \
    1067         -e s:"%FPP_DEF         .*.$":"%FPP_DEF             $FPP_DEF":1 \
    1068         -e s:"%BASE_LD         .*.$":"%BASE_LD             $BASE_LD":1 \
    1069         -e s:"%ARFLAGS         .*.$":"%ARFLAGS             $ARFLAGS":1 \
     1052    if [[ $real = r8 ]]; then FPP_DEF=NC_DOUBLE; else FPP_DEF=""; fi
     1053    sed -e s:"%COMPILER        .*.$:%COMPILER            $compiler":1 \
     1054        -e s:"%LINK            .*.$:%LINK                $compiler":1 \
     1055        -e s:"%PROD_FFLAGS     .*.$:%PROD_FFLAGS         $OPTIM":1 \
     1056        -e s:"%DEV_FFLAGS      .*.$:%DEV_FFLAGS          $OPTDEV":1 \
     1057        -e s:"%DEBUG_FFLAGS    .*.$:%DEBUG_FFLAGS        $OPTDEB":1 \
     1058        -e s:"%BASE_FFLAGS     .*.$:%BASE_FFLAGS         $OPTPREC":1 \
     1059        -e s:"%FPP_DEF         .*.$:%FPP_DEF             $FPP_DEF":1 \
     1060        -e s:"%BASE_LD         .*.$:%BASE_LD             $BASE_LD":1 \
     1061        -e s:"%ARFLAGS         .*.$:%ARFLAGS             $ARFLAGS":1 \
    10701062        arch-linux-32bit.fcm > arch-local.fcm
    10711063
     
    10751067    #echo "bld::tool::SHELL   $whereisthatshell" >> bld.cfg
    10761068
    1077 fi # of if [ "$pclinux" = 1 ]
     1069fi # of if [[ "$pclinux" = 1 ]]
    10781070#---------------------------------------------------------------------
    10791071# Option de compilation du rayonnement : depend de $mysvn ><= r4185
     
    10821074
    10831075case $rad in
    1084     oldrad) iflag_rrtm=0 ; NSW=2 ; opt_rad="" ;;
    1085     rrtm)   iflag_rrtm=1 ; NSW=6
    1086             if [ $mysvn -le 4185 ] ; then
     1076    oldrad) iflag_rrtm=0; NSW=2; opt_rad="";;
     1077    rrtm)   iflag_rrtm=1; NSW=6
     1078            if [[ $mysvn -le 4185 ]]; then
    10871079                opt_rad="-rrtm true"
    10881080            else
    10891081                opt_rad="-rad rrtm"
    1090             fi ;;
    1091     ecrad)  iflag_rrtm=2 ; NSW=6 ; opt_rad="-rad ecrad" ;;
    1092     *) echo Only oldrad rrtm ecrad for rad option ; exit
     1082            fi;;
     1083    ecrad)  iflag_rrtm=2; NSW=6; opt_rad="-rad ecrad";;
     1084    *) echo "Only oldrad rrtm ecrad for rad option"; exit 1
    10931085esac
    10941086
    1095 if [ $mysvn -le 4185 -a $rad = "ecrad" ] ; then
    1096     echo "ecrad only available for LMDZ rev starting with 4186 " ; exit
     1087if [[ $mysvn -le 4185 && $rad = "ecrad" ]]; then
     1088    echo "ecrad only available for LMDZ rev starting with 4186 "; exit 1
    10971089fi
    10981090
     
    11001092
    11011093
    1102 if [[ ! -f libf/misc/netcdf95.F90 &&  ! -d $MODEL/NetCDF95-0.3 ]]
    1103 then
    1104     cd $MODEL
     1094if [[ ! -f libf/misc/netcdf95.F90 &&  ! -d $MODEL/NetCDF95-0.3 ]]; then
     1095    cd "$MODEL"
    11051096    myget src_archives/netcdf/NetCDF95-0.3.tar.gz
    11061097    tar -xf NetCDF95-0.3.tar.gz
     
    11091100    mkdir build
    11101101    cd build
    1111     cmake .. -DCMAKE_BUILD_TYPE=Release -DCMAKE_PREFIX_PATH=$ncdfdir \
    1112           -DCMAKE_INSTALL_PREFIX=$MODEL/modipsl
     1102    cmake .. -DCMAKE_BUILD_TYPE=Release -DCMAKE_PREFIX_PATH="$ncdfdir" \
     1103          -DCMAKE_INSTALL_PREFIX="$MODEL/modipsl"
    11131104    make install
    1114     cd $MODEL/modipsl/modeles/LMDZ*
     1105    cd "$MODEL/modipsl/modeles/"LMDZ*
    11151106fi
    11161107
     
    11181109echo "Preparing script compile.sh for LMDZ compilation"
    11191110echo "It will only be run automatically if bench=1/tuto"
    1120 echo Here bench=$bench
     1111echo "Here bench=$bench"
    11211112echo '##################################################################'
    11221113
    1123 if [ "$env_file" != "" ] ; then
     1114if [[ $env_file != "" ]]; then
    11241115    mv arch/arch-${arch}.env arch/arch-${arch}.orig
    1125     \cp -f $env_file arch/arch-${arch}.env
    1126 fi
    1127 
    1128 if [ $compile_with_fcm = 1 ] ; then
     1116    \cp -f "$env_file" arch/arch-${arch}.env
     1117fi
     1118
     1119if [[ $compile_with_fcm = 1 ]]; then
    11291120    makelmdz="makelmdz_fcm $optim -arch $arch -j 8 "
    11301121else
     
    11331124
    11341125# sequential compilation
    1135 if [ "$sequential" = 1 ] ; then
     1126if [[ "$sequential" = 1 ]]; then
    11361127    echo Sequential compilation command, saved in compile.sh:
    11371128    echo "./$makelmdz $optim $OPT_MAKELMDZ $optim $opt_rad $opt_cosp " \
     
    11401131         "-d ${grid_resolution} -v $veget_version gcm " > compile.sh
    11411132    chmod +x ./compile.sh
    1142     if [ $bench = 1 ] ; then
    1143         echo install_lmdz.sh start_lmdz_seq_compilation `date`
    1144         echo log file: $lmdzlog
    1145         ./compile.sh > $lmdzlog 2>&1
    1146         echo install_lmdz.sh end_lmdz_seq_compilation `date`
     1133    if [[ $bench = 1 ]]; then
     1134        echo "install_lmdz.sh start_lmdz_seq_compilation $(date)"
     1135        echo "log file: $lmdzlog"
     1136        ./compile.sh > "$lmdzlog" 2>&1
     1137        echo "install_lmdz.sh end_lmdz_seq_compilation $(date)"
    11471138    fi
    11481139fi # fin sequential
    11491140
    11501141# compiling in parallel mode
    1151 if [ $parallel != "none" ] ; then
     1142if [[ $parallel != "none" ]]; then
    11521143    echo '##########################################################'
    11531144    echo ' Parallel compile '
    11541145    echo '##########################################################'
    11551146    echo "(after saving the sequential libs and binaries)"
    1156     cd $MODEL/modipsl
     1147    cd "$MODEL/modipsl"
    11571148    tar cf sequential.tar bin/ lib/
    11581149    #
    11591150    # Orchidee
    11601151    #
    1161     cd $ORCHPATH
    1162     if [ -d src_parallel -a $veget != 'NONE' ] ; then
     1152    cd "$ORCHPATH"
     1153    if [[ -d src_parallel && $veget != 'NONE' ]]; then
    11631154        cd arch
    11641155        sed  \
    1165             -e s:"%COMPILER.*.$":"%COMPILER            $par_comp":1 \
    1166             -e s:"%LINK.*.$":"%LINK                $par_comp":1 \
    1167             -e s:"%MPI_FFLAG.*.$":"%MPI_FFLAGS          $MPI_FLAGS":1 \
    1168             -e s:"%OMP_FFLAG.*.$":"%OMP_FFLAGS          $OMP_FLAGS":1 \
    1169             -e s:"%MPI_LD.*.$":"%MPI_LD              $MPI_LD":1 \
    1170             -e s:"%OMP_LD.*.$":"%OMP_LD              $OMP_LD":1 \
     1156            -e s:"%COMPILER.*.$:%COMPILER            $par_comp":1 \
     1157            -e s:"%LINK.*.$:%LINK                $par_comp":1 \
     1158            -e s:"%MPI_FFLAG.*.$:%MPI_FFLAGS          $MPI_FLAGS":1 \
     1159            -e s:"%OMP_FFLAG.*.$:%OMP_FFLAGS          $OMP_FLAGS":1 \
     1160            -e s:"%MPI_LD.*.$:%MPI_LD              $MPI_LD":1 \
     1161            -e s:"%OMP_LD.*.$:%OMP_LD              $OMP_LD":1 \
    11711162            arch-local.fcm > tmp.fcm
    11721163
    11731164        mv tmp.fcm arch-local.fcm
    11741165        cd ../
    1175         echo Compiling ORCHIDEE in parallel mode `date`
    1176         echo logfile $orchideelog
     1166        echo "Compiling ORCHIDEE in parallel mode $(date)"
     1167        echo "logfile $orchideelog"
    11771168        echo "NOTE : to recompile it when necessary, use ./compile_orc.sh " \
    11781169             "in modipsl/modeles/ORCHIDEE"
    11791170        echo ./makeorchidee_fcm -j 8 -clean $xios_orchid $opt_orc \
    1180              -parallel $parallel -arch $arch > compile_orc.sh
     1171             -parallel "$parallel" -arch $arch > compile_orc.sh
    11811172        echo ./makeorchidee_fcm -j 8 $xios_orchid $opt_orc \
    1182              -parallel $parallel -arch $arch >> compile_orc.sh
     1173             -parallel "$parallel" -arch $arch >> compile_orc.sh
    11831174        echo echo Now you must also recompile LMDZ, by running ./compile.sh \
    11841175             in modeles/LMDZ >> compile_orc.sh
    11851176        chmod u+x compile_orc.sh
    11861177        ./makeorchidee_fcm -j 8 -clean $xios_orchid $opt_orc \
    1187                            -parallel $parallel -arch $arch > $orchideelog 2>&1
    1188         ./makeorchidee_fcm -j 8 $xios_orchid $opt_orc -parallel $parallel \
    1189                            -arch $arch >> $orchideelog 2>&1
    1190         echo End of ORCHIDEE compilation in parallel mode `date`
    1191     elif [ $veget != 'NONE' ] ; then
     1178                           -parallel "$parallel" -arch $arch > "$orchideelog" 2>&1
     1179        ./makeorchidee_fcm -j 8 $xios_orchid $opt_orc -parallel "$parallel" \
     1180                           -arch $arch >> "$orchideelog" 2>&1
     1181        echo "End of ORCHIDEE compilation in parallel mode $(date)"
     1182    elif [[ $veget != 'NONE' ]]; then
    11921183        echo '##########################################################'
    11931184        echo ' Orchidee version too old                                 '
    11941185        echo ' Please update to new version                             '
    11951186        echo '##########################################################'
    1196         exit
    1197     fi # of [ -d src_parallel -a $veget != 'NONE' ]
     1187        exit 1
     1188    fi #�of [ -d src_parallel && $veget != 'NONE' ]
    11981189
    11991190    # LMDZ
    1200     cd $LMDZPATH
    1201     if [ $arch = local ] ; then
     1191    cd "$LMDZPATH"
     1192    if [[ $arch = local ]]; then
    12021193        cd arch
    1203         sed -e s:"%COMPILER.*.$":"%COMPILER            $par_comp":1 \
    1204             -e s:"%LINK.*.$":"%LINK                $par_comp":1 \
    1205             -e s:"%MPI_FFLAG.*.$":"%MPI_FFLAGS          $MPI_FLAGS":1 \
    1206             -e s:"%OMP_FFLAG.*.$":"%OMP_FFLAGS          $OMP_FLAGS":1 \
    1207             -e s:"%ARFLAGS.*.$":"%ARFLAGS          $ARFLAGS":1 \
    1208             -e s@"%BASE_LD.*.$"@"%BASE_LD             -Wl,-rpath=${root_mpi}/lib:${ncdfdir}/lib"@1 \
    1209             -e s:"%MPI_LD.*.$":"%MPI_LD              $MPI_LD":1 \
    1210             -e s:"%OMP_LD.*.$":"%OMP_LD              $OMP_LD":1 \
     1194        sed -e s:"%COMPILER.*.$:%COMPILER            $par_comp":1 \
     1195            -e s:"%LINK.*.$:%LINK                $par_comp":1 \
     1196            -e s:"%MPI_FFLAG.*.$:%MPI_FFLAGS          $MPI_FLAGS":1 \
     1197            -e s:"%OMP_FFLAG.*.$:%OMP_FFLAGS          $OMP_FLAGS":1 \
     1198            -e s:"%ARFLAGS.*.$:%ARFLAGS          $ARFLAGS":1 \
     1199            -e "s§%BASE_LD.*.$§%BASE_LD             -Wl,-rpath=${root_mpi}/lib:${ncdfdir}/lib§1" \
     1200            -e s:"%MPI_LD.*.$:%MPI_LD              $MPI_LD":1 \
     1201            -e s:"%OMP_LD.*.$:%OMP_LD              $OMP_LD":1 \
    12111202            arch-local.fcm > tmp.fcm
    12121203        mv tmp.fcm arch-local.fcm
     
    12141205    fi
    12151206    rm -f compile.sh
    1216     echo resol=${grid_resolution} >> compile.sh
    1217     if [ ${hostname:0:5} = jean- -a "$cosp" = "v2" ] ; then
    1218 
    1219         echo LMDZ compilation command in parallel mode, saved in compile.sh, \
    1220              is :
     1207    echo resol="$grid_resolution" >> compile.sh
     1208    if [[ ${hostname:0:5} = jean- && "$cosp" = "v2" ]]; then
     1209
     1210        echo "LMDZ compilation command in parallel mode, saved in compile.sh, is :"
    12211211        echo "(ATTENTION le probleme de cospv2 sur jean-zay en mode prod " \
    12221212             "n est pas corrige ! )"
    12231213        # ATTENTION le probleme de cospv2 sur jean-zay en mode prod n
    12241214        # est pas corrige
    1225         echo ./$makelmdz -dev $optim $OPT_MAKELMDZ $opt_rad $opt_cosp \
    1226              $opt_makelmdz_xios -d \$resol -v $veget_version -mem \
    1227              -parallel $parallel gcm >> compile.sh
    1228         echo ./$makelmdz -dev $optim $OPT_MAKELMDZ $opt_rad $opt_cosp \
    1229              $opt_makelmdz_xios -d \$resol -v $veget_version -mem \
    1230              -parallel $parallel gcm
     1215        echo ./"$makelmdz" -dev $optim "$OPT_MAKELMDZ" "$opt_rad" "$opt_cosp" \
     1216             "$opt_makelmdz_xios" -d \$resol -v $veget_version -mem \
     1217             -parallel "$parallel" gcm >> compile.sh
     1218        echo ./"$makelmdz" -dev $optim "$OPT_MAKELMDZ" "$opt_rad" "$opt_cosp" \
     1219             "$opt_makelmdz_xios" -d \$resol -v $veget_version -mem \
     1220             -parallel "$parallel" gcm
    12311221    else
    1232         echo ./$makelmdz $optim $OPT_MAKELMDZ $opt_rad $opt_cosp \
    1233              $opt_makelmdz_xios -d \$resol -v $veget_version -mem \
    1234              -parallel $parallel gcm >> compile.sh
    1235         echo ./$makelmdz $optim $OPT_MAKELMDZ $opt_rad $opt_cosp \
    1236              $opt_makelmdz_xios -d \$resol -v $veget_version -mem \
    1237              -parallel $parallel gcm
     1222        echo ./"$makelmdz" $optim "$OPT_MAKELMDZ" "$opt_rad" "$opt_cosp" \
     1223             "$opt_makelmdz_xios" -d \$resol -v $veget_version -mem \
     1224             -parallel "$parallel" gcm >> compile.sh
     1225        echo ./"$makelmdz" $optim "$OPT_MAKELMDZ" "$opt_rad" "$opt_cosp" \
     1226             "$opt_makelmdz_xios" -d \$resol -v $veget_version -mem \
     1227             -parallel "$parallel" gcm
    12381228    fi
    12391229    chmod +x ./compile.sh
    12401230
    1241     if [ $bench = 1 ] ; then
    1242         echo Compiling LMDZ in parallel mode `date`,  LMDZ log file: $lmdzlog
    1243         ./compile.sh > $lmdzlog 2>&1
    1244     fi
    1245 
    1246 fi # of if [ $parallel != "none" ]
     1231    if [[ $bench = 1 ]]; then
     1232        echo "Compiling LMDZ in parallel mode $(date),  LMDZ log file: $lmdzlog"
     1233        ./compile.sh > "$lmdzlog" 2>&1
     1234    fi
     1235
     1236fi # of if [[ $parallel != "none" ]]
    12471237
    12481238
     
    12531243# Recherche de l'executable dont le nom a change au fil du temps ...
    12541244# suffix contains radiative option starting with revision 4186
    1255 if [ $mysvn -ge 4186 ] ; then suff_exe=_${rad}${suff_exe} ; fi
     1245if [[ $mysvn -ge 4186 ]]; then suff_exe=_${rad}${suff_exe}; fi
    12561246gcm=""
    12571247
    12581248for exe in gcm.e bin/gcm_${grid_resolution}_phylmd${suff_exe}${suff_orc}.e
    12591249do
    1260     if [ -f $exe ] ; then gcm=$exe ; fi
     1250    if [[ -f $exe ]]; then gcm=$exe; fi
    12611251done
    12621252
    1263 if [ "$gcm" = "" ] ; then
    1264     if [ $bench = 1 ] ; then
     1253if [[ "$gcm" = "" ]]; then
     1254    if [[ $bench = 1 ]]; then
    12651255        echo 'Compilation failed !! Cannot run the benchmark;'
    1266         exit
     1256        exit 1
    12671257    else
    12681258        echo 'Compilation not done (only done when bench=1)'
     
    12701260else
    12711261    echo '##########################################################'
    1272     echo 'Compilation successfull !! ' `date`
     1262    echo "Compilation successfull !!  $(date)"
    12731263    echo '##########################################################'
    1274     echo The executable is $gcm
     1264    echo "The executable is $gcm"
    12751265fi
    12761266
     
    12791269##################################################################
    12801270
    1281 if [ $bench = tuto ] ; then
    1282     myget Training/tutorial.tar ; tar xf tutorial.tar ; cd TUTORIAL
     1271if [[ $bench = tuto ]]; then
     1272    myget Training/tutorial.tar; tar xf tutorial.tar; cd TUTORIAL
    12831273    ./init.sh
    12841274
    1285 elif [[ $bench = 1 && ! -d BENCH${grid_resolution} ]] ; then
     1275elif [[ $bench = 1 && ! -d BENCH${grid_resolution} ]]; then
    12861276    # TOUTE CETTE SECTION DEVRAIT DISPARAITRE POUR UNE COMMANDE
    12871277    # OU DES BENCHS PAR MOTS CLES COMME tuto
     
    12911281    echo '##########################################################'
    12921282
    1293     \rm -rf BENCH${grid_resolution}
     1283    \rm -rf "BENCH${grid_resolution}"
    12941284    bench=bench_lmdz_${grid_resolution}
    1295     echo install_lmdz.sh before bench download  `date`
     1285    echo "install_lmdz.sh before bench download  $(date)"
    12961286    #wget http://www.lmd.jussieu.fr/~lmdz/Distrib/$bench.tar.gz
    1297     myget 3DBenchs/$bench.tar.gz
    1298     echo install_lmdz.sh after bench download  `date`
    1299     tar xf $bench.tar.gz
    1300 
    1301     if [ "$cosp" = "v1" -o "$cosp" = "v2" ] ; then
    1302         cd BENCH${grid_resolution}
     1287    myget "3DBenchs/$bench.tar.gz"
     1288    echo "install_lmdz.sh after bench download  $(date)"
     1289    tar xf "$bench.tar.gz"
     1290
     1291    if [[ "$cosp" = "v1" || "$cosp" = "v2" ]]; then
     1292        cd "BENCH${grid_resolution}"
    13031293        # copier les fichiers namelist input et output our COSP
    13041294        cp ../DefLists/cosp*_input_nl.txt .
     
    13101300    fi
    13111301
    1312     if [ -n "$physiq" ]; then
    1313         cd BENCH${grid_resolution}
    1314         if [ -f physiq.def_${physiq} ]; then
    1315             cp physiq.def_${physiq} physiq.def
    1316             echo using physiq.def_${physiq}
     1302    if [[ -n "$physiq" ]]; then
     1303        cd "BENCH${grid_resolution}"
     1304        if [[ -f "physiq.def_${physiq}" ]]; then
     1305            cp "physiq.def_${physiq}" physiq.def
     1306            echo using "physiq.def_${physiq}"
    13171307        else
    13181308            echo using standard physiq.def
     
    13231313    fi
    13241314
    1325     if [ "$with_xios" = "y" ] ; then
    1326         cd BENCH${grid_resolution}
     1315    if [[ "$with_xios" = "y" ]]; then
     1316        cd "BENCH${grid_resolution}"
    13271317        cp ../DefLists/iodef.xml .
    13281318        cp ../DefLists/context_lmdz.xml .
    13291319        cp ../DefLists/field_def_lmdz.xml .
    13301320        # A raffiner par la suite
    1331         echo A FAIRE : Copier les *xml en fonction de l option cosp
     1321        echo "A FAIRE : Copier les *xml en fonction de l option cosp"
    13321322        cp ../DefLists/field_def_cosp*.xml .
    13331323        cp ../DefLists/file_def_hist*xml .
     
    13411331        for histfile in file_def_hist*xml
    13421332        do
    1343             if [ "$histfile" = "file_def_histday_lmdz.xml" ] ; then
     1333            if [[ "$histfile" = "file_def_histday_lmdz.xml" ]]; then
    13441334                sed -e 's@enabled="_AUTO_"@type="one_file" enabled=".TRUE."@' \
    1345                     $histfile > tmp
    1346                 \mv -f tmp $histfile
    1347                 sed -e 's@output_level="_AUTO_"@output_level="5"@' $histfile \
     1335                    "$histfile" > tmp
     1336                \mv -f tmp "$histfile"
     1337                sed -e 's@output_level="_AUTO_"@output_level="5"@' "$histfile" \
    13481338                    > tmp
    1349                 \mv -f tmp $histfile
     1339                \mv -f tmp "$histfile"
    13501340                sed -e 's@compression_level="2"@compression_level="0"@' \
    1351                     $histfile > tmp
    1352                 \mv -f tmp $histfile
     1341                    "$histfile" > tmp
     1342                \mv -f tmp "$histfile"
    13531343            else
    13541344                sed -e 's@enabled="_AUTO_"@type="one_file" enabled=".FALSE."@' \
    1355                     $histfile > tmp
    1356                 \mv -f tmp $histfile
     1345                    "$histfile" > tmp
     1346                \mv -f tmp "$histfile"
    13571347            fi
    13581348        done
     
    13621352
    13631353        #activer les sorties pour Cosp
    1364         if [ "$cosp" = "v1" ] ; then
     1354        if [[ "$cosp" = "v1" ]]; then
    13651355            sed -i'' -e 's@enabled=".FALSE."@enabled=".TRUE."@' \
    13661356                     -e 's@output_level="_AUTO_"@output_level="5"@' \
     
    13681358                     file_def_histdayCOSP_lmdz.xml
    13691359        fi
    1370         if [ "$cosp" = "v2" ] ; then
     1360        if [[ "$cosp" = "v2" ]]; then
    13711361            sed -e 's@compression_level="2"@compression_level="0"@' file_def_histdayCOSPv2_lmdz.xml
    1372             for type_ in hf day mth ; do
     1362            for type_ in hf day mth; do
    13731363                file=file_def_hist${type_}COSP
    13741364                sed -i'' -e 's@src="./'${file}'_lmdz.xml"@src="./'${file}'v2_lmdz.xml"@' context_lmdz.xml
     
    13811371
    13821372    # Cas Bensh avec ecrad
    1383     if [ "$rad" = "ecrad" ] ; then
    1384         cd BENCH${grid_resolution}
     1373    if [[ "$rad" = "ecrad" ]]; then
     1374        cd "BENCH${grid_resolution}"
    13851375        cp  ../DefLists/namelist_ecrad .
    13861376        cp -r ../libf/phylmd/ecrad/data .
     
    13891379
    13901380    # Adjusting bench physiq.def to radiative code chosen
    1391     cd BENCH${grid_resolution}
     1381    cd "BENCH${grid_resolution}"
    13921382    sed -e 's/iflag_rrtm=.*.$/iflag_rrtm='$iflag_rrtm'/' \
    13931383        -e 's/NSW=.*.$/NSW='$NSW'/' physiq.def > tmpdef
     
    13951385    cd ..
    13961386
    1397     cp $gcm BENCH${grid_resolution}/gcm.e
    1398 
    1399     cd BENCH${grid_resolution}
     1387    cp "$gcm" "BENCH${grid_resolution}/gcm.e"
     1388
     1389    cd "BENCH${grid_resolution}"
    14001390    # On cree le fichier bench.sh au besoin
    14011391    # Dans le cas 48x36x39 le bench.sh existe deja en parallele
    14021392
    1403     if [ "$grid_resolution" = "48x36x39" ] ; then
     1393    if [[ "$grid_resolution" = "48x36x39" ]]; then
    14041394        echo On ne touche pas au bench.sh
    14051395        # But we have to adapt "run_local.sh" for $mpirun
     
    14071397        mv -f tmp run_local.sh
    14081398        chmod u=rwx run_local.sh
    1409     elif [ "${parallel:0:3}" = "mpi" ] ; then
     1399    elif [[ "${parallel:0:3}" = "mpi" ]]; then
    14101400        # Lancement avec deux procs mpi et 2 openMP
    14111401        echo "export OMP_STACKSIZE=800M" > bench.sh
    1412         if [ "${parallel:4:3}" = "omp" ] ; then
     1402        if [[ "${parallel:4:3}" = "omp" ]]; then
    14131403            echo "export OMP_NUM_THREADS=2" >> bench.sh
    14141404        fi
    1415         if [ "$cosp" = "v1" -o "$cosp" = "v2" ] ; then
    1416             if [ ${hostname:0:5} = jean- ] ; then
     1405        if [[ "$cosp" = "v1" || "$cosp" = "v2" ]]; then
     1406            if [[ ${hostname:0:5} = jean- ]]; then
    14171407                   chmod +x ../arch.env
    14181408                ../arch.env       
     
    14241414            echo "ulimit -s unlimited" >> bench.sh
    14251415        fi
    1426         if [ ${hostname:0:5} = jean- ] ; then
     1416        if [[ ${hostname:0:5} = jean- ]]; then
    14271417            . ../arch/arch-${arch}.env
    1428             echo "srun -n 2 -A $idris_acct@cpu gcm.e > listing  2>&1" \
     1418            echo "srun -n 2 && $idris_acct@cpu gcm.e > listing  2>&1" \
    14291419                 >> bench.sh
    14301420        else
     
    14321422        fi
    14331423        # Add rebuild, using reb.sh if it is there
    1434         echo 'if [ -f reb.sh ] ; then' >> bench.sh
    1435         echo '  ./reb.sh histday ; ./reb.sh histmth ; ./reb.sh histhf ; ' \
    1436              './reb.sh histins ; ./reb.sh stomate_history ; ' \
    1437              './reb.sh sechiba_history ; ./reb.sh sechiba_out_2 ' >> bench.sh
    1438         echo 'fi' >> bench.sh
     1424        cat <<EOF >> bench.sh
     1425if [[ -f reb.sh ]]; then
     1426  ./reb.sh histday; ./reb.sh histmth; ./reb.sh histhf;
     1427  ./reb.sh histins; ./reb.sh stomate_history;
     1428  ./reb.sh sechiba_history; ./reb.sh sechiba_out_2
     1429fi
     1430EOF
    14391431    else
    14401432        echo "./gcm.e > listing  2>&1" > bench.sh
    14411433    fi
    14421434    # Getting orchidee stuff
    1443     if [ $veget == 'CMIP6' ] ; then
     1435    if [[ $veget == 'CMIP6' ]]; then
    14441436        #echo 'myget 3DBenchs/BENCHorch11.tar.gz'
    14451437        #myget 3DBenchs/BENCHorch11.tar.gz
     
    14501442        sed -e "s:VEGET=n:VEGET=y:" config.def > tmp
    14511443        mv -f tmp config.def
    1452         if [ "$with_xios" = "y" ] ; then
     1444        if [[ "$with_xios" = "y" ]]; then
    14531445            cp ../../ORCHIDEE/src_xml/context_orchidee.xml .
    14541446            echo '<context id="orchidee" src="./context_orchidee.xml"/>' \
     
    14571449            cp ../../ORCHIDEE/src_xml/file_def_orchidee.xml .
    14581450            cp ../../ORCHIDEE/src_xml/file_def_input_orchidee.xml .
    1459             if [ -f ../../ORCHIDEE/src_xml/context_input_orchidee.xml ] ; then
     1451            if [[ -f ../../ORCHIDEE/src_xml/context_input_orchidee.xml ]]; then
    14601452                   cp ../../ORCHIDEE/src_xml/context_input_orchidee.xml .
    14611453                   echo '<context id="orchidee" ' \
     
    14921484    echo EXECUTION DU BENCH
    14931485    set +e
    1494     date ; ./bench.sh > out.bench 2>&1 ; date
     1486    date; ./bench.sh > out.bench 2>&1; date
    14951487    set -e
    14961488    tail listing
    14971489
    14981490
    1499     echo '##########################################################'
    1500     echo 'Simulation finished in' `pwd`
    1501     echo 'You have compiled with:'
     1491    echo "##########################################################"
     1492    echo "Simulation finished in $(pwd)"
     1493    echo "You have compiled with:"
    15021494    cat ../compile.sh
    1503     if [ $parallel = "none" ] ; then
    1504         echo 'You may re-run it with : cd ' `pwd` ' ; gcm.e'
    1505         echo 'or ./bench.sh'
     1495    if [[ $parallel = "none" ]]; then
     1496        echo "You may re-run it with : cd  $(pwd) ; gcm.e"
     1497        echo "or ./bench.sh"
    15061498    else
    1507         echo 'You may re-run it with : '
    1508         echo 'cd ' `pwd` '; ./bench.sh'
     1499        echo "You may re-run it with : "
     1500        echo "cd  $(pwd) ; ./bench.sh"
    15091501        #  echo 'ulimit -s unlimited'
    15101502        #  echo 'export OMP_NUM_THREADS=2'
     
    15211513#################################################################
    15221514
    1523 if [ $SCM = 1 ] ; then
    1524     cd $MODEL
     1515if [[ $SCM = 1 ]]; then
     1516    cd "$MODEL"
    15251517    myget 1D/1D.tar.gz
    15261518    tar xf 1D.tar.gz
    15271519    cd 1D
    1528     if [ $rad = oldrad ] ; then
     1520    if [[ $rad = oldrad ]]; then
    15291521        sed -i'' -e 's/^rad=.*$/rad=oldrad/' run.sh
    15301522        sed -i'' -e 's/^rad=.*$/rad=oldrad/' bin/compile
    15311523    fi
    1532     echo Running 1D/run.sh, log in `pwd`/run1d.log
    1533     ./run.sh > `pwd`/run1d.log 2>&1
     1524    echo "Running 1D/run.sh, log in $(pwd)/run1d.log"
     1525    ./run.sh > "$(pwd)/run1d.log" 2>&1
    15341526fi
    15351527
     
    15381530# sauvegarde des options veget pour utilisation eventuelle tutorial_prod
    15391531#################################################################
    1540 cd $MODEL/modipsl/modeles
     1532cd "$MODEL/modipsl/modeles"
    15411533#echo surface_env file created in $MODEL
    1542 echo 'veget='$veget > surface_env
    1543 #opt_veget="-v $veget_version"
    1544 #echo 'opt_veget="'$opt_veget\" >> surface_env
    1545 echo 'opt_veget="'-v $veget_version\" >> surface_env
    1546 echo 'orchidee_rev='$orchidee_rev >> surface_env
    1547 echo 'suforch='$suff_orc >> surface_env
     1534cat <<EOF >surface_env
     1535veget=$veget
     1536opt_veget="-v $veget_version"
     1537orchidee_rev=$orchidee_rev
     1538suforch=$suff_orc
     1539EOF
Note: See TracChangeset for help on using the changeset viewer.