Index: /trunk/libIGCM/libIGCM_card/libIGCM_card.ksh
===================================================================
--- /trunk/libIGCM/libIGCM_card/libIGCM_card.ksh	(revision 1110)
+++ /trunk/libIGCM/libIGCM_card/libIGCM_card.ksh	(revision 1111)
@@ -56,14 +56,14 @@
 function IGCM_card_PrintOption
 {
-    IGCM_debug_PushStack "IGCM_card_PrintOption" $@
-    if ( [ -r "$1" ] && [ -f "$1" ] ) ; then
-      gawk -f ${libIGCM}/libIGCM_card/IGCM_card_PrintOption.awk "$@"
-    else
-      echo
-      IGCM_debug_Print 1 "--Error--> IGCM_card_PrintOption $@"
-      IGCM_debug_Print 1 "           $1 is not readable"
-      IGCM_debug_Exit "IGCM_card_PrintOption"
-    fi
-    IGCM_debug_PopStack "IGCM_card_PrintOption"
+  IGCM_debug_PushStack "IGCM_card_PrintOption" $@
+  if ( [ -r "$1" ] && [ -f "$1" ] ) ; then
+    gawk -f ${libIGCM}/libIGCM_card/IGCM_card_PrintOption.awk "$@"
+  else
+    echo
+    IGCM_debug_Print 1 "--Error--> IGCM_card_PrintOption $@"
+    IGCM_debug_Print 1 "           $1 is not readable"
+    IGCM_debug_Exit "IGCM_card_PrintOption"
+  fi
+  IGCM_debug_PopStack "IGCM_card_PrintOption"
 }
 
@@ -76,13 +76,13 @@
 function IGCM_card_PrintSection
 {
-    IGCM_debug_PushStack "IGCM_card_PrintSection" $@
-    if ( [ -r "$1" ] && [ -f "$1" ] ) ; then
-      gawk -f ${libIGCM}/libIGCM_card/IGCM_card_PrintSection.awk -- "$@"
-    else
-      IGCM_debug_Print 1 "--Error--> IGCM_card_PrintSection $@"
-      IGCM_debug_Print 1 "           $1 is not readable"
-      IGCM_debug_Exit "IGCM_card_PrintSection"
-    fi
-    IGCM_debug_PopStack "IGCM_card_PrintSection"
+  IGCM_debug_PushStack "IGCM_card_PrintSection" $@
+  if ( [ -r "$1" ] && [ -f "$1" ] ) ; then
+    gawk -f ${libIGCM}/libIGCM_card/IGCM_card_PrintSection.awk -- "$@"
+  else
+    IGCM_debug_Print 1 "--Error--> IGCM_card_PrintSection $@"
+    IGCM_debug_Print 1 "           $1 is not readable"
+    IGCM_debug_Exit "IGCM_card_PrintSection"
+  fi
+  IGCM_debug_PopStack "IGCM_card_PrintSection"
 }
 
