Changeset 1111


Ignore:
Timestamp:
10/23/14 12:04:17 (10 years ago)
Author:
sdipsl
Message:

cosmetics. emacs macro whitespace-cleanup and indent-region

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/libIGCM/libIGCM_card/libIGCM_card.ksh

    r1109 r1111  
    5656function IGCM_card_PrintOption 
    5757{ 
    58     IGCM_debug_PushStack "IGCM_card_PrintOption" $@ 
    59     if ( [ -r "$1" ] && [ -f "$1" ] ) ; then 
    60       gawk -f ${libIGCM}/libIGCM_card/IGCM_card_PrintOption.awk "$@" 
    61     else 
    62       echo 
    63       IGCM_debug_Print 1 "--Error--> IGCM_card_PrintOption $@" 
    64       IGCM_debug_Print 1 "           $1 is not readable" 
    65       IGCM_debug_Exit "IGCM_card_PrintOption" 
    66     fi 
    67     IGCM_debug_PopStack "IGCM_card_PrintOption" 
     58  IGCM_debug_PushStack "IGCM_card_PrintOption" $@ 
     59  if ( [ -r "$1" ] && [ -f "$1" ] ) ; then 
     60    gawk -f ${libIGCM}/libIGCM_card/IGCM_card_PrintOption.awk "$@" 
     61  else 
     62    echo 
     63    IGCM_debug_Print 1 "--Error--> IGCM_card_PrintOption $@" 
     64    IGCM_debug_Print 1 "           $1 is not readable" 
     65    IGCM_debug_Exit "IGCM_card_PrintOption" 
     66  fi 
     67  IGCM_debug_PopStack "IGCM_card_PrintOption" 
    6868} 
    6969 
     
    7676function IGCM_card_PrintSection 
    7777{ 
    78     IGCM_debug_PushStack "IGCM_card_PrintSection" $@ 
    79     if ( [ -r "$1" ] && [ -f "$1" ] ) ; then 
    80       gawk -f ${libIGCM}/libIGCM_card/IGCM_card_PrintSection.awk -- "$@" 
    81     else 
    82       IGCM_debug_Print 1 "--Error--> IGCM_card_PrintSection $@" 
    83       IGCM_debug_Print 1 "           $1 is not readable" 
    84       IGCM_debug_Exit "IGCM_card_PrintSection" 
    85     fi 
    86     IGCM_debug_PopStack "IGCM_card_PrintSection" 
     78  IGCM_debug_PushStack "IGCM_card_PrintSection" $@ 
     79  if ( [ -r "$1" ] && [ -f "$1" ] ) ; then 
     80    gawk -f ${libIGCM}/libIGCM_card/IGCM_card_PrintSection.awk -- "$@" 
     81  else 
     82    IGCM_debug_Print 1 "--Error--> IGCM_card_PrintSection $@" 
     83    IGCM_debug_Print 1 "           $1 is not readable" 
     84    IGCM_debug_Exit "IGCM_card_PrintSection" 
     85  fi 
     86  IGCM_debug_PopStack "IGCM_card_PrintSection" 
    8787} 
    8888 
     
    9595function IGCM_card_DefineVariableFromOption 
    9696{ 
    97     IGCM_debug_PushStack "IGCM_card_DefineVariableFromOption" $@ 
    98     if ( [ -r "$1" ] && [ -f "$1" ] ) ; then 
    99       # Get basename of card file ($1) 
    100       typeset name1=${1##*/} 
     97  IGCM_debug_PushStack "IGCM_card_DefineVariableFromOption" $@ 
     98  if ( [ -r "$1" ] && [ -f "$1" ] ) ; then 
     99    # Get basename of card file ($1) 
     100    typeset name1=${1##*/} 
    101101      # Build name of variable as $1_$2_$3 (cardname_Section_Option) 
    102102      typeset name=${name1%%.*}_${2}_${3} 
     
    113113      fi 
    114114      eval ${name}=${value} 
    115     else 
    116       echo 
    117       IGCM_debug_Print 1 "--Error--> IGCM_card_DefineVariableFromOption" 
    118       IGCM_debug_Print 1 "--Error--> $1 is not readable" 
    119       IGCM_debug_Exit "IGCM_card_DefineVariableFromOption" 
    120       IGCM_debug_Verif_Exit 
    121     fi 
    122     IGCM_debug_PopStack "IGCM_card_DefineVariableFromOption" 
     115  else 
     116    echo 
     117    IGCM_debug_Print 1 "--Error--> IGCM_card_DefineVariableFromOption" 
     118    IGCM_debug_Print 1 "--Error--> $1 is not readable" 
     119    IGCM_debug_Exit "IGCM_card_DefineVariableFromOption" 
     120    IGCM_debug_Verif_Exit 
     121  fi 
     122  IGCM_debug_PopStack "IGCM_card_DefineVariableFromOption" 
    123123} 
    124124 
     
    131131function IGCM_card_DefineArrayFromOption 
    132132{ 
    133     IGCM_debug_PushStack "IGCM_card_DefineArrayFromOption" $@ 
    134     if ( [ -r "$1" ] && [ -f "$1" ] ) ; then 
    135       # Get basename of card file ($1) 
    136       typeset name1=${1##*/} 
    137       # Build name of array as $1_$2_$3 (cardname_Section_Option) 
    138       typeset name=${name1%%.*}_${2}_${3} 
    139       eval unset ${name} 
    140       eval ${name}[0]=${NULL_STR} 
    141       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)}' ) 
    142     else 
    143       echo 
    144       IGCM_debug_Print 1 "--Error--> IGCM_card_DefineArrayFromOption $@" 
    145       IGCM_debug_Print 1 "           $1 is not readable" 
    146       IGCM_debug_Exit "IGCM_card_DefineArrayFromOption" 
    147     fi 
    148     IGCM_debug_PopStack "IGCM_card_DefineArrayFromOption" 
     133  IGCM_debug_PushStack "IGCM_card_DefineArrayFromOption" $@ 
     134  if ( [ -r "$1" ] && [ -f "$1" ] ) ; then 
     135    # Get basename of card file ($1) 
     136    typeset name1=${1##*/} 
     137    # Build name of array as $1_$2_$3 (cardname_Section_Option) 
     138    typeset name=${name1%%.*}_${2}_${3} 
     139    eval unset ${name} 
     140    eval ${name}[0]=${NULL_STR} 
     141    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)}' ) 
     142  else 
     143    echo 
     144    IGCM_debug_Print 1 "--Error--> IGCM_card_DefineArrayFromOption $@" 
     145    IGCM_debug_Print 1 "           $1 is not readable" 
     146    IGCM_debug_Exit "IGCM_card_DefineArrayFromOption" 
     147  fi 
     148  IGCM_debug_PopStack "IGCM_card_DefineArrayFromOption" 
    149149} 
    150150 
     
    157157function IGCM_card_DefineArrayFromSection 
    158158{ 
    159     IGCM_debug_PushStack "IGCM_card_DefineArrayFromSection" $@ 
    160     if ( [ -r "$1" ] && [ -f "$1" ] ) ; then 
    161       # Get basename of card file ($1) 
    162       typeset name1=${1##*/} 
    163       # Build name of array as $1_$2 (cardname_Section) 
    164       typeset name=${name1%%.*}_${2} 
     159  IGCM_debug_PushStack "IGCM_card_DefineArrayFromSection" $@ 
     160  if ( [ -r "$1" ] && [ -f "$1" ] ) ; then 
     161    # Get basename of card file ($1) 
     162    typeset name1=${1##*/} 
     163    # Build name of array as $1_$2 (cardname_Section) 
     164    typeset name=${name1%%.*}_${2} 
     165    eval unset ${name} 
     166    eval ${name}[0]=${NULL_STR} 
     167    set +A ${name} -- $( gawk -f ${libIGCM}/libIGCM_card/IGCM_card_PrintSection.awk -- "$@" ) 
     168    #if [ "$( eval echo \${${name}[@]} )" = "Error: Section not found" ] ; then 
     169    #    echo 
     170    #    IGCM_debug_Print 1 "Error with readding of ${name} variable in ${1}." 
     171    #    IGCM_debug_Print 1 "Error: Section ${2} not found" 
     172    #    IGCM_debug_Exit 
     173    #    IGCM_debug_Verif_Exit 
     174    #fi 
     175    if [ "$( eval echo \${${name}[@]} )" = "Error: Section not found" ] ; then 
     176      echo 
     177      IGCM_debug_Print 1 "Warning with readding of ${name} variable in ${1}." 
     178      IGCM_debug_Print 1 "Warning: Section ${2} not found" 
    165179      eval unset ${name} 
    166       eval ${name}[0]=${NULL_STR} 
    167       set +A ${name} -- $( gawk -f ${libIGCM}/libIGCM_card/IGCM_card_PrintSection.awk -- "$@" ) 
    168       #if [ "$( eval echo \${${name}[@]} )" = "Error: Section not found" ] ; then 
    169       #    echo 
    170       #    IGCM_debug_Print 1 "Error with readding of ${name} variable in ${1}." 
    171       #    IGCM_debug_Print 1 "Error: Section ${2} not found" 
    172       #    IGCM_debug_Exit 
    173       #    IGCM_debug_Verif_Exit 
    174       #fi 
    175       if [ "$( eval echo \${${name}[@]} )" = "Error: Section not found" ] ; then 
    176         echo 
    177         IGCM_debug_Print 1 "Warning with readding of ${name} variable in ${1}." 
    178         IGCM_debug_Print 1 "Warning: Section ${2} not found" 
    179         eval unset ${name} 
    180       fi 
    181     else 
    182       IGCM_debug_Print 1 "--Error--> IGCM_card_DefineArrayFromSection $@" 
    183       IGCM_debug_Print 1 "           $1 is not readable" 
    184       IGCM_debug_Exit "IGCM_card_DefineArrayFromSection" 
    185180    fi 
    186     IGCM_debug_PopStack "IGCM_card_DefineArrayFromSection" 
     181  else 
     182    IGCM_debug_Print 1 "--Error--> IGCM_card_DefineArrayFromSection $@" 
     183    IGCM_debug_Print 1 "           $1 is not readable" 
     184    IGCM_debug_Exit "IGCM_card_DefineArrayFromSection" 
     185  fi 
     186  IGCM_debug_PopStack "IGCM_card_DefineArrayFromSection" 
    187187} 
    188188 
     
    199199function IGCM_card_WriteOption 
    200200{ 
    201     IGCM_debug_PushStack "IGCM_card_WriteOption" $@ 
    202     if ( [ -r "$1" ] && [ -w "$1" ]  && [ -f "$1" ] ) ; then 
    203       typeset tmpfile=tmpfile_$$ 
    204       ( IGCM_card_PrintOption "$1" "$2" "$3" | grep "not found" ) > ${tmpfile} 
    205       if [ $( cat ${tmpfile} | wc -l ) -gt 0 ] ; then 
    206         IGCM_debug_Print 1 "!!! Issue with IGCM_card_WriteOption !!!" 
    207         IGCM_debug_Print 1 "We tried to write : $@" 
    208         IGCM_debug_Exit "Must check that option $3 in section $2 exist in this file $1" 
    209         IGCM_debug_Verif_Exit 
    210       fi 
    211       \rm ${tmpfile} 
    212  
    213       # The tmpfile uses now the real path of the card to be modified, 
    214       # not just a local tmpfile with PID. 
    215       tmpfile=$1_mutex_$$ 
    216  
    217       IGCM_card_CheckConflict $1 
    218  
    219       # Do the job 
    220       ( gawk -f ${libIGCM}/libIGCM_card/IGCM_card_WriteOption.awk -- "$@" 2> /dev/null ) > ${tmpfile} 
    221  
    222       cp $1 $1.bak 
    223       mv ${tmpfile} $1 
    224  
    225     else 
    226       echo 
    227       IGCM_debug_Print 1 "--Error--> IGCM_card_WriteOption $@" 
    228       IGCM_debug_Print 1 "           $1 is not readable or not writable" 
    229       IGCM_debug_Exit "IGCM_card_WriteOption" 
     201  IGCM_debug_PushStack "IGCM_card_WriteOption" $@ 
     202  if ( [ -r "$1" ] && [ -w "$1" ]  && [ -f "$1" ] ) ; then 
     203    typeset tmpfile=tmpfile_$$ 
     204    ( IGCM_card_PrintOption "$1" "$2" "$3" | grep "not found" ) > ${tmpfile} 
     205    if [ $( cat ${tmpfile} | wc -l ) -gt 0 ] ; then 
     206      IGCM_debug_Print 1 "!!! Issue with IGCM_card_WriteOption !!!" 
     207      IGCM_debug_Print 1 "We tried to write : $@" 
     208      IGCM_debug_Exit "Must check that option $3 in section $2 exist in this file $1" 
     209      IGCM_debug_Verif_Exit 
    230210    fi 
    231     IGCM_debug_PopStack "IGCM_card_WriteOption" 
    232 } 
    233  
     211    \rm ${tmpfile} 
     212 
     213    # The tmpfile uses now the real path of the card to be modified, 
     214    # not just a local tmpfile with PID. 
     215    tmpfile=$1_mutex_$$ 
     216 
     217    IGCM_card_CheckConflict $1 
     218 
     219    # Do the job 
     220    ( gawk -f ${libIGCM}/libIGCM_card/IGCM_card_WriteOption.awk -- "$@" 2> /dev/null ) > ${tmpfile} 
     221 
     222    cp $1 $1.bak 
     223    mv ${tmpfile} $1 
     224 
     225  else 
     226    echo 
     227    IGCM_debug_Print 1 "--Error--> IGCM_card_WriteOption $@" 
     228    IGCM_debug_Print 1 "           $1 is not readable or not writable" 
     229    IGCM_debug_Exit "IGCM_card_WriteOption" 
     230  fi 
     231  IGCM_debug_PopStack "IGCM_card_WriteOption" 
     232} 
     233 
     234#D-#================================================================== 
     235#D-function IGCM_card_CheckConflict 
     236#D-* Purpose: Check that a card is not in use by another process. If it is the case wait until it is not. 
     237#D-* Usage: IGCM_card_CheckConflict run.card 
     238#D-* Examples: 
     239#D- 
    234240function IGCM_card_CheckConflict 
    235241{ 
    236     IGCM_debug_PushStack "IGCM_card_CheckConflict" $@ 
    237  
    238     typeset isleep tmpfiles 
    239  
    240     # Watch for possible conflics : Check for other tmpfiles. 
     242  IGCM_debug_PushStack "IGCM_card_CheckConflict" $@ 
     243  typeset isleep tmpfiles 
     244 
     245  # Watch for possible conflics : Check for other tmpfiles. 
     246  set +A tmpfiles -- $( ls $1_mutex_[0-9]* 2>/dev/null ) 
     247  ((isleep=0)) 
     248  while [ ${#tmpfiles[@]} -gt 0 ] ; do 
     249    echo "Conflict between two processes working on " $1 "!!!" ${tmpfiles[@]} 
     250    sleep 1 
     251    ((isleep=isleep+1)) 
     252    if [ ${isleep} -gt 20 ] ; then 
     253      echo "Too many loops waiting for other process working on " $1 ". We continue." 
     254      echo "You should see if one process of your run or post-treatment may have terminated suddenly." 
     255      echo "Afer, you should erase this(those) file(s) : " ${tmpfiles[@]} 
     256      # Send a mail to USER ?? 
     257      break ; 
     258    fi 
     259    unset tmpfiles 
    241260    set +A tmpfiles -- $( ls $1_mutex_[0-9]* 2>/dev/null ) 
    242     ((isleep=0)) 
    243     while [ ${#tmpfiles[@]} -gt 0 ] ; do 
    244       echo "Conflict between two processes working on " $1 "!!!" ${tmpfiles[@]} 
    245       sleep 1 
    246       ((isleep=isleep+1)) 
    247       if [ ${isleep} -gt 20 ] ; then 
    248         echo "Too many loops waiting for other process working on " $1 ". We continue." 
    249         echo "You should see if one process of your run or post-treatment may have terminated suddenly." 
    250         echo "Afer, you should erase this(those) file(s) : " ${tmpfiles[@]} 
    251 # Send a mail to USER ?? 
    252         break ; 
    253       fi 
    254       unset tmpfiles 
    255       set +A tmpfiles -- $( ls $1_mutex_[0-9]* 2>/dev/null ) 
    256     done 
    257  
    258     IGCM_debug_PopStack "IGCM_card_CheckConflict" 
     261  done 
     262 
     263  IGCM_debug_PopStack "IGCM_card_CheckConflict" 
    259264} 
    260265 
     
    268273function IGCM_card_WriteArrayOption 
    269274{ 
    270     IGCM_debug_PushStack "IGCM_card_WriteArrayOption" $@ 
    271  
    272     if ( [ -r "$1" ] && [ -w "$1" ]  && [ -f "$1" ] ) ; then 
    273       typeset tmpfile=tmpfile_$$ 
    274       if [ X"${4}" != X"" ]; then 
    275         tab=$4 
    276         IGCM_card_WriteOption $1 $2 $3 '('$( eval echo \${${tab}[@]} | sed -e 's/ /,/g' )')' 
    277       else 
    278         IGCM_card_WriteOption $1 $2 $3 '()' 
    279       fi 
     275  IGCM_debug_PushStack "IGCM_card_WriteArrayOption" $@ 
     276 
     277  if ( [ -r "$1" ] && [ -w "$1" ]  && [ -f "$1" ] ) ; then 
     278    typeset tmpfile=tmpfile_$$ 
     279    if [ X"${4}" != X"" ]; then 
     280      tab=$4 
     281      IGCM_card_WriteOption $1 $2 $3 '('$( eval echo \${${tab}[@]} | sed -e 's/ /,/g' )')' 
    280282    else 
    281       echo 
    282       IGCM_debug_Print 1 "--Error--> IGCM_card_WriteArrayOption $@" 
    283       IGCM_debug_Print 1 "           $1 is not readable or not writable" 
    284       IGCM_debug_Exit "IGCM_card_WriteArrayOption" 
     283      IGCM_card_WriteOption $1 $2 $3 '()' 
    285284    fi 
    286     IGCM_debug_PopStack "IGCM_card_WriteArrayOption" 
     285  else 
     286    echo 
     287    IGCM_debug_Print 1 "--Error--> IGCM_card_WriteArrayOption $@" 
     288    IGCM_debug_Print 1 "           $1 is not readable or not writable" 
     289    IGCM_debug_Exit "IGCM_card_WriteArrayOption" 
     290  fi 
     291  IGCM_debug_PopStack "IGCM_card_WriteArrayOption" 
    287292} 
    288293 
     
    294299function IGCM_card_Check 
    295300{ 
    296     #--------------------- 
    297     if [ ! -n "${libIGCM}" ] ; then 
    298       echo "Check libIGCM_card ...........................................[ FAILED ]" 
    299       echo "--Error--> libIGCM variable is not defined" 
    300       IGCM_debug_Exit "IGCM_card_Check" 
    301     fi 
    302  
    303     #--------------------- 
    304     whence -v gawk > /dev/null 2>&1 
    305     if [ ! $? -eq 0 ] ; then 
    306       echo "Check libIGCM_card ...........................................[ FAILED ]" 
    307       echo "--Error--> gawk command is not defined" 
    308       IGCM_debug_Exit "IGCM_card_Check" 
    309     fi 
    310  
    311     #--------------------- 
    312     ${libIGCM}/libIGCM_card/IGCM_card_Test.ksh > /tmp/IGCM_card_Test.$$.ref.failed 2>&1 
    313     status=$? 
    314  
    315     if [ ${status} -gt 0 ] ; then 
    316       IGCM_debug_Print 2 "IGCM_card_Test.ksh failed for some reason" 
    317       IGCM_debug_Print 2 "Is /tmp full?" 
    318       df -h 
    319       IGCM_debug_Print 2 "Where /tmp is pointing to?" 
    320       ls -l / 
    321     fi 
    322  
    323     if diff /tmp/IGCM_card_Test.$$.ref.failed ${libIGCM}/libIGCM_card/IGCM_card_Test.ref > /dev/null 2>&1 ; then 
    324       echo "Check libIGCM_card ...............................................[ OK ]" 
    325       rm -f /tmp/IGCM_card_Test.$$.ref.failed 
    326     else 
    327       echo "Check libIGCM_card ...........................................[ FAILED ]" 
    328       echo "--Error--> Execution of ${libIGCM}/libIGCM_card/IGCM_card_Test.ksh" 
    329       echo "           has produced the file IGCM_card_Test.ref.failed" 
    330       echo "           Please analyse differences with the reference file by typing:" 
    331       echo "           diff IGCM_card_Test.ref.failed ${libIGCM}/libIGCM_card/IGCM_card_Test.ref" 
    332       echo "           Report errors to the author: Patrick.Brockmann@cea.fr" 
    333       cat /tmp/IGCM_card_Test.$$.ref.failed 
    334       IGCM_debug_Exit "IGCM_card_Check" 
    335     fi 
    336 } 
     301  #--------------------- 
     302  if [ ! -n "${libIGCM}" ] ; then 
     303    echo "Check libIGCM_card ...........................................[ FAILED ]" 
     304    echo "--Error--> libIGCM variable is not defined" 
     305    IGCM_debug_Exit "IGCM_card_Check" 
     306  fi 
     307 
     308  #--------------------- 
     309  whence -v gawk > /dev/null 2>&1 
     310  if [ ! $? -eq 0 ] ; then 
     311    echo "Check libIGCM_card ...........................................[ FAILED ]" 
     312    echo "--Error--> gawk command is not defined" 
     313    IGCM_debug_Exit "IGCM_card_Check" 
     314  fi 
     315 
     316  #--------------------- 
     317  ${libIGCM}/libIGCM_card/IGCM_card_Test.ksh > /tmp/IGCM_card_Test.$$.ref.failed 2>&1 
     318  status=$? 
     319 
     320  if [ ${status} -gt 0 ] ; then 
     321    IGCM_debug_Print 2 "IGCM_card_Test.ksh failed for some reason" 
     322    IGCM_debug_Print 2 "Is /tmp full?" 
     323    df -h 
     324    IGCM_debug_Print 2 "Where /tmp is pointing to?" 
     325    ls -l / 
     326  fi 
     327 
     328  if diff /tmp/IGCM_card_Test.$$.ref.failed ${libIGCM}/libIGCM_card/IGCM_card_Test.ref > /dev/null 2>&1 ; then 
     329    echo "Check libIGCM_card ...............................................[ OK ]" 
     330    rm -f /tmp/IGCM_card_Test.$$.ref.failed 
     331  else 
     332    echo "Check libIGCM_card ...........................................[ FAILED ]" 
     333    echo "--Error--> Execution of ${libIGCM}/libIGCM_card/IGCM_card_Test.ksh" 
     334    echo "           has produced the file IGCM_card_Test.ref.failed" 
     335    echo "           Please analyse differences with the reference file by typing:" 
     336    echo "           diff IGCM_card_Test.ref.failed ${libIGCM}/libIGCM_card/IGCM_card_Test.ref" 
     337    echo "           Report errors to the author: Patrick.Brockmann@cea.fr" 
     338    cat /tmp/IGCM_card_Test.$$.ref.failed 
     339    IGCM_debug_Exit "IGCM_card_Check" 
     340  fi 
     341} 
Note: See TracChangeset for help on using the changeset viewer.