source: branches/publications/ORCHIDEE_gmd_2018_MICT-LEAK/makeorchidee_fcm @ 7346

Last change on this file since 7346 was 3924, checked in by albert.jornet, 8 years ago

Merge: from trunk revisions [3643:3883/trunk/ORCHIDEE]

Done in [3887:3922/perso/albert.jornet/MICT-MERGING]

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