source: LMDZ6/branches/Amaury_dev/makelmdz_fcm @ 5186

Last change on this file since 5186 was 5159, checked in by abarral, 7 weeks ago

Put dimensions.h and paramet.h into modules

  • 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
RevLine 
[1279]1#!/bin/bash
2# $Id: makelmdz_fcm 5159 2024-08-02 19:58:25Z abarral $
3# This is a script in Bash.
4
[5089]5# FH : on ne crée plus le fichier arch.mk qui est supposé exister par
[783]6# FH : ailleurs.
[5089]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.
[783]12#
[5089]13set -eu
[783]14
[5089]15function init_vars() {
16  ########################################################################
17  # options par defaut pour la commande make
18  ########################################################################
[783]19
[5089]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
[2743]46
[5089]47  arch_defined="FALSE"
48  arch_path="arch"
49  arch_default_path="arch"
[783]50
[5091]51  LMDGCM=$(pwd)
[5089]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
[783]66
[5089]67  ########################################################################
68  #  Quelques initialisations de variables du shell.
69  ########################################################################
[783]70
[5089]71  CPP_KEY="IN_LMDZ"
72  INCLUDE=""
73  LIB=""
74  COMPIL_FFLAGS="%PROD_FFLAGS"
75  PARA_FFLAGS=""
76  PARA_LD=""
77  EXT_SRC=""
78}
[783]79
[5089]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
[783]134fin
[5089]135      exit 2;;
[783]136
[5089]137        "-d")
138      dim=$2; shift; shift;;
[783]139
[5089]140        "-p")
141      physique="$2";  shift; shift;;
[783]142
[5089]143        "-c")
144      couple="$2"; shift; shift;;
[1002]145
[5089]146        "-prod")
147      compil_mod="prod"; shift;;
[1002]148
[5089]149        "-dev")
150      compil_mod="dev"; shift;;
[1002]151
[5089]152        "-debug")
153      compil_mod="debug"; shift;;
[783]154
[5089]155        "-io")
156      io="$2"; shift; shift;;
[783]157
[5089]158        "-v")
159      veget="$2"; shift; shift;;
[3793]160
[5089]161        "-inlandsis")
162            inlandsis="$2"; shift; shift;;
[1990]163
[5089]164        "-rrtm")
165            if [ "$2" = "false" ]; then rad="oldrad"; else rad="rrtm"; fi; shift; shift;;
[3908]166
[5089]167        "-rad")
168            rad="$2"; shift; shift;;
[2631]169
[5089]170        "-dust")
171      dust="$2"; shift; shift;;
[2690]172
[5089]173        "-strataer")
174      strataer="$2"; shift; shift;;
[783]175
[5089]176        "-chimie")
177      chimie="$2"; shift; shift;;
[4247]178
[5089]179       "-cplocninca")
180            cplocninca=TRUE; shift;;
[3924]181
[5089]182        "-isotopes")
183      isotopes="$2"; shift; shift;;
[3924]184
[5089]185        "-isoverif")
186      isoverif="$2"; shift; shift;;
[3924]187
[5089]188        "-diagiso")
189      diagiso="$2"; shift; shift;;
[3924]190
[5089]191        "-isotrac")
192      isotrac="$2"; shift; shift;;
[783]193
[5089]194        "-parallel")
195      parallel="$2"; shift; shift;;
[1132]196
[5089]197        "-include")
198      INCLUDE="$INCLUDE -I$2"; shift; shift;;
[783]199
[5089]200        "-cpp")
201      CPP_KEY="$CPP_KEY $2"; shift; shift;;
[3358]202
[5089]203        "-cosp")
204            cosp="$2"; shift; shift;;
[3491]205
[5089]206        "-cosp2")
207            cosp2="$2"; shift; shift;;
[783]208
[5089]209        "-cospv2")
210            cospv2="$2"; shift; shift;;
[783]211
[5089]212        "-mem")
213            echo "option -mem is obsolete (now always on in parallel)"
214            paramem="mem"; shift;;
[1136]215
[5089]216        "-filtre")
217      filtre=$2; shift; shift;;
[783]218
[5089]219        "-link")
220      LIB="$LIB $2"; shift; shift;;
[2358]221
[5089]222        "-fcm_path")
223      fcm_path=$2; shift; shift;;
[2358]224
[5089]225        "-ext_src")
226      EXT_SRC=$2; shift; shift;;
[783]227
[5089]228        "-j")
229      job=$2; shift; shift;;
[2358]230
[5089]231        "-full")
232      full="-full"; shift;;
[783]233
[5089]234        "-libphy")
235      libphy="true"; shift;;
[2743]236
[5089]237        "-arch")
238      arch=$2; arch_defined="TRUE"; shift; shift;;
[4096]239
[5089]240        "-arch_path")
241      arch_path=$2; shift; shift;;
[1279]242
[5089]243        "-force_compile")
244      force_compile=true; shift;;
[783]245
[5089]246        *)
247      code="$1"; shift;;
248    esac
249  done
[1757]250
[5089]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
[1136]260
[5089]261  # add fcm_path to PATH
262  export PATH=$fcm_path:$PATH
263  echo "Path to fcm: $fcm_path"
264}
[783]265
[5089]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
[2743]274
[5091]275  if [[ "$arch_defined" = "TRUE" ]]; then
[5089]276    local i
277    for i in "path" "fcm" "env"; do
278      rm -f "arch.$i"
[2743]279
[5089]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
[2743]292  else
[5089]293    echo "STOP: You must define a target architecture"; exit 1
[2743]294  fi
[5089]295}
[2743]296
[5089]297function cpp_keys_and_include_mod_path() {
298  ########################################################################
299  # Definition des clefs CPP, des chemins des includes et modules
300  #  et des libraries
301  ########################################################################
[783]302
[5089]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
[2250]310
[5089]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
[783]318
[5089]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
[2239]328
[5091]329  if [[ $filtre = "filtrez" ]]; then
[5089]330     FILTRE_PATH=${LIBFGCM}/$filtre
331  fi
[783]332
[5091]333  if [[ $chimie = "INCA" ]]; then
[5089]334     CPP_KEY="$CPP_KEY INCA"
335     INCLUDE="$INCLUDE ${INCA_INCDIR}"
336     LIB="$LIB ${INCA_LIBDIR} ${INCA_LIB}"
337  fi
[3924]338
[5091]339  if [[ $isotopes = "true" ]]; then
[5089]340     CPP_KEY="$CPP_KEY ISO"
341  fi
[3924]342
[5091]343  if [[ $isoverif = "true" ]]; then
[5089]344     CPP_KEY="$CPP_KEY ISOVERIF"
345  fi
[3924]346
[5091]347  if [[ $diagiso = "true" ]]; then
[5089]348     CPP_KEY="$CPP_KEY DIAGISO"
349  fi
[3924]350
[5091]351  if [[ $isotrac = "true" ]]; then
[5089]352     CPP_KEY="$CPP_KEY ISOTRAC"
353  fi
[783]354
[5091]355  if [[ $couple != "false" ]]; then
356      if [[ $couple = "MPI1" ]]; then
[5089]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
[783]368
[5091]369  if [[ $parallel = "mpi" ]]; then
[5089]370     CPP_KEY="$CPP_KEY CPP_PARA CPP_MPI"
371     PARA_FFLAGS="%MPI_FFLAGS"
372     PARA_LD="%MPI_LD"
[5091]373  elif [[ $parallel = "omp" ]]; then
[5089]374     CPP_KEY="$CPP_KEY CPP_PARA CPP_OMP"
375     PARA_FFLAGS="%OMP_FFLAGS"
376     PARA_LD="%OMP_LD"
[5091]377  elif [[ $parallel = "mpi_omp" ]]; then
[5089]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
[783]382
[5091]383  if [[ ( $parallel = "omp" || $parallel = "mpi_omp" ) && $compil_mod = "debug" ]]; then
[5089]384      echo "Usually, parallelization with OpenMP requires some optimization."
385      echo "We suggest switching to \"-dev\"."
386  fi
387
[5122]388  if [[ $veget = "true" || $veget = "orchidee1.9" || $veget = "orchidee2.0" \
[5091]389   || $veget = "orchidee2.1" || $veget = "orchideetrunk" ]]; then
[4426]390        echo "doing orchidee"
[1811]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
[4426]394   INCLUDE="${INCLUDE} ${ORCH_INCDIR}"
[1772]395   CPP_KEY="$CPP_KEY CPP_VEGET"
[5122]396# temporary, for Orchidee versions 1.9.* (before openmp activatmodion)
[5091]397   if [[ "$veget" = "orchidee1.9" ]]; then
[1811]398      CPP_KEY="$CPP_KEY ORCHIDEE_NOOPENMP"
[5089]399    fi
400    if [[ "$veget" = "orchidee2.0" ]]; then
[4426]401      orch_libs="-lsechiba -lparameters -lstomate -lparallel -lorglob -lorchidee"
[3435]402      CPP_KEY="$CPP_KEY ORCHIDEE_NOUNSTRUCT"
[5089]403    elif [[ "$veget" = "orchidee2.1" ]]; then
[4283]404      CPP_KEY="$CPP_KEY ORCHIDEE_NOLIC"
[4426]405      orch_libs="-lsechiba -lparameters -lstomate -lparallel -lorglob -lorchidee"
[5089]406    elif [[ "$veget" = "orchideetrunk" ]]; then
[4426]407      orch_libs="-lorchidee"
[5089]408    else
[4426]409      orch_libs="-lsechiba -lparameters -lstomate -lparallel -lorglob"
[5089]410    fi
411    LIB="${LIB} ${ORCH_LIBDIR} ${orch_libs}"
412    echo "orchidee lib"
413    echo "${LIB}"
[5091]414  elif [[ $veget != "false" ]]; then
[5089]415    echo "Option -v $veget does not exist"
416    echo "Use ./makelmdz_fcm -h for more information"
417    exit  1
418  fi
[783]419
[5103]420  INLANDSIS_PATH="$LIBFGCM/phy${physique}/inlandsis"
[5091]421  if [[ $inlandsis = "true" ]]; then
[5089]422     CPP_KEY="$CPP_KEY CPP_INLANDSIS"
423  fi
[3793]424
[5091]425  if [[ $rad = "rrtm" ]]; then
[5089]426     CPP_KEY="$CPP_KEY CPP_RRTM"
427     RAD_PATH="$LIBFGCM/phy${physique}/rrtm"
[5091]428  elif [[ $rad = "ecrad" ]]; then
[5089]429     CPP_KEY="$CPP_KEY CPP_ECRAD"
430     RAD_PATH="$LIBFGCM/phy${physique}/ecrad"
431  fi
[1990]432
[5099]433  DUST_PATH="$LIBFGCM/phy${physique}/Dust"
[5091]434  if [[ $dust = "true" ]]; then
[5089]435     CPP_KEY="$CPP_KEY CPP_Dust"
436  fi
[2631]437
[5098]438  STRATAER_PATH="$LIBFGCM/phy${physique}/StratAer"
[5091]439  if [[ $strataer = "true" ]]; then
[5089]440     CPP_KEY="$CPP_KEY CPP_StratAer"
441  fi
[2690]442
[5089]443  INCLUDE="$INCLUDE ${NETCDF95_INCDIR}"
444  LIB="$LIB ${NETCDF95_LIBDIR} ${NETCDF95_LIB}"
[4489]445
[5091]446  if [[ $io = "ioipsl" ]]; then
[5130]447     CPP_KEY="$CPP_KEY"
[5089]448     INCLUDE="$INCLUDE ${IOIPSL_INCDIR}"
449     LIB="$LIB ${IOIPSL_LIBDIR} ${IOIPSL_LIB}"
[5091]450  elif [[ $io = "mix" ]]; then
[5130]451     CPP_KEY="$CPP_KEY CPP_XIOS"
[5089]452     INCLUDE="$INCLUDE ${IOIPSL_INCDIR} ${XIOS_INCDIR}"
453     LIB="$LIB ${IOIPSL_LIBDIR} ${IOIPSL_LIB} ${XIOS_LIBDIR} ${XIOS_LIB}"
[5091]454  elif [[ $io = "xios" ]]; then
[5130]455     CPP_KEY="$CPP_KEY CPP_XIOS CPP_IOIPSL_NO_OUTPUT"
[5089]456     INCLUDE="$INCLUDE ${IOIPSL_INCDIR} ${XIOS_INCDIR}"
457     LIB="$LIB ${IOIPSL_LIBDIR} ${IOIPSL_LIB} ${XIOS_LIBDIR} ${XIOS_LIB}"
458  fi
[1897]459
[5091]460  if [[ $cosp = "true" ]]; then
[5089]461     CPP_KEY="$CPP_KEY CPP_COSP"
462     COSP_PATH="$LIBFGCM/phylmd/cosp"
463  fi
[783]464
[5091]465  if [[ $cosp2 = "true" ]]; then
[5089]466     CPP_KEY="$CPP_KEY CPP_COSP2"
467     COSP_PATH="$LIBFGCM/phylmd/cosp2"
468  fi
[3358]469
[5091]470  if [[ $cospv2 = "true" ]]; then
[5089]471     CPP_KEY="$CPP_KEY CPP_COSPV2"
472     COSP_PATH="$LIBFGCM/phylmd/cospv2"
473  fi
[3358]474
[5091]475  if [[ $cplocninca = "TRUE" ]]; then
[5089]476      CPP_KEY="${CPP_KEY} CPP_CPLOCNINCA"
477  fi
[3491]478
479
[5089]480  INCLUDE="$INCLUDE ${NETCDF_INCDIR}"
481  LIB="$LIB ${NETCDF_LIBDIR} ${NETCDF_LIB}"
482}
[1551]483
[5091]484function handle_dimension() {
485  ########################################################################
486  # calcul du nombre de dimensions
487  ########################################################################
[5089]488
[5091]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"
[5159]500  if [[ -f lmdz_dimensions.f90 ]]; then
[5091]501      if [[ $force_compile = "true" ]]; then
[5159]502          rm -f "$LIBFGCM/grid/lmdz_dimensions.f90"
[5091]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"
[5159]508          echo "rm -f \"$LIBFGCM/grid/lmdz_dimensions.f90\""
[5091]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
[5159]518  cat "$LIBFGCM/grid/lmdz_dimensions.f90"
[5091]519  cd "$LMDGCM"
520}
[5089]521
[5091]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
[783]534
[5091]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}
[783]545
[5091]546function create_config_suffix() {
547  ######################################################################
548  # Creation du suffixe de la configuration
549  ######################################################################
[783]550
[5091]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}
[4096]559    else
[5091]560        echo "The version of the dynamics in dyn3dpar is no longer updated."
561        echo "You should use option \"-mem\"."
[5048]562        exit 1
[4096]563    fi
[5091]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
[1695]573
[5091]574  if [[ $veget != "false" ]]; then
575    SUFF_NAME=${SUFF_NAME}_orch
576  fi
[1695]577
[5091]578  if [[ $dust = "true" ]]; then
579    SUFF_NAME=${SUFF_NAME}_spla
580  fi
[5048]581
[5091]582  if [[ $couple != "false" ]]; then
583    SUFF_NAME=${SUFF_NAME}_couple
584  fi
[783]585
[5091]586  if [[ $chimie = "INCA" ]]; then
587    SUFF_NAME=${SUFF_NAME}_inca
588  fi
[783]589
[5091]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
[783]602
[5091]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}
[783]617
[5091]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
[783]624
[5091]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
[2239]652
[5091]653  # ecrad conf
654  if [[ $rad = "ecrad" ]]; then
655    cp bld.cfg.ecrad bld.cfg
[2202]656  else
[5091]657    cp bld.cfg.rrtm bld.cfg
[1680]658  fi
[5091]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
[2239]664  else
[5091]665    ln -s .void_file arch.opt
[2239]666  fi
[5091]667}
[783]668
[5091]669function build_gcm() {
670  set +e
[783]671
[5091]672  rm -f "$LIBOGCM/$arch$SUFF_NAME/.config/fcm.bld.lock"
673  ./build_gcm "$fcm_path" -j "$job" $full
674  build_status=$?
[3804]675
[5093]676  rm -rf tmp_src config
[5091]677  ln -s "$LIBOGCM/$arch$SUFF_NAME/.config" config
678  ln -s "$LIBOGCM/$arch$SUFF_NAME/.config/ppsrc" tmp_src
[5093]679  cp -r "$LIBOGCM/$arch$SUFF_NAME/.config/bin" .
[783]680
[5159]681  if [[ -r $LIBFGCM/grid/lmdz_dimensions.f90 ]]; then
682    # Cleanup: remove dimensionlmdz_dimensions.f90 file
683    rm -f "$LIBFGCM/grid/lmdz_dimensions.f90"
[5091]684  fi
[783]685
[5091]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
[3924]696
[5091]697  exit $build_status
698}
[2358]699
[5091]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.