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