source: branches/publications/ORCHIDEE-MICT-BIOENERGY_r7298/makeorchidee_fcm @ 7442

Last change on this file since 7442 was 3026, checked in by albert.jornet, 9 years ago

Merge: from perso [2623:3024/perso/albert.jornet/ORCHIDEE-MICT].

It includes ORCHIDEE trunk changes [2247:2749:/trunk/ORCHIDEE] and lots of fixes.

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