source: tags/ORCHIDEE_4_1/ORCHIDEE/makeorchidee_fcm @ 7852

Last change on this file since 7852 was 7486, checked in by josefine.ghattas, 2 years ago

Small modification not to overwrite TARGET variable. No significant changes for standard use, already done in ORCHIDEE_2_2 [7474]

File size: 18.6 KB
Line 
1#!/bin/bash
2
3#==============================================================================================================================\n
4#  MODULE       : makeorchidee_fcm
5#
6#  CONTACT      : orchidee-help _at_ listes.ipsl.fr
7#
8#  LICENCE      : IPSL (2006)
9#  This software is governed by the CeCILL licence see ORCHIDEE/ORCHIDEE_CeCILL.LIC
10#
11# SVN     :
12# $HeadURL: svn://forge.ipsl.jussieu.fr/orchidee/trunk/ORCHIDEE/makeorchidee_fcm $
13# $Date: $
14# $Revision: $
15# \n
16####################################################################################################
17#
18# This script has several possible functions :
19#   1. Compiling ORCHIDEE
20#   2. Building of the documentation
21#
22#***************************************************************************************************
23#
24# Command lines :
25#
26#   1) makeorchidee_fcm   [ -parallel  PARALLEL_TYPE ]
27#                         [ -driver ]
28#                         [ -arch XXX ]
29#                         [ -prod | -dev | -debug ]
30#
31#   2) makeorchidee_fcm   [ -clean ]
32#
33#   3) makeorchidee_fcm   [ -doc | -doc_para ] ## actually doc_para is commented
34#                         [ -rmdoc ]
35#                         [ -doc_tree ]
36#
37
38########################################################################
39#
40# 1) Set default values. Some of them can be specified using environnement variables.
41#
42
43is_driver_opt=FALSE
44is_other_opt=FALSE
45clean=FALSE
46compile_flags="%PROD_FFLAGS"
47xios=FALSE
48full=""
49ext_src=""
50export P_P=""
51export SECTIONS_PARA=""
52ORCHDIR=`/bin/pwd`
53fcm_path=$ORCHDIR/tools/FCM_V1.2/bin
54compile_doc=FALSE
55
56arch_default_path="arch"
57arch_path="arch"
58
59# Path to store files produced during compilation
60# Note: config_path was previously named .config
61rel_config_path=build
62config_path=$ORCHDIR/${rel_config_path}
63
64
65# Following variables can be set as environement variables if wanted
66if [ -n "$FCM_ARCH" ]; then
67    arch="$FCM_ARCH"
68else
69    arch=NONE
70fi
71if [ -n "$FCM_PARA" ]; then
72    parallel_mode="$FCM_PARA"
73else
74    parallel_mode=seq
75fi
76if [ -n "$FCM_JOBS" ]; then
77    job="$FCM_JOBS"
78else
79    job=1
80fi
81
82
83#########################################################################
84# 2. Read arguments
85#
86while (($# > 0)) ; do
87
88  case $1 in
89    "-h")
90        print_help=TRUE ; shift ;;
91
92    "-parallel")
93        parallel_mode=$2 ; shift ; shift ;;
94
95    "-p")
96        parallel_mode=$2 ; shift ; shift ;;
97                       
98    "-driver")
99        is_driver_opt=TRUE ; shift ;;
100
101    "-otherexec")
102        is_other_opt=TRUE
103        is_driver_opt=TRUE ; shift ;;
104
105    "-arch")
106        arch="$2" ; shift ; shift ;;
107
108    "-arch_path")
109        arch_path=$2 ; shift ; shift ;;
110
111    "-xios")
112        xios=TRUE
113        shift ;;
114
115    "-xios2")
116        xios=TRUE
117        shift ;;
118
119    "-noxios")
120        xios=FALSE
121        shift ;;
122
123    "-prod")
124        compile_flags="%PROD_FFLAGS" ; shift ;;
125
126    "-dev")
127        compile_flags="%DEV_FFLAGS" ; shift ;;
128
129    "-debug")
130        compile_flags="%DEBUG_FFLAGS" ; shift ;;
131
132     "-j")
133        job="$2" ; shift ; shift ;;
134     
135     "-full")
136        full='-full' ; shift ;;
137
138     "-clean")
139        clean=TRUE ; shift ;;
140
141     "-ext_src")
142        ext_src=$2 ; shift ; shift ;;
143
144#    "-doc_para")
145#        setenv P_P -DCPP_PARA
146#       setenv SECTIONS_PARA "-e s&ENABLED_SECTIONS\ *= &ENABLED_SECTIONS       = CPP_PARA&g"
147#       goto doc
148
149     "-doc")
150          compile_doc=TRUE ; shift ;;
151
152     "-rmdoc")
153          \rm -rf docs
154          shift ;;
155
156     "-doc_tree") 
157          cd ..
158        find ORCHIDEE \( -not -path '*.svn*' \
159                        -a \( -name '*.f90' -o -name "*.F90" -o -name "*.h" \) \) \
160                    -exec bash -c 'mkdir -p ORCHIDEE/DOC/$( dirname {} )/$( echo $( basename {} ) | sed -e "s/\..*//" )' \;
161        cd ORCHIDEE
162        shift ;;
163
164    *)
165        echo "unknown option "$1" , exiting..."
166        exit
167   esac
168done
169
170#########################################################################
171# 3. Print help documentation and exit
172#
173if [[ "$print_help" == "TRUE" ]] ; then
174  cat <<fin
175
176########################################################################
177# Usage of the script makeorchidee_fcm
178#
179# makeorchidee_fcm compiles ORCHIDEE using the Fcm software developed
180# by the Hadley Centre. Fcm is stored in tools directory.
181# Platform specific compile options are found in the arch directory.
182########################################################################
183
184./makeorchidee_fcm [Options]
185
186Main options
187[ -h ]        : show this help
188
189[ -arch XXX ] : name of the architecture file containing platform dependent compile options.
190                The files arch/arch-XXX.fcm and arch/arch-XXX.path must exist. If the
191                file arch/arch-XXX.env exist, it'll be sourced before compilation starts.
192
193[ -arch_path XXX ] : directory of the archicture file containg platform dependent compile options.
194                     Default is ./arch directory. If the files are not found in the folder given by arch_path,
195                     the default ./arch folder will be used.
196
197[ -parallel|-p PARALLEL_TYPE ] : choose parallelization mode for ORCHIDEE :
198    PARALLEL_TYPE =
199    ( mpi | MPI )              : only MPI (Message Passing Interface)
200    ( omp | OMP )              : only OpenMP
201    ( mpi_omp | MPI_OMP )      : hybrid MPI/OpenMP mode
202    ( none | NONE | seq )      : sequential mode (default)
203
204[ -driver ]      : compilation of ORCHIDEE offline standard driver
205[ -otherexec ]   : compilation of other programs: forcesoil, testrouting.
206                   Warning! All these programs are not fully validated or maintained.
207
208Options related to cleaning
209| -clean ]       : delete all files produced during previous compilation
210| -full ]        : activate full recompiling
211
212Options for XIOS, only choose one of the following
213[ -xios | -xios2 ] : linking with XIOS 2.0 (it is not longer possible to use XIOS1)
214[ -noxios ]        : compilation without XIOS (default)
215
216Options for optimization, choose only one of the following
217[ -prod ]        : compilation for production (all optimization)
218[ -dev ]         : compilation for development (low optimization and -g)
219[ -debug ]       : compilation for debugging (no optimization and all debug options)
220
221Option to optimize the compilation time
222[ -j x ]         : activate parallel compiling on x task, default 1 task
223
224Option to add extra source to compile
225[ -ext_src path] : path to an additional directory with fortran routines to compile with the model
226
227Options for compiling the Doxygen documentation
228[ -doc ]         : generate documentation with Doxygen (exit after doc computation)
229[ -doc_para ]    : generate documentation with Doxygen with parallelization calls
230[ -rmdoc ]       : remove documentation directory (before generate new documentation with Doxygen ?)
231[ -doc_tree ]    : generate tree of ORCHIDEE directories for each file
232
233
234Example 1 : compile at curie(TGCC) for MPI parallel run mode
235   ./makeorchidee_fcm -parallel mpi -arch X64_CURIE -driver
236
237Example 2 : compile at ada(IDRIS) for MPI-OpenMP parallel run mode
238   ./makeorchidee_fcm -parallel mpi_omp -arch X64_ADA -driver
239
240Example 3 : compile at obelix(LSCE)
241   ./makeorchidee_fcm -arch ifort_LSCE -driver
242
243Example 4 : compile using gfortran compiler for sequential run mode
244First make sure that the files arch/gfortran.fcm and arch/gfortran.path are suitable for
245your environement especially the path to netcdf library.
246   ./makeorchidee_fcm -parallel seq -arch gfortran -driver
247
248Example 5 : clean files created during previous compilation
249   ./makeorchidee_fcm -clean
250
251fin
252
253  exit
254fi
255#
256#
257#####################################################################################################
258# 4. Building the documentation:
259# ------------------------------
260# We assume to start in the ORCHIDEE directory
261#
262#****  Directory structure:
263#
264# ..                       : parent of the start dir.
265#   -- ORCHIDEE            : ($MODELPATH), start directory
266#       - src_sechiba
267#       - src_stomate
268#       + DOC
269#       + webdoc
270#   -- IOIPSL
271#       - src
272#   ++ modeles_doc         : ($SRCPATH), source files for the documentation, emptied at start, temporary
273#
274#****  gawk scripts called :
275#
276# codeinc.awk              : encaspulates code parts in Doxygen documentation
277# codedox.awk              : transforms almost all comments in Doxygen comments for documentation
278# codealgo.awk             : emphasizes main algorithm description of each routine in their Doxygen documentation
279#
280#****
281if [[ "$comple_doc" == "TRUE" ]] ; then
282
283    unalias cd
284
285    export REV=`svn info | grep vision | sed -e 's&.*vision.*: \([0-9]*\)&\1&' | head -n 1`
286    export TAG=`svn info | grep URL | sed -e 's&.*URL.*: svn://forge.ipsl.jussieu.fr/orchidee/\(.*\)&\1&' | head -n 1 | xargs dirname`
287    cd ..
288   
289    \rm -rf modeles_doc
290    export MODELPATH=${PWD}
291    \mkdir modeles_doc
292    export SRCPATH=${MODELPATH}/modeles_doc
293   
294    find IOIPSL/src \( -not -path '*.svn*' \
295        -a \( -name '*.f90' -o -name "*.F90" -o -name "*.h" \) \) \
296        -exec bash -c 'mkdir -p '${SRCPATH}'/$( dirname {} ); cp -p {} '${SRCPATH}'/$( dirname {} )' \;
297           
298    find ORCHIDEE \( -not -path '*.svn*' \
299        -a \( -name '*.f90' -o -name "*.F90" -o -name "*.h" \) \) \
300        -exec bash -c 'mkdir -p '${SRCPATH}'/$( dirname {} ); cp -p {} '${SRCPATH}'/$( dirname {} )' \;
301    cd ${SRCPATH}
302    # Use standard preprocessor to suppress all preproc directives
303    \find . -name "*.f90" -exec cpp -P -C -traditional -x assembler-with-cpp ${P_P} '{}' '{}'_ \;
304    \find . -name "*.f90" -print -exec mv -f '{}'_ '{}' \;
305
306    # use codeinc script to encaspulate code parts in Doxygen documentation
307    \find . -name "*.f90" -exec gawk -f ${MODELPATH}/ORCHIDEE/DOC/TOOLS/codeinc.awk '{}' \; > /dev/null
308    \find . -name "*.f90" -print -exec mv -f '{}'_preproc_codeinc '{}' \;
309    # use codedox script to transform almost all comments in Doxygen comments for documentation (use with care !)
310    \find . -name "*.f90" -exec gawk -f ${MODELPATH}/ORCHIDEE/DOC/TOOLS/codedox.awk '{}' \; > /dev/null
311    \find . -name "*.f90" -print -exec mv -f '{}'_preproc_codedox '{}' \;
312   
313    # use codealgo script to emphasize main algorithm description of each routine in their Doxygen documentation
314    \find . -name "*.f90" -exec gawk -f ${MODELPATH}/ORCHIDEE/DOC/TOOLS/codealgo.awk '{}' \; > /dev/null
315    \find . -name "*.f90" -print -exec mv -f '{}'_preproc_codealgo '{}' \;
316    cd ../ORCHIDEE
317    \rm -f ${MODELPATH}/ORCHIDEE/Doxyfile_ORCHIDEE
318    sed -e 's&MYPATH&'${MODELPATH}'&g' -e 's&SRCPATH&'${SRCPATH}'&g' \
319        -e 's&MYTAG&'${TAG}'&' -e 's&MYREV&'${REV}'&' ${SECTIONS_PARA} \
320        ${MODELPATH}/ORCHIDEE/Doxyfile_ORCHIDEE.init > ${MODELPATH}/ORCHIDEE/Doxyfile_ORCHIDEE
321    \rm -f ${MODELPATH}/ORCHIDEE/DOC/header.tex
322    sed -e "s&MYTAG&${TAG}&" -e "s&MYREV&${REV}&" \
323        ${MODELPATH}/ORCHIDEE/DOC/header.tex.init > ${MODELPATH}/ORCHIDEE/DOC/header.tex
324    ln -s /home/orchidee01/maignan/ORCHIDEE/DOC/IMAGES ${MODELPATH}/ORCHIDEE/DOC/IMAGES
325    gmake doc
326    gmake bib
327    gmake toc
328    \rm -rf ${MODELPATH}/ORCHIDEE/webdoc
329    \mv ${MODELPATH}/ORCHIDEE/docs/html ${MODELPATH}/ORCHIDEE/webdoc
330    gmake index
331    gmake toc
332    \rm -rf ${SRCPATH}
333    cp ${MODELPATH}/ORCHIDEE/docs/latex/refman.pdf ${MODELPATH}/ORCHIDEE/documentation.pdf
334    exit
335fi
336
337#####################################################################################################
338# 5. Clean directory from files produced during previous compilation
339# --------------------------------------
340if [[ "$clean" == "TRUE" ]] ; then
341    # Remove the whole directory created during previous compilation
342    rm -fr ${config_path}
343
344    # Clean ORCHIDEE modules in modipsl/lib folder
345    rm -f ../../lib/intersurf.mod
346    rm -f ../../lib/sechiba.mod
347    rm -f ../../lib/chemistry.mod
348    rm -f ../../lib/liborglob.a
349    rm -f ../../lib/libparallel.a
350    rm -f ../../lib/libsechiba.a
351    rm -f ../../lib/libstomate.a
352    rm -f ../../lib/libparameters.a
353    rm -f ../../lib/liborchidee_ol.a
354    rm -f ../../lib/liborchidee.a
355
356    echo Clean files created during previous compilation of ORCHIDEE done
357
358    exit
359fi
360
361#########################################################################
362# 6. Prepare compilation
363#
364# Add fcm in environement path
365export PATH=${fcm_path}:${PATH}
366
367# Define architecture files
368if [[ "$arch" != "NONE" ]] ; then
369  # First search for file in arch_path folder, if they are not there, search in arch_default_path
370  if [[ -e $arch_path/arch-${arch}.path ]] ; then
371    rm -f arch.path
372    ln -s $arch_path/arch-${arch}.path arch.path
373  elif [[ -e $arch_default_path/arch-${arch}.path ]] ; then
374    rm -f arch.path
375    ln -s $arch_default_path/arch-${arch}.path arch.path
376  fi
377       
378  if [[ -e $arch_path/arch-${arch}.fcm ]] ; then
379    rm -f arch.fcm
380    ln -s $arch_path/arch-${arch}.fcm arch.fcm
381  elif [[ -e $arch_default_path/arch-${arch}.fcm ]] ; then
382    rm -f arch.fcm
383    ln -s $arch_default_path/arch-${arch}.fcm arch.fcm
384  fi
385
386  if [[ -e $arch_path/arch-${arch}.env ]] ; then
387    rm -f arch.env
388    ln -s $arch_path/arch-${arch}.env arch.env
389  elif [[ -e $arch_default_path/arch-${arch}.env ]] ; then
390    rm -f arch.env
391    ln -s $arch_default_path/arch-${arch}.env arch.env
392  else
393    ln -s .void_file arch.env
394  fi
395  source arch.env
396  source arch.path
397else
398  echo "Warning : architecture not specified, taking default file <<arch.fcm>> and <<arch.path>>" 
399  if [[ ! -e arch.fcm ]] ; then
400    echo "architecture file : << arch.fcm >> is missing, exit now...."
401    exit
402  fi
403
404  if [[ -e arch.path ]] ; then
405    source arch.path
406  else
407    echo "architecture file : << arch.path >> is missing, exit now...."
408    exit
409  fi
410
411  if [[ -e arch.env ]] ; then
412    source arch.env
413  fi
414fi
415
416# set compiler flags
417FFLAGS="%BASE_FFLAGS"
418LD_FFLAGS="%BASE_LD"
419CPP_KEY="%FPP_DEF"
420
421# set compiler flags for optimisation
422FFLAGS=${FFLAGS}" "$compile_flags
423LD_FFLAGS=${LD_FFLAGS}" "$compile_flags
424
425# set compiler flags for parallelism
426echo "parallel_mode = "${parallel_mode}
427
428if [[ "$parallel_mode" == "mpi" ]] || [[ "$parallel_mode" == "MPI" ]] ; then
429    FFLAGS="${FFLAGS} %MPI_FFLAGS"
430    LD_FFLAGS="%MPI_LD ${LD_FFLAGS}"
431    CPP_KEY="CPP_PARA ${CPP_KEY}"
432elif [[ "$parallel_mode" == "omp" ]] || [[ "$parallel_mode" == "OMP" ]] ; then
433    FFLAGS="${FFLAGS} %OMP_FFLAGS"
434    LD_FFLAGS="%OMP_LD ${LD_FFLAGS}"
435    CPP_KEY="CPP_OMP CPP_PARA ${CPP_KEY}"
436elif [[ "$parallel_mode" == "mpi_omp" ]] || [[ "$parallel_mode" == "MPI_OMP" ]] ; then
437    FFLAGS="${FFLAGS} %MPI_FFLAGS %OMP_FFLAGS"
438    LD_FFLAGS="%MPI_LD %OMP_LD ${LD_FFLAGS}"
439    CPP_KEY="CPP_OMP CPP_PARA ${CPP_KEY}"
440elif [[ "$parallel_mode" == "none" ]] || [[ "$parallel_mode" == "NONE" ]] || [[ "$parallel_mode" == "seq" ]] ; then
441    echo "Compiling for sequential mode"
442else
443    echo "This option for parallel_mode is not implemeted. Choose between mpi, omp, mpi_omp and none."
444    exit
445fi
446
447#
448# Create some temporary variable to which we add as needed
449#
450INCDIR="$NETCDF_INCDIR $IOIPSL_INCDIR"
451LIBDIR="$NETCDF_LIBDIR $NETCDF_LIB $IOIPSL_LIBDIR $IOIPSL_LIB"
452
453# Do we need to link with XIOS
454#
455if [[ "$xios" == "TRUE" ]] ; then
456    CPP_KEY="XIOS ${CPP_KEY}"
457    INCDIR="${INCDIR} $XIOS_INCDIR"
458    LIBDIR="${LIBDIR} $XIOS_LIBDIR $XIOS_LIB"
459fi
460
461# Determine if also need to compile the OASIS driver. This is only the case if the
462# path for the libraries is provided and exists
463if [ -n "$OASIS_LIBDIR" ] ; then
464    is_oasisdriver_opt=TRUE
465    # Check also if the provided path also exist. If not, delete the option.
466    if [ ! -d ${OASIS_LIBDIR} ]; then
467        is_oasisdriver_opt=FALSE
468    fi
469else
470    is_oasisdriver_opt=FALSE
471fi
472
473# set target
474TARGET="liborchidee.a"
475if [[ "$is_driver_opt" == "TRUE" ]] ; then
476    TARGET="${TARGET} liborchidee_ol.a dim2_driver.exe orchideedriver.exe"
477fi
478if [[ "$is_other_opt" == "TRUE" ]] ; then
479    TARGET="${TARGET} forcesoil.exe testrouting.exe"
480fi
481
482if [[ "$is_oasisdriver_opt" == "TRUE" ]] ; then
483    CPP_KEY="OASIS ${CPP_KEY}"
484    TARGET="${TARGET} driver2oasis.exe orchideeoasis.exe"
485    INCDIR="${INCDIR} ${OASIS_INCDIR}/psmile.MPI1 ${OASIS_INCDIR}/scrip  ${OASIS_INCDIR}/mct"
486    LIBDIR="${LIBDIR} ${OASIS_LIBDIR} -lpsmile.MPI1 -lmct -lmpeu -lscrip"
487    echo "OASIS : ${INCDIR}"
488fi
489
490
491# build config file
492config_fcm="config.fcm"
493rm -f $config_fcm
494touch $config_fcm
495
496echo "%CONFIG_PATH   $config_path"                      >> $config_fcm 
497echo "%ARCH          $arch"                             >> $config_fcm 
498echo "%FFLAGS        $FFLAGS"                           >> $config_fcm 
499echo "%CPP_KEY       $CPP_KEY"                          >> $config_fcm
500echo "%EXEC          $TARGET"                           >> $config_fcm
501echo "%LD_FFLAGS     $LD_FFLAGS"                        >> $config_fcm
502echo "%INCDIR        ${INCDIR}"                         >> $config_fcm
503echo "%LIBDIR        ${LIBDIR}"                         >> $config_fcm
504echo "%EXT_SRC       $ext_src"                          >> $config_fcm
505
506
507# Delete interface module from modipsl/lib directory
508rm -f ../../lib/intersurf.mod
509rm -f ../../lib/sechiba.mod
510
511# Check if compiling is locked
512if [ -f ${config_path}/fcm.bld.lock ] ; then
513    echo "WARNING : build lock file exists"
514    echo "This means that either someone else is compiling this directory right now "
515    echo "or the previous compiling was interrupt abnormally."
516    echo ""
517    echo "Do you whant to remove this file and start compiling? [answer yes/no]" 
518    read answer
519    if [ $answer = "yes" ] || [ $answer = "y" ] ; then
520        rm -f ${config_path}/fcm.bld.lock
521    else
522        echo "Exit now!!!"
523        exit 1
524    fi
525fi
526
527#########################################################################
528# 7. Do the compiling
529fcm build -j $job $full
530err=$?
531
532# Check error message from fcm build
533if [ $err != 0 ] ; then 
534  # ERROR IN COMPILING
535  echo ERROR IN COMPILING ORCHIDEE : $err 
536  exit 1
537fi 
538
539# Create link to bin, lib and inc folders directly in ORCHIDEE folder
540# Use rel_config_path to create link with the relative path
541rm -f bin ; rm -f lib; rm -f inc
542ln -s ${rel_config_path}/bin bin
543ln -s ${rel_config_path}/lib lib
544ln -s ${rel_config_path}/inc inc
545 
546# Copy into modipsl/lib directory libraries and interface module needed by LMDZ
547cp ${config_path}/lib/lib*a          ../../lib/.
548cp ${config_path}/inc/intersurf.mod  ../../lib/.
549cp ${config_path}/inc/sechiba.mod    ../../lib/.
550
551# Move created executables to modipsl/bin directory
552if [ -f ${config_path}/bin/dim2_driver.exe ]    ; then cp -f ${config_path}/bin/dim2_driver.exe ../../bin/orchidee_ol ; fi
553if [ -f ${config_path}/bin/forcesoil.exe ]      ; then cp -f ${config_path}/bin/forcesoil.exe ../../bin/forcesoil ; fi
554if [ -f ${config_path}/bin/orchideedriver.exe ] ; then cp -f ${config_path}/bin/orchideedriver.exe ../../bin/orchideedriver ; fi
555if [ -f ${config_path}/bin/testrouting.exe ]    ; then cp -f ${config_path}/bin/testrouting.exe ../../bin/testrouting ; fi
556if [ -f ${config_path}/bin/driver2oasis.exe ]   ; then cp -f ${config_path}/bin/driver2oasis.exe ../../bin/driver2oasis ; fi
557if [ -f ${config_path}/bin/orchideeoasis.exe ]  ; then cp -f ${config_path}/bin/orchideeoasis.exe ../../bin/orchideeoasis ; fi
558
559
Note: See TracBrowser for help on using the repository browser.