source: modipsl/trunk/util/ins_job @ 91

Last change on this file since 91 was 91, checked in by bellier, 17 years ago

JB: add ins_job

  • Property svn:executable set to *
File size: 3.4 KB
Line 
1#!/bin/ksh
2# $Id$
3#---------------------------------------------------------------------
4#- Installation of jobs according to an environment
5#---------------------------------------------------------------------
6function ins_job_Usage
7{
8echo "
9ins_job installs the jobs in the directories
10which contain a file config.card
11
12ins_job must be launched on the host
13on which the job will be submitted
14
15Usage :
16  ${b_n} [-h] [-v]
17
18Options :
19  -h   : help
20  -v   : verbose mode
21"
22}
23#-
24#   dirname and  basename
25#-
26d_n=${0%/*}; b_n=${0##*/};
27#-
28# Retrieving and validation of the options
29#-
30x_v='silencious';
31while getopts :hv V
32  do
33   case $V in
34    (h)  ins_job_Usage; exit 0;;
35    (v)  x_v='verbose';;
36    (:)  echo ${b_n}" : -"${OPTARG}" option : missing value" 1>&2;
37         exit 2;;
38    (\?) echo ${b_n}" : -"${OPTARG}" option : not supported" 1>&2;
39         exit 2;;
40    esac
41  done
42shift $(($OPTIND-1));
43#-
44# Define working files
45#-
46F_MOD=$(cd ${d_n}'/..';pwd)
47[[ ${F_MOD##*/} != 'modipsl' ]] && \
48 { print - "directory 'modipsl' unreachable"; exit 3; }
49W_W=${d_n}'/../libIGCM'
50[[ ! -d ${W_W} ]] && { print - "${W_W} unreachable"; exit 3; }
51libIGCM=$(cd ${W_W};pwd)
52F_JOB=${libIGCM}'/AA_job';
53[[ ! -f ${F_JOB} ]] && { print - "${F_JOB} unreachable"; exit 3; }
54F_RCI=${libIGCM}'/run.card.init';
55[[ ! -f ${F_RCI} ]] && { print - "${F_RCI} unreachable"; exit 3; }
56#-
57# Host Name
58#-
59x_t=$(${d_n}/w_i_h) 2>/dev/null;
60{ [[ ${?} != 0 ]] && \
61   { print - "\nw_i_h or uname unreachable\n" 1>&2; exit 1; }; } || \
62  [[ ${x_t} = "Unknown" ]] && \
63   { print - "\nLocal_Host not supported\n" 1>&2; exit 1; };
64#-
65W_W=$(sed -n -e "s/^#-Q-  *\([^ ]*\).*$/\1/p" ${F_JOB} | \
66       sort -u | sed -e "/${x_t}/!d");
67[[ '\?'"${W_W}" != '\?'${x_t} ]] && \
68  {
69   print - "\nHost  "${x_t}"  not supported" 1>&2;
70   print - "'default' will be used" 1>&2;
71   x_t='default'
72  }
73#-
74[[ ${x_v} = 'verbose' ]] && \
75 {
76  print - "";
77  print - '--- Host        : '${x_t};
78  print - '--- modipsl     : '${F_MOD};
79  print - '--- libIGCM     : '${libIGCM};
80  print - '--- basic job   : '${F_JOB};
81  print - '--- basic card  : '${F_RCI};
82 }
83#-
84print - "\nInstallation of jobs for '${x_t}'";
85#-
86# Accessing to functions (without stack)
87#-
88DEBUG_debug=false
89. ${libIGCM}/libIGCM_debug/libIGCM_debug.ksh
90. ${libIGCM}/libIGCM_card/libIGCM_card.ksh
91#-
92# Extract list of 'config.card' files
93# and create jobs with AA_job
94#-
95F_CFG='config.card';
96l_cfg=$(find ${d_n}/.. -name ${F_CFG} -print)
97for i in ${l_cfg}
98do
99  j=$(cd ${i%/*};pwd)
100  \cp ${F_RCI} ${j}
101# IGCM_card_DefineArrayFromSection ${j}'/'${F_CFG} UserChoices
102  IGCM_card_DefineVariableFromOption ${j}'/'${F_CFG} UserChoices JobName
103  print - "\nWorking with file ${F_CFG}";
104  print - "in directory ${j}";
105  print - "for Job_${config_UserChoices_JobName}"
106  W_P='#-Q- '; W_W=${W_P}${x_t};
107  sed -e "/^${W_W} */ s///" \
108      -e "/^${W_P}/d"       \
109      -e "s%::modipsl::%${F_MOD}%" \
110      -e "s/::Jobname::/${config_UserChoices_JobName}/" \
111      ${F_JOB} > ${j}'/Job_'${config_UserChoices_JobName}
112done
113#-
114# Extract list of AA_* files in libIGCM
115# and create jobs (but not with AA_job
116#-
117l_cfg=$(find ${libIGCM} -name "AA_*" -print)
118for i in ${l_cfg}
119do
120  i_f=${i##*/};
121  [[ ${i_f} = 'AA_job' ]] && continue
122  i_d=${i%/*}; n_f=${i_f#AA_}'.job';
123  print - "\nIn directory ${i_d}\n${i_f} -> ${n_f}"
124  sed -e "/^${W_W} */ s///" \
125      -e "/^${W_P}/d"       \
126      ${i} > ${i_d}'/'${n_f}
127done
128#-
129# That's all folks
130#-
131exit 0;
Note: See TracBrowser for help on using the repository browser.