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