source: modipsl/trunk/util/model @ 6679

Last change on this file since 6679 was 6679, checked in by jgipsl, 7 months ago

Update comment

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