source: LMDZ6/trunk/makelmdz @ 5529

Last change on this file since 5529 was 5528, checked in by fhourdin, 5 days ago

Rephasage makelmdz/create_make_gcm

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