Index: /BOL/script_install/install_lmdz.sh
===================================================================
--- /BOL/script_install/install_lmdz.sh	(revision 3055)
+++ /BOL/script_install/install_lmdz.sh	(revision 3056)
@@ -89,4 +89,8 @@
 MODEL=""
 
+## also compile XIOS? (and more recent NetCDF/HDF5 libraries) Default=no
+with_xios="n"
+opt_makelmdz_xios=""
+
 #########################################################################
 #  Options interactives
@@ -116,6 +120,15 @@
     -name      LOCAL_MODEL_NAME : default = LMDZversion.release
 
+    -netcdf    PATH : full path to an existing installed NetCDF library
+               (without -netcdf: also download and install the NetCDF library)  
+    
+    -xios      also download and compile the XIOS library
+               (requires the NetCDF4-HDF5 library, also installed by default)
+               (requires to also have -parallel mpi_omp)
+
     -gprof     to compile with -pg to enable profiling with gprof
+
     -SCM        install 1D version automatically
+
     -opt_makelmdz     to call makelmdz or makelmdz_fcm with additional options
 ........fin
@@ -134,4 +147,6 @@
      "-bench") bench=$2 ; shift ; shift ;;
      "-name") MODEL=$2 ; shift ; shift ;;
+     "-netcdf") netcdf=$2 ; shift ; shift ;;
+     "-xios") with_xios="y" ; shift ;;
      *) ./install_lmdz.sh -h ; exit
    esac
@@ -169,16 +184,35 @@
             arch=X64_ADA ;;
 
+   cicla)   compilo="gfortran" ;
+            if [ $parallel != none ] ; then
+              module load openmpi/1.4.5-gfortran ;
+              root_mpi=$MPI_HOME ;
+              path_mpi=$root_mpi/bin ;
+              par_comp=${path_mpi}/mpif90 ;
+              mpirun=${path_mpi}/mpirun ;
+            fi ;
+            arch=local  ;
+            make=make ;
+            o_ins_make="-t g95" ;;
+            
    *)       compilo="gfortran" ;
             if [ $parallel = none -o -f /usr/bin/mpif90 ] ; then
                 path_mpi="" ;
-            # Pour les installations Scientifique Linux LMD ou ciclad :
+                if [ -d /usr/lib64/openmpi ] ; then
+                  root_mpi="/usr/lib64/openmpi"
+                else
+                  root_mpi="/usr"
+                fi
+            # For Scientifique Linux at LMD :
             elif [ -f /usr/lib64/openmpi/1.4.5-gfortran/bin/mpif90 ] ; then
-                path_mpi=/usr/lib64/openmpi/1.4.5-gfortran/bin/ ;
+                path_mpi=/usr/lib64/openmpi/1.4.5-gfortran/bin ;
+                root_mpi=/usr/lib64/openmpi/1.4.5-gfortran ;
+                export LD_LIBRARY_PATH=${root_mpi}/lib:$LD_LIBRARY_PATH
             else
-               echo Je ne trouve pas mpif90 ;
+               echo "Cannot find mpif90" ;
                exit ;
             fi ;
-            par_comp=${path_mpi}mpif90 ;
-            mpirun=${path_mpi}mpirun ;
+            par_comp=${path_mpi}/mpif90 ;
+            mpirun=${path_mpi}/mpirun ;
             arch=local  ;
             make=make ;
@@ -188,5 +222,5 @@
 
 # MPI_FLAGS are the flags needed for compilation with MPI
-MPI_FLAGS="-I/usr/include/openmpi-x86_64 -fcray-pointer"
+#MPI_FLAGS="-I/usr/include/openmpi-x86_64 -fcray-pointer"
 MPI_FLAGS="-fcray-pointer"
 # MPI_LD are the flags needed for linking with MPI
@@ -195,5 +229,5 @@
 OMP_FLAGS="-fopenmp -fcray-pointer"
 # OMP_LD are the flags needed for linking with OpenMP
