source: tags/libIGCM_v1_10/libIGCM_debug/libIGCM_debug.ksh @ 998

Last change on this file since 998 was 373, checked in by sdipsl, 14 years ago

Remove libIGCM_sys_claude.ksh and libIGCM_sys_calculo.ksh
Update/homogenize all headers usgin the new fixed-length keyword syntax regarding properties keywords
$Rev:: 13 i $: Revision of last commit
$Author:: harry $: Author of last commit
$Date:: 2006-03-15 02:33:03 -0500 (Wed, 15 Mar 2006) $: Date of last commit
Add / update original author and contact when missing

  • Property licence set to
    The following licence information concerns ONLY the libIGCM tools
    ==================================================================

    Copyright © Centre National de la Recherche Scientifique CNRS
    Commissariat à l'Énergie Atomique CEA

    libIGCM : Library for Portable Models Computation of IGCM Group.

    IGCM Group is the french IPSL Global Climate Model Group.

    This library is a set of shell scripts and functions whose purpose is
    the management of the initialization, the launch, the transfer of
    output files, the post-processing and the monitoring of datas produce
    by any numerical program on any plateforme.

    This software is governed by the CeCILL license under French law and
    abiding by the rules of distribution of free software. You can use,
    modify and/ or redistribute the software under the terms of the CeCILL
    license as circulated by CEA, CNRS and INRIA at the following URL
    "http://www.cecill.info".

    As a counterpart to the access to the source code and rights to copy,
    modify and redistribute granted by the license, users are provided only
    with a limited warranty and the software's author, the holder of the
    economic rights, and the successive licensors have only limited
    liability.

    In this respect, the user's attention is drawn to the risks associated
    with loading, using, modifying and/or developing or reproducing the
    software by the user in light of its specific status of free software,
    that may mean that it is complicated to manipulate, and that also
    therefore means that it is reserved for developers and experienced
    professionals having in-depth computer knowledge. Users are therefore
    encouraged to load and test the software's suitability as regards their
    requirements in conditions enabling the security of their systems and/or
    data to be ensured and, more generally, to use and operate it in the
    same conditions as regards security.

    The fact that you are presently reading this means that you have had
    knowledge of the CeCILL license and that you accept its terms.
  • Property svn:keywords set to Revision Author Date
