source: branches/publications/ORCHIDEE_CAN_r2290/makeorchidee_fcm

Last change on this file was 1902, checked in by matthew.mcgrath, 11 years ago

DEV: Trunk merges up to and including r1892

File size: 12.7 KB
Line 
1#!/bin/bash
2
3#==============================================================================================================================\n
4#  MODULE       :
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# Author: Martial.Mancip
12# Contact: josefine.ghattas_at_ipsl.jussieu.fr
13# $Revision::                                   $ Revision of last commit
14# $Author::                                     $ Author of last commit
15# $Date::
16#
17# Modification:
18#   26/04/13, P. Maugis : comments and notice
19#   18/07/13, A. Cozic  : translate in bash to fit with idris and tgcc
20#   01/10/13, J. Ghattas : add options full, job and ext_src
21#
22####################################################################################################
23
24####################################################################################################
25#
26# This script has several possible functions :
27#   1. Compiling ORCHIDEE
28#   2. Building of the documentation
29#
30#***************************************************************************************************
31#
32# command lines :
33#
34#   1) makeorchidee_fcm   [ -parallel  PARALLEL_TYPE ]
35#                         [ -driver ]
36#                         [ -arch ARCHitecture ]
37#                         [ -prod | -dev | -debug ]
38#
39#   2) makeorchidee_fcm   [ -doc | -doc_para ] ## actually doc_para is commented
40#                         [ -rmdoc ]
41#                         [ -doc_tree ]
42#
43
44parallel_mode=NONE
45is_driver_opt=FALSE
46is_arch_opt=FALSE
47is_compile_opt=FALSE
48clean=FALSE
49default_compile_flags="%PROD_FFLAGS"
50xios=FALSE
51full=""
52job=1
53ext_src=""
54
55export P_P=""
56export SECTIONS_PARA=""
57
58ORCHDIR=`/bin/pwd`
59fcm_path=$ORCHDIR/tools/FCM_V1.2/bin
60
61while (($# > 0))
62  do
63  case $1 in
64      "-h") cat <<fin
65
66########################################################################
67# Manuel en ligne
68########################################################################
69more <<eod
70
71
72makeorchidee_fcm [Options]
73
74[ -parallel|-p PARALLEL_TYPE ] : activate parallelization with 3 options :
75    PARALLEL_TYPE =
76    ( mpi | MPI )  : use Message Passing Interface standard
77    ( omp | OMP )  : use OpenMP standard
78    ( mpi_omp | MPI_OMP ) : use both MPI and OpenMP
79    ( none | NONE | seq ) : sequential mode (default)
80
81[ -driver ] : compilation of ORCHIDEE driver if equal TRUE
82
83[ -arch ARCHitecture ] : if TRUE, change architecture for ARCHitecture
84
85[ -xios ] : compilation with XIOS
86
87[ -noxios ] : compilation without XIOS
88
89[ -prod ] : compilation for production (all optimization)
90
91[ -dev ] : compilation for development (low optimization and -g)
92
93[ -d|-debug ] : compilation for debugging (no optmization and all debug options)
94
95| -full ] : activate full recompiling
96
97| -clean ] : delete all files produceed during previous compilation
98
99[ -j x ] : activate parallel compiling on x task, default 1 task
100
101[ -ext_src path] : path to an additional set of routines to compile with the model
102
103[ -doc ] : generate documentation with Doxygen (exit after doc computation)
104
105[ -doc_para ] : generate documentation with Doxygen with parallelization calls
106
107[ -rmdoc ] : remove documentation directory (before generate new documentation with Doxygen ?)
108
109[ -doc_tree ] : generate tree of ORCHIDEE directories for each file
110
111fin
112    exit;;
113########################################################################
114# Lecture des differentes options
115########################################################################
116
117    "-parallel")
118        parallel_mode=$2 ; shift ; shift ;;
119                       
120    "-driver")
121         is_driver_opt=TRUE
122        shift ;;
123
124    "-arch")
125        is_arch_opt=TRUE
126        arch="$2" ; shift ; shift ;;
127
128    "-xios")
129         xios=TRUE
130        shift ;;
131
132    "-noxios")
133         xios=FALSE
134        shift ;;
135
136    "-prod")
137        is_compile_opt=TRUE
138        compile_flags="%PROD_FFLAGS"
139        shift ;;
140
141    "-dev")
142        is_compile_opt=TRUE
143        compile_flags="%DEV_FFLAGS"
144        shift ;;
145
146    "-debug")
147        is_compile_opt=TRUE
148        compile_flags="%DEBUG_FFLAGS"
149        shift ;;
150
151     "-j")
152        job="$2" ; shift ; shift ;;
153
154     "-full")
155        full='-full'
156        shift ;;
157
158     "-clean")
159        clean=TRUE
160        shift ;;
161
162      "-ext_src")
163        ext_src=$2 ; shift ; shift ;;
164
165#    "-doc_para")
166#        setenv P_P -DCPP_PARA
167#       setenv SECTIONS_PARA "-e s&ENABLED_SECTIONS\ *= &ENABLED_SECTIONS       = CPP_PARA&g"
168#       goto doc
169
170        "-doc")
171#####################################################################################################
172
173# 2) Building the documentation:
174# ------------------------------
175# We assume to start in the ORCHIDEE directory
176#
177#****  Directory structure:
178#
179# ..                       : parent of the start dir.
180#   -- ORCHIDEE            : ($MODELPATH), start directory
181#       - src_sechiba
182#       - src_stomate
183#       + DOC
184#       + webdoc
185#   -- IOIPSL
186#       - src
187#   ++ modeles_doc         : ($SRCPATH), source files for the documentation, emptied at start, temporary
188#
189#****  gawk scripts called :
190#
191# codeinc.awk              : encaspulates code parts in Doxygen documentation
192# codedox.awk              : transforms almost all comments in Doxygen comments for documentation
193# codealgo.awk             : emphasizes main algorithm description of each routine in their Doxygen documentation
194#
195#****
196        unalias cd
197
198        export REV=`svn info | grep vision | sed -e 's&.*vision.*: \([0-9]*\)&\1&' | head -n 1`
199        export TAG=`svn info | grep URL | sed -e 's&.*URL.*: svn://forge.ipsl.jussieu.fr/orchidee/\(.*\)&\1&' | head -n 1 | xargs dirname`
200        cd ..
201
202        \rm -rf modeles_doc
203        export MODELPATH=${PWD}
204        \mkdir modeles_doc
205        export SRCPATH=${MODELPATH}/modeles_doc
206
207        find IOIPSL/src \( -not -path '*.svn*' \
208                        -a \( -name '*.f90' -o -name "*.F90" -o -name "*.h" \) \) \
209                    -exec bash -c 'mkdir -p '${SRCPATH}'/$( dirname {} ); cp -p {} '${SRCPATH}'/$( dirname {} )' \;
210
211        find ORCHIDEE \( -not -path '*.svn*' \
212                        -a \( -name '*.f90' -o -name "*.F90" -o -name "*.h" \) \) \
213                    -exec bash -c 'mkdir -p '${SRCPATH}'/$( dirname {} ); cp -p {} '${SRCPATH}'/$( dirname {} )' \;
214        cd ${SRCPATH}
215        # Use standard preprocessor to suppress all preproc directives
216        \find . -name "*.f90" -exec cpp -P -C -traditional -x assembler-with-cpp ${P_P} '{}' '{}'_ \;
217        \find . -name "*.f90" -print -exec mv -f '{}'_ '{}' \;
218
219        # use codeinc script to encaspulate code parts in Doxygen documentation
220        \find . -name "*.f90" -exec gawk -f ${MODELPATH}/ORCHIDEE/DOC/TOOLS/codeinc.awk '{}' \; > /dev/null
221        \find . -name "*.f90" -print -exec mv -f '{}'_preproc_codeinc '{}' \;
222        # use codedox script to transform almost all comments in Doxygen comments for documentation (use with care !)
223        \find . -name "*.f90" -exec gawk -f ${MODELPATH}/ORCHIDEE/DOC/TOOLS/codedox.awk '{}' \; > /dev/null
224        \find . -name "*.f90" -print -exec mv -f '{}'_preproc_codedox '{}' \;
225
226        # use codealgo script to emphasize main algorithm description of each routine in their Doxygen documentation
227        \find . -name "*.f90" -exec gawk -f ${MODELPATH}/ORCHIDEE/DOC/TOOLS/codealgo.awk '{}' \; > /dev/null
228        \find . -name "*.f90" -print -exec mv -f '{}'_preproc_codealgo '{}' \;
229        cd ../ORCHIDEE
230        \rm -f ${MODELPATH}/ORCHIDEE/Doxyfile_ORCHIDEE
231        sed -e 's&MYPATH&'${MODELPATH}'&g' -e 's&SRCPATH&'${SRCPATH}'&g' \
232            -e 's&MYTAG&'${TAG}'&' -e 's&MYREV&'${REV}'&' ${SECTIONS_PARA} \
233            ${MODELPATH}/ORCHIDEE/Doxyfile_ORCHIDEE.init > ${MODELPATH}/ORCHIDEE/Doxyfile_ORCHIDEE
234        \rm -f ${MODELPATH}/ORCHIDEE/DOC/header.tex
235        sed -e "s&MYTAG&${TAG}&" -e "s&MYREV&${REV}&" \
236            ${MODELPATH}/ORCHIDEE/DOC/header.tex.init > ${MODELPATH}/ORCHIDEE/DOC/header.tex
237        ln -s /home/orchidee01/maignan/ORCHIDEE/DOC/IMAGES ${MODELPATH}/ORCHIDEE/DOC/IMAGES
238        gmake doc
239        gmake bib
240        gmake toc
241        \rm -rf ${MODELPATH}/ORCHIDEE/webdoc
242        \mv ${MODELPATH}/ORCHIDEE/docs/html ${MODELPATH}/ORCHIDEE/webdoc
243        gmake index
244        gmake toc
245        \rm -rf ${SRCPATH}
246        cp ${MODELPATH}/ORCHIDEE/docs/latex/refman.pdf ${MODELPATH}/ORCHIDEE/documentation.pdf
247        exit
248        shift ;;
249
250
251     "-rmdoc")
252        \rm -rf docs
253        shift ;;
254
255     "-doc_tree") 
256        cd ..
257        find ORCHIDEE \( -not -path '*.svn*' \
258                        -a \( -name '*.f90' -o -name "*.F90" -o -name "*.h" \) \) \
259                    -exec bash -c 'mkdir -p ORCHIDEE/DOC/$( dirname {} )/$( echo $( basename {} ) | sed -e "s/\..*//" )' \;
260        cd ORCHIDEE
261        shift ;;
262
263    *)
264        echo "unknown option "$1" , exiting..."
265        exit
266   esac
267done
268
269#####################################################################################################
270# 0) Clean directory from files produced during previous compilation
271# --------------------------------------
272if [[ "$clean" == "TRUE" ]] ; then
273    rm -fr .config
274    rm -fr lib
275    rm -fr bin
276    rm -fr tmp_src
277    rm -f ../../lib/intersurf.mod
278    rm -f ../../lib/liborglob.a
279    rm -f ../../lib/libparallel.a
280    rm -f ../../lib/libsechiba.a
281    rm -f ../../lib/libstomate.a
282    rm -f ../../lib/libparameters.a
283    rm -f ../../lib/liborchidee_ol.a
284    rm -f ../../lib/liborchidee.a
285
286    exit
287fi
288
289# 1) Compilation du code direct avec fcm
290# --------------------------------------
291# Add fcm in environement path
292export PATH=${fcm_path}:${PATH}
293
294#define architecture files
295if [[ "$is_arch_opt" == "TRUE" ]]
296 then
297  if [[ -e arch/arch-${arch}.fcm ]]
298 then
299    rm -f arch.fcm
300    ln -s arch/arch-${arch}.fcm arch.fcm
301  else
302    echo "architecture file : << arch/arch-${arch}.fcm >> is missing, exiting...."
303    exit
304  fi
305 
306  if [[ -e arch/arch-${arch}.path ]]
307 then
308    rm -f arch.path
309    ln -s arch/arch-${arch}.path arch.path
310  else
311    echo "architecture file : << arch/arch-${arch}.path >> is missing, exiting...."
312    exit
313  fi
314else
315  echo "Warning : architecture not specified, taking default file <<arch.fcm>> and <<arch.path>>" 
316  if [[ ! -e arch.fcm ]]
317 then
318    echo "architecture file : << arch.fcm >> is missing, exiting...."
319    exit
320  fi
321
322  if [[ ! -e arch.fcm ]]
323 then
324    echo "architecture file : << arch.path >> is missing, exiting...."
325    exit
326  fi
327fi
328 
329# set compiler flags
330FFLAGS="%BASE_FFLAGS"
331LD_FFLAGS="%BASE_LD"
332CPP_KEY="%FPP_DEF"
333
334# set compiler flags for optimisation
335if [[ "$is_compile_opt" == "FALSE" ]]
336 then
337  compile_flags=$default_compile_flags
338fi
339FFLAGS=${FFLAGS}" "$compile_flags
340LD_FFLAGS=${LD_FFLAGS}" "$compile_flags
341
342# set compiler flags for parallelism
343echo "parallel_mode = "${parallel_mode}
344
345if [[ "$parallel_mode" == "mpi" ]] || [[ "$parallel_mode" == "MPI" ]]
346then
347    FFLAGS="${FFLAGS} %MPI_FFLAGS"
348    LD_FFLAGS="%MPI_LD ${LD_FFLAGS}"
349    CPP_KEY="CPP_PARA ${CPP_KEY}"
350elif [[ "$parallel_mode" == "omp" ]] || [[ "$parallel_mode" == "OMP" ]]
351then
352    FFLAGS="${FFLAGS} %OMP_FFLAGS"
353    LD_FFLAGS="%OMP_LD ${LD_FFLAGS}"
354    CPP_KEY="CPP_OMP CPP_PARA ${CPP_KEY}"
355elif [[ "$parallel_mode" == "mpi_omp" ]] || [[ "$parallel_mode" == "MPI_OMP" ]]
356then
357    FFLAGS="${FFLAGS} %MPI_FFLAGS %OMP_FFLAGS"
358    LD_FFLAGS="%MPI_LD %OMP_LD ${LD_FFLAGS}"
359    CPP_KEY="CPP_OMP CPP_PARA ${CPP_KEY}"
360elif [[ "$parallel_mode" == "none" ]] || [[ "$parallel_mode" == "NONE" ]] || [[ "$parallel_mode" == "seq" ]]
361then
362    echo "Compiling for sequential mode"
363else
364    echo "This option for parallel_mode is not implemeted. Choose between mpi, omp, mpi_omp and none."
365    exit
366fi
367
368
369if [[ "$xios" == "TRUE" ]] 
370  then
371    CPP_KEY="XIOS ${CPP_KEY}"
372fi
373
374# set target
375TARGET=liborchidee.a
376if [[ "$is_driver_opt" == "TRUE" ]] 
377then
378    TARGET="liborchidee_ol.a dim2_driver.exe teststomate.exe forcesoil.exe"
379fi
380
381source ./arch.path
382
383# build config file
384config_fcm="config.fcm"
385rm -f $config_fcm
386touch $config_fcm
387
388echo "%ARCH          $arch"                             >> $config_fcm 
389echo "%FFLAGS        $FFLAGS"                           >> $config_fcm 
390echo "%CPP_KEY       $CPP_KEY"                          >> $config_fcm
391echo "%EXEC          $TARGET"                           >> $config_fcm
392echo "%LD_FFLAGS     $LD_FFLAGS"                        >> $config_fcm
393if [[ "$xios" == "TRUE" ]]
394  then
395   echo "%INCDIR        -I$NETCDF_INCDIR -I$IOIPSL_INCDIR -I$XIOS_INCDIR" >> $config_fcm
396   echo "%LIBDIR        -L$NETCDF_LIBDIR -L$IOIPSL_LIBDIR -L$XIOS_LIBDIR" >> $config_fcm
397else
398   echo "%INCDIR        -I$NETCDF_INCDIR -I$IOIPSL_INCDIR" >> $config_fcm
399   echo "%LIBDIR        -L$NETCDF_LIBDIR -L$IOIPSL_LIBDIR" >> $config_fcm
400fi
401echo "%EXT_SRC       $ext_src"                          >> $config_fcm
402
403
404# Delete interface module from modipsl/lib directory
405rm -f ../../lib/intersurf.mod
406
407# Do the compiling
408fcm build -j $job $full
409
410# Copy into modipsl/lib directory libraries and interface module needed by LMDZ
411cp lib/lib*a ../../lib/.
412cp lib/intersurf.mod ../../lib/.
413
414# Copy executables to modipsl/bin directory
415if [[ "$is_driver_opt" == "TRUE" ]] 
416then
417    cp bin/dim2_driver.exe ../../bin/orchidee_ol
418    cp bin/teststomate.exe ../../bin/teststomate
419    cp bin/forcesoil.exe ../../bin/forcesoil
420fi
421
422
Note: See TracBrowser for help on using the repository browser.