source: trunk/LMDZ.COMMON/makelmdz @ 1661

Last change on this file since 1661 was 1661, checked in by slebonnois, 8 years ago

SL: Cloud model for Venus. Not validated yet.

  • Property svn:executable set to *
File size: 27.2 KB
Line 
1#!/bin/bash
2#
3# $Id $
4#
5#
6########################################################################
7# for debug, uncomment line below
8#set -xv
9########################################################################
10# options par defaut pour la commande make
11########################################################################
12dim="96x72x19"
13physique=lmd
14code=gcm
15filtre=filtrez
16grille=reg
17couple=false
18veget=false
19chimie=false
20parallel=none
21paramem="par"
22compil_mod=prod
23io=ioipsl
24LIBPREFIX=""
25fcm_path=none
26cosp=false
27sisvat=false
28rrtm=false
29dust=false
30strataer=false
31bands=""
32scatterers=""
33full=''
34
35arch_defined="FALSE"
36arch_path="arch"
37arch_default_path="arch"
38
39# guess a default 'arch'
40arch="local" # start with assuming we're on a local machine with local arch file
41arch_defined="TRUE" # and thus also set arch_defined to true
42## try to recognise machine and infer arch from it
43machine=`hostname`
44if [[ "${machine:0:3}" == "ada" ]]
45then
46  arch="X64_ADA"
47fi
48if [[ "${machine:0:7}" == "platine" ]]
49then
50  arch="IA64_PLATINE"
51fi
52if [[ "${machine:0:6}" == "titane" ]]
53then
54  arch="X64_TITANE"
55fi
56if [[ "${machine:0:8}" == "mercure1" ]]
57then
58  arch="SX8_MERCURE"
59fi
60if [[ "${machine:0:8}" == "mercure2" ]]
61then
62  arch="SX9_MERCURE"
63fi
64
65LMDGCM=`pwd -P`
66LIBFGCM=$LMDGCM/libf
67LIBOGCM=$LMDGCM/libo
68if [[ ! -d $LIBOGCM ]]
69then
70  # create the directory
71  mkdir $LIBOGCM
72  if [[ ! $? ]]
73  then
74  echo "Failed to create directory $LIBOGCM"
75  exit
76  fi
77fi
78COSP_PATH=$LMDGCM/.void_dir
79
80
81
82localdir=`pwd -P`
83########################################################################
84#  Quelques initialisations de variables du shell.
85########################################################################
86
87CPP_KEY="" 
88INCLUDE='-I$(LIBF)/grid -I$(LIBF)/misc -I$(LIBF)/filtrez -I. '
89LIB=""
90adjnt=""
91##COMPIL_FFLAGS="%PROD_FFLAGS"
92PARA_FFLAGS=""
93PARA_LD=""
94EXT_SRC=""
95#src_dirs: directories containing source files
96src_dirs="grid misc" 
97ccompiler=""
98OPTIMC=""
99INCLUDEC=""
100
101########################################################################
102# lecture des options
103########################################################################
104
105while (($# > 0))
106  do
107  case $1 in
108      "-h") cat <<fin
109manuel complet sur http://...
110Usage :
111makeldmz [options] -arch arch exec
112[-h]                       : brief help
113[-d [[IMx]JMx]LM]          : IM, JM, LM are the dimensions in x, y, z (default: $dim)
114[-s nscat]                 : (Generic) Number of radiatively active scatterers
115[-b IRxVIS]                : (Generic) Number of infrared (IR) and visible (VIS) bands for radiative transfer
116[-p PHYS]                  : set of physical parametrizations (in libf/phyPHYS), (default: lmd)
117[-prod / -dev / -debug]    : compilation mode production (default) / developement / debug .
118[-c false/MPI1/MPI2]       : (Earth) coupling with ocean model : MPI1/MPI2/false (default: false)
119[-v false/orchidee2.0/orchidee1.9/true] : version of the vegetation model to include (default: false)
120          false       : no vegetation model
121          orchidee2.0 : compile using ORCHIDEE 2.0 (or more recent version)
122          orchidee1.9 : compile using ORCHIDEE up to the version including OpenMP in ORCHIDEE : tag 1.9-1.9.5(version AR5)-1.9.6
123          true        : (obsolete; for backward compatibility) use ORCHIDEE tag 1.9-1.9.6
124
125[-chimie INCA/false]       : (Earth) with INCA chemistry model or without (default: false)
126[-cosp cosp/false]         : (Earth) add the cosp model (default: false)
127[-sisvat true/false]  : (Earth) compile with/without sisvat package (default: false)
128[-rrtm true/false]    : (Earth) compile with/without rrtm package (default: false)
129[-dust true/false]    : (Earth) compile with/without the dust package from Boucher et al. (default: false)
130[-strataer true/false]    : (Earth) compile with/without the strat aer package from Boucher et al. (default: false)
131[-parallel none/mpi/omp/mpi_omp] : parallelism (default: none) : mpi, openmp or mixted mpi_openmp
132[-g GRI]                   : grid configuration in dyn3d/GRI_xy.h  (default: reg, inclues a zoom)
133[-io ioipsl/mix/xios]                   : Input/Output library (default: ioipsl)
134[-include INCLUDES]        : extra include path to add
135[-cpp CPP_KEY]             : additional preprocessing definitions
136[-adjnt]                   : adjoint model, not operational ...
137[-mem]                     : reduced memory dynamics (if in parallel mode)
138[-filtre NOMFILTRE]        : use filtre from libf/NOMFILTRE (default: filtrez)
139[-link LINKS]              : additional links with other libraries
140[-full]                    : full (re-)compilation (from scratch)
141[-ext_src path]            : path to an additional set of routines to compile with the model
142[-arch_path path]          : path to architecture files (default: $arch_default_path)
143 -arch arch                : target architecture
144 exec                      : executable to build
145fin
146          exit;;
147      "-d")
148          dim=$2 ; shift ; shift ;;
149     
150      "-p")
151          physique="$2" ; shift ; shift ;;
152
153      "-s")
154          scatterers=$2 ; shift ; shift ;;
155
156      "-b")
157          bands=$2 ; shift ; shift ;;
158
159      "-g")
160          grille="$2" ; shift ; shift ;;
161
162      "-c")
163          couple="$2" ; shift ; shift ;;
164
165      "-prod")
166          compil_mod="prod" ; shift ;;
167
168      "-dev")
169          compil_mod="dev" ; shift ;;
170
171      "-debug")
172          compil_mod="debug" ; shift ;;
173
174      "-io")
175          io="$2" ; shift ; shift ;;
176
177      "-v")
178          veget="$2" ; shift ; shift ;;
179
180      "-chimie")
181          chimie="$2" ; shift ; shift ;;
182
183      "-parallel")
184          parallel="$2" ; shift ; shift ;;
185     
186      "-include")
187          INCLUDE="$INCLUDE -I$2" ; shift ; shift ;;
188
189      "-cpp")
190          CPP_KEY="$CPP_KEY $2" ; shift ; shift ;;
191
192      "-cosp")
193          cosp="$2" ; shift ; shift ;;
194     
195      "-sisvat")
196          sisvat="$2" ; shift ; shift ;;
197     
198      "-rrtm")
199          rrtm="$2" ; shift ; shift ;;
200     
201      "-dust")
202          dust="$2" ; shift ; shift ;;
203     
204      "-strataer")
205          strataer="$2" ; shift ; shift ;;
206     
207      "-mem")
208          paramem="mem" ; shift ;;
209
210      "-filtre")
211          filtre=$2 ; shift ; shift ;;
212
213      "-link")
214          LIB="$LIB $2" ; shift ; shift ;;
215
216      "-full")
217          full="full" ; shift ;;
218
219      "-ext_src")
220          EXT_SRC=$2 ; shift ; shift ;;
221
222      "-arch")
223          arch=$2 ; arch_defined="TRUE" ; shift ; shift ;;
224
225      "-arch_path")
226          arch_path=$2 ; arch_path_defined="TRUE"; shift ; shift ;;
227
228      *)
229          code="$1" ; shift ;;
230  esac
231done
232
233###############################################################
234# lecture des chemins propres \`a l'architecture de la machine #
235###############################################################
236rm -f .void_file
237echo > .void_file
238rm -rf .void_dir
239mkdir .void_dir
240
241if [[ "$arch_defined" == "TRUE" ]]
242then
243  rm -f arch.path
244  rm -f arch.fcm
245  rm -f arch.env
246
247  if test -f $arch_path/arch-${arch}.path
248  then
249    ln -s $arch_path/arch-${arch}.path arch.path
250  elif test -f $arch_default_path/arch-${arch}.path
251  then
252    ln -s $arch_default_path/arch-${arch}.path arch.path
253  fi
254       
255  if test -f $arch_path/arch-${arch}.fcm
256  then
257    ln -s $arch_path/arch-${arch}.fcm arch.fcm
258  elif test -f $arch_default_path/arch-${arch}.fcm
259  then
260    ln -s $arch_default_path/arch-${arch}.fcm arch.fcm
261  fi
262
263  if test -f $arch_path/arch-${arch}.env
264  then
265    ln -s $arch_path/arch-${arch}.env arch.env
266  elif test -f $arch_default_path/arch-${arch}.env
267  then
268    ln -s $arch_default_path/arch-${arch}.env arch.env
269  else
270    ln -s .void_file arch.env
271  fi
272  # source architecture PATH and ENV files
273  source arch.env
274  source arch.path
275else
276  echo "You must define a target architecture"
277  exit 1
278fi
279
280########################################################################
281# Definition des clefs CPP, des chemins des includes et modules
282#  et des libraries
283########################################################################
284
285# basic compile flags from arch.fcm file
286archfileline=$( grep -i '^%BASE_FFLAGS' arch.fcm )
287COMPIL_FFLAGS=$( echo ${archfileline##%BASE_FFLAGS} )
288
289# other compile flags, depending on compilation mode
290if [[ "$compil_mod" == "prod" ]]
291then
292## read COMPIL_FFLAGS from arch.fcm file
293  archfileline=$( grep -i '^%PROD_FFLAGS' arch.fcm )
294  archfileopt=$( echo ${archfileline##%PROD_FFLAGS} )
295  COMPIL_FFLAGS="${COMPIL_FFLAGS} ${archfileopt}"
296elif [[ "$compil_mod" == "dev" ]]
297then
298## read %DEV_FFLAGS from arch.fcm file
299  archfileline=$( grep -i '^%DEV_FFLAGS' arch.fcm )
300  archfileopt=$( echo ${archfileline##%DEV_FFLAGS} )
301  COMPIL_FFLAGS="${COMPIL_FFLAGS} ${archfileopt}"
302elif [[ "$compil_mod" == "debug" ]]
303then
304## read %DEBUG_FFLAGS from arch.fcm file
305  archfileline=$( grep -i '^%DEBUG_FFLAGS' arch.fcm )
306  archfileopt=$( echo ${archfileline##%DEBUG_FFLAGS} )
307  COMPIL_FFLAGS="${COMPIL_FFLAGS} ${archfileopt}"
308fi
309
310# add CPP_KEY defined in arch.fcm file
311archfileline=$( grep -i '^%FPP_DEF' arch.fcm )
312archfileopt=$( echo ${archfileline##%FPP_DEF} )
313CPP_KEY="$CPP_KEY ${archfileopt}"
314
315# get compiler name from arch.fcm file
316archfileline=$( grep -i '^%COMPILER' arch.fcm )
317fcompiler=$( echo ${archfileline##%COMPILER} )
318
319# get linker name from arch.fcm file
320archfileline=$( grep -i '^%LINK' arch.fcm )
321linker=$( echo ${archfileline##%LINK} )
322
323# get ar command from arch.fcm file
324archfileline=$( grep -i '^%AR' arch.fcm )
325arcommand=$( echo ${archfileline##%AR} )
326
327# get make utility from arch.fcm file
328archfileline=$( grep -i '^%MAKE' arch.fcm )
329makecommand=$( echo ${archfileline##%MAKE} )
330
331# get basic libraries to link with arch.fcm file
332archfileline=$( grep -i '^%BASE_LD' arch.fcm )
333archfileopt=$( echo ${archfileline##%BASE_LD} )
334LIB="$LIB  ${archfileopt}"
335
336#NB some -I... might be located in the %FPP_FLAGS section of the arch file
337archfileline=$( grep -i '^%FPP_FLAGS' arch.fcm )
338for inc in $archfileline ; do INCLUDE="$INCLUDE `echo $inc | grep '\-I'`" ; done
339
340phys_root=$physique
341if [[ "${physique:0:3}" == "lmd" ]] ; then phys_root=lmd ; fi
342if [[ "${physique:0:3}" == "mar" ]] ; then phys_root=mar ; fi
343if [[ "${physique:0:4}" == "mars" ]] ; then phys_root=mars ; fi
344if [[ "${physique:0:3}" == "std" ]] ; then phys_root=std ; fi
345if [[ "${physique:0:5}" == "venus" ]] ; then phys_root=venus ; fi
346if [[ "${physique:0:5}" == "titan" ]] ; then phys_root=titan ; fi
347if [[ "${physique:0:3}" == "dev" ]] ; then phys_root=dev ; fi
348
349if [[ "$physique" != "nophys" ]]
350then
351   #We'll use some physics
352   src_dirs="$src_dirs phy_common phy$physique"
353   LIBPHY='$(LIBO)/libphy'"$physique"'.a'
354   LIBPHY_COMMON='$(LIBO)/libphy_common.a'
355   lib_phy='-lphy'"$physique"' -lphy_common'
356   CPP_KEY="$CPP_KEY CPP_PHYS"
357   if [[ "${phys_root}" == "lmd" ]]
358   then
359   #For lmd physics, default planet type is Earth
360   CPP_KEY="$CPP_KEY CPP_EARTH"
361   fi
362fi
363
364######### CAS PARTICULIER CHIMIE TITAN
365if [[ "$physique" == "titan" ]]
366then
367   INCLUDE="$INCLUDE"' -I$(LIBF)/chim'"$physique"
368   LIB="$LIB -l${LIBPREFIX}chim$physique"
369   opt_dep="$opt_dep chim$physique"
370   src_dirs="$src_dirs chim$physique"
371# get C compiler name and optim from arch.fcm file
372   archfileline=$( grep -i '^%C_COMPILER' arch.fcm )
373   ccompiler=$( echo ${archfileline##%C_COMPILER} )
374   archfileline=$( grep -i '^%C_OPTIM' arch.fcm )
375   coptim=$( echo ${archfileline##%C_OPTIM} )
376   OPTIMC="${coptim}"
377   INCLUDEC='-I$(LIBF)/grid -I.'
378fi
379#########
380
381######### CAS PARTICULIER NUAGES VENUS
382if [[ "$physique" == "venus" ]]
383then
384   src_dirs="$src_dirs phy${physique}/cloudvenus"
385fi
386#########
387
388# for Mars (but could be used by others as well), there is also "aeronomars"
389if [[ -d ${LIBFGCM}/aerono${physique} ]]
390then
391   src_dirs="$src_dirs aerono$physique"
392   INCLUDE="$INCLUDE -I${LIBFGCM}/aerono${physique}"
393   LIB="$LIB -l${LIBPREFIX}aerono$physique"
394   opt_dep="$opt_dep aerono$physique"
395   laeronomars="-l${LIBPREFIX}aeronomars"
396fi
397
398
399if [[ "$chimie" == "INCA" ]]
400then
401   CPP_KEY="$CPP_KEY INCA"
402   INCLUDE="$INCLUDE -I${INCA_INCDIR}"
403   LIB="$LIB -L${INCA_LIBDIR} -lchimie"
404   libchimie=" -L${INCA_LIBDIR} -lchimie"
405fi
406
407if [[ "$couple" != "false" ]]
408then
409   CPP_KEY="$CPP_KEY CPP_COUPLE"
410   INCLUDE="$INCLUDE -I${OASIS_INCDIR}"
411   LIB="$LIB -L${OASIS_LIBDIR} -lpsmile.${couple} -lmpp_io"
412fi
413
414if [[ "$parallel" != "none" && \
415     ( "$code" == "newstart" || "$code" == "start2archive" ) ]]
416then
417    echo "newstart or start2archive utilities should be run in serial!"
418    echo " Compile without -parallel [mpi|omp|mpi_omp] option!"
419    exit
420fi
421
422if [[ "$parallel" == "none" ]]
423then
424  FLAG_PARA=''
425else
426  FLAG_PARA="$paramem"
427fi
428
429if [[ "$parallel" == "mpi" ]]
430then
431   CPP_KEY="$CPP_KEY CPP_PARA CPP_MPI"
432  # MPI additional compilation options
433  archfileline=$( grep -i '^%MPI_FFLAGS' arch.fcm )
434  PARA_FFLAGS=$( echo ${archfileline##%MPI_FFLAGS} )
435  # MPI additional links
436  archfileline=$( grep -i '^%MPI_LD' arch.fcm )
437  PARA_LD=$( echo ${archfileline##%MPI_LD} )
438elif [[ "$parallel" == "omp" ]]
439then
440   CPP_KEY="$CPP_KEY CPP_PARA CPP_OMP"
441  # OMP additional compilation options
442  archfileline=$( grep -i '^%OMP_FFLAGS' arch.fcm )
443  PARA_FFLAGS=$( echo ${archfileline##%OMP_FFLAGS} )
444  # OMP additional links
445  archfileline=$( grep -i '^%OMP_LD' arch.fcm )
446  PARA_LD=$( echo ${archfileline##%OMP_LD} )
447elif [[ "$parallel" == "mpi_omp" ]]
448then
449   CPP_KEY="$CPP_KEY CPP_PARA CPP_MPI CPP_OMP"
450  # MPI additional compilation options
451  archfileline=$( grep -i '^%MPI_FFLAGS' arch.fcm )
452  PARA_FFLAGS=$( echo ${archfileline##%MPI_FFLAGS} )
453  # OMP additional compilation options
454  archfileline=$( grep -i '^%OMP_FFLAGS' arch.fcm )
455  PARA_FFLAGS="${PARA_FFLAGS} "$( echo $archfileopt ${archfileline##%OMP_FFLAGS} )
456  # MPI additional links
457  archfileline=$( grep -i '^%MPI_LD' arch.fcm )
458  PARA_LD=$( echo ${archfileline##%MPI_LD} )
459  # OMP additional links
460  archfileline=$( grep -i '^%OMP_LD' arch.fcm )
461  PARA_LD="${PARA_LD} "$( echo $archfileopt ${archfileline##%OMP_LD} )
462fi
463
464if [[ ( "$parallel" == "omp" || "$parallel" == "mpi_omp" ) \
465   && "$compil_mod" == "debug" ]]
466then
467    echo "Usually, parallelization with OpenMP requires some optimization."
468    echo "We suggest switching to \"-dev\"."
469fi
470
471if [ "$veget" = "true" -o "$veget" = "orchidee1.9" -o "$veget" = "orchidee2.0" ]
472then
473
474   INCLUDE="${INCLUDE} -I${ORCH_INCDIR}"
475   CPP_KEY="$CPP_KEY CPP_VEGET"
476# temporary, for Orchidee versions 1.9.* (before openmp activation)
477   if [[ "$veget" == "orchidee1.9" ]] ; then
478      CPP_KEY="$CPP_KEY ORCHIDEE_NOOPENMP"
479   fi
480   if [[ "$veget" == "orchidee2.0" ]] ; then
481      orch_libs="sechiba parameters stomate parallel orglob orchidee"
482   else
483      orch_libs="sechiba parameters stomate parallel orglob"
484   fi
485   LIB="${LIB} -L${ORCH_LIBDIR}"
486   for lib in ${orch_libs} ; do
487      if [ -f ${ORCH_LIBDIR}/lib${LIBPREFIX}$lib.a ] ; then
488         LIB="${LIB} -l${LIBPREFIX}$lib "
489      fi
490   done
491elif [[ "$veget" != "false" ]] ; then
492   echo "Option -v $veget does not exist"
493   echo "Use ./makelmdz -h for more information"
494   exit 
495fi
496
497if [[ $io == ioipsl ]]
498then
499   CPP_KEY="$CPP_KEY CPP_IOIPSL"
500   INCLUDE="$INCLUDE -I${IOIPSL_INCDIR}"
501   LIB="$LIB -L${IOIPSL_LIBDIR} -l${LIBPREFIX}ioipsl"
502elif [[ $io == mix ]]
503then
504   # For now, xios implies also using ioipsl
505   CPP_KEY="$CPP_KEY CPP_IOIPSL CPP_XIOS"
506   INCLUDE="$INCLUDE -I${IOIPSL_INCDIR} -I${XIOS_INCDIR}"
507   LIB="$LIB -L${IOIPSL_LIBDIR} -l${LIBPREFIX}ioipsl -L${XIOS_LIBDIR} -l${LIBPREFIX}stdc++ -l${LIBPREFIX}xios"
508elif [[ $io == xios ]]
509then
510   # For now, xios implies also using ioipsl
511   CPP_KEY="$CPP_KEY CPP_IOIPSL CPP_XIOS CPP_IOIPSL_NO_OUTPUT"
512   INCLUDE="$INCLUDE -I${IOIPSL_INCDIR} -I${XIOS_INCDIR}"
513   LIB="$LIB -L${IOIPSL_LIBDIR} -l${LIBPREFIX}ioipsl -L${XIOS_LIBDIR} -l${LIBPREFIX}stdc++ -l${LIBPREFIX}xios"
514fi
515
516if [[ "$cosp" == "true" ]]
517then
518   CPP_KEY="$CPP_KEY CPP_COSP"
519   COSP_PATH="$LIBFGCM/cosp"
520   src_dirs="$src_dirs cosp"
521#   LIB="${LIB} -l${LIBPREFIX}cosp"
522   opt_dep="$opt_dep cosp"
523   lcosp="-l${LIBPREFIX}cosp"
524   INCLUDE="$INCLUDE"' -I$(LIBF)/cosp'
525fi
526
527if [[ "$sisvat" == "true" ]]
528then
529   CPP_KEY="$CPP_KEY CPP_SISVAT"
530   src_dirs="$src_dirs phy${physique}/sisvat"
531fi
532
533if [[ "$rrtm" == "true" ]]
534then
535   CPP_KEY="$CPP_KEY CPP_RRTM"
536   src_dirs="$src_dirs phy${physique}/rrtm"
537fi
538
539if [[ "$dust" == "true" ]]
540then
541   CPP_KEY="$CPP_KEY CPP_Dust"
542   src_dirs="$src_dirs phy${physique}/Dust"
543fi
544
545if [[ "$strataer" == "true" ]]
546then
547   CPP_KEY="$CPP_KEY CPP_StratAer"
548   src_dirs="$src_dirs phy${physique}/StratAer"
549fi
550
551
552INCLUDE="$INCLUDE ${NETCDF_INCDIR}"
553LIB="$LIB ${NETCDF_LIBDIR}"
554
555########################################################################
556# calcul du nombre de dimensions
557########################################################################
558
559
560dim_full=$dim
561dim=`echo $dim | sed -e 's/[^0-9]/ /g'` 
562set $dim
563dimc=$#
564echo calcul de la dimension
565echo dim $dim
566echo dimc $dimc
567
568
569########################################################################
570# Gestion des dimensions du modele.
571# on cree ou remplace le fichier des dimensions
572########################################################################
573
574cd $LIBFGCM/grid
575if [[ -f dimensions.h ]]
576then
577  echo 'ATTENTION: vous etes sans doute en train de compiler le modele par ailleurs'
578  echo "Attendez que la premiere compilation soit terminee pour relancer la suivante."
579  echo "Si vous etes sur que vous ne compilez pas le modele par ailleurs,"
580  echo  vous pouvez continuer en repondant oui.
581  echo "Voulez-vous vraiment continuer?"
582  echo ""
583  echo "WARNING: you are probably already compiling the model somewhere else."
584  echo "Wait until the first compilation is finished before launching this one."
585  echo "If you are sure that you are not compiling elsewhere, just answer "
586  echo "yes (or 'oui') to the question below to proceed."
587  echo "Do you wish to continue?"
588  read reponse
589  if [[ $reponse == "oui" || $reponse == "yes" ]]
590  then
591    \rm -f $LIBFGCM/grid/dimensions.h
592  else
593    exit
594  fi
595fi
596
597
598cd $LIBFGCM/grid/dimension
599./makdim $dim
600if (($? != 0))
601then
602    exit 1
603fi
604
605cat $LIBFGCM/grid/dimensions.h
606cd $LMDGCM
607
608if [[ "$bands" != "" ]]
609then
610  # Generic model, recreate bands.h (IR & VIS bands for radiative transfer)
611  bands=$(echo $bands | sed -e 's/[^0-9]/ /g')
612  cd $LIBFGCM/phy$physique/bands
613  ./makbands $bands
614  cat $LIBFGCM/phy$physique/bands.h
615  cd $LMDGCM
616fi
617
618if [[ "$scatterers" != "" ]]
619then
620  # Generic model, recreate scatterers.h
621  cd $LIBFGCM/phy$physique/scatterers
622  ./make_scatterers $scatterers
623  cat $LIBFGCM/phy$physique/scatterers.h
624  cd $LMDGCM
625fi
626
627
628########################################################################
629# Differentes dynamiques (3d, 2d, 1d)
630########################################################################
631
632if (( $dimc == 3 )) ; then
633   src_dirs="$src_dirs $filtre dyn3d_common dyn3d${FLAG_PARA}"
634   if [[ $physique != "nophys" ]] ; then
635     src_dirs="$src_dirs dynphy_lonlat dynphy_lonlat/phy${phys_root}"
636     libdyn_phy="-ldynphy_lonlat"
637     LIBDYN_PHYS='$(LIBO)/libdynphy_lonlat.a'
638     INCLUDE="$INCLUDE "'-I$(LIBF)/dynphy_lonlat'
639     INCLUDE="$INCLUDE "'-I$(LIBF)/dynphy_lonlat/'"${phys_root}"
640   fi
641  cd $LIBFGCM/grid
642  \rm fxyprim.h
643  cp -p fxy_${grille}.h fxyprim.h
644  filtre="FILTRE=$filtre"
645  INCLUDE="$INCLUDE "'-I$(LIBF)/dyn3d${FLAG_PARA} -I$(LIBF)/dyn3d_common '
646elif (( $dimc == 2 )) ; then
647   src_dirs="$src_dirs dyn2d"
648   filtre="FILTRE= L_FILTRE= "
649   INCLUDE="$INCLUDE "'-I$(LIBF)/dyn2d'
650elif (( $dimc == 1 )) ; then
651   ## Sanity check: 1D models should be used in serial
652   if [[ $parallel != "none" ]]
653   then
654     echo "Error: a 1D model should not be compiled with "
655     echo "       -parallel [mpi|omp|mpi_omp] option!"
656     exit
657   fi
658   echo pas de dynamique
659   src_dirs="$src_dirs phy${physique}/dyn1d"
660   CPP_KEY="$CPP_KEY CPP_1D"
661   filtre="L_DYN= DYN= FILTRE= L_FILTRE= "
662   #INCLUDE="$INCLUDE "'-I$(LIBF)/dyn3d -I$(LIBF)/dyn3d_common ' # Pas tres propre
663   INCLUDE="$INCLUDE "' -I$(LIBF)/phy'"$physique"'/dyn1d'
664else
665   echo Dimension dimc=$dimc pas prevu ; exit
666fi
667
668cd $LMDGCM
669
670########################################################################
671# library directory name:
672########################################################################
673
674nomlib=`echo ${arch}_${physique}_${dim_full}_${grille}_${compil_mod}_parall${parallel}_${CPP_KEY}_${FLAG_PARA} | sed -e 's/ //g' -e 's/-//g ' | sed -e 's/CPP_//g'`
675echo "Path to library: "$nomlib
676
677########################################################################
678#  Cleanup for a full recompilation, if requested
679########################################################################
680
681if [[ $full == "full" ]]
682then
683# remove makefile and libraries
684  echo "-full option: recompiling from scratch"
685  \rm -f makefile
686  \rm -rf "${LIBOGCM}/${nomlib}"
687fi
688
689########################################################################
690#  Avant de lancer le make, on recree le makefile si necessaire
691########################################################################
692########################################################################
693# c'est a dire dans 3 cas:
694# 1. si la liste des fichiers .F et .h a ete modifiee depuis la
695#    derniere creation du makefile
696# 2. si le fichier contenant cette liste "liste_des_sources"
697#    n'existe pas.
698# 3. Si le makefile n'existe pas.
699########################################################################
700cd $LMDGCM
701
702
703if [[ -r .makelmdz ]]
704then
705old_lmdz_configuration=$(cat .makelmdz )
706else
707old_lmdz_configuration=""
708fi
709lmdz_configuration="$src_dirs"
710if [[ "$lmdz_configuration" != "$old_lmdz_configuration" ]]
711then
712  configuration_change="true"
713else
714  configuration_change="false"
715fi
716
717mkdir -p make_dir
718suf_make=`echo $src_dirs | sed -e 's/\//_/g' -e 's/ /_/g'`
719echo suf_make $suf_make
720
721\rm tmp77 tmp90
722for dir in $src_dirs ; do
723find libf/$dir -name '*.[Fh]' -print | sort >> tmp77
724find libf/$dir -name '*.F90' -print | sort >> tmp90
725######### CAS PARTICULIER CHIMIE TITAN
726if [[ "$physique" == "titan" ]]
727then 
728  find libf -name '*.[ch]' -print | sort > tmpC
729fi
730#########
731done
732
733liste77=make_dir/liste_des_sources_f77_$suf_make
734liste90=make_dir/liste_des_sources_f90_$suf_make
735if [[ "$physique" == "titan" ]] ; then
736listeC=make_dir/liste_des_sources_C_$suf_make
737fi
738makefile=make_dir/makefile_$suf_make
739
740if [[ $configuration_change == "true" || ! ( -r makefile ) || ! ( -r $liste90 ) || ! ( -r $liste77 ) || ` diff tmp77 $liste77 | wc -w ` -ne 0 || ` diff tmp90 $liste90 | wc -w ` -ne 0 ]]
741then
742  echo "les fichiers suivants ont ete crees ou detruits"
743  echo "ou les fichiers suivants sont passes ou ne sont plus en Fortran 90"
744  diff $liste77  tmp77
745  diff $liste90 tmp90
746  \cp -f tmp77 $liste77
747  \cp -f tmp90 $liste90
748######### CAS PARTICULIER CHIMIE TITAN
749  if [[ "$physique" == "titan" ]]
750  then 
751  diff $listeC tmpC
752  \cp -f tmpC $listeC
753  fi
754#########
755  echo "Recreating the makefile"
756  echo "src_dirs: $src_dirs"
757  ./create_make_gcm $src_dirs > tmp
758  \mv -f tmp $makefile
759  echo "New makefile created"
760######### CAS PARTICULIER CHIMIE TITAN
761else if [[ "$physique" == "titan" ]]
762 then
763   if [[ ! ( -r $listeC ) || ` diff tmpC $listeC | wc -w ` -ne 0 ]]
764   then
765     diff $listeC tmpC
766     \cp -f tmpC $listeC
767     echo "on recree le makefile"
768     ./create_make_gcm $src_dirs > tmp
769     \mv -f tmp $makefile
770     echo "Nouveau makefile cree"
771   fi
772 fi
773#########
774fi
775
776ln -sf $makefile makefile
777
778#Create a .makelmdz file containing main compilation option for later comparisons
779echo "$lmdz_configuration" > .makelmdz
780
781#################################################################
782# Preparation de l'execution de la commande make
783#################################################################
784
785# find code suffix and directory where code is located
786if [[ -r $LMDGCM/libf/dyn${dimc}d${FLAG_PARA}/${code}.F ]]
787then
788  source_code=${code}.F
789  dirmain=dyn${dimc}d${FLAG_PARA}
790else
791  if [[ -r $LMDGCM/libf/dyn${dimc}d${FLAG_PARA}/${code}.F90 ]]
792  then
793    source_code=${code}.F90
794    dirmain=dyn${dimc}d${FLAG_PARA}
795  else
796    if [[ -r $LMDGCM/libf/phy${physique}/${code}.F ]]
797    then
798      source_code=${code}.F
799      dirmain=phy${physique}
800    else
801      if [[ -r $LMDGCM/libf/phy${physique}/${code}.F90 ]]
802      then
803        source_code=${code}.F90
804        dirmain=phy${physique}
805      else
806        if [[ -r $LMDGCM/libf/dynphy_lonlat/phy$phys_root/${code}.F ]] 
807        then
808          source_code=${code}.F
809          dirmain="dynphy_lonlat/phy${phys_root}"
810        else
811          if [[ -r $LMDGCM/libf/phy$physique/dyn1d/${code}.F ]]
812          then
813            source_code=${code}.F
814            dirmain=phy$physique/dyn1d
815          else
816            echo "Error: cannot find ${code}.F[90]"
817            echo " neither in dyn${dimc}d${FLAG_PARA} nor in phy${physique}"
818            exit
819          fi
820        fi
821      fi
822    fi
823  fi
824fi
825
826if [[ ! -d "${LIBOGCM}/${nomlib}" ]]
827then
828  mkdir ${LIBOGCM}/${nomlib}
829  # check we indeed managed to create the directory
830  if [[ ! $? ]]
831  then
832    echo "Error: could not create directory ${LIBOGCM}/${nomlib}"
833    exit
834  fi
835fi
836
837# where module files are created
838mod_loc_dir=$localdir
839
840if [[ "$physique" != "nophys" ]]
841then
842  INCLUDE="$INCLUDE"' -I$(LIBF)/phy'"$physique"
843#  phys="PHYS=$physique"
844#else
845#  # trick to avoid having a physics-related library in the makefile
846#  phys="L_PHY= LIBPHY="
847fi
848INCLUDE="$INCLUDE"' -I'${LIBOGCM}/${nomlib}
849#if (( $dimension == 1 ))
850#then
851# INCLUDE="$INCLUDE"' -I$(LIBF)/dyn3d -I'${LIBOGCM}/${nomlib}
852#else
853#INCLUDE="$INCLUDE"' -I$(LIBF)/dyn'${dimc}'d'$FLAG_PARA' -I'${LIBOGCM}/${nomlib}
854#fi
855
856# ranlib utility (check it exists or else default to ls)
857if [[ `which ranlib > /dev/null 2>&1 ; echo $?` -eq 0 ]]
858then
859  ranlib="ranlib"
860else
861  ranlib="ls"
862fi
863
864# add CPP keys to COMPIL_FLAGS
865# (but first add -D before all CPP_KEY items)
866cpp_definitions=`echo $CPP_KEY | sed -e 's/[A-Za-z_=0-9]*/-D&/g'`
867# (but add a -WF,-D before all CPP_KEY items) => for xlf on Vargas
868if [[ "${fcompiler:0:3}" == "xlf" ]]
869then
870cpp_definitions=`echo $CPP_KEY | sed -e 's/[A-Za-z_=0-9]*/-WF,-D&/g'`
871fi
872COMPIL_FFLAGS="${COMPIL_FFLAGS} ${cpp_definitions}"
873
874#################################################################
875# Execution du make
876#################################################################
877echo $makecommand RANLIB=$ranlib -f $LMDGCM/makefile \
878OPTION_DEP="$opt_dep" OPTION_LINK="$LIB ${PARA_LD}" \
879OPTIM90="${COMPIL_FFLAGS} ${PARA_FFLAGS}" \
880OPTIMTRU90="${COMPIL_FFLAGS} ${PARA_FFLAGS}" \
881OPTIM="${COMPIL_FFLAGS} ${PARA_FFLAGS}" \
882OPTIMC="$OPTIMC" \
883INCLUDE="$INCLUDE" \
884INCLUDEC="$includec" \
885$filtre \
886LIBO=${LIBOGCM}/${nomlib} \
887"PHYS=$physique" \
888LIBPHY=${LIBPHY} \
889LIBPHY_COMMON=${LIBPHY_COMMON} \
890LIBDYN_PHYS=${LIBDYN_PHYS} \
891DIM=$dimc \
892FLAG_PARA=$FLAG_PARA \
893L_PHY="$lib_phy" \
894L_DYN_PHY="$libdyn_phy" \
895L_ADJNT=$adjnt \
896L_COSP="$lcosp" \
897L_AERONOMARS="$laeronomars" \
898L_CHIMIE="$libchimie" \
899LOCAL_DIR="$localdir"  \
900F77="$fcompiler" \
901F90="$fcompiler" \
902CCC="$ccompiler" \
903OPLINK="$LIB" \
904LINK="$linker" \
905GCM="$LMDGCM" \
906MOD_LOC_DIR=$mod_loc_dir \
907MOD_SUFFIX="mod" \
908AR=$arcommand \
909DIRMAIN=$dirmain \
910SOURCE=$source_code \
911PROG=$code
912
913$makecommand RANLIB=$ranlib -f $LMDGCM/makefile \
914OPTION_DEP="$opt_dep" OPTION_LINK="$LIB ${PARA_LD}" \
915OPTIM90="${COMPIL_FFLAGS} ${PARA_FFLAGS}" \
916OPTIMTRU90="${COMPIL_FFLAGS} ${PARA_FFLAGS}" \
917OPTIM="${COMPIL_FFLAGS} ${PARA_FFLAGS}" \
918OPTIMC="$OPTIMC" \
919INCLUDE="$INCLUDE" \
920INCLUDEC="$includec" \
921$filtre \
922LIBO=${LIBOGCM}/${nomlib} \
923"PHYS=$physique" \
924LIBPHY=${LIBPHY} \
925LIBPHY_COMMON=${LIBPHY_COMMON} \
926LIBDYN_PHYS=${LIBDYN_PHYS} \
927DIM=$dimc \
928FLAG_PARA=$FLAG_PARA \
929L_PHY="$lib_phy" \
930L_DYN_PHY="$libdyn_phy" \
931L_ADJNT="$adjnt" \
932L_COSP="$lcosp" \
933L_AERONOMARS="$laeronomars" \
934L_CHIMIE="$libchimie" \
935LOCAL_DIR="$localdir"  \
936F77="$fcompiler" \
937F90="$fcompiler" \
938CCC="$ccompiler" \
939OPLINK="$LIB" \
940LINK="$linker" \
941GCM="$LMDGCM" \
942MOD_LOC_DIR=$mod_loc_dir \
943MOD_SUFFIX="mod" \
944AR=$arcommand \
945DIRMAIN=$dirmain \
946SOURCE=$source_code \
947PROG=$code
948
949if [[ -r $LIBFGCM/grid/dimensions.h ]]
950then
951  # Cleanup: remove dimension.h file
952  \rm -f $LIBFGCM/grid/dimensions.h
953fi
Note: See TracBrowser for help on using the repository browser.