source: CONFIG_DEVT/IPSLCM6.5_work_ENSEMBLES/modeles/ORCHIDEE/makeorchidee_fcm @ 5501

Last change on this file since 5501 was 5501, checked in by aclsce, 4 years ago

First import of IPSLCM6.5_work_ENSEMBLES working configuration

  • Property svn:executable set to *
File size: 18.6 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
56arch_default_path="arch"
57arch_path="arch"
58
59# Path to store files produced during compilation
60# Note: config_path was previously named .config
61rel_config_path=build
62config_path=$ORCHDIR/${rel_config_path}
63
64
65# Following variables can be set as environement variables if wanted
66if [ -n "$FCM_ARCH" ]; then
67    arch="$FCM_ARCH"
68else
69    arch=NONE
70fi
71if [ -n "$FCM_PARA" ]; then
72    parallel_mode="$FCM_PARA"
73else
74    parallel_mode=seq
75fi
76if [ -n "$FCM_JOBS" ]; then
77    job="$FCM_JOBS"
78else
79    job=1
80fi
81
82
83#########################################################################
84# 2. Read arguments
85#
86while (($# > 0)) ; do
87
88  case $1 in
89    "-h")
90        print_help=TRUE ; shift ;;
91
92    "-parallel")
93        parallel_mode=$2 ; shift ; shift ;;
94
95    "-p")
96        parallel_mode=$2 ; shift ; shift ;;
97                       
98    "-driver")
99        is_driver_opt=TRUE ; shift ;;
100
101    "-otherexec")
102        is_other_opt=TRUE
103        is_driver_opt=TRUE ; shift ;;
104
105    "-arch")
106        arch="$2" ; shift ; shift ;;
107
108    "-arch_path")
109        arch_path=$2 ; shift ; shift ;;
110
111    "-xios")
112        xios=TRUE
113        shift ;;
114
115    "-xios2")
116        xios=TRUE
117        shift ;;
118
119    "-noxios")
120        xios=FALSE
121        shift ;;
122
123    "-prod")
124        compile_flags="%PROD_FFLAGS" ; shift ;;
125
126    "-dev")
127        compile_flags="%DEV_FFLAGS" ; shift ;;
128
129    "-debug")
130        compile_flags="%DEBUG_FFLAGS" ; shift ;;
131
132     "-j")
133        job="$2" ; shift ; shift ;;
134     
135     "-full")
136        full='-full' ; shift ;;
137
138     "-clean")
139        clean=TRUE ; shift ;;
140
141     "-ext_src")
142        ext_src=$2 ; shift ; shift ;;
143
144#    "-doc_para")
145#        setenv P_P -DCPP_PARA
146#       setenv SECTIONS_PARA "-e s&ENABLED_SECTIONS\ *= &ENABLED_SECTIONS       = CPP_PARA&g"
147#       goto doc
148
149     "-doc")
150          compile_doc=TRUE ; shift ;;
151
152     "-rmdoc")
153          \rm -rf docs
154          shift ;;
155
156     "-doc_tree") 
157          cd ..
158        find ORCHIDEE \( -not -path '*.svn*' \
159                        -a \( -name '*.f90' -o -name "*.F90" -o -name "*.h" \) \) \
160                    -exec bash -c 'mkdir -p ORCHIDEE/DOC/$( dirname {} )/$( echo $( basename {} ) | sed -e "s/\..*//" )' \;
161        cd ORCHIDEE
162        shift ;;
163
164    *)
165        echo "unknown option "$1" , exiting..."
166        exit
167   esac
168done
169
170#########################################################################
171# 3. Print help documentation and exit
172#
173if [[ "$print_help" == "TRUE" ]] ; then
174  cat <<fin
175
176########################################################################
177# Usage of the script makeorchidee_fcm
178#
179# makeorchidee_fcm compiles ORCHIDEE using the Fcm a software developed
180# by the Hadley Centre. Fcm is stored in tools directory.
181# Platform specific compile options are found in the arch directory.
182########################################################################
183
184./makeorchidee_fcm [Options]
185
186Main options
187[ -h ]        : show this help
188
189[ -arch XXX ] : name of the archicture file containg platform dependent compile options.
190                The files arch/arch-XXX.fcm and arch/arch-XXX.path must exist.
191
192[ -arch_path XXX ] : directory of the archicture file containg platform dependent compile options.
193                     Default is ./arch directory. If the files are not found in the folder, the default ./arch folder will be used.
194
195[ -parallel|-p PARALLEL_TYPE ] : choose parallelization mode for ORCHIDEE :
196    PARALLEL_TYPE =
197    ( mpi | MPI )              : only MPI (Message Passing Interface)
198    ( omp | OMP )              : only OpenMP
199    ( mpi_omp | MPI_OMP )      : hybrid MPI/OpenMP mode
200    ( none | NONE | seq )      : sequential mode (default)
201
202[ -driver ]      : compilation of ORCHIDEE offline standard driver
203[ -otherexec ]   : compilation of other programs: teststomate, forcesoil, testrouting.
204                   Warning! All these programs are not fully validated or maintained.
205
206Options related to cleaning
207| -clean ]       : delete all files produceed during previous compilation
208| -full ]        : activate full recompiling
209
210Options for XIOS, only choose one of the following
211[ -xios | -xios2 ] : linking with XIOS 2.0 (it is not longer possible to use XIOS1)
212[ -noxios ]        : compilation without XIOS (default)
213
214Options for optimization, choose only one of the following
215[ -prod ]        : compilation for production (all optimization)
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    # Remove the whole directory created during previous compilation
340    rm -fr ${config_path}
341
342    # Clean ORCHIDEE modules in modipsl/lib folder
343    rm -f ../../lib/intersurf.mod
344    rm -f ../../lib/sechiba.mod
345    rm -f ../../lib/chemistry.mod
346    rm -f ../../lib/liborglob.a
347    rm -f ../../lib/libparallel.a
348    rm -f ../../lib/libsechiba.a
349    rm -f ../../lib/libstomate.a
350    rm -f ../../lib/libparameters.a
351    rm -f ../../lib/liborchidee_ol.a
352    rm -f ../../lib/liborchidee.a
353
354    echo Clean files created during previous compilation of ORCHIDEE done
355
356    exit
357fi
358
359#########################################################################
360# 6. Prepare compilation
361#
362# Add fcm in environement path
363export PATH=${fcm_path}:${PATH}
364
365# Define architecture files
366if [[ "$arch" != "NONE" ]] ; then
367  # First search for file in arch_path folder, if they are not there, search in arch_default_path
368  if [[ -e $arch_path/arch-${arch}.path ]] ; then
369    rm -f arch.path
370    ln -s $arch_path/arch-${arch}.path arch.path
371  elif [[ -e $arch_default_path/arch-${arch}.path ]] ; then
372    rm -f arch.path
373    ln -s $arch_default_path/arch-${arch}.path arch.path
374  fi
375       
376  if [[ -e $arch_path/arch-${arch}.fcm ]] ; then
377    rm -f arch.fcm
378    ln -s $arch_path/arch-${arch}.fcm arch.fcm
379  elif [[ -e $arch_default_path/arch-${arch}.fcm ]] ; then
380    rm -f arch.fcm
381    ln -s $arch_default_path/arch-${arch}.fcm arch.fcm
382  fi
383
384  if [[ -e $arch_path/arch-${arch}.env ]] ; then
385    rm -f arch.env
386    ln -s $arch_path/arch-${arch}.env arch.env
387  elif [[ -e $arch_default_path/arch-${arch}.env ]] ; then
388    rm -f arch.env
389    ln -s $arch_default_path/arch-${arch}.env arch.env
390  else
391    ln -s .void_file arch.env
392  fi
393  source arch.env
394  source arch.path
395else
396  echo "Warning : architecture not specified, taking default file <<arch.fcm>> and <<arch.path>>" 
397  if [[ ! -e arch.fcm ]] ; then
398    echo "architecture file : << arch.fcm >> is missing, exit now...."
399    exit
400  fi
401
402  if [[ -e arch.path ]] ; then
403    source arch.path
404  else
405    echo "architecture file : << arch.path >> is missing, exit now...."
406    exit
407  fi
408
409  if [[ -e arch.env ]] ; then
410    source arch.env
411  fi
412fi
413
414# set compiler flags
415FFLAGS="%BASE_FFLAGS"
416LD_FFLAGS="%BASE_LD"
417CPP_KEY="%FPP_DEF"
418
419# set compiler flags for optimisation
420FFLAGS=${FFLAGS}" "$compile_flags
421LD_FFLAGS=${LD_FFLAGS}" "$compile_flags
422
423# set compiler flags for parallelism
424echo "parallel_mode = "${parallel_mode}
425
426if [[ "$parallel_mode" == "mpi" ]] || [[ "$parallel_mode" == "MPI" ]] ; then
427    FFLAGS="${FFLAGS} %MPI_FFLAGS"
428    LD_FFLAGS="%MPI_LD ${LD_FFLAGS}"
429    CPP_KEY="CPP_PARA ${CPP_KEY}"
430elif [[ "$parallel_mode" == "omp" ]] || [[ "$parallel_mode" == "OMP" ]] ; then
431    FFLAGS="${FFLAGS} %OMP_FFLAGS"
432    LD_FFLAGS="%OMP_LD ${LD_FFLAGS}"
433    CPP_KEY="CPP_OMP CPP_PARA ${CPP_KEY}"
434elif [[ "$parallel_mode" == "mpi_omp" ]] || [[ "$parallel_mode" == "MPI_OMP" ]] ; then
435    FFLAGS="${FFLAGS} %MPI_FFLAGS %OMP_FFLAGS"
436    LD_FFLAGS="%MPI_LD %OMP_LD ${LD_FFLAGS}"
437    CPP_KEY="CPP_OMP CPP_PARA ${CPP_KEY}"
438elif [[ "$parallel_mode" == "none" ]] || [[ "$parallel_mode" == "NONE" ]] || [[ "$parallel_mode" == "seq" ]] ; then
439    echo "Compiling for sequential mode"
440else
441    echo "This option for parallel_mode is not implemeted. Choose between mpi, omp, mpi_omp and none."
442    exit
443fi
444
445#
446# Create some temporary variable to which we add as needed
447#
448INCDIR="$NETCDF_INCDIR $IOIPSL_INCDIR"
449LIBDIR="$NETCDF_LIBDIR $NETCDF_LIB $IOIPSL_LIBDIR $IOIPSL_LIB"
450
451# Do we need to link with XIOS
452#
453if [[ "$xios" == "TRUE" ]] ; then
454    CPP_KEY="XIOS ${CPP_KEY}"
455    INCDIR="${INCDIR} $XIOS_INCDIR"
456    LIBDIR="${LIBDIR} $XIOS_LIBDIR $XIOS_LIB"
457fi
458
459# Determine if also need to compile the OASIS driver. This is only the case if the
460# path for the libraries is provided and exists
461if [ -n "$OASIS_LIBDIR" ] ; then
462    is_oasisdriver_opt=TRUE
463    # Check also if the provided path also exist. If not, delete the option.
464    if [ ! -d ${OASIS_LIBDIR} ]; then
465        is_oasisdriver_opt=FALSE
466    fi
467else
468    is_oasisdriver_opt=FALSE
469fi
470
471# set target
472TARGET=liborchidee.a
473if [[ "$is_driver_opt" == "TRUE" ]] ; then
474    TARGET="liborchidee_ol.a dim2_driver.exe orchideedriver.exe"
475fi
476if [[ "$is_other_opt" == "TRUE" ]] ; then
477    TARGET="${TARGET} teststomate.exe forcesoil.exe testrouting.exe"
478fi
479
480if [[ "$is_oasisdriver_opt" == "TRUE" ]] ; then
481    CPP_KEY="OASIS ${CPP_KEY}"
482    TARGET="${TARGET} driver2oasis.exe orchideeoasis.exe"
483    INCDIR="${INCDIR} ${OASIS_INCDIR}/psmile.MPI1 ${OASIS_INCDIR}/scrip  ${OASIS_INCDIR}/mct"
484    LIBDIR="${LIBDIR} ${OASIS_LIBDIR} -lpsmile.MPI1 -lmct -lmpeu -lscrip"
485    echo "OASIS : ${INCDIR}"
486fi
487
488
489# build config file
490config_fcm="config.fcm"
491rm -f $config_fcm
492touch $config_fcm
493
494echo "%CONFIG_PATH   $config_path"                      >> $config_fcm 
495echo "%ARCH          $arch"                             >> $config_fcm 
496echo "%FFLAGS        $FFLAGS"                           >> $config_fcm 
497echo "%CPP_KEY       $CPP_KEY"                          >> $config_fcm
498echo "%EXEC          $TARGET"                           >> $config_fcm
499echo "%LD_FFLAGS     $LD_FFLAGS"                        >> $config_fcm
500echo "%INCDIR        ${INCDIR}"                         >> $config_fcm
501echo "%LIBDIR        ${LIBDIR}"                         >> $config_fcm
502echo "%EXT_SRC       $ext_src"                          >> $config_fcm
503
504
505# Delete interface module from modipsl/lib directory
506rm -f ../../lib/intersurf.mod
507rm -f ../../lib/sechiba.mod
508
509# Check if compiling is locked
510if [ -f ${config_path}/fcm.bld.lock ] ; then
511    echo "WARNING : build lock file exists"
512    echo "This means that either someone else is compiling this directory right now "
513    echo "or the previous compiling was interrupt abnormally."
514    echo ""
515    echo "Do you whant to remove this file and start compiling? [answer yes/no]" 
516    read answer
517    if [ $answer = "yes" ] || [ $answer = "y" ] ; then
518        rm -f ${config_path}/fcm.bld.lock
519    else
520        echo "Exit now!!!"
521        exit 1
522    fi
523fi
524
525#########################################################################
526# 7. Do the compiling
527fcm build -j $job $full
528err=$?
529
530# Check error message from fcm build
531if [ $err != 0 ] ; then 
532  # ERROR IN COMPILING
533  echo ERROR IN COMPILING ORCHIDEE : $err 
534  exit 1
535fi 
536
537# Create link to bin, lib and inc folders directly in ORCHIDEE folder
538# Use rel_config_path to create link with the relative path
539rm -f bin ; rm -f lib; rm -f inc
540ln -s ${rel_config_path}/bin bin
541ln -s ${rel_config_path}/lib lib
542ln -s ${rel_config_path}/inc inc
543 
544# Copy into modipsl/lib directory libraries and interface module needed by LMDZ
545cp ${config_path}/lib/lib*a          ../../lib/.
546cp ${config_path}/inc/intersurf.mod  ../../lib/.
547cp ${config_path}/inc/sechiba.mod    ../../lib/.
548
549# Move created executables to modipsl/bin directory
550if [ -f ${config_path}/bin/dim2_driver.exe ]    ; then cp -f ${config_path}/bin/dim2_driver.exe ../../bin/orchidee_ol ; fi
551if [ -f ${config_path}/bin/teststomate.exe ]    ; then cp -f ${config_path}/bin/teststomate.exe ../../bin/teststomate ; fi
552if [ -f ${config_path}/bin/forcesoil.exe ]      ; then cp -f ${config_path}/bin/forcesoil.exe ../../bin/forcesoil ; fi
553if [ -f ${config_path}/bin/orchideedriver.exe ] ; then cp -f ${config_path}/bin/orchideedriver.exe ../../bin/orchideedriver ; fi
554if [ -f ${config_path}/bin/testrouting.exe ]    ; then cp -f ${config_path}/bin/testrouting.exe ../../bin/testrouting ; fi
555if [ -f ${config_path}/bin/driver2oasis.exe ]   ; then cp -f ${config_path}/bin/driver2oasis.exe ../../bin/driver2oasis ; fi
556if [ -f ${config_path}/bin/orchideeoasis.exe ]  ; then cp -f ${config_path}/bin/orchideeoasis.exe ../../bin/orchideeoasis ; fi
557
558
Note: See TracBrowser for help on using the repository browser.