source: branches/publications/ORCHIDEE_gmd-2018-57/makeorchidee_fcm @ 6145

Last change on this file since 6145 was 4260, checked in by jan.polcher, 7 years ago

Corrections to the model to allow common usage of OASIS and XIOS. A number of bugs have been corrected which also affect the Trunk. This will be documents in corresponding tickets.

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