source: branches/publications/ORCHIDEE-GMv3.2/ORCHIDEE/ORCHIDEE/makeorchidee_fcm @ 6938

Last change on this file since 6938 was 3595, checked in by josefine.ghattas, 8 years ago

Added error handling.

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