source: modipsl/trunk/util/model @ 6671

Last change on this file since 6671 was 6671, checked in by jgipsl, 8 months ago

Add possibility to extract a sub-configuration of IPSLCM7 configuration.

  • Property svn:executable set to *
  • Property svn:keywords set to Id
File size: 15.7 KB
Line 
1#!/bin/ksh
2#- $Id$
3#---------------------------------------------------------------------
4# @(#)Actions concerning IPSL models
5#---------------------------------------------------------------------
6#set -xv
7MAIL_ADDRESS=platform-extract@listes.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 2 ]] && \
48  { echo 'Only one model can be specified' 1>&2; exit 3; }
49[[ ${#} -eq 1 ]] && { m_n="${1}"; }
50sub_conf="FULL"
51[[ ${#} -eq 2 ]] && { m_n="${1}"; sub_conf="${2}"; }
52[[ ${m_a} != 'help' && -z ${m_n} ]] && \
53 {
54  echo 'Model not specified' 1>&2;
55  echo 'Try "'${b_n}' -h [model-name]"' 1>&2;
56  exit 3;
57 }
58
59case ${m_n} in
60    ( IPSLCM7* )
61    # subconfiguration is optional
62    if [ ${sub_conf} == "LMDZOR" ] ; then
63        comp_to_exclude="NEMO OASIS INCA DYNAMICO"
64    elif [ ${sub_conf} == "LMDZORINCA" ] ; then
65        comp_to_exclude="NEMO OASIS DYNAMICO"
66    elif [ ${sub_conf} == "ICOLMDZOR" ] ; then
67        comp_to_exclude="NEMO OASIS INCA"
68    elif [ ${sub_conf} == "ICOLMDZORINCA" ] ; then
69        comp_to_exclude="NEMO OASIS"
70    elif [ ${sub_conf} == "FULL" ] ; then
71        comp_to_exculde=" "
72    else
73        echo Sub-configuration ${sub_conf} is not supported.
74        echo Choose between ICOLMDZOR, ICOLMDZORINCA, LMDZOR or LMDZORINCA
75        echo For full configuration, do not specify the second argument or choose FULL
76        exit
77    fi
78    ;;
79    ( * )
80    # sub configuration is not possible
81    if [ ${sub_conf} != "FULL" ] ; then
82        echo Extraction of a sub-configuration is not supported for this model. Remove second argument and retry.
83        exit
84    fi
85esac
86
87#-
88# Test availability of the definition file
89#-
90F_DEF=${d_n}'/mod.def'
91[[ ! -f "${F_DEF}" ]] && { echo "${F_DEF} unreachable ..."; exit 3; }
92#-
93# Extract the names of the supported models
94#-
95qi=0;
96while read v0 v1 v2
97  do
98    [[ -n "${v0}" && "${v0}" = '#-C-' ]] && \
99     {
100      i_m=-1;
101      qa=0; while (( ${qa} < ${#m_x[@]} ))
102       do
103         ((qa=qa+1));
104         [[ -n "${v1}" && "${v1}" = ${m_x[${qa}]} ]] && \
105          { i_m=${qa}; break; };
106       done
107      (( ${i_m} < 0 )) && { ((qi=qi+1)); m_x[${qi}]=${v1}; };
108     }
109  done <${F_DEF}
110unset v0 v1 v2;
111#-
112# Model name validation and data retrieving
113#-
114[[ -n "${m_n}" ]] && \
115  {
116    #- Validate the model name
117    i_m=-1;
118    qi=0; while (( ${qi} < ${#m_x[@]} ))
119      do
120        ((qi=qi+1));
121        [[ ${m_n} = ${m_x[${qi}]} ]] && { i_m=${qi}; break; };
122      done
123    (( ${i_m} < 0 )) && \
124     { echo 'Model '"${m_n}"' unknown' 1>&2;
125       echo 'Try "'${b_n}' -h"' 1>&2; exit 3; }
126    #- Extract the repository informations
127    #- ( index, repository system, servers address )
128    while read v0 v1 v2 v3
129      do
130        [[ -n "${v0}" && "${v0}" = '#-S-' ]] && \
131         { r_p[${v1}]=${v2}; r_s[${v1}]=${v3}; }
132      done <${F_DEF}
133    unset v0 v1 v2 v3;
134    #- Extract the model informations
135    qi=0; 
136    while read v0 v1 v2 v3 v4 v5 v6 v7
137      do
138         [[ -n "${v1}" && "${v1}" = "${m_n}" ]] && \
139         {
140          #- model manager email address
141          [[ "${v0}" = '#-M-' ]] && { m_m=${v2}; continue; }
142          #- elements for the model component
143          [[ "${v0}" = '#-C-' ]] && \
144           {
145            ((qi=qi+1));
146            [[ -z "${v2}" ]] && \
147             {
148              echo 'Component not found for '${m_n};
149              exit 3;
150             }
151            m_c[${qi}]=${v2};
152            [[ -z "${v3}" ]] && \
153             {
154              echo 'Tag not found for component '${v2}' of '${m_n};
155              exit 3;
156             }
157            [[ ${no_tag} = 'false' ]] && \
158             { m_t[${qi}]=${v3}; }    || \
159             { m_t[${qi}]='?'; }
160            [[ -z "${v4}" ]] && \
161             {
162              echo 'Repository index not found for '${m_n};
163              exit 3;
164             }
165            m_p[${qi}]=${r_p[${v4}]};
166            [[ ${m_p[${qi}]} = svn || ${m_p[${qi}]} = cvs || ${m_p[${qi}]} = git ]] || \
167             {
168              echo 'Control system '"${m_p[${qi}]}"' not supported' 1>&2;
169              exit 3;
170             }
171            m_s[${qi}]=${r_s[${v4}]};
172            [[ -z "${m_s[${qi}]}" ]] && \
173             {
174              echo 'Server '${v4}'  not found for '${m_n};
175              exit 3;
176             }
177            m_d[${qi}]=${v5};
178            [[ -z "${m_d[${qi}]}" ]] && { m_d[${qi}]="."; }
179            m_l[${qi}]=${v6};
180            [[ -z "${m_l[${qi}]}" ]] && { m_l[${qi}]="modeles"; }
181            m_7[${qi}]=${v7};
182            [[ -z "${m_7[${qi}]}" ]] && { m_7[${qi}]="none"; }
183           }
184         }
185      done <${F_DEF}
186    unset v0 v1 v2 v3 v4 v5 v6 v7
187    #- Validate the model informations
188    #- m_m: model manager email address. If not found in mod.def then set default adress.
189    [[ -z "${m_m}" ]] && \
190        { m_m=${MAIL_ADDRESS}; }
191    #- model components
192    [[ ${#m_c[@]} = 0 ]] && \
193     { echo 'Components not found for '${m_n}; exit 3; }
194  }
195#-
196# send an email at the first use of modipsl
197# ie directory ~/.modipsl does not exist
198#-
199D_LOG=${HOME}/.modipsl
200[[ -d "${D_LOG}" ]] || \
201 {
202  mkdir "${D_LOG}";
203  echo $(date +"%D %T") $(whoami) $(uname -m) \
204    first use of model | \
205    ${MAIL_COM} -s "first use of modipsl" \
206    ${MAIL_ADDRESS} >/dev/null 2>&1;
207   echo $(date +"%D %T") creation >"${D_LOG}"/first;
208  }
209#-
210# "help" action
211#-
212[[ ${m_a} = 'help' ]] && \
213 {
214  echo ' ';
215  if [ -z "${m_n}" ]; then
216    echo ${b_n} ': This script is used to extract one configuration';
217    echo ' ';
218    echo 'Usage    :';
219    echo './'${b_n} '[-h]';
220    echo './'${b_n} '[-h] ConfName';
221    echo './'${b_n} '[-v] ConfName';
222    echo ''
223    echo 'Arguments :'
224    echo 'ConfName       : name of configuration to be extracted';
225    echo '-h             : this help';
226    echo '-h ConfName    : description of configuration ConfName';
227# Meaningless option    echo '-e                : extract model';
228# Does not work    echo 'H                : suppress the tags and take the HEAD version';
229    echo '-v             : verbose mode';
230#    echo 'd                : extract default components without option to change';
231    echo ' ';
232    echo 'Possible configurations are :';
233    qi=0; while (( ${qi} < ${#m_x[@]} ));
234      do ((qi=qi+1)); echo ${m_x[${qi}]}; done
235  else
236    echo 'model : '${m_n};
237    [[ ${sub_conf} != "FULL" ]] && echo "Subconfiguration : ${sub_conf} (following components will not be extracted:  ${comp_to_exclude})"
238    echo ' ';
239    while read v0 v1 v2
240     do
241       [[ -n "${v0}" && "${v0}" = '#-H-' && \
242          -n "${v1}" && "${v1}" = "${m_n}" ]] && { echo ${v2}; }
243     done <${F_DEF}
244    unset v0 v1 v2;
245    echo ' ';
246    echo 'model manager email address : '${m_m};
247    echo ' ';
248    qi=0; while (( ${qi} < ${#m_c[@]} ))
249      do
250        ((qi=qi+1));
251       
252        # Check if the component is in the list of compents to exclude from installation
253        # If that's the case, continue to next component
254        z7=${m_7[${qi}]}
255        if [ "X$( echo ${comp_to_exclude} | grep $z7 )" != "X" ] ; then
256            [[ ${m_v} = 'verbose' ]] && { echo Component ${z7} will not be extracted. ; }
257            continue
258        fi
259        echo 'Component '${qi}' : '${m_c[${qi}]};
260        echo 'Revision  '${qi}' : '${m_t[${qi}]};
261        echo 'System    '${qi}' : '${m_p[${qi}]};
262        echo 'Server    '${qi}' : '${m_s[${qi}]};
263        echo 'Directory '${qi}' : '${m_d[${qi}]};
264        echo 'Local Dir '${qi}' : '${m_l[${qi}]};
265        echo 'Comp name '${qi}' : '${z7};
266        echo ''
267      done
268  fi
269  echo ' ';
270  exit 0;
271 }
272#-
273# Record information about the action in the "log" file
274#-
275F_LOG=${d_n}'/log'
276echo "${F_LOG}"
277echo $(date +"%D %T") $0 $* >>"${F_LOG}"
278#-
279# Verbose mode
280#-
281[ ${m_v} = 'verbose' ] && \
282 { echo '--- Model        : '${m_n};
283   echo '--- Action       : '${m_a};
284   echo '--- Mode         : '${m_v}; }
285#-
286# Record information about the action in the "log" file
287#-
288{ echo '--- Model        : '${m_n};
289  echo '--- Action       : '${m_a};
290  echo '--- Mode         : '${m_v};
291  echo '--- Mail address : '${m_m}; } >>"${F_LOG}"
292#-
293# Components root directory
294#-
295d_m=${d_n}'/..';
296#-
297# send an email at the first use of this IPSL model
298# ie file ~/.modipsl/log.${m_n} does not exist
299#-
300M_LOG=${D_LOG}/log.${m_n}
301[[ -f "${M_LOG}" ]] || \
302  {
303   echo $(date +"%D %T") $(whoami) $(uname -m) \
304    first usage of model ${m_n} | \
305   ${MAIL_COM} -s "first usage of model ${m_n}" \
306    ${m_m} >/dev/null 2>&1;
307   echo $(date +"%D %T") model ${m_n} >"${M_LOG}";
308  }
309#-
310# Extract the model components
311#-
312qi=0; while (( ${qi} < ${#m_c[@]} ))
313  do
314    ((qi=qi+1));
315    zc=${m_c[${qi}]}; zt=${m_t[${qi}]};
316    zp=${m_p[${qi}]}; zs=${m_s[${qi}]};
317    zd=${m_d[${qi}]}; zl=${m_l[${qi}]};
318    z7=${m_7[${qi}]};
319
320    # Check if the component is in the list of compents to exclude from installation
321    # If that's the case, continue to next component
322    if [ "X$( echo ${comp_to_exclude} | grep $z7 )" != "X" ] ; then
323        [[ ${m_v} = 'verbose' ]] && { echo Component ${z7} will not be extracted. ; }
324        continue
325    fi
326
327# Maybe change some information marked with DEFAULT.
328# Check if key word DEFAULT is used in component name
329    defcomp=$(echo ${zc} | awk -FDEFAULT: '{print $2}')
330    if [ X$defcomp != X ] ; then
331        if [ $changeok == 'yes' ] ; then
332            echo "=> Default component $defcomp can be changed."
333            echo "   Do you want to change this path ? Type new path or return for the above default."
334            read newcomp
335            echo "   Type revision number for chosen component version or return for $zt default value"
336            read newrev
337            if [ X$newcomp == X ] ; then
338                zc=$defcomp
339            else
340                zc=$newcomp
341            fi
342
343            if [ X$newrev != X ] ; then
344                zt=$newrev
345            fi
346        else
347            # changeok=no : Take default value#
348            zc=$defcomp
349        fi
350    fi
351    if [ ${m_v} == 'verbose' ] ; then
352       echo '---';
353       echo '--- Component  : '${zc};
354       echo '--- Tag        : '${zt};
355       echo '--- System     : '${zp};
356       echo '--- Server     : '${zs};
357       echo '--- Directory  : '${zd};
358       echo '--- Local Dir  : '${zl};
359       echo '--- Component name : '${z7};
360    else
361       echo '--- Component : '${zd};
362    fi
363#-----
364#----  Record information about the action in the "log" file
365#-----
366     { echo '---';
367       echo '--- Component  : '${zc};
368       echo '--- Tag        : '${zt};
369       echo '--- System     : '${zp};
370       echo '--- Server     : '${zs};
371       echo '--- Directory  : '${zd};
372       echo '--- Local Dir  : '${zl};
373       echo '--- Component name  : '${z7}; } >>"${F_LOG}"
374#---
375    [[ ${zp} = 'cvs' ]] && \
376     {
377      c_c='(cd '${d_m}/${zl}'; '${zp}' -d :pserver:'${zs}' '${m_a};
378      [[ ${zt} != '?' ]] && { c_c=${c_c}' -r '${zt}; }
379      [[ ${zd} != '.' ]] && { c_c=${c_c}' -d '${zd}; }
380      c_c=${c_c}' '${zc}')';
381      grep "${zs%%/*}"'.*/'"${zs#*/}" ~/.cvspass > /dev/null;
382      [[ ${?} != 0 ]] && \
383       {
384        c_z='cvs -d :pserver:'${zs}' login';
385        [[ ${m_v} = 'verbose' ]] && { echo ${c_z}; }
386        eval ${c_z};
387       }
388     }
389#---
390    [[ ${zp} = 'svn' ]] && \
391     {
392      c_c='(cd '${d_m}/${zl}'; '${zp}' '${m_a};
393      [[ ${zt} != '?' ]] && { c_c=${c_c}' -r '${zt}; }
394      c_c=${c_c}' '${zs}'/'${zc}@${zt};
395      [[ ${zd} != '.' ]] && { c_c=${c_c}' '${zd}; }
396      c_c=${c_c}')';
397     }
398#---
399    [[ ${zp} = 'git' ]] && \
400     {
401        c_c='(cd '${d_m}/${zl}' ; '${zp}'  clone  '${m_s[${qi}]}' '${zd}  ;
402        [[ ${zt} != 'HEAD' ]] && { c_c=${c_c}' ; cd '${zd}' ; '${zp}' '${m_a}' '${zt}; }
403        [[ ${zt} == 'HEAD' ]] && { c_c=${c_c}' ; cd '${zd}' ; '${zp}' '${m_a}' '${zc}; } 
404        c_c=${c_c}')';
405     }
406#---
407    [[ ${m_v} = 'verbose' ]] && { echo '--- Command    : '${c_c}; }
408    eval ${c_c};
409  done
410
411#-
412# Actions related to NEMOGCM
413#-
414
415case ${m_n} in
416     ( NEMO_v* | IPSLCM6* | IPSLESM6 | IPSLCM7* )
417    d_m1=${d_m}/modeles/NEMOGCM/CONFIG
418    cfg_file=${d_m1}/cfg.txt
419    list_cfg='ORCA1_LIM3_PISCES ORCA025_LIM3_PISCES ORCA1_OFF_PISCES eORCA025_LIM3 eORCA025_LIM3_PISCES_CRS'
420    # Creates configuration ORCA1_LIM3_PISCES
421    # (see https://forge.ipsl.jussieu.fr/shaconemo/wiki/README_ORCA1_LIM3_PISCES )
422    for cfg in ${list_cfg}
423       do
424        if [[ -d ${d_m1}/${cfg} ]] ; then
425           grep ${cfg} ${cfg_file} > /dev/null 2>&1
426           err=${?}
427           if [[ ${err} = 1 ]] ; then
428              pis=`echo ${cfg} | grep "PISCES" | wc -l`
429              off=`echo ${cfg} | grep "OFF"    | wc -l`
430              if [[ ${pis} = 1 ]] ; then
431                 if [[ ${off} = 1 ]] ; then
432                    echo "${cfg} OPA_SRC OFF_SRC TOP_SRC" >> ${cfg_file}
433                 else
434                    echo "${cfg} OPA_SRC LIM_SRC_3 NST_SRC TOP_SRC" >> ${cfg_file}
435                 fi
436              else
437                echo "${cfg} OPA_SRC LIM_SRC_3 NST_SRC" >> ${cfg_file}
438             fi
439           fi
440        fi
441     done
442esac
443
444#-
445# Actions related to the WORK directory for the OPA models
446#-
447case ${m_n} in
448  ( IPSLCM4_LOOP )
449    d_m1=${d_m}/modeles/OPA  ;
450    [ -d ${d_m1}/WORK ] && \rm -rf ${d_m1}/WORK;
451    mkdir ${d_m1}/WORK;
452    cd ${d_m1}/WORK;
453#-- Getting the configuration files to build the Makefile
454    ln -sf ../../../*/${m_n}/scripts/BB_make AA_make;
455    ln -sf ../../../*/${m_n}/scripts/BB_make.ldef AA_make.ldef ;
456    [ "${m_n}" = "IPSLCM4_LOOP" ] && \
457        echo " Creation du catalogue OPA/WORK = ORCA + LIM + TRC" || \
458        echo " Creation du catalogue OPA/WORK = ORCA + LIM"
459    ln -sf ../SRC_ORCA/*.[Ffh] .
460    [ "${m_n}" = "IPSLCM4_LOOP" ] && \rm *.passivetrc.h
461    [ "${m_n}" = "IPSLCM4_LOOP" ] && \
462        ln -sf ../SRC_TRC/*.[Ffh] ../SRC_TRC/trc_sms/*.[Ffh] .
463    ln -sf ../SRC_UCL/[a-z]* .
464#-- Building the standard list of source files
465    cat >.patron <<"EOF"
466CVS
467SRC_PARAM
468SRC_FILE_LIST
469tmplist
470AA_make
471KEY_CPP
472Makefile
473*?.o
474 i.?*
475*?.L
476.patron
477bloc.com
478para.com
479defcst.f
480fontbc.f
481icdyna.f
482thersf.f
483EOF
484    ls -1 | fgrep -v -f .patron  >SRC_FILE_LIST;
485    cp SRC_FILE_LIST SRC_FILE_LIST.temp;
486    KEY=$(grep P_P AA_make.ldef);
487    [ -f "KEY_CPP" ] || echo $KEY > KEY_CPP;
488  ;;
489  ( IPSLCM5A )
490  ../modeles/UTIL/fait_config IPSLCM5A ;;
491  ( IPSLCM5A_C )
492  ../modeles/UTIL/fait_config IPSLCM5A_C ;;
493  ( IPSLCM5B )
494  ../modeles/UTIL/fait_config IPSLCM5B ;;
495  ( IPSLCM5_v5 )
496  ../modeles/UTIL/fait_config IPSLCM5_v5 ;;
497  ( IPSLCM5CHS_v5 )
498  ../modeles/UTIL/fait_config IPSLCM5CHS_v5 ;;
499  ( IPSLCM5CHT_v5 )
500  ../modeles/UTIL/fait_config IPSLCM5CHT_v5 ;;
501esac
502
503case ${m_n} in ( IPSLCM7* )
504               if [ ${sub_conf} == "LMDZOR" ] ; then
505                   rm -fr ../config/IPSLCM7*/EXPERIMENTS/IPSLCM*
506                   rm -fr ../config/IPSLCM7*/EXPERIMENTS/ICOLMDZ*
507                   rm -fr ../config/IPSLCM7*/EXPERIMENTS/*INCA*
508               elif [ ${sub_conf} == "LMDZORINCA" ] ; then
509                   rm -fr ../config/IPSLCM7*/EXPERIMENTS/IPSLCM*
510                   rm -fr ../config/IPSLCM7*/EXPERIMENTS/ICOLMDZ*
511               elif [ ${sub_conf} == "ICOLMDZOR" ] ; then
512                   rm -fr ../config/IPSLCM7*/EXPERIMENTS/IPSLCM*
513                   rm -fr ../config/IPSLCM7*/EXPERIMENTS/*INCA*
514               elif [ ${sub_conf} == "ICOLMDZORINCA" ] ; then
515                   rm -fr ../config/IPSLCM7*/EXPERIMENTS/IPSLCM*
516               fi
517               ;;
518esac
519
520#--- Create Makefiles using the script ins_make
521#    ins_make will detect target machine among predefined targets in AA_make.gdef and
522#    create Makefiles to the corresponding target.
523#    ins_make can be re-run afterwards using another target or after editing the
524#    AA_make.gdef. ins_make will then overwrite Makefiles already created.
525#
526./ins_make
527
528#---
529#- That's all folks
530#---
531exit 0;
Note: See TracBrowser for help on using the repository browser.