-OMP_LD="-fopenmp -L/usr/lib64 -lnuma"
+#OMP_LD="-fopenmp -L/usr/lib64 -lnuma"
 OMP_LD="-fopenmp"
 
@@ -226,5 +260,12 @@
 #####################################################################
 
-
+## if also compiling XIOS, parallel must be mpi_omp
+if [ "$with_xios" = "y" -a "$parallel" != "mpi_omp" ] ; then 
+  echo "Error, you must set -parallel mpi_omp if you want XIOS"
+  exit
+fi
+if [ "$with_xios" = "y" ] ; then
+  opt_makelmdz_xios="-io xios"
+fi
 
 echo '################################################################'
@@ -394,18 +435,36 @@
 echo '##########################################################'
 cd $MODEL
-#wget http://www.lmd.jussieu.fr/~lmdz/Distrib/netcdf-4.0.1.tar.gz
-myget netcdf-4.0.1.tar.gz
-gunzip netcdf-4.0.1.tar.gz
-tar xvf netcdf-4.0.1.tar
-\rm -f netcdf-4.0.1.tar
-
-cd netcdf-4.0.1
-
-sed -e 's/gfortran/'$gfortran'/g' configure >| tmp ; mv -f tmp configure ; chmod +x configure
-localdir=`pwd -P`
-./configure --prefix=$localdir --enable-shared --disable-cxx
-sed -e 's/gfortran/'$gfortran'/g' Makefile >| tmp ; mv -f tmp Makefile
-$make check
-$make install
+if [ "$with_xios" = "n" ] ; then
+  # keep it simple
+  #wget http://www.lmd.jussieu.fr/~lmdz/Distrib/netcdf-4.0.1.tar.gz
+  myget netcdf-4.0.1.tar.gz
+  gunzip netcdf-4.0.1.tar.gz
+  tar xvf netcdf-4.0.1.tar
+  \rm -f netcdf-4.0.1.tar
+
+  cd netcdf-4.0.1
+
+  # seds to possibly use gfortran44 obsolete nowdays (Ehouarn: 10/2017)
+  #sed -e 's/gfortran/'$gfortran'/g' configure >| tmp ; mv -f tmp configure ; chmod +x configure
+  localdir=`pwd -P`
+  ./configure --prefix=$localdir --enable-shared --disable-cxx
+  #sed -e 's/gfortran/'$gfortran'/g' Makefile >| tmp ; mv -f tmp Makefile
+  $make check
+  $make install
+else
+  # download and compile hdf5 and netcdf, etc. using the install_netcdf4_hdf5.bash script
+  #wget http://www.lmd.jussieu.fr/~lmdz/Distrib/install_netcdf4_hdf5.bash
+  myget install_netcdf4_hdf5.bash
+  chmod u=rwx install_netcdf4_hdf5.bash
+  if [ "$compilo" = "gfortran" ] ; then
+  ./install_netcdf4_hdf5.bash -prefix $MODEL/netcdf4_hdf5 -CC gcc -FC gfortran -CXX g++ -MPI $root_mpi
+  elif [ "$compilo" = "ifort" ] ; then
+  ./install_netcdf4_hdf5.bash -prefix $MODEL/netcdf4_hdf5 -CC icc -FC ifort -CXX icpc -MPI $root_mpi
+  elif [ "$compilo" = "pgf90" ] ; then
+  ./install_netcdf4_hdf5.bash -prefix $MODEL/netcdf4_hdf5 -CC pgcc -FC pgf90 -CXX pgCC -MPI $root_mpi
+  else
+    echo "unexpected compiler $compilo" ; exit
+  fi
+fi  # of if [ "$with_xios" = "n" ]
 echo install.sh netcdf_OK `date`
 fi # of if [ $netcdf = 1 ]
@@ -420,7 +479,11 @@
 
 if [ $netcdf = 0 -o $netcdf = 1 ] ; then
-ncdfdir=$MODEL/netcdf-4.0.1
+  if [ "$with_xios" = "y" ] ; then
+  ncdfdir=$MODEL/netcdf4_hdf5
+  else
+  ncdfdir=$MODEL/netcdf-4.0.1
+  fi
 else
