source: modipsl/trunk/util/model @ 3693

Last change on this file since 3693 was 3693, checked in by acosce, 6 years ago

Add IPSLESM to the list of model using NEMOGCM

  • Property svn:executable set to *
  • Property svn:keywords set to Id
File size: 12.5 KB
Line 
1#!/bin/ksh
2#- $Id$
3#---------------------------------------------------------------------
4# @(#)Actions concerning IPSL models
5#---------------------------------------------------------------------
6#set -xv
7MAIL_ADDRESS=arnaud.caubel@lsce.ipsl.fr
8MAIL_COM=mail
9#MAIL_COM=Mail
10#-
11#     Dirname     and      Basename
12#-
13d_n=$(dirname ${0}); b_n=$(basename ${0});
14#-
15# Retrieve and validate the options
16#-
17m_n=""; m_a="checkout"; m_v='silencious'; no_tag='false';
18# Option -d to take default set up without asking
19changeok='yes'
20while getopts :hevdH V
21  do
22    case $V in
23      (h)  m_a='help';;
24      (e)  m_a='checkout';;
25      (v)  m_v='verbose';;
26      (d)  changeok='no';;
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
34shift $(($OPTIND-1));
35#-
36# Validate the action
37#-
38[[ ${m_a} = help || ${m_a} = checkout ]] || \
39 {
40  echo 'Action '"${m_a}"' not supported' 1>&2;
41  echo 'Try "'${b_n}' -h [model-name]"' 1>&2;
42  exit 4;
43 }
44#-
45# Retrieve the model name
46#-
47[[ ${#} -gt 1 ]] && \
48  { echo 'Only one model can be specified' 1>&2; exit 3; }
49[[ ${#} -eq 1 ]] && { m_n="${1}"; }
50[[ ${m_a} != 'help' && -z ${m_n} ]] && \
51 {
52  echo 'Model not specified' 1>&2;
53  echo 'Try "'${b_n}' -h [model-name]"' 1>&2;
54  exit 3;
55 }
56#-
57# Test availability of the definition file
58#-
59F_DEF=${d_n}'/mod.def'
60[[ ! -f "${F_DEF}" ]] && { echo "${F_DEF} unreachable ..."; exit 3; }
61#-
62# Extract the names of the supported models
63#-
64qi=0;
65while read v0 v1 v2
66  do
67    [[ -n "${v0}" && "${v0}" = '#-C-' ]] && \
68     {
69      i_m=-1;
70      qa=0; while (( ${qa} < ${#m_x[@]} ))
71       do
72         ((qa=qa+1));
73         [[ -n "${v1}" && "${v1}" = ${m_x[${qa}]} ]] && \
74          { i_m=${qa}; break; };
75       done
76      (( ${i_m} < 0 )) && { ((qi=qi+1)); m_x[${qi}]=${v1}; };
77     }
78  done <${F_DEF}
79unset v0 v1 v2;
80#-
81# Model name validation and data retrieving
82#-
83[[ -n "${m_n}" ]] && \
84  {
85    #- Validate the model name
86    i_m=-1;
87    qi=0; while (( ${qi} < ${#m_x[@]} ))
88      do
89        ((qi=qi+1));
90        [[ ${m_n} = ${m_x[${qi}]} ]] && { i_m=${qi}; break; };
91      done
92    (( ${i_m} < 0 )) && \
93     { echo 'Model '"${m_n}"' unknown' 1>&2;
94       echo 'Try "'${b_n}' -h"' 1>&2; exit 3; }
95    #- Extract the repository informations
96    #- ( index, repository system, servers address )
97    while read v0 v1 v2 v3
98      do
99        [[ -n "${v0}" && "${v0}" = '#-S-' ]] && \
100         { r_p[${v1}]=${v2}; r_s[${v1}]=${v3}; }
101      done <${F_DEF}
102    unset v0 v1 v2 v3;
103    #- Extract the model informations
104    qi=0;
105    while read v0 v1 v2 v3 v4 v5 v6
106      do
107        [[ -n "${v1}" && "${v1}" = "${m_n}" ]] && \
108         {
109          #- model manager email address
110          [[ "${v0}" = '#-M-' ]] && { m_m=${v2}; continue; }
111          #- elements for the model component
112          [[ "${v0}" = '#-C-' ]] && \
113           {
114            ((qi=qi+1));
115            [[ -z "${v2}" ]] && \
116             {
117              echo 'Component not found for '${m_n};
118              exit 3;
119             }
120            m_c[${qi}]=${v2};
121            [[ -z "${v3}" ]] && \
122             {
123              echo 'Tag not found for component '${v2}' of '${m_n};
124              exit 3;
125             }
126            [[ ${no_tag} = 'false' ]] && \
127             { m_t[${qi}]=${v3}; }    || \
128             { m_t[${qi}]='?'; }
129            [[ -z "${v4}" ]] && \
130             {
131              echo 'Repository index not found for '${m_n};
132              exit 3;
133             }
134            m_p[${qi}]=${r_p[${v4}]};
135            [[ ${m_p[${qi}]} = svn || ${m_p[${qi}]} = cvs ]] || \
136             {
137              echo 'Control system '"${m_p[${qi}]}"' not supported' 1>&2;
138              exit 3;
139             }
140            m_s[${qi}]=${r_s[${v4}]};
141            [[ -z "${m_s[${qi}]}" ]] && \
142             {
143              echo 'Server '${v4}'  not found for '${m_n};
144              exit 3;
145             }
146            m_d[${qi}]=${v5};
147            [[ -z "${m_d[${qi}]}" ]] && { m_d[${qi}]="."; }
148            m_l[${qi}]=${v6};
149            [[ -z "${m_l[${qi}]}" ]] && { m_l[${qi}]="modeles"; }
150           }
151         }
152      done <${F_DEF}
153    unset v0 v1 v2 v3 v4 v5 v6
154    #- Validate the model informations
155    #- model manager email address
156    [[ -z "${m_m}" ]] && \
157     { echo 'Manager email address not found for '${m_n}; exit 3; }
158    #- model components
159    [[ ${#m_c[@]} = 0 ]] && \
160     { echo 'Components not found for '${m_n}; exit 3; }
161  }
162#-
163# send an email at the first use of modipsl
164# ie directory ~/.modipsl does not exist
165#-
166D_LOG=${HOME}/.modipsl
167[[ -d "${D_LOG}" ]] || \
168 {
169  mkdir "${D_LOG}";
170  echo $(date +"%D %T") $(whoami) $(uname -m) \
171    first use of model | \
172    ${MAIL_COM} -s "first use of modipsl" \
173    ${MAIL_ADDRESS} >/dev/null 2>&1;
174   echo $(date +"%D %T") creation >"${D_LOG}"/first;
175  }
176#-
177# "help" action
178#-
179[[ ${m_a} = 'help' ]] && \
180 {
181  echo ' ';
182  if [ -z "${m_n}" ]; then
183    echo ${b_n} ': This script is used to extract one configuration';
184    echo ' ';
185    echo 'Usage    :';
186    echo './'${b_n} '[-h]';
187    echo './'${b_n} '[-h] ConfName';
188    echo './'${b_n} '[-v] ConfName';
189    echo ''
190    echo 'Arguments :'
191    echo 'ConfName       : name of configuration to be extracted';
192    echo '-h             : this help';
193    echo '-h ConfName    : description of configuration ConfName';
194# Meaningless option    echo '-e                : extract model';
195# Does not work    echo 'H                : suppress the tags and take the HEAD version';
196    echo '-v             : verbose mode';
197#    echo 'd                : extract default components without option to change';
198    echo ' ';
199    echo 'Possible configurations are :';
200    qi=0; while (( ${qi} < ${#m_x[@]} ));
201      do ((qi=qi+1)); echo ${m_x[${qi}]}; done
202  else
203    echo 'model : '${m_n};
204    echo ' ';
205    while read v0 v1 v2
206     do
207       [[ -n "${v0}" && "${v0}" = '#-H-' && \
208          -n "${v1}" && "${v1}" = "${m_n}" ]] && { echo ${v2}; }
209     done <${F_DEF}
210    unset v0 v1 v2;
211    echo ' ';
212    echo 'model manager email address : '${m_m};
213    echo ' ';
214    qi=0; while (( ${qi} < ${#m_c[@]} ))
215      do
216        ((qi=qi+1));
217        echo 'Component '${qi}' : '${m_c[${qi}]};
218        echo 'Revision  '${qi}' : '${m_t[${qi}]};
219        echo 'System    '${qi}' : '${m_p[${qi}]};
220        echo 'Server    '${qi}' : '${m_s[${qi}]};
221        echo 'Directory '${qi}' : '${m_d[${qi}]};
222        echo 'Local Dir '${qi}' : '${m_l[${qi}]};
223      done
224  fi
225  echo ' ';
226  exit 0;
227 }
228#-
229# Record information about the action in the "log" file
230#-
231F_LOG=${d_n}'/log'
232echo "${F_LOG}"
233echo $(date +"%D %T") $0 $* >>"${F_LOG}"
234#-
235# Verbose mode
236#-
237[ ${m_v} = 'verbose' ] && \
238 { echo '--- Model        : '${m_n};
239   echo '--- Action       : '${m_a};
240   echo '--- Mode         : '${m_v}; }
241#-
242# Record information about the action in the "log" file
243#-
244{ echo '--- Model        : '${m_n};
245  echo '--- Action       : '${m_a};
246  echo '--- Mode         : '${m_v};
247  echo '--- Mail address : '${m_m}; } >>"${F_LOG}"
248#-
249# Components root directory
250#-
251d_m=${d_n}'/..';
252#-
253# send an email at the first use of this IPSL model
254# ie file ~/.modipsl/log.${m_n} does not exist
255#-
256M_LOG=${D_LOG}/log.${m_n}
257[[ -f "${M_LOG}" ]] || \
258  {
259   echo $(date +"%D %T") $(whoami) $(uname -m) \
260    first usage of model ${m_n} | \
261   ${MAIL_COM} -s "first usage of model ${m_n}" \
262    ${m_m} >/dev/null 2>&1;
263   echo $(date +"%D %T") model ${m_n} >"${M_LOG}";
264  }
265#-
266# Extract the model components
267#-
268qi=0; while (( ${qi} < ${#m_c[@]} ))
269  do
270    ((qi=qi+1));
271    zc=${m_c[${qi}]}; zt=${m_t[${qi}]};
272    zp=${m_p[${qi}]}; zs=${m_s[${qi}]};
273    zd=${m_d[${qi}]}; zl=${m_l[${qi}]};
274
275# Maybe change some information marked with DEFAULT.
276# Check if key word DEFAULT is used in component name
277    defcomp=$(echo ${zc} | awk -FDEFAULT: '{print $2}')
278    if [ X$defcomp != X ] ; then
279        if [ $changeok == 'yes' ] ; then
280            echo "=> Default component $defcomp can be changed."
281            echo "   Do you want to change this path ? Type new path or return for the above default."
282            read newcomp
283            echo "   Type revision number for chosen component version or return for $zt default value"
284            read newrev
285            if [ X$newcomp == X ] ; then
286                zc=$defcomp
287            else
288                zc=$newcomp
289            fi
290
291            if [ X$newrev != X ] ; then
292                zt=$newrev
293            fi
294        else
295            # changeok=no : Take default value#
296            zc=$defcomp
297        fi
298    fi
299    [[ ${m_v} = 'verbose' ]] && \
300     { echo '---';
301       echo '--- Component  : '${zc};
302       echo '--- Tag        : '${zt};
303       echo '--- System     : '${zp};
304       echo '--- Server     : '${zs};
305       echo '--- Directory  : '${zd};
306       echo '--- Local Dir  : '${zl}; }
307#-----
308#----  Record information about the action in the "log" file
309#-----
310     { echo '---';
311       echo '--- Component  : '${zc};
312       echo '--- Tag        : '${zt};
313       echo '--- System     : '${zp};
314       echo '--- Server     : '${zs};
315       echo '--- Directory  : '${zd};
316       echo '--- Local Dir  : '${zl}; } >>"${F_LOG}"
317#---
318    [[ ${zp} = 'cvs' ]] && \
319     {
320      c_c='(cd '${d_m}/${zl}'; '${zp}' -d :pserver:'${zs}' '${m_a};
321      [[ ${zt} != '?' ]] && { c_c=${c_c}' -r '${zt}; }
322      [[ ${zd} != '.' ]] && { c_c=${c_c}' -d '${zd}; }
323      c_c=${c_c}' '${zc}')';
324      grep "${zs%%/*}"'.*/'"${zs#*/}" ~/.cvspass > /dev/null;
325      [[ ${?} != 0 ]] && \
326       {
327        c_z='cvs -d :pserver:'${zs}' login';
328        [[ ${m_v} = 'verbose' ]] && { echo ${c_z}; }
329        eval ${c_z};
330       }
331     }
332#---
333    [[ ${zp} = 'svn' ]] && \
334     {
335      c_c='(cd '${d_m}/${zl}'; '${zp}' '${m_a};
336      [[ ${zt} != '?' ]] && { c_c=${c_c}' -r '${zt}; }
337      c_c=${c_c}' '${zs}'/'${zc};
338      [[ ${zd} != '.' ]] && { c_c=${c_c}' '${zd}; }
339      c_c=${c_c}')';
340     }
341#---
342    [[ ${m_v} = 'verbose' ]] && { echo '--- Command    : '${c_c}; }
343    eval ${c_c};
344  done
345
346#-
347# Actions related to NEMOGCM
348#-
349
350case ${m_n} in
351     ( NEMO_v* | IPSLCM6*LR | IPSLCM6*LR_CMIP6 | PREIPSLCM6.1-LR | IPSLESM6 )
352    d_m1=${d_m}/modeles/NEMOGCM/CONFIG
353    cfg_file=${d_m1}/cfg.txt
354    list_cfg='ORCA1_LIM3_PISCES eORCA025_LIM3 eORCA025_LIM3_PISCES'
355    # Creates configuration ORCA1_LIM3_PISCES
356    # (see https://forge.ipsl.jussieu.fr/shaconemo/wiki/README_ORCA1_LIM3_PISCES )
357    for cfg in ${list_cfg}
358       do
359        if [[ -d ${d_m1}/${cfg} ]] ; then
360           grep ${cfg} ${cfg_file} > /dev/null 2>&1
361           err=${?}
362           if [[ ${err} = 1 ]] ; then
363              pis=`echo ${cfg} | grep "PISCES" | wc -l`
364              if [[ ${pis} = 1 ]] ; then
365                 echo "${cfg} OPA_SRC LIM_SRC_3 NST_SRC TOP_SRC" >> ${cfg_file}
366              else
367                echo "${cfg} OPA_SRC LIM_SRC_3 NST_SRC" >> ${cfg_file}
368             fi
369           fi
370        fi
371     done
372esac
373
374#-
375# Actions related to the WORK directory for the OPA models
376#-
377case ${m_n} in
378  ( IPSLCM4_LOOP )
379    d_m1=${d_m}/modeles/OPA  ;
380    [ -d ${d_m1}/WORK ] && \rm -rf ${d_m1}/WORK;
381    mkdir ${d_m1}/WORK;
382    cd ${d_m1}/WORK;
383#-- Getting the configuration files to build the Makefile
384    ln -sf ../../../*/${m_n}/scripts/BB_make AA_make;
385    ln -sf ../../../*/${m_n}/scripts/BB_make.ldef AA_make.ldef ;
386    [ "${m_n}" = "IPSLCM4_LOOP" ] && \
387        echo " Creation du catalogue OPA/WORK = ORCA + LIM + TRC" || \
388        echo " Creation du catalogue OPA/WORK = ORCA + LIM"
389    ln -sf ../SRC_ORCA/*.[Ffh] .
390    [ "${m_n}" = "IPSLCM4_LOOP" ] && \rm *.passivetrc.h
391    [ "${m_n}" = "IPSLCM4_LOOP" ] && \
392        ln -sf ../SRC_TRC/*.[Ffh] ../SRC_TRC/trc_sms/*.[Ffh] .
393    ln -sf ../SRC_UCL/[a-z]* .
394#-- Building the standard list of source files
395    cat >.patron <<"EOF"
396CVS
397SRC_PARAM
398SRC_FILE_LIST
399tmplist
400AA_make
401KEY_CPP
402Makefile
403*?.o
404 i.?*
405*?.L
406.patron
407bloc.com
408para.com
409defcst.f
410fontbc.f
411icdyna.f
412thersf.f
413EOF
414    ls -1 | fgrep -v -f .patron  >SRC_FILE_LIST;
415    cp SRC_FILE_LIST SRC_FILE_LIST.temp;
416    KEY=$(grep P_P AA_make.ldef);
417    [ -f "KEY_CPP" ] || echo $KEY > KEY_CPP;
418  ;;
419  ( IPSLCM5A )
420  ../modeles/UTIL/fait_config IPSLCM5A ;;
421  ( IPSLCM5A_C )
422  ../modeles/UTIL/fait_config IPSLCM5A_C ;;
423  ( IPSLCM5B )
424  ../modeles/UTIL/fait_config IPSLCM5B ;;
425  ( IPSLCM5_v5 )
426  ../modeles/UTIL/fait_config IPSLCM5_v5 ;;
427  ( IPSLCM5CHS_v5 )
428  ../modeles/UTIL/fait_config IPSLCM5CHS_v5 ;;
429  ( IPSLCM5CHT_v5 )
430  ../modeles/UTIL/fait_config IPSLCM5CHT_v5 ;;
431esac
432
433#--- Create Makefiles using the script ins_make
434#    ins_make will detect target machine among predefined targets in AA_make.gdef and
435#    create Makefiles to the corresponding target.
436#    ins_make can be re-run afterwards using another target or after editing the
437#    AA_make.gdef. ins_make will then overwrite Makefiles already created.
438#
439./ins_make
440
441#---
442#- That's all folks
443#---
444exit 0;
Note: See TracBrowser for help on using the repository browser.