source: trunk/LMDZ.COMMON/makelmdz_fcm @ 3991

Last change on this file since 3991 was 3985, checked in by jbclement, 13 days ago

PEM:
Addition of a module "phys_constants" to read and store physical parameter of the planet properly, i.e. without going through the module "comcstfi_h" and/or "comconst_mod".
JBC

File size: 30.2 KB
Line 
1#!/bin/bash
2# $Id: makelmdz_fcm 1615 2012-02-10 15:42:26Z emillour $
3# This is a script in Bash to compile the GCM and related tools
4#
5##set -x
6set -e
7########################################################################
8# options par defaut pour la commande make
9########################################################################
10
11
12dim="96x72x19"
13physique=lmd
14filtre=filtrez
15grille=reg
16couple=false
17veget=false
18sisvat=false
19rrtm=false
20dust=false
21strataer=false
22chimie=false
23chemistry=false
24parallel=none
25paramem="par"
26compil_mod=prod
27io=ioipsl
28LIBPREFIX=""
29cosp=false
30bands=""
31scatterers=""
32job=1
33full=''
34libphy=false
35clean=false
36
37arch_defined="FALSE"
38arch_path="arch"
39arch_default_path="arch"
40
41LMDGCM=`/bin/pwd`
42LIBOGCM=$LMDGCM/libo
43LIBFGCM=$LMDGCM/libf
44DYN_COMMON_PATH=$LIBFGCM/dyn3d_common
45# path for optional packages, but default set to ".void_dir"
46FILTRE_PATH=$LMDGCM/.void_dir
47DYN_PHYS_PATH=$LMDGCM/.void_dir
48DYN_PHYS_SUB_PATH=$LMDGCM/.void_dir
49PHY_COMMON_PATH=$LMDGCM/.void_dir
50RRTM_PATH=$LMDGCM/.void_dir
51DUST_PATH=$LMDGCM/.void_dir
52STRATAER_PATH=$LMDGCM/.void_dir
53SISVAT_PATH=$LMDGCM/.void_dir
54COSP_PATH=$LMDGCM/.void_dir
55CHEM_PATH=$LMDGCM/.void_dir
56CLOUD_PATH=$LMDGCM/.void_dir
57MUPHY_PATH=$LMDGCM/.void_dir
58AERONO_PATH=$LMDGCM/.void_dir
59EVOLUTION_PATH=$LMDGCM/.void_dir
60# Path to fcm utility:
61##fcm_path=$LMDGCM/tools/fcm/bin
62##fcm_path=/planeto/mturbet/planeto2-mturbet/FCM_V1.2/bin
63fcm_path=$(dirname $(which fcm))
64
65########################################################################
66#  Quelques initialisations de variables du shell.
67########################################################################
68
69CPP_KEY=""
70INCLUDE_DIR=""
71LIB=""
72adjnt=""
73COMPIL_FFLAGS="%PROD_FFLAGS"
74PARA_FFLAGS=""
75PARA_LD=""
76EXT_SRC=""
77
78########################################################################
79# lecture des options de mymake
80########################################################################
81
82# Get the compilation command
83compilation_command="$(basename $0) $@"
84
85# Parse arguments and capture options
86while (($# > 0))
87  do
88  case $1 in
89      "-h") cat <<fin
90Usage :
91makelmdz_fcm [options] -arch arch_name exec
92[-h]                       : brief help
93[-d [[IMx]JMx]LM]          : IM, JM, LM are the dimensions in x, y, z (default: $dim)
94[-s nscat]                 : (Generic) Number of radiatively active scatterers
95[-b IRxVIS]                : (Generic) Number of infrared (IR) and visible (VIS) bands for radiative transfer
96[-p PHYS]                  : set of physical parametrizations (in libf/phyPHYS), (default: lmd)
97[-prod / -dev / -debug]    : compilation mode production (default) / developement / debug .
98[-c false/MPI1/OMCT]       : (Earth) coupling with ocean model : MPI1/OMCT/false (default: false)
99[-v false/orchidee2.0/orchidee1.9/true] : (Earth) version of the vegetation model to include (default: false)
100          false       : no vegetation model
101          orchidee2.0 : compile using ORCHIDEE 2.0 (or more recent version)
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]       : (Earth) with INCA chemistry model or without (default: false)
105[-cosp true/false]         : (Earth) add the cosp model (default: false)
106[-sisvat true/false]  : (Earth) compile with/without sisvat package (default: false)
107[-rrtm true/false]    : (Earth) compile with/without rrtm package (default: false)
108[-dust true/false]    : (Earth) compile with/without the dust package by Boucher and co (default: false)
109[-strataer true/false]    : (Earth) compile with/without the strat aer package by Boucher and co (default: false)
110[-parallel none/mpi/omp/mpi_omp] : parallelism (default: none) : mpi, openmp or mixted mpi_openmp
111[-g GRI]                   : grid configuration in dyn3d/GRI_xy.h  (default: reg, inclues a zoom)
112[-io ioipsl/mix/xios]                   : Input/Output library (default: ioipsl)
113[-include INCLUDES]        : extra include path to add
114[-cpp CPP_KEY]             : additional preprocessing definitions
115[-adjnt]                   : adjoint model, not operational ...
116[-mem]                     : reduced memory dynamics (if in parallel mode)
117[-filtre NOMFILTRE]        : use filtre from libf/NOMFILTRE (default: filtrez)
118[-link LINKS]              : additional links with other libraries
119[-j n]                     : active parallel compiling on ntask
120[-full]                    : full (re-)compilation (from scratch)
121[-libphy]                  : only compile physics package (no dynamics or main program)
122[-fcm_path path]           : path to the fcm tool (default: tools/fcm/bin)
123[-ext_src path]            : path to an additional set of routines to compile with the model
124[-arch_path path]          : path to architecture files (default: $arch_default_path)
125 -arch arch                : target architecture
126 exec                      : executable to build
127fin
128      exit;;
129
130      "-d")
131      dim=$2 ; shift ; shift ;;
132
133      "-p")
134      physique="$2" ;  shift ; shift ;;
135
136      "-s")
137      scatterers=$2 ; shift ; shift ;;
138
139      "-b")
140      bands=$2 ; shift ; shift ;;
141
142      "-g")
143      grille="$2" ; shift ; shift ;;
144
145      "-c")
146      couple="$2" ; shift ; shift ;;
147
148      "-prod")
149      compil_mod="prod" ; shift ;;
150
151      "-dev")
152      compil_mod="dev" ; shift ;;
153
154      "-debug")
155      compil_mod="debug" ; shift ;;
156
157      "-io")
158      io="$2" ; shift ; shift ;;
159
160      "-v")
161      veget="$2" ; shift ; shift ;;
162
163      "-sisvat")
164      sisvat="$2" ; shift ; shift ;;
165
166      "-rrtm")
167      rrtm="$2" ; shift ; shift ;;
168
169      "-dust")
170      dust="$2" ; shift ; shift ;;
171
172      "-strataer")
173      strataer="$2" ; shift ; shift ;;
174
175      "-chimie")
176      chimie="$2" ; shift ; shift ;;
177
178      "-parallel")
179      parallel="$2" ; shift ; shift ;;
180
181      "-include")
182      INCLUDE_DIR="$INCLUDE_DIR -I$2" ; shift ; shift ;;
183
184      "-cpp")
185      CPP_KEY="$CPP_KEY $2" ; shift ; shift ;;
186
187      "-adjnt")
188      echo "not operational ... work to be done here ";exit 1
189      opt_dep="$opt_dep adjnt" ; adjnt="-ladjnt -ldyn3d "
190      optim="$optim -Dadj" ; shift ;;
191
192      "-cosp")
193          cosp="$2" ; shift ; shift ;;
194
195      "-mem")
196          paramem="mem" ; shift ;;
197
198      "-filtre")
199      filtre=$2 ; shift ; shift ;;
200
201      "-link")
202      LIB="$LIB $2" ; shift ; shift ;;
203
204      "-fcm_path")
205      fcm_path=$2 ; shift ; shift ;;
206
207      "-ext_src")
208      EXT_SRC=$2 ; shift ; shift ;;
209
210      "-j")
211      job=$2 ; shift ; shift ;;
212
213      "-full")
214      full="-full" ; shift ;;
215
216      "-libphy")
217      libphy="true" ; shift ;;
218
219      "-clean")
220      clean="true" ; shift ;;
221
222      "-arch")
223      arch=$2 ; arch_defined="TRUE" ; shift ; shift ;;
224
225      "-arch_path")
226      arch_path=$2 ; arch_path_defined="TRUE"; shift ; shift ;;
227
228      *)
229      code="$1" ; shift ;;
230  esac
231done
232
233###############################################################
234# path to fcm
235###############################################################
236# handle case when provided path to fcm was given as a relative
237# path (from makelmdz_fcm script directory) and not an absolute path
238if [[ ${fcm_path:0:1} != "/" ]] ; then
239  # prepend with makelmdz_fcm location
240  fcm_path=$(cd $(dirname $0) ; pwd)"/"${fcm_path}
241fi
242
243# add fcm_path to PATH
244export PATH=${fcm_path}:${PATH}
245
246echo "Path to fcm:"
247echo ${fcm_path}
248
249#################################
250# setup arch.env and arch.path  #
251#################################
252rm -f .void_file
253echo > .void_file
254rm -rf .void_dir
255mkdir .void_dir
256
257if [[ "$arch_defined" == "TRUE" ]]
258then
259  rm -f arch.path
260  rm -f arch.env
261
262  if test -f $arch_path/arch-${arch}.path
263  then
264    ln -s $arch_path/arch-${arch}.path arch.path
265  elif test -f $arch_default_path/arch-${arch}.path
266  then
267    ln -s $arch_default_path/arch-${arch}.path arch.path
268  fi
269
270  if test -f $arch_path/arch-${arch}.env
271  then
272    ln -s $arch_path/arch-${arch}.env arch.env
273  elif test -f $arch_default_path/arch-${arch}.env
274  then
275    ln -s $arch_default_path/arch-${arch}.env arch.env
276  else
277    ln -s .void_file arch.env
278  fi
279  # source architecture PATH and ENV files
280  source arch.env
281  source arch.path
282else
283  echo "You must define a target architecture"
284  exit 1
285fi
286
287########################################################################
288# Definition des clefs CPP, des chemins des includes et modules
289#  et des libraries
290########################################################################
291
292if [[ "$compil_mod" == "prod" ]]
293then
294  COMPIL_FFLAGS="%PROD_FFLAGS"
295elif [[ "$compil_mod" == "dev" ]]
296then
297  COMPIL_FFLAGS="%DEV_FFLAGS"
298elif [[ "$compil_mod" == "debug" ]]
299then
300  COMPIL_FFLAGS="%DEBUG_FFLAGS"
301fi
302
303phys_root=$physique
304if [[ "${physique:0:3}" == "lmd" ]] ; then phys_root=lmd ; fi
305if [[ "${physique:0:3}" == "mar" ]] ; then phys_root=mar ; fi
306if [[ "${physique:0:4}" == "mars" ]] ; then phys_root=mars ; fi
307if [[ "${physique:0:3}" == "std" ]] ; then phys_root=std ; fi
308if [[ "${physique:0:5}" == "venus" ]] ; then phys_root=venus ; fi
309if [[ "${physique:0:5}" == "titan" ]] ; then phys_root=titan ; fi
310if [[ "${physique:0:3}" == "dev" ]] ; then phys_root=dev ; fi
311
312if [[ "$physique" != "nophys" ]]
313then
314   #We'll use some physics
315   CPP_KEY="$CPP_KEY CPP_PHYS"
316   if [[ "${phys_root}" == "lmd" ]]
317   then
318   #For lmd physics, default planet type is Earth
319   CPP_KEY="$CPP_KEY CPP_EARTH"
320   fi
321   # set physics common utilities path
322   PHY_COMMON_PATH="${LIBFGCM}/phy_common"
323   # set the dyn/phys interface path
324   DYN_PHYS_PATH="${LIBFGCM}/dynphy_lonlat"
325   DYN_PHYS_SUB_PATH="${LIBFGCM}/dynphy_lonlat/phy${phys_root}"
326fi
327
328if [[ "$filtre" == "filtrez" ]]
329then
330   FILTRE_PATH=${LIBFGCM}/$filtre
331fi
332
333if [[ "$chimie" == "INCA" ]]
334then
335   CPP_KEY="$CPP_KEY INCA"
336   INCLUDE_DIR="$INCLUDE_DIR -I${INCA_INCDIR}"
337   LIB="$LIB -L${INCA_LIBDIR} ${INCA_LIB}"
338fi
339
340if [[ "$couple" != "false" ]]
341then
342    if [[ "$couple" == "MPI1" ]]
343    then
344    CPP_KEY="$CPP_KEY CPP_COUPLE"
345    export OASIS_INCDIR=$LMDGCM/../../prism/X64/build/lib/psmile.MPI1
346    export OASIS_LIBDIR=$LMDGCM/../../prism/X64/lib
347    INCLUDE_DIR="$INCLUDE_DIR -I${OASIS_INCDIR}"
348    LIB="$LIB -L${OASIS_LIBDIR} ${OASIS_LIB}"
349    else
350    CPP_KEY="$CPP_KEY CPP_COUPLE CPP_OMCT"
351    INCLUDE_DIR="$INCLUDE_DIR -I${OASIS_INCDIR}"
352    LIB="$LIB -L${OASIS_LIBDIR} ${OASIS_LIB}"
353    fi
354fi
355
356if [[ "$parallel" != "none" && \
357     ( "$code" == "newstart" || "$code" == "start2archive" ) ]]
358then
359    echo "newstart or start2archive utilities should be run in serial!"
360    echo " Compile without -parallel [mpi|omp|mpi_omp] option!"
361    exit 1
362fi
363
364if [[ "$parallel" == "mpi" ]]
365then
366   CPP_KEY="$CPP_KEY CPP_PARA CPP_MPI"
367   PARA_FFLAGS="%MPI_FFLAGS"
368   PARA_LD="%MPI_LD"
369elif [[ "$parallel" == "omp" ]]
370then
371   CPP_KEY="$CPP_KEY CPP_PARA CPP_OMP"
372   PARA_FFLAGS="%OMP_FFLAGS"
373   PARA_LD="%OMP_LD"
374elif [[ "$parallel" == "mpi_omp" ]]
375then
376   CPP_KEY="$CPP_KEY CPP_PARA CPP_MPI CPP_OMP"
377   PARA_FFLAGS="%MPI_FFLAGS %OMP_FFLAGS"
378   PARA_LD="%MPI_LD %OMP_LD"
379fi
380
381if [[ ( "$parallel" == "omp" || "$parallel" == "mpi_omp" ) \
382   && "$compil_mod" == "debug" ]]
383then
384    echo "Usually, parallelization with OpenMP requires some optimization."
385    echo "We suggest switching to \"-dev\"."
386fi
387
388if [ "$veget" = "true" -o "$veget" = "orchidee1.9" -o "$veget" = "orchidee2.0" ]
389then
390#NB: option 'true': for backward compatibility. To be used with ORCHIDEE tag 1.9-1.9.6
391#    For this case, cpp flag ORCHIDEE_NOOPENMP must be added to the makelmdz_fcm arguments
392#    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
393   INCLUDE_DIR="${INCLUDE_DIR} ${ORCHIDEE_INCDIR}"
394   CPP_KEY="$CPP_KEY CPP_VEGET"
395# temporary, for Orchidee versions 1.9.* (before openmp activation)
396   if [[ "$veget" == "orchidee1.9" ]] ; then
397      CPP_KEY="$CPP_KEY ORCHIDEE_NOOPENMP"
398   fi
399   if [[ "$veget" == "orchidee2.0" ]] ; then
400      orch_libs="sechiba parameters stomate parallel orglob orchidee"
401   else
402      orch_libs="sechiba parameters stomate parallel orglob"
403   fi
404   LIB="${LIB} -L${ORCHIDEE_LIBDIR} ${ORCHIDEE_LIB}"
405elif [[ "$veget" != "false" ]] ; then
406   echo "Option -v $veget does not exist"
407   echo "Use ./makelmdz_fcm -h for more information"
408   exit 1
409fi
410
411if [[ "$sisvat" == "true" ]]
412then
413   CPP_KEY="$CPP_KEY CPP_SISVAT"
414   SISVAT_PATH="$LIBFGCM/%PHYS/sisvat"
415fi
416
417if [[ "$rrtm" == "true" ]]
418then
419   CPP_KEY="$CPP_KEY CPP_RRTM"
420   RRTM_PATH="$LIBFGCM/%PHYS/rrtm"
421fi
422
423if [[ "$dust" == "true" ]]
424then
425   CPP_KEY="$CPP_KEY CPP_Dust"
426   DUST_PATH="$LIBFGCM/%PHYS/Dust"
427fi
428
429if [[ "$strataer" == "true" ]]
430then
431   CPP_KEY="$CPP_KEY CPP_StratAer"
432   STRATAER_PATH="$LIBFGCM/%PHYS/StratAer"
433fi
434
435if [[ $io == ioipsl ]]
436then
437   CPP_KEY="$CPP_KEY CPP_IOIPSL"
438   INCLUDE_DIR="$INCLUDE_DIR ${IOIPSL_INCDIR}"
439   LIB="$LIB ${IOIPSL_LIBDIR} ${IOIPSL_LIB}"
440elif [[ $io == mix ]]
441then
442   # For now, xios implies also using ioipsl
443   CPP_KEY="$CPP_KEY CPP_IOIPSL CPP_XIOS"
444   INCLUDE_DIR="$INCLUDE_DIR ${IOIPSL_INCDIR} ${XIOS_INCDIR}"
445   LIB="$LIB ${IOIPSL_LIBDIR} ${IOIPSL_LIB} ${XIOS_LIBDIR} ${XIOS_LIB}"
446elif [[ $io == xios ]]
447then
448   # For now, xios implies also using ioipsl
449   CPP_KEY="$CPP_KEY CPP_IOIPSL CPP_XIOS CPP_IOIPSL_NO_OUTPUT"
450   INCLUDE_DIR="$INCLUDE_DIR ${IOIPSL_INCDIR} ${XIOS_INCDIR}"
451   LIB="$LIB ${IOIPSL_LIBDIR} ${IOIPSL_LIB} ${XIOS_LIBDIR} ${XIOS_LIB}"
452fi
453
454if [[ "$cosp" == "true" ]]
455then
456   CPP_KEY="$CPP_KEY CPP_COSP"
457   COSP_PATH="$LIBFGCM/cosp"
458#   LIB="${LIB} -l${LIBPREFIX}cosp"
459fi
460
461# for Titan (but could be used by others as well), there is also "chimtitan"
462if [[ -d ${LIBFGCM}/chim${physique} ]]
463then
464   CHEM_PATH="${LIBFGCM}/chim${physique}"
465   INCLUDE_DIR="$INCLUDE_DIR -I${LIBFGCM}/chim${physique}"
466fi
467
468# for Titan add microphysics dependencies
469if [[ -d ${LIBFGCM}/muphy${physique} ]] ; then
470  if ! [ `echo $CPP_KEY | grep -c "OLD_COMPILO"` -gt 0 ] ; then
471    # add muphy{physique} to the list of files to compile.
472    MUPHY_PATH="${LIBFGCM}/muphy${physique}"
473    # For Titan as we embbed some libraries with CPP keys, we define them:
474    #   -DPREC={32|64|80} real kind precision (32: simple, 64: double, 80: extended double)
475    #   -DHAVE_NC_FTN=1 (mandatory: for support of NetCDF in lintnd).
476    CPP_KEY="$CPP_KEY PREC=64 HAVE_NC_FTN=1"
477    if [[ "${physique}" == "titan" ]] ; then
478      echo "Yaahh you're about to use YAMMS in a GCM..."
479    fi
480  fi
481fi
482
483# for Venus (but could be used by others as well), there is also "phyvenus/cloudvenus"
484if [[ -d ${LIBFGCM}/phy${physique}/cloud${physique} ]]
485then
486   CLOUD_PATH="${LIBFGCM}/phy${physique}/cloud${physique}"
487   INCLUDE_DIR="$INCLUDE_DIR -I${LIBFGCM}/phy${physique}/cloud${physique}"
488fi
489
490# for Mars (but could be used by others as well), there is also "aeronomars"
491if [[ -d ${LIBFGCM}/aerono${physique} ]]
492then
493   AERONO_PATH="${LIBFGCM}/aerono${physique}"
494   INCLUDE_DIR="$INCLUDE_DIR -I${LIBFGCM}/aerono${physique}"
495fi
496
497if [[ -d ${LIBFGCM}/evolution &&  "$code" == "pem" ]]
498then
499if [[ "$physique" == "std" ]]
500then
501   CPP_KEY="$CPP_KEY CPP_STD"
502fi
503   EVOLUTION_PATH="${LIBFGCM}/evolution"
504   INCLUDE="$INCLUDE -I${LIBFGCM}/evolution"
505fi
506
507
508# NETCDF library include/library paths
509INCLUDE_DIR="$INCLUDE_DIR ${NETCDF_INCDIR}"
510LIB="$LIB ${NETCDF_LIBDIR} ${NETCDF_LIB}"
511
512########################################################################
513# calcul du nombre de dimensions
514########################################################################
515
516
517dim_full=$dim
518dim=`echo $dim | sed -e 's/[^0-9]/ /g'`
519set $dim
520dimc=$#
521echo calcul de la dimension
522echo dim $dim
523echo dimc $dimc
524
525
526########################################################################
527# Gestion des dimensions du modele.
528# on cree ou remplace le fichier des dimensions
529########################################################################
530
531cd $LIBFGCM/grid
532if [[ -f dimensions.h ]]
533then
534  echo 'ATTENTION: vous etes sans doute en train de compiler le modele par ailleurs'
535  echo "Attendez que la premiere compilation soit terminee pour relancer la suivante."
536  echo "Si vous etes sur que vous ne compilez pas le modele par ailleurs,"
537  echo  vous pouvez continuer en repondant oui.
538  echo "Voulez-vous vraiment continuer?"
539  echo ""
540  echo "WARNING: you are probably already compiling the model somewhere else."
541  echo "Wait until the first compilation is finished before launching this one."
542  echo "If you are sure that you are not compiling elsewhere, just answer "
543  echo "yes (or 'oui') to the question below to proceed."
544  echo "Do you wish to continue?"
545  read reponse
546  if [[ $reponse == "oui" || $reponse == "yes" ]]
547  then
548    \rm -f $LIBFGCM/grid/dimensions.h
549  else
550    exit 1
551  fi
552fi
553
554
555cd $LIBFGCM/grid/dimension
556./makdim $dim
557if (($? != 0))
558then
559    exit 1
560fi
561
562cat $LIBFGCM/grid/dimensions.h
563cd $LMDGCM
564
565if [[ "$bands" != "" ]]
566then
567  # Generic model, recreate bands.h (IR & VIS bands for radiative transfer)
568  makbandsarg=$(echo $bands | sed -e 's/[^0-9]/ /g')
569  cd $LIBFGCM/phy$physique/bands
570  ./makbands $makbandsarg
571  cat $LIBFGCM/phy$physique/bands.h
572  cd $LMDGCM
573fi
574
575if [[ "$scatterers" != "" ]]
576then
577  if [[ -f $LIBFGCM/phy$physique/scatterers/make_scatterers ]]
578  then
579    # Generic model, recreate scatterers.h
580    cd $LIBFGCM/phy$physique/scatterers
581    ./make_scatterers $scatterers
582    cat $LIBFGCM/phy$physique/scatterers.h
583    cd $LMDGCM
584  else
585    echo "Error: you should not use the -s # option with -p $physique"
586    exit 1
587  fi
588fi
589
590
591########################################################################
592# Generation of a Fortran subroutine to track compilation and version
593# details through the executable file
594########################################################################
595
596# Path to the root directory where we want to check version control system
597root_dir="$LMDGCM/.."
598
599# Path and name of the generated file
600version_F90file="$LIBFGCM/misc/pgrm_version.F90"
601
602# Path and name of the file containing the compilation and version details
603default_out_file="pgrm_version_details.txt"
604
605# Get the current date
606current_date=$(date)
607
608# Function to process problematic characters
609#   - Convert input to UTF-8 and ignore invalid characters
610#   - Remove carriage return characters to prevent formatting issues
611#   - Escape backslashes and single quotes
612clean_output() {
613    iconv -f "$(locale charmap)" -t UTF-8//IGNORE \
614        | tr -d '\r' \
615        | sed 's/\\/\\\\/g; s/'\''/'\'\''/g'
616}
617
618vcs_info=""
619vcs_diff=""
620vcs_stat=""
621# Check if there is a Git repository at the root
622if command -v git > /dev/null 2>&1 && git -C "$root_dir" rev-parse --is-inside-work-tree > /dev/null 2>&1; then
623    dir_name="$(basename "$root_dir")"
624    vcs_info+="-> Git Information for \"$dir_name\"\n$(git -C "$root_dir" log -1 --pretty=format:"%H%n%an%n%ad%n%s" | clean_output)\n"
625    vcs_stat+="-> Git Status for \"$dir_name\"\n$(git -C "$root_dir" status --short | clean_output)\n"
626    vcs_diff+="-> Git Diff for \"$dir_name\"\n$(git -C "$root_dir" diff | clean_output)\n"
627else # No so we iterate through each subdirectory to determine version control system
628    for dir in "$root_dir"/*; do
629        # Skip if it is not a directory or the name contains "git" or "svn"
630        [ -d "$dir" ] || continue
631        [[ "$dir" == *git* || "$dir" == *svn* ]] && continue
632
633        # Determine the version control system for each subdirectory
634        dir_name="$(basename "$dir")"
635        if command -v svn > /dev/null 2>&1 && svn info "$dir" > /dev/null 2>&1; then # SVN
636            vcs_info+="\n-> SVN Information for \"$dir_name\"\n$(svn info "$dir" | clean_output)\n"
637            vcs_diff+="\n-> SVN Diff for \"$dir_name\"\n$(svn diff "$dir" | clean_output)\n"
638            vcs_stat+="\n-> SVN Status for \"$dir_name\"\n$(svn status "$dir" | clean_output)\n"
639        elif command -v git > /dev/null 2>&1 && git -C "$dir" rev-parse --is-inside-work-tree > /dev/null 2>&1; then # Git
640            vcs_info+="-> Git Information for \"$dir_name\"\n$(git -C "$dir" log -1 --pretty=format:"%H%n%an%n%ad%n%s" | clean_output)\n"
641            vcs_diff+="\n-> Git Diff for \"$dir_name\"\n$(git -C "$dir" diff | clean_output)\n"
642            vcs_stat+="\n-> Git Status for \"$dir_name\"\n$(git -C "$dir" status --short | clean_output)\n"
643        else # None
644            vcs_info+="\n-> No version control system for \"$dir_name\"\n"
645        fi
646    done
647fi
648
649# Generate the Fortran subroutine
650cat << EOF > "$version_F90file"
651MODULE pgrm_version_mod
652
653!***********************************************************************
654! File generated automatically at compilation
655!
656! DESCRIPTION:
657!    The subroutine 'print_pgrm_version' prints compilation details, the version
658!    control information (SVN or Git), the status and the diff result if applicable.
659!
660! PARAMETERS:
661!    None.
662!
663! USAGE:
664!    Use the command-line option "--version [file]" when running your program:
665!       ./myprogram --version [file]
666!    This will write compilation and version details into the specified [file].
667!    If [file] is omitted, the default name "pgrm_version_details.txt" will be used.
668!    This feature helps track code builds and their exact compilation context
669!    directly from the executable.
670!***********************************************************************
671
672implicit none
673
674character(*), parameter :: default_out_file = "${default_out_file}"
675
676!=======================================================================
677contains
678!=======================================================================
679
680SUBROUTINE print_pgrm_version(user_out_file)
681
682!---- Arguments
683character(*), optional, intent(in) :: user_out_file
684
685!---- Variables
686integer, parameter        :: io_unit = 10
687character(:), allocatable :: out_file
688
689!---- Code
690if (present(user_out_file)) then
691    out_file = trim(adjustl(user_out_file))
692else
693    out_file = trim(adjustl(default_out_file))
694endif
695
696open(io_unit,file = out_file,status = 'replace',action = 'write')
697
698write(*,*)
699write(*,'(a)') '-> Writing compilation details to the file "'//out_file//'".'
700write(io_unit,'(a)') '========================= COMPILATION DETAILS =========================='
701write(io_unit,'(a)') '-> Date   : ${current_date}'
702write(io_unit,'(a)') '-> Command: ${compilation_command}'
703write(io_unit,*)
704EOF
705
706if [ -n "$vcs_info" ]; then
707    echo "write(*,'(a)') '-> Writing information result to the file \"'//out_file//'\".'" >> "$version_F90file"
708    echo "write(io_unit,'(a)') '===================== VERSION CONTROL INFORMATION ======================'" >> "$version_F90file"
709    while IFS= read -r line; do
710        echo "write(io_unit,'(a)') '${line}'" >> "$version_F90file"
711    done <<< "$(echo -e "$vcs_info")"
712else
713    echo "write(io_unit,'(a)') '====================== NO VERSION CONTROL SYSTEM ======================='" >> "$version_F90file"
714fi
715
716if [ -n "$vcs_stat" ]; then
717    echo "write(*,'(a)') '-> Writing status result to the file \"'//out_file//'\".'" >> "$version_F90file"
718    echo "write(io_unit,*)" >> "$version_F90file"
719    echo "write(io_unit,'(a)') '======================== VERSION CONTROL STATUS ========================'" >> "$version_F90file"
720    while IFS= read -r line; do
721        echo "write(io_unit,'(a)') '${line}'" >> "$version_F90file"
722    done <<< "$(echo -e "$vcs_stat")"
723fi
724
725if [ -n "$vcs_diff" ]; then
726    echo "write(*,'(a)') '-> Writing diff result to the file \"'//out_file//'\".'" >> "$version_F90file"
727    echo "write(io_unit,*)" >> "$version_F90file"
728    echo "write(io_unit,'(a)') '========================= VERSION CONTROL DIFF ========================='" >> "$version_F90file"
729    while IFS= read -r line; do
730        echo "write(io_unit,'(a)') '${line}'" >> "$version_F90file"
731    done <<< "$(echo -e "$vcs_diff")"
732fi
733
734cat << EOF >> "$version_F90file"
735write(io_unit,'(a)') '========================================================================'
736write(*,*)
737
738close(io_unit)
739
740END SUBROUTINE print_pgrm_version
741
742END MODULE pgrm_version_mod
743EOF
744
745# Termination message
746echo "'$version_F90file' has been generated successfully."
747
748
749########################################################################
750# Differentes dynamiques (3d, 2d, 1d)
751########################################################################
752
753dimension=`echo $dim | wc -w`
754echo dimension $dimension
755
756if (( $dimension == 3 ))
757then
758  cd $LIBFGCM/grid
759  \rm fxyprim.h
760  cp -p fxy_${grille}.h fxyprim.h
761#else
762#  echo "Probleme dans les dimensions de la dynamique !!"
763#  echo "Non reactive pour l'instant !!!"
764fi
765
766if (( $dimension == 1 ))
767then
768## Sanity check: 1D models should be used in serial
769## unless compiled with xios and then it should be in mpi only
770  if [[ $io == xios ]]
771  then
772   echo "OK io xios"
773   if [[ $parallel != "mpi" ]]
774   then
775    echo "Error: a 1D model compiled with xios should also be compiled with "
776    echo "       -parallel mpi option!"
777    exit 1
778   fi
779  else
780  # no xios, check that it is in serial only
781   if [[ $parallel != "none" ]]
782   then
783    echo "Error: a 1D model should not be compiled with "
784    echo "       -parallel [mpi|omp|mpi_omp] option!"
785    exit 1
786   fi
787  fi # of if [[ $io == "xios" ]]
788  CPP_KEY="$CPP_KEY CPP_1D"
789##in 1D, add dyn3d to include path (because main prog is in physics)
790  INCLUDE_DIR="$INCLUDE_DIR -Ilibf/dyn3d -Ilibf/dyn3d_common"
791## no filtre in 1d:
792  FILTRE_PATH=$LMDGCM/.void_dir
793## no need to compile all routines in dyn3d_common either:
794  DYN_COMMON_PATH=$LMDGCM/.void_dir
795## no need to compile all routines in dynlmdz_phy... ;
796## (because key ones are included in 1D main program)
797  DYN_PHYS_PATH=$LMDGCM/.void_dir
798  DYN_PHYS_SUB_PATH=$LMDGCM/.void_dir
799fi
800
801######################################################################
802#   Traitement special pour le nouveau rayonnement de Laurent Li.
803#   ---> YM desactive pour le traitemement en parallele
804######################################################################
805
806#if [[ -f $libf/phy$physique/raddim.h ]]
807#then
808# if [[ -f $libf/phy$physique/raddim.$dimh.h ]]
809#then
810#  \rm -f $libf/phy$physique/raddim.h
811#  cp -p $libf/phy$physique/raddim.$dimh.h $libf/phy$physique/raddim.h
812#  echo $libf/phy$physique/raddim.$dimh.h
813#  cat $libf/phy$physique/raddim.h
814# else
815#  echo On peut diminuer la taille de l executable en creant
816#  echo le fichier $libf/phy$physique/raddim.$dimh.h
817#  \cp -p $libf/phy$physique/raddim.defaut.h $libf/phy$physique/raddim.h
818# fi
819#fi
820
821######################################################################
822# Gestion du filtre qui n'existe qu'en 3d.
823######################################################################
824
825if (( `expr $dimc \> 2` == 1 ))
826then
827   filtre="FILTRE=$filtre"
828else
829   filtre="FILTRE= L_FILTRE= "
830fi
831echo MACRO FILTRE $filtre
832
833echo $dimc
834
835
836
837######################################################################
838# Creation du suffixe de la configuration
839######################################################################
840
841if [[ $libphy != "true" ]];then
842  SUFF_NAME=_${dim_full}
843fi
844SUFF_NAME=${SUFF_NAME}_phy${physique}
845
846if [[ "$bands" != "" ]]
847then
848  #if bands option -b VISxIR is used, add "_bVISxIR" to executable name
849  SUFF_NAME=${SUFF_NAME}_b$bands
850fi
851
852if [[ "$parallel" != "none" ]]
853then
854  SUFF_NAME=${SUFF_NAME}_para
855  if (( $dimension == 1 ))
856  then
857    # dynamics-related routines in"dyn1d" subdirectory of phy${physique}
858    DYN=phy${physique}/dyn1d
859  else
860    DYN=dyn${dimc}d${paramem}
861  fi
862  if [[ "$paramem" == "mem" ]]
863  then
864   SUFF_NAME=${SUFF_NAME}_${paramem}
865  fi
866else
867  SUFF_NAME=${SUFF_NAME}_seq
868  if (( $dimension == 1 ))
869  then
870    # dynamics-related routines in"dyn1d" subdirectory of phy${physique}
871    DYN=phy${physique}/dyn1d
872  else
873    DYN=dyn${dimc}d
874  fi
875fi
876
877if [[ $veget != "false" ]]
878then
879  SUFF_NAME=${SUFF_NAME}_orch
880fi
881
882if [[ $couple != "false" ]]
883then
884  SUFF_NAME=${SUFF_NAME}_couple
885fi
886
887if [[ $chimie == "INCA" ]]
888then
889  SUFF_NAME=${SUFF_NAME}_inca
890fi
891SUFF_DEBUG=
892if [[ "$compil_mod" == "debug" ]]
893then
894  SUFF_DEBUG=_debug
895fi
896SUFF_DIR=${SUFF_NAME}${SUFF_DEBUG}
897
898if [[ $libphy == "true" ]]
899then
900  # special case where we compile only the physics
901  DYN=$LMDGCM/.void_dir
902  DYN_COMMON_PATH=$LMDGCM/.void_dir
903  FILTRE_PATH=$LMDGCM/.void_dir
904  DYN_PHYS_PATH=$LMDGCM/.void_dir
905  DYN_PHYS_SUB_PATH=$LMDGCM/.void_dir
906  #and there is no main program to generate
907  code=""
908  SUFF_NAME=""
909  # SUFF_DIR=
910else
911  SUFF_NAME=${SUFF_NAME}.e
912fi
913
914cd $LMDGCM
915config_fcm="config.fcm"
916rm -f $config_fcm
917touch $config_fcm
918
919echo "%ARCH          $arch"          >> $config_fcm
920echo "%INCDIR        $INCLUDE_DIR"       >> $config_fcm
921echo "%LIB           $LIB"           >> $config_fcm
922echo "%ROOT_PATH     $PWD"           >> $config_fcm
923echo "%LIBF          $LIBFGCM"       >> $config_fcm
924echo "%LIBO          $LIBOGCM"       >> $config_fcm
925echo "%DYN           $DYN"           >> $config_fcm
926echo "%DYN_COMMON    $DYN_COMMON_PATH" >> $config_fcm
927echo "%PHY_COMMON    $PHY_COMMON_PATH" >> $config_fcm
928echo "%FILTRE        $FILTRE_PATH"   >> $config_fcm
929echo "%PHYS          phy${physique}" >> $config_fcm
930echo "%DYN_PHYS      $DYN_PHYS_PATH" >> $config_fcm
931echo "%DYN_PHYS_SUB  $DYN_PHYS_SUB_PATH" >> $config_fcm
932echo "%RRTM          $RRTM_PATH"     >> $config_fcm
933echo "%DUST          $DUST_PATH"     >> $config_fcm
934echo "%STRATAER      $STRATAER_PATH" >> $config_fcm
935echo "%SISVAT        $SISVAT_PATH"   >> $config_fcm
936echo "%COSP          $COSP_PATH"     >> $config_fcm
937echo "%CHEM          $CHEM_PATH"     >> $config_fcm
938echo "%CLOUD         $CLOUD_PATH"    >> $config_fcm
939echo "%MUPHY         $MUPHY_PATH"    >> $config_fcm
940echo "%AERONO        $AERONO_PATH"   >> $config_fcm
941echo "%EVOLUTION     $EVOLUTION_PATH"  >> $config_fcm
942echo "%CPP_KEY       $CPP_KEY"       >> $config_fcm
943echo "%EXEC          $code"          >> $config_fcm
944echo "%SUFF_NAME     $SUFF_NAME"     >> $config_fcm
945echo "%SUFF_DIR      $SUFF_DIR"      >> $config_fcm
946echo "%COMPIL_FFLAGS $COMPIL_FFLAGS" >> $config_fcm
947echo "%PARA_FFLAGS   $PARA_FFLAGS"   >> $config_fcm
948echo "%PARA_LD       $PARA_LD"       >> $config_fcm
949echo "%EXT_SRC       $EXT_SRC"       >> $config_fcm
950
951# setup arch.fcm and arch.opt
952rm -f arch.fcm
953rm -f arch.opt
954ln -s arch/arch-${arch}.fcm arch.fcm
955if test -f arch/arch-${arch}.opt &&  [ $compil_mod = "prod" ]
956  then
957  ln -s arch/arch-${arch}.opt arch.opt
958else
959  ln -s .void_file arch.opt
960fi
961
962# cleanup before compiling
963if [[ $libphy != "true" ]]; then
964  rm -f bin/${code}${SUFF_NAME}
965fi
966rm -f $LIBOGCM/${arch}${SUFF_DIR}/.config/fcm.bld.lock
967
968function delete_dim_h {
969  if [[ -r $LIBFGCM/grid/dimensions.h ]];then
970    echo "Removing dimensions.h"
971    \rm -f $LIBFGCM/grid/dimensions.h
972  fi
973}
974
975if [[ $clean == "true" ]];then
976    echo "-- Cleaning up folder $LIBOGCM/${arch}${SUFF_DIR} --"
977    delete_dim_h
978    rm -rf tmp_src
979    rm -rf config
980    rm -rf $LIBOGCM/${arch}${SUFF_DIR}
981    exit 0
982fi
983
984./build_gcm ${fcm_path} -j $job $full || (echo "Build gcm failed."; delete_dim_h; exit 1)
985
986rm -rf tmp_src
987rm -rf config
988ln -s $LIBOGCM/${arch}${SUFF_DIR}/.config config
989ln -s $LIBOGCM/${arch}${SUFF_DIR}/.config/ppsrc tmp_src
990
991delete_dim_h
Note: See TracBrowser for help on using the repository browser.