source: modipsl/trunk/util/model @ 6757

Last change on this file since 6757 was 6728, checked in by jgipsl, 4 months ago

Add ORCHIDEE_OL (ORCHIDEE offline configuration) as possible sub configuration to IPSLCM7

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