1 | #!/bin/bash |
---|
2 | #set -x |
---|
3 | set -o posix |
---|
4 | #set -u |
---|
5 | #set -e |
---|
6 | #+ |
---|
7 | # |
---|
8 | # =============== |
---|
9 | # makenemo_fcm.sh |
---|
10 | # =============== |
---|
11 | # |
---|
12 | # -------------------------- |
---|
13 | # Compile NEMO |
---|
14 | # -------------------------- |
---|
15 | # |
---|
16 | # SYNOPSIS |
---|
17 | # ======== |
---|
18 | # |
---|
19 | # :: |
---|
20 | # |
---|
21 | # $ makenemo_fcm.sh |
---|
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_fcm -t 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 | # - rblod 2010-06-20T16:11:47Z |
---|
75 | # |
---|
76 | # * creation |
---|
77 | # |
---|
78 | #- |
---|
79 | |
---|
80 | #- Local variables --- |
---|
81 | b_n=$(basename ${0}) |
---|
82 | export MAIN_DIR=${PWD%/NEMOGCM*}/NEMOGCM |
---|
83 | export CONFIG_DIR=${MAIN_DIR}/CONFIG |
---|
84 | export TOOLS_DIR=${MAIN_DIR}/TOOLS |
---|
85 | export NEMO_DIR=${MAIN_DIR}/NEMO |
---|
86 | export AGRIFUSE=10 |
---|
87 | declare -a TAB |
---|
88 | #- |
---|
89 | #- FCM and functions location --- |
---|
90 | export PATH=${MAIN_DIR}/EXTERNAL/fcm/bin:$PATH |
---|
91 | |
---|
92 | #- |
---|
93 | #- Choice of the options --- |
---|
94 | x_d=""; |
---|
95 | x_n=""; |
---|
96 | x_r=""; |
---|
97 | x_m=""; |
---|
98 | x_t=""; |
---|
99 | x_j=1; |
---|
100 | while getopts :hld:n:r:m:j:t: V |
---|
101 | do |
---|
102 | case $V in |
---|
103 | (h) echo "Usage : "${b_n} \ |
---|
104 | " [-h] [-l] [-n name] [-m arch] [-d "dir1 dir2"] [-r conf] [-j No]"; |
---|
105 | echo " -h : help"; |
---|
106 | echo " -l : list existing configurations"; |
---|
107 | echo " -n name : config name"; |
---|
108 | echo " -m arch : choose machine"; |
---|
109 | echo " -d dir : choose NEMO sub-directories"; |
---|
110 | echo " -r conf : choose reference configuration"; |
---|
111 | echo " -j No : number of processes used to compile (0=nocompilation)"; |
---|
112 | echo " -t dir : remporary directory for compilation" |
---|
113 | echo ""; |
---|
114 | echo "Example to install a new configuration MY_CONFIG"; |
---|
115 | echo "with OPA_SRC and LIM_SRC_2 "; |
---|
116 | echo "makenemo_fcm -n MY_CONFIG -d \"OPA_SRC LIM_SRC_2\""; |
---|
117 | echo ""; |
---|
118 | echo "Defaults : "; |
---|
119 | echo ""; |
---|
120 | exit 0;; |
---|
121 | (d) x_d=${OPTARG};; |
---|
122 | (n) x_n=${OPTARG};; |
---|
123 | (r) x_r=${OPTARG};; |
---|
124 | (m) x_m=${OPTARG};; |
---|
125 | (j) x_j=${OPTARG};; |
---|
126 | (t) x_t=${OPTARG};; |
---|
127 | (l) echo "Available configurations :"; cat ${TOOLS_DIR}/cfg.txt; exit;; |
---|
128 | (:) echo ${b_n}" : -"${OPTARG}" option : missing value" 1>&2; |
---|
129 | exit 2;; |
---|
130 | (\?) echo ${b_n}" : -"${OPTARG}" option : not supported" 1>&2; |
---|
131 | exit 2;; |
---|
132 | esac |
---|
133 | done |
---|
134 | shift $(($OPTIND-1)); |
---|
135 | |
---|
136 | #- |
---|
137 | #- Go to NEMOGCM/config directory --- |
---|
138 | cd ${CONFIG_DIR} |
---|
139 | |
---|
140 | #- |
---|
141 | #- Initialisation from input --- |
---|
142 | export NEW_CONF=${x_n} |
---|
143 | NBR_PRC=${x_j} |
---|
144 | CMP_NAM=${x_m} |
---|
145 | NEM_SUBDIR=${x_d} |
---|
146 | REF_CONF=${x_r} |
---|
147 | NEMO_TDIR=${x_t:-$NEMO_TDIR} |
---|
148 | export NEMO_TDIR=${NEMO_TDIR:-$CONFIG_DIR} |
---|
149 | |
---|
150 | #- When used for the first time, choose a compiler --- |
---|
151 | . ${TOOLS_DIR}/Fcheck_archfile.sh ${CMP_NAM} || exit |
---|
152 | |
---|
153 | #- |
---|
154 | #- Choose a default configuration if needed --- |
---|
155 | #- ORCA2_LIM or last one used --- |
---|
156 | . ${TOOLS_DIR}/Fcheck_config.sh ${NEW_CONF} || exit |
---|
157 | |
---|
158 | if [ ${#NEW_CONF} -eq 0 ] ; then |
---|
159 | if [ ${#NEM_SUBDIR} -eq 0 -a ${#REF_CONF} -eq 0 ]; then |
---|
160 | echo "You are installing a new configuration" |
---|
161 | ind=0 |
---|
162 | . ${TOOLS_DIR}/Fread_dir.sh OPA_SRC YES |
---|
163 | . ${TOOLS_DIR}/Fread_dir.sh LIM_SRC_2 YES |
---|
164 | . ${TOOLS_DIR}/Fread_dir.sh LIM_SRC_3 NO |
---|
165 | . ${TOOLS_DIR}/Fread_dir.sh TOP_SRC NO |
---|
166 | . ${TOOLS_DIR}/Fread_dir.sh C1D_SRC YES |
---|
167 | . ${TOOLS_DIR}/Fread_dir.sh NST_SRC YES |
---|
168 | . ${TOOLS_DIR}/Fread_dir.sh OFF_SRC NO |
---|
169 | REF_CONF=ORCA2_LIM |
---|
170 | elif [ ${#NEM_SUBDIR} -gt 0 ] && [ ${#REF_CONF} -eq 0 ]; then |
---|
171 | echo "You are installing a new configuration" |
---|
172 | TAB=( ${NEM_SUBDIR} ) |
---|
173 | REF_CONF=ORCA2_LIM |
---|
174 | elif [ ${#NEM_SUBDIR} -eq 0 ] && [ ${#REF_CONF} -gt 0 ]; then |
---|
175 | echo "You are installing a new configuration based on ${REF_CONF}" |
---|
176 | ${TOOLS_DIR}/Fcopy_dir.sh ${REF_CONF} |
---|
177 | fi |
---|
178 | NEW_CONF=${x_n} |
---|
179 | . ${TOOLS_DIR}/Fmake_config.sh ${NEW_CONF} ${REF_CONF} |
---|
180 | else |
---|
181 | sed -e "/${NEW_CONF} /d" ${TOOLS_DIR}/cfg.txt > ${TOOLS_DIR}/cfg.tmp |
---|
182 | \mv ${TOOLS_DIR}/cfg.tmp ${TOOLS_DIR}/cfg.txt |
---|
183 | fi |
---|
184 | |
---|
185 | #- |
---|
186 | #- Save new configuration and directories names --- |
---|
187 | echo ${NEW_CONF} ${TAB[*]} >> ${TOOLS_DIR}/cfg.txt |
---|
188 | |
---|
189 | #- |
---|
190 | #- Create the WORK --- |
---|
191 | #- Clean links and librairies --- |
---|
192 | #- Creating the good links, at first on OPA_SRC --- |
---|
193 | . ${TOOLS_DIR}/Fmake_WORK.sh ${NEW_CONF} ${TAB[*]} || exit |
---|
194 | |
---|
195 | . ${TOOLS_DIR}/Fmake_bld.sh ${NEW_CONF} ${NEMO_TDIR} || exit |
---|
196 | |
---|
197 | #- At this stage the configuration has beeen chosen |
---|
198 | #- We look after agrif |
---|
199 | grep key_agrif ${TOOLS_DIR}/cpp.fcm && export AGRIFUSE=1 |
---|
200 | . ${TOOLS_DIR}/Fprep_agrif.sh ${NEW_CONF} ${NEMO_TDIR} || exit |
---|
201 | |
---|
202 | #- |
---|
203 | #_ END OF CONFIGURATION PHASE |
---|
204 | #_ |
---|
205 | |
---|
206 | #- |
---|
207 | #- Compile --- |
---|
208 | |
---|
209 | if [ "${NBR_PRC}" -gt 0 ]; then |
---|
210 | cd ${NEMO_TDIR}/${NEW_CONF} || cd - |
---|
211 | |
---|
212 | #if AGRIF we do a first preprocessing |
---|
213 | [ "$AGRIFUSE" == 1 ] && fcm build --ignore-lock -s 2 ${TOOLS_DIR}/bld.cfg |
---|
214 | [ "$AGRIFUSE" == 1 ] && rm -rf ${NEMO_TDIR}/${NEW_CONF}/BLD/* |
---|
215 | fcm build --ignore-lock -v 1 -j ${NBR_PRC} ${TOOLS_DIR}/bld.cfg || cd - |
---|
216 | [ -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 |
---|
217 | fi |
---|
218 | |
---|
219 | #- |
---|
220 | #- Come back to original directory --- |
---|
221 | cd - |
---|
222 | |
---|
223 | #- |
---|
224 | #- Unset variables |
---|
225 | ${TOOLS_DIR}/Fclean_var.sh |
---|
226 | |
---|
227 | |
---|
228 | exit 0; |
---|