[2] | 1 | #!/bin/ksh |
---|
| 2 | |
---|
| 3 | #************************************************************** |
---|
| 4 | # Author: Patrick Brockmann, Martial Mancip |
---|
| 5 | # Contact: Patrick.Brockmann@cea.fr Martial.Mancip@ipsl.jussieu.fr |
---|
[4] | 6 | # $Date$ |
---|
[5] | 7 | # $Author$ |
---|
| 8 | # $Revision$ |
---|
[2] | 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 |
---|
[98] | 29 | typeset DEBUG_debug=${DEBUG_debug:=false} |
---|
[2] | 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 |
---|
[54] | 59 | #set -A IGCM_debug_Stack ${NULL_STR} |
---|
| 60 | #set -A IGCM_debug_StackArgs ${NULL_STR} |
---|
[59] | 61 | unset IGCM_debug_Stack |
---|
| 62 | unset IGCM_debug_StackArgs |
---|
[54] | 63 | IGCM_debug_Stack[0]=${NULL_STR} |
---|
| 64 | IGCM_debug_StackArgs[0]=${NULL_STR} |
---|
[2] | 65 | IGCM_debug_LenStack=0 |
---|
| 66 | |
---|
| 67 | #D-#================================================================== |
---|
| 68 | #D-function IGCM_debug_CallStack |
---|
| 69 | #D-* Purpose: Echo the Stack |
---|
| 70 | #D- |
---|
| 71 | function IGCM_debug_CallStack { |
---|
| 72 | echo |
---|
| 73 | echo "!!!!!!!!!!!!!!!!!!!!!!!!!!" |
---|
| 74 | echo "!! IGCM_debug_CallStack !!" |
---|
| 75 | echo "!------------------------!" |
---|
| 76 | echo |
---|
| 77 | if ( $DEBUG_debug ) ; then |
---|
| 78 | # La pile d'appels est affichée de la plus vieille à la plus récente |
---|
| 79 | # (c'est donc l'inverse de la norme d'affichage). |
---|
| 80 | typeset i decal |
---|
| 81 | (( i=0 )) |
---|
| 82 | until [ $i -eq ${IGCM_debug_LenStack} ]; do |
---|
| 83 | decal=0 |
---|
| 84 | until [ $decal -eq ${i} ]; do |
---|
| 85 | printf -- ' ' |
---|
| 86 | let $(( decal=decal+1 )) |
---|
| 87 | done |
---|
| 88 | echo "$i - ${IGCM_debug_Stack[$(( $IGCM_debug_LenStack-$i-1 ))]}"\ |
---|
| 89 | "(${IGCM_debug_StackArgs[$(( $IGCM_debug_LenStack-$i-1 ))]})" |
---|
| 90 | let $((i=i+1)) |
---|
| 91 | done |
---|
[157] | 92 | echo "!------------------------!" |
---|
[2] | 93 | fi |
---|
| 94 | } |
---|
| 95 | |
---|
| 96 | #D-#================================================================== |
---|
| 97 | #D-function IGCM_debug_PushStack |
---|
| 98 | #D-* Purpose: Push a function name in the stack |
---|
| 99 | #D- |
---|
| 100 | function IGCM_debug_PushStack { |
---|
| 101 | if ( $DEBUG_debug ) ; then |
---|
| 102 | typeset decal |
---|
| 103 | echo >> stack |
---|
| 104 | decal=0 |
---|
| 105 | while [ $decal -lt ${IGCM_debug_LenStack} ]; do |
---|
| 106 | # printf -- ' ' >> stack |
---|
| 107 | printf ' ' >> stack |
---|
| 108 | let $(( decal=decal+1 )) |
---|
| 109 | done |
---|
| 110 | echo "> ${IGCM_debug_LenStack} : ${@}" >> stack |
---|
| 111 | |
---|
| 112 | # We add function call name on beginning of the stack |
---|
| 113 | set +A IGCM_debug_Stack ${1} ${IGCM_debug_Stack[*]} |
---|
| 114 | |
---|
| 115 | # We include the "null" Args in the beginning of the StackArgs |
---|
| 116 | set +A IGCM_debug_StackArgs ${NULL_STR} ${IGCM_debug_StackArgs[*]} |
---|
| 117 | # Then, we shift StackArgs tabular |
---|
| 118 | if [ $# -gt 1 ]; then |
---|
| 119 | shift; |
---|
| 120 | IGCM_debug_StackArgs=$(echo ${@} | sed -e "s/\ /,/g") >&2 |
---|
| 121 | fi |
---|
| 122 | (( IGCM_debug_LenStack = IGCM_debug_LenStack + 1 )) |
---|
| 123 | |
---|
| 124 | # If you want to print CallStack each time : |
---|
| 125 | # IGCM_debug_CallStack |
---|
| 126 | fi |
---|
| 127 | } |
---|
| 128 | |
---|
| 129 | #D-#================================================================== |
---|
| 130 | #D-function IGCM_debug_PopStack |
---|
| 131 | #D-* Purpose: Pop a function name in the stack |
---|
| 132 | #D- |
---|
| 133 | function IGCM_debug_PopStack { |
---|
| 134 | if ( $DEBUG_debug ) ; then |
---|
[36] | 135 | if ( ${ExitFlag} ) ; then |
---|
| 136 | echo '!!! ExitFlag has been activated !!!' >> stack |
---|
| 137 | fi |
---|
[2] | 138 | if [ "${IGCM_debug_Stack[0]}" = "${1}" ]; then |
---|
| 139 | let $(( IGCM_debug_LenStack = IGCM_debug_LenStack - 1 )) |
---|
| 140 | |
---|
| 141 | IGCM_debug_Stack[0]="" |
---|
| 142 | IGCM_debug_StackArgs[0]="" |
---|
| 143 | |
---|
| 144 | set +A IGCM_debug_Stack ${IGCM_debug_Stack[*]} |
---|
| 145 | set +A IGCM_debug_StackArgs ${IGCM_debug_StackArgs[*]} |
---|
| 146 | else |
---|
| 147 | echo 'IGCM_debug_Exit : stack is corrupted ! LenStack =' ${IGCM_debug_LenStack} |
---|
| 148 | IGCM_debug_Exit $@ |
---|
| 149 | fi |
---|
| 150 | typeset decal=0 |
---|
| 151 | while [ $decal -lt ${IGCM_debug_LenStack} ]; do |
---|
| 152 | # printf -- ' ' >> stack |
---|
| 153 | printf ' ' >> stack |
---|
| 154 | (( decal=decal+1 )) |
---|
| 155 | done |
---|
| 156 | echo "< ${IGCM_debug_LenStack} : ${@}" >> stack |
---|
| 157 | |
---|
| 158 | if [ ${IGCM_debug_LenStack} = 0 ]; then |
---|
| 159 | # Reset array only when necessary |
---|
| 160 | #echo |
---|
| 161 | #IGCM_debug_Print 3 "Clean stack array" |
---|
| 162 | #echo |
---|
[54] | 163 | #set -A IGCM_debug_Stack ${NULL_STR} |
---|
| 164 | #set -A IGCM_debug_StackArgs ${NULL_STR} |
---|
| 165 | IGCM_debug_Stack[0]=${NULL_STR} |
---|
| 166 | IGCM_debug_StackArgs[0]=${NULL_STR} |
---|
[2] | 167 | fi |
---|
| 168 | |
---|
| 169 | fi |
---|
| 170 | |
---|
| 171 | #IGCM_debug_CallStack |
---|
| 172 | } |
---|
| 173 | |
---|
| 174 | #D-#================================================================== |
---|
| 175 | #D-function IGCM_debug_Exit |
---|
| 176 | #D-* Purpose: Print Call Stack and set ExitFlag to true |
---|
| 177 | #D- |
---|
| 178 | function IGCM_debug_Exit { |
---|
| 179 | IGCM_debug_PushStack "IGCM_debug_Exit" |
---|
| 180 | echo "IGCM_debug_Exit : " "${@}" |
---|
| 181 | IGCM_debug_CallStack |
---|
[108] | 182 | ExitFlag=true |
---|
[2] | 183 | IGCM_debug_PopStack "IGCM_debug_Exit" |
---|
| 184 | } |
---|
| 185 | |
---|
| 186 | #D-#================================================== |
---|
| 187 | #D-function IGCM_debug_Verif_Exit |
---|
| 188 | #D-* Purpose: exit with number 1 if ExitFlag is true |
---|
| 189 | #D- |
---|
| 190 | function IGCM_debug_Verif_Exit { |
---|
| 191 | if ( ${ExitFlag} ) ; then |
---|
| 192 | IGCM_card_WriteOption ${SUBMIT_DIR}/run.card Configuration PeriodState "Fatal" |
---|
| 193 | echo "IGCM_debug_Verif_Exit : Something wrong append." |
---|
| 194 | echo " EXIT THE JOB." |
---|
| 195 | echo |
---|
| 196 | if ( $DEBUG_debug ) ; then |
---|
[113] | 197 | IGCM_sys_Cp stack ${SUBMIT_DIR}/stack_error |
---|
[2] | 198 | echo "Your files on ${R_OUT} :" |
---|
| 199 | IGCM_sys_Tree ${R_SAVE} |
---|
| 200 | echo |
---|
| 201 | fi |
---|
| 202 | date |
---|
| 203 | exit 1 |
---|
| 204 | fi |
---|
| 205 | } |
---|
| 206 | |
---|
| 207 | #D-#================================================== |
---|
| 208 | #D-function IGCM_debug_Verif_Exit_Post |
---|
| 209 | #D-* Purpose: exit with number 1 if ExitFlag is true for Post-treatment |
---|
| 210 | #D- |
---|
| 211 | function IGCM_debug_Verif_Exit_Post { |
---|
| 212 | if ( ${ExitFlag} ) ; then |
---|
| 213 | echo "IGCM_debug_Verif_Exit_Post : Something wrong append." |
---|
[46] | 214 | #echo " EXIT THE JOB." |
---|
| 215 | echo " BUT WE DO NOT EXIT THE JOB." |
---|
[2] | 216 | echo |
---|
| 217 | date |
---|
[46] | 218 | #exit 1 |
---|
[2] | 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 | |
---|
[54] | 256 | list=$( set | grep $1 | sed -e "s/'//g" ) |
---|
| 257 | |
---|
| 258 | if [ "X${list}" != X ] ; then |
---|
[2] | 259 | IGCM_debug_Print ${level} ${list} |
---|
| 260 | fi |
---|
| 261 | } |
---|
| 262 | |
---|
| 263 | #D-#================================================================== |
---|
| 264 | #D-function IGCM_debug_Check |
---|
| 265 | #D- * Purpose: Check the present file by comparison with a reference file |
---|
| 266 | function IGCM_debug_Check |
---|
| 267 | { |
---|
| 268 | #--------------------- |
---|
| 269 | if [ ! -n "${libIGCM}" ] ; then |
---|
| 270 | echo "Check libIGCM_debug ..........................................[ FAILED ]" |
---|
| 271 | echo "--Error--> libIGCM variable is not defined" |
---|
| 272 | exit 2 |
---|
| 273 | fi |
---|
| 274 | |
---|
| 275 | #--------------------- |
---|
| 276 | if [ ! -n "${Verbosity}" ] ; then |
---|
| 277 | echo "Check libIGCM_debug ..........................................[ FAILED ]" |
---|
| 278 | echo "--Error--> Verbosity variable is not defined" |
---|
| 279 | exit 3 |
---|
| 280 | fi |
---|
| 281 | |
---|
| 282 | #--------------------- |
---|
| 283 | ${libIGCM}/libIGCM_debug/IGCM_debug_Test.ksh > IGCM_debug_Test.ref.failed 2>&1 |
---|
| 284 | sleep 2 |
---|
| 285 | |
---|
| 286 | if diff IGCM_debug_Test.ref.failed ${libIGCM}/libIGCM_debug/IGCM_debug_Test.ref > /dev/null 2>&1 ; then |
---|
| 287 | echo "Check libIGCM_debug ..............................................[ OK ]" |
---|
| 288 | rm -f IGCM_debug_Test.ref.failed |
---|
| 289 | else |
---|
| 290 | echo "Check libIGCM_debug ..........................................[ FAILED ]" |
---|
| 291 | echo "--Error--> Execution of ${libIGCM}/libIGCM_debug/IGCM_debug_Test.ksh" |
---|
| 292 | echo " has produced the file IGCM_debug_Test.ref.failed" |
---|
| 293 | echo " Please analyse differences with the reference file by typing:" |
---|
| 294 | echo " diff IGCM_debug_Test.ref.failed ${libIGCM}/libIGCM_debug/IGCM_debug_Test.ref" |
---|
| 295 | echo " Report errors to the author: Patrick.Brockmann@cea.fr" |
---|
| 296 | exit 4 |
---|
| 297 | fi |
---|
| 298 | #--------------------- |
---|
| 299 | } |
---|