-ncdfdir=$netcdf
+  ncdfdir=$netcdf
 fi
 
@@ -523,4 +586,18 @@
   cd $MODEL/modipsl
   tar cf ioipsl.tar lib/ bin/
+
+#===========================================================================
+if [ "$with_xios" = "y" ] ; then
+  echo '##########################################################'
+  echo 'Compiling XIOS'
+  echo '##########################################################'
+  cd $MODEL/modipsl/modeles
+  #wget http://www.lmd.jussieu.fr/~lmdz/Distrib/install_xios.bash
+  myget install_xios.bash
+  chmod u=rwx install_xios.bash
+  ./install_xios.bash -prefix $MODEL/modipsl/modeles \
+                      -netcdf ${ncdfdir} -hdf5 ${ncdfdir} \
+                      -MPI $root_mpi -arch $arch
+fi
 
 #============================================================================
@@ -632,8 +709,8 @@
 
 
-cd $MODEL/modipsl/modeles/LMD*
+cd $MODEL/modipsl/modeles/LMDZ*
 
 ##################################################################
-# Mise a jour eventuelle de LMDZ en cas de specification de la release svn
+# Possibly update LMDZ if a specific svn release is requested
 ##################################################################
 
@@ -666,17 +743,17 @@
 # compiling in parallel mode
 if [ $parallel != "none" ] ; then
-echo '##########################################################'
-echo ' Parallel compile '
-echo '##########################################################'
-# saving the sequential libs and binaries
-cd $MODEL/modipsl
-tar cf sequential.tar bin/ lib/
-\rm -rf bin/ lib/
-tar xf ioipsl.tar
-# 
-# Orchidee
-#
-cd $ORCHPATH
-if [ -d src_parallel ] ; then
+  echo '##########################################################'
+  echo ' Parallel compile '
+  echo '##########################################################'
+  # saving the sequential libs and binaries
+  cd $MODEL/modipsl
+  tar cf sequential.tar bin/ lib/
+  \rm -rf bin/ lib/
+  tar xf ioipsl.tar
+  # 
+  # Orchidee
+  #
+  cd $ORCHPATH
+  if [ -d src_parallel ] ; then
      cd arch
      sed  \
@@ -691,5 +768,5 @@
      mv tmp.fcm arch-local.fcm
      cd ../
-# compiling ORCHIDEE parallel mode
+     # compiling ORCHIDEE parallel mode
      ./makeorchidee_fcm -j 8 -clean -noxios -prod -parallel $parallel -arch $arch
      ./makeorchidee_fcm -j 8 -noxios -prod -parallel $parallel -arch $arch
@@ -697,34 +774,35 @@
      echo ./makeorchidee_fcm -j 8 -noxios -prod -parallel $parallel -arch $arch
      echo deuxieme compilation orchidee ; pwd
