source: BOL/script_install/install.sh @ 1589

Last change on this file since 1589 was 1589, checked in by jghattas, 13 years ago

Updated install.sh :

  • Alwas compile netcdf with r4.
  • Added option real=r4 or =r8(defaut) for the compiling of LMDZ. If r8, then also adding cpp key NC_DOUBLE.

FH

File size: 17.0 KB
Line 
1#!/bin/bash
2
3###########################################################################
4# Auteur : Frédéric Hourdin/LMD/hourdin@lmd.jussieu.fr
5# Usage  : install.sh
6#
7# Script bash d'installation du modele LMDZ sur un ordinateur PC/Linux
8# en utilisant le compilateur g95.
9# Le modele est récupéré dans une arborescence
10# $MODEL/modipsl/modeles/...
11# en utilisant l'infrastructure "modipsl" mise au point à l'"IPSL" pour
12#les besoins de la modélisation couplée du climat
13#(atmosphere/ocean/vegetation/chimie)
14# On ne récupère ici que les composantes atmosphériques (LMDZ4)
15# et végétation (ORCHIDEE).
16#
17# Sous le répertoire "modeles", on trouve en fait les sources de différents
18# modèles. Ici, LMDZ4, ORCHIDEEet IOIPSL, ensemble de programmes
19# d'entrée/sortie faisant appel à la librairie netcdf.
20#
21# Le script récupères les différents jeux de sources (y compris une
22# version de netcdf) et utilitaires, compile le modèle, et lance une
23# simulation de test dans une configuration très légère sur
24# $MODEL/modipsl/modeles/LMDZ4/INI
25#
26# Pré-requis : g95/pgf90/gfortran, ksh, wget , gunzip, tar, ... (à compléter)
27#
28# Modif 18/11/2011
29#    changement pour l'option real 8.
30#      On compile avec -r8 (ou équivalent) et -DNC_DOUBLE pour le GCM
31#      mais avec -r4 netcdf. La variable real est initialisée à
32#      r4 ou r8 en début de script.
33#
34###########################################################################
35
36echo '################################################################'
37echo  Choix des options d installation
38echo '################################################################'
39
40
41real=r4
42real=r8
43
44# ATTENTION !!!! Pour des versions anterieures a octobre 2009, utiliser
45# install.v2.sh au lieu de install.sh
46
47version=20110921.trunk
48#Chemin pour placer le modele
49MODEL=./LMDZ$version
50
51getlmdzor=1
52netcdf=1   #  1 for automatic installation
53           #  0 for no installation
54           #  /.../../netcdf-4.0.1 if wanting to link with an already
55           #  compiled netcdf library (implies to check option compatibility)
56check_linux=1
57ioipsl=1
58veget=0
59bench=1
60## compilo=pgf90 ou g95 ou gfortran sur PC linux
61compilo=gfortran
62pclinux=1
63
64## compile_with_fcm=1 : utilise makelmdz_fcm, possible a partir de la version 20111103.trunk (LMDZ5/trunk rev 1578)
65## compile_with_fcm=0 : utilise makegcm (default)
66compile_with_fcm=0
67
68OPTPREC=""
69echo '################################################################'
70echo  Choix des options de compilation
71echo '################################################################'
72
73if [ $compilo = g95 ] ; then
74   if [ $real = r8 ] ; then OPTPREC="-r8 -DNC_DOUBLE" ; fi
75   OPTIM='-i4 -O3'
76elif [ $compilo = gfortran ] ; then
77   if [ $real = r8 ] ; then OPTPREC="-fdefault-real-8 -DNC_DOUBLE" ; fi
78   OPTIM='-O3'
79else #pgf90
80   if [ $real = r8 ] ; then echo "Option real 8 non disponible pour pgf90" ; exit ; fi
81   OPTIM='-O2 -Munroll -Mnoframe -Mautoinline -Mcache_align'
82fi
83OPTIMGCM="$OPTIM $OPTPREC"
84
85# choix de la resolution pour le bench
86# grid_resolution= 32x24x11 for test (test without ORCHIDEE)
87#                  96x71x19  standard configuration
88grid_resolution=48x36x19
89
90hostname=`hostname`
91
92##########################################################################
93# Dans le cas où on installe sur des machines connues comme la NEC
94# brodie
95# de l'IDRIS, on ne verifie pas les logiciels existants et on n'installe
96# pas netcdf.
97if [ $hostname = brodie ] ; then
98netcdf=0
99check_linux=0
100pclinux=0
101fi
102##########################################################################
103
104
105mkdir -p $MODEL
106echo $MODEL
107MODEL=`( cd $MODEL ; pwd )` # transformation en chemin absolu si necessaire
108
109
110
111# Le -fendian=big n'est à utiliser vraiment utile que pour ARPEGE1D.
112# Le -r8 doit sans doute être éviter si on veut tourner rapidement sur
113# des machines 32 bits.
114# L'option r8 n'est pas forcement indispensable et elle produit
115# des executables plus gros.
116# Elles est indispensable cependant pour ARPEGE1D
117# On doit pouvoir aussi utiliser des optimisations plus fortes (-O3 par
118# exemple).
119
120
121echo '################################################################'
122if [ "$check_linux" = 1 ] ; then
123echo   Test sur les logiciels requis
124echo '################################################################'
125
126#### Ehouarn: test if ksh and/or bash are available
127use_shell="ksh" # default: use ksh
128if [ "`which ksh`" = "" ] ; then
129  echo "pas de ksh ... on va utiliser bash"
130  use_shell="bash"
131  if [ "`which bash`" = "" ] ; then
132    echo "Il faut d\'abord installer ksh (ou bash)"
133  fi
134fi
135
136
137for logiciel in csh wget tar gzip make $compilo gcc ; do
138if [ "`which $logiciel`" = "" ] ; then
139echo Il faut installer d\'abord $logiciel
140exit
141fi
142done
143
144if [ $pclinux = 1 ] ; then
145cd $MODEL
146cat <<eod> tt.f90
147print*,'coucou'
148end
149eod
150$compilo tt.f90
151./a.out >| tt
152if [ "`cat tt | sed -e 's/ //g' `" != "coucou" ] ; then
153echo probleme avec installation de $compilo ; exit ; fi
154\rm tt a.out tt.f90
155fi
156fi
157
158###########################################################################
159
160
161
162if [ $getlmdzor = 1 ] ; then
163echo '##########################################################'
164echo  On recupere une version un peu modifiee de LMDZ
165echo '##########################################################'
166cd $MODEL
167wget http://www.lmd.jussieu.fr/~lmdz/DistribG95/modipsl.$version.tar.gz
168gunzip modipsl.$version.tar.gz
169tar xvf modipsl.$version.tar
170\rm modipsl.$version.tar
171
172# On recupere en fait une version du 01 10 2006 obtenue
173# Par un cvs get
174# Puis modifiees pour etre compatible avec la compilation $compilo.
175# et pour betoner ORCHIDEE
176# Cette version est recuperable avec le script
177# wget http://www.lmd.jussieu.fr/~lmdz/DistribG95/getlmdzor.x
178fi
179
180echo OK1
181
182if [ $netcdf = 1 ] ; then
183echo '##########################################################'
184echo Compilation de netcdf
185echo '##########################################################'
186cd $MODEL
187wget http://www.lmd.jussieu.fr/~lmdz/DistribG95/netcdf-4.0.1.tar.gz
188gunzip netcdf-4.0.1.tar.gz
189tar xvf netcdf-4.0.1.tar
190\rm -f netcdf-4.0.1.tar
191
192cd netcdf-4.0.1
193
194OPTIMNC=$OPTIM
195if [ $compilo = g95 ] ; then
196# On modifie les options de compilation
197   export FC=g95
198   export F90=g95
199   export F90FLAGS=" -cpp -ffree-form $OPTIMNC"
200   export FFLAGS=" -cpp $OPTIMNC"
201   export CPPFLAGS=-Df2cFortran
202   export CC=gcc
203   export CXX=g++
204elif [ $compilo = gfortran ] ; then
205   export FC=gfortran
206   export F90=gfortran
207   export F90FLAGS=" -ffree-form $OPTIMNC"
208   export FFLAGS=" $OPTIMNC"
209   export CPPFLAGS=
210   export CC=gcc
211   export CXX=g++
212elif [ $compilo = pgf90 ] ; then
213   export CPPFLAGS="-DNDEBUG -DpgiFortran"
214   export CC=pgcc
215   export CFLAGS="-Msignextend"
216   export CXX=pgCC
217   export CXXFLAGS="-Msignextend"
218   export FC=pgf90
219   export FFLAGS="$OPTIMNC"
220   export F90=pgf90
221   export F90FLAGS="$OPTIMNC"
222else
223   echo Le compilateur $compilo pas prevu ; exit
224fi
225## end of if [ $netcdf = 1 ]
226cd src
227
228### Correction d'un petit probleme de netcdf
229##sed -e '83s/^$/\#define f2cFortran/' cfortran.h >| tmp ; \mv tmp cfortran.h
230
231# Compilation
232# Modif du 6 juillet 2009. Plantage quand on essaie de compiler netcdf avec
233# gcc plutôt que c++
234##sed -e 's/ c++/ gcc/g' configure >| tmp ; mv -f tmp configure ; chmod +x configure
235localdir=`pwd -P`
236./configure --prefix=$localdir
237make check
238make install
239fi
240
241echo OK2 ioipsl=$ioipsl
242echo '##########################################################'
243echo Installation de MODIPSL, la procedure d\'installation des
244echo modeles de l\'IPSL
245echo '##########################################################'
246
247if [ $netcdf = 0 -o $netcdf = 1 ] ; then
248ncdfdir=$MODEL/netcdf-4.0.1
249else
250ncdfdir=$netcdf
251fi
252
253if [ $ioipsl = 1 ] ; then
254cd $MODEL/modipsl
255\rm -r lib/*
256
257cd util
258
259if [ $compilo = pgf90 ] ; then 
260  fmod='module '
261elif [ $compilo = g95 ] ; then
262  fmod='fmod='
263else # gfortran
264  fmod='I '
265fi
266cp AA_make.gdef AA_make.orig
267sed -e 's/^\#.*.g95.*.\#.*.$/\#/' AA_make.gdef > tmp
268sed -e "s:F_L = g95:F_L = $compilo:" -e "s:F_C = g95 -c:F_C = $compilo -c": \
269-e 's/g95.*.w_w.*.(F_D)/g95      w_w = '"$OPTIMGCM"'/' \
270-e 's:g95.*.NCDF_INC.*.$:g95      NCDF_INC='"$ncdfdir"'/include:' \
271-e 's:g95.*.NCDF_LIB.*.$:g95      NCDF_LIB='"$ncdfdir"'/lib:' \
272-e "s:-fmod=:-$fmod:" -e 's/-fno-second-underscore//' \
273-e 's:#-Q- g95      M_K = gmake:#-Q- g95      M_K = make:' \
274tmp >| AA_make.gdef
275
276
277if [ "$use_shell" = "ksh" ] ; then
278  if [ "$pclinux" = 1 ] ; then
279     ./ins_make -t g95 # On utilise les lignes g95 meme pour les autres compilo
280  fi
281else # bash
282  sed -e s:/bin/ksh:/bin/bash:g ins_make > ins_make.bash
283  chmod u=rwx ins_make.bash
284  if [ "$pclinux" = 1 ] ; then
285  ./ins_make.bash -t g95 # On utilise les lignes g95 meme pour les autres compilo
286  else
287  ./ins_make.bash
288  fi
289fi
290
291echo '##########################################################'
292echo Compilation de IOIPSL, bibliotheque d\'interface avec Netcd
293echo '##########################################################'
294
295cd $MODEL/modipsl/modeles/IOIPSL/src
296if [ "$use_shell" = "bash" ] ; then
297  cp Makefile Makefile.ksh
298  sed -e s:/bin/ksh:/bin/bash:g Makefile.ksh > Makefile
299fi
300if [ "$pclinux" = 1 ] ; then
301  make clean
302  make
303  if [ $compilo = gfortran ] ; then # copy module files to lib
304    cp -f *.mod ../../../lib
305  fi
306else
307  # we're on brodie
308  sxgmake clean
309  sxgmake
310fi
311
312if [ "$veget" = 1 ] ; then
313echo '########################################################'
314echo Compilation de ORCHIDEE, modele des surface continentales
315echo '########################################################'
316cd $MODEL/modipsl/modeles/ORCHIDEE
317cd src_parameters
318# Une petite astuce pour ORCHIDEE suivant qu'on est en real*4 ou real*8
319
320
321\cp reqdprec.$real reqdprec.f90
322make
323if [ $compilo = gfortran ] ; then # copy module files to lib
324  cp -f *.mod ../../../lib
325fi
326cd ../src_stomate
327make
328if [ $compilo = gfortran ] ; then # copy module files to lib
329  cp -f *.mod ../../../lib
330fi
331cd ../src_sechiba
332make
333if [ $compilo = gfortran ] ; then # copy module files to lib
334  cp -f *.mod ../../../lib
335fi
336fi
337fi
338
339
340# Ehouarn: it may be directory LMDZ4 or LMDZ5 depending on tar file...
341if [[ -d $MODEL/modipsl/modeles/LMDZ4 ]] ; then
342  echo '##########################################################'
343  echo 'Compilation de LMDZ4'
344  echo '##########################################################'
345  cd $MODEL/modipsl/modeles/LMDZ4
346else
347  if [[ -d $MODEL/modipsl/modeles/LMDZ5 ]] ; then
348    echo '##########################################################'
349    echo 'Compilation de LMDZ5'
350    echo '##########################################################'
351    cd $MODEL/modipsl/modeles/LMDZ5
352  else
353    echo "ERROR: No LMDZ4 (or LMDZ5) directory !!!"
354    exit
355  fi
356fi
357
358if [ "$pclinux" = 1 ] ; then
359  if [ $compilo = gfortran ] ; then
360sed \
361-e 's:\#setenv NCDFINC.*.$:setenv NCDFINC '"$ncdfdir"'/include:' \
362-e 's:\#setenv NCDFLIB.*.$:setenv NCDFLIB '"$ncdfdir"'/lib:' \
363-e 's:setenv NCDFINC.*.$:setenv NCDFINC '"$ncdfdir"'/include:' \
364-e 's:setenv NCDFLIB.*.$:setenv NCDFLIB '"$ncdfdir"'/lib:' \
365-e 's/set FC_LINUX.*.$/set FC_LINUX='$compilo'/' \
366-e 's/g95/gfortran/g' \
367-e 's/-fmod=/-I/g' \
368-e 's/-fno-second-underscore//' -e 's/-fstatic//' \
369-e 's/-lparallel//' \
370-e 's/-lorglob//' \
371-e 's/-ffixed-form//' -e 's/-ffree-form//' \
372-e 's/set OPT_LINUX.*.$/set OPT_LINUX=\"'"$OPTIMGCM"\"'/' makegcm.orig >| makegcm
373  else # g95 or pgf90
374sed \
375-e 's:\#setenv NCDFINC.*.$:setenv NCDFINC '"$ncdfdir"'/include:' \
376-e 's:\#setenv NCDFLIB.*.$:setenv NCDFLIB '"$ncdfdir"'/lib:' \
377-e 's:setenv NCDFINC.*.$:setenv NCDFINC '"$ncdfdir"'/include:' \
378-e 's:setenv NCDFLIB.*.$:setenv NCDFLIB '"$ncdfdir"'/lib:' \
379-e 's/set FC_LINUX.*.$/set FC_LINUX='$compilo'/' \
380-e 's/-fno-second-underscore//' -e 's/-fstatic//' \
381-e 's/-lparallel//' \
382-e 's/-lorglob//' \
383-e 's/-ffixed-form//' -e 's/-ffree-form//' \
384-e 's/set OPT_LINUX.*.$/set OPT_LINUX=\"'"$OPTIMGCM"\"'/' makegcm.orig >| makegcm
385  fi
386else
387sed \
388-e 's/-lparallel//' \
389-e 's/-lorglob//' \
390-e 's/-lsxorglob//' \
391-e 's/-lsxparallel//' \
392-e 's/-lsxioipsl/-lioipsl/g' \
393makegcm.orig >| makegcm
394fi
395
396chmod +x makegcm
397
398###########################################################
399# Pour ceux qui voudraient utiliser fcm et pouvoir faire :
400#  makelmdz_fcm -arch local .....
401############################################################
402
403if [ "$pclinux" = 1 ] ; then
404# creation de fichiers 'arch' locaux (si sur PC Linx):
405cd arch
406# fichier arch-local.path
407echo "NETCDF_LIBDIR=\"-L/${ncdfdir}/lib -lnetcdf\"" > arch-local.path
408echo "NETCDF_INCDIR=-I/${ncdfdir}/include" >> arch-local.path
409echo 'IOIPSL_INCDIR=$LMDGCM/../../lib' >> arch-local.path
410echo 'IOIPSL_LIBDIR=$LMDGCM/../../lib' >> arch-local.path
411echo 'ORCH_INCDIR=$LMDGCM/../../lib' >> arch-local.path
412echo 'ORCH_LIBDIR=$LMDGCM/../../lib' >> arch-local.path
413# fichier arch-local.fcm (adaptation de arch-linux-32bit.fcm)
414if [ $compilo = g95 ] ; then
415sed -e s:"%COMPILER            pgf95":"%COMPILER            g95":1 \
416    -e s:"%LINK                pgf95":"%LINK                g95":1 \
417    -e s:"%PROD_FFLAGS         -fast":"%PROD_FFLAGS         ":1 \
418    -e s:"%BASE_FFLAGS         ":"%BASE_FFLAGS         $OPTIMGCM":1 \
419   arch-linux-32bit.fcm > arch-local.fcm
420   if [ $real = r8 ] ; then
421     sed -e s:"%FPP_DEF             ":"%FPP_DEF             NC_DOUBLE":1 \
422     arch-local.fcm > arch-local.fcm.new
423     mv -f arch-local.fcm.new arch-local.fcm
424   fi
425elif [ $compilo = gfortran ] ; then
426sed -e s:"%COMPILER            pgf95":"%COMPILER            gfortran":1 \
427    -e s:"%LINK                pgf95":"%LINK                gfortran":1 \
428    -e s:"%PROD_FFLAGS         -fast":"%PROD_FFLAGS         ":1 \
429    -e s:"%BASE_FFLAGS         ":"%BASE_FFLAGS         $OPTIMGCM":1 \
430   arch-linux-32bit.fcm > arch-local.fcm
431   if [ $real = r8 ] ; then
432     sed -e s:"%FPP_DEF             ":"%FPP_DEF             NC_DOUBLE":1 \
433     arch-local.fcm > arch-local.fcm.new
434     mv -f arch-local.fcm.new arch-local.fcm
435   fi
436elif [ $compilo = pgf90 ] ; then
437sed -e s:"-Wl,-Bstatic -L/usr/lib/gcc-lib/i386-linux/2.95.2":" ":1 \
438    -e s:"%PROD_FFLAGS         -fast":"%PROD_FFLAGS         ":1 \
439    -e s:"%BASE_FFLAGS         ":"%BASE_FFLAGS         $OPTIMGCM":1 \
440   arch-linux-32bit.fcm > arch-local.fcm
441   if [ $real = r8] ; then
442     sed -e s:"%FPP_DEF             ":"%FPP_DEF             NC_DOUBLE":1 \
443     arch-local.fcm > arch-local.fcm.new
444     mv -f arch-local.fcm.new arch-local.fcm
445   fi
446else
447   echo Le compilateur $compilo pas prevu ; exit
448fi # of if [ $compilo = g95 ] elif [ $compilo = pgf90 ]
449cd ..
450### Adaptation de "bld.cfg" (ajout du shell):
451whereisthatshell=$(which ${use_shell})
452echo "bld::tool::SHELL   $whereisthatshell" >> bld.cfg
453
454### Modification de makelmdz_fcm pour utilisation de ORCHIDEE dans cette bench:
455### on enleve liborglob.a et libparallel.a
456cp makelmdz_fcm makelmdz_fcm.orig
457sed -e "s/-l\${LIBPREFIX}parallel//" \
458sed -e "s/-l\${LIBPREFIX}orglob//" \
459    makelmdz_fcm.orig > makelmdz_fcm
460
461fi # of if [ "$pclinux" = 1 ]
462
463##################################################################
464# Lance compilation de LMDZ
465##################################################################
466ok_veget=false
467if [ "$veget" = 1 ] ; then ok_veget = true; fi
468if [ $compile_with_fcm = 1 ] ; then
469# Compilation avec makelmdz_fcm
470        ./makelmdz_fcm -d ${grid_resolution} -arch local -v $ok_veget gcm
471else
472# Compilation avec makegcm
473        ./makegcm -d ${grid_resolution} -v $ok_veget gcm
474        ./makegcm -d ${grid_resolution} -v $ok_veget gcm
475        ./makegcm -d ${grid_resolution} -v $ok_veget gcm
476fi
477
478if [ -f gcm.e ] || [ -f bin/gcm_${grid_resolution}_phylmd_seq_orch.e ] || [ -f bin/gcm_${grid_resolution}_phylmd_seq.e ]  ; then
479echo '##########################################################'
480echo Compilation reussie
481echo '##########################################################'
482else
483echo Probleme de compilation
484exit
485fi
486
487##################################################################
488# Ci dessous le lancement eventuel d'un cas test (si bench=0)
489##################################################################
490if [ $bench = 0 ] ; then
491                exit
492fi
493
494echo '##########################################################'
495echo Lancement d\'une simulation de test
496echo '##########################################################'
497
498\rm -r BENCH${grid_resolution}
499bench=bench_lmdz_${grid_resolution}
500wget http://www.lmd.jussieu.fr/~lmdz/DistribG95/$bench.tar.gz
501gunzip $bench.tar.gz
502tar xvf $bench.tar
503
504if [ -f gcm.e ] ; then 
505    cp gcm.e BENCH${grid_resolution}/
506elif [ -f bin/gcm_${grid_resolution}_phylmd_seq_orch.e ] ; then
507    cp bin/gcm_${grid_resolution}_phylmd_seq_orch.e  BENCH${grid_resolution}/gcm.e
508elif [ -f bin/gcm_${grid_resolution}_phylmd_seq.e ] ; then
509    cp bin/gcm_${grid_resolution}_phylmd_seq.e  BENCH${grid_resolution}/gcm.e
510else
511    echo "No gcm.e found"
512    exit
513fi
514
515if [ $hostname = brodie ] ; then
516echo POUR LANCER LE BENCH, IL FAUT SE LOGUER SUR BRODIE01
517echo puis aller sur `pwd`/BENCH${grid_resolution}
518echo et lancer le gcm
519exit
520fi
521
522cd BENCH${grid_resolution}
523./bench.sh > bench.out  2>&1
524
525echo '##########################################################'
526echo ' Resultat du bench '
527echo '##########################################################'
528
529cat ./bench.out
530
531echo '##########################################################'
532echo 'La simulation test est terminee sur' `pwd`
533echo 'vous pouvez la relancer : cd ' `pwd` ' ; gcm.e'
534echo 'ou ./bench.sh'
535echo '##########################################################'
536
Note: See TracBrowser for help on using the repository browser.