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

Last change on this file since 262 was 220, checked in by ymipsl, 10 years ago

Creating temporary dynamico/lmdz/saturn branche

YM

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