source: modipsl/trunk/util/model @ 2665

Last change on this file since 2665 was 2665, checked in by cetlod, 6 years ago

Restore TOP component for ORCA1_LIM3_PISCES configuration, previously suppressed for tests

  • Property svn:executable set to *
  • Property svn:keywords set to Id
File size: 14.2 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 'Tag       '${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     ( NEMOGCM* )
352    d_m1=${d_m}/modeles/NEMOGCM/CONFIG
353    d_m2=${d_m}/config
354    list_cfg='ORCA2_LIM ORCA2_LIM_PISCES ORCA2_OFF_PISCES'
355   
356    # Creates configuration ORCA1_LIM3_PISCES
357    # (see https://forge.ipsl.jussieu.fr/shaconemo/wiki/README_ORCA1_LIM3_PISCES )
358
359 
360    if [ -d ${d_m1}/SHARED  ]; then
361    {
362      for i in ${list_cfg}
363       do 
364         \rm -f ${d_m2}/${i}/IGCM00/PARAM/*.xml
365          cp ${d_m1}/SHARED/* ${d_m2}/${i}/IGCM00/PARAM
366          cp ${d_m1}/${i}/EXP00/iodef.xml  ${d_m2}/${i}/IGCM00/PARAM
367       done
368    }
369    fi
370    \rm -f  ${d_m2}/ORCA2_LIM_PISCES/IGCM00/PARAM/namelist
371    \rm -f  ${d_m2}/ORCA2_LIM_PISCES/IGCM00/PARAM/namelist_ice*
372    cp      ${d_m1}/ORCA2_LIM/EXP00/namelist* ${d_m2}/ORCA2_LIM_PISCES/IGCM00/PARAM/.
373    ;;
374esac
375
376#-
377#- Creates configuration ORCA1_LIM3_PISCES
378#- (see https://forge.ipsl.jussieu.fr/shaconemo/wiki/README_ORCA1_LIM3_PISCES )
379#-
380d_m1=${d_m}/modeles/NEMOGCM/CONFIG
381cfg_file=${d_m1}/cfg.txt
382if [[ -d ${d_m1}/ORCA1_LIM3_PISCES ]] ; then
383    grep ORCA1_LIM3_PISCES ${cfg_file} > /dev/null 2>&1
384    err=${?}
385    [[ ${err} = 1 ]] && ( echo "ORCA1_LIM3_PISCES OPA_SRC LIM_SRC_3 NST_SRC TOP_SRC" >> ${cfg_file} )
386fi
387
388#-
389# Actions related to the WORK directory for the OPA models
390#-
391case ${m_n} in
392  ( EEL* |  ORCA* | OFF_TRC | IPSLCM4* | IPSL_ESM_v1 | ORCA_TOYATM | \
393    NEMO_ORCA2_LIM | GYRE )
394    d_m1=${d_m}/modeles/OPA  ;
395    [ -d ${d_m1}/WORK ] && \rm -rf ${d_m1}/WORK;
396    mkdir ${d_m1}/WORK;
397    cd ${d_m1}/WORK;
398#-- Getting the configuration files to build the Makefile
399    ln -sf ../../../*/${m_n}/scripts/BB_make AA_make;
400    ln -sf ../../../*/${m_n}/scripts/BB_make.ldef AA_make.ldef ;
401    case ${m_n} in
402     ( ORCA2_LMDZ96x71 )
403      echo " Creation du catalogue OPA/WORK = ORCA + LIM"
404      ln -sf ../SRC_ORCA/*.[Ffh] .
405      ln -sf ../SRC_UCL/[a-z]* .
406      ln -sf ../../${m_n}/scripts/prep.sed.coupled .;;
407     ( ORCA2 | ORCA4 | ORCA05 | EEL2 | EEL6 )
408      echo " Creation du catalogue OPA/WORK = ORCA"
409      ln -sf ../SRC_ORCA/*.[Ffh] .;;
410     ( ORCA*LIM | IPSLCM4*  | IPSL_ESM* | ORCA_TOYATM | ORCA*LMD* )
411      [ "${m_n}" = "IPSLCM4_LOOP" ] && \
412       echo " Creation du catalogue OPA/WORK = ORCA + LIM + TRC" || \
413       echo " Creation du catalogue OPA/WORK = ORCA + LIM"
414      ln -sf ../SRC_ORCA/*.[Ffh] .
415      [ "${m_n}" = "IPSLCM4_LOOP" ] && \rm *.passivetrc.h
416      [ "${m_n}" = "IPSLCM4_LOOP" ] && \
417       ln -sf ../SRC_TRC/*.[Ffh] ../SRC_TRC/trc_sms/*.[Ffh] .
418      ln -sf ../SRC_UCL/[a-z]* .;;
419     ( ORCA*_LIM_TRC )
420      echo " Creation du catalogue OPA/WORK = ORCA + LIM + TRC"
421      ln -sf ../SRC_ORCA/*.[Ffh] .
422      \rm *.passivetrc.h
423      ln -sf ../SRC_TRC/*.[Ffh] ../SRC_TRC/trc_sms/*.[Ffh] .
424      ln -sf ../SRC_UCL/[a-z]* .;;
425     ( *LOBSTER1 )
426      echo " Creation du catalogue OPA/WORK = ORCA + TRC"
427      ln -sf ../SRC_ORCA/*.[Ffh] .
428      \rm *.passivetrc.h
429      ln -sf ../SRC_TRC/*.[Ffh] ../SRC_TRC/trc_sms/*.[Ffh] .;;
430     ( ORCA*_OFF_TRC )
431      echo " Creation du catalogue OPA/WORK = TRC + OFFLINE"
432      ln -sf ../SRC_TRC/*.[Ffh] ../SRC_TRC/trc_sms/*.[Ffh] .
433      ln -sf ../SRC_OFFLINE_TRC/*.[Ffh] .;;
434    esac
435#-- Building the standard list of source files
436    cat >.patron <<"EOF"
437CVS
438SRC_PARAM
439SRC_FILE_LIST
440tmplist
441AA_make
442KEY_CPP
443Makefile
444*?.o
445 i.?*
446*?.L
447.patron
448bloc.com
449para.com
450defcst.f
451fontbc.f
452icdyna.f
453thersf.f
454EOF
455    ls -1 | fgrep -v -f .patron  >SRC_FILE_LIST;
456    cp SRC_FILE_LIST SRC_FILE_LIST.temp;
457    KEY=$(grep P_P AA_make.ldef);
458    [ -f "KEY_CPP" ] || echo $KEY > KEY_CPP;
459  ;;
460  ( IPSLCM5_LOOP )
461  ../modeles/UTIL/fait_config IPSLCM5_LOOP ;;
462  ( IPSLCM5_v3 )
463  ../modeles/UTIL/fait_config IPSLCM5_v3 ;;
464  ( IPSLCM5A )
465  ../modeles/UTIL/fait_config IPSLCM5A ;;
466  ( IPSLCM5A_C )
467  ../modeles/UTIL/fait_config IPSLCM5A_C ;;
468  ( IPSLCM5B )
469  ../modeles/UTIL/fait_config IPSLCM5B ;;
470  ( IPSLCM5_v5 )
471  ../modeles/UTIL/fait_config IPSLCM5_v5 ;;
472  ( IPSLCM5CHS_v5 )
473  ../modeles/UTIL/fait_config IPSLCM5CHS_v5 ;;
474  ( IPSLCM5CHT_v5 )
475  ../modeles/UTIL/fait_config IPSLCM5CHT_v5 ;;
476  (IPSLCM5* )
477  ../modeles/UTIL/fait_config IPSLCM5 ;;
478  ( IPSL_ESM_v2 )
479  ../modeles/UTIL/fait_config IPSL_ESM_v2 ;;
480esac
481
482#--- Create Makefiles using the script ins_make
483#    ins_make will detect target machine among predefined targets in AA_make.gdef and
484#    create Makefiles to the corresponding target.
485#    ins_make can be re-run afterwards using another target or after editing the
486#    AA_make.gdef. ins_make will then overwrite Makefiles already created.
487#
488./ins_make
489
490#---
491#- That's all folks
492#---
493exit 0;
Note: See TracBrowser for help on using the repository browser.