1 | #!/bin/bash |
---|
2 | #set -x |
---|
3 | set -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 from |
---|
41 | # - CMP_NAM : compiler name |
---|
42 | # - NBR_PRC : number of processes used to compile |
---|
43 | # - USP_CONF : unsupported (external) configuration to build the new one from |
---|
44 | # - NEM_SUBDIR : NEMO subdirectory used (specified) |
---|
45 | # |
---|
46 | # Locally defined : |
---|
47 | # |
---|
48 | # - TAB : NEMO subdirectory used (read) |
---|
49 | # - MAIN_DIR : self explaining |
---|
50 | # - CONFIG_DIR : " " " |
---|
51 | # - MODELES_DIR : " " " |
---|
52 | # - TOOLS_DIR : " " " |
---|
53 | # - NEMO_DIR : " " " |
---|
54 | # - REMOTE_CTL : URL link to a remote resource list for an external configuration |
---|
55 | # which is not part of the reference suite |
---|
56 | # - LOCAL_REF : Nearest reference configuration to an external configuration |
---|
57 | # which is not part of the reference suite |
---|
58 | # (used to populate work directories if remote access is not available) |
---|
59 | # |
---|
60 | # EXAMPLES |
---|
61 | # ======== |
---|
62 | # |
---|
63 | # :: |
---|
64 | # |
---|
65 | # $ ./makenemo -m ifort_osx - j3 -n ORCA2_LIM3_PISCES |
---|
66 | # |
---|
67 | # |
---|
68 | # TODO |
---|
69 | # ==== |
---|
70 | # |
---|
71 | # option debug |
---|
72 | # |
---|
73 | # |
---|
74 | # EVOLUTIONS |
---|
75 | # ========== |
---|
76 | # |
---|
77 | # $Id$ |
---|
78 | # |
---|
79 | # |
---|
80 | # |
---|
81 | # * creation |
---|
82 | # |
---|
83 | #- |
---|
84 | |
---|
85 | #- |
---|
86 | #- Initialization of the options --- |
---|
87 | x_d=""; |
---|
88 | x_h=""; |
---|
89 | x_n=""; |
---|
90 | x_r=""; |
---|
91 | x_u=""; |
---|
92 | x_a=""; |
---|
93 | x_m=""; |
---|
94 | x_t=""; |
---|
95 | x_c=""; |
---|
96 | x_j=1; |
---|
97 | x_e="none"; |
---|
98 | x_s=NEMO; |
---|
99 | x_v=1; |
---|
100 | |
---|
101 | #- Local variables --- |
---|
102 | b_n=$(basename ${0}) |
---|
103 | OPTIND=1 |
---|
104 | MAIN_DIR=$(cd $(dirname "$0"); pwd) |
---|
105 | MAIN_DIR=${MAIN_DIR%/SETTE*} |
---|
106 | MAIN_DIR=${MAIN_DIR%/TOOLS*} |
---|
107 | MAIN_DIR=${MAIN_DIR%/CONFIG*} |
---|
108 | export MAIN_DIR |
---|
109 | # |
---|
110 | export CONFIG_DIR=${MAIN_DIR}/CONFIG |
---|
111 | export TOOLS_DIR=${MAIN_DIR}/TOOLS |
---|
112 | export COMPIL_DIR=${MAIN_DIR}/TOOLS/COMPILE |
---|
113 | export NEMO_DIR=${MAIN_DIR}/${x_s} |
---|
114 | export AGRIFUSE=10 |
---|
115 | declare -a TAB |
---|
116 | declare -a REMOTE_CTL |
---|
117 | declare -a LOCAL_REF |
---|
118 | list_key=0 |
---|
119 | chk_key=1 |
---|
120 | #- |
---|
121 | #- FCM and functions location --- |
---|
122 | export PATH=${MAIN_DIR}/EXTERNAL/fcm/bin:$PATH |
---|
123 | |
---|
124 | #- |
---|
125 | #- Choice of the options --- |
---|
126 | while getopts :hd:n:r:u:a:m:j:e:s:v:t:k: V |
---|
127 | do |
---|
128 | case $V in |
---|
129 | (h) x_h=${OPTARG}; |
---|
130 | echo "Usage : "${b_n} \ |
---|
131 | " [-h] [-n name] [-m arch] [-d "dir1 dir2"] [-r conf] [-u conf] [-s Path] [-e Path] [-j No] [-v No] [-k 0/1]"; |
---|
132 | echo " -h : help"; |
---|
133 | echo " -h institute : specific help for consortium members"; |
---|
134 | echo " -n name : config name, [-n help] to list existing configurations"; |
---|
135 | echo " -m arch : choose compiler, [-m help] to list existing compilers"; |
---|
136 | echo " -d dir : choose NEMO sub-directories"; |
---|
137 | echo " -r conf : choose reference configuration"; |
---|
138 | echo " -u conf : choose an unsupported (external) configuration"; |
---|
139 | echo " -s Path : choose alternative location for NEMO main directory"; |
---|
140 | echo " -e Path : choose alternative location for MY_SRC directory"; |
---|
141 | echo " -j No : number of processes used to compile (0=nocompilation)"; |
---|
142 | echo " -v No : set verbosity level for compilation [0-3]"; |
---|
143 | echo " -k 0/1 : used cpp keys check (default = 1 -> check activated)"; |
---|
144 | echo " -t dir : temporary directory for compilation" |
---|
145 | echo " -a dir : alternative sub-directory for configurations (below CONFIG)" |
---|
146 | echo ""; |
---|
147 | echo "Example to install a new configuration MY_CONFIG"; |
---|
148 | echo "with OPA_SRC and LIM_SRC_2 "; |
---|
149 | echo "makenemo -n MY_CONFIG -d \"OPA_SRC LIM_SRC_2\""; |
---|
150 | echo ""; |
---|
151 | echo "Available configurations :"; cat ${CONFIG_DIR}/cfg.txt; |
---|
152 | echo ""; |
---|
153 | echo "Available unsupported (external) configurations :"; |
---|
154 | if [ -f ${CONFIG_DIR}/uspcfg.txt ] ; then cat ${CONFIG_DIR}/uspcfg.txt; fi; |
---|
155 | echo ""; |
---|
156 | echo "Example to install an unsupoorted configuration MY_USP"; |
---|
157 | echo "makenemo -n MY_USP -u MY_USP" ; |
---|
158 | echo ""; |
---|
159 | echo "Example to remove bad configuration "; |
---|
160 | echo "./makenemo -n MY_CONFIG clean_config"; |
---|
161 | echo ""; |
---|
162 | echo "Example to clean "; |
---|
163 | echo "./makenemo clean"; |
---|
164 | echo ""; |
---|
165 | echo "Example to list the available keys of a CONFIG "; |
---|
166 | echo "./makenemo list_key"; |
---|
167 | echo ""; |
---|
168 | echo "Example to add and remove keys"; |
---|
169 | echo "./makenemo add_key \"key_iomput key_mpp_mpi\" del_key \"key_agrif\" "; |
---|
170 | echo ""; |
---|
171 | echo "Example to add and remove keys for a new configuration, and do not compile"; |
---|
172 | echo "./makenemo -n MY_CONFIG -j0 add_key \"key_iomput key_mpp_mpi\" del_key \"key_agrif\" "; |
---|
173 | echo ""; |
---|
174 | . ${COMPIL_DIR}/Flist_archfile.sh ${x_h} ; |
---|
175 | echo ""; |
---|
176 | echo "Default : previous configuration and compiler"; |
---|
177 | exit 0;; |
---|
178 | (d) x_d=${OPTARG};; |
---|
179 | (n) x_n=${OPTARG};; |
---|
180 | (r) x_r=${OPTARG};; |
---|
181 | (u) x_u=${OPTARG};; |
---|
182 | (a) x_a=${OPTARG};; |
---|
183 | (m) x_m=${OPTARG};; |
---|
184 | (j) x_j=${OPTARG};; |
---|
185 | (t) x_t=${OPTARG};; |
---|
186 | (e) x_e=${OPTARG};; |
---|
187 | (s) x_s=${OPTARG};; |
---|
188 | (v) x_v=${OPTARG};; |
---|
189 | (k) chk_key=${OPTARG};; |
---|
190 | (:) echo ${b_n}" : -"${OPTARG}" option : missing value" 1>&2; |
---|
191 | exit 2;; |
---|
192 | (\?) echo ${b_n}" : -"${OPTARG}" option : not supported" 1>&2; |
---|
193 | exit 2;; |
---|
194 | esac |
---|
195 | done |
---|
196 | shift $(($OPTIND-1)); |
---|
197 | |
---|
198 | while [ ${#1} -gt 0 ] # Get clean, clean_config options |
---|
199 | do |
---|
200 | case "$1" in |
---|
201 | clean) |
---|
202 | x_c="--$1" |
---|
203 | ;; |
---|
204 | clean_config) |
---|
205 | . ${COMPIL_DIR}/Fclean_config.sh |
---|
206 | exit |
---|
207 | ;; |
---|
208 | add_key) |
---|
209 | # Checking if argument has anything other than whitespace |
---|
210 | [[ ! "$2" =~ ^\ +$ ]] && { list_add_key=$2; export ${list_add_key}; } |
---|
211 | shift |
---|
212 | ;; |
---|
213 | del_key) |
---|
214 | # Checking if argument has anything other than whitespace |
---|
215 | [[ ! "$2" =~ ^\ +$ ]] && { list_del_key=$2; export ${list_del_key}; } |
---|
216 | shift |
---|
217 | ;; |
---|
218 | list_key) |
---|
219 | list_key=1 |
---|
220 | ;; |
---|
221 | *) |
---|
222 | echo " \"$1\" BAD OPTION" |
---|
223 | exit |
---|
224 | ;; |
---|
225 | |
---|
226 | esac |
---|
227 | shift |
---|
228 | done |
---|
229 | |
---|
230 | |
---|
231 | #- |
---|
232 | #- Go to NEMOGCM/CONFIG directory --- |
---|
233 | cd ${CONFIG_DIR} |
---|
234 | |
---|
235 | #- |
---|
236 | #- Initialisation from input --- |
---|
237 | export ALT_DIR=${x_a} |
---|
238 | if [ ! -z $ALT_DIR ]; then |
---|
239 | if [ -d ${CONFIG_DIR}/${ALT_DIR} ]; then |
---|
240 | export CONFIG_DIR=${CONFIG_DIR}/${ALT_DIR} |
---|
241 | #- |
---|
242 | #- Go to named subdirectory of the NEMOGCM/CONFIG directory --- |
---|
243 | cd ${CONFIG_DIR} |
---|
244 | fi |
---|
245 | fi |
---|
246 | export NEW_CONF=${x_n} |
---|
247 | NBR_PRC=${x_j} |
---|
248 | CMP_NAM=${x_m} |
---|
249 | NEM_SUBDIR=${x_d} |
---|
250 | REF_CONF=${x_r} |
---|
251 | USP_CONF=${x_u} |
---|
252 | NEMO_TDIR=${x_t} |
---|
253 | export NEMO_TDIR=${NEMO_TDIR:-$CONFIG_DIR} |
---|
254 | export NEMO_DIR=${MAIN_DIR}/${x_s} |
---|
255 | |
---|
256 | #- Check if the tool or the compiler exist or list it |
---|
257 | if [ "${NEW_CONF}" == help ] ; then |
---|
258 | echo "Available configurations :" |
---|
259 | cat ${CONFIG_DIR}/cfg.txt |
---|
260 | echo |
---|
261 | echo "Available unsupported (external) configurations :" |
---|
262 | if [ -f ${CONFIG_DIR}/uspcfg.txt ] ; then cat ${CONFIG_DIR}/uspcfg.txt; fi; |
---|
263 | exit |
---|
264 | fi |
---|
265 | [ "${CMP_NAM}" == help ] && . ${COMPIL_DIR}/Flist_archfile.sh all && exit |
---|
266 | |
---|
267 | #- |
---|
268 | #- Choose a default configuration if needed --- |
---|
269 | #- ORCA2_LIM3_PISCES or last one used --- |
---|
270 | . ${COMPIL_DIR}/Fcheck_config.sh cfg.txt ${NEW_CONF} || exit |
---|
271 | |
---|
272 | if [ ${#NEW_CONF} -eq 0 ] ; then |
---|
273 | if [ ${#NEM_SUBDIR} -eq 0 ] && [ ${#REF_CONF} -eq 0 ] && [ ${#USP_CONF} -eq 0 ] ; then |
---|
274 | echo "You are installing a new default (ORCA2_LIM3_PISCES) configuration" |
---|
275 | ind=0 |
---|
276 | . ${COMPIL_DIR}/Fread_dir.sh OPA_SRC YES |
---|
277 | . ${COMPIL_DIR}/Fread_dir.sh LIM_SRC_2 YES |
---|
278 | . ${COMPIL_DIR}/Fread_dir.sh LIM_SRC_3 NO |
---|
279 | . ${COMPIL_DIR}/Fread_dir.sh TOP_SRC NO |
---|
280 | . ${COMPIL_DIR}/Fread_dir.sh NST_SRC YES |
---|
281 | . ${COMPIL_DIR}/Fread_dir.sh OFF_SRC NO |
---|
282 | . ${COMPIL_DIR}/Fread_dir.sh SAO_SRC NO |
---|
283 | . ${COMPIL_DIR}/Fread_dir.sh SAS_SRC NO |
---|
284 | REF_CONF=ORCA2_LIM3_PISCES |
---|
285 | elif [ ${#NEM_SUBDIR} -gt 0 ] && [ ${#REF_CONF} -eq 0 ] && [ ${#USP_CONF} -eq 0 ] ; then |
---|
286 | echo "You are installing a new configuration based on ORCA2_LIM3_PISCES" |
---|
287 | TAB=( ${NEM_SUBDIR} ) |
---|
288 | REF_CONF=ORCA2_LIM3_PISCES |
---|
289 | elif [ ${#NEM_SUBDIR} -eq 0 ] && [ ${#REF_CONF} -gt 0 ]; then |
---|
290 | echo "You are installing a new configuration based on ${REF_CONF}" |
---|
291 | . ${COMPIL_DIR}/Fcopy_dir.sh ${REF_CONF} |
---|
292 | elif [ ${#NEM_SUBDIR} -gt 0 ] && [ ${#REF_CONF} -gt 0 ]; then |
---|
293 | echo "You are installing an hydrid configuration based on ${REF_CONF} with components ${NEM_SUBDIR}" |
---|
294 | . ${COMPIL_DIR}/Fcopy_dir.sh ${REF_CONF} |
---|
295 | TAB=( ${NEM_SUBDIR} ) |
---|
296 | elif [ ${#NEM_SUBDIR} -eq 0 ] && [ ${#USP_CONF} -gt 0 ]; then |
---|
297 | echo "You are installing a new configuration based on the unsupported (external) ${USP_CONF}" |
---|
298 | . ${COMPIL_DIR}/Fcopy_extdir.sh ${USP_CONF} |
---|
299 | #echo "TTT " ${TAB} |
---|
300 | #echo "RRR " ${REMOTE_CTL} |
---|
301 | #echo "LLL " ${LOCAL_REF} |
---|
302 | fi |
---|
303 | NEW_CONF=${x_n} |
---|
304 | |
---|
305 | if [ ${#USP_CONF} -gt 0 ]; then |
---|
306 | . ${COMPIL_DIR}/Fmake_extconfig.sh ${NEW_CONF} ${LOCAL_REF} |
---|
307 | . ${COMPIL_DIR}/Ffetch_extdir.sh ${NEW_CONF} ${REMOTE_CTL} |
---|
308 | else |
---|
309 | . ${COMPIL_DIR}/Fmake_config.sh ${NEW_CONF} ${REF_CONF} |
---|
310 | fi |
---|
311 | else |
---|
312 | sed -e "/${NEW_CONF} /d" ${CONFIG_DIR}/cfg.txt > ${COMPIL_DIR}/cfg.tmp |
---|
313 | \mv ${COMPIL_DIR}/cfg.tmp ${CONFIG_DIR}/cfg.txt |
---|
314 | fi |
---|
315 | |
---|
316 | #- |
---|
317 | #- Save new configuration and directories names --- |
---|
318 | echo ${NEW_CONF} ${TAB[*]} >> ${CONFIG_DIR}/cfg.txt |
---|
319 | |
---|
320 | #- |
---|
321 | #- Create the WORK --- |
---|
322 | #- Clean links and librairies --- |
---|
323 | #- Creating the good links, at first on OPA_SRC --- |
---|
324 | . ${COMPIL_DIR}/Fmake_WORK.sh ${x_e} ${NEW_CONF} ${TAB[*]} || exit |
---|
325 | |
---|
326 | . ${COMPIL_DIR}/Fmake_bld.sh ${CONFIG_DIR} ${NEW_CONF} ${NEMO_TDIR} || exit |
---|
327 | |
---|
328 | # build the complete list of the cpp keys of this configuration |
---|
329 | if [ $chk_key -eq 1 ] ; then |
---|
330 | for i in $( grep "^ *#.* key_" ${NEW_CONF}/WORK/* ) |
---|
331 | do |
---|
332 | echo $i | grep key_ | sed -e "s/=.*//" |
---|
333 | done | sort -d | uniq > ${COMPIL_DIR}/full_key_list.txt |
---|
334 | if [ $list_key -eq 1 ]; then |
---|
335 | cat ${COMPIL_DIR}/full_key_list.txt |
---|
336 | exit 0 |
---|
337 | fi |
---|
338 | fi |
---|
339 | |
---|
340 | #- At this stage new configuration has been added, we add or remove keys |
---|
341 | [ ! -z "${list_add_key}" ] && { . ${COMPIL_DIR}/Fadd_keys.sh ${NEW_CONF} add_key ${list_add_key}; } |
---|
342 | [ ! -z "${list_del_key}" ] && { . ${COMPIL_DIR}/Fdel_keys.sh ${NEW_CONF} del_key ${list_del_key}; } |
---|
343 | |
---|
344 | #- check that all keys are really existing... |
---|
345 | if [ $chk_key -eq 1 ] ; then |
---|
346 | for kk in $( cat ${NEW_CONF}/cpp_${NEW_CONF}.fcm ) |
---|
347 | do |
---|
348 | if [ "$( echo $kk | cut -c 1-4 )" == "key_" ]; then |
---|
349 | kk=${kk/=*/} |
---|
350 | nb=$( grep -c $kk ${COMPIL_DIR}/full_key_list.txt ) |
---|
351 | if [ $nb -eq 0 ]; then |
---|
352 | echo |
---|
353 | echo "E R R O R : key "$kk" is not found in ${NEW_CONF}/WORK routines..." |
---|
354 | echo "we stop..." |
---|
355 | echo |
---|
356 | exit 1 |
---|
357 | fi |
---|
358 | fi |
---|
359 | done |
---|
360 | fi |
---|
361 | |
---|
362 | #- At this stage cpp keys have been updated. we can check the arch file |
---|
363 | #- When used for the first time, choose a compiler --- |
---|
364 | . ${COMPIL_DIR}/Fcheck_archfile.sh arch_nemo.fcm cpp.fcm ${CMP_NAM} || exit |
---|
365 | |
---|
366 | #- At this stage the configuration has beeen chosen |
---|
367 | #- We coose the default light file |
---|
368 | export USEBLD=bldxag.cfg |
---|
369 | |
---|
370 | #- We look after agrif |
---|
371 | grep key_agrif ${COMPIL_DIR}/cpp.fcm && export AGRIFUSE=1 && export USEBLD=${USEBLD/xag/} |
---|
372 | . ${COMPIL_DIR}/Fprep_agrif.sh ${NEW_CONF} ${NEMO_TDIR} || exit |
---|
373 | |
---|
374 | #- |
---|
375 | #_ END OF CONFIGURATION PHASE |
---|
376 | #_ |
---|
377 | |
---|
378 | #- |
---|
379 | #- Compile --- |
---|
380 | |
---|
381 | if [ "${NBR_PRC}" -gt 0 ]; then |
---|
382 | cd ${NEMO_TDIR}/${NEW_CONF} || cd - |
---|
383 | |
---|
384 | #if AGRIF we do a first preprocessing |
---|
385 | if [ ${#x_c} -eq 0 ]; then |
---|
386 | if [ "$AGRIFUSE" == 1 ]; then |
---|
387 | fcm build --ignore-lock -j 1 ${COMPIL_DIR}/bld_preproagr.cfg ||{ cd - ; exit ;} |
---|
388 | echo "" |
---|
389 | echo "---------------------------------" |
---|
390 | echo "CONV preprocessing successfull !!" |
---|
391 | echo "---------------------------------" |
---|
392 | echo "" |
---|
393 | fi |
---|
394 | fi |
---|
395 | fcm build ${x_c} --ignore-lock -v ${x_v} -j ${NBR_PRC} ${COMPIL_DIR}/$USEBLD || cd - |
---|
396 | [ -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 |
---|
397 | |
---|
398 | #add remove for clean option |
---|
399 | if [ ${#x_c} -ne 0 ]; then |
---|
400 | rm -rf ${NEMO_TDIR}/${NEW_CONF}/OPAFILES |
---|
401 | rm -rf ${NEMO_TDIR}/${NEW_CONF}/WORK |
---|
402 | rm -rf ${NEMO_TDIR}/${NEW_CONF}/BLD |
---|
403 | rm -rf ${NEMO_TDIR}/${NEW_CONF}/EXP00/opa |
---|
404 | rm -f ${COMPIL_DIR}/*history ${COMPIL_DIR}/*fcm ${COMPIL_DIR}/*txt |
---|
405 | echo "cleaning ${NEW_CONF} WORK, BLD" |
---|
406 | fi |
---|
407 | |
---|
408 | fi |
---|
409 | |
---|
410 | #- Come back to original directory --- |
---|
411 | cd - |
---|
412 | |
---|
413 | #- |
---|
414 | #- Unset variables |
---|
415 | ${COMPIL_DIR}/Fclean_var.sh |
---|
416 | |
---|
417 | |
---|