-else
-  echo '##########################################################'
-  echo ' Orchidee version too old                                 '
-  echo ' Please update to new version                             '
-  echo '##########################################################'
-  exit
-fi
-# LMDZ
-cd $LMDZPATH
-     if [ $arch = local ] ; then
-     cd arch
-     sed -e s:"%COMPILER.*.$":"%COMPILER            $par_comp":1 \
-     -e s:"%LINK.*.$":"%LINK                $par_comp":1 \
-     -e s:"%MPI_FFLAG.*.$":"%MPI_FFLAGS          $MPI_FLAGS":1 \
-     -e s:"%OMP_FFLAG.*.$":"%OMP_FFLAGS          $OMP_FLAGS":1 \
-     -e s:"%MPI_LD.*.$":"%MPI_LD              $MPI_LD":1 \
-     -e s:"%OMP_LD.*.$":"%OMP_LD              $OMP_LD":1 \
-     arch-local.fcm > tmp.fcm
-     mv tmp.fcm arch-local.fcm
-     cd ../
-     fi
-     rm -f compile.sh
-     if [ ${hostname:0:5} = ada33 ] ; then echo "module load intel/2013.0" > compile.sh ; fi
-     echo resol=${grid_resolution} >> compile.sh
-     echo ./$makelmdz $OPT_MAKELMDZ -rrtm true -d \$resol -v $veget_version -mem -parallel $parallel gcm >> compile.sh
-     chmod +x ./compile.sh ; ./compile.sh
-
-     echo Compilation finished
-
-fi
+  else
+    echo '##########################################################'
+    echo ' Orchidee version too old                                 '
+    echo ' Please update to new version                             '
+    echo '##########################################################'
+    exit
+  fi # of if [ -d src_parallel ]
+  # LMDZ
+  cd $LMDZPATH
+  if [ $arch = local ] ; then
+    cd arch
+    sed -e s:"%COMPILER.*.$":"%COMPILER            $par_comp":1 \
+    -e s:"%LINK.*.$":"%LINK                $par_comp":1 \
+    -e s:"%MPI_FFLAG.*.$":"%MPI_FFLAGS          $MPI_FLAGS":1 \
+    -e s:"%OMP_FFLAG.*.$":"%OMP_FFLAGS          $OMP_FLAGS":1 \
+    -e s@"%BASE_LD.*.$"@"%BASE_LD             -Wl,-rpath=${root_mpi}/lib:${ncdfdir}/lib"@1 \
+    -e s:"%MPI_LD.*.$":"%MPI_LD              $MPI_LD":1 \
+    -e s:"%OMP_LD.*.$":"%OMP_LD              $OMP_LD":1 \
+    arch-local.fcm > tmp.fcm
+    mv tmp.fcm arch-local.fcm
+    cd ../
+  fi
+  rm -f compile.sh
+  if [ ${hostname:0:5} = ada33 ] ; then echo "module load intel/2013.0" > compile.sh ; fi
+  echo resol=${grid_resolution} >> compile.sh
+  echo ./$makelmdz $OPT_MAKELMDZ -rrtm true $opt_makelmdz_xios -d \$resol -v $veget_version -mem -parallel $parallel gcm >> compile.sh
+  chmod +x ./compile.sh ; ./compile.sh
+
+  echo "Compilation finished"
+  
+fi # of if [ $parallel != "none" ]
 
 echo LLLLLLLLLLLLLLLLLLLLLLLLLLL
@@ -748,5 +826,7 @@
 if [ "$gcm" = "" ] ; then
    echo 'Compilation failed !!'
-   exit
+   # Ehouarn : temporary, do not exit and let job finish (to set up bench case)
+   #exit
+   set +e
 else
    echo '##########################################################'
@@ -774,6 +854,30 @@
 tar xvf $bench.tar.gz
 
+if [ "$with_xios" = "y" ] ; then
+  cd BENCH${grid_resolution}
+  cp ../DefLists/iodef.xml .
+  cp ../DefLists/context_lmdz.xml .
+  cp ../DefLists/field_def_lmdz.xml .
+  cp ../DefLists/file_def_hist*xml .
+  # adapt iodef.xml to use attached mode
+  sed -e 's@"using_server" type="bool">true@"using_server" type="bool">false@' iodef.xml > tmp
+  \mv -f tmp iodef.xml
+  # and convert all the enabled="_AUTO_" (for libIGCM) to enabled=.FALSE.
+  # except for histday
+  for histfile in file_def_hist*xml
+  do
+    if [ "$histfile" = "file_def_histday_lmdz.xml" ] ; then
+    sed -e 's@enabled="_AUTO_"@type="one_file" enabled=".TRUE."@' $histfile > tmp ; \mv -f tmp $histfile
+    else
+    sed -e 's@enabled="_AUTO_"@type="one_file" enabled=".FALSE."@' $histfile > tmp ; \mv -f tmp $histfile
+    fi
+  done
+  # and add option "ok_all_xml=y" in config.def
+  echo "### XIOS outputs" >> config.def
+  echo 'ok_all_xml=.true.' >> config.def
+  cd ..
+fi
+
 cp $gcm BENCH${grid_resolution}/gcm.e
-
 
 cd BENCH${grid_resolution}
