source: BOL/script_install/install_lmdz.sh @ 4208

Last change on this file since 4208 was 4208, checked in by lguez, 2 years ago

Do not run the bench again if it is already there

  • Property svn:executable set to *
File size: 49.2 KB
Line 
1#!/bin/bash
2
3#set -vx
4
5###########################################################################
6# Author : Laurent Fairhead et Frédéric Hourdin
7# Usage  : install_lmdz.sh -help
8#
9# bash installation script of the LMDZ model on different computer types :
10# Linux PC, "mesocentre" (IPSL-UPMC, IPSL-X), super-computer (IDRIS)
11#
12# The model is downloaded in the following directory tree
13# $MODEL/modipsl/modeles/...
14# using the "modipsl" infrastructure created by the "IPSL"
15# for coupled (atmosphere/ocean/vegetation/chemistry) climate modeling
16# activities.
17# Here we only download atmospheric (LMDZ) and vegetation (ORCHIDEE)
18# components.
19#
20# The sources of the models can be found in the "modeles" directory.
21# In the present case, LMDZ, ORCHIDEE, and IOIPSL or XIOS (handling of input-outputs
22# using the NetCDF library).
23#
24# The script downloads various source files (including a version of NetCDF)
25# and utilities, compiles the model, and runs a test simulation in a
26# minimal configuration.
27#
28# Prerequisites : pgf90/gfortran, bash or ksh, wget , gunzip, tar, ...
29#
30# Modif 18/11/2011
31#    changes for option real 8.
32#      We compile with -r8 (or equivalent) and -DNC_DOUBLE for the GCM
33#      but with -r4 for netcdf. Variable real must be set to
34#      r4 or r8 at the beginning of the script below.
35#
36###########################################################################
37
38echo install_lmdz.sh DEBUT `date`
39set -e
40
41################################################################
42# Choice of installation options
43################################################################
44
45################################################################
46# A function to fetch files either locally or on the internet
47################################################################
48function myget { #1st and only argument should be file name
49  # 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 .
54  else
55    wget --no-check-certificate -nv http://lmdz.lmd.jussieu.fr/pub/$1
56    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 ; cp -r `basename $1` $dir
59    fi
60  fi
61}
62
63# 04_2021 : tester si r4 marche encore !
64#real=r4
65real=r8
66
67
68#########################################################################
69# Valeur par défaut des parametres
70#########################################################################
71svn=""
72#version=trunk
73version=20220131.trunk
74
75getlmdzor=1
76netcdf=1   #  1 for automatic installation
77           #  0 for no installation
78           #  /.../../netcdf-4.0.1 if wanting to link with an already
79           #  compiled netcdf library (implies to check option compatibility)
80check_linux=1
81ioipsl=1
82bench=1
83pclinux=1
84pcmac=0 # default: not on a Mac
85compiler=gfortran
86SCM=0
87# surface/vegetation scheme treatment
88# controlled by the single variable veget which can have the following values
89# - NONE: bucket scheme (default)
90# - CMIP6: orchidee version used in CMIP exercise, rev 5661
91# - number: orchidee version number
92veget=NONE
93# choose the resolution for the bench runs
94# grid_resolution= 32x24x11 or 48x36x19 for tests (test without ORCHIDEE)
95#                  96x71x19  standard configuration
96grid_resolution=144x142x79
97grid_resolution=96x95x39
98grid_resolution=48x36x19
99grid_resolution=32x32x39
100# choose the physiq version you want to test
101#physiq=NPv6.0.14splith
102physiq=
103
104## parallel can take the values none/mpi/omp/mpi_omp
105parallel=mpi_omp
106parallel=none
107idris_acct=lmd
108OPT_GPROF=""
109OPT_MAKELMDZ=""
110MODEL=""
111
112## also compile XIOS? (and more recent NetCDF/HDF5 libraries) Default=no
113with_xios="n"
114opt_makelmdz_xios=""
115
116## compile with oldrad/rrtm/ecrad radiatif code (Default=rrtm)
117rad=rrtm
118
119## compile_with_fcm=1 : use makelmdz_fcm (1) or makelmdz (0)
120compile_with_fcm=1
121
122#Compilation with Cosp (cosp=NONE/v1/v2 ; default=NONE)
123cosp=NONE
124opt_cosp=""
125
126# Check if on a Mac
127if [ `uname` = "Darwin" ]
128then
129    pcmac=1
130    export MAKE=make
131fi
132#echo "pcmac="$pcmac
133
134env_file=""
135
136#########################################################################
137#  Options interactives
138#########################################################################
139while (($# > 0))
140   do
141   case $1 in
142     "-h") cat <<........fin
143    $0 [ -v version ] [ -r svn_release ]
144           [ -parallel PARA ] [ -d GRID_RESOLUTION ] [ -bench 0/1 ]
145           [-name LOCAL_MODEL_NAME] [-gprof] [-opt_makelmdz] [-rad RADIATIF]
146
147    -v       "version" like 20150828.trunk
148             see http://www.lmd.jussieu.fr/~lmdz/Distrib/LISMOI.trunk
149
150    -r       "svn_release" : either the svn release number or "last"
151
152    -compiler gfortran|ifort|pgf90 (default: gfortran)
153
154    -parallel PARA : can be mpi_omp (mpi with openMP) or none (for sequential)
155
156    -d        GRID_RESOLUTION should be among the available benchs if -bench 1
157              among which : 48x36x19, 48x36x39
158              if wanting to run a bench simulation in addition to compilation
159              default : 48x36x19
160
161    -bench     activating the bench or not (0/1). Default 1
162
163    -name      LOCAL_MODEL_NAME : default = LMDZversion.release
164
165    -netcdf    PATH : full path to an existing installed NetCDF library
166               (without -netcdf: also download and install the NetCDF library)
167
168    -xios      also download and compile the XIOS library
169               (requires the NetCDF4-HDF5 library, also installed by default)
170               (requires to also have -parallel mpi_omp)
171
172    -gprof     to compile with -pg to enable profiling with gprof
173
174    -cosp      to run without our with cospv1 or cospv2 [none/v1/v2]
175
176    -rad RADIATIF can be oldrad, rrtm or ecrad radiatif code
177
178    -nofcm     to compile without fcm
179
180    -SCM        install 1D version automatically
181
182    -debug      compile everything in debug mode
183
184    -opt_makelmdz     to call makelmdz or makelmdz_fcm with additional options
185
186    -physiq    to choose which physics package to use
187
188    -env_file  specify an arch.env file to overwrite the existing one
189
190    -veget surface model to run [NONE/CMIP6/xxxx]
191
192........fin
193     exit ;;
194     "-v") version=$2 ; shift ; shift ;;
195     "-r") svn=$2 ; shift ; shift ;;
196     "-compiler") compiler=$2
197                  case $compiler in
198                    "gfortran"|"ifort"|"pgf90") compiler=$2 ; shift ; shift ;;
199                    *) echo "Only gfortran , ifort or pgf90 for the compiler option" ; exit
200                  esac ;;
201     "-d") grid_resolution=$2 ; shift ; shift ;;
202     "-gprof") OPT_GPROF="-pg" ; shift ;;
203     "-cosp") cosp=$2
204              case $cosp in
205                  "none"|"v1"|"v2") cosp=$2 ; shift ; shift ;;
206                  *) echo Only none v1 v2 for cosp option ; exit
207              esac ;;
208     "-nofcm") compile_with_fcm=0 ; shift ;;
209     "-SCM") SCM=1 ; shift ;;
210     "-opt_makelmdz") OPT_MAKELMDZ="$2" ; shift ; shift ;;
211     "-rrtm") rrtm="$2" ; if [ "$2" = "false" ] ; then rad="oldrad" ; else rad="rrtm" ; fi ; shift ; shift ;;
212     "-rad") rad=$2
213             case $rad in
214                "oldrad"|"rrtm"|"ecrad") rad=$2 ; shift ; shift ;;
215                *) echo Only oldrad rrtm ecrad for rad option ; exit
216             esac ;;
217     "-parallel") parallel=$2
218                  case $parallel in
219                    "none"|"mpi"|"omp"|"mpi_omp") parallel=$2 ; shift ; shift ;;
220                    *) echo Only none mpi omp mpi_omp for the parallel option ; exit
221                  esac ;;
222     "-bench") bench=$2 ; shift ; shift ;;
223     "-debug") optim=-debug ; shift ;;
224     "-name") MODEL=$2 ; shift ; shift ;;
225     "-netcdf") netcdf=$2 ; shift ; shift ;;
226     "-physiq") physiq=$2 ; shift ; shift ;;
227     "-xios") with_xios="y" ; shift ;;
228     "-env_file") env_file=$2 ; shift ; shift ;;
229     "-veget") veget=$2 ; shift ; shift ;;
230     *) ./install_lmdz.sh -h ; exit
231   esac
232done
233
234# Option de compilation du rayonnement : depend de $mysvn ><= r4185, sera donc definie plus bas
235#opt_rad=""
236#case $rad in
237#   rrtm) opt_rad="-rad rrtm" ;;
238#   ecrad) opt_rad="-rad ecrad" ;;
239#esac
240
241
242# Option de compilation pour Cosp
243opt_cosp=""
244case cosp in
245   v1) opt_cosp="-cosp true" ;;
246   v2) opt_cosp="-cospv2 true" ;;
247esac
248
249# Check on veget version
250#if [ "$veget" != 'NONE'  -a "$veget" != "CMIP6" -a "$veget" != +([0-9]) ] ; then
251if [ $veget != 'NONE'   -a $veget != "CMIP6" ] ; then
252    re='^[0-9]+$'
253    if ! [[ $veget =~ $re ]] ; then
254        echo 'Valeur de l option veget non valable'
255        exit
256    fi
257fi
258
259#Define veget-related suffix for gcm name
260if [ "$veget" = 'NONE' ] ; then
261    suff_orc=''
262    #For use with tutorial, orchidee_rev is also defined (will be written in surface_env at the end of the script)
263    orchidee_rev=''
264else
265    suff_orc='_orch'
266fi
267
268
269if [ $parallel = none ] ; then sequential=1; suff_exe='_seq' ; else sequential=0; suff_exe='_para_mem' ; fi
270
271#Chemin pour placer le modele
272if [ "$MODEL" = "" ] ; then MODEL=./LMDZ$version$svn$optim ; fi
273
274
275arch=local
276
277
278if [ $compiler = g95 ] ; then echo g95 is not supported anymore ; exit ; fi
279
280################################################################
281# Specificite des machines
282################################################################
283
284hostname=`hostname`
285if [ "$pclinux" = 1 ] ; then o_ins_make="-t g95" ; else o_ins_make="" ; fi
286
287case ${hostname:0:5} in
288
289   jean-)   compiler="mpiifort" ;
290            par_comp="mpiifort" ;
291            o_ins_make="-t jeanzay" ;
292            make=gmake ;
293            module purge
294            module load intel-compilers/19.0.4 ;
295            #module load intel-mpi/19.0.4 ;
296            #module load intel-mkl/19.0.4 ;
297            module load hdf5/1.10.5-mpi ;
298            module load netcdf/4.7.2-mpi ;
299            module load netcdf-fortran/4.5.2-mpi ;
300            module load subversion/1.9.7 ;
301            export NETCDF_LIBDIR=./
302            export NETCDFFORTRAN_INCDIR=./
303            export NETCDFFORTRAN_LIBDIR=./
304            arch=X64_JEANZAY ;;
305
306   cicla|camel)   compiler="gfortran" ;
307            if [ $parallel != none ] ; then
308              module load openmpi/1.6.5-gfortran ;
309              root_mpi=$MPI_HOME ;
310              path_mpi=$root_mpi/bin ;
311              par_comp=${path_mpi}/mpif90 ;
312              mpirun=${path_mpi}/mpirun ;
313            fi ;
314            arch=local  ;
315            make=make ;
316            o_ins_make="-t g95" ;;
317
318   *)       if [ $parallel = none -o -f /usr/bin/mpif90 ] ; then
319                path_mpi=`which mpif90 | sed -e s:/mpif90::` ;
320                if [ -d /usr/lib64/openmpi ] ; then
321                  root_mpi="/usr/lib64/openmpi"
322                else
323                  root_mpi="/usr"
324                fi
325            else
326               echo "Cannot find mpif90" ;
327               if [ $parallel = none ] ; then exit ; fi ;
328            fi ;
329            if [ $parallel != none ] ; then
330              root_mpi=$(which mpif90 | sed -e s:/bin/mpif90::)
331              path_mpi=$(which mpif90 | sed -e s:/mpif90::)
332              export LD_LIBRARY_PATH=${root_mpi}/lib:$LD_LIBRARY_PATH
333            fi
334            par_comp=${path_mpi}/mpif90 ;
335            mpirun=${path_mpi}/mpirun ;
336            arch=local  ;
337            make=make ;
338            o_ins_make="-t g95"
339esac
340
341# Flags for parallelism:
342if [ $parallel != none ] ; then
343  # MPI_LD are the flags needed for linking with MPI
344  MPI_LD="-L${root_mpi}/lib -lmpi"
345  if [ "$compiler" = "gfortran" ] ; then
346    # MPI_FLAGS are the flags needed for compilation with MPI
347    MPI_FLAGS="-fcray-pointer"
348    # OMP_FLAGS are the flags needed for compilation with OpenMP
349    OMP_FLAGS="-fopenmp -fcray-pointer"
350    # OMP_LD are the flags needed for linking with OpenMP
351    OMP_LD="-fopenmp"
352  elif [ "$compiler" = "ifort" ] ; then
353    MPI_FLAGS=""
354    OMP_FLAGS="-openmp"
355    OMP_LD="-openmp"
356  else # pgf90
357    MPI_FLAGS=""
358    OMP_FLAGS="-mp"
359    OMP_LD="-mp"
360  fi
361fi
362
363#####################################################################
364# Test for old gfortran compilers
365# If the compiler is too old (older than 4.3.x) we test if the
366# temporary gfortran44 patch is available on the computer in which
367# case the compiler is changed from gfortran to gfortran44
368# Must be aware than parallelism can not be activated in this case
369#####################################################################
370
371if [ "$compiler" = "gfortran" ] ; then
372   gfortran=gfortran
373   gfortranv=`gfortran --version | \
374   head -1 | awk ' { print $NF } ' | awk -F. ' { print $1 * 10 + $2 } '`
375   if [ $gfortranv -le 43 ] ; then
376       echo ERROR : Your gfortran compiler is too old
377       echo 'Please choose a new one (ifort) and change the line'
378       echo compiler=xxx
379       echo in the install_lmdz.sh script and rerun it
380       if [ `which gfortran44 | wc -w` -ne 0 ] ; then
381          gfortran=gfortran44
382       else
383          echo gfotran trop vieux ; exit
384       fi
385   fi
386   compiler=$gfortran
387fi
388#####################################################################
389
390## if also compiling XIOS, parallel must be mpi_omp
391if [ "$with_xios" = "y" -a "$parallel" != "mpi_omp" ] ; then
392  echo "Error, you must set -parallel mpi_omp if you want XIOS"
393  exit
394fi
395
396if [ "$with_xios" = "y" ] ; then
397  opt_makelmdz_xios="-io xios"
398fi
399
400if [ "$cosp" = "v2" -a "$with_xios" = "n" ] ; then
401  echo "Error, Cospv2 cannot run without Xios"
402  exit
403fi
404
405echo '################################################################'
406echo  Choix des options de compilation
407echo '################################################################'
408
409export FC=$compiler
410export F90=$compiler
411export F77=$compiler
412export CPPFLAGS=
413OPTIMNC=$OPTIM
414BASE_LD="$OPT_GPROF"
415OPTPREC="$OPT_GPROF"
416ARFLAGS="rs" ; if [ -f /etc/issue ] ; then if [ "`grep -i ubuntu /etc/issue`" != "" ] ; then if [ "`grep -i ubuntu /etc/issue | awk ' { print $2 } ' | cut -d. -f1`" -ge 16 ] ; then ARFLAGS="rU" ; fi ; fi ; fi
417
418
419
420if [ "$compiler" = "$gfortran" ] ; then
421   OPTIM='-O3'
422   OPTDEB="-g3 -Wall -fbounds-check -ffpe-trap=invalid,zero,overflow -O0 -fstack-protector-all -fbacktrace -finit-real=snan"
423   OPTDEV="-Wall -fbounds-check"
424   fmod='I '
425   OPTPREC="$OPTPREC -cpp -ffree-line-length-0"
426   if [ $real = r8 ] ; then OPTPREC="$OPTPREC -fdefault-real-8 -DNC_DOUBLE" ; fi
427   export F90FLAGS=" -ffree-form $OPTIMNC"
428   export FFLAGS=" $OPTIMNC"
429   export CC=gcc
430   export CXX=g++
431   export fpp_flags="-P -C -traditional -ffreestanding"
432
433elif [ $compiler = mpif90 ] ; then
434   OPTIM='-O3'
435   OPTDEB="-g3 -Wall -fbounds-check -ffpe-trap=invalid,zero,overflow -O0 -fstack-protector-all"
436   OPTDEV="-Wall -fbounds-check"
437   BASE_LD="$BASE_LD -lblas"
438   fmod='I '
439   if [ $real = r8 ] ; then OPTPREC="$OPTPREC -fdefault-real-8 -DNC_DOUBLE -fcray-pointer" ; fi
440   export F90FLAGS=" -ffree-form $OPTIMNC"
441   export FFLAGS=" $OPTIMNC"
442   export CC=gcc
443   export CXX=g++
444
445elif [ $compiler = pgf90 ] ; then
446   OPTIM='-O2 -Mipa -Munroll -Mnoframe -Mautoinline -Mcache_align'
447   OPTDEB='-g -Mdclchk -Mbounds -Mchkfpstk -Mchkptr -Minform=inform -Mstandard -Ktrap=fp -traceback'
448   OPTDEV='-g -Mbounds -Ktrap=fp -traceback'
449   fmod='module '
450   if [ $real = r8 ] ; then OPTPREC="$OPTPREC -r8 -DNC_DOUBLE" ; fi
451   export CPPFLAGS="-DpgiFortran"
452   export CC=pgcc
453   export CFLAGS="-O2 -Msignextend"
454   export CXX=pgCC
455   export CXXFLAGS="-O2 -Msignextend"
456   export FFLAGS="-O2 $OPTIMNC"
457   export F90FLAGS="-O2 $OPTIMNC"
458   compile_with_fcm=1
459
460elif [ $compiler = ifort ] ; then
461   OPTIM="-O2 -fp-model strict -ip -align all "
462   OPTDEV="-p -g -O2 -traceback -fp-stack-check -ftrapuv -check"
463   OPTDEB="-g -no-ftz -traceback -ftrapuv -fp-stack-check -check"
464   fmod='module '
465   if [ $real = r8 ] ; then OPTPREC="$OPTPREC -real-size 64 -DNC_DOUBLE" ; fi
466   export CPP="icc -E"
467   export FFLAGS="-O2 -ip -fpic -mcmodel=large"
468   export FCFLAGS="-O2 -ip -fpic -mcmodel=large"
469   export CC=icc
470   export CFLAGS="-O2 -ip -fpic -mcmodel=large"
471   export CXX=icpc
472   export CXXFLAGS="-O2 -ip -fpic -mcmodel=large"
473   export fpp_flags="-P -traditional"
474   # Pourquoi forcer la compilation fcm. Marche mieux sans
475   #compile_with_fcm=1
476
477elif [ $compiler = mpiifort ] ; then
478   echo on ne fait rien la
479   # Pourquoi forcer la compilation fcm. Marche mieux sans
480   #compile_with_fcm=1
481
482else
483   echo unexpected compiler $compiler ; exit
484fi
485
486OPTIMGCM="$OPTIM $OPTPREC"
487
488hostname=`hostname`
489
490##########################################################################
491# If installing on known machines such as Jean-Zay at IDRIS,
492# don't check for available software and don't install netcdf
493if [ ${hostname:0:5} = jean- ] ; then
494  netcdf=0 # no need to recompile netcdf, alreday available
495  check_linux=0
496  pclinux=0
497  ioipsl=0 # no need to recompile ioipsl, already available
498  #netcdf="/smplocal/pub/NetCDF/4.1.3"
499  compiler="mpiifort"
500  fmod='module '
501  if [ $real = r8 ] ; then OPTPREC="$OPTPREC -i4 -r8 -DNC_DOUBLE" ; fi
502  OPTIM="-auto -align all -O2 -fp-model strict -xHost "
503  OPTIMGCM="$OPTIM $OPTPREC"
504fi
505##########################################################################
506
507
508mkdir -p $MODEL
509echo $MODEL
510MODEL=`( cd $MODEL ; pwd )` # to get absolute path, if necessary
511
512
513echo '################################################################'
514if [ "$check_linux" = 1 ] ; then
515echo   Check if required software is available
516echo '################################################################'
517
518#### Ehouarn: test if the required shell is available
519#### Maj FH-LF-AS 2021-04 : default=bash ; if bash missing, use ksh
520use_shell="bash" # default
521if [ "`which bash`" = "" ] ; then
522  echo "no bash ; we will use ksh"
523  use_shell="ksh"
524  if [ "`which ksh`" = "" ] ; then
525    echo "bash (or ksh) needed!! Install it!"
526    exit
527  fi
528fi
529
530for logiciel in wget tar gzip make $compiler gcc ; do
531if [ "`which $logiciel`" = "" ] ; then
532echo You must first install $logiciel on your system
533exit
534fi
535done
536
537if [ $pclinux = 1 ] ; then
538cd $MODEL
539cat <<eod > tt.f90
540print*,'coucou'
541end
542eod
543$compiler tt.f90 -o a.out
544./a.out >| tt
545if [ "`cat tt | sed -e 's/ //g' `" != "coucou" ] ; then
546echo problem installing with compiler $compiler ; exit ; fi
547\rm tt a.out tt.f90
548fi
549fi
550
551###########################################################################
552if [ $getlmdzor = 1 -a ! -d $MODEL/modipsl ] ; then
553###########################################################################
554   echo '##########################################################'
555   echo  Download a slightly modified version of  LMDZ
556   echo '##########################################################'
557   cd $MODEL
558   myget src/modipsl.$version.tar.gz
559   echo install_lmdz.sh wget_OK `date`
560   gunzip modipsl.$version.tar.gz
561   tar xf modipsl.$version.tar
562   \rm modipsl.$version.tar
563fi
564
565###########################################################################
566if [ $netcdf = 1 -a ! -d $MODEL/netcdf ] ; then
567###########################################################################
568   cd $MODEL
569   netcdflog=`pwd`/netcdf.log
570   echo '##########################################################'
571   echo Compiling the Netcdf library
572   echo '##########################################################'
573   echo log file : $netcdflog
574   if [ "$with_xios" = "n" ] ; then
575      # keep it simple
576      #wget http://www.lmd.jussieu.fr/~lmdz/Distrib/netcdf-4.0.1.tar.gz
577      myget import/netcdf-4.0.1.tar.gz
578      gunzip netcdf-4.0.1.tar.gz
579      tar xvf netcdf-4.0.1.tar
580      \rm -f netcdf-4.0.1.tar
581   
582      cd netcdf-4.0.1
583   
584      localdir=`pwd -P`
585      ./configure --prefix=$localdir --enable-shared --disable-cxx
586      #sed -e 's/gfortran/'$gfortran'/g' Makefile >| tmp ; mv -f tmp Makefile
587      $make check > $netcdflog 2>&1
588      $make install >> $netcdflog 2>&1
589    #LF rajout d'une verrue, pour une raison non encore expliquee, la librairie est parfois rangée dans lib64
590    #   et non dans lib par certains compilateurs
591      if [ ! -e lib -a -d lib64 ] ; then ln -s lib64 lib; fi
592   else
593      # download and compile hdf5 and netcdf, etc. using the install_netcdf4_hdf5.bash script
594      #wget http://www.lmd.jussieu.fr/~lmdz/Distrib/install_netcdf4_hdf5.bash
595      myget import/install_netcdf4_hdf5.bash
596      chmod u=rwx install_netcdf4_hdf5.bash
597      if [ "$compiler" = "gfortran" ] ; then
598      ./install_netcdf4_hdf5.bash -prefix $MODEL/netcdf4_hdf5 -CC gcc -FC gfortran -CXX g++ -MPI $root_mpi  > $netcdflog 2>&1
599      elif [ "$compiler" = "ifort" ] ; then
600      ./install_netcdf4_hdf5.bash -prefix $MODEL/netcdf4_hdf5 -CC icc -FC ifort -CXX icpc -MPI $root_mpi  > $netcdflog 2>&1
601      elif [ "$compiler" = "pgf90" ] ; then
602      ./install_netcdf4_hdf5.bash -prefix $MODEL/netcdf4_hdf5 -CC pgcc -FC pgf90 -CXX pgCC -MPI $root_mpi  > $netcdflog 2>&1
603      else
604        echo "unexpected compiler $compiler" ; exit
605      fi
606   fi  # of if [ "$with_xios" = "n" ]
607   echo install_lmdz.sh netcdf_OK `date`
608fi # of if [ $netcdf = 1 ]
609
610# ncdfdir contains the directory where netcdf is installed
611if [ $netcdf = 0 -o $netcdf = 1 ] ; then
612   if [ "$with_xios" = "y" ] ; then
613      ncdfdir=$MODEL/netcdf4_hdf5
614   else
615      ncdfdir=$MODEL/netcdf-4.0.1
616   fi
617else
618   ncdfdir=$netcdf
619fi
620
621#=========================================================================
622if [[ ! -f $MODEL/modipsl/lib/libioipsl.a ]]
623then
624if [ $ioipsl = 1 ] ; then
625#=========================================================================
626   echo OK ioipsl=$ioipsl
627   echo '##########################################################'
628   echo 'Installing MODIPSL, the installation package manager for the '
629   echo 'IPSL models and tools'
630   echo '##########################################################'
631   echo `date`
632
633   cd $MODEL/modipsl
634   \rm -rf lib/*
635   cd util
636   cp AA_make.gdef AA_make.orig
637   F_C="$compiler -c " ; if [ "$compiler" = "$gfortran" -o "$compiler" = "mpif90" ] ; then F_C="$compiler -c -cpp " ; fi
638   if [ "$compiler" = "pgf90" ] ; then F_C="$compiler -c -Mpreprocess" ; fi
639   sed -e 's/^\#.*.g95.*.\#.*.$/\#/' AA_make.gdef > tmp
640   sed -e "s:F_L = g95:F_L = $compiler:" -e "s:F_C = g95 -c -cpp:F_C = $F_C": \
641   -e 's/g95.*.w_w.*.(F_D)/g95      w_w = '"$OPTIMGCM"'/' \
642   -e 's:g95.*.NCDF_INC.*.$:g95      NCDF_INC= '"$ncdfdir"'/include:' \
643   -e 's:g95.*.NCDF_LIB.*.$:g95      NCDF_LIB= -L'"$ncdfdir"'/lib -lnetcdff -lnetcdf:' \
644   -e 's:g95      L_O =:g95      L_O = -Wl,-rpath='"$ncdfdir"'/lib:' \
645   -e "s:-fmod=:-$fmod:" -e 's/-fno-second-underscore//' \
646   -e 's:#-Q- g95      M_K = gmake:#-Q- g95      M_K = make:' \
647   tmp >| AA_make.gdef
648
649   if [ $pcmac == 1 ]
650   then
651       cp AA_make.gdef tmp
652       sed -e 's/rpath=/rpath,/g' tmp > AA_make.gdef
653   fi
654
655
656 # We use lines for g95 even for the other compilers to run ins_make
657   if [ "$use_shell" = "ksh" ] ; then
658     ./ins_make $o_ins_make
659   else # bash
660     sed -e s:/bin/ksh:/bin/bash:g ins_make > ins_make.bash
661     if [ "`grep jeanzay AA_make.gdef`" = "" ] ; then # Bidouille pour compiler sur ada des vieux modipsl.tar
662         echo 'Warning jean-zay not in AA_make.gdef'
663         echo 'Think about updating'
664         exit 1
665     fi
666
667     chmod u=rwx ins_make.bash
668     ./ins_make.bash $o_ins_make
669   fi # of if [ "$use_shell" = "ksh" ]
670
671   echo install_lmdz.sh MODIPSL_OK `date`
672
673   cd $MODEL/modipsl/modeles/IOIPSL/src
674   ioipsllog=`pwd`/ioipsl.log
675   echo '##########################################################'
676   echo 'Compiling IOIPSL, the interface library with Netcdf'
677   echo '##########################################################'
678   echo `date`
679   echo log file : $ioipsllog
680
681   if [ "$use_shell" = "bash" ] ; then
682     cp Makefile Makefile.ksh
683     sed -e s:/bin/ksh:/bin/bash:g Makefile.ksh > Makefile
684   fi
685 # if [ "$pclinux" = 1 ] ; then
686     # Build IOIPSL modules and library
687     $make clean
688     $make > $ioipsllog 2>&1
689     if [ "$compiler" = "$gfortran" -o "$compiler" = "mpif90" ] ; then # copy module files to lib
690       cp -f *.mod ../../../lib
691     fi
692     # Build IOIPSL tools (ie: "rebuild", if present)
693     if [ -f $MODEL/modipsl/modeles/IOIPSL/tools/rebuild ] ; then
694       cd $MODEL/modipsl/modeles/IOIPSL/tools
695       # adapt Makefile & rebuild script if in bash
696       if [ "$use_shell" = "bash" ] ; then
697         cp Makefile Makefile.ksh
698         sed -e s:/bin/ksh:/bin/bash:g Makefile.ksh > Makefile
699         cp rebuild rebuild.ksh
700         sed -e 's:/bin/ksh:/bin/bash:g' \
701             -e 's:print -u2:echo:g' \
702             -e 's:print:echo:g' rebuild.ksh > rebuild
703       fi
704       $make clean
705       $make > $ioipsllog 2>&1
706     fi
707# fi # of if [ "$pclinux" = 1 ]
708
709else # of if [ $ioipsl = 1 ]
710   if [ ${hostname:0:5} = jean- ] ; then
711      cd $MODEL/modipsl
712      cd util
713        if [ "`grep jeanzay AA_make.gdef`" = "" ] ; then
714         echo 'Warning jean-zay not in AA_make.gdef'
715         echo 'Think about updating'
716         exit 1
717        fi
718        ./ins_make $o_ins_make
719# Compile IOIPSL on jean-zay
720        cd $MODEL/modipsl/modeles/IOIPSL/src
721        gmake > ioipsl.log
722        cd $MODEL/modipsl/modeles/IOIPSL/tools
723        gmake > ioipsl.log
724
725   fi
726   echo install_lmdz.sh ioipsl_OK `date`
727fi # of if [ $ioipsl = 1 ]
728fi
729# Saving ioipsl lib for possible parallel compile
730  cd $MODEL/modipsl
731  tar cf ioipsl.tar lib/ bin/
732
733#=========================================================================
734if [ "$with_xios" = "y" ] ; then
735  echo '##########################################################'
736  echo 'Compiling XIOS'
737  echo '##########################################################'
738  cd $MODEL/modipsl/modeles
739  xioslog=`pwd`/xios.log
740  #wget http://www.lmd.jussieu.fr/~lmdz/Distrib/install_xios.bash
741  myget import/install_xios.bash
742  chmod u=rwx install_xios.bash
743  if [ ${hostname:0:5} = jean- ] ; then
744     svn co http://forge.ipsl.jussieu.fr/ioserver/svn/XIOS/branchs/xios-2.5 XIOS
745     cd XIOS/arch
746     svn update
747     cd ..
748     echo "Compiling XIOS, start" `date` "(it takes about 20 min on Jean-Zay)"
749     echo "log file: $xioslog"
750     ./make_xios --prod --arch $arch --job 4 > xios.log 2>&1
751  else
752     ./install_xios.bash -prefix $MODEL/modipsl/modeles \
753                      -netcdf ${ncdfdir} -hdf5 ${ncdfdir} \
754                      -MPI $root_mpi -arch $arch > xios.log 2>&1
755  fi # of case Jean-Zay
756  if [ -f XIOS/lib/libxios.a ] ; then
757     echo "XIOS library successfully generated"
758     echo install_lmdz.sh XIOS_OK `date`
759  fi
760fi
761
762#============================================================================
763veget_version=false
764if [ "$veget" != 'NONE' ] ; then
765  cd $MODEL/modipsl/modeles/ORCHIDEE
766  set +e ; svn upgrade ; set -e
767  if [ "$veget" = "CMIP6" ] ; then
768    veget_version=orchidee2.0
769    orchidee_rev=6592
770  else # specific orchidee revision newer than CMIP6, on 2_1 or 2_2 branches
771    veget_version=orchidee2.1
772    orchidee_rev=$veget
773     if [ $veget -lt 4465 ] ; then
774             echo 'Stopping, ORCHIDEE version too old, script needs work on the CPP flags to pass to makelmdz'
775             exit 1
776     fi
777     set +e
778     # which branch is my version on?
779     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}'`
780     # switch to that branch
781     echo IF YOU INSTALL ORCHIDEE THE VERY FIRST TIME, ASK for PASSWORD at orchidee-help@listes.ipsl.fr
782     svn switch -r $veget --accept theirs-full svn://forge.ipsl.jussieu.fr/orchidee/$orcbranch
783     svn log -r $veget | grep  $veget
784     if [  $? -gt 0 ] ; then
785          echo 'Cannot update ORCHIDEE as not on the right branch for ORCHIDEE'
786          exit
787      fi
788      set -e
789      set +e ; svn update -r $veget ; set -e
790  fi
791  # Correctif suite debug Jean-Zay
792  sed -i -e 's/9010  FORMAT(A52,F17.14)/9010  FORMAT(A52,F20.14)/' src_stomate/stomate.f90
793  opt_orc="-prod" ; if [ "$optim" = "-debug" ] ; then opt_orc="-debug" ; fi
794
795  orchideelog=`pwd`/orchidee.log
796  echo '########################################################'
797  echo 'Compiling ORCHIDEE, the continental surface model '
798  echo '########################################################'
799  echo Start of the first compilation of orchidee, in sequential mode: `date`
800  echo log file : $orchideelog
801
802  export ORCHPATH=`pwd`
803  xios_orchid="-noxios"
804  if [ "$with_xios" = "y" ] ; then
805    xios_orchid="-xios"
806  fi
807  if [ -d tools ] ; then
808###################################################################
809# Pour les experts qui voudraient changer de version d'orchidee.
810# Attention : necessite d'avoir le password pour orchidee
811
812      # Correctif suite debug Jean-Zay
813      if [ -f src_global/time.f90 ] ; then sed -i -e 's/CALL tlen2itau/\!CALL tlen2itau/' src_global/time.f90 ; fi
814###################################################################
815     if [ "$veget_version" == "false" ] ; then veget_version=orchidee2.0 ; fi
816      cd arch
817      sed -e s:"%COMPILER        .*.$":"%COMPILER            $compiler":1 \
818     -e s:"%LINK            .*.$":"%LINK                $compiler":1 \
819     -e s:"%FPP_FLAGS       .*.$":"%FPP_FLAGS           $fpp_flags":1 \
820     -e s:"%PROD_FFLAGS     .*.$":"%PROD_FFLAGS         $OPTIM":1 \
821     -e s:"%DEV_FFLAGS      .*.$":"%DEV_FFLAGS          $OPTDEV":1 \
822     -e s:"%DEBUG_FFLAGS    .*.$":"%DEBUG_FFLAGS        $OPTDEB":1 \
823     -e s:"%BASE_FFLAGS     .*.$":"%BASE_FFLAGS         $OPTPREC":1 \
824     -e s:"%BASE_LD         .*.$":"%BASE_LD             $BASE_LD":1 \
825     -e s:"%ARFLAGS         .*.$":"%ARFLAGS             $ARFLAGS":1 \
826     arch-gfortran.fcm > arch-local.fcm
827     echo "NETCDF_LIBDIR=\"-L${ncdfdir}/lib -lnetcdff -lnetcdf\"" > arch-local.path
828     echo "NETCDF_INCDIR=${ncdfdir}/include" >> arch-local.path
829     echo "IOIPSL_INCDIR=$ORCHPATH/../../lib" >> arch-local.path
830     echo "IOIPSL_LIBDIR=$ORCHPATH/../../lib" >> arch-local.path
831     echo 'XIOS_INCDIR=${ORCHDIR}/../XIOS/inc' >> arch-local.path
832     echo 'XIOS_LIBDIR="${ORCHDIR}/../XIOS/lib -lxios"' >> arch-local.path
833     cd ../
834
835     echo ./makeorchidee_fcm -j $xios_orchid $opt_orc -parallel none -arch $arch
836     ./makeorchidee_fcm -j 8 $xios_orchid $opt_orc -parallel none -arch $arch > $orchideelog 2>&1
837     pwd
838  else # of "if [ -d tools ]"
839     if [ -d src_parallel ] ; then
840       liste_src="parallel parameters global stomate sechiba driver"
841       if [ "$veget_version" == "false" ] ; then veget_version=orchidee2.0 ; fi
842     fi
843     for d in $liste_src ; do src_d=src_$d
844        echo src_d $src_d
845        echo ls ; ls
846        if [ ! -d $src_d ] ; then echo Problem orchidee : no $src_d ; exit ; fi
847        cd $src_d ; \rm -f *.mod make ; $make clean
848        $make > $orchideelog 2>&1 ; if [ "$compiler" = "$gfortran" -o "$compiler" = "mpif90" ] ; then cp -f *.mod ../../../lib ; fi
849        cd ..
850     done
851  fi # of "if [ -d tools ]"
852  echo install_lmdz.sh orchidee_compil_seq_OK `date`
853fi # of if [ "$veget" != 'NONE' ]
854
855
856#============================================================================
857# Ehouarn: the directory name LMDZ* depends on version/tar file...
858if [ -d $MODEL/modipsl/modeles/LMD* ] ; then
859  echo '###############################################################'
860  echo 'Preparing LMDZ compilation : arch file, svn switch if needed...'
861  echo '###############################################################'
862  cd $MODEL/modipsl/modeles/LMD*
863  LMDZPATH=`pwd`
864else
865  echo "ERROR: No LMD* directory !!!"
866  exit
867fi
868
869###########################################################
870# For those who want to use fcm to compile via :
871#  makelmdz_fcm -arch local .....
872############################################################
873
874if [ "$pclinux" = "1" ] ; then
875
876# create local 'arch' files (if on Linux PC):
877cd arch
878# arch-local.path file
879echo "NETCDF_LIBDIR=\"-L${ncdfdir}/lib -lnetcdff -lnetcdf\"" > arch-local.path
880echo "NETCDF_INCDIR=-I${ncdfdir}/include" >> arch-local.path
881echo 'IOIPSL_INCDIR=$LMDGCM/../../lib' >> arch-local.path
882echo 'IOIPSL_LIBDIR=$LMDGCM/../../lib' >> arch-local.path
883echo 'XIOS_INCDIR=$LMDGCM/../XIOS/inc' >> arch-local.path
884echo 'XIOS_LIBDIR=$LMDGCM/../XIOS/lib' >> arch-local.path
885echo 'ORCH_INCDIR=$LMDGCM/../../lib' >> arch-local.path
886echo 'ORCH_LIBDIR=$LMDGCM/../../lib' >> arch-local.path
887
888if [ $pcmac == 1 ] ; then
889    BASE_LD="$BASE_LD -Wl,-rpath,${ncdfdir}/lib"
890else
891    BASE_LD="$BASE_LD -Wl,-rpath=${ncdfdir}/lib"
892fi
893# Arch-local.fcm file (adapted from arch-linux-32bit.fcm)
894
895if [ $real = r8 ] ; then FPP_DEF=NC_DOUBLE ; else FPP_DEF="" ; fi
896sed -e s:"%COMPILER        .*.$":"%COMPILER            $compiler":1 \
897    -e s:"%LINK            .*.$":"%LINK                $compiler":1 \
898    -e s:"%PROD_FFLAGS     .*.$":"%PROD_FFLAGS         $OPTIM":1 \
899    -e s:"%DEV_FFLAGS      .*.$":"%DEV_FFLAGS          $OPTDEV":1 \
900    -e s:"%DEBUG_FFLAGS    .*.$":"%DEBUG_FFLAGS        $OPTDEB":1 \
901    -e s:"%BASE_FFLAGS     .*.$":"%BASE_FFLAGS         $OPTPREC":1 \
902    -e s:"%FPP_DEF         .*.$":"%FPP_DEF             $FPP_DEF":1 \
903    -e s:"%BASE_LD         .*.$":"%BASE_LD             $BASE_LD":1 \
904    -e s:"%ARFLAGS         .*.$":"%ARFLAGS             $ARFLAGS":1 \
905    arch-linux-32bit.fcm > arch-local.fcm
906
907cd ..
908### Adapt "bld.cfg" (add the shell):
909#whereisthatshell=$(which ${use_shell})
910#echo "bld::tool::SHELL   $whereisthatshell" >> bld.cfg
911
912fi # of if [ "$pclinux" = 1 ]
913
914
915cd $MODEL/modipsl/modeles/LMDZ*
916lmdzlog=`pwd`/lmdz.log
917
918##################################################################
919# Possibly update LMDZ if a specific svn release is requested
920##################################################################
921
922set +e ; svn upgrade ; set -e
923
924if [ "$svn" = "last" ] ; then svnopt="" ; else svnopt="-r $svn" ; fi
925if [ "$svn" != "" ] ; then
926    set +e ; svn info | grep -q 'http:'
927    if [ $? = 0 ] ; then
928        svn switch --relocate http://svn.lmd.jussieu.fr/LMDZ https://svn.lmd.jussieu.fr/LMDZ
929    fi
930    svn update $svnopt
931fi
932set -e
933
934##################################################################
935# Retrieve the final svn release number, and adjust compilation options accordingly
936mysvn=`svnversion . | egrep -o "[0-9]+"`
937
938# Option de compilation du rayonnement : depend de $mysvn ><= r4185
939opt_rad=""
940
941case $rad in
942    oldrad) iflag_rrtm=0 ; NSW=2 ; opt_rad="" ;;
943    rrtm)   iflag_rrtm=1 ; NSW=6 ; if [ $mysvn -le 4185 ] ; then opt_rad="-rrtm true" ; else opt_rad="-rad rrtm" ; fi ;;
944    ecrad)  iflag_rrtm=2 ; NSW=6 ; opt_rad="-rad ecrad" ;;
945    *) echo Only oldrad rrtm ecrad for rad option ; exit
946esac
947
948if [ $mysvn -le 4185 -a $rad = "ecrad" ] ; then echo "ecrad only available for LMDZ rev starting with 4186 " ; exit ; fi
949
950##################################################################
951
952echo '##################################################################'
953echo "Preparing script compile.sh for LMDZ compilation"
954echo "It will only be run automatically if bench=1/tuto"
955echo Here bench=$bench
956echo '##################################################################'
957
958if [ "$env_file" != "" ] ; then mv arch/arch-${arch}.env arch/arch-${arch}.orig ; \cp -f $env_file arch/arch-${arch}.env ; fi
959
960if [ $compile_with_fcm = 1 ] ; then makelmdz="makelmdz_fcm $optim -arch $arch -j 8 " ; else makelmdz="makelmdz $optim -arch $arch" ; fi
961
962# sequential compilation
963if [ "$sequential" = 1 ] ; then
964  echo Sequential compilation command, saved in compile.sh:
965  echo "./$makelmdz $optim $OPT_MAKELMDZ $optim $opt_rad $opt_cosp -d ${grid_resolution} -v $veget_version gcm "
966  echo "./$makelmdz $optim $OPT_MAKELMDZ $optim $opt_rad $opt_cosp -d ${grid_resolution} -v $veget_version gcm " >> compile.sh
967  chmod +x ./compile.sh
968  if [ $bench = 1 ] ; then
969    echo install_lmdz.sh start_lmdz_seq_compilation `date`
970    echo log file: $lmdzlog
971    ./compile.sh > $lmdzlog 2>&1
972    echo install_lmdz.sh end_lmdz_seq_compilation `date`
973  fi
974fi # fin sequential
975
976# compiling in parallel mode
977if [ $parallel != "none" ] ; then
978  echo '##########################################################'
979  echo ' Parallel compile '
980  echo '##########################################################'
981  echo "(after saving the sequential libs and binaries)"
982  cd $MODEL/modipsl
983  tar cf sequential.tar bin/ lib/
984  \rm -rf bin/ lib/
985  tar xf ioipsl.tar
986  #
987  # Orchidee
988  #
989  cd $ORCHPATH
990  if [ -d src_parallel -a $veget != 'NONE' ] ; then
991     cd arch
992     sed  \
993     -e s:"%COMPILER.*.$":"%COMPILER            $par_comp":1 \
994     -e s:"%LINK.*.$":"%LINK                $par_comp":1 \
995     -e s:"%MPI_FFLAG.*.$":"%MPI_FFLAGS          $MPI_FLAGS":1 \
996     -e s:"%OMP_FFLAG.*.$":"%OMP_FFLAGS          $OMP_FLAGS":1 \
997     -e s:"%MPI_LD.*.$":"%MPI_LD              $MPI_LD":1 \
998     -e s:"%OMP_LD.*.$":"%OMP_LD              $OMP_LD":1 \
999     arch-local.fcm > tmp.fcm
1000
1001     mv tmp.fcm arch-local.fcm
1002     cd ../
1003     echo Compiling ORCHIDEE in parallel mode `date`
1004     echo logfile $orchideelog
1005     echo "NOTE : to recompile it when necessary, use ./compile_orc.sh in modipsl/modeles/ORCHIDEE"
1006     echo ./makeorchidee_fcm -j 8 -clean $xios_orchid $opt_orc -parallel $parallel -arch $arch > compile_orc.sh
1007     echo ./makeorchidee_fcm -j 8 $xios_orchid $opt_orc -parallel $parallel -arch $arch >> compile_orc.sh
1008     echo echo Now you must also recompile LMDZ, by running ./compile.sh in modeles/LMDZ >> compile_orc.sh
1009     chmod u+x compile_orc.sh
1010     ./makeorchidee_fcm -j 8 -clean $xios_orchid $opt_orc -parallel $parallel -arch $arch > $orchideelog 2>&1
1011     ./makeorchidee_fcm -j 8 $xios_orchid $opt_orc -parallel $parallel -arch $arch >> $orchideelog 2>&1
1012     echo End of ORCHIDEE compilation in parallel mode `date`
1013  elif [ $veget != 'NONE' ] ; then
1014    echo '##########################################################'
1015    echo ' Orchidee version too old                                 '
1016    echo ' Please update to new version                             '
1017    echo '##########################################################'
1018    exit
1019  fi # of [ -d src_parallel -a $veget != 'NONE' ]
1020
1021  # LMDZ
1022  cd $LMDZPATH
1023  if [ $arch = local ] ; then
1024    cd arch
1025    sed -e s:"%COMPILER.*.$":"%COMPILER            $par_comp":1 \
1026    -e s:"%LINK.*.$":"%LINK                $par_comp":1 \
1027    -e s:"%MPI_FFLAG.*.$":"%MPI_FFLAGS          $MPI_FLAGS":1 \
1028    -e s:"%OMP_FFLAG.*.$":"%OMP_FFLAGS          $OMP_FLAGS":1 \
1029    -e s:"%ARFLAGS.*.$":"%ARFLAGS          $ARFLAGS":1 \
1030    -e s@"%BASE_LD.*.$"@"%BASE_LD             -Wl,-rpath=${root_mpi}/lib:${ncdfdir}/lib"@1 \
1031    -e s:"%MPI_LD.*.$":"%MPI_LD              $MPI_LD":1 \
1032    -e s:"%OMP_LD.*.$":"%OMP_LD              $OMP_LD":1 \
1033    arch-local.fcm > tmp.fcm
1034    mv tmp.fcm arch-local.fcm
1035    cd ../
1036  fi
1037  rm -f compile.sh
1038  echo resol=${grid_resolution} >> compile.sh
1039  if [ ${hostname:0:5} = jean- -a "$cosp" = "v2" ] ; then
1040
1041  echo LMDZ compilation command in parallel mode, saved in compile.sh, is :
1042  echo "(ATTENTION le probleme de cospv2 sur jean-zay en mode prod n est pas corrige ! )"
1043# ATTENTION le probleme de cospv2 sur jean-zay en mode prod n est pas corrige
1044     echo ./$makelmdz -dev $optim $OPT_MAKELMDZ $opt_rad $opt_cosp $opt_makelmdz_xios -d \$resol -v $veget_version -mem -parallel $parallel gcm >> compile.sh
1045     echo ./$makelmdz -dev $optim $OPT_MAKELMDZ $opt_rad $opt_cosp $opt_makelmdz_xios -d \$resol -v $veget_version -mem -parallel $parallel gcm
1046  else
1047    echo ./$makelmdz $optim $OPT_MAKELMDZ $opt_rad $opt_cosp $opt_makelmdz_xios -d \$resol -v $veget_version -mem -parallel $parallel gcm >> compile.sh
1048    echo ./$makelmdz $optim $OPT_MAKELMDZ $opt_rad $opt_cosp $opt_makelmdz_xios -d \$resol -v $veget_version -mem -parallel $parallel gcm
1049  fi
1050  chmod +x ./compile.sh
1051
1052  if [ $bench = 1 ] ; then
1053     echo Compiling LMDZ in parallel mode `date`,  LMDZ log file: $lmdzlog ; ./compile.sh > $lmdzlog 2>&1
1054  fi
1055
1056fi # of if [ $parallel != "none" ]
1057
1058
1059##################################################################
1060# Verification du succes de la compilation
1061##################################################################
1062
1063# Recherche de l'executable dont le nom a change au fil du temps ...
1064# suffix contains radiative option starting with revision 4186
1065if [ $mysvn -ge 4186 ] ; then suff_exe=_${rad}${suff_exe} ; fi
1066gcm=""
1067#for exe in gcm.e bin/gcm_${grid_resolution}_phylmd_seq_orch.e bin/gcm_${grid_resolution}_phylmd_seq.e bin/gcm_${grid_resolution}_phylmd_para_mem_orch.e bin/gcm_${grid_resolution}_phylmd_para_mem.e  ; do
1068for exe in gcm.e bin/gcm_${grid_resolution}_phylmd${suff_exe}${suff_orc}.e ; do   if [ -f $exe ] ; then gcm=$exe ; fi
1069done
1070
1071if [ "$gcm" = "" ] ; then
1072  if [ $bench = 1 ] ; then
1073    echo 'Compilation failed !! Cannot run the benchmark;'
1074    exit
1075  else
1076    echo 'Compilation not done (only done when bench=1)'
1077  fi
1078else
1079   echo '##########################################################'
1080   echo 'Compilation successfull !! ' `date`
1081   echo '##########################################################'
1082   echo The executable is $gcm
1083fi
1084
1085##################################################################
1086# Below, we run a benchmark if bench=1 or tuto
1087##################################################################
1088
1089if [ $bench = tuto ] ; then
1090   myget Training/tutorial.tar ; tar xvf tutorial.tar ; cd TUTORIAL ; ./init.sh
1091
1092elif [[ $bench = 1 && ! -d BENCH${grid_resolution} ]] ; then
1093   # TOUTE CETTE SECTION DEVRAIT DISPARAITRE POUR UNE COMMANDE
1094   # OU DES BENCHS PAR MOTS CLES COMME tuto
1095
1096   echo '##########################################################'
1097   echo ' Running a test run '
1098   echo '##########################################################'
1099
1100   \rm -rf BENCH${grid_resolution}
1101   bench=bench_lmdz_${grid_resolution}
1102   echo install_lmdz.sh before bench download  `date`
1103   #wget http://www.lmd.jussieu.fr/~lmdz/Distrib/$bench.tar.gz
1104   myget 3DBenchs/$bench.tar.gz
1105   echo install_lmdz.sh after bench download  `date`
1106   tar xvf $bench.tar.gz
1107
1108   if [ "$cosp" = "v1" -o "$cosp" = "v2" ] ; then
1109     cd BENCH${grid_resolution}
1110   # copier les fichiers namelist input et output our COSP
1111     cp ../DefLists/cosp*_input_nl.txt .
1112     cp ../DefLists/cosp*_output_nl.txt .
1113   # Activer la cles ok_cosp pour tourner avec COSP
1114     sed -e 's@ok_cosp=n@ok_cosp=y@' config.def > tmp
1115      \mv -f tmp config.def
1116     cd ..
1117   fi
1118
1119   if [ -n "$physiq" ]; then
1120     cd BENCH${grid_resolution}
1121     if [ -f physiq.def_${physiq} ]; then
1122       cp physiq.def_${physiq} physiq.def
1123       echo using physiq.def_${physiq}
1124     else
1125       echo using standard physiq.def
1126     fi
1127     cd ..
1128   else
1129     echo using standard physiq.def
1130   fi
1131
1132   if [ "$with_xios" = "y" ] ; then
1133     cd BENCH${grid_resolution}
1134     cp ../DefLists/iodef.xml .
1135     cp ../DefLists/context_lmdz.xml .
1136     cp ../DefLists/field_def_lmdz.xml .
1137   # A raffiner par la suite
1138     echo A FAIRE : Copier les *xml en fonction de l option cosp
1139     cp ../DefLists/field_def_cosp*.xml .
1140     cp ../DefLists/file_def_hist*xml .
1141     # adapt iodef.xml to use attached mode
1142     sed -e 's@"using_server" type="bool">true@"using_server" type="bool">false@' iodef.xml > tmp
1143     \mv -f tmp iodef.xml
1144
1145     # and convert all the enabled="_AUTO_" (for libIGCM) to enabled=.FALSE.
1146     # except for histday
1147     for histfile in file_def_hist*xml
1148     do
1149       if [ "$histfile" = "file_def_histday_lmdz.xml" ] ; then
1150       sed -e 's@enabled="_AUTO_"@type="one_file" enabled=".TRUE."@' $histfile > tmp ; \mv -f tmp $histfile
1151       sed -e 's@output_level="_AUTO_"@output_level="5"@' $histfile > tmp ; \mv -f tmp $histfile
1152       sed -e 's@compression_level="2"@compression_level="0"@' $histfile > tmp ; \mv -f tmp $histfile
1153       else
1154       sed -e 's@enabled="_AUTO_"@type="one_file" enabled=".FALSE."@' $histfile > tmp ; \mv -f tmp $histfile
1155       fi
1156     done
1157     # and add option "ok_all_xml=y" in config.def
1158     echo "### XIOS outputs" >> config.def
1159     echo 'ok_all_xml=.true.' >> config.def
1160
1161     #activer les sorties pour Cosp
1162     if [ "$cosp" = "v1" ] ; then
1163      histfile=file_def_histdayCOSP_lmdz.xml
1164      sed -e 's@enabled=".FALSE."@enabled=".TRUE."@' $histfile > tmp ; \mv -f tmp $histfile
1165      sed -e 's@output_level="_AUTO_"@output_level="5"@' $histfile > tmp ; \mv -f tmp $histfile
1166      sed -e 's@compression_level="2"@compression_level="0"@' $histfile > tmp ; \mv -f tmp $histfile
1167     fi
1168     if [ "$cosp" = "v2" ] ; then
1169      histfile=file_def_histdayCOSPv2_lmdz.xml
1170      sed -e 's@compression_level="2"@compression_level="0"@' $histfile > tmp ; \mv -f tmp $histfile
1171      contextfile=context_lmdz.xml
1172      sed -e 's@src="./file_def_histdayCOSP_lmdz.xml"@src="./file_def_histdayCOSPv2_lmdz.xml"@' $contextfile > tmp ; \mv -f tmp $contextfile
1173      sed -e 's@src="./file_def_histmthCOSP_lmdz.xml"@src="./file_def_histmthCOSPv2_lmdz.xml"@' $contextfile > tmp ; \mv -f tmp $contextfile
1174      sed -e 's@src="./file_def_histhfCOSP_lmdz.xml"@src="./file_def_histhfCOSPv2_lmdz.xml"@' $contextfile > tmp ; \mv -f tmp $contextfile
1175      fieldfile=field_def_lmdz.xml
1176      sed -e 's@field_def_cosp1.xml@field_def_cospv2.xml@' $fieldfile > tmp ; \mv -f tmp $fieldfile
1177     fi
1178
1179     cd ..
1180   fi
1181
1182   # Cas Bensh avec ecrad
1183   if [ "$rad" = "ecrad" ] ; then
1184     cd BENCH${grid_resolution}
1185     cp  ../DefLists/namelist_ecrad .
1186     cp -r ../libf/phylmd/ecrad/data .
1187     cd ..
1188   fi
1189
1190   # Adjusting bench physiq.def to radiative code chosen
1191   cd BENCH${grid_resolution}
1192   sed -e 's/iflag_rrtm=.*.$/iflag_rrtm='$iflag_rrtm'/' -e 's/NSW=.*.$/NSW='$NSW'/' physiq.def > tmpdef
1193   \mv tmpdef physiq.def
1194   cd ..
1195
1196   cp $gcm BENCH${grid_resolution}/gcm.e
1197
1198   cd BENCH${grid_resolution}
1199   # On cree le fichier bench.sh au besoin
1200   # Dans le cas 48x36x39 le bench.sh existe deja en parallele
1201
1202   if [ "$grid_resolution" = "48x36x39" ] ; then
1203      echo On ne touche pas au bench.sh
1204      # But we have to adapt "run_local.sh" for $mpirun
1205      sed -e "s@mpirun@$mpirun@g" run_local.sh > tmp
1206      mv -f tmp run_local.sh
1207      chmod u=rwx run_local.sh
1208   elif [ "${parallel:0:3}" = "mpi" ] ; then
1209      # Lancement avec deux procs mpi et 2 openMP
1210      echo "export OMP_STACKSIZE=800M" > bench.sh
1211      if [ "${parallel:4:3}" = "omp" ] ; then
1212        echo "export OMP_NUM_THREADS=2" >> bench.sh
1213      fi
1214      if [ "$cosp" = "v1" -o "$cosp" = "v2" ] ; then
1215         if [ ${hostname:0:5} = jean- ] ; then
1216        chmod +x ../arch.env
1217           ../arch.env 
1218           echo "ulimit -s 2000000" >> bench.sh
1219         else
1220           echo "ulimit -s 200000" >> bench.sh
1221         fi     
1222      else
1223         echo "ulimit -s unlimited" >> bench.sh
1224      fi
1225      if [ ${hostname:0:5} = jean- ] ; then
1226        . ../arch/arch-${arch}.env
1227        echo "srun -n 2 -A $idris_acct@cpu gcm.e > listing  2>&1" >> bench.sh
1228      else
1229        echo "$mpirun -np 2 gcm.e > listing  2>&1" >> bench.sh
1230      fi
1231      # Add rebuild, using reb.sh if it is there
1232      echo 'if [ -f reb.sh ] ; then' >> bench.sh
1233      echo '  ./reb.sh histday ; ./reb.sh histmth ; ./reb.sh histhf ; ./reb.sh histins ; ./reb.sh stomate_history ; ./reb.sh sechiba_history ; ./reb.sh sechiba_out_2 ' >> bench.sh
1234      echo 'fi' >> bench.sh
1235   else
1236      echo "./gcm.e > listing  2>&1" > bench.sh
1237   fi
1238   # Getting orchidee stuff
1239   if [ $veget == 'CMIP6' ] ; then
1240       #echo 'myget 3DBenchs/BENCHorch11.tar.gz'
1241       #myget 3DBenchs/BENCHorch11.tar.gz
1242       #tar xvzf BENCHorch11.tar.gz
1243       echo 'myget 3DBenchs/BENCHCMIP6.tar.gz'
1244       myget 3DBenchs/BENCHCMIP6.tar.gz
1245       tar xvzf BENCHCMIP6.tar.gz
1246       sed -e "s:VEGET=n:VEGET=y:" config.def > tmp
1247       mv -f tmp config.def
1248       if [ "$with_xios" = "y" ] ; then
1249         cp ../../ORCHIDEE/src_xml/context_orchidee.xml .
1250         echo '<context id="orchidee" src="./context_orchidee.xml"/>' > add.tmp
1251         cp ../../ORCHIDEE/src_xml/field_def_orchidee.xml .
1252         cp ../../ORCHIDEE/src_xml/file_def_orchidee.xml .
1253         cp ../../ORCHIDEE/src_xml/file_def_input_orchidee.xml .
1254         if [ -f ../../ORCHIDEE/src_xml/context_input_orchidee.xml ] ; then
1255        cp ../../ORCHIDEE/src_xml/context_input_orchidee.xml .
1256        echo '<context id="orchidee" src="./context_input_orchidee.xml"/>' >> add.tmp
1257         fi
1258         sed -e '/id="LMDZ"/r add.tmp' iodef.xml > tmp
1259         mv tmp iodef.xml
1260         sed -e'{/sechiba1/ s/enabled="_AUTO_"/type="one_file" enabled=".TRUE."/}' file_def_orchidee.xml > tmp ; \mv -f tmp file_def_orchidee.xml
1261         sed -e 's@enabled="_AUTO_"@type="one_file" enabled=".FALSE."@' file_def_orchidee.xml > tmp ; \mv -f tmp file_def_orchidee.xml
1262         sed -e 's@output_level="_AUTO_"@output_level="1"@' file_def_orchidee.xml > tmp ; \mv -f tmp file_def_orchidee.xml
1263         sed -e 's@output_freq="_AUTO_"@output_freq="1d"@' file_def_orchidee.xml > tmp ; \mv -f tmp file_def_orchidee.xml
1264         sed -e 's@compression_level="4"@compression_level="0"@' file_def_orchidee.xml > tmp ; \mv -f tmp file_def_orchidee.xml
1265         sed -e 's@XIOS_ORCHIDEE_OK = n@XIOS_ORCHIDEE_OK = y@' orchidee.def > tmp ; \mv -f tmp orchidee.def
1266       fi
1267   fi
1268   echo EXECUTION DU BENCH
1269   set +e
1270   date ; ./bench.sh > out.bench 2>&1 ; date
1271   set -e
1272   tail listing
1273
1274
1275   echo '##########################################################'
1276   echo 'Simulation finished in' `pwd`
1277      echo 'You have compiled with:'
1278      cat ../compile.sh
1279   if [ $parallel = "none" ] ; then
1280     echo 'You may re-run it with : cd ' `pwd` ' ; gcm.e'
1281     echo 'or ./bench.sh'
1282   else
1283     echo 'You may re-run it with : '
1284     echo 'cd ' `pwd` '; ./bench.sh'
1285   #  echo 'ulimit -s unlimited'
1286   #  echo 'export OMP_NUM_THREADS=2'
1287   #  echo 'export OMP_STACKSIZE=800M'
1288   #  echo "$mpirun -np 2 gcm.e "
1289   fi
1290   echo '##########################################################'
1291
1292fi # bench
1293
1294
1295#################################################################
1296# Installation eventuelle du 1D
1297#################################################################
1298
1299if [ $SCM = 1 ] ; then
1300cd $MODEL
1301#wget http://www.lmd.jussieu.fr/~lmdz/Distrib/1D.tar.gz
1302myget 1D/1D.tar.gz
1303tar xvf 1D.tar.gz
1304cd 1D
1305./run.sh -rad $rad
1306fi
1307#set -vx
1308
1309#################################################################
1310# sauvegarde des options veget pour utilisation eventuelle tutorial_prod
1311#################################################################
1312cd $MODEL/modipsl/modeles
1313#echo surface_env file created in $MODEL
1314echo 'veget='$veget > surface_env
1315#opt_veget="-v $veget_version"
1316#echo 'opt_veget="'$opt_veget\" >> surface_env
1317echo 'opt_veget="'-v $veget_version\" >> surface_env
1318echo 'orchidee_rev='$orchidee_rev >> surface_env
1319echo 'suforch='$suff_orc >> surface_env
1320
1321
1322
1323
Note: See TracBrowser for help on using the repository browser.