source: LMDZ5/branches/testing/makelmdz_fcm @ 2283

Last change on this file since 2283 was 2220, checked in by Laurent Fairhead, 9 years ago

Merged trunk changes -r2186:2216 into testing branch

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