source: codes/icosagcm/branches/SATURN_DYNAMICO/LMDZ.COMMON/makelmdz_fcm @ 341

Last change on this file since 341 was 341, checked in by aslmd, 9 years ago

fix in LMDZ.COMMON/makelmdz_fcm cleaning arch.env was missing; link to fcm was not universal.

  • Property svn:executable set to *
File size: 17.1 KB
Line 
1#!/bin/bash
2# $Id: makelmdz_fcm 1615 2012-02-10 15:42:26Z emillour $
3# This is a script in Bash.
4
5# FH : on ne crée plus le fichier arch.mk qui est supposé exister par
6# FH : ailleurs.
7# FH : ulterieurement, ce fichier sera pré-existant pour une série
8# FH : de configurations en versions optimisées et debug qui seront
9# FH : liés (ln -s) avec arch.mk en fonction de l'architecture.
10# FH : Pour le moment, cette version est en test et on peut créer les
11# FH : arch.mk en lançant une première fois makegcm.
12#
13##set -x
14########################################################################
15# options par defaut pour la commande make
16########################################################################
17
18dim="96x72x19"
19physique=lmd
20filtre=filtrez
21grille=reg
22couple=false
23veget=false
24sisvat=false
25rrtm=false
26chimie=false
27chemistry=false
28parallel=none
29paramem="par"
30compil_mod=prod
31io=ioipsl
32LIBPREFIX=""
33cosp=false
34bands=""
35scatterers=""
36job=1
37full=''
38
39LMDGCM=`/bin/pwd`
40LIBOGCM=$LMDGCM/libo
41LIBFGCM=$LMDGCM/libf
42# path for optional packages, but default set to ".void_dir"
43RRTM_PATH=$LMDGCM/.void_dir
44SISVAT_PATH=$LMDGCM/.void_dir
45COSP_PATH=$LMDGCM/.void_dir
46CHEM_PATH=$LMDGCM/.void_dir
47AERONO_PATH=$LMDGCM/.void_dir
48# Path to fcm utility:
49##fcm_path=$LMDGCM/tools/fcm/bin
50fcm_path=$(dirname $(which fcm))
51#fcm_path=/home/millour/FCM_V1.2/bin
52
53########################################################################
54#  Quelques initialisations de variables du shell.
55########################################################################
56
57CPP_KEY="" 
58INCLUDE=""
59LIB=""
60adjnt=""
61COMPIL_FFLAGS="%PROD_FFLAGS"
62PARA_FFLAGS=""
63PARA_LD=""
64EXT_SRC=""
65
66########################################################################
67# lecture des options de mymake
68########################################################################
69
70while (($# > 0))
71  do
72  case $1 in
73      "-h") cat <<fin
74Usage :
75makegcm [options] -arch arch exec
76[-h]                       : brief help
77[-d [[IMx]JMx]LM]          : IM, JM, LM are the dimensions in x, y, z (default: $dim)
78[-s nscat]                 : (Generic) Number of radiatively active scatterers
79[-b IRxVIS]                : (Generic) Number of infrared (IR) and visible (VIS) bands for radiative transfer
80[-p PHYS]                  : set of physical parametrizations (in libf/phyPHYS), (default: lmd)
81[-prod / -dev / -debug]    : compilation mode production (default) / developement / debug .
82[-c false/MPI1/OMCT]       : coupling with ocean model : MPI1/OMCT/false (default: false)
83[-v false/orchidee2.0/orchidee1.9/true] : version of the vegetation model to include (default: false)
84          false       : no vegetation model
85          orchidee2.0 : compile using ORCHIDEE 2.0 (or more recent version)
86          orchidee1.9 : compile using ORCHIDEE up to the version including OpenMP in ORCHIDEE : tag 1.9-1.9.5(version AR5)-1.9.6
87          true        : (obsolete; for backward compatibility) use ORCHIDEE tag 1.9-1.9.6
88[-chimie INCA/false]       : (Earth) with INCA chemistry model or without (default: false)
89[-cosp cosp/false]         : (Earth) add the cosp model (default: false)
90[-parallel none/mpi/omp/mpi_omp] : parallelism (default: none) : mpi, openmp or mixted mpi_openmp
91[-g GRI]                   : grid configuration in dyn3d/GRI_xy.h  (default: reg, inclues a zoom)
92[-io IO]                   : Input/Output library (default: ioipsl)
93[-include INCLUDES]        : extra include path to add
94[-cpp CPP_KEY]             : additional preprocessing definitions
95[-adjnt]                   : adjoint model, not operational ...
96[-mem]                     : reduced memory dynamics (if in parallel mode)
97[-filtre NOMFILTRE]        : use filtre from libf/NOMFILTRE (default: filtrez)
98[-link LINKS]              : additional links with other libraries
99[-j n]                     : active parallel compiling on ntask
100[-full]                    : full (re-)compilation (from scratch)
101[-fcm_path path]           : path to the fcm tool (default: tools/fcm/bin)
102[-ext_src path]            : path to an additional set of routines to compile with the model
103 -arch arch                : target architecture
104 exec                      : executable to build
105fin
106          exit;;
107
108      "-d")
109          dim=$2 ; shift ; shift ;;
110     
111      "-p")
112          physique="$2" ;  shift ; shift ;;
113
114      "-s")
115          scatterers=$2 ; shift ; shift ;;
116
117      "-b")
118          bands=$2 ; shift ; shift ;;
119
120      "-g")
121          grille="$2" ; shift ; shift ;;
122
123      "-c")
124          couple="$2" ; shift ; shift ;;
125
126      "-prod")
127          compil_mod="prod" ; shift ;;
128
129      "-dev")
130          compil_mod="dev" ; shift ;;
131
132      "-debug")
133          compil_mod="debug" ; shift ;;
134
135      "-io")
136          io="$2" ; shift ; shift ;;
137
138      "-v")
139          veget="$2" ; shift ; shift ;;
140
141      "-sisvat")
142          sisvat="$2" ; shift ; shift ;;
143
144      "-rrtm")
145          rrtm="$2" ; shift ; shift ;;
146
147      "-chimie")
148          chimie="$2" ; shift ; shift ;;
149
150      "-parallel")
151          parallel="$2" ; shift ; shift ;;
152     
153      "-include")
154          INCLUDE="$INCLUDE -I$2" ; shift ; shift ;;
155
156      "-cpp")
157          CPP_KEY="$CPP_KEY $2" ; shift ; shift ;;
158
159      "-adjnt")
160          echo "not operational ... work to be done here ";exit
161          opt_dep="$opt_dep adjnt" ; adjnt="-ladjnt -ldyn3d "
162          optim="$optim -Dadj" ; shift ;;
163
164      "-cosp")
165          cosp="$2" ; shift ; shift ;;
166
167      "-mem")
168          paramem="mem" ; shift ;;
169
170      "-filtre")
171          filtre=$2 ; shift ; shift ;;
172
173      "-link")
174          LIB="$LIB $2" ; shift ; shift ;;
175
176      "-fcm_path")
177          fcm_path=$2 ; shift ; shift ;;
178
179      "-ext_src")
180          EXT_SRC=$2 ; shift ; shift ;;
181
182      "-j")
183          job=$2 ; shift ; shift ;;
184
185      "-full")
186          full="-full" ; shift ;;
187
188      "-arch")
189          arch=$2 ; shift ; shift ;;
190
191      *)
192          code="$1" ; shift ;;
193  esac
194done
195
196###############################################################
197# path to fcm
198###############################################################
199# handle case when provided path to fcm was given as a relative
200# path (from makelmdz_fcm script directory) and not an absolute path
201if [[ ${fcm_path:0:1} != "/" ]] ; then
202  # prepend with makelmdz_fcm location
203  fcm_path=$(cd $(dirname $0) ; pwd)"/"${fcm_path}
204fi
205
206# add fcm_path to PATH
207export PATH=${fcm_path}:${PATH}
208
209echo "Path to fcm:"
210echo ${fcm_path}
211
212###############################################################
213# lecture des chemins propres à l'architecture de la machine #
214###############################################################
215rm -f .void_file
216echo > .void_file
217rm -rf .void_dir
218mkdir .void_dir
219rm -f arch.path
220rm -f arch.env
221ln -s arch/arch-${arch}.path ./arch.path
222ln -s arch/arch-${arch}.env ./arch.env
223source arch.env
224source arch.path
225
226########################################################################
227# Definition des clefs CPP, des chemins des includes et modules
228#  et des libraries
229########################################################################
230
231if [[ "$compil_mod" == "prod" ]]
232then
233  COMPIL_FFLAGS="%PROD_FFLAGS"
234elif [[ "$compil_mod" == "dev" ]]
235then
236  COMPIL_FFLAGS="%DEV_FFLAGS"
237elif [[ "$compil_mod" == "debug" ]]
238then
239  COMPIL_FFLAGS="%DEBUG_FFLAGS"
240fi
241
242if [[ "$physique" != "nophys" ]]
243then
244   #We'll use some physics
245   CPP_KEY="$CPP_KEY CPP_PHYS"
246   if [[ "${physique:0:3}" == "lmd" ]]
247   then
248   #For lmd physics, default planet type is Earth
249   CPP_KEY="$CPP_KEY CPP_EARTH"
250   fi
251fi
252
253if [[ "$chimie" == "INCA" ]]
254then
255   CPP_KEY="$CPP_KEY INCA"
256   INCLUDE="$INCLUDE -I${INCA_INCDIR}"
257   LIB="$LIB -L${INCA_LIBDIR} -lchimie"
258fi
259
260if [[ "$couple" != "false" ]]
261then
262    if [[ "$couple" == "MPI1" ]]
263    then
264        CPP_KEY="$CPP_KEY CPP_COUPLE"
265        export OASIS_INCDIR=$LMDGCM/../../prism/X64/build/lib/psmile.MPI1
266        export OASIS_LIBDIR=$LMDGCM/../../prism/X64/lib
267        INCLUDE="$INCLUDE -I${OASIS_INCDIR}"
268        LIB="$LIB -L${OASIS_LIBDIR} -lpsmile.MPI1 -lmpp_io"
269    else
270        CPP_KEY="$CPP_KEY CPP_COUPLE CPP_OMCT"
271        INCLUDE="$INCLUDE -I${OASIS_INCDIR}"
272        LIB="$LIB -L${OASIS_LIBDIR} -lpsmile.MPI1 -lscrip -lmct -lmpeu"
273    fi
274fi
275
276if [[ "$parallel" == "mpi" ]]
277then
278   CPP_KEY="$CPP_KEY CPP_PARA CPP_MPI"
279   PARA_FFLAGS="%MPI_FFLAGS"
280   PARA_LD="%MPI_LD"
281elif [[ "$parallel" == "omp" ]]
282then
283   CPP_KEY="$CPP_KEY CPP_PARA CPP_OMP"
284   PARA_FFLAGS="%OMP_FFLAGS"
285   PARA_LD="%OMP_LD"
286elif [[ "$parallel" == "mpi_omp" ]]
287then
288   CPP_KEY="$CPP_KEY CPP_PARA CPP_MPI CPP_OMP"
289   PARA_FFLAGS="%MPI_FFLAGS %OMP_FFLAGS"
290   PARA_LD="%MPI_LD %OMP_LD"
291fi
292
293if [[ ( "$parallel" == "omp" || "$parallel" == "mpi_omp" ) \
294   && "$compil_mod" == "debug" ]]
295then
296    echo "Usually, parallelization with OpenMP requires some optimization."
297    echo "We suggest switching to \"-dev\"."
298fi
299
300if [ "$veget" = "true" -o "$veget" = "orchidee1.9" -o "$veget" = "orchidee2.0" ]
301then
302#NB: option 'true': for backward compatibility. To be used with ORCHIDEE tag 1.9-1.9.6
303#    For this case, cpp flag ORCHIDEE_NOOPENMP must be added to the makelmdz_fcm arguments
304#    option orchidee1.9 : Compile with ORCHIDEE version up to the inclusion of OpenMP in ORCHIDEE : tag 1.9-1.9.5(version AR5)-1.9.6
305   INCLUDE="${INCLUDE} -I${ORCH_INCDIR}"
306   CPP_KEY="$CPP_KEY CPP_VEGET"
307# temporary, for Orchidee versions 1.9.* (before openmp activation)
308   if [[ "$veget" == "orchidee1.9" ]] ; then
309      CPP_KEY="$CPP_KEY ORCHIDEE_NOOPENMP"
310   fi
311   if [[ "$veget" == "orchidee2.0" ]] ; then
312      orch_libs="sechiba parameters stomate parallel orglob orchidee"
313   else
314      orch_libs="sechiba parameters stomate parallel orglob"
315   fi
316   LIB="${LIB} -L${ORCH_LIBDIR}"
317   for lib in ${orch_libs} ; do
318      if [ -f ${ORCH_LIBDIR}/lib${LIBPREFIX}$lib.a ] ; then
319         LIB="${LIB} -l${LIBPREFIX}$lib "
320      fi
321   done
322elif [[ "$veget" != "false" ]] ; then
323   echo "Option -v $veget does not exist"
324   echo "Use ./makelmdz_fcm -h for more information"
325   exit
326fi
327
328if [[ "$sisvat" == "true" ]]
329then
330   CPP_KEY="$CPP_KEY CPP_SISVAT"
331   SISVAT_PATH="$LIBFGCM/%PHYS/sisvat"
332   #sed -e 's/^#src::sisvat/src::sisvat/' bld.cfg > bld.tmp
333   #mv bld.tmp bld.cfg
334fi
335
336if [[ "$rrtm" == "true" ]]
337then
338   CPP_KEY="$CPP_KEY CPP_RRTM"
339   RRTM_PATH="$LIBFGCM/%PHYS/rrtm"
340   #sed -e 's/^#src::rrtm/src::rrtm/' bld.cfg > bld.tmp
341   #mv bld.tmp bld.cfg
342fi
343
344if [[ $io == ioipsl ]]
345then
346   CPP_KEY="$CPP_KEY CPP_IOIPSL"
347   INCLUDE="$INCLUDE -I${IOIPSL_INCDIR}"
348   LIB="$LIB -L${IOIPSL_LIBDIR} -l${LIBPREFIX}ioipsl"
349elif [[ $io == xios ]]
350then
351   # For now, xios implies also using ioipsl
352   CPP_KEY="$CPP_KEY CPP_IOIPSL CPP_XIOS"
353   INCLUDE="$INCLUDE -I${IOIPSL_INCDIR} -I${XIOS_INCDIR}"
354   LIB="$LIB -L${IOIPSL_LIBDIR} -l${LIBPREFIX}ioipsl -L${XIOS_LIBDIR} -l${LIBPREFIX}stdc++ -l${LIBPREFIX}xios"
355fi
356
357if [[ "$cosp" == "true" ]]
358then
359   CPP_KEY="$CPP_KEY CPP_COSP"
360   COSP_PATH="$LIBFGCM/cosp"
361#   LIB="${LIB} -l${LIBPREFIX}cosp"
362fi
363
364if [[ "$physique" == "titan" ]]
365then
366   CHEM_PATH="${LIBFGCM}/chim${physique}"
367   INCLUDE="$INCLUDE -I${LIBFGCM}/chim${physique}"
368fi
369
370# for Mars (but could be used by others as well), there is also "aeronomars"
371if [[ -d ${LIBFGCM}/aerono${physique} ]]
372then
373   AERONO_PATH="${LIBFGCM}/aerono${physique}"
374   INCLUDE="$INCLUDE -I${LIBFGCM}/aerono${physique}"
375fi
376
377INCLUDE="$INCLUDE ${NETCDF_INCDIR}"
378LIB="$LIB ${NETCDF_LIBDIR}"
379
380
381########################################################################
382# calcul du nombre de dimensions
383########################################################################
384
385
386dim_full=$dim
387dim=`echo $dim | sed -e 's/[^0-9]/ /g'` 
388set $dim
389dimc=$#
390echo calcul de la dimension
391echo dim $dim
392echo dimc $dimc
393
394
395########################################################################
396# Gestion des dimensions du modele.
397# on cree ou remplace le fichier des dimensions
398########################################################################
399
400cd $LIBFGCM/grid
401if [[ -f dimensions.h ]]
402then
403  echo 'ATTENTION: vous etes sans doute en train de compiler le modele par ailleurs'
404  echo "Attendez que la premiere compilation soit terminee pour relancer la suivante."
405  echo "Si vous etes sur que vous ne compilez pas le modele par ailleurs,"
406  echo  vous pouvez continuer en repondant oui.
407  echo "Voulez-vous vraiment continuer?"
408  echo ""
409  echo "WARNING: you are probably already compiling the model somewhere else."
410  echo "Wait until the first compilation is finished before launching this one."
411  echo "If you are sure that you are not compiling elsewhere, just answer "
412  echo "yes (or 'oui') to the question below to proceed."
413  echo "Do you wish to continue?"
414  read reponse
415  if [[ $reponse == "oui" || $reponse == "yes" ]]
416  then
417    \rm -f $LIBFGCM/grid/dimensions.h
418  else
419    exit
420  fi
421fi
422
423
424cd $LIBFGCM/grid/dimension
425./makdim $dim
426cat $LIBFGCM/grid/dimensions.h
427cd $LMDGCM
428
429if [[ "$bands" != "" ]]
430then
431  # Generic model, recreate bands.h (IR & VIS bands for radiative transfer)
432  bands=$(echo $bands | sed -e 's/[^0-9]/ /g')
433  cd $LIBFGCM/phy$physique/bands
434  ./makbands $bands
435  cat $LIBFGCM/phy$physique/bands.h
436  cd $LMDGCM
437fi
438
439if [[ "$scatterers" != "" ]]
440then
441  # Generic model, recreate scatterers.h
442  cd $LIBFGCM/phy$physique/scatterers
443  ./make_scatterers $scatterers
444  cat $LIBFGCM/phy$physique/scatterers.h
445  cd $LMDGCM
446fi
447
448
449########################################################################
450# Differentes dynamiques (3d, 2d, 1d)
451########################################################################
452
453dimension=`echo $dim | wc -w`
454echo dimension $dimension
455
456if (( $dimension == 3 ))
457then
458  cd $LIBFGCM/grid
459  \rm fxyprim.h
460  cp -p fxy_${grille}.h fxyprim.h
461#else
462#  echo "Probleme dans les dimensions de la dynamique !!"
463#  echo "Non reactive pour l'instant !!!"
464fi
465
466if (( $dimension == 1 ))
467then
468##in 1D, add dyn3d to include path (because main prog is in physics)
469  INCLUDE="$INCLUDE -Ilibf/dyn3d"
470#  echo pas de dynamique
471#  dyn="DYN= L_DYN=-ldyn3d "
472fi
473
474######################################################################
475#   Traitement special pour le nouveau rayonnement de Laurent Li.
476#   ---> YM desactive pour le traitemement en parallele
477######################################################################
478
479#if [[ -f $libf/phy$physique/raddim.h ]]
480#then
481# if [[ -f $libf/phy$physique/raddim.$dimh.h ]]
482#then
483#  \rm -f $libf/phy$physique/raddim.h
484#  cp -p $libf/phy$physique/raddim.$dimh.h $libf/phy$physique/raddim.h
485#  echo $libf/phy$physique/raddim.$dimh.h
486#  cat $libf/phy$physique/raddim.h
487# else
488#  echo On peut diminuer la taille de l executable en creant
489#  echo le fichier $libf/phy$physique/raddim.$dimh.h
490#  \cp -p $libf/phy$physique/raddim.defaut.h $libf/phy$physique/raddim.h
491# fi
492#fi
493
494######################################################################
495# Gestion du filtre qui n'existe qu'en 3d.
496######################################################################
497
498if (( `expr $dimc \> 2` == 1 ))
499then
500   filtre="FILTRE=$filtre"
501else
502   filtre="FILTRE= L_FILTRE= "
503fi
504echo MACRO FILTRE $filtre
505
506echo $dimc
507
508
509
510######################################################################
511# Creation du suffixe de la configuration
512######################################################################
513
514
515SUFF_NAME=_${dim_full}
516SUFF_NAME=${SUFF_NAME}_phy${physique}
517
518if [[ "$parallel" != "none" ]]
519then
520  SUFF_NAME=${SUFF_NAME}_para
521  DYN=dyn${dimc}d${paramem}
522  if [[ "$paramem" == "mem" ]]
523  then
524   SUFF_NAME=${SUFF_NAME}_${paramem}
525  fi
526else
527  SUFF_NAME=${SUFF_NAME}_seq
528  DYN=dyn${dimc}d
529  ## specific stuff for 1D model (needs includes which are in dyn3d)
530  if (( $dimension == 1 )) ; then
531    SUFF_NAME=${SUFF_NAME}
532    DYN=dyn3d
533  fi
534fi
535
536if [[ $veget != "false" ]]
537then
538  SUFF_NAME=${SUFF_NAME}_orch
539fi
540
541if [[ $couple != "false" ]]
542then
543  SUFF_NAME=${SUFF_NAME}_couple
544fi
545
546if [[ $chimie == "INCA" ]]
547then
548  SUFF_NAME=${SUFF_NAME}_inca
549fi
550
551cd $LMDGCM
552config_fcm="config.fcm"
553rm -f $config_fcm
554touch $config_fcm
555rm -f bin/${code}${SUFF_NAME}.e
556rm -f arch.fcm
557rm -f arch.opt
558
559echo "%ARCH          $arch"          >> $config_fcm
560echo "%INCDIR        $INCLUDE"       >> $config_fcm 
561echo "%LIB           $LIB"           >> $config_fcm
562echo "%ROOT_PATH     $PWD"           >> $config_fcm
563echo "%LIBF          $LIBFGCM"       >> $config_fcm
564echo "%LIBO          $LIBOGCM"       >> $config_fcm
565echo "%DYN           $DYN"           >> $config_fcm
566echo "%PHYS          phy${physique}" >> $config_fcm
567echo "%RRTM          $RRTM_PATH"     >> $config_fcm
568echo "%SISVAT        $SISVAT_PATH"   >> $config_fcm
569echo "%COSP          $COSP_PATH"     >> $config_fcm
570echo "%CHEM          $CHEM_PATH"     >> $config_fcm
571echo "%AERONO        $AERONO_PATH"   >> $config_fcm
572echo "%CPP_KEY       $CPP_KEY"       >> $config_fcm
573echo "%EXEC          $code"          >> $config_fcm
574echo "%SUFF_NAME     $SUFF_NAME"     >> $config_fcm
575echo "%COMPIL_FFLAGS $COMPIL_FFLAGS" >> $config_fcm
576echo "%PARA_FFLAGS   $PARA_FFLAGS"   >> $config_fcm
577echo "%PARA_LD       $PARA_LD"       >> $config_fcm
578echo "%EXT_SRC       $EXT_SRC"       >> $config_fcm
579
580
581
582ln -s arch/arch-${arch}.fcm arch.fcm
583if test -f arch/arch-${arch}.opt &&  [ $compil_mod = "prod" ]
584  then
585  ln -s arch/arch-${arch}.opt arch.opt
586else
587  ln -s .void_file arch.opt
588fi
589
590
591rm -f $LIBOGCM/${arch}${SUFF_NAME}/.config/fcm.bld.lock
592./build_gcm ${fcm_path} -j $job $full
593
594rm -rf tmp_src
595rm -rf config
596ln -s $LIBOGCM/${arch}${SUFF_NAME}/.config config
597ln -s $LIBOGCM/${arch}${SUFF_NAME}/.config/tmp tmp_src
598
599#eventual cleanup for SISVAT
600#sed -e 's/^src::sisvat/#src::sisvat/' bld.cfg > bld.tmp
601#mv bld.tmp bld.cfg
602
603#eventual cleanup for RRTM
604#sed -e 's/^src::rrtm/#src::rrtm/' bld.cfg > bld.tmp
605#mv bld.tmp bld.cfg
606
607
608if [[ -r $LIBFGCM/grid/dimensions.h ]]
609then
610  # Cleanup: remove dimension.h file
611  \rm -f $LIBFGCM/grid/dimensions.h
612fi
Note: See TracBrowser for help on using the repository browser.