source: branches/publications/ORCHIDEE_GLUC_r6545/makeorchidee_fcm @ 6737

Last change on this file since 6737 was 4719, checked in by albert.jornet, 7 years ago

Merge: from revisions [4491:4695/trunk/ORCHIDEE]

Merge done in [4671:4718/perso/albert.jornet/MICT_MERGE]

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