source: LMDZ6/trunk/makelmdz @ 4186

Last change on this file since 4186 was 4186, checked in by idelkadi, 22 months ago

Modification of the name of the library according to the radiative transfer code used (ecrad/rrtm)

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