source: tags/ORCHIDEE_2_0/ORCHIDEE/makeorchidee_fcm @ 5110

Last change on this file since 5110 was 4595, checked in by josefine.ghattas, 7 years ago

Correction needed when linking with oasis, see ticket #362

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