source: modipsl/trunk/util/ins_job @ 1618

Last change on this file since 1618 was 1618, checked in by jgipsl, 13 years ago

Added specific treatment if new configuration structure :
if the directory USER_SPEC and GENERAL exist beside the config.card, then create new run directory. This is the case for the configuration IPSLCM5_v4.

Noting change if old configuration structure.

  • Property svn:executable set to *
  • Property svn:keywords set to Id
File size: 6.7 KB
Line 
1#!/bin/ksh
2# $Id$
3#---------------------------------------------------------------------
4#- Installation of jobs according to an environment
5#---------------------------------------------------------------------
6function ins_job_Usage
7{
8print - "
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}
23function 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#-
32d_n=$(dirname ${0}); b_n=$(basename ${0});
33#-
34# Retrieving and validation of the options
35#-
36x_v='silencious';
37while 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
48shift $(($OPTIND-1));
49#-
50# Define working files
51#-
52F_MOD=$(cd ${d_n}'/..';/bin/pwd;)
53# [[ ${F_MOD##*/} != 'modipsl' ]] && \
54#  { print - "directory 'modipsl' unreachable"; exit 3; }
55W_W=${d_n}'/../libIGCM'
56[[ ! -d ${W_W} ]] && { print - "${W_W} unreachable"; exit 3; }
57libIGCM=$(cd ${W_W};/bin/pwd;)
58F_JOB=${libIGCM}'/AA_job';
59[[ ! -f ${F_JOB} ]] && { print - "${F_JOB} unreachable"; exit 3; }
60F_RCI=${libIGCM}'/run.card.init';
61[[ ! -f ${F_RCI} ]] && { print - "${F_RCI} unreachable"; exit 3; }
62#-
63# Host Name
64#-
65x_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#-
71W_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#-
90print - "\nInstallation of jobs for '${x_t}'";
91#-
92# Accessing to functions (without stack)
93#-
94DEBUG_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#-
100W_P='#-Q- '; W_W=${W_P}${x_t};
101#-
102# Extract list of 'config.card' files
103# and create jobs with AA_job
104#-
105F_CFG='config.card';
106for i in $(find ${d_n}/.. -name ${F_CFG} -print)
107do
108 j=$(cd ${i%/*};/bin/pwd;)
109 n_f=${F_RCI##*/};
110 print - "\nWorking with file ${F_CFG}\nin directory ${j}\nfor ${n_f}";
111
112# Add specific treatment for new type of directory structure
113  if [ ! X$( echo ${j} | grep USER_SPEC ) = X ] ; then
114      echo "USER_SPEC directory exist in path, do not use this config.card"
115      continue
116  fi
117
118  if [ -d ${j}/USER_SPEC ] && [ -d ${j}/GENERAL ] ; then
119      echo "This is new configuration structure"
120      IGCM_card_DefineVariableFromOption ${j}'/'${F_CFG} UserChoices JobName
121      IGCM_card_DefineVariableFromOption ${j}'/'${F_CFG} UserChoices UserSpec
122      echo "JobName=${config_UserChoices_JobName}"
123      if [ X${config_UserChoices_UserSpec} = X ] ; then
124        echo "The variable UserSpec must be added in config.card in section UserChoices"
125        echo "UserSpec gives the directory for the .card configurtaion files for the wanted experiement. For exemple UserSpec=IPSLCM5/historical"
126        echo "UserSpec= $Config_UserChoices_UserSpec "
127        continue
128      else
129        echo "UserSpec= $Config_UserChoices_UserSpec "
130      fi
131
132      if [ -d ${j}/${config_UserChoices_JobName} ] ; then
133          echo "Directory ${j}/${config_UserChoices_JobName} exist already, continue next config.card"
134          continue
135      fi
136      cp -r ${j}/USER_SPEC/${config_UserChoices_UserSpec} ${j}/${config_UserChoices_JobName}
137      cp -r ${j}/GENERAL/* ${j}/${config_UserChoices_JobName}/.
138      cp -f ${j}/${F_CFG}  ${j}/${config_UserChoices_JobName}/.
139      j=${j}/${config_UserChoices_JobName}
140      echo new j=$j
141  fi
142# end specific treatment for new type directory structure
143
144 [[ -f ${j}'/'${n_f} ]] && { ins_job_Warning; } || \
145  {
146   print - "\nCopying file ${F_RCI}\nin directory ${j}";
147   \cp ${F_RCI} ${j};
148  }
149 # We keep explicitly JobName because it is not optionnal.
150 RESOL_ATM_3D=this_is_a_test_string
151 RESOL=this_is_another_test_string
152 IGCM_card_DefineVariableFromOption ${j}'/'${F_CFG} UserChoices JobName
153 if [ ! X$( echo ${config_UserChoices_JobName} | grep ${RESOL_ATM_3D} ) = X ] ; then
154    TRUERESOL=$( find ../ -name ".resol" -exec tail -1 {} \; | awk "-F=" '{print $2}' )
155    config_UserChoices_JobName=$( echo ${config_UserChoices_JobName} | sed -e "s/${RESOL_ATM_3D}/${TRUERESOL}/" )
156    IGCM_card_WriteOption ${j}'/'${F_CFG} UserChoices JobName ${config_UserChoices_JobName}
157 else
158    if [ ! X$( echo ${config_UserChoices_JobName} | grep ${RESOL} ) = X ] ; then
159            TRUERESOL=$( find ../ -name ".resol" -exec head -1 {} \; )
160            config_UserChoices_JobName=$( echo ${config_UserChoices_JobName} | sed -e "s/${RESOL}/${TRUERESOL}/" )
161            IGCM_card_WriteOption ${j}'/'${F_CFG} UserChoices JobName ${config_UserChoices_JobName}
162    fi
163 fi
164 
165 # Other options are not always needed
166 IGCM_card_DefineArrayFromSection ${j}'/'${F_CFG} UserChoices
167 # Default values
168 config_UserChoices_JobClass=mono
169 config_UserChoices_JobNumProcTot=1
170 # config.card optionnal values
171 typeset option
172 for option in ${config_UserChoices[*]} ; do
173     IGCM_card_DefineVariableFromOption ${j}'/'${F_CFG} UserChoices ${option}
174 done
175 # File name for Job
176 n_f='Job_'${config_UserChoices_JobName};
177 [[ -f ${j}'/'${n_f} ]] && { ins_job_Warning; continue; }
178 print - "\nWorking with file ${F_CFG}\nin directory ${j}\nfor ${n_f}";
179 sed -e "/^${W_W} */ s///" \
180     -e "/^${W_P}/d"       \
181     -e "s%::modipsl::%${F_MOD}%" \
182     -e "s/::Jobname::/${config_UserChoices_JobName}/" \
183     -e "s/::JobClass::/${config_UserChoices_JobClass}/" \
184     -e "s/::JobNumProcTot::/${config_UserChoices_JobNumProcTot}/" \
185     ${F_JOB} > ${j}'/'${n_f}
186 chmod u+x ${j}'/'${n_f}
187done
188#-
189# Extract list of AA_* files in libIGCM
190# and create jobs (for all except AA_job)
191#-
192for i in $(find ${libIGCM} -name "AA_*" -print | grep -v .svn )
193do
194 i_f=${i##*/};
195 [[ ${i_f} = 'AA_job' ]] && { continue; }
196 j=${i%/*}; n_f=${i_f#AA_}'.job';
197 [[ -f ${j}'/'${n_f} ]] && { ins_job_Warning; continue; }
198 print - "\nIn directory ${j}\n${i_f} -> ${n_f}"
199 sed -e "/^${W_W} */ s///" \
200     -e "s%::modipsl::%${F_MOD}%" \
201     -e "/^${W_P}/d"       \
202     ${i} > ${j}'/'${n_f}
203 chmod u+x ${j}'/'${n_f}
204done
205#-
206print - "";
207#-
208# That's all folks
209#-
210exit 0;
Note: See TracBrowser for help on using the repository browser.