source: LMDZ6/branches/Amaury_dev/makelmdz_fcm @ 5144

Last change on this file since 5144 was 5133, checked in by abarral, 4 months ago

Fix 1D, rrtm & ecrad compilation

  • 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: 21.8 KB
Line 
1#!/bin/bash
2# $Id: makelmdz_fcm 5133 2024-07-26 12:20:54Z abarral $
3# This is a script in Bash.
4
5# FH : on ne crée plus le fichier arch.mk qui est supposé exister par
6# FH : ailleurs.
7# FH : ulterieurement, ce fichier sera pré-existant pour une série
8# FH : de configurations en versions optimisées et debug qui seront
9# FH : liés (ln -s) avec arch.mk en fonction de l'architecture.
10# FH : Pour le moment, cette version est en test et on peut créer les
11# FH : arch.mk en lançant une première fois makegcm.
12#
13set -eu
14
15function init_vars() {
16  ########################################################################
17  # options par defaut pour la commande make
18  ########################################################################
19
20  dim="96x72x19"
21  physique=lmd
22  filtre=filtrez
23  couple=false
24  veget=false
25  inlandsis=false
26  rad="oldrad"
27  dust=false
28  strataer=false
29  chimie=false
30  parallel=none
31  paramem="mem"
32  compil_mod=prod
33  io=ioipsl
34  cosp=false
35  cosp2=false
36  cospv2=false
37  job=1
38  full=''
39  libphy=false
40  isotopes=false
41  isoverif=false
42  diagiso=false
43  isotrac=false
44  force_compile=false
45  cplocninca=false
46
47  arch_defined="FALSE"
48  arch_path="arch"
49  arch_default_path="arch"
50
51  LMDGCM=$(pwd)
52  LIBOGCM=$LMDGCM/libo
53  LIBFGCM=$LMDGCM/libf
54  DYN_COMMON_PATH=$LIBFGCM/dyn3d_common
55  # path for optional packages, but default set to ".void_dir"
56  FILTRE_PATH=$LMDGCM/.void_dir
57  DYN_PHYS_PATH=$LMDGCM/.void_dir
58  DYN_PHYS_SUB_PATH=$LMDGCM/.void_dir
59  PHY_COMMON_PATH=$LMDGCM/.void_dir
60  RAD_PATH=$LMDGCM/.void_dir
61  INLANDSIS_PATH=$LMDGCM/.void_dir
62  DUST_PATH=$LMDGCM/.void_dir
63  STRATAER_PATH=$LMDGCM/.void_dir
64  COSP_PATH=$LMDGCM/.void_dir
65  fcm_path=$LMDGCM/tools/fcm/bin
66
67  ########################################################################
68  #  Quelques initialisations de variables du shell.
69  ########################################################################
70
71  CPP_KEY="IN_LMDZ"
72  INCLUDE=""
73  LIB=""
74  COMPIL_FFLAGS="%PROD_FFLAGS"
75  PARA_FFLAGS=""
76  PARA_LD=""
77  EXT_SRC=""
78}
79
80function read_cmdline_options() {
81
82  ########################################################################
83  # lecture des options de mymake
84  ########################################################################
85
86  while (($# > 0))
87    do
88    case $1 in
89        "-h") cat <<fin
90  Usage :
91  makelmdz_fcm [options] -arch nom_arch exec
92  [-h]                       : brief help
93  [-d [[IMx]JMx]LM]          : IM, JM, LM are the dimensions in x, y, z (default: $dim)
94  [-p PHYS]                  : set of physical parametrizations (in libf/phyPHYS), (default: lmd)
95  [-prod / -dev / -debug]    : compilation mode production (default) / developement / debug
96  [-c false/MPI1/OMCT]       : coupling with ocean model : MPI1/OMCT/false (default: false)
97  [-v false/orchideetrunk/orchidee2.1/orchidee2.0/orchidee1.9] : version of the vegetation model to include (default: false)
98            false       : no vegetation model
99            orchideetrunk : compile using ORCHIDEE trunk from revision 7757 or higher
100            orchidee2.1 : compile using ORCHIDEE 2.1 until 4.1 included or until revision 7757 on the trunk
101            orchidee2.0 : compile using ORCHIDEE 2.0
102            orchidee1.9 : compile using ORCHIDEE up to the version including OpenMP in ORCHIDEE : tag 1.9-1.9.5(version AR5)-1.9.6
103            true        : (obsolete; for backward compatibility) use ORCHIDEE tag 1.9-1.9.6
104  [-chimie INCA/false]       : with INCA chemistry model or without (default: false)
105  [-cplocninca ]        : allow transfer of species from PISCES to INCA (default: false)
106  [-cosp true/false]    : compile with/without cosp package (default: false)
107  [-cosp2 true/false]    : compile with/without cosp2 package (default: false)
108  [-cospv2 true/false]    : compile with/without cospv2 package (default: false)
109  [-inlandsis true/false]  : compile with/without inlandsis package (default: false)
110  [-rrtm true/false]    : compile with/without rrtm package (default: false)
111  [-rad oldrad/rrtm/ecrad]    : compile with oldrad/rrtm/ecrad radiatif code (default: oldrad)
112  [-dust true/false]    : compile with/without the dust package by Boucher and co (default: false)
113  [-strataer true/false]    : compile with/without the strat aer package by Boucher and co (default: false)
114  [-isotopes true/false]    : compile with/without water isotopes in the physics
115  [-isoverif true/false]    : compile with/without verifications for water isotopes in the physics
116  [-diagiso true/false]    : compile with/without special diagnostics for water isotopes in the physics
117  [-isotrac true/false]    : compile with/without tracers of water isotopes in the physics
118  [-parallel none/mpi/omp/mpi_omp] : parallelism (default: none) : mpi, openmp or mixted mpi_openmp
119  [-io ioipsl/mix/xios]                   : Input/Output library (default: ioipsl)
120  [-include INCLUDES]        : extra include path to add
121  [-cpp CPP_KEY]             : additional preprocessing definitions
122  [-mem]                     : reduced memory dynamics (obsolete flag; always on in parallel mode)
123  [-filtre NOMFILTRE]        : use filtre from libf/NOMFILTRE (default: filtrez)
124  [-link LINKS]              : additional links with other libraries
125  [-j n]                     : active parallel compiling on ntask
126  [-full]                    : full recompiling
127  [-libphy]                  : only compile physics package (no dynamics or main program)
128  [-fcm_path path]           : path to the fcm tool (default: tools/fcm/bin)
129  [-ext_src path]            : path to an additional set of routines to compile with the model
130  [-arch_path path]          : path to architecture files (default: $arch_default_path)
131  [-force_compile]           : recompile although there seems to be an on-going compilation
132   -arch nom_arch            : target architecture
133   exec                      : executable to build
134fin
135      exit 2;;
136
137        "-d")
138      dim=$2; shift; shift;;
139
140        "-p")
141      physique="$2";  shift; shift;;
142
143        "-c")
144      couple="$2"; shift; shift;;
145
146        "-prod")
147      compil_mod="prod"; shift;;
148
149        "-dev")
150      compil_mod="dev"; shift;;
151
152        "-debug")
153      compil_mod="debug"; shift;;
154
155        "-io")
156      io="$2"; shift; shift;;
157
158        "-v")
159      veget="$2"; shift; shift;;
160
161        "-inlandsis")
162            inlandsis="$2"; shift; shift;;
163
164        "-rrtm")
165            if [ "$2" = "false" ]; then rad="oldrad"; else rad="rrtm"; fi; shift; shift;;
166
167        "-rad")
168            rad="$2"; shift; shift;;
169
170        "-dust")
171      dust="$2"; shift; shift;;
172
173        "-strataer")
174      strataer="$2"; shift; shift;;
175
176        "-chimie")
177      chimie="$2"; shift; shift;;
178
179       "-cplocninca")
180            cplocninca=TRUE; shift;;
181
182        "-isotopes")
183      isotopes="$2"; shift; shift;;
184
185        "-isoverif")
186      isoverif="$2"; shift; shift;;
187
188        "-diagiso")
189      diagiso="$2"; shift; shift;;
190
191        "-isotrac")
192      isotrac="$2"; shift; shift;;
193
194        "-parallel")
195      parallel="$2"; shift; shift;;
196
197        "-include")
198      INCLUDE="$INCLUDE -I$2"; shift; shift;;
199
200        "-cpp")
201      CPP_KEY="$CPP_KEY $2"; shift; shift;;
202
203        "-cosp")
204            cosp="$2"; shift; shift;;
205
206        "-cosp2")
207            cosp2="$2"; shift; shift;;
208
209        "-cospv2")
210            cospv2="$2"; shift; shift;;
211
212        "-mem")
213            echo "option -mem is obsolete (now always on in parallel)"
214            paramem="mem"; shift;;
215
216        "-filtre")
217      filtre=$2; shift; shift;;
218
219        "-link")
220      LIB="$LIB $2"; shift; shift;;
221
222        "-fcm_path")
223      fcm_path=$2; shift; shift;;
224
225        "-ext_src")
226      EXT_SRC=$2; shift; shift;;
227
228        "-j")
229      job=$2; shift; shift;;
230
231        "-full")
232      full="-full"; shift;;
233
234        "-libphy")
235      libphy="true"; shift;;
236
237        "-arch")
238      arch=$2; arch_defined="TRUE"; shift; shift;;
239
240        "-arch_path")
241      arch_path=$2; shift; shift;;
242
243        "-force_compile")
244      force_compile=true; shift;;
245
246        *)
247      code="$1"; shift;;
248    esac
249  done
250
251  ###############################################################
252  # path to fcm
253  ###############################################################
254  # handle case when provided path to fcm was given as a relative
255  # path (from makelmdz_fcm script directory) and not an absolute path
256  if [[ ${fcm_path:0:1} != "/" ]]; then
257    # prepend with makelmdz_fcm location
258    fcm_path="$(cd "$(dirname "$0")"; pwd)/$fcm_path"
259  fi
260
261  # add fcm_path to PATH
262  export PATH=$fcm_path:$PATH
263  echo "Path to fcm: $fcm_path"
264}
265
266function init_arch() {
267  ###############################################################
268  # lecture des chemins propres à l'architecture de la machine #
269  ###############################################################
270  rm -f .void_file
271  touch .void_file
272  rm -rf .void_dir
273  mkdir .void_dir
274
275  if [[ "$arch_defined" = "TRUE" ]]; then
276    local i
277    for i in "path" "fcm" "env"; do
278      rm -f "arch.$i"
279
280      if [[ -f "$arch_path/arch-$arch.$i" ]]; then
281        ln -s "$arch_path/arch-$arch.$i" "arch.$i"
282      elif [[ -f "$arch_default_path/arch-$arch.$i" ]]; then
283        ln -s "$arch_default_path/arch-$arch.$i" "arch.$i"
284      elif [[ $i = "env" ]]; then
285        ln -s .void_file arch.env
286      fi
287    done
288
289    # source architecture PATH and ENV files
290    source arch.env
291    source arch.path
292  else
293    echo "STOP: You must define a target architecture"; exit 1
294  fi
295}
296
297function cpp_keys_and_include_mod_path() {
298  ########################################################################
299  # Definition des clefs CPP, des chemins des includes et modules
300  #  et des libraries
301  ########################################################################
302
303  if [[ $compil_mod = "prod" ]]; then
304    COMPIL_FFLAGS="%PROD_FFLAGS"
305  elif [[ $compil_mod = "dev" ]]; then
306    COMPIL_FFLAGS="%DEV_FFLAGS"
307  elif [[ $compil_mod = "debug" ]]; then
308    COMPIL_FFLAGS="%DEBUG_FFLAGS"
309  fi
310
311  phys_root=$physique
312  if [[ ${physique:0:3} = "lmd" ]]; then phys_root=lmd; fi
313  if [[ ${physique:0:4} = "mars" ]]; then phys_root=mars; fi
314  if [[ ${physique:0:3} = "std" ]]; then phys_root=std; fi
315  if [[ ${physique:0:5} = "venus" ]]; then phys_root=venus; fi
316  if [[ ${physique:0:5} = "titan" ]]; then phys_root=titan; fi
317  if [[ ${physique:0:3} = "dev" ]]; then phys_root=dev; fi
318
319  if [[ $physique != "nophys" ]]; then
320     #We'll use some physics
321     CPP_KEY="$CPP_KEY CPP_PHYS"
322     # set physics common utilities path
323     PHY_COMMON_PATH="${LIBFGCM}/phy_common"
324     # set the dyn/phys interface path
325     DYN_PHYS_PATH="${LIBFGCM}/dynphy_lonlat"
326     DYN_PHYS_SUB_PATH="${LIBFGCM}/dynphy_lonlat/phy${phys_root}"
327  fi
328
329  if [[ $filtre = "filtrez" ]]; then
330     FILTRE_PATH=${LIBFGCM}/$filtre
331  fi
332
333  if [[ $chimie = "INCA" ]]; then
334     CPP_KEY="$CPP_KEY INCA"
335     INCLUDE="$INCLUDE ${INCA_INCDIR}"
336     LIB="$LIB ${INCA_LIBDIR} ${INCA_LIB}"
337  fi
338
339  if [[ $isotopes = "true" ]]; then
340     CPP_KEY="$CPP_KEY ISO"
341  fi
342
343  if [[ $isoverif = "true" ]]; then
344     CPP_KEY="$CPP_KEY ISOVERIF"
345  fi
346
347  if [[ $diagiso = "true" ]]; then
348     CPP_KEY="$CPP_KEY DIAGISO"
349  fi
350
351  if [[ $isotrac = "true" ]]; then
352     CPP_KEY="$CPP_KEY ISOTRAC"
353  fi
354
355  if [[ $couple != "false" ]]; then
356      if [[ $couple = "MPI1" ]]; then
357        CPP_KEY="$CPP_KEY CPP_COUPLE"
358        export OASIS_INCDIR=$LMDGCM/../../prism/X64/build/lib/psmile.MPI1
359        export OASIS_LIBDIR=$LMDGCM/../../prism/X64/lib
360        INCLUDE="$INCLUDE -I${OASIS_INCDIR}"
361        LIB="$LIB -L${OASIS_LIBDIR} -lpsmile.MPI1 -lmpp_io"
362      else
363        CPP_KEY="$CPP_KEY CPP_COUPLE CPP_OMCT"
364        INCLUDE="$INCLUDE ${OASIS_INCDIR}"
365        LIB="$LIB ${OASIS_LIBDIR} -lpsmile.MPI1 -lscrip -lmct -lmpeu"
366      fi
367  fi
368
369  if [[ $parallel = "mpi" ]]; then
370     CPP_KEY="$CPP_KEY CPP_PARA CPP_MPI"
371     PARA_FFLAGS="%MPI_FFLAGS"
372     PARA_LD="%MPI_LD"
373  elif [[ $parallel = "omp" ]]; then
374     CPP_KEY="$CPP_KEY CPP_PARA CPP_OMP"
375     PARA_FFLAGS="%OMP_FFLAGS"
376     PARA_LD="%OMP_LD"
377  elif [[ $parallel = "mpi_omp" ]]; then
378     CPP_KEY="$CPP_KEY CPP_PARA CPP_MPI CPP_OMP"
379     PARA_FFLAGS="%MPI_FFLAGS %OMP_FFLAGS"
380     PARA_LD="%MPI_LD %OMP_LD"
381  fi
382
383  if [[ ( $parallel = "omp" || $parallel = "mpi_omp" ) && $compil_mod = "debug" ]]; then
384      echo "Usually, parallelization with OpenMP requires some optimization."
385      echo "We suggest switching to \"-dev\"."
386  fi
387
388  if [[ $veget = "true" || $veget = "orchidee1.9" || $veget = "orchidee2.0" \
389   || $veget = "orchidee2.1" || $veget = "orchideetrunk" ]]; then
390        echo "doing orchidee"
391#NB: option 'true': for backward compatibility. To be used with ORCHIDEE tag 1.9-1.9.6
392#    For this case, cpp flag ORCHIDEE_NOOPENMP must be added to the makelmdz_fcm arguments
393#    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
394   INCLUDE="${INCLUDE} ${ORCH_INCDIR}"
395   CPP_KEY="$CPP_KEY CPP_VEGET"
396# temporary, for Orchidee versions 1.9.* (before openmp activatmodion)
397   if [[ "$veget" = "orchidee1.9" ]]; then
398      CPP_KEY="$CPP_KEY ORCHIDEE_NOOPENMP"
399    fi
400    if [[ "$veget" = "orchidee2.0" ]]; then
401      orch_libs="-lsechiba -lparameters -lstomate -lparallel -lorglob -lorchidee"
402      CPP_KEY="$CPP_KEY ORCHIDEE_NOUNSTRUCT"
403    elif [[ "$veget" = "orchidee2.1" ]]; then
404      CPP_KEY="$CPP_KEY ORCHIDEE_NOLIC"
405      orch_libs="-lsechiba -lparameters -lstomate -lparallel -lorglob -lorchidee"
406    elif [[ "$veget" = "orchideetrunk" ]]; then
407      orch_libs="-lorchidee"
408    else
409      orch_libs="-lsechiba -lparameters -lstomate -lparallel -lorglob"
410    fi
411    LIB="${LIB} ${ORCH_LIBDIR} ${orch_libs}"
412    echo "orchidee lib"
413    echo "${LIB}"
414  elif [[ $veget != "false" ]]; then
415    echo "Option -v $veget does not exist"
416    echo "Use ./makelmdz_fcm -h for more information"
417    exit  1
418  fi
419
420  INLANDSIS_PATH="$LIBFGCM/phy${physique}/inlandsis"
421  if [[ $inlandsis = "true" ]]; then
422     CPP_KEY="$CPP_KEY CPP_INLANDSIS"
423  fi
424
425  if [[ $rad = "rrtm" ]]; then
426     CPP_KEY="$CPP_KEY CPP_RRTM"
427     RAD_PATH="$LIBFGCM/phy${physique}/rrtm"
428  elif [[ $rad = "ecrad" ]]; then
429     CPP_KEY="$CPP_KEY CPP_ECRAD"
430     RAD_PATH="$LIBFGCM/phy${physique}/ecrad"
431  fi
432
433  DUST_PATH="$LIBFGCM/phy${physique}/Dust"
434  if [[ $dust = "true" ]]; then
435     CPP_KEY="$CPP_KEY CPP_Dust"
436  fi
437
438  STRATAER_PATH="$LIBFGCM/phy${physique}/StratAer"
439  if [[ $strataer = "true" ]]; then
440     CPP_KEY="$CPP_KEY CPP_StratAer"
441  fi
442
443  INCLUDE="$INCLUDE ${NETCDF95_INCDIR}"
444  LIB="$LIB ${NETCDF95_LIBDIR} ${NETCDF95_LIB}"
445
446  if [[ $io = "ioipsl" ]]; then
447     CPP_KEY="$CPP_KEY"
448     INCLUDE="$INCLUDE ${IOIPSL_INCDIR}"
449     LIB="$LIB ${IOIPSL_LIBDIR} ${IOIPSL_LIB}"
450  elif [[ $io = "mix" ]]; then
451     CPP_KEY="$CPP_KEY CPP_XIOS"
452     INCLUDE="$INCLUDE ${IOIPSL_INCDIR} ${XIOS_INCDIR}"
453     LIB="$LIB ${IOIPSL_LIBDIR} ${IOIPSL_LIB} ${XIOS_LIBDIR} ${XIOS_LIB}"
454  elif [[ $io = "xios" ]]; then
455     CPP_KEY="$CPP_KEY CPP_XIOS CPP_IOIPSL_NO_OUTPUT"
456     INCLUDE="$INCLUDE ${IOIPSL_INCDIR} ${XIOS_INCDIR}"
457     LIB="$LIB ${IOIPSL_LIBDIR} ${IOIPSL_LIB} ${XIOS_LIBDIR} ${XIOS_LIB}"
458  fi
459
460  if [[ $cosp = "true" ]]; then
461     CPP_KEY="$CPP_KEY CPP_COSP"
462     COSP_PATH="$LIBFGCM/phylmd/cosp"
463  fi
464
465  if [[ $cosp2 = "true" ]]; then
466     CPP_KEY="$CPP_KEY CPP_COSP2"
467     COSP_PATH="$LIBFGCM/phylmd/cosp2"
468  fi
469
470  if [[ $cospv2 = "true" ]]; then
471     CPP_KEY="$CPP_KEY CPP_COSPV2"
472     COSP_PATH="$LIBFGCM/phylmd/cospv2"
473  fi
474
475  if [[ $cplocninca = "TRUE" ]]; then
476      CPP_KEY="${CPP_KEY} CPP_CPLOCNINCA"
477  fi
478
479
480  INCLUDE="$INCLUDE ${NETCDF_INCDIR}"
481  LIB="$LIB ${NETCDF_LIBDIR} ${NETCDF_LIB}"
482}
483
484function handle_dimension() {
485  ########################################################################
486  # calcul du nombre de dimensions
487  ########################################################################
488
489  dim_full=$dim
490  dim=$(echo "$dim" | sed -e 's/[^0-9]/ /g')
491  dimc=$(awk -F" " '{print NF}' <<< "$dim")
492  echo "calcul de la dimension: dim=$dim, dimc=$dimc"
493 
494  ########################################################################
495  # Gestion des dimensions du modele.
496  # on cree ou remplace le fichier des dimensions
497  ########################################################################
498 
499  cd "$LIBFGCM/grid"
500  if [[ -f dimensions.h ]]; then
501      if [[ $force_compile = "true" ]]; then
502          rm -f "$LIBFGCM/grid/dimensions.h"
503      else
504          echo "WARNING: you are probably already compiling the model somewhere else."
505          echo "Wait until the first compilation is finished before launching this one."
506          echo "If you are sure that you are not compiling elsewhere, "
507          echo "If you are sure that you are not compiling elsewhere, then"
508          echo "rm -f \"$LIBFGCM/grid/dimensions.h\""
509          echo "before reruning the compilation"
510          echo "or run makelmdz_fcm with option -force_compile"
511          exit 1
512      fi
513  fi
514 
515  cd "$LIBFGCM/grid/dimension"
516  # shellcheck disable=SC2086
517  ./makdim $dim
518  cat "$LIBFGCM/grid/dimensions.h"
519  cd "$LMDGCM"
520}
521
522function different_dynamics() {
523  ########################################################################
524  # Differentes dynamiques (3d, 2d, 1d)
525  ########################################################################
526  if [[ $dimc = 1 ]]; then
527    ## no need to compile all routines in dyn3d_common either:
528    DYN_COMMON_PATH="$LMDGCM/.void_dir"
529    ## no need to compile all routines in dynlmdz_phy...;
530    ## (because key ones are included in 1D main program)
531    DYN_PHYS_PATH="$LMDGCM/.void_dir"
532    DYN_PHYS_SUB_PATH="$LMDGCM/.void_dir"
533  fi
534
535  ######################################################################
536  # Gestion du filtre qui n'existe qu'en 3d.
537  ######################################################################
538  if [[ $dimc -gt 2 ]]; then
539     filtre="FILTRE=$filtre"
540  else
541     filtre="FILTRE= L_FILTRE= "
542  fi
543  echo "MACRO FILTRE $filtre (dimc=$dimc)"
544}
545
546function create_config_suffix() {
547  ######################################################################
548  # Creation du suffixe de la configuration
549  ######################################################################
550
551  SUFF_NAME=_${dim_full}
552  SUFF_NAME=${SUFF_NAME}_phy${physique}_${rad}
553
554  if [[ $parallel != "none" ]]; then
555    SUFF_NAME=${SUFF_NAME}_para
556    DYN=dyn${dimc}d${paramem}
557    if [[ $paramem = "mem" ]]; then
558        SUFF_NAME=${SUFF_NAME}_${paramem}
559    else
560        echo "The version of the dynamics in dyn3dpar is no longer updated."
561        echo "You should use option \"-mem\"."
562        exit 1
563    fi
564  else
565    SUFF_NAME=${SUFF_NAME}_seq
566    if [[ $dimc = 1 ]]; then
567      # dynamics-related routines in"dyn1d" subdirectory of phy${physique}
568      DYN=phy${physique}/dyn1d
569    else
570      DYN=dyn${dimc}d
571    fi
572  fi
573
574  if [[ $veget != "false" ]]; then
575    SUFF_NAME=${SUFF_NAME}_orch
576  fi
577
578  if [[ $dust = "true" ]]; then
579    SUFF_NAME=${SUFF_NAME}_spla
580  fi
581
582  if [[ $couple != "false" ]]; then
583    SUFF_NAME=${SUFF_NAME}_couple
584  fi
585
586  if [[ $chimie = "INCA" ]]; then
587    SUFF_NAME=${SUFF_NAME}_inca
588  fi
589
590  if [[ "$isotopes" = "true" ]]; then
591    SUFF_NAME=${SUFF_NAME}_iso
592  fi
593  if [[ "$isoverif" = "true" ]]; then
594    SUFF_NAME=${SUFF_NAME}_isoverif
595  fi
596  if [[ "$isotrac" = "true" ]]; then
597    SUFF_NAME=${SUFF_NAME}_isotrac
598  fi
599  if [[ "$diagiso" = "true" ]]; then
600    SUFF_NAME=${SUFF_NAME}_diagiso
601  fi
602
603  if [[ $libphy = "true" ]]; then
604    # special case where we compile only the physics
605    DYN=$LMDGCM/.void_dir
606    DYN_COMMON_PATH=$LMDGCM/.void_dir
607    FILTRE_PATH=$LMDGCM/.void_dir
608    DYN_PHYS_PATH=$LMDGCM/.void_dir
609    DYN_PHYS_SUB_PATH=$LMDGCM/.void_dir
610    #and there is no main program to generate
611    code=""
612    SUFF_NAME=""
613  else
614    SUFF_NAME=${SUFF_NAME}.e
615  fi
616}
617
618function create_fcm_conf() {
619  cd "$LMDGCM"
620  config_fcm="config.fcm"
621  rm -f "bin/${code}${SUFF_NAME}.e"
622  rm -f arch.fcm
623  rm -f arch.opt
624
625  {
626    echo "%ARCH          $arch"
627    echo "%INCDIR        $INCLUDE"
628    echo "%LIB           $LIB"
629    echo "%ROOT_PATH     $PWD"
630    echo "%LIBF          $LIBFGCM"
631    echo "%LIBO          $LIBOGCM"
632    echo "%DYN           $DYN"
633    echo "%DYN_COMMON    $DYN_COMMON_PATH"
634    echo "%PHY_COMMON    $PHY_COMMON_PATH"
635    echo "%FILTRE        $FILTRE_PATH"
636    echo "%PHYS          phy${physique}"
637    echo "%DYN_PHYS      $DYN_PHYS_PATH"
638    echo "%DYN_PHYS_SUB  $DYN_PHYS_SUB_PATH"
639    echo "%RAD           $RAD_PATH"
640    echo "%DUST          $DUST_PATH"
641    echo "%STRATAER      $STRATAER_PATH"
642    echo "%INLANDSIS     $INLANDSIS_PATH"
643    echo "%COSP          $COSP_PATH"
644    echo "%CPP_KEY       $CPP_KEY"
645    echo "%EXEC          $code"
646    echo "%SUFF_NAME     $SUFF_NAME"
647    echo "%COMPIL_FFLAGS $COMPIL_FFLAGS"
648    echo "%PARA_FFLAGS   $PARA_FFLAGS"
649    echo "%PARA_LD       $PARA_LD"
650    echo "%EXT_SRC       $EXT_SRC"
651  } > $config_fcm
652
653  # ecrad conf
654  if [[ $rad = "ecrad" ]]; then
655    cp bld.cfg.ecrad bld.cfg
656  else
657    cp bld.cfg.rrtm bld.cfg
658  fi
659
660  # arch.fcm and arch.opt
661  ln -s "arch/arch-$arch.fcm" arch.fcm
662  if [[ -f arch/arch-$arch.opt && $compil_mod = "prod" ]]; then
663    ln -s "arch/arch-$arch.opt" arch.opt
664  else
665    ln -s .void_file arch.opt
666  fi
667}
668
669function build_gcm() {
670  set +e
671
672  rm -f "$LIBOGCM/$arch$SUFF_NAME/.config/fcm.bld.lock"
673  ./build_gcm "$fcm_path" -j "$job" $full
674  build_status=$?
675
676  rm -rf tmp_src config
677  ln -s "$LIBOGCM/$arch$SUFF_NAME/.config" config
678  ln -s "$LIBOGCM/$arch$SUFF_NAME/.config/ppsrc" tmp_src
679  cp -r "$LIBOGCM/$arch$SUFF_NAME/.config/bin" .
680
681  if [[ -r $LIBFGCM/grid/dimensions.h ]]; then
682    # Cleanup: remove dimension.h file
683    rm -f "$LIBFGCM/grid/dimensions.h"
684  fi
685
686  # build netcdf95 library necessary for the makelmdz script
687  if [[ $build_status = 0 ]]; then
688    if [[ ! -d tools/netcdf95/include ]]; then
689        mkdir tools/netcdf95/include tools/netcdf95/lib
690        cp config/inc/netcdf95.mod config/inc/nf95_*mod tools/netcdf95/include
691        cp config/obj/netcdf95.o config/obj/nf95_*o config/obj/check_start_count_m.o tools/netcdf95/lib
692        cd tools/netcdf95/lib; ar rv libnetcdf95.a -- *.o; ranlib libnetcdf95.a
693        cd -
694      fi
695  fi
696
697  exit $build_status
698}
699
700init_vars
701read_cmdline_options "$@"
702init_arch
703cpp_keys_and_include_mod_path
704handle_dimension
705different_dynamics
706create_config_suffix
707create_fcm_conf
708build_gcm
Note: See TracBrowser for help on using the repository browser.