source: trunk/LMDZ.COMMON/makelmdz_fcm @ 3801

Last change on this file since 3801 was 3796, checked in by jbclement, 3 days ago

COMMON:
Avoid redundant git diff calls in subdirectories for "version_diff.txt" when a top-level repository is detected.
JBC

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