source: branches/publications/ORCHIDEE-MICT-OP-r6850/makeorchidee_fcm @ 6889

Last change on this file since 6889 was 5890, checked in by albert.jornet, 5 years ago

Merge: from [5888/perso/albert.jornet/MICT_PFUNIT]

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