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