File size: 9.3 KB
Line 
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
22typeset -i Verbosity=${Verbosity:=3}
23
24#==================================================
25# DEBUG_debug
26# Add low level verbosity
27typeset DEBUG_debug=${DEBUG_debug:=false}
28
29if ( $DEBUG_debug ) ; then
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
36fi
37
38#==================================================
39# NULL_STR
40# Default null string
41typeset -r NULL_STR="_0_" 
42
43#==================================================
44# libIGCM_CurrentTag
45# Current libIGCM tag, check compatibilty with *.card
46typeset -r libIGCM_CurrentTag="1.0" 
47
48#==================================================
49# Exit Flag (internal debug)
50# When true, end the master loop AFTER SAVES FILES
51ExitFlag=false
52
53#==================================================
54# Declare a stack of functions calls
55
56# insert last argument of the Stack
57#set -A IGCM_debug_Stack ${NULL_STR}
58#set -A IGCM_debug_StackArgs ${NULL_STR}
59unset IGCM_debug_Stack
60unset IGCM_debug_StackArgs
61IGCM_debug_Stack[0]=${NULL_STR}
62IGCM_debug_StackArgs[0]=${NULL_STR}
63IGCM_debug_LenStack=0
64
65#D-#==================================================================
66#D-function IGCM_debug_CallStack
67#D-* Purpose: Echo the Stack
68#D-
69function IGCM_debug_CallStack {
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
83                printf -- ' '
84                let $(( decal=decal+1 ))
85            done
86            echo "$i - ${IGCM_debug_Stack[$(( $IGCM_debug_LenStack-$i-1 ))]}"\
87                "(${IGCM_debug_StackArgs[$(( $IGCM_debug_LenStack-$i-1 ))]})"
88            let $((i=i+1))
89        done
90        echo "!------------------------!"
91    fi
92}
93
94#D-#==================================================================
95#D-function IGCM_debug_PushStack
96#D-* Purpose: Push a function name in the stack
97#D-
98function IGCM_debug_PushStack {
99    if ( $DEBUG_debug ) ; then
100       typeset decal
101       echo >> stack
102       decal=0
103       while [ $decal -lt ${IGCM_debug_LenStack} ]; do
104#          printf -- ' ' >> stack
105           printf ' ' >> stack
106           let $(( decal=decal+1 ))
107       done
108       echo "> ${IGCM_debug_LenStack} : ${@}" >> stack
109
110       # We add function call name on beginning of the stack
111       set +A IGCM_debug_Stack -- ${1} ${IGCM_debug_Stack[*]}
112
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 ))
121
122       # If you want to print CallStack each time :
123       # IGCM_debug_CallStack
124    fi
125}
126
127#D-#==================================================================
128#D-function IGCM_debug_PopStack
129#D-* Purpose: Pop a function name in the stack
130#D-
131function IGCM_debug_PopStack {
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 ))
138
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[*]} 
145
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
161
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}
173      fi
174
175    fi
176
177    #IGCM_debug_CallStack
178}
179
180#D-#==================================================================
181#D-function IGCM_debug_Exit
182#D-* Purpose: Print Call Stack and set ExitFlag to true
183#D-
184function IGCM_debug_Exit {
185    IGCM_debug_PushStack "IGCM_debug_Exit"
186    echo "IGCM_debug_Exit : " "${@}"
187    IGCM_debug_CallStack
188    ExitFlag=true
189    IGCM_debug_PopStack "IGCM_debug_Exit"
190}
191
192#D-#==================================================
193#D-function IGCM_debug_Verif_Exit
194#D-* Purpose: exit with number 1 if ExitFlag is true
195#D-
196function IGCM_debug_Verif_Exit {
197    if ( ${ExitFlag} ) ; then
198        IGCM_card_WriteOption ${SUBMIT_DIR}/run.card Configuration PeriodState "Fatal"
199        echo "IGCM_debug_Verif_Exit : Something wrong append."
200        echo "                        EXIT THE JOB."
201        echo
202        if ( $DEBUG_debug ) ; then
203            IGCM_sys_Cp stack ${SUBMIT_DIR}/stack_error
204            echo "Your files on ${R_OUT} :"
205            IGCM_sys_Tree ${R_SAVE}
206            echo
207        fi
208        date
209        exit 1
210    fi
211}
212
213#D-#==================================================
214#D-function IGCM_debug_Verif_Exit_Post
215#D-* Purpose: exit with number 1 if ExitFlag is true for Post-treatment
216#D-
217function IGCM_debug_Verif_Exit_Post {
218    if ( ${ExitFlag} ) ; then
219        echo "IGCM_debug_Verif_Exit_Post : Something wrong append."
220        #echo "                        EXIT THE JOB."
221        echo "         BUT WE DO NOT EXIT THE JOB."
222        echo
223        date
224        #exit 1
225    fi
226}
227
228#D-#==================================================================
229#D-function IGCM_debug_Print
230#D-* Purpose: Print arguments according to a level of verbosity.
231#D-
232function IGCM_debug_Print
233{
234    typeset level=$1
235    shift
236
237    if [ X"${1}" = X"-e" ]; then
238        typeset cmd_echo="echo -e"
239        shift
240    else
241        typeset cmd_echo="echo"
242    fi
243
244    if [ ${level} -le ${Verbosity} ] ; then
245        typeset i
246        case "${level}" in
247            1) for i in "$@" ; do
248                    ${cmd_echo} "--Debug1-->" ${i}
249              done ;;
250            2) for i in "$@" ; do
251                    ${cmd_echo} "--------Debug2-->" ${i}
252              done ;;
253            3) for i in "$@" ; do
254                    ${cmd_echo} "--------------Debug3-->" ${i}
255              done ;;
256        esac
257    fi
258}
259
260#D-#==================================================================
261#D-function IGCM_debug_PrintVariables
262#D-* Purpose: Print arguments when match a pattern
263#D-           according to a level of verbosity.
264function IGCM_debug_PrintVariables
265{
266    typeset level=$1
267    shift
268
269    list=$( set | grep $1 | sed -e "s/'//g" )
270
271    if [ "X${list}" != X ]  ; then
272        IGCM_debug_Print ${level} ${list}
273    fi
274}
275
276#D-#==================================================================
277#D-function IGCM_debug_Check
278#D- * Purpose: Check the present file by comparison with a reference file
279function IGCM_debug_Check
280{
281    #---------------------
282    if [ ! -n "${libIGCM}" ] ; then
283        echo "Check libIGCM_debug ..........................................[ FAILED ]"
284        echo "--Error--> libIGCM variable is not defined"
285        exit 2
286    fi
287
288    #---------------------
289    if [ ! -n "${Verbosity}" ] ; then
290        echo "Check libIGCM_debug ..........................................[ FAILED ]"
291        echo "--Error--> Verbosity variable is not defined"
292        exit 3
293    fi
294
295    #---------------------
296    ${libIGCM}/libIGCM_debug/IGCM_debug_Test.ksh > IGCM_debug_Test.ref.failed 2>&1
297    sleep 2
298
299    if diff IGCM_debug_Test.ref.failed ${libIGCM}/libIGCM_debug/IGCM_debug_Test.ref > /dev/null 2>&1 ; then
300        echo "Check libIGCM_debug ..............................................[ OK ]"
301        rm -f IGCM_debug_Test.ref.failed
302    else
303        echo "Check libIGCM_debug ..........................................[ FAILED ]"
304        echo "--Error--> Execution of ${libIGCM}/libIGCM_debug/IGCM_debug_Test.ksh"
305        echo "           has produced the file IGCM_debug_Test.ref.failed"
306        echo "           Please analyse differences with the reference file by typing:"
307        echo "           diff IGCM_debug_Test.ref.failed ${libIGCM}/libIGCM_debug/IGCM_debug_Test.ref"
308        echo "           Report errors to the author: Patrick.Brockmann@cea.fr"
309        exit 4
310    fi
311    #---------------------
312}
Note: See TracBrowser for help on using the repository browser.