source: branches/publications/ORCHIDEE_CAN_r3069/makeorchidee_fcm @ 7193

Last change on this file since 7193 was 2571, checked in by sebastiaan.luyssaert, 9 years ago

DEV: trunk changes up to and including r2203

File size: 13.7 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
38parallel_mode=seq
39is_driver_opt=FALSE
40is_arch_opt=FALSE
41clean=FALSE
42compile_flags="%PROD_FFLAGS"
43xios=FALSE
44full=""
45job=1
46ext_src=""
47
48export P_P=""
49export SECTIONS_PARA=""
50
51ORCHDIR=`/bin/pwd`
52fcm_path=$ORCHDIR/tools/FCM_V1.2/bin
53
54while (($# > 0)); do
55  case $1 in
56      "-h") cat <<fin
57
58########################################################################
59# Usage of the script makeorchidee_fcm
60#
61# makeorchidee_fcm compiles ORCHIDEE using the Fcm a software developed
62# by the Hadley Centre. Fcm is stored in tools directory. 
63# Platform specific compile options are found in the arch directory.
64########################################################################
65 
66./makeorchidee_fcm [Options] 
67         
68Main options
69[ -h ]        : show this help
70         
71[ -arch XXX ] : name of the archicture file containg platform dependent compile options. 
72                The files arch/arch-XXX.fcm and arch/arch-XXX.path must exist. 
73         
74[ -parallel|-p PARALLEL_TYPE ] : choose parallelization mode for ORCHIDEE :
75 
76    PARALLEL_TYPE =
77
78    ( mpi | MPI )              : only MPI (Message Passing Interface)
79    ( omp | OMP )              : only OpenMP
80    ( mpi_omp | MPI_OMP )      : hybrid MPI/OpenMP mode
81    ( none | NONE | seq )      : sequential mode (default)
82 
83 [ -driver ]      : compilation of ORCHIDEE offline driver (default compiling only the library)
84         
85 Options related to cleaning
86 | -clean ]       : delete all files produceed during previous compilation
87 | -full ]        : activate full recompiling 
88         
89 Options for XIOS, only choose one of the following
90 [ -xios ]        : linking with XIOS
91 [ -noxios ]      : compilation without XIOS (default)
92 
93 Options for optimization, choose only one of the following
94 [ -prod ]        : compilation for production (all optimization)
95 [ -dev ]         : compilation for development (low optimization and -g)
96 [ -debug ]       : compilation for debugging (no optmization and all debug options)
97         
98 Option to optimize the compilation time
99 [ -j x ]         : activate parallel compiling on x task, default 1 task
100 
101 Option to add extra source to compile
102 [ -ext_src path] : path to an additional directory with fortran routines to compile with the model
103         
104 Options for compiling the documentation :
105 [ -doc ]         : generate documentation with Doxygen (exit after doc computation)
106 [ -doc_para ]    : generate documentation with Doxygen with parallelization calls
107 [ -rmdoc ]       : remove documentation directory (before generate new documentation with Doxygen ?)
108 [ -doc_tree ]    : generate tree of ORCHIDEE directories for each file
109         
110         
111 Example 1 : compile at curie(TGCC) for MPI parallel run mode
112    ./makeorchidee_fcm -parallel mpi -arch X64_CURIE -driver
113         
114 Example 2 : compile at ada(IDRIS) for MPI-OpenMP parallel run mode
115    ./makeorchidee_fcm -parallel mpi_omp -arch X64_ADA -driver
116         
117 Example 3 : compile at obelix(LSCE)
118    ./makeorchidee_fcm -arch ifort_LSCE -driver
119         
120 Example 4 : compile using gfortran compiler for sequential run mode 
121 First make sure that the files arch/gfortran.fcm and arch/gfortran.path are suitable for 
122 your environement especially the path to netcdf library. 
123   ./makeorchidee_fcm -parallel seq -arch gfortran -driver
124         
125 Example 5 : clean files created during previous compilation
126    ./makeorchidee_fcm -clean
127
128fin
129    exit;;
130
131########################################################################
132# Read argument
133########################################################################
134
135    "-parallel")
136        parallel_mode=$2 ; shift ; shift ;;
137                       
138    "-driver")
139         is_driver_opt=TRUE
140        shift ;;
141
142    "-arch")
143        is_arch_opt=TRUE
144        arch="$2" ; shift ; shift ;;
145
146    "-xios")
147         xios=TRUE
148        shift ;;
149
150    "-noxios")
151         xios=FALSE
152        shift ;;
153
154    "-prod")
155        compile_flags="%PROD_FFLAGS"
156        shift ;;
157
158    "-dev")
159        compile_flags="%DEV_FFLAGS"
160        shift ;;
161
162    "-debug")
163        compile_flags="%DEBUG_FFLAGS"
164        shift ;;
165
166     "-j")
167        job="$2" ; shift ; shift ;;
168
169     "-full")
170        full='-full'
171        shift ;;
172
173     "-clean")
174        clean=TRUE
175        shift ;;
176
177      "-ext_src")
178        ext_src=$2 ; shift ; shift ;;
179
180#    "-doc_para")
181#        setenv P_P -DCPP_PARA
182#       setenv SECTIONS_PARA "-e s&ENABLED_SECTIONS\ *= &ENABLED_SECTIONS       = CPP_PARA&g"
183#       goto doc
184
185        "-doc")
186#####################################################################################################
187
188# 2) Building the documentation:
189# ------------------------------
190# We assume to start in the ORCHIDEE directory
191#
192#****  Directory structure:
193#
194# ..                       : parent of the start dir.
195#   -- ORCHIDEE            : ($MODELPATH), start directory
196#       - src_sechiba
197#       - src_stomate
198#       + DOC
199#       + webdoc
200#   -- IOIPSL
201#       - src
202#   ++ modeles_doc         : ($SRCPATH), source files for the documentation, emptied at start, temporary
203#
204#****  gawk scripts called :
205#
206# codeinc.awk              : encaspulates code parts in Doxygen documentation
207# codedox.awk              : transforms almost all comments in Doxygen comments for documentation
208# codealgo.awk             : emphasizes main algorithm description of each routine in their Doxygen documentation
209#
210#****
211        unalias cd
212
213        export REV=`svn info | grep vision | sed -e 's&.*vision.*: \([0-9]*\)&\1&' | head -n 1`
214        export TAG=`svn info | grep URL | sed -e 's&.*URL.*: svn://forge.ipsl.jussieu.fr/orchidee/\(.*\)&\1&' | head -n 1 | xargs dirname`
215        cd ..
216
217        \rm -rf modeles_doc
218        export MODELPATH=${PWD}
219        \mkdir modeles_doc
220        export SRCPATH=${MODELPATH}/modeles_doc
221
222        find IOIPSL/src \( -not -path '*.svn*' \
223                        -a \( -name '*.f90' -o -name "*.F90" -o -name "*.h" \) \) \
224                    -exec bash -c 'mkdir -p '${SRCPATH}'/$( dirname {} ); cp -p {} '${SRCPATH}'/$( dirname {} )' \;
225
226        find ORCHIDEE \( -not -path '*.svn*' \
227                        -a \( -name '*.f90' -o -name "*.F90" -o -name "*.h" \) \) \
228                    -exec bash -c 'mkdir -p '${SRCPATH}'/$( dirname {} ); cp -p {} '${SRCPATH}'/$( dirname {} )' \;
229        cd ${SRCPATH}
230        # Use standard preprocessor to suppress all preproc directives
231        \find . -name "*.f90" -exec cpp -P -C -traditional -x assembler-with-cpp ${P_P} '{}' '{}'_ \;
232        \find . -name "*.f90" -print -exec mv -f '{}'_ '{}' \;
233
234        # use codeinc script to encaspulate code parts in Doxygen documentation
235        \find . -name "*.f90" -exec gawk -f ${MODELPATH}/ORCHIDEE/DOC/TOOLS/codeinc.awk '{}' \; > /dev/null
236        \find . -name "*.f90" -print -exec mv -f '{}'_preproc_codeinc '{}' \;
237        # use codedox script to transform almost all comments in Doxygen comments for documentation (use with care !)
238        \find . -name "*.f90" -exec gawk -f ${MODELPATH}/ORCHIDEE/DOC/TOOLS/codedox.awk '{}' \; > /dev/null
239        \find . -name "*.f90" -print -exec mv -f '{}'_preproc_codedox '{}' \;
240
241        # use codealgo script to emphasize main algorithm description of each routine in their Doxygen documentation
242        \find . -name "*.f90" -exec gawk -f ${MODELPATH}/ORCHIDEE/DOC/TOOLS/codealgo.awk '{}' \; > /dev/null
243        \find . -name "*.f90" -print -exec mv -f '{}'_preproc_codealgo '{}' \;
244        cd ../ORCHIDEE
245        \rm -f ${MODELPATH}/ORCHIDEE/Doxyfile_ORCHIDEE
246        sed -e 's&MYPATH&'${MODELPATH}'&g' -e 's&SRCPATH&'${SRCPATH}'&g' \
247            -e 's&MYTAG&'${TAG}'&' -e 's&MYREV&'${REV}'&' ${SECTIONS_PARA} \
248            ${MODELPATH}/ORCHIDEE/Doxyfile_ORCHIDEE.init > ${MODELPATH}/ORCHIDEE/Doxyfile_ORCHIDEE
249        \rm -f ${MODELPATH}/ORCHIDEE/DOC/header.tex
250        sed -e "s&MYTAG&${TAG}&" -e "s&MYREV&${REV}&" \
251            ${MODELPATH}/ORCHIDEE/DOC/header.tex.init > ${MODELPATH}/ORCHIDEE/DOC/header.tex
252        ln -s /home/orchidee01/maignan/ORCHIDEE/DOC/IMAGES ${MODELPATH}/ORCHIDEE/DOC/IMAGES
253        gmake doc
254        gmake bib
255        gmake toc
256        \rm -rf ${MODELPATH}/ORCHIDEE/webdoc
257        \mv ${MODELPATH}/ORCHIDEE/docs/html ${MODELPATH}/ORCHIDEE/webdoc
258        gmake index
259        gmake toc
260        \rm -rf ${SRCPATH}
261        cp ${MODELPATH}/ORCHIDEE/docs/latex/refman.pdf ${MODELPATH}/ORCHIDEE/documentation.pdf
262        exit
263        shift ;;
264
265
266     "-rmdoc")
267        \rm -rf docs
268        shift ;;
269
270     "-doc_tree") 
271        cd ..
272        find ORCHIDEE \( -not -path '*.svn*' \
273                        -a \( -name '*.f90' -o -name "*.F90" -o -name "*.h" \) \) \
274                    -exec bash -c 'mkdir -p ORCHIDEE/DOC/$( dirname {} )/$( echo $( basename {} ) | sed -e "s/\..*//" )' \;
275        cd ORCHIDEE
276        shift ;;
277
278    *)
279        echo "unknown option "$1" , exiting..."
280        exit
281   esac
282done
283
284#####################################################################################################
285# 0) Clean directory from files produced during previous compilation
286# --------------------------------------
287if [[ "$clean" == "TRUE" ]] ; then
288    rm -fr .config
289    rm -fr lib
290    rm -fr bin
291    rm -fr tmp_src
292    rm -f ../../lib/intersurf.mod
293    rm -f ../../lib/liborglob.a
294    rm -f ../../lib/libparallel.a
295    rm -f ../../lib/libsechiba.a
296    rm -f ../../lib/libstomate.a
297    rm -f ../../lib/libparameters.a
298    rm -f ../../lib/liborchidee_ol.a
299    rm -f ../../lib/liborchidee.a
300
301    exit
302fi
303
304# 1) Compilation du code direct avec fcm
305# --------------------------------------
306# Add fcm in environement path
307export PATH=${fcm_path}:${PATH}
308
309#define architecture files
310if [[ "$is_arch_opt" == "TRUE" ]]; then
311  if [[ -e arch/arch-${arch}.fcm ]]; then
312    rm -f arch.fcm
313    ln -s arch/arch-${arch}.fcm arch.fcm
314  else
315    echo "architecture file : << arch/arch-${arch}.fcm >> is missing, exiting...."
316    exit
317  fi
318 
319  if [[ -e arch/arch-${arch}.path ]]; then
320    rm -f arch.path
321    ln -s arch/arch-${arch}.path arch.path
322  else
323    echo "architecture file : << arch/arch-${arch}.path >> is missing, exiting...."
324    exit
325  fi
326else
327  echo "Warning : architecture not specified, taking default file <<arch.fcm>> and <<arch.path>>" 
328  if [[ ! -e arch.fcm ]]; then
329    echo "architecture file : << arch.fcm >> is missing, exiting...."
330    exit
331  fi
332
333  if [[ ! -e arch.fcm ]]
334 then
335    echo "architecture file : << arch.path >> is missing, exiting...."
336    exit
337  fi
338fi
339 
340# set compiler flags
341FFLAGS="%BASE_FFLAGS"
342LD_FFLAGS="%BASE_LD"
343CPP_KEY="%FPP_DEF"
344
345# set compiler flags for optimisation
346FFLAGS=${FFLAGS}" "$compile_flags
347LD_FFLAGS=${LD_FFLAGS}" "$compile_flags
348
349# set compiler flags for parallelism
350echo "parallel_mode = "${parallel_mode}
351
352if [[ "$parallel_mode" == "mpi" ]] || [[ "$parallel_mode" == "MPI" ]]; then
353    FFLAGS="${FFLAGS} %MPI_FFLAGS"
354    LD_FFLAGS="%MPI_LD ${LD_FFLAGS}"
355    CPP_KEY="CPP_PARA ${CPP_KEY}"
356elif [[ "$parallel_mode" == "omp" ]] || [[ "$parallel_mode" == "OMP" ]]; then
357    FFLAGS="${FFLAGS} %OMP_FFLAGS"
358    LD_FFLAGS="%OMP_LD ${LD_FFLAGS}"
359    CPP_KEY="CPP_OMP CPP_PARA ${CPP_KEY}"
360elif [[ "$parallel_mode" == "mpi_omp" ]] || [[ "$parallel_mode" == "MPI_OMP" ]]; then
361    FFLAGS="${FFLAGS} %MPI_FFLAGS %OMP_FFLAGS"
362    LD_FFLAGS="%MPI_LD %OMP_LD ${LD_FFLAGS}"
363    CPP_KEY="CPP_OMP CPP_PARA ${CPP_KEY}"
364elif [[ "$parallel_mode" == "none" ]] || [[ "$parallel_mode" == "NONE" ]] || [[ "$parallel_mode" == "seq" ]]; then
365    echo "Compiling for sequential mode"
366else
367    echo "This option for parallel_mode is not implemeted. Choose between mpi, omp, mpi_omp and none."
368    exit
369fi
370
371
372if [[ "$xios" == "TRUE" ]]; then
373    CPP_KEY="XIOS ${CPP_KEY}"
374fi
375
376# set target
377TARGET=liborchidee.a
378if [[ "$is_driver_opt" == "TRUE" ]]; then
379    TARGET="liborchidee_ol.a dim2_driver.exe teststomate.exe forcesoil.exe"
380fi
381
382source ./arch.path
383
384# build config file
385config_fcm="config.fcm"
386rm -f $config_fcm
387touch $config_fcm
388
389echo "%ARCH          $arch"                             >> $config_fcm 
390echo "%FFLAGS        $FFLAGS"                           >> $config_fcm 
391echo "%CPP_KEY       $CPP_KEY"                          >> $config_fcm
392echo "%EXEC          $TARGET"                           >> $config_fcm
393echo "%LD_FFLAGS     $LD_FFLAGS"                        >> $config_fcm
394if [[ "$xios" == "TRUE" ]]
395  then
396   echo "%INCDIR        -I$NETCDF_INCDIR -I$IOIPSL_INCDIR -I$XIOS_INCDIR" >> $config_fcm
397   echo "%LIBDIR        -L$NETCDF_LIBDIR -L$IOIPSL_LIBDIR -L$XIOS_LIBDIR" >> $config_fcm
398else
399   echo "%INCDIR        -I$NETCDF_INCDIR -I$IOIPSL_INCDIR" >> $config_fcm
400   echo "%LIBDIR        -L$NETCDF_LIBDIR -L$IOIPSL_LIBDIR" >> $config_fcm
401fi
402echo "%EXT_SRC       $ext_src"                          >> $config_fcm
403
404
405# Delete interface module from modipsl/lib directory
406rm -f ../../lib/intersurf.mod
407
408# Do the compiling
409fcm build -j $job $full
410
411# Copy into modipsl/lib directory libraries and interface module needed by LMDZ
412cp lib/lib*a ../../lib/.
413cp lib/intersurf.mod ../../lib/.
414
415# Copy executables to modipsl/bin directory
416if [[ "$is_driver_opt" == "TRUE" ]]; then
417    cp bin/dim2_driver.exe ../../bin/orchidee_ol
418    cp bin/teststomate.exe ../../bin/teststomate
419    cp bin/forcesoil.exe ../../bin/forcesoil
420fi
421
422
Note: See TracBrowser for help on using the repository browser.