[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 | |
---|
[823] | 29 | # Where the stack file containing call tree will be stored. |
---|
| 30 | typeset StackFileLocation=${StackFileLocation:=${PWD}} |
---|
| 31 | |
---|
[2] | 32 | if ( $DEBUG_debug ) ; then |
---|
[823] | 33 | if [ -f ${StackFileLocation}/stack ] ; |
---|
[544] | 34 | then |
---|
[823] | 35 | echo "Stack of an libIGCM job :" >> ${StackFileLocation}/stack |
---|
[544] | 36 | else |
---|
[823] | 37 | echo "Stack of an libIGCM job :" > ${StackFileLocation}/stack |
---|
[544] | 38 | fi |
---|
[2] | 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 |
---|
[54] | 60 | #set -A IGCM_debug_Stack ${NULL_STR} |
---|
| 61 | #set -A IGCM_debug_StackArgs ${NULL_STR} |
---|
[59] | 62 | unset IGCM_debug_Stack |
---|
| 63 | unset IGCM_debug_StackArgs |
---|
[54] | 64 | IGCM_debug_Stack[0]=${NULL_STR} |
---|
| 65 | IGCM_debug_StackArgs[0]=${NULL_STR} |
---|
[2] | 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 { |
---|
[544] | 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 |
---|
[823] | 82 | i=0 |
---|
[544] | 83 | until [ $i -eq ${IGCM_debug_LenStack} ]; do |
---|
| 84 | decal=0 |
---|
| 85 | until [ $decal -eq ${i} ]; do |
---|
[785] | 86 | printf -- ' ' |
---|
[823] | 87 | (( decal = decal + 1 )) |
---|
[544] | 88 | done |
---|
| 89 | echo "$i - ${IGCM_debug_Stack[$(( $IGCM_debug_LenStack-$i-1 ))]}"\ |
---|
[785] | 90 | "(${IGCM_debug_StackArgs[$(( $IGCM_debug_LenStack-$i-1 ))]})" |
---|
[823] | 91 | ((i = i + 1)) |
---|
[544] | 92 | done |
---|
[2] | 93 | echo "!------------------------!" |
---|
[544] | 94 | fi |
---|
[2] | 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 { |
---|
[544] | 102 | if ( $DEBUG_debug ) ; then |
---|
[823] | 103 | typeset decal inputs |
---|
| 104 | echo >> ${StackFileLocation}/stack |
---|
[544] | 105 | decal=0 |
---|
[823] | 106 | while [ ${decal} -lt ${IGCM_debug_LenStack} ]; do |
---|
| 107 | printf ' ' >> ${StackFileLocation}/stack |
---|
| 108 | (( decal = decal + 1 )) |
---|
[544] | 109 | done |
---|
[823] | 110 | echo "> ${IGCM_debug_LenStack} : ${@}" >> ${StackFileLocation}/stack |
---|
[2] | 111 | |
---|
[823] | 112 | # STORE input list in an indexed array |
---|
| 113 | INPUTS=( $@ ) |
---|
[544] | 114 | # We add function call name on beginning of the stack |
---|
| 115 | set +A IGCM_debug_Stack -- ${1} ${IGCM_debug_Stack[*]} |
---|
[2] | 116 | |
---|
[544] | 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 |
---|
[823] | 121 | IGCM_debug_StackArgs[0]=$(echo ${INPUTS[*]:1} | sed -e "s/\ /,/g") |
---|
[544] | 122 | fi |
---|
| 123 | (( IGCM_debug_LenStack = IGCM_debug_LenStack + 1 )) |
---|
[2] | 124 | |
---|
[544] | 125 | # If you want to print CallStack each time : |
---|
| 126 | # IGCM_debug_CallStack |
---|
| 127 | fi |
---|
[2] | 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 { |
---|
[544] | 135 | if ( $DEBUG_debug ) ; then |
---|
| 136 | if ( ${ExitFlag} ) ; then |
---|
[823] | 137 | echo '!!! ExitFlag has been activated !!!' >> ${StackFileLocation}/stack |
---|
[544] | 138 | fi |
---|
[823] | 139 | typeset decal |
---|
[544] | 140 | if [ "${IGCM_debug_Stack[0]}" = "${1}" ]; then |
---|
[823] | 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} |
---|
[544] | 144 | else |
---|
| 145 | echo 'IGCM_debug_Exit : stack is corrupted ! LenStack =' ${IGCM_debug_LenStack} |
---|
| 146 | IGCM_debug_Exit $@ |
---|
| 147 | fi |
---|
[823] | 148 | decal=0 |
---|
| 149 | while [ ${decal} -lt ${IGCM_debug_LenStack} ]; do |
---|
| 150 | printf ' ' >> ${StackFileLocation}/stack |
---|
| 151 | (( decal = decal + 1 )) |
---|
[544] | 152 | done |
---|
[823] | 153 | echo "< ${IGCM_debug_LenStack} : ${@}" >> ${StackFileLocation}/stack |
---|
[2] | 154 | |
---|
[544] | 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} |
---|
[2] | 166 | fi |
---|
[544] | 167 | fi |
---|
| 168 | #IGCM_debug_CallStack |
---|
[2] | 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 { |
---|
[544] | 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" |
---|
[2] | 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 { |
---|
[544] | 188 | if ( ${ExitFlag} ) ; then |
---|
| 189 | # Plan to send an email here with IGCM_sys_SendMail |
---|
[775] | 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 |
---|
[544] | 196 | if ( $DEBUG_debug ) ; then |
---|
| 197 | echo "Your files on ${R_OUT} :" |
---|
| 198 | IGCM_sys_Tree ${R_SAVE} |
---|
| 199 | echo |
---|
[2] | 200 | fi |
---|
[544] | 201 | # Mail notification |
---|
| 202 | IGCM_sys_SendMail |
---|
| 203 | # And Good Bye |
---|
| 204 | date |
---|
| 205 | exit 1 |
---|
| 206 | fi |
---|
[2] | 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 { |
---|
[544] | 214 | if ( ${ExitFlag} ) ; then |
---|
[765] | 215 | echo "IGCM_debug_Verif_Exit_Post : Something wrong happened." |
---|
[544] | 216 | # If SpaceName is PROD then we stop if post_processing fails |
---|
| 217 | # Plan to send an email here with IGCM_sys_SendMail |
---|
[706] | 218 | if [ X${config_UserChoices_SpaceName} = XPROD ] ; then |
---|
[544] | 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" |
---|
[765] | 228 | echo "or inside the main Job the variable JobType is not in RUN mode" |
---|
[544] | 229 | echo " SO WE DO NOT EXIT THE JOB." |
---|
| 230 | echo |
---|
| 231 | date |
---|
[2] | 232 | fi |
---|
[544] | 233 | fi |
---|
[2] | 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 | { |
---|
[544] | 242 | typeset level=$1 |
---|
| 243 | shift |
---|
| 244 | |
---|
| 245 | if [ X"${1}" = X"-e" ]; then |
---|
| 246 | typeset cmd_echo="echo -e" |
---|
[2] | 247 | shift |
---|
[544] | 248 | else |
---|
| 249 | typeset cmd_echo="echo" |
---|
| 250 | fi |
---|
[2] | 251 | |
---|
[544] | 252 | if [ ${level} -le ${Verbosity} ] ; then |
---|
| 253 | typeset i |
---|
| 254 | case "${level}" in |
---|
| 255 | 1) for i in "$@" ; do |
---|
[734] | 256 | ${cmd_echo} $(date +"%Y-%m-%d %T") "--Debug1-->" ${i} |
---|
[544] | 257 | done ;; |
---|
| 258 | 2) for i in "$@" ; do |
---|
[734] | 259 | ${cmd_echo} $(date +"%Y-%m-%d %T") "--------Debug2-->" ${i} |
---|
[544] | 260 | done ;; |
---|
| 261 | 3) for i in "$@" ; do |
---|
[734] | 262 | ${cmd_echo} $(date +"%Y-%m-%d %T") "--------------Debug3-->" ${i} |
---|
[544] | 263 | done ;; |
---|
| 264 | esac |
---|
| 265 | fi |
---|
[2] | 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 | { |
---|
[544] | 274 | typeset level=$1 |
---|
| 275 | shift |
---|
[2] | 276 | |
---|
[830] | 277 | list=$( set | grep ^$1 | sed -e "s/'//g" ) |
---|
[54] | 278 | |
---|
[544] | 279 | if [ "X${list}" != X ] ; then |
---|
| 280 | IGCM_debug_Print ${level} ${list} |
---|
| 281 | fi |
---|
[2] | 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 | { |
---|
[544] | 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 |
---|
[2] | 295 | |
---|
[544] | 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 |
---|
[2] | 302 | |
---|
[544] | 303 | #--------------------- |
---|
| 304 | ${libIGCM}/libIGCM_debug/IGCM_debug_Test.ksh > IGCM_debug_Test.ref.failed 2>&1 |
---|
| 305 | sleep 2 |
---|
[2] | 306 | |
---|
[772] | 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 | |
---|
[544] | 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 | #--------------------- |
---|
[2] | 324 | } |
---|