source: NEMO/branches/NERC/dev_release-3.4_NEMOTAM_consolidated/NEMOGCM/CONFIG/makenemo @ 11809

Last change on this file since 11809 was 3722, checked in by rblod, 9 years ago

Submission of dev_r3604_LEGI8_TAM merge branch - See Ticket #1035

  • Property svn:executable set to *
  • Property svn:keywords set to Id
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$
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   . ${COMPIL_DIR}/Fread_dir.sh OPATAM_SRC    NO
244   REF_CONF=ORCA2_LIM
245    elif [ ${#NEM_SUBDIR} -gt 0 ] && [ ${#REF_CONF} -eq 0 ]; then
246   echo "You are  installing a new configuration"
247   TAB=( ${NEM_SUBDIR} )
248   REF_CONF=ORCA2_LIM
249    elif [ ${#NEM_SUBDIR} -eq 0 ] && [ ${#REF_CONF} -gt 0 ]; then
250   echo "You are  installing a new configuration based on ${REF_CONF}"
251   . ${COMPIL_DIR}/Fcopy_dir.sh ${REF_CONF}
252    fi
253    NEW_CONF=${x_n}
254    . ${COMPIL_DIR}/Fmake_config.sh ${NEW_CONF} ${REF_CONF}
255else
256    sed -e "/${NEW_CONF} /d"  ${CONFIG_DIR}/cfg.txt >  ${COMPIL_DIR}/cfg.tmp
257    \m${COMPIL_DIR}/cfg.tmp  ${CONFIG_DIR}/cfg.txt
258fi
259
260#-
261#- Save new configuration and directories names ---
262echo ${NEW_CONF} ${TAB[*]} >> ${CONFIG_DIR}/cfg.txt
263
264#-
265#- Create the WORK ---
266#- Clean links and librairies ---
267#- Creating the good links, at first on OPA_SRC ---
268. ${COMPIL_DIR}/Fmake_WORK.sh ${x_e} ${NEW_CONF} ${TAB[*]} || exit
269
270. ${COMPIL_DIR}/Fmake_bld.sh ${CONFIG_DIR} ${NEW_CONF}  ${NEMO_TDIR} || exit
271
272#- At this stage new configuration has been added,
273#- We add or remove keys
274if [ ${#list_add_key} -ne 0 ] ; then
275    . ${COMPIL_DIR}/Fadd_keys.sh ${NEW_CONF} add_key ${list_add_key}
276fi
277
278if [ ${#list_del_key} -ne 0 ] ; then
279    . ${COMPIL_DIR}/Fdel_keys.sh ${NEW_CONF} del_key ${list_del_key}
280fi
281
282#- At this stage the configuration has beeen chosen
283#- We coose the default light file
284export USEBLD=bldxioxag.cfg
285
286#- We look after agrif
287grep key_agrif ${COMPIL_DIR}/cpp.fcm && export AGRIFUSE=1 && export USEBLD=${USEBLD/xag/}
288. ${COMPIL_DIR}/Fprep_agrif.sh ${NEW_CONF} ${NEMO_TDIR} || exit
289
290#- and test whether we need to build the ioserver
291grep key_iomput ${COMPIL_DIR}/cpp.fcm && export USEBLD=${USEBLD/xio/}
292grep key_tam ${COMPIL_DIR}/cpp.fcm && export USEBLD=${USEBLD/xioxag/tam}
293
294#-
295#_ END OF CONFIGURATION PHASE
296#_
297
298#-
299#- Compile ---
300
301if [ "${NBR_PRC}" -gt 0 ]; then
302    cd ${NEMO_TDIR}/${NEW_CONF} || cd -
303
304#if AGRIF we do a first preprocessing
305    if [ ${#x_c} -eq 0 ]; then
306        [ "$AGRIFUSE" == 1 ] && fcm build --ignore-lock -s 2 ${COMPIL_DIR}/$USEBLD
307        [ "$AGRIFUSE" == 1 ] && rm -rf  ${NEMO_TDIR}/${NEW_CONF}/BLD/*
308    fi
309    fcm build ${x_c} --ignore-lock -v ${x_v} -j ${NBR_PRC} ${COMPIL_DIR}/$USEBLD || cd -
310    [ -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
311    [ -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
312
313#add remove for clean option
314    if  [ ${#x_c} -ne 0 ]; then
315        rm -rf ${NEMO_TDIR}/${NEW_CONF}/WORK
316        rm -rf ${NEMO_TDIR}/${NEW_CONF}/BLD
317        rm -rf ${NEMO_TDIR}/${NEW_CONF}/EXP00/opa
318        rm -rf ${NEMO_TDIR}/${NEW_CONF}/EXP00/server.exe
319        echo "cleaning ${NEW_CONF} WORK, BLD"
320    fi
321
322fi
323
324#- Come back to original directory ---
325cd -
326
327#-
328#- Unset variables
329${COMPIL_DIR}/Fclean_var.sh
330
331
Note: See TracBrowser for help on using the repository browser.