Changeset 1075


Ignore:
Timestamp:
10/01/14 11:49:05 (10 years ago)
Author:
sdipsl
Message:

cosmetics (replace tabulations by space and use the same indentation)

File:
1 edited

Legend:

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

    r1074 r1075  
    953953# 
    954954# This function is used to modify a parameter file for a specific variable. 
    955 # The file must be a ".def" file, i.e. with IOIPSL parameter file syntax.  
    956 # This function can be used in the comp.driver files for the components.  
     955# The file must be a ".def" file, i.e. with IOIPSL parameter file syntax. 
     956# This function can be used in the comp.driver files for the components. 
    957957# 
    958 # Arguments:  
    959 # - type   : first argument must be blocker or nonblocker.  
    960 #            For "blocker" case, the variable must be attributed the keyworld AUTO  
     958# Arguments: 
     959# - type   : first argument must be blocker or nonblocker. 
     960#            For "blocker" case, the variable must be attributed the keyworld AUTO 
    961961#            otherwise this function will exit. 
    962 #            For "nonblocker" case, the user can remove or modify the variable. For  
    963 #            this case, as long as AUTO is not set, no modification will be done.  
     962#            For "nonblocker" case, the user can remove or modify the variable. For 
     963#            this case, as long as AUTO is not set, no modification will be done. 
    964964# - filein : the file in run directory of .def type in which the variable should be set 
    965965# - key    : the variable to modify 
    966 # - value  : the value to set the key equal to, optional. If value is not set or if  
     966# - value  : the value to set the key equal to, optional. If value is not set or if 
    967967#            value=DEFAULT, then a default value must be given in filein using syntax : 
    968968#            key= AUTO : DEFAULT=def_value 
    969969# 
    970     IGCM_debug_PushStack "IGCM_comp_modifyDefFile" 
    971      
    972     # Set local variables and test the arguments 
    973     if [ $# = 4 ] ; then 
    974         # Normal case with 4 arguments 
    975         type=$1 ; filein=$2 ; key=$3 ; value=$4 
    976     elif [ $# = 3 ] ; then 
    977         # Normal case with 3 arguments 
    978         type=$1 ; filein=$2 ;   key=$3; value="DEFAULT" 
     970  IGCM_debug_PushStack "IGCM_comp_modifyDefFile" 
     971 
     972  # Set local variables and test the arguments 
     973  if [ $# = 4 ] ; then 
     974    # Normal case with 4 arguments 
     975    type=$1 ; filein=$2 ; key=$3 ; value=$4 
     976  elif [ $# = 3 ] ; then 
     977    # Normal case with 3 arguments 
     978    type=$1 ; filein=$2 ;       key=$3; value="DEFAULT" 
     979  else 
     980    IGCM_debug_Exit "IGCM_comp_modifyDefFile: Bad number of arguments." 
     981    return 
     982  fi 
     983  IGCM_debug_Print 1 "Entering IGCM_comp_modifyDefFile with arguments: $type $filein $key $value" 
     984 
     985  # Test if first argument is correct 
     986  if [ $type != blocker ] && [ $type != nonblocker ] ; then 
     987    IGCM_debug_Exit "IGCM_comp_modifyDefFile: Error in first argument must be blocker or nonblocker" 
     988    return 
     989  fi 
     990 
     991  # Test if the file exist 
     992  if [ ! -f ${filein} ] ; then 
     993    IGCM_debug_Exit "IGCM_comp_modifyDefFile: $filein does not exist." 
     994    return 
     995  fi 
     996 
     997  # Define list of files to test using all files with suffix .def 
     998  filelist=$( ls *def ) 
     999 
     1000  # Count number of occurances for the key in all files 
     1001  nb_occ=$( grep -w $key $filelist |grep -v "#"  |wc -l ) 
     1002 
     1003  # Test if key is set several times 
     1004  if [ $nb_occ -gt 1 ] ; then 
     1005    IGCM_debug_Exit "IGCM_comp_modifyDefFile : Error in $filein: Variable=$key is set ${nb_occ} times" 
     1006    return 
     1007  fi 
     1008 
     1009  # Treatement according to different cases 
     1010  if [ $nb_occ -eq 0 ] && [ $type = blocker ] ; then 
     1011    # Stop if the key is never set and the function is blocker 
     1012    IGCM_debug_Exit "IGCM_comp_modifyDefFile : Error in $filein: Variable=$key has been removed but this function is blocker. " 
     1013    IGCM_debug_Print 1 "IGCM_comp_modifyDefFile: restore $filein for variable $key." 
     1014  elif [ $nb_occ -eq 0 ] && [ $type = nonblocker ] ; then 
     1015    # The key is not set but it is a nonblocker call so nothing is done. 
     1016    IGCM_debug_Print 1 "IGCM_comp_modifyDefFile: $key is not set in $filein. This is a nonblocker call so nothing is done." 
     1017    IGCM_debug_Print 1 "IGCM_comp_modifyDefFile: Default value for $key from the model will be used." 
     1018  elif [ $( grep $key $filein | grep -v "\#"  |wc -l ) = 0 ] ; then 
     1019    # Variable key is not set in filein, stop. 
     1020    IGCM_debug_Exit "IGCM_comp_modifyDefFile : Variable $key is not set in correct file. It should be set in $filein." 
     1021  else 
     1022    # Read the value of key from filein 
     1023    if [ X"$( grep $key $filein | grep -v "\#" | grep AUTO )" = "X" ] ; then 
     1024      # The key variable is not set to AUTO 
     1025      if [ $type = blocker ] ; then 
     1026        # Stop because this is a blocker call 
     1027        IGCM_debug_Exit "IGCM_comp_modifyDefFile : The variable $key cannot be modified. It should be set to AUTO." 
     1028      else 
     1029        # Do nothing. Suppose that the user did set the variable correct 
     1030        IGCM_debug_Print 1 "IGCM_comp_modifyDefFile: $key is set by the user. Nothing done." 
     1031      fi 
    9791032    else 
    980         IGCM_debug_Exit "IGCM_comp_modifyDefFile: Bad number of arguments." 
    981         return 
    982     fi 
    983     IGCM_debug_Print 1 "Entering IGCM_comp_modifyDefFile with arguments: $type $filein $key $value" 
    984  
    985     # Test if first argument is correct 
    986     if [ $type != blocker ] && [ $type != nonblocker ] ; then 
    987         IGCM_debug_Exit "IGCM_comp_modifyDefFile: Error in first argument must be blocker or nonblocker" 
    988         return 
    989     fi 
    990  
    991     # Test if the file exist 
    992     if [ ! -f ${filein} ] ; then 
    993         IGCM_debug_Exit "IGCM_comp_modifyDefFile: $filein does not exist." 
    994         return 
    995     fi 
    996  
    997     # Define list of files to test using all files with suffix .def 
    998     filelist=$( ls *def ) 
    999  
    1000     # Count number of occurances for the key in all files 
    1001     nb_occ=$( grep -w $key $filelist |grep -v "#"  |wc -l ) 
    1002  
    1003     # Test if key is set several times 
    1004     if [ $nb_occ -gt 1 ] ; then 
    1005         IGCM_debug_Exit "IGCM_comp_modifyDefFile : Error in $filein: Variable=$key is set ${nb_occ} times" 
    1006         return 
    1007     fi 
    1008  
    1009     # Treatement according to different cases 
    1010     if [ $nb_occ -eq 0 ] && [ $type = blocker ] ; then 
    1011         # Stop if the key is never set and the function is blocker 
    1012         IGCM_debug_Exit "IGCM_comp_modifyDefFile : Error in $filein: Variable=$key has been removed but this function is blocker. " 
    1013         IGCM_debug_Print 1 "IGCM_comp_modifyDefFile: restore $filein for variable $key." 
    1014     elif [ $nb_occ -eq 0 ] && [ $type = nonblocker ] ; then 
    1015         # The key is not set but it is a nonblocker call so nothing is done. 
    1016         IGCM_debug_Print 1 "IGCM_comp_modifyDefFile: $key is not set in $filein. This is a nonblocker call so nothing is done." 
    1017         IGCM_debug_Print 1 "IGCM_comp_modifyDefFile: Default value for $key from the model will be used." 
    1018     elif [ $( grep $key $filein | grep -v "\#"  |wc -l ) = 0 ] ; then 
    1019         # Variable key is not set in filein, stop.  
    1020         IGCM_debug_Exit "IGCM_comp_modifyDefFile : Variable $key is not set in correct file. It should be set in $filein." 
    1021     else 
    1022         # Read the value of key from filein 
    1023         if [ X"$( grep $key $filein | grep -v "\#" | grep AUTO )" = "X" ] ; then 
    1024             # The key variable is not set to AUTO  
    1025             if [ $type = blocker ] ; then 
    1026                 # Stop because this is a blocker call 
    1027                 IGCM_debug_Exit "IGCM_comp_modifyDefFile : The variable $key cannot be modified. It should be set to AUTO." 
    1028             else 
    1029                 # Do nothing. Suppose that the user did set the variable correct 
    1030                 IGCM_debug_Print 1 "IGCM_comp_modifyDefFile: $key is set by the user. Nothing done." 
    1031             fi 
    1032         else 
    1033             # The variable key is set to AUTO. 
    1034  
    1035             # For option DEFAULT, read default value from file. 
    1036             if [ X"$value" = XDEFAULT ] || [ X"$value" = X ] ; then 
    1037                 # Case to set DEFAULT value 
    1038                 # Read default value from filein 
    1039                 value=$( grep $key $filein | grep -v "\#" | awk  -F"DEFAULT *=" '{print $2}') 
    1040  
    1041                 if [ X"$value" = X ] ; then 
    1042                     IGCM_debug_Exit "IGCM_comp_modifyDefFile : The variable $key needs a DEFAULT value in $filein." 
    1043                     IGCM_debug_Print 1 "IGCM_comp_modifyDefFile: The syntax in $filein should be:" 
    1044                     IGCM_debug_Print 1 "IGCM_comp_modifyDefFile: $key=_AUTO_:DEFAULT=def_value" 
    1045                     return 
    1046                 fi 
    1047             fi 
    1048  
    1049             # Now change key in filein 
    1050             sed -e "s/^${key}\ *=.*/${key}= ${value}/" $filein > $filein.tmp 
    1051             IGCM_debug_Print 1 "IGCM_comp_modifyDefFile: In $filein set $key=$value" 
    1052             \mv $filein.tmp $filein 
    1053         fi 
    1054     fi   
     1033      # The variable key is set to AUTO. 
     1034 
     1035      # For option DEFAULT, read default value from file. 
     1036      if [ X"$value" = XDEFAULT ] || [ X"$value" = X ] ; then 
     1037        # Case to set DEFAULT value 
     1038        # Read default value from filein 
     1039        value=$( grep $key $filein | grep -v "\#" | awk  -F"DEFAULT *=" '{print $2}') 
     1040 
     1041        if [ X"$value" = X ] ; then 
     1042          IGCM_debug_Exit "IGCM_comp_modifyDefFile : The variable $key needs a DEFAULT value in $filein." 
     1043          IGCM_debug_Print 1 "IGCM_comp_modifyDefFile: The syntax in $filein should be:" 
     1044          IGCM_debug_Print 1 "IGCM_comp_modifyDefFile: $key=_AUTO_:DEFAULT=def_value" 
     1045          return 
     1046        fi 
     1047      fi 
     1048 
     1049      # Now change key in filein 
     1050      sed -e "s/^${key}\ *=.*/${key}= ${value}/" $filein > $filein.tmp 
     1051      IGCM_debug_Print 1 "IGCM_comp_modifyDefFile: In $filein set $key=$value" 
     1052      \mv $filein.tmp $filein 
     1053    fi 
     1054  fi 
    10551055} 
    10561056 
     
    10661066# This function is used to modify the value for a specific attribute and variable id. 
    10671067# The file must be a of xml syntax. 
    1068 # This function can be used in the comp.driver files for the components.  
     1068# This function can be used in the comp.driver files for the components. 
    10691069# 
    1070 # Arguments:  
    1071 # - type      : first argument must be blocker, nonblocker or force.  
    1072 #               For "blocker" case, the variable must be attributed the keyworld AUTO  
     1070# Arguments: 
     1071# - type      : first argument must be blocker, nonblocker or force. 
     1072#               For "blocker" case, the variable must be attributed the keyworld AUTO 
    10731073#               otherwise this function will exit. 
    1074 #               For "nonblocker" case, the user can remove or modify the variable. For  
     1074#               For "nonblocker" case, the user can remove or modify the variable. For 
    10751075#               this case, as long as AUTO is not set, no modification will be done. 
    1076 #               For "force" case, the variable will be modified even if it is not set to AUTO  
     1076#               For "force" case, the variable will be modified even if it is not set to AUTO 
    10771077# - filein    : the file in run directory of .xml type in which the variable should be set 
    10781078# - keyid     : the variable to modify 
     
    10801080# - value     : the value to set in the filein 
    10811081# 
    1082     IGCM_debug_PushStack "IGCM_comp_modifyXmlFile" 
    1083      
    1084     # Set local variables and test the arguments 
    1085     if [ $# = 5 ] ; then 
    1086         # Normal case with 4 arguments 
    1087         type=$1 ; filein=$2 ; keyid=$3 ; keyattrib=$4 ; value=$5 
     1082  IGCM_debug_PushStack "IGCM_comp_modifyXmlFile" 
     1083 
     1084  # Set local variables and test the arguments 
     1085  if [ $# = 5 ] ; then 
     1086    # Normal case with 4 arguments 
     1087    type=$1 ; filein=$2 ; keyid=$3 ; keyattrib=$4 ; value=$5 
     1088  else 
     1089    IGCM_debug_Exit "IGCM_comp_modifyXmlFile: Bad number of arguments." 
     1090    return 
     1091  fi 
     1092  IGCM_debug_Print 2 "Entering IGCM_comp_modifyXmlFile with arguments: type=$type file=$filein, id=$keyid attribute=$keyattrib, value=$value" 
     1093 
     1094  # Test if first argument is correct 
     1095  if [ $type != blocker ] && [ $type != nonblocker ] && [ $type != force ] ; then 
     1096    IGCM_debug_Exit "IGCM_comp_modifyXmlFile: Error in first argument must be blocker, nonblocker or force" 
     1097    return 
     1098  fi 
     1099 
     1100  # Test if the file exist 
     1101  if [ ! -f ${filein} ] ; then 
     1102    IGCM_debug_Exit "IGCM_comp_modifyXmlFile: $filein does not exist." 
     1103    return 
     1104  fi 
     1105 
     1106  # Test if keyid is set in filein, otherwise exit 
     1107  if [ $( grep -w $keyid $filein | wc -l ) = 0 ] ; then 
     1108    # Variable key is not set in filein, stop. 
     1109    IGCM_debug_Exit "IGCM_comp_modifyXmlFile : $keyid is not set in the file. Bad syntax of $filein file." 
     1110    return 
     1111  fi 
     1112 
     1113  # Check if AUTO is set on the same line as keyid and keyattrib 
     1114  if [  $( grep -w $keyid $filein | grep AUTO | wc -l ) = 1 ] ; then 
     1115    # Modifification will be done 
     1116    modify=yes 
     1117  else 
     1118    if [ $type = blocker ] ; then 
     1119      # Exit, the variable must be set to AUTO 
     1120      IGCM_debug_Exit "IGCM_comp_modifyXmlFile : blocker function. The $keyattrib for $keyid must be set to AUTO in $filein." 
     1121      return 
     1122    elif [ $type = nonblocker ] ; then 
     1123      # Nothing will be done 
     1124      IGCM_debug_Print 1 "Nonblocker nothing is done for ${filein}, id=${keyid} and attribute ${keyattrib}" 
     1125      modify=no 
     1126    elif [ $type = force ] ; then 
     1127      # Force modification 
     1128      IGCM_debug_Print 1 "IGCM_comp_modifyXmlFile : Attribute=$keyattrib for id=$keyid was not set to AUTO. Modification will be forced." 
     1129      modify=yes 
     1130    fi 
     1131  fi 
     1132 
     1133  # Do the modifcation now 
     1134  if [ $modify = yes ] ; then 
     1135    if [ $keyattrib = NONE ] ; then 
     1136      # Case to modify the variable itself 
     1137      IGCM_debug_Print 1 "Now modify ${filein} for id=${keyid} by setting the variable=${value}" 
     1138      sed -e "s/\(<[^\"]*\"${keyid}\".*>\)\([^<]*\)\(<[^>]*\)/\1${value}\3/" $filein > $filein.tmp 
    10881139    else 
    1089         IGCM_debug_Exit "IGCM_comp_modifyXmlFile: Bad number of arguments." 
    1090         return 
    1091     fi 
    1092     IGCM_debug_Print 2 "Entering IGCM_comp_modifyXmlFile with arguments: type=$type file=$filein, id=$keyid attribute=$keyattrib, value=$value" 
    1093  
    1094     # Test if first argument is correct 
    1095     if [ $type != blocker ] && [ $type != nonblocker ] && [ $type != force ] ; then 
    1096         IGCM_debug_Exit "IGCM_comp_modifyXmlFile: Error in first argument must be blocker, nonblocker or force" 
    1097         return 
    1098     fi 
    1099  
    1100     # Test if the file exist 
    1101     if [ ! -f ${filein} ] ; then 
    1102         IGCM_debug_Exit "IGCM_comp_modifyXmlFile: $filein does not exist." 
    1103         return 
    1104     fi 
    1105  
    1106     # Test if keyid is set in filein, otherwise exit 
    1107     if [ $( grep -w $keyid $filein | wc -l ) = 0 ] ; then 
    1108         # Variable key is not set in filein, stop.  
    1109         IGCM_debug_Exit "IGCM_comp_modifyXmlFile : $keyid is not set in the file. Bad syntax of $filein file." 
    1110         return 
    1111     fi 
    1112  
    1113     # Check if AUTO is set on the same line as keyid and keyattrib 
    1114     if [  $( grep -w $keyid $filein | grep AUTO | wc -l ) = 1 ] ; then 
    1115         # Modifification will be done 
    1116         modify=yes 
    1117     else 
    1118         if [ $type = blocker ] ; then 
    1119             # Exit, the variable must be set to AUTO 
    1120             IGCM_debug_Exit "IGCM_comp_modifyXmlFile : blocker function. The $keyattrib for $keyid must be set to AUTO in $filein." 
    1121             return 
    1122         elif [ $type = nonblocker ] ; then 
    1123             # Nothing will be done 
    1124             IGCM_debug_Print 1 "Nonblocker nothing is done for ${filein}, id=${keyid} and attribute ${keyattrib}" 
    1125             modify=no 
    1126         elif [ $type = force ] ; then 
    1127             # Force modification 
    1128             IGCM_debug_Print 1 "IGCM_comp_modifyXmlFile : Attribute=$keyattrib for id=$keyid was not set to AUTO. Modification will be forced." 
    1129             modify=yes 
    1130         fi 
    1131     fi 
    1132  
    1133     # Do the modifcation now 
    1134     if [ $modify = yes ] ; then 
    1135         if [ $keyattrib = NONE ] ; then 
    1136             # Case to modify the variable itself 
    1137             IGCM_debug_Print 1 "Now modify ${filein} for id=${keyid} by setting the variable=${value}" 
    1138             sed -e "s/\(<[^\"]*\"${keyid}\".*>\)\([^<]*\)\(<[^>]*\)/\1${value}\3/" $filein > $filein.tmp 
    1139         else 
    1140             # Case to modify the attribute value 
    1141             IGCM_debug_Print 1 "Now modify ${filein} for id=${keyid} by setting attribute to ${keyattrib}=${value}" 
    1142             sed -e "/id=\"${keyid}\"/s/\(${keyattrib}=\"\)[^\"]*\(\"\)/\1${value}\2/" $filein > $filein.tmp 
    1143         fi 
    1144         \mv $filein.tmp $filein  
    1145     fi 
    1146     IGCM_debug_PopStack "IGCM_comp_modifyXmlFile" 
     1140      # Case to modify the attribute value 
     1141      IGCM_debug_Print 1 "Now modify ${filein} for id=${keyid} by setting attribute to ${keyattrib}=${value}" 
     1142      sed -e "/id=\"${keyid}\"/s/\(${keyattrib}=\"\)[^\"]*\(\"\)/\1${value}\2/" $filein > $filein.tmp 
     1143    fi 
     1144    \mv $filein.tmp $filein 
     1145  fi 
     1146  IGCM_debug_PopStack "IGCM_comp_modifyXmlFile" 
    11471147} 
    11481148 
Note: See TracChangeset for help on using the changeset viewer.