1 | #!/bin/ksh |
---|
2 | #- $Id$ |
---|
3 | #--------------------------------------------------------------------- |
---|
4 | # @(#)Actions concerning IPSL models |
---|
5 | #--------------------------------------------------------------------- |
---|
6 | #set -xv |
---|
7 | MAIL_ADDRESS=patricia.cadule@ipsl.jussieu.fr |
---|
8 | MAIL_COM=mail |
---|
9 | #MAIL_COM=Mail |
---|
10 | #- |
---|
11 | # Dirname and Basename |
---|
12 | #- |
---|
13 | d_n=${0%/*}; b_n=${0##*/}; |
---|
14 | #- |
---|
15 | # Retrieve and validate the options |
---|
16 | #- |
---|
17 | m_n=""; m_a="checkout"; m_v='silencious'; no_tag='false'; |
---|
18 | while getopts :hevH V |
---|
19 | do |
---|
20 | case $V in |
---|
21 | (h) m_a='help';; |
---|
22 | (e) m_a='checkout';; |
---|
23 | (v) m_v='verbose';; |
---|
24 | (H) no_tag='true';; |
---|
25 | (:) echo ${b_n}" : option $OPTARG : missing value" 1>&2; |
---|
26 | exit 2;; |
---|
27 | (\?) echo ${b_n}" : option $OPTARG : not supported" 1>&2; |
---|
28 | exit 2;; |
---|
29 | esac |
---|
30 | done |
---|
31 | shift $(($OPTIND-1)); |
---|
32 | #- |
---|
33 | # Validate the action |
---|
34 | #- |
---|
35 | [[ ${m_a} = help || ${m_a} = checkout ]] || \ |
---|
36 | { |
---|
37 | echo 'Action '"${m_a}"' not supported' 1>&2; |
---|
38 | echo 'Try "'${b_n}' -h [model-name]"' 1>&2; |
---|
39 | exit 4; |
---|
40 | } |
---|
41 | #- |
---|
42 | # Retrieve the model name |
---|
43 | #- |
---|
44 | [[ ${#} -gt 1 ]] && \ |
---|
45 | { echo 'Only one model can be specified' 1>&2; exit 3; } |
---|
46 | [[ ${#} -eq 1 ]] && { m_n="${1}"; } |
---|
47 | [[ ${m_a} != 'help' && -z ${m_n} ]] && \ |
---|
48 | { |
---|
49 | echo 'Model not specified' 1>&2; |
---|
50 | echo 'Try "'${b_n}' -h [model-name]"' 1>&2; |
---|
51 | exit 3; |
---|
52 | } |
---|
53 | #- |
---|
54 | # Test availability of the definition file |
---|
55 | #- |
---|
56 | F_DEF=${d_n}'/mod.def' |
---|
57 | [[ ! -f "${F_DEF}" ]] && { echo "${F_DEF} unreachable ..."; exit 3; } |
---|
58 | #- |
---|
59 | # Extract the names of the supported models |
---|
60 | #- |
---|
61 | qi=0; |
---|
62 | while read v0 v1 v2 |
---|
63 | do |
---|
64 | [[ -n "${v0}" && "${v0}" = '#-C-' ]] && \ |
---|
65 | { |
---|
66 | i_m=-1; |
---|
67 | qa=0; while (( ${qa} < ${#m_x[@]} )) |
---|
68 | do |
---|
69 | ((qa=qa+1)); |
---|
70 | [[ -n "${v1}" && "${v1}" = ${m_x[${qa}]} ]] && \ |
---|
71 | { i_m=${qa}; break; }; |
---|
72 | done |
---|
73 | (( ${i_m} < 0 )) && { ((qi=qi+1)); m_x[${qi}]=${v1}; }; |
---|
74 | } |
---|
75 | done <${F_DEF} |
---|
76 | unset v0 v1 v2; |
---|
77 | #- |
---|
78 | # Model name validation and data retrieving |
---|
79 | #- |
---|
80 | [[ -n "${m_n}" ]] && \ |
---|
81 | { |
---|
82 | #- Validate the model name |
---|
83 | i_m=-1; |
---|
84 | qi=0; while (( ${qi} < ${#m_x[@]} )) |
---|
85 | do |
---|
86 | ((qi=qi+1)); |
---|
87 | [[ ${m_n} = ${m_x[${qi}]} ]] && { i_m=${qi}; break; }; |
---|
88 | done |
---|
89 | (( ${i_m} < 0 )) && \ |
---|
90 | { echo 'Model '"${m_n}"' unknown' 1>&2; |
---|
91 | echo 'Try "'${b_n}' -h"' 1>&2; exit 3; } |
---|
92 | #- Extract the repository informations |
---|
93 | #- ( index, repository system, servers address ) |
---|
94 | while read v0 v1 v2 v3 |
---|
95 | do |
---|
96 | [[ -n "${v0}" && "${v0}" = '#-S-' ]] && \ |
---|
97 | { r_p[${v1}]=${v2}; r_s[${v1}]=${v3}; } |
---|
98 | done <${F_DEF} |
---|
99 | unset v0 v1 v2 v3; |
---|
100 | #- Extract the model informations |
---|
101 | qi=0; |
---|
102 | while read v0 v1 v2 v3 v4 v5 v6 |
---|
103 | do |
---|
104 | [[ -n "${v1}" && "${v1}" = "${m_n}" ]] && \ |
---|
105 | { |
---|
106 | #- model manager email address |
---|
107 | [[ "${v0}" = '#-M-' ]] && { m_m=${v2}; continue; } |
---|
108 | #- elements for the model component |
---|
109 | [[ "${v0}" = '#-C-' ]] && \ |
---|
110 | { |
---|
111 | ((qi=qi+1)); |
---|
112 | [[ -z "${v2}" ]] && \ |
---|
113 | { |
---|
114 | echo 'Component not found for '${m_n}; |
---|
115 | exit 3; |
---|
116 | } |
---|
117 | m_c[${qi}]=${v2}; |
---|
118 | [[ -z "${v3}" ]] && \ |
---|
119 | { |
---|
120 | echo 'Tag not found for component '${v2}' of '${m_n}; |
---|
121 | exit 3; |
---|
122 | } |
---|
123 | [[ ${no_tag} = 'false' ]] && \ |
---|
124 | { m_t[${qi}]=${v3}; } || \ |
---|
125 | { m_t[${qi}]='?'; } |
---|
126 | [[ -z "${v4}" ]] && \ |
---|
127 | { |
---|
128 | echo 'Repository index not found for '${m_n}; |
---|
129 | exit 3; |
---|
130 | } |
---|
131 | m_p[${qi}]=${r_p[${v4}]}; |
---|
132 | [[ ${m_p[${qi}]} = svn || ${m_p[${qi}]} = cvs ]] || \ |
---|
133 | { |
---|
134 | echo 'Control system '"${m_p[${qi}]}"' not supported' 1>&2; |
---|
135 | exit 3; |
---|
136 | } |
---|
137 | m_s[${qi}]=${r_s[${v4}]}; |
---|
138 | [[ -z "${m_s[${qi}]}" ]] && \ |
---|
139 | { |
---|
140 | echo 'Server '${v4}' not found for '${m_n}; |
---|
141 | exit 3; |
---|
142 | } |
---|
143 | m_d[${qi}]=${v5}; |
---|
144 | [[ -z "${m_d[${qi}]}" ]] && { m_d[${qi}]="."; } |
---|
145 | m_l[${qi}]=${v6}; |
---|
146 | [[ -z "${m_l[${qi}]}" ]] && { m_l[${qi}]="modeles"; } |
---|
147 | } |
---|
148 | } |
---|
149 | done <${F_DEF} |
---|
150 | unset v0 v1 v2 v3 v4 v5 v6 |
---|
151 | #- Validate the model informations |
---|
152 | #- model manager email address |
---|
153 | [[ -z "${m_m}" ]] && \ |
---|
154 | { echo 'Manager email address not found for '${m_n}; exit 3; } |
---|
155 | #- model components |
---|
156 | [[ ${#m_c[@]} = 0 ]] && \ |
---|
157 | { echo 'Components not found for '${m_n}; exit 3; } |
---|
158 | } |
---|
159 | #- |
---|
160 | # send an email at the first use of modipsl |
---|
161 | # ie directory ~/.modipsl does not exist |
---|
162 | #- |
---|
163 | D_LOG=${HOME}/.modipsl |
---|
164 | [[ -d "${D_LOG}" ]] || \ |
---|
165 | { |
---|
166 | mkdir "${D_LOG}"; |
---|
167 | echo $(date +"%D %T") $(whoami) $(uname -m) \ |
---|
168 | first use of model | \ |
---|
169 | ${MAIL_COM} -s "first use of modipsl" \ |
---|
170 | ${MAIL_ADDRESS} >/dev/null 2>&1; |
---|
171 | echo $(date +"%D %T") creation >"${D_LOG}"/first; |
---|
172 | } |
---|
173 | #- |
---|
174 | # "help" action |
---|
175 | #- |
---|
176 | [[ ${m_a} = 'help' ]] && \ |
---|
177 | { |
---|
178 | echo ' '; |
---|
179 | if [ -z "${m_n}" ]; then |
---|
180 | echo ${b_n} 'extracts the components of a model'; |
---|
181 | echo ' '; |
---|
182 | echo 'Usage :'; |
---|
183 | echo ${b_n} '[-h]'; |
---|
184 | echo ${b_n} '[-h] model_name'; |
---|
185 | echo ${b_n} '[-e] [-H] [-v] model_name'; |
---|
186 | echo 'h : this help'; |
---|
187 | echo 'h model-name : help on model'; |
---|
188 | echo 'e : extract model'; |
---|
189 | echo 'H : suppress the tags and take the HEAD version'; |
---|
190 | echo 'v : verbose mode'; |
---|
191 | echo 'Defaults : -e'; |
---|
192 | echo ' '; |
---|
193 | echo 'model_name in :'; |
---|
194 | qi=0; while (( ${qi} < ${#m_x[@]} )); |
---|
195 | do ((qi=qi+1)); echo ${m_x[${qi}]}; done |
---|
196 | else |
---|
197 | echo 'model : '${m_n}; |
---|
198 | echo ' '; |
---|
199 | while read v0 v1 v2 |
---|
200 | do |
---|
201 | [[ -n "${v0}" && "${v0}" = '#-H-' && \ |
---|
202 | -n "${v1}" && "${v1}" = "${m_n}" ]] && { echo ${v2}; } |
---|
203 | done <${F_DEF} |
---|
204 | unset v0 v1 v2; |
---|
205 | echo ' '; |
---|
206 | echo 'model manager email address : '${m_m}; |
---|
207 | echo ' '; |
---|
208 | qi=0; while (( ${qi} < ${#m_c[@]} )) |
---|
209 | do |
---|
210 | ((qi=qi+1)); |
---|
211 | echo 'Component '${qi}' : '${m_c[${qi}]}; |
---|
212 | echo 'Tag '${qi}' : '${m_t[${qi}]}; |
---|
213 | echo 'System '${qi}' : '${m_p[${qi}]}; |
---|
214 | echo 'Server '${qi}' : '${m_s[${qi}]}; |
---|
215 | echo 'Directory '${qi}' : '${m_d[${qi}]}; |
---|
216 | echo 'Local Dir '${qi}' : '${m_l[${qi}]}; |
---|
217 | done |
---|
218 | fi |
---|
219 | echo ' '; |
---|
220 | exit 0; |
---|
221 | } |
---|
222 | #- |
---|
223 | # Record information about the action in the "log" file |
---|
224 | #- |
---|
225 | F_LOG=${d_n}'/log' |
---|
226 | echo "${F_LOG}" |
---|
227 | echo $(date +"%D %T") $0 $* >>"${F_LOG}" |
---|
228 | #- |
---|
229 | # Verbose mode |
---|
230 | #- |
---|
231 | [ ${m_v} = 'verbose' ] && \ |
---|
232 | { echo '--- Model : '${m_n}; |
---|
233 | echo '--- Action : '${m_a}; |
---|
234 | echo '--- Mode : '${m_v}; } |
---|
235 | #- |
---|
236 | # Record information about the action in the "log" file |
---|
237 | #- |
---|
238 | { echo '--- Model : '${m_n}; |
---|
239 | echo '--- Action : '${m_a}; |
---|
240 | echo '--- Mode : '${m_v}; |
---|
241 | echo '--- Mail address : '${m_m}; } >>"${F_LOG}" |
---|
242 | #- |
---|
243 | # Components root directory |
---|
244 | #- |
---|
245 | d_m=${d_n}'/..'; |
---|
246 | #- |
---|
247 | # send an email at the first use of this IPSL model |
---|
248 | # ie file ~/.modipsl/log.${m_n} does not exist |
---|
249 | #- |
---|
250 | M_LOG=${D_LOG}/log.${m_n} |
---|
251 | [[ -f "${M_LOG}" ]] || \ |
---|
252 | { |
---|
253 | echo $(date +"%D %T") $(whoami) $(uname -m) \ |
---|
254 | first usage of model ${m_n} | \ |
---|
255 | ${MAIL_COM} -s "first usage of model ${m_n}" \ |
---|
256 | ${m_m} >/dev/null 2>&1; |
---|
257 | echo $(date +"%D %T") model ${m_n} >"${M_LOG}"; |
---|
258 | } |
---|
259 | #- |
---|
260 | # Extract the model components |
---|
261 | #- |
---|
262 | qi=0; while (( ${qi} < ${#m_c[@]} )) |
---|
263 | do |
---|
264 | ((qi=qi+1)); |
---|
265 | zc=${m_c[${qi}]}; zt=${m_t[${qi}]}; |
---|
266 | zp=${m_p[${qi}]}; zs=${m_s[${qi}]}; |
---|
267 | zd=${m_d[${qi}]}; zl=${m_l[${qi}]}; |
---|
268 | [[ ${m_v} = 'verbose' ]] && \ |
---|
269 | { echo '---'; |
---|
270 | echo '--- Component : '${zc}; |
---|
271 | echo '--- Tag : '${zt}; |
---|
272 | echo '--- System : '${zp}; |
---|
273 | echo '--- Server : '${zs}; |
---|
274 | echo '--- Directory : '${zd}; |
---|
275 | echo '--- Local Dir : '${zl}; } |
---|
276 | #----- |
---|
277 | #---- Record information about the action in the "log" file |
---|
278 | #----- |
---|
279 | { echo '---'; |
---|
280 | echo '--- Component : '${zc}; |
---|
281 | echo '--- Tag : '${zt}; |
---|
282 | echo '--- System : '${zp}; |
---|
283 | echo '--- Server : '${zs}; |
---|
284 | echo '--- Directory : '${zd}; |
---|
285 | echo '--- Local Dir : '${zl}; } >>"${F_LOG}" |
---|
286 | #--- |
---|
287 | [[ ${zp} = 'cvs' ]] && \ |
---|
288 | { |
---|
289 | c_c='(cd '${d_m}/${zl}'; '${zp}' -d :pserver:'${zs}' '${m_a}; |
---|
290 | [[ ${zt} != '?' ]] && { c_c=${c_c}' -r '${zt}; } |
---|
291 | [[ ${zd} != '.' ]] && { c_c=${c_c}' -d '${zd}; } |
---|
292 | c_c=${c_c}' '${zc}')'; |
---|
293 | grep "${zs%%/*}"'.*/'"${zs#*/}" ~/.cvspass > /dev/null; |
---|
294 | [[ ${?} != 0 ]] && \ |
---|
295 | { |
---|
296 | c_z='cvs -d :pserver:'${zs}' login'; |
---|
297 | [[ ${m_v} = 'verbose' ]] && { echo ${c_z}; } |
---|
298 | eval ${c_z}; |
---|
299 | } |
---|
300 | } |
---|
301 | #--- |
---|
302 | [[ ${zp} = 'svn' ]] && \ |
---|
303 | { |
---|
304 | c_c='(cd '${d_m}/${zl}'; '${zp}' '${m_a}; |
---|
305 | [[ ${zt} != '?' ]] && { c_c=${c_c}' -r '${zt}; } |
---|
306 | c_c=${c_c}' '${zs}'/'${zc}; |
---|
307 | [[ ${zd} != '.' ]] && { c_c=${c_c}' '${zd}; } |
---|
308 | c_c=${c_c}')'; |
---|
309 | } |
---|
310 | #--- |
---|
311 | [[ ${m_v} = 'verbose' ]] && { echo '--- Command : '${c_c}; } |
---|
312 | eval ${c_c}; |
---|
313 | done |
---|
314 | #- |
---|
315 | # Actions related to the WORK directory for the OPA models |
---|
316 | #- |
---|
317 | case ${m_n} in |
---|
318 | ( EEL* | ORCA* | OFF_TRC | IPSLCM* | IPSL_ESM* | ORCA_TOYATM | \ |
---|
319 | NEMO_ORCA2_LIM | GYRE ) |
---|
320 | d_m1=${d_m}/modeles/OPA ; |
---|
321 | [ -d ${d_m1}/WORK ] && \rm -rf ${d_m1}/WORK; |
---|
322 | mkdir ${d_m1}/WORK; |
---|
323 | cd ${d_m1}/WORK; |
---|
324 | #-- Getting the configuration files to build the Makefile |
---|
325 | ln -sf ../../../*/${m_n}/scripts/BB_make AA_make; |
---|
326 | ln -sf ../../../*/${m_n}/scripts/BB_make.ldef AA_make.ldef ; |
---|
327 | case ${m_n} in |
---|
328 | ( ORCA2_LMDZ96x71 ) |
---|
329 | echo " Creation du catalogue OPA/WORK = ORCA + LIM" |
---|
330 | ln -sf ../SRC_ORCA/*.[Ffh] . |
---|
331 | ln -sf ../SRC_UCL/[a-z]* . |
---|
332 | ln -sf ../../${m_n}/scripts/prep.sed.coupled .;; |
---|
333 | ( ORCA2 | ORCA4 | ORCA05 | EEL2 | EEL6 ) |
---|
334 | echo " Creation du catalogue OPA/WORK = ORCA" |
---|
335 | ln -sf ../SRC_ORCA/*.[Ffh] .;; |
---|
336 | ( ORCA*LIM | IPSLCM* | ORCA_TOYATM | ORCA*LMD* ) |
---|
337 | [ "${m_n}" = "IPSLCM4_LOOP" ] && \ |
---|
338 | echo " Creation du catalogue OPA/WORK = ORCA + LIM + TRC" || \ |
---|
339 | echo " Creation du catalogue OPA/WORK = ORCA + LIM" |
---|
340 | ln -sf ../SRC_ORCA/*.[Ffh] . |
---|
341 | [ "${m_n}" = "IPSLCM4_LOOP" ] && \rm *.passivetrc.h |
---|
342 | [ "${m_n}" = "IPSLCM4_LOOP" ] && \ |
---|
343 | ln -sf ../SRC_TRC/*.[Ffh] ../SRC_TRC/trc_sms/*.[Ffh] . |
---|
344 | ln -sf ../SRC_UCL/[a-z]* .;; |
---|
345 | ( ORCA*_LIM_TRC ) |
---|
346 | echo " Creation du catalogue OPA/WORK = ORCA + LIM + TRC" |
---|
347 | ln -sf ../SRC_ORCA/*.[Ffh] . |
---|
348 | \rm *.passivetrc.h |
---|
349 | ln -sf ../SRC_TRC/*.[Ffh] ../SRC_TRC/trc_sms/*.[Ffh] . |
---|
350 | ln -sf ../SRC_UCL/[a-z]* .;; |
---|
351 | ( *LOBSTER1 ) |
---|
352 | echo " Creation du catalogue OPA/WORK = ORCA + TRC" |
---|
353 | ln -sf ../SRC_ORCA/*.[Ffh] . |
---|
354 | \rm *.passivetrc.h |
---|
355 | ln -sf ../SRC_TRC/*.[Ffh] ../SRC_TRC/trc_sms/*.[Ffh] .;; |
---|
356 | ( ORCA*_OFF_TRC ) |
---|
357 | echo " Creation du catalogue OPA/WORK = TRC + OFFLINE" |
---|
358 | ln -sf ../SRC_TRC/*.[Ffh] ../SRC_TRC/trc_sms/*.[Ffh] . |
---|
359 | ln -sf ../SRC_OFFLINE_TRC/*.[Ffh] .;; |
---|
360 | esac |
---|
361 | #-- Building the standard list of source files |
---|
362 | cat >.patron <<"EOF" |
---|
363 | CVS |
---|
364 | SRC_PARAM |
---|
365 | SRC_FILE_LIST |
---|
366 | tmplist |
---|
367 | AA_make |
---|
368 | KEY_CPP |
---|
369 | Makefile |
---|
370 | *?.o |
---|
371 | i.?* |
---|
372 | *?.L |
---|
373 | .patron |
---|
374 | bloc.com |
---|
375 | para.com |
---|
376 | defcst.f |
---|
377 | fontbc.f |
---|
378 | icdyna.f |
---|
379 | thersf.f |
---|
380 | EOF |
---|
381 | ls -1 | fgrep -v -f .patron >SRC_FILE_LIST; |
---|
382 | cp SRC_FILE_LIST SRC_FILE_LIST.temp; |
---|
383 | KEY=$(grep P_P AA_make.ldef); |
---|
384 | [ -f "KEY_CPP" ] || echo $KEY > KEY_CPP; |
---|
385 | ;; |
---|
386 | esac |
---|
387 | #--- |
---|
388 | #- That's all folks |
---|
389 | #--- |
---|
390 | exit 0; |
---|