source: vendor/nemo/v3.4_r_3300/NEMOGCM/CONFIG/makenemo

Last change on this file was 4, checked in by cholod, 13 years ago

Load NEMO_TMP into vendor/nemo/current.

  • Property svn:executable set to *
File size: 8.3 KB
Line 
1#!/bin/bash
2#set -x
3set -o posix
4#set -u
5#set -e
6#+
7#
8# ===============
9# makenemo
10# ===============
11#
12# --------------------------
13# Compile NEMO
14# --------------------------
15#
16# SYNOPSIS
17# ========
18#
19# ::
20#
21#  $ makenemo
22#
23#
24# DESCRIPTION
25# ===========
26#
27#
28# This script aims :
29#
30# - to choose MYCONFIG
31# - to choose compiler options 
32# - to create the CONFIG/MYCONFIG/WORK directory
33# - to compile this configuration
34#
35#  Variables used :
36#
37#  From user input
38#
39# - NEW_CONF    : configuration to be created
40# - REF_CONF    : reference configuration to build the new one
41# - CMP_NAM     : compiler name
42# - NBR_PRC     : number of processes used to compile 
43# - NEM_SUBDIR  : NEMO subdirectory used (specified)
44#
45#  Locally defined :
46#
47# - TAB         : NEMO subdirectory used (read) 
48# - MAIN_DIR    : self explaining
49# - CONFIG_DIR  :   "    "    "   
50# - MODELES_DIR :   "    "    "
51# - TOOLS_DIR   :   "    "    "
52# - NEMO_DIR    :   "    "    "
53#
54# EXAMPLES
55# ========
56#
57# ::
58#
59#  $ ./makenemo -m ifort_osx - j3 -n ORCA2_LIM
60#
61#
62# TODO
63# ====
64#
65# option debug
66#
67#
68# EVOLUTIONS
69# ==========
70#
71# $Id: makenemo 3294 2012-01-28 16:44:18Z rblod $
72#
73#
74#
75#   * creation
76#
77#-
78
79#-
80#- Initialization of the options ---
81x_d="";
82x_h="";
83x_n="";
84x_r="";
85x_m="";
86x_t="";
87x_c="";
88x_j=1;
89x_e="none";
90x_s=NEMO;
91x_v=1;
92
93#- Local variables ---
94b_n=$(basename ${0})
95OPTIND=1
96MAIN_DIR=$(cd $(dirname "$0"); pwd)
97MAIN_DIR=${MAIN_DIR%/SETTE*}
98MAIN_DIR=${MAIN_DIR%/TOOLS*}
99MAIN_DIR=${MAIN_DIR%/CONFIG*}
100export MAIN_DIR
101#
102export CONFIG_DIR=${MAIN_DIR}/CONFIG
103export TOOLS_DIR=${MAIN_DIR}/TOOLS
104export COMPIL_DIR=${MAIN_DIR}/TOOLS/COMPILE
105export NEMO_DIR=${MAIN_DIR}/${x_s}
106export AGRIFUSE=10
107declare -a TAB
108#-
109#- FCM and functions location ---
110export PATH=${MAIN_DIR}/EXTERNAL/fcm/bin:$PATH
111
112#-
113#- Choice of the options ---
114while getopts :hd:n:r:m:j:e:s:v:t: V
115do
116    case $V in
117        (h) x_h=${OPTARG};
118        echo "Usage      : "${b_n} \
119            " [-h] [-n name] [-m arch] [-d "dir1 dir2"] [-r conf] [-s Path] [-e Path] [-j No] [-v No]";
120        echo " -h               : help";
121        echo " -h institute : specific help for consortium members";
122        echo " -n name      : config name, [-n help] to list existing configurations";
123        echo " -m arch      : choose compiler, [-m help] to list existing compilers";
124        echo " -d dir       : choose NEMO sub-directories";
125        echo " -r conf      : choose reference configuration";
126        echo " -s Path      : choose alternative location for NEMO main directory";
127        echo " -e Path      : choose alternative location for MY_SRC directory";
128        echo " -j No        : number of processes used to compile (0=nocompilation)";
129        echo " -v No        : set verbosity level for compilation [0-3]";
130        echo " -t dir       : temporary directory for compilation"
131        echo "";
132        echo "Example to install a new configuration MY_CONFIG";
133        echo "with OPA_SRC and LIM_SRC_2 ";
134        echo "makenemo -n MY_CONFIG -d \"OPA_SRC LIM_SRC_2\"";
135        echo "";
136        echo "Available configurations :"; cat ${CONFIG_DIR}/cfg.txt;
137        echo "";
138        echo "Example to remove bad configuration ";
139        echo "./makenemo -n MY_CONFIG clean_config";
140        echo "";
141        echo "Example to clean ";
142        echo "./makenemo clean";
143        echo "";
144        echo "Example to add and remove keys";
145        echo "./makenemo add_key \"key_iomput key_mpp_mpi\" del_key \"key_agrif\" ";
146        echo "";
147        echo "Example to add and remove keys for a new configuration, and do not compile";
148        echo "./makenemo -n MY_CONFIG -j0 add_key \"key_iomput key_mpp_mpi\" del_key \"key_agrif\" ";
149        echo "";
150        . ${COMPIL_DIR}/Flist_archfile.sh ${x_h}  ;
151        echo "";
152        echo "Default : previous configuration and compiler";
153        exit 0;;
154        (d)  x_d=${OPTARG};;
155        (n)  x_n=${OPTARG};;
156        (r)  x_r=${OPTARG};;
157        (m)  x_m=${OPTARG};;
158        (j)  x_j=${OPTARG};;
159        (t)  x_t=${OPTARG};;
160    (e)  x_e=${OPTARG};;
161    (s)  x_s=${OPTARG};;
162    (v)  x_v=${OPTARG};;
163        (:)  echo ${b_n}" : -"${OPTARG}" option : missing value" 1>&2;
164        exit 2;;
165        (\?) echo ${b_n}" : -"${OPTARG}" option : not supported" 1>&2;
166        exit 2;;
167    esac
168done
169shift $(($OPTIND-1));
170
171while [ ${#1} -gt 0 ]   # Get clean, clean_config options
172do
173    case "$1" in
174        clean)
175            x_c="--$1"
176            ;;
177        clean_config)
178            . ${COMPIL_DIR}/Fclean_config.sh
179            exit
180            ;;
181        add_key)
182            list_add_key=$2
183            export ${list_add_key}
184            shift
185            ;;
186        del_key)
187            list_del_key=$2
188            export ${list_del_key}
189            shift
190            ;;
191        *)
192            echo " \"$1\" BAD OPTION" 
193            exit
194            ;;
195       
196    esac
197    shift
198done
199
200
201#-
202#- Go to NEMOGCM/config directory ---
203cd ${CONFIG_DIR}
204
205#-
206#- Initialisation from input ---
207export NEW_CONF=${x_n}
208NBR_PRC=${x_j}
209CMP_NAM=${x_m}
210NEM_SUBDIR=${x_d}
211REF_CONF=${x_r}
212NEMO_TDIR=${x_t:-$NEMO_TDIR}
213export NEMO_TDIR=${NEMO_TDIR:-$CONFIG_DIR}
214export NEMO_DIR=${MAIN_DIR}/${x_s}
215
216#- Check if the tool or the compiler exist or list it
217if [ "${NEW_CONF}" == help ] ; then
218    echo "Available configurations :" 
219    cat ${CONFIG_DIR}/cfg.txt
220    exit
221fi
222[ "${CMP_NAM}" ==  help ] && . ${COMPIL_DIR}/Flist_archfile.sh all && exit
223
224#- When used for the first time, choose a compiler ---
225. ${COMPIL_DIR}/Fcheck_archfile.sh arch_nemo.fcm ${CMP_NAM} || exit
226
227#-
228#- Choose a default configuration if needed ---
229#- ORCA2_LIM or last one used ---
230. ${COMPIL_DIR}/Fcheck_config.sh cfg.txt ${NEW_CONF} || exit
231
232
233if [ ${#NEW_CONF} -eq 0 ] ; then
234    if [ ${#NEM_SUBDIR} -eq 0 -a ${#REF_CONF} -eq 0 ]; then
235        echo "You are  installing a new configuration"
236        ind=0
237        . ${COMPIL_DIR}/Fread_dir.sh OPA_SRC     YES
238        . ${COMPIL_DIR}/Fread_dir.sh LIM_SRC_2   YES
239        . ${COMPIL_DIR}/Fread_dir.sh LIM_SRC_3   NO 
240        . ${COMPIL_DIR}/Fread_dir.sh TOP_SRC     NO 
241        . ${COMPIL_DIR}/Fread_dir.sh NST_SRC     YES
242        . ${COMPIL_DIR}/Fread_dir.sh OFF_SRC     NO 
243        REF_CONF=ORCA2_LIM
244    elif [ ${#NEM_SUBDIR} -gt 0 ] && [ ${#REF_CONF} -eq 0 ]; then
245        echo "You are  installing a new configuration"
246        TAB=( ${NEM_SUBDIR} )
247        REF_CONF=ORCA2_LIM
248    elif [ ${#NEM_SUBDIR} -eq 0 ] && [ ${#REF_CONF} -gt 0 ]; then
249        echo "You are  installing a new configuration based on ${REF_CONF}"
250        . ${COMPIL_DIR}/Fcopy_dir.sh ${REF_CONF} 
251    fi
252    NEW_CONF=${x_n}
253    . ${COMPIL_DIR}/Fmake_config.sh ${NEW_CONF} ${REF_CONF}
254else
255    sed -e "/${NEW_CONF} /d"  ${CONFIG_DIR}/cfg.txt >  ${COMPIL_DIR}/cfg.tmp
256    \m${COMPIL_DIR}/cfg.tmp  ${CONFIG_DIR}/cfg.txt
257fi
258
259#-
260#- Save new configuration and directories names ---
261echo ${NEW_CONF} ${TAB[*]} >> ${CONFIG_DIR}/cfg.txt
262
263#-
264#- Create the WORK ---
265#- Clean links and librairies ---
266#- Creating the good links, at first on OPA_SRC ---
267. ${COMPIL_DIR}/Fmake_WORK.sh ${x_e} ${NEW_CONF} ${TAB[*]} || exit
268
269. ${COMPIL_DIR}/Fmake_bld.sh ${CONFIG_DIR} ${NEW_CONF}  ${NEMO_TDIR} || exit
270
271#- At this stage new configuration has been added,
272#- We add or remove keys
273if [ ${#list_add_key} -ne 0 ] ; then
274    . ${COMPIL_DIR}/Fadd_keys.sh ${NEW_CONF} add_key ${list_add_key} 
275fi
276
277if [ ${#list_del_key} -ne 0 ] ; then
278    . ${COMPIL_DIR}/Fdel_keys.sh ${NEW_CONF} del_key ${list_del_key}
279fi
280
281#- At this stage the configuration has beeen chosen
282#- We coose the default light file
283export USEBLD=bldxioxag.cfg
284
285#- We look after agrif
286grep key_agrif ${COMPIL_DIR}/cpp.fcm && export AGRIFUSE=1 && export USEBLD=${USEBLD/xag/}
287. ${COMPIL_DIR}/Fprep_agrif.sh ${NEW_CONF} ${NEMO_TDIR} || exit
288
289#- and test whether we need to build the ioserver
290grep key_iomput ${COMPIL_DIR}/cpp.fcm && export USEBLD=${USEBLD/xio/}
291
292#-
293#_ END OF CONFIGURATION PHASE
294#_
295
296#-
297#- Compile ---
298
299if [ "${NBR_PRC}" -gt 0 ]; then
300    cd ${NEMO_TDIR}/${NEW_CONF} || cd -
301
302#if AGRIF we do a first preprocessing
303    if [ ${#x_c} -eq 0 ]; then
304        [ "$AGRIFUSE" == 1 ] && fcm build --ignore-lock -s 2 ${COMPIL_DIR}/$USEBLD
305        [ "$AGRIFUSE" == 1 ] && rm -rf  ${NEMO_TDIR}/${NEW_CONF}/BLD/*
306    fi
307    fcm build ${x_c} --ignore-lock -v ${x_v} -j ${NBR_PRC} ${COMPIL_DIR}/$USEBLD || cd -
308    [ -f ${NEMO_TDIR}/${NEW_CONF}/BLD/bin/nemo.exe ] && ln -sf ${NEMO_TDIR}/${NEW_CONF}/BLD/bin/nemo.exe  ${CONFIG_DIR}/${NEW_CONF}/EXP00/opa
309    [ -f ${NEMO_TDIR}/${NEW_CONF}/BLD/bin/server.exe ] && ln -sf ${NEMO_TDIR}/${NEW_CONF}/BLD/bin/server.exe  ${CONFIG_DIR}/${NEW_CONF}/EXP00/server.exe
310
311#add remove for clean option
312    if  [ ${#x_c} -ne 0 ]; then
313        rm -rf ${NEMO_TDIR}/${NEW_CONF}/WORK
314        rm -rf ${NEMO_TDIR}/${NEW_CONF}/BLD
315        rm -rf ${NEMO_TDIR}/${NEW_CONF}/EXP00/opa
316        rm -rf ${NEMO_TDIR}/${NEW_CONF}/EXP00/server.exe
317        echo "cleaning ${NEW_CONF} WORK, BLD"
318    fi
319
320fi
321
322#- Come back to original directory ---
323cd -
324
325#-
326#- Unset variables
327${COMPIL_DIR}/Fclean_var.sh
328
329
Note: See TracBrowser for help on using the repository browser.