1 | #!/bin/ksh |
---|
2 | # $Id$ |
---|
3 | #--------------------------------------------------------------------- |
---|
4 | #- Installation of jobs according to an environment |
---|
5 | #--------------------------------------------------------------------- |
---|
6 | function ins_job_Usage |
---|
7 | { |
---|
8 | print - " |
---|
9 | ins_job installs the jobs in the directories |
---|
10 | which contain a file config.card |
---|
11 | |
---|
12 | ins_job must be launched on the host |
---|
13 | on which the job will be submitted |
---|
14 | |
---|
15 | Usage : |
---|
16 | ${b_n} [-h] [-v] |
---|
17 | |
---|
18 | Options : |
---|
19 | -h : help |
---|
20 | -v : verbose mode |
---|
21 | " |
---|
22 | } |
---|
23 | function ins_job_Warning |
---|
24 | { |
---|
25 | print - "\n############### WARNING ###############"; |
---|
26 | print - "File ${n_f} already exists\nin directory ${j}"; |
---|
27 | print - "You must delete this file to update !"; |
---|
28 | } |
---|
29 | #- |
---|
30 | # dirname and basename |
---|
31 | #- |
---|
32 | d_n=$(dirname ${0}); b_n=$(basename ${0}); |
---|
33 | #- |
---|
34 | # Retrieving and validation of the options |
---|
35 | #- |
---|
36 | x_v='silencious'; |
---|
37 | while getopts :hv V |
---|
38 | do |
---|
39 | case $V in |
---|
40 | (h) ins_job_Usage; exit 0;; |
---|
41 | (v) x_v='verbose';; |
---|
42 | (:) echo ${b_n}" : -"${OPTARG}" option : missing value" 1>&2; |
---|
43 | exit 2;; |
---|
44 | (\?) echo ${b_n}" : -"${OPTARG}" option : not supported" 1>&2; |
---|
45 | exit 2;; |
---|
46 | esac |
---|
47 | done |
---|
48 | shift $(($OPTIND-1)); |
---|
49 | #- |
---|
50 | # Define working files |
---|
51 | #- |
---|
52 | F_MOD=$(cd ${d_n}'/..';/bin/pwd;) |
---|
53 | # [[ ${F_MOD##*/} != 'modipsl' ]] && \ |
---|
54 | # { print - "directory 'modipsl' unreachable"; exit 3; } |
---|
55 | W_W=${d_n}'/../libIGCM' |
---|
56 | [[ ! -d ${W_W} ]] && { print - "${W_W} unreachable"; exit 3; } |
---|
57 | libIGCM=$(cd ${W_W};/bin/pwd;) |
---|
58 | F_JOB=${libIGCM}'/AA_job'; |
---|
59 | [[ ! -f ${F_JOB} ]] && { print - "${F_JOB} unreachable"; exit 3; } |
---|
60 | F_RCI=${libIGCM}'/run.card.init'; |
---|
61 | [[ ! -f ${F_RCI} ]] && { print - "${F_RCI} unreachable"; exit 3; } |
---|
62 | #- |
---|
63 | # Host Name |
---|
64 | #- |
---|
65 | x_t=$(${d_n}/w_i_h) 2>/dev/null; |
---|
66 | { [[ ${?} != 0 ]] && \ |
---|
67 | { print - "\nw_i_h or uname unreachable\n" 1>&2; exit 1; }; } || \ |
---|
68 | [[ ${x_t} = "Unknown" ]] && \ |
---|
69 | { print - "\nLocal_Host not supported\n" 1>&2; exit 1; }; |
---|
70 | #- |
---|
71 | W_W=$(sed -n -e "s/^#-Q- *\([^ ]*\).*$/\1/p" ${F_JOB} | \ |
---|
72 | sort -u | sed -e "/${x_t}/!d"); |
---|
73 | [[ '\?'"${W_W}" != '\?'${x_t} ]] && \ |
---|
74 | { |
---|
75 | print - "\nHost "${x_t}" not supported" 1>&2; |
---|
76 | print - "'default' will be used" 1>&2; |
---|
77 | x_t='default' |
---|
78 | } |
---|
79 | #- |
---|
80 | [[ ${x_v} = 'verbose' ]] && \ |
---|
81 | { |
---|
82 | print - ""; |
---|
83 | print - '--- Host : '${x_t}; |
---|
84 | print - '--- modipsl : '${F_MOD}; |
---|
85 | print - '--- libIGCM : '${libIGCM}; |
---|
86 | print - '--- basic job : '${F_JOB}; |
---|
87 | print - '--- basic card : '${F_RCI}; |
---|
88 | } |
---|
89 | #- |
---|
90 | print - "\nInstallation of jobs for '${x_t}'"; |
---|
91 | #- |
---|
92 | # Accessing to functions (without stack) |
---|
93 | #- |
---|
94 | DEBUG_debug=false |
---|
95 | . ${libIGCM}/libIGCM_debug/libIGCM_debug.ksh |
---|
96 | . ${libIGCM}/libIGCM_card/libIGCM_card.ksh |
---|
97 | #- |
---|
98 | # Define the pattern string to substitute |
---|
99 | #- |
---|
100 | W_P='#-Q- '; W_W=${W_P}${x_t}; |
---|
101 | #- |
---|
102 | # Extract list of 'config.card' files |
---|
103 | # and create jobs with AA_job |
---|
104 | #- |
---|
105 | F_CFG='config.card'; |
---|
106 | for i in $(find ${d_n}/.. -name ${F_CFG} -print) |
---|
107 | do |
---|
108 | j=$(cd ${i%/*};/bin/pwd;) |
---|
109 | n_f=${F_RCI##*/}; |
---|
110 | |
---|
111 | if [ ! X$( echo ${j} | grep USER_SPEC ) = X ] ; then |
---|
112 | # Do not treat config.card if it is in sub-directory of USER_SPEC |
---|
113 | # Continue to next config.card |
---|
114 | continue |
---|
115 | else |
---|
116 | print - "\nWorking with file ${F_CFG}\nin directory ${j}\nfor ${n_f}"; |
---|
117 | fi |
---|
118 | |
---|
119 | # Get all variables declared in section UserChoices in config.card |
---|
120 | IGCM_card_DefineArrayFromSection ${j}'/'${F_CFG} UserChoices |
---|
121 | # Set default values |
---|
122 | config_UserChoices_JobClass=mono |
---|
123 | config_UserChoices_JobNumProcTot=1 |
---|
124 | config_UserChoices_UserSpec="" |
---|
125 | RESOL_ATM_3D=this_is_a_test_string |
---|
126 | RESOL=this_is_another_test_string |
---|
127 | typeset option |
---|
128 | for option in ${config_UserChoices[*]} ; do |
---|
129 | IGCM_card_DefineVariableFromOption ${j}'/'${F_CFG} UserChoices ${option} |
---|
130 | done |
---|
131 | |
---|
132 | # Find the JobName : JobName might contain the variable RESOL_ATM_3D that will be replaced by what is in .resol file |
---|
133 | if [ ! X$( echo ${config_UserChoices_JobName} | grep ${RESOL_ATM_3D} ) = X ] ; then |
---|
134 | TRUERESOL=$( find ../ -name ".resol" -exec tail -1 {} \; | awk "-F=" '{print $2}' ) |
---|
135 | JobName=$( echo ${config_UserChoices_JobName} | sed -e "s/${RESOL_ATM_3D}/${TRUERESOL}/" ) |
---|
136 | IGCM_card_WriteOption ${j}'/'${F_CFG} UserChoices JobName ${JobName} |
---|
137 | elif [ ! X$( echo ${config_UserChoices_JobName} | grep ${RESOL} ) = X ] ; then |
---|
138 | TRUERESOL=$( find ../ -name ".resol" -exec head -1 {} \; ) |
---|
139 | JobName=$( echo ${config_UserChoices_JobName} | sed -e "s/${RESOL}/${TRUERESOL}/" ) |
---|
140 | IGCM_card_WriteOption ${j}'/'${F_CFG} UserChoices JobName ${JobName} |
---|
141 | else |
---|
142 | JobName=${config_UserChoices_JobName} |
---|
143 | fi |
---|
144 | echo "JobName=${JobName}" |
---|
145 | |
---|
146 | # Add specific treatment for new type of directory structure |
---|
147 | if [ -d ${j}/USER_SPEC ] && [ -d ${j}/GENERAL ] ; then |
---|
148 | echo "This is new configuration structure" |
---|
149 | |
---|
150 | if [ "X${config_UserChoices_UserSpec}" = X ] ; then |
---|
151 | echo "\nERROR in ${j}/config.card" |
---|
152 | echo "ins_job stops here" |
---|
153 | echo "=> The variable UserSpec must be added in config.card in section UserChoices" |
---|
154 | echo "=> UserSpec gives the directory for the .card configurtaion files for the wanted experiement. For exemple UserSpec=IPSLCM5/historical" |
---|
155 | exit 4 |
---|
156 | else |
---|
157 | echo "UserSpec= ${config_UserChoices_UserSpec}" |
---|
158 | fi |
---|
159 | |
---|
160 | if [ -d ${j}/${JobName} ] ; then |
---|
161 | echo "Directory ${j}/${JobName} exist already, continue next config.card" |
---|
162 | continue |
---|
163 | fi |
---|
164 | cp -r ${j}/USER_SPEC/${config_UserChoices_UserSpec} ${j}/${JobName} |
---|
165 | cp -r ${j}/GENERAL/* ${j}/${JobName}/. |
---|
166 | cp -f ${j}/${F_CFG} ${j}/${JobName}/. |
---|
167 | j=${j}/${JobName} |
---|
168 | echo new j=$j |
---|
169 | fi |
---|
170 | # end specific treatment for new type directory structure |
---|
171 | |
---|
172 | [[ -f ${j}'/'${n_f} ]] && { ins_job_Warning; } || \ |
---|
173 | { |
---|
174 | print - "\nCopying file ${F_RCI}\nin directory ${j}"; |
---|
175 | \cp ${F_RCI} ${j}; |
---|
176 | } |
---|
177 | |
---|
178 | # File name for Job |
---|
179 | n_f='Job_'${JobName}; |
---|
180 | [[ -f ${j}'/'${n_f} ]] && { ins_job_Warning; continue; } |
---|
181 | print - "\nWorking with file ${F_CFG}\nin directory ${j}\nfor ${n_f}"; |
---|
182 | sed -e "/^${W_W} */ s///" \ |
---|
183 | -e "/^${W_P}/d" \ |
---|
184 | -e "s%::modipsl::%${F_MOD}%" \ |
---|
185 | -e "s/::Jobname::/${JobName}/" \ |
---|
186 | -e "s/::JobClass::/${config_UserChoices_JobClass}/" \ |
---|
187 | -e "s/::JobNumProcTot::/${config_UserChoices_JobNumProcTot}/" \ |
---|
188 | ${F_JOB} > ${j}'/'${n_f} |
---|
189 | chmod u+x ${j}'/'${n_f} |
---|
190 | done |
---|
191 | #- |
---|
192 | # Extract list of AA_* files in libIGCM |
---|
193 | # and create jobs (for all except AA_job) |
---|
194 | #- |
---|
195 | for i in $(find ${libIGCM} -name "AA_*" -print | grep -v .svn ) |
---|
196 | do |
---|
197 | i_f=${i##*/}; |
---|
198 | [[ ${i_f} = 'AA_job' ]] && { continue; } |
---|
199 | j=${i%/*}; n_f=${i_f#AA_}'.job'; |
---|
200 | [[ -f ${j}'/'${n_f} ]] && { ins_job_Warning; continue; } |
---|
201 | print - "\nIn directory ${j}\n${i_f} -> ${n_f}" |
---|
202 | sed -e "/^${W_W} */ s///" \ |
---|
203 | -e "s%::modipsl::%${F_MOD}%" \ |
---|
204 | -e "/^${W_P}/d" \ |
---|
205 | ${i} > ${j}'/'${n_f} |
---|
206 | chmod u+x ${j}'/'${n_f} |
---|
207 | done |
---|
208 | #- |
---|
209 | print - ""; |
---|
210 | #- |
---|
211 | # That's all folks |
---|
212 | #- |
---|
213 | exit 0; |
---|