1 | #!/bin/ksh |
---|
2 | |
---|
3 | #************************************************************** |
---|
4 | # Author: Patrick Brockmann, Martial Mancip |
---|
5 | # Contact: Patrick.Brockmann__at__cea.fr Martial.Mancip__at__ipsl.jussieu.fr |
---|
6 | # $Revision:: $ Revision of last commit |
---|
7 | # $Author:: $ Author of last commit |
---|
8 | # $Date:: $ Date of last commit |
---|
9 | # IPSL (2006) |
---|
10 | # This software is governed by the CeCILL licence see libIGCM/libIGCM_CeCILL.LIC |
---|
11 | # |
---|
12 | #************************************************************** |
---|
13 | |
---|
14 | #================================================== |
---|
15 | # The documentation of this file can be automatically generated |
---|
16 | # if you use the prefix #D- for comments to be extracted. |
---|
17 | # Extract with command: cat lib* | grep "^#D-" | cut -c "4-" |
---|
18 | #================================================== |
---|
19 | |
---|
20 | #================================================== |
---|
21 | # Add high level verbosity |
---|
22 | typeset -i Verbosity=${Verbosity:=3} |
---|
23 | |
---|
24 | #================================================== |
---|
25 | # DEBUG_debug |
---|
26 | # Add low level verbosity |
---|
27 | typeset DEBUG_debug=${DEBUG_debug:=false} |
---|
28 | |
---|
29 | # Where the stack file containing call tree will be stored. |
---|
30 | typeset StackFileLocation=${StackFileLocation:=${PWD}} |
---|
31 | |
---|
32 | if ( $DEBUG_debug ) ; then |
---|
33 | if [ -f ${StackFileLocation}/stack ] ; |
---|
34 | then |
---|
35 | echo "Stack of an libIGCM job :" >> ${StackFileLocation}/stack |
---|
36 | else |
---|
37 | echo "Stack of an libIGCM job :" > ${StackFileLocation}/stack |
---|
38 | fi |
---|
39 | fi |
---|
40 | |
---|
41 | #================================================== |
---|
42 | # NULL_STR |
---|
43 | # Default null string |
---|
44 | typeset -r NULL_STR="_0_" |
---|
45 | |
---|
46 | #================================================== |
---|
47 | # libIGCM_CurrentTag |
---|
48 | # Current libIGCM tag, check compatibilty with *.card |
---|
49 | typeset -r libIGCM_CurrentTag="1.0" |
---|
50 | |
---|
51 | #================================================== |
---|
52 | # Exit Flag (internal debug) |
---|
53 | # When true, end the master loop AFTER SAVES FILES |
---|
54 | ExitFlag=false |
---|
55 | |
---|
56 | #================================================== |
---|
57 | # Declare a stack of functions calls |
---|
58 | |
---|
59 | # insert last argument of the Stack |
---|
60 | #set -A IGCM_debug_Stack ${NULL_STR} |
---|
61 | #set -A IGCM_debug_StackArgs ${NULL_STR} |
---|
62 | unset IGCM_debug_Stack |
---|
63 | unset IGCM_debug_StackArgs |
---|
64 | IGCM_debug_Stack[0]=${NULL_STR} |
---|
65 | IGCM_debug_StackArgs[0]=${NULL_STR} |
---|
66 | IGCM_debug_LenStack=0 |
---|
67 | |
---|
68 | #D-#================================================================== |
---|
69 | #D-function IGCM_debug_CallStack |
---|
70 | #D-* Purpose: Echo the Stack |
---|
71 | #D- |
---|
72 | function IGCM_debug_CallStack { |
---|
73 | echo |
---|
74 | echo "!!!!!!!!!!!!!!!!!!!!!!!!!!" |
---|
75 | echo "!! IGCM_debug_CallStack !!" |
---|
76 | echo "!------------------------!" |
---|
77 | echo |
---|
78 | if ( $DEBUG_debug ) ; then |
---|
79 | # La pile d'appels est affichée de la plus vieille à la plus récente |
---|
80 | # (c'est donc l'inverse de la norme d'affichage). |
---|
81 | typeset i decal |
---|
82 | i=0 |
---|
83 | until [ $i -eq ${IGCM_debug_LenStack} ]; do |
---|
84 | decal=0 |
---|
85 | until [ $decal -eq ${i} ]; do |
---|
86 | printf -- ' ' |
---|
87 | (( decal = decal + 1 )) |
---|
88 | done |
---|
89 | echo "$i - ${IGCM_debug_Stack[$(( $IGCM_debug_LenStack-$i-1 ))]}"\ |
---|
90 | "(${IGCM_debug_StackArgs[$(( $IGCM_debug_LenStack-$i-1 ))]})" |
---|
91 | ((i = i + 1)) |
---|
92 | done |
---|
93 | echo "!------------------------!" |
---|
94 | fi |
---|
95 | } |
---|
96 | |
---|
97 | #D-#================================================================== |
---|
98 | #D-function IGCM_debug_PushStack |
---|
99 | #D-* Purpose: Push a function name in the stack |
---|
100 | #D- |
---|
101 | function IGCM_debug_PushStack { |
---|
102 | if ( $DEBUG_debug ) ; then |
---|
103 | typeset decal inputs |
---|
104 | echo >> ${StackFileLocation}/stack |
---|
105 | decal=0 |
---|
106 | while [ ${decal} -lt ${IGCM_debug_LenStack} ]; do |
---|
107 | printf ' ' >> ${StackFileLocation}/stack |
---|
108 | (( decal = decal + 1 )) |
---|
109 | done |
---|
110 | echo "> ${IGCM_debug_LenStack} : ${@}" >> ${StackFileLocation}/stack |
---|
111 | |
---|
112 | # STORE input list in an indexed array |
---|
113 | INPUTS=( $@ ) |
---|
114 | # We add function call name on beginning of the stack |
---|
115 | set +A IGCM_debug_Stack -- ${1} ${IGCM_debug_Stack[*]} |
---|
116 | |
---|
117 | # We include the "null" Args in the beginning of the StackArgs |
---|
118 | set +A IGCM_debug_StackArgs ${NULL_STR} ${IGCM_debug_StackArgs[*]} |
---|
119 | # Then, we shift StackArgs tabular |
---|
120 | if [ $# -gt 1 ]; then |
---|
121 | IGCM_debug_StackArgs[0]=$(echo ${INPUTS[*]:1} | sed -e "s/\ /,/g") |
---|
122 | fi |
---|
123 | (( IGCM_debug_LenStack = IGCM_debug_LenStack + 1 )) |
---|
124 | |
---|
125 | # If you want to print CallStack each time : |
---|
126 | # IGCM_debug_CallStack |
---|
127 | fi |
---|
128 | } |
---|
129 | |
---|
130 | #D-#================================================================== |
---|
131 | #D-function IGCM_debug_PopStack |
---|
132 | #D-* Purpose: Pop a function name in the stack |
---|
133 | #D- |
---|
134 | function IGCM_debug_PopStack { |
---|
135 | if ( $DEBUG_debug ) ; then |
---|
136 | if ( ${ExitFlag} ) ; then |
---|
137 | echo '!!! ExitFlag has been activated !!!' >> ${StackFileLocation}/stack |
---|
138 | fi |
---|
139 | typeset decal |
---|
140 | if [ "${IGCM_debug_Stack[0]}" = "${1}" ]; then |
---|
141 | (( IGCM_debug_LenStack = IGCM_debug_LenStack - 1 )) |
---|
142 | set -A IGCM_debug_Stack -- ${IGCM_debug_Stack[*]:1} |
---|
143 | set -A IGCM_debug_StackArgs -- ${IGCM_debug_StackArgs[*]:1} |
---|
144 | else |
---|
145 | echo 'IGCM_debug_Exit : stack is corrupted ! LenStack =' ${IGCM_debug_LenStack} |
---|
146 | IGCM_debug_Exit $@ |
---|
147 | fi |
---|
148 | decal=0 |
---|
149 | while [ ${decal} -lt ${IGCM_debug_LenStack} ]; do |
---|
150 | printf ' ' >> ${StackFileLocation}/stack |
---|
151 | (( decal = decal + 1 )) |
---|
152 | done |
---|
153 | echo "< ${IGCM_debug_LenStack} : ${@}" >> ${StackFileLocation}/stack |
---|
154 | |
---|
155 | if [ ${IGCM_debug_LenStack} = 0 ]; then |
---|
156 | # Reset array only when necessary |
---|
157 | #echo |
---|
158 | #IGCM_debug_Print 3 "Clean stack array" |
---|
159 | #echo |
---|
160 | #set -A IGCM_debug_Stack ${NULL_STR} |
---|
161 | #set -A IGCM_debug_StackArgs ${NULL_STR} |
---|
162 | unset IGCM_debug_Stack |
---|
163 | unset IGCM_debug_StackArgs |
---|
164 | IGCM_debug_Stack[0]=${NULL_STR} |
---|
165 | IGCM_debug_StackArgs[0]=${NULL_STR} |
---|
166 | fi |
---|
167 | fi |
---|
168 | #IGCM_debug_CallStack |
---|
169 | } |
---|
170 | |
---|
171 | #D-#================================================================== |
---|
172 | #D-function IGCM_debug_Exit |
---|
173 | #D-* Purpose: Print Call Stack and set ExitFlag to true |
---|
174 | #D- |
---|
175 | function IGCM_debug_Exit { |
---|
176 | IGCM_debug_PushStack "IGCM_debug_Exit" |
---|
177 | echo "IGCM_debug_Exit : " "${@}" |
---|
178 | IGCM_debug_CallStack |
---|
179 | ExitFlag=true |
---|
180 | IGCM_debug_PopStack "IGCM_debug_Exit" |
---|
181 | } |
---|
182 | |
---|
183 | #D-#================================================== |
---|
184 | #D-function IGCM_debug_Verif_Exit |
---|
185 | #D-* Purpose: exit with number 1 if ExitFlag is true |
---|
186 | #D- |
---|
187 | function IGCM_debug_Verif_Exit { |
---|
188 | if ( ${ExitFlag} ) ; then |
---|
189 | # Plan to send an email here with IGCM_sys_SendMail |
---|
190 | if [ X${TaskType} != Xchecking ] ; then |
---|
191 | IGCM_card_WriteOption ${SUBMIT_DIR}/run.card Configuration PeriodState "Fatal" |
---|
192 | echo "IGCM_debug_Verif_Exit : Something wrong happened." |
---|
193 | echo " EXIT THE JOB." |
---|
194 | echo |
---|
195 | fi |
---|
196 | if ( $DEBUG_debug ) ; then |
---|
197 | echo "Your files on ${R_OUT} :" |
---|
198 | IGCM_sys_Tree ${R_SAVE} |
---|
199 | echo |
---|
200 | fi |
---|
201 | # Mail notification |
---|
202 | IGCM_sys_SendMail |
---|
203 | # And Good Bye |
---|
204 | date |
---|
205 | exit 1 |
---|
206 | fi |
---|
207 | } |
---|
208 | |
---|
209 | #D-#================================================== |
---|
210 | #D-function IGCM_debug_Verif_Exit_Post |
---|
211 | #D-* Purpose: exit with number 1 if ExitFlag is true for Post-treatment |
---|
212 | #D- |
---|
213 | function IGCM_debug_Verif_Exit_Post { |
---|
214 | if ( ${ExitFlag} ) ; then |
---|
215 | echo "IGCM_debug_Verif_Exit_Post : Something wrong happened." |
---|
216 | # If SpaceName is PROD then we stop if post_processing fails |
---|
217 | # Plan to send an email here with IGCM_sys_SendMail |
---|
218 | if [ X${config_UserChoices_SpaceName} = XPROD ] ; then |
---|
219 | echo " EXIT THE JOB." |
---|
220 | echo |
---|
221 | # Mail notification |
---|
222 | #IGCM_sys_SendMailPost |
---|
223 | # And Good Bye |
---|
224 | date |
---|
225 | exit 1 |
---|
226 | else |
---|
227 | echo "Either inside config.card the variable SpaceName is not in PROD" |
---|
228 | echo "or inside the main Job the variable JobType is not in RUN mode" |
---|
229 | echo " SO WE DO NOT EXIT THE JOB." |
---|
230 | echo |
---|
231 | date |
---|
232 | fi |
---|
233 | fi |
---|
234 | } |
---|
235 | |
---|
236 | #D-#================================================================== |
---|
237 | #D-function IGCM_debug_Print |
---|
238 | #D-* Purpose: Print arguments according to a level of verbosity. |
---|
239 | #D- |
---|
240 | function IGCM_debug_Print |
---|
241 | { |
---|
242 | typeset level=$1 |
---|
243 | shift |
---|
244 | |
---|
245 | if [ X"${1}" = X"-e" ]; then |
---|
246 | typeset cmd_echo="echo -e" |
---|
247 | shift |
---|
248 | else |
---|
249 | typeset cmd_echo="echo" |
---|
250 | fi |
---|
251 | |
---|
252 | if [ ${level} -le ${Verbosity} ] ; then |
---|
253 | typeset i |
---|
254 | case "${level}" in |
---|
255 | 1) for i in "$@" ; do |
---|
256 | ${cmd_echo} $(date +"%Y-%m-%d %T") "--Debug1-->" ${i} |
---|
257 | done ;; |
---|
258 | 2) for i in "$@" ; do |
---|
259 | ${cmd_echo} $(date +"%Y-%m-%d %T") "--------Debug2-->" ${i} |
---|
260 | done ;; |
---|
261 | 3) for i in "$@" ; do |
---|
262 | ${cmd_echo} $(date +"%Y-%m-%d %T") "--------------Debug3-->" ${i} |
---|
263 | done ;; |
---|
264 | esac |
---|
265 | fi |
---|
266 | } |
---|
267 | |
---|
268 | #D-#================================================================== |
---|
269 | #D-function IGCM_debug_PrintVariables |
---|
270 | #D-* Purpose: Print arguments when match a pattern |
---|
271 | #D- according to a level of verbosity. |
---|
272 | function IGCM_debug_PrintVariables |
---|
273 | { |
---|
274 | typeset level=$1 |
---|
275 | shift |
---|
276 | |
---|
277 | list=$( set | grep ^$1 | sed -e "s/'//g" ) |
---|
278 | |
---|
279 | if [ "X${list}" != X ] ; then |
---|
280 | IGCM_debug_Print ${level} ${list} |
---|
281 | fi |
---|
282 | } |
---|
283 | |
---|
284 | #D-#================================================================== |
---|
285 | #D-function IGCM_debug_Check |
---|
286 | #D- * Purpose: Check the present file by comparison with a reference file |
---|
287 | function IGCM_debug_Check |
---|
288 | { |
---|
289 | #--------------------- |
---|
290 | if [ ! -n "${libIGCM}" ] ; then |
---|
291 | echo "Check libIGCM_debug ..........................................[ FAILED ]" |
---|
292 | echo "--Error--> libIGCM variable is not defined" |
---|
293 | exit 2 |
---|
294 | fi |
---|
295 | |
---|
296 | #--------------------- |
---|
297 | if [ ! -n "${Verbosity}" ] ; then |
---|
298 | echo "Check libIGCM_debug ..........................................[ FAILED ]" |
---|
299 | echo "--Error--> Verbosity variable is not defined" |
---|
300 | exit 3 |
---|
301 | fi |
---|
302 | |
---|
303 | #--------------------- |
---|
304 | ${libIGCM}/libIGCM_debug/IGCM_debug_Test.ksh > IGCM_debug_Test.ref.failed 2>&1 |
---|
305 | sleep 2 |
---|
306 | |
---|
307 | # Remove date stamp. |
---|
308 | sed -e "s:[0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9] [0-9][0-9]\:[0-9][0-9]\:[0-9][0-9] ::g" IGCM_debug_Test.ref.failed > IGCM_debug_Test.ref.failed.nodate |
---|
309 | mv IGCM_debug_Test.ref.failed.nodate IGCM_debug_Test.ref.failed |
---|
310 | |
---|
311 | if diff IGCM_debug_Test.ref.failed ${libIGCM}/libIGCM_debug/IGCM_debug_Test.ref > /dev/null 2>&1 ; then |
---|
312 | echo "Check libIGCM_debug ..............................................[ OK ]" |
---|
313 | rm -f IGCM_debug_Test.ref.failed |
---|
314 | else |
---|
315 | echo "Check libIGCM_debug ..........................................[ FAILED ]" |
---|
316 | echo "--Error--> Execution of ${libIGCM}/libIGCM_debug/IGCM_debug_Test.ksh" |
---|
317 | echo " has produced the file IGCM_debug_Test.ref.failed" |
---|
318 | echo " Please analyse differences with the reference file by typing:" |
---|
319 | echo " diff IGCM_debug_Test.ref.failed ${libIGCM}/libIGCM_debug/IGCM_debug_Test.ref" |
---|
320 | echo " Report errors to the author: Patrick.Brockmann@cea.fr" |
---|
321 | exit 4 |
---|
322 | fi |
---|
323 | #--------------------- |
---|
324 | } |
---|