source: branches/publications/ORCHILEAK-Gommet/makeorchidee_fcm @ 7346

Last change on this file since 7346 was 3225, checked in by acosce, 8 years ago

We add a routine to create the interface between Orchidee and INCA
Emission fluxes for BVOCs and NOx, vegetation fraction, leaf area index are now read by INCA at each model time step
(Juliette Lathiere - Anne Cozic - Josefine Ghattas)

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