Index: /trunk/libIGCM/libIGCM_debug/libIGCM_debug.ksh
===================================================================
--- /trunk/libIGCM/libIGCM_debug/libIGCM_debug.ksh	(revision 822)
+++ /trunk/libIGCM/libIGCM_debug/libIGCM_debug.ksh	(revision 823)
@@ -27,10 +27,13 @@
 typeset DEBUG_debug=${DEBUG_debug:=false}
 
+# Where the stack file containing call tree will be stored.
+typeset StackFileLocation=${StackFileLocation:=${PWD}}
+
 if ( $DEBUG_debug ) ; then
-  if [ -f stack ] ;
+  if [ -f ${StackFileLocation}/stack ] ;
   then
-    echo "Stack of an libIGCM job :" >> stack
+    echo "Stack of an libIGCM job :" >> ${StackFileLocation}/stack
   else
-    echo "Stack of an libIGCM job :" >  stack
+    echo "Stack of an libIGCM job :" >  ${StackFileLocation}/stack
   fi
 fi
@@ -77,14 +80,14 @@
     # (c'est donc l'inverse de la norme d'affichage).
     typeset i decal
-    (( i=0 ))
+    i=0
     until [ $i -eq ${IGCM_debug_LenStack} ]; do
       decal=0
       until [ $decal -eq ${i} ]; do
         printf -- ' '
-        let $(( decal=decal+1 ))
+        (( decal = decal + 1 ))
       done
       echo "$i - ${IGCM_debug_Stack[$(( $IGCM_debug_LenStack-$i-1 ))]}"\
            "(${IGCM_debug_StackArgs[$(( $IGCM_debug_LenStack-$i-1 ))]})"
-      let $((i=i+1))
+      ((i = i + 1))
     done
     echo "!------------------------!"
@@ -98,14 +101,15 @@
 function IGCM_debug_PushStack {
   if ( $DEBUG_debug ) ; then
-    typeset decal
-    echo >> stack
+    typeset decal inputs
+    echo >> ${StackFileLocation}/stack
     decal=0
-    while [ $decal -lt ${IGCM_debug_LenStack} ]; do
-#          printf -- ' ' >> stack
-      printf ' ' >> stack
-      let $(( decal=decal+1 ))
+    while [ ${decal} -lt ${IGCM_debug_LenStack} ]; do
+      printf ' ' >> ${StackFileLocation}/stack
+      (( decal = decal + 1 ))
     done
-    echo "> ${IGCM_debug_LenStack} : ${@}" >> stack
-
+    echo "> ${IGCM_debug_LenStack} : ${@}" >> ${StackFileLocation}/stack
+
+    # STORE input list in an indexed array
+    INPUTS=( $@ )
     # We add function call name on beginning of the stack
     set +A IGCM_debug_Stack -- ${1} ${IGCM_debug_Stack[*]}
@@ -115,6 +119,5 @@
     # Then, we shift StackArgs tabular
     if [ $# -gt 1 ]; then 
-      shift; 
-      IGCM_debug_StackArgs[0]=$(echo ${@} | sed -e "s/\ /,/g") >&2
+      IGCM_debug_StackArgs[0]=$(echo ${INPUTS[*]:1} | sed -e "s/\ /,/g")
     fi
     (( IGCM_debug_LenStack = IGCM_debug_LenStack + 1 ))
@@ -132,31 +135,21 @@
   if ( $DEBUG_debug ) ; then
     if ( ${ExitFlag} ) ; then
-      echo '!!! ExitFlag has been activated !!!' >> stack
-    fi
+      echo '!!! ExitFlag has been activated !!!' >> ${StackFileLocation}/stack
+    fi
+    typeset decal
     if [ "${IGCM_debug_Stack[0]}" = "${1}" ]; then
-      let $(( IGCM_debug_LenStack = IGCM_debug_LenStack - 1 ))
-
-      IGCM_debug_Stack[0]="" 
-      IGCM_debug_StackArgs[0]=""
-      
-      set +A tmpStack -- ${IGCM_debug_Stack[*]}
-      unset IGCM_debug_Stack
-      set +A IGCM_debug_Stack -- ${tmpStack[*]} 
-
-      set +A tmpStack -- ${IGCM_debug_StackArgs[*]}
-      unset IGCM_debug_StackArgs
-      set +A IGCM_debug_StackArgs -- ${tmpStack[*]}
-      unset tmpStack
+      (( IGCM_debug_LenStack = IGCM_debug_LenStack - 1 ))
+      set -A IGCM_debug_Stack -- ${IGCM_debug_Stack[*]:1}
+      set -A IGCM_debug_StackArgs -- ${IGCM_debug_StackArgs[*]:1}
     else
       echo 'IGCM_debug_Exit : stack is corrupted ! LenStack =' ${IGCM_debug_LenStack}
       IGCM_debug_Exit $@
     fi
-    typeset decal=0
-    while [ $decal -lt ${IGCM_debug_LenStack} ]; do
-      # printf -- ' ' >> stack
-      printf ' ' >> stack
-      (( decal=decal+1 ))
+    decal=0
+    while [ ${decal} -lt ${IGCM_debug_LenStack} ]; do
+      printf ' ' >> ${StackFileLocation}/stack
+      (( decal = decal + 1 ))
     done
-    echo "< ${IGCM_debug_LenStack} : ${@}" >> stack
+    echo "< ${IGCM_debug_LenStack} : ${@}" >> ${StackFileLocation}/stack
 
     if [ ${IGCM_debug_LenStack} = 0 ]; then
@@ -172,5 +165,4 @@
       IGCM_debug_StackArgs[0]=${NULL_STR}
     fi
-
   fi
   #IGCM_debug_CallStack
@@ -203,5 +195,4 @@
     fi
     if ( $DEBUG_debug ) ; then
-      IGCM_sys_Cp stack ${SUBMIT_DIR}/stack_error
       echo "Your files on ${R_OUT} :"
       IGCM_sys_Tree ${R_SAVE}
@@ -228,8 +219,4 @@
       echo "                        EXIT THE JOB."
       echo
-      if ( $DEBUG_debug ) ; then
-        IGCM_sys_Cp stack ${SUBMIT_DIR}/stack_error
-        echo
-      fi
       # Mail notification
       #IGCM_sys_SendMailPost