@@ -95,8 +95,8 @@
 function IGCM_card_DefineVariableFromOption
 {
-    IGCM_debug_PushStack "IGCM_card_DefineVariableFromOption" $@
-    if ( [ -r "$1" ] && [ -f "$1" ] ) ; then
-      # Get basename of card file ($1)
-      typeset name1=${1##*/}
+  IGCM_debug_PushStack "IGCM_card_DefineVariableFromOption" $@
+  if ( [ -r "$1" ] && [ -f "$1" ] ) ; then
+    # Get basename of card file ($1)
+    typeset name1=${1##*/}
       # Build name of variable as $1_$2_$3 (cardname_Section_Option)
       typeset name=${name1%%.*}_${2}_${3}
@@ -113,12 +113,12 @@
       fi
       eval ${name}=${value}
-    else
-      echo
-      IGCM_debug_Print 1 "--Error--> IGCM_card_DefineVariableFromOption"
-      IGCM_debug_Print 1 "--Error--> $1 is not readable"
-      IGCM_debug_Exit "IGCM_card_DefineVariableFromOption"
-      IGCM_debug_Verif_Exit
-    fi
-    IGCM_debug_PopStack "IGCM_card_DefineVariableFromOption"
+  else
+    echo
+    IGCM_debug_Print 1 "--Error--> IGCM_card_DefineVariableFromOption"
+    IGCM_debug_Print 1 "--Error--> $1 is not readable"
+    IGCM_debug_Exit "IGCM_card_DefineVariableFromOption"
+    IGCM_debug_Verif_Exit
+  fi
+  IGCM_debug_PopStack "IGCM_card_DefineVariableFromOption"
 }
 
@@ -131,20 +131,20 @@
 function IGCM_card_DefineArrayFromOption
 {
-    IGCM_debug_PushStack "IGCM_card_DefineArrayFromOption" $@
-    if ( [ -r "$1" ] && [ -f "$1" ] ) ; then
-      # Get basename of card file ($1)
-      typeset name1=${1##*/}
-      # Build name of array as $1_$2_$3 (cardname_Section_Option)
-      typeset name=${name1%%.*}_${2}_${3}
-      eval unset ${name}
-      eval ${name}[0]=${NULL_STR}
-      set +A ${name} -- $( gawk -f ${libIGCM}/libIGCM_card/IGCM_card_PrintOption.awk -- "$@" | gawk -- 'BEGIN {FS="[() ,]+"} {for (i=2; i <= NF-1; i++) printf("%s ",$i)}' )
-    else
-      echo
-      IGCM_debug_Print 1 "--Error--> IGCM_card_DefineArrayFromOption $@"
-      IGCM_debug_Print 1 "           $1 is not readable"
-      IGCM_debug_Exit "IGCM_card_DefineArrayFromOption"
-    fi
-    IGCM_debug_PopStack "IGCM_card_DefineArrayFromOption"
+  IGCM_debug_PushStack "IGCM_card_DefineArrayFromOption" $@
+  if ( [ -r "$1" ] && [ -f "$1" ] ) ; then
+    # Get basename of card file ($1)
+    typeset name1=${1##*/}
+    # Build name of array as $1_$2_$3 (cardname_Section_Option)
+    typeset name=${name1%%.*}_${2}_${3}
+    eval unset ${name}
+    eval ${name}[0]=${NULL_STR}
+    set +A ${name} -- $( gawk -f ${libIGCM}/libIGCM_card/IGCM_card_PrintOption.awk -- "$@" | gawk -- 'BEGIN {FS="[() ,]+"} {for (i=2; i <= NF-1; i++) printf("%s ",$i)}' )
+  else
+    echo
+    IGCM_debug_Print 1 "--Error--> IGCM_card_DefineArrayFromOption $@"
+    IGCM_debug_Print 1 "           $1 is not readable"
+    IGCM_debug_Exit "IGCM_card_DefineArrayFromOption"
+  fi
+  IGCM_debug_PopStack "IGCM_card_DefineArrayFromOption"
 }
 
@@ -157,32 +157,32 @@
 function IGCM_card_DefineArrayFromSection
 {
-    IGCM_debug_PushStack "IGCM_card_DefineArrayFromSection" $@
-    if ( [ -r "$1" ] && [ -f "$1" ] ) ; then
-      # Get basename of card file ($1)
-      typeset name1=${1##*/}
-      # Build name of array as $1_$2 (cardname_Section)
-      typeset name=${name1%%.*}_${2}
+  IGCM_debug_PushStack "IGCM_card_DefineArrayFromSection" $@
+  if ( [ -r "$1" ] && [ -f "$1" ] ) ; then
+    # Get basename of card file ($1)
+    typeset name1=${1##*/}
+    # Build name of array as $1_$2 (cardname_Section)
+    typeset name=${name1%%.*}_${2}
+    eval unset ${name}
+    eval ${name}[0]=${NULL_STR}
+    set +A ${name} -- $( gawk -f ${libIGCM}/libIGCM_card/IGCM_card_PrintSection.awk -- "$@" )
+    #if [ "$( eval echo \${${name}[@]} )" = "Error: Section not found" ] ; then
+    #    echo
+    #    IGCM_debug_Print 1 "Error with readding of ${name} variable in ${1}."
+    #    IGCM_debug_Print 1 "Error: Section ${2} not found"
+    #    IGCM_debug_Exit
+    #    IGCM_debug_Verif_Exit
+    #fi
+    if [ "$( eval echo \${${name}[@]} )" = "Error: Section not found" ] ; then
+      echo
+      IGCM_debug_Print 1 "Warning with readding of ${name} variable in ${1}."
+      IGCM_debug_Print 1 "Warning: Section ${2} not found"
       eval unset ${name}
-      eval ${name}[0]=${NULL_STR}
-      set +A ${name} -- $( gawk -f ${libIGCM}/libIGCM_card/IGCM_card_PrintSection.awk -- "$@" )
-      #if [ "$( eval echo \${${name}[@]} )" = "Error: Section not found" ] ; then
-      #    echo
-      #    IGCM_debug_Print 1 "Error with readding of ${name} variable in ${1}."
-      #    IGCM_debug_Print 1 "Error: Section ${2} not found"
-      #    IGCM_debug_Exit
-      #    IGCM_debug_Verif_Exit
-      #fi
-      if [ "$( eval echo \${${name}[@]} )" = "Error: Section not found" ] ; then
-        echo
-        IGCM_debug_Print 1 "Warning with readding of ${name} variable in ${1}."
-        IGCM_debug_Print 1 "Warning: Section ${2} not found"
-        eval unset ${name}
-      fi
-    else
-      IGCM_debug_Print 1 "--Error--> IGCM_card_DefineArrayFromSection $@"
-      IGCM_debug_Print 1 "           $1 is not readable"
-      IGCM_debug_Exit "IGCM_card_DefineArrayFromSection"
     fi
-    IGCM_debug_PopStack "IGCM_card_DefineArrayFromSection"
+  else
+    IGCM_debug_Print 1 "--Error--> IGCM_card_DefineArrayFromSection $@"
+    IGCM_debug_Print 1 "           $1 is not readable"
+    IGCM_debug_Exit "IGCM_card_DefineArrayFromSection"
+  fi
+  IGCM_debug_PopStack "IGCM_card_DefineArrayFromSection"
 }
 
@@ -199,62 +199,67 @@
 function IGCM_card_WriteOption
 {
-    IGCM_debug_PushStack "IGCM_card_WriteOption" $@
-    if ( [ -r "$1" ] && [ -w "$1" ]  && [ -f "$1" ] ) ; then
-      typeset tmpfile=tmpfile_$$
-      ( IGCM_card_PrintOption "$1" "$2" "$3" | grep "not found" ) > ${tmpfile}
-      if [ $( cat ${tmpfile} | wc -l ) -gt 0 ] ; then
-        IGCM_debug_Print 1 "!!! Issue with IGCM_card_WriteOption !!!"
-        IGCM_debug_Print 1 "We tried to write : $@"
-        IGCM_debug_Exit "Must check that option $3 in section $2 exist in this file $1"
-        IGCM_debug_Verif_Exit
-      fi
-      \rm ${tmpfile}
-
-      # The tmpfile uses now the real path of the card to be modified,
-      # not just a local tmpfile with PID.
-      tmpfile=$1_mutex_$$
-
-      IGCM_card_CheckConflict $1
-
-      # Do the job
-      ( gawk -f ${libIGCM}/libIGCM_card/IGCM_card_WriteOption.awk -- "$@" 2> /dev/null ) > ${tmpfile}
-
-      cp $1 $1.bak
-      mv ${tmpfile} $1
-
-    else
-      echo
-      IGCM_debug_Print 1 "--Error--> IGCM_card_WriteOption $@"
-      IGCM_debug_Print 1 "           $1 is not readable or not writable"
-      IGCM_debug_Exit "IGCM_card_WriteOption"
+  IGCM_debug_PushStack "IGCM_card_WriteOption" $@
+  if ( [ -r "$1" ] && [ -w "$1" ]  && [ -f "$1" ] ) ; then
+    typeset tmpfile=tmpfile_$$
+    ( IGCM_card_PrintOption "$1" "$2" "$3" | grep "not found" ) > ${tmpfile}
+    if [ $( cat ${tmpfile} | wc -l ) -gt 0 ] ; then
+      IGCM_debug_Print 1 "!!! Issue with IGCM_card_WriteOption !!!"
+      IGCM_debug_Print 1 "We tried to write : $@"
+      IGCM_debug_Exit "Must check that option $3 in section $2 exist in this file $1"
+      IGCM_debug_Verif_Exit
     fi
-    IGCM_debug_PopStack "IGCM_card_WriteOption"
-}
-
+    \rm ${tmpfile}
+
+    # The tmpfile uses now the real path of the card to be modified,
+    # not just a local tmpfile with PID.
+    tmpfile=$1_mutex_$$
+
+    IGCM_card_CheckConflict $1
+
+    # Do the job
+    ( gawk -f ${libIGCM}/libIGCM_card/IGCM_card_WriteOption.awk -- "$@" 2> /dev/null ) > ${tmpfile}
+
+    cp $1 $1.bak
+    mv ${tmpfile} $1
+
+  else
+    echo
+    IGCM_debug_Print 1 "--Error--> IGCM_card_WriteOption $@"
+    IGCM_debug_Print 1 "           $1 is not readable or not writable"
+    IGCM_debug_Exit "IGCM_card_WriteOption"
+  fi
+  IGCM_debug_PopStack "IGCM_card_WriteOption"
+}
+
+#D-#==================================================================
+#D-function IGCM_card_CheckConflict
+#D-* Purpose: Check that a card is not in use by another process. If it is the case wait until it is not.
+#D-* Usage: IGCM_card_CheckConflict run.card
+#D-* Examples:
+#D-
 function IGCM_card_CheckConflict
 {
-    IGCM_debug_PushStack "IGCM_card_CheckConflict" $@
-
-    typeset isleep tmpfiles
-
-    # Watch for possible conflics : Check for other tmpfiles.
+  IGCM_debug_PushStack "IGCM_card_CheckConflict" $@
+  typeset isleep tmpfiles
+
+  # Watch for possible conflics : Check for other tmpfiles.
+  set +A tmpfiles -- $( ls $1_mutex_[0-9]* 2>/dev/null )
+  ((isleep=0))
+  while [ ${#tmpfiles[@]} -gt 0 ] ; do
+    echo "Conflict between two processes working on " $1 "!!!" ${tmpfiles[@]}
+    sleep 1
+    ((isleep=isleep+1))
+    if [ ${isleep} -gt 20 ] ; then
+      echo "Too many loops waiting for other process working on " $1 ". We continue."
+      echo "You should see if one process of your run or post-treatment may have terminated suddenly."
+      echo "Afer, you should erase this(those) file(s) : " ${tmpfiles[@]}
+      # Send a mail to USER ??
+      break ;
+    fi
+    unset tmpfiles
     set +A tmpfiles -- $( ls $1_mutex_[0-9]* 2>/dev/null )
-    ((isleep=0))
-    while [ ${#tmpfiles[@]} -gt 0 ] ; do
-      echo "Conflict between two processes working on " $1 "!!!" ${tmpfiles[@]}
-      sleep 1
-      ((isleep=isleep+1))
-      if [ ${isleep} -gt 20 ] ; then
-        echo "Too many loops waiting for other process working on " $1 ". We continue."
-        echo "You should see if one process of your run or post-treatment may have terminated suddenly."
-        echo "Afer, you should erase this(those) file(s) : " ${tmpfiles[@]}
-# Send a mail to USER ??
-        break ;
-      fi
-      unset tmpfiles
-      set +A tmpfiles -- $( ls $1_mutex_[0-9]* 2>/dev/null )
-    done
-
-    IGCM_debug_PopStack "IGCM_card_CheckConflict"
+  done
+
+  IGCM_debug_PopStack "IGCM_card_CheckConflict"
 }
 
@@ -268,21 +273,21 @@
 function IGCM_card_WriteArrayOption
 {
-    IGCM_debug_PushStack "IGCM_card_WriteArrayOption" $@
-
-    if ( [ -r "$1" ] && [ -w "$1" ]  && [ -f "$1" ] ) ; then
-      typeset tmpfile=tmpfile_$$
-      if [ X"${4}" != X"" ]; then
-        tab=$4
-        IGCM_card_WriteOption $1 $2 $3 '('$( eval echo \${${tab}[@]} | sed -e 's/ /,/g' )')'
-      else
-        IGCM_card_WriteOption $1 $2 $3 '()'
-      fi
+  IGCM_debug_PushStack "IGCM_card_WriteArrayOption" $@
+
+  if ( [ -r "$1" ] && [ -w "$1" ]  && [ -f "$1" ] ) ; then
+    typeset tmpfile=tmpfile_$$
+    if [ X"${4}" != X"" ]; then
+      tab=$4
+      IGCM_card_WriteOption $1 $2 $3 '('$( eval echo \${${tab}[@]} | sed -e 's/ /,/g' )')'
     else
-      echo
-      IGCM_debug_Print 1 "--Error--> IGCM_card_WriteArrayOption $@"
-      IGCM_debug_Print 1 "           $1 is not readable or not writable"
-      IGCM_debug_Exit "IGCM_card_WriteArrayOption"
+      IGCM_card_WriteOption $1 $2 $3 '()'
     fi
-    IGCM_debug_PopStack "IGCM_card_WriteArrayOption"
+  else
+    echo
+    IGCM_debug_Print 1 "--Error--> IGCM_card_WriteArrayOption $@"
+    IGCM_debug_Print 1 "           $1 is not readable or not writable"
+    IGCM_debug_Exit "IGCM_card_WriteArrayOption"
+  fi
+  IGCM_debug_PopStack "IGCM_card_WriteArrayOption"
 }
 
@@ -294,43 +299,43 @@
 function IGCM_card_Check
 {
-    #---------------------
-    if [ ! -n "${libIGCM}" ] ; then
-      echo "Check libIGCM_card ...........................................[ FAILED ]"
-      echo "--Error--> libIGCM variable is not defined"
-      IGCM_debug_Exit "IGCM_card_Check"
-    fi
-
-    #---------------------
-    whence -v gawk > /dev/null 2>&1
-    if [ ! $? -eq 0 ] ; then
-      echo "Check libIGCM_card ...........................................[ FAILED ]"
-      echo "--Error--> gawk command is not defined"
-      IGCM_debug_Exit "IGCM_card_Check"
-    fi
-
-    #---------------------
-    ${libIGCM}/libIGCM_card/IGCM_card_Test.ksh > /tmp/IGCM_card_Test.$$.ref.failed 2>&1
-    status=$?
-
-    if [ ${status} -gt 0 ] ; then
-      IGCM_debug_Print 2 "IGCM_card_Test.ksh failed for some reason"
-      IGCM_debug_Print 2 "Is /tmp full?"
-      df -h
-      IGCM_debug_Print 2 "Where /tmp is pointing to?"
-      ls -l /
-    fi
-
-    if diff /tmp/IGCM_card_Test.$$.ref.failed ${libIGCM}/libIGCM_card/IGCM_card_Test.ref > /dev/null 2>&1 ; then
-      echo "Check libIGCM_card ...............................................[ OK ]"
-      rm -f /tmp/IGCM_card_Test.$$.ref.failed
-    else
-      echo "Check libIGCM_card ...........................................[ FAILED ]"
-      echo "--Error--> Execution of ${libIGCM}/libIGCM_card/IGCM_card_Test.ksh"
-      echo "           has produced the file IGCM_card_Test.ref.failed"
-      echo "           Please analyse differences with the reference file by typing:"
-      echo "           diff IGCM_card_Test.ref.failed ${libIGCM}/libIGCM_card/IGCM_card_Test.ref"
-      echo "           Report errors to the author: Patrick.Brockmann@cea.fr"
-      cat /tmp/IGCM_card_Test.$$.ref.failed
-      IGCM_debug_Exit "IGCM_card_Check"
-    fi
-}
+  #---------------------
+  if [ ! -n "${libIGCM}" ] ; then
+    echo "Check libIGCM_card ...........................................[ FAILED ]"
+    echo "--Error--> libIGCM variable is not defined"
+    IGCM_debug_Exit "IGCM_card_Check"
+  fi
+
+  #---------------------
+  whence -v gawk > /dev/null 2>&1
+  if [ ! $? -eq 0 ] ; then
+    echo "Check libIGCM_card ...........................................[ FAILED ]"
+    echo "--Error--> gawk command is not defined"
+    IGCM_debug_Exit "IGCM_card_Check"
+  fi
+
+  #---------------------
+  ${libIGCM}/libIGCM_card/IGCM_card_Test.ksh > /tmp/IGCM_card_Test.$$.ref.failed 2>&1
+  status=$?
+
+  if [ ${status} -gt 0 ] ; then
+    IGCM_debug_Print 2 "IGCM_card_Test.ksh failed for some reason"
+    IGCM_debug_Print 2 "Is /tmp full?"
+    df -h
+    IGCM_debug_Print 2 "Where /tmp is pointing to?"
+    ls -l /
+  fi
+
+  if diff /tmp/IGCM_card_Test.$$.ref.failed ${libIGCM}/libIGCM_card/IGCM_card_Test.ref > /dev/null 2>&1 ; then
+    echo "Check libIGCM_card ...............................................[ OK ]"
+    rm -f /tmp/IGCM_card_Test.$$.ref.failed
+  else
+    echo "Check libIGCM_card ...........................................[ FAILED ]"
+    echo "--Error--> Execution of ${libIGCM}/libIGCM_card/IGCM_card_Test.ksh"
+    echo "           has produced the file IGCM_card_Test.ref.failed"
+    echo "           Please analyse differences with the reference file by typing:"
+    echo "           diff IGCM_card_Test.ref.failed ${libIGCM}/libIGCM_card/IGCM_card_Test.ref"
+    echo "           Report errors to the author: Patrick.Brockmann@cea.fr"
+    cat /tmp/IGCM_card_Test.$$.ref.failed
+    IGCM_debug_Exit "IGCM_card_Check"
+  fi
+}
