[5570] | 1 | #!/bin/ksh |
---|
| 2 | |
---|
| 3 | #D--------------------------------------------------------------------== |
---|
| 4 | |
---|
| 5 | function ENSEMBLE_initialize |
---|
| 6 | { |
---|
| 7 | IGCM_debug_PushStack "ENSEMBLE_initialize" |
---|
| 8 | |
---|
| 9 | # config.card : |
---|
| 10 | # ------------- |
---|
| 11 | IGCM_card_DefineArrayFromSection ${SUBMIT_DIR}/config.card UserChoices |
---|
| 12 | typeset option |
---|
| 13 | for option in ${config_UserChoices[*]} ; do |
---|
| 14 | IGCM_card_DefineVariableFromOption ${SUBMIT_DIR}/config.card UserChoices ${option} |
---|
| 15 | done |
---|
| 16 | |
---|
| 17 | DateBegin=$( IGCM_date_ConvertFormatToGregorian ${config_UserChoices_DateBegin} ) |
---|
| 18 | IGCM_date_GetYearMonth ${DateBegin} year month |
---|
| 19 | |
---|
| 20 | IGCM_card_DefineArrayFromSection ${SUBMIT_DIR}/config.card SubJobPost |
---|
| 21 | typeset option |
---|
| 22 | for option in ${config_SubJobPost[*]} ; do |
---|
| 23 | IGCM_card_DefineVariableFromOption ${SUBMIT_DIR}/config.card SubJobPost ${option} |
---|
| 24 | done |
---|
| 25 | |
---|
| 26 | # Subjobs configuration : |
---|
| 27 | # ----------------------- |
---|
| 28 | |
---|
| 29 | # 1) UserChoices section of your card |
---|
| 30 | |
---|
| 31 | # This section groups standard options to be passed to ORCHIDEE. |
---|
| 32 | IGCM_card_DefineArrayFromSection ${SUBMIT_DIR}/ensemble.card UserChoices |
---|
| 33 | set +A ensemble_UserChoices -- ${ensemble_UserChoices[*]} > /dev/null 2>&1 |
---|
| 34 | typeset option |
---|
| 35 | for option in ${ensemble_UserChoices[*]} ; do |
---|
| 36 | IGCM_card_DefineVariableFromOption ${SUBMIT_DIR}/ensemble.card UserChoices ${option} |
---|
| 37 | done |
---|
| 38 | |
---|
| 39 | IGCM_card_DefineArrayFromSection ${SUBMIT_DIR}/config.card SRF |
---|
| 40 | typeset option |
---|
| 41 | for option in ${config_SRF[*]} ; do |
---|
| 42 | IGCM_card_DefineVariableFromOption ${SUBMIT_DIR}/config.card SRF ${option} |
---|
| 43 | done |
---|
| 44 | if [ X"${ensemble_UserChoices_ok_stomate}" = "Xy" ] ; then |
---|
| 45 | IGCM_card_DefineArrayFromSection ${SUBMIT_DIR}/config.card SBG |
---|
| 46 | typeset option |
---|
| 47 | for option in ${config_SBG[*]} ; do |
---|
| 48 | IGCM_card_DefineVariableFromOption ${SUBMIT_DIR}/config.card SBG ${option} |
---|
| 49 | done |
---|
| 50 | fi |
---|
| 51 | |
---|
| 52 | # 2) CONFIG section : |
---|
| 53 | |
---|
| 54 | # This section groups specific options for ENSEMBLE configuration : |
---|
| 55 | # - Forcing files path |
---|
| 56 | IGCM_card_DefineVariableFromOption ${SUBMIT_DIR}/ensemble.card CONFIG ForcingPath |
---|
| 57 | |
---|
| 58 | # - List of the sites/information to be treated : |
---|
| 59 | # * Number of PFTs |
---|
| 60 | IGCM_card_DefineVariableFromOption ${SUBMIT_DIR}/ensemble.card CONFIG NbPFTs |
---|
| 61 | NbPFTs=${ensemble_CONFIG_NbPFTs} |
---|
| 62 | |
---|
| 63 | # * Number of physical parameters on each sites per PFTs |
---|
| 64 | IGCM_card_DefineVariableFromOption ${SUBMIT_DIR}/ensemble.card CONFIG NbSitesParam |
---|
| 65 | # * ORCHIDEE name for physical parameters on each sites |
---|
| 66 | IGCM_card_DefineArrayFromOption ${SUBMIT_DIR}/ensemble.card CONFIG NameSitesParam |
---|
| 67 | # * Sites descriptions |
---|
| 68 | |
---|
| 69 | IGCM_card_DefineArrayFromOption ${SUBMIT_DIR}/ensemble.card CONFIG Groups |
---|
| 70 | |
---|
| 71 | if [ X${ensemble_CONFIG_Groups[0]} == X"Option" ] ; then |
---|
| 72 | typeset name=ensemble_CONFIG_Groups |
---|
| 73 | eval unset ${name} |
---|
| 74 | eval ${name}[0]=${NULL_STR} |
---|
| 75 | set +A ${name} -- Sites |
---|
| 76 | fi |
---|
| 77 | for group in ${ensemble_CONFIG_Groups[*]} ; do |
---|
| 78 | IGCM_card_DefineArrayFromOption ${SUBMIT_DIR}/ensemble.card CONFIG $group |
---|
| 79 | done |
---|
| 80 | |
---|
| 81 | first_group=${ensemble_CONFIG_Groups[*]} |
---|
| 82 | echo 'first group:' ${first_group} |
---|
| 83 | |
---|
| 84 | if [ X"${ensemble_UserChoices_CRUP}" = "Xy" ] ; then |
---|
| 85 | NumInfosBySite=7 |
---|
| 86 | else |
---|
| 87 | NumInfosBySite=5 |
---|
| 88 | fi |
---|
| 89 | (( iphys = 0 )) |
---|
| 90 | while [ $iphys -lt ${ensemble_CONFIG_NbSitesParam} ] ; do |
---|
| 91 | |
---|
| 92 | # Detect if physical parameter has |
---|
| 93 | # array description or line per PFT description in the parameter file |
---|
| 94 | SearchParam="" |
---|
| 95 | ORCHIDEE_grep ${ensemble_CONFIG_NameSitesParam[${iphys}]} |
---|
| 96 | echo 'Param:' ${ensemble_CONFIG_NameSitesParam[${iphys}]} |
---|
| 97 | echo 'SearchParam:' ${SearchParam} |
---|
| 98 | echo 'nbPFTs:' $NbPFTs |
---|
| 99 | case ${SearchParam} in |
---|
| 100 | undefined) |
---|
| 101 | echo "ERROR : parameter ${ensemble_CONFIG_NameSitesParam[${iphys}]} doesn't exist in run.def parameter file !" |
---|
| 102 | echo "You must correct NameSiteParam option in your card file or add new parameter in run.def file" |
---|
| 103 | echo "We must STOP here." |
---|
| 104 | exit 1 |
---|
| 105 | ;; |
---|
| 106 | value) |
---|
| 107 | (( NumInfosBySite = NumInfosBySite + 1 )) |
---|
| 108 | ;; |
---|
| 109 | line) |
---|
| 110 | (( NumInfosBySite = NumInfosBySite + NbPFTs )) |
---|
| 111 | ;; |
---|
| 112 | vector) |
---|
| 113 | (( NumInfosBySite = NumInfosBySite + NbPFTs )) |
---|
| 114 | ;; |
---|
| 115 | esac |
---|
| 116 | |
---|
| 117 | (( iphys = iphys + 1 )) |
---|
| 118 | done |
---|
| 119 | |
---|
| 120 | echo 'NumInfosBySite: ' $NumInfosBySite |
---|
| 121 | |
---|
| 122 | |
---|
| 123 | # Num of Columns : name, filename, length, + ${NbPFTs} PFT |
---|
| 124 | ColumnName=0 |
---|
| 125 | ColumnFilename=1 |
---|
| 126 | ColumnYear=2 |
---|
| 127 | ColumnLength=3 |
---|
| 128 | ColumnAge=4 |
---|
| 129 | ColumnLat=5 |
---|
| 130 | ColumnLon=6 |
---|
| 131 | |
---|
| 132 | # 3) SPINUP section : files path and spinup parameters |
---|
| 133 | # This section groups specific options for SPINUP : |
---|
| 134 | IGCM_card_DefineArrayFromSection ${SUBMIT_DIR}/ensemble.card SPINUP |
---|
| 135 | set +A ensemble_SPINUP -- ${ensemble_SPINUP[*]} > /dev/null 2>&1 |
---|
| 136 | typeset option |
---|
| 137 | for option in ${ensemble_SPINUP[*]} ; do |
---|
| 138 | IGCM_card_DefineVariableFromOption ${SUBMIT_DIR}/ensemble.card SPINUP ${option} |
---|
| 139 | done |
---|
| 140 | |
---|
| 141 | # 4) Subjob run.def parametrisation : SubJobParams in your card |
---|
| 142 | # This section give flags to put in run.def of Subjobs. |
---|
| 143 | IGCM_card_DefineArrayFromSection ${SUBMIT_DIR}/ensemble.card SubJobParams |
---|
| 144 | set +A ensemble_SubJobParams -- ${ensemble_SubJobParams[*]} > /dev/null 2>&1 |
---|
| 145 | eval first_option=${ensemble_SubJobParams[0]} > /dev/null 2>&1 |
---|
| 146 | if [ X${first_option} != X"Error:" ] ; then |
---|
| 147 | typeset option |
---|
| 148 | for option in ${ensemble_SubJobParams[*]} ; do |
---|
| 149 | IGCM_card_DefineVariableFromOption ${SUBMIT_DIR}/ensemble.card SubJobParams ${option} |
---|
| 150 | done |
---|
| 151 | fi |
---|
| 152 | |
---|
| 153 | IGCM_debug_PopStack "ENSEMBLE_initialize" |
---|
| 154 | } |
---|
| 155 | |
---|
| 156 | # Function to sed parameter files in Subjob dirs |
---|
| 157 | # For run.def : |
---|
| 158 | function ORCHIDEE_def |
---|
| 159 | { |
---|
| 160 | IGCM_debug_PushStack "ORCHIDEE_def" |
---|
| 161 | |
---|
| 162 | typeset ORCHIDEE_def_KEY ORCHIDEE_default_KEY |
---|
| 163 | |
---|
| 164 | ORCHIDEE_def_KEY=$( grep -e "^${1}\ *=" ${New_SUBMIT_DIR}/PARAM/run.def | gawk -- 'BEGIN {FS="="} {print $2}') |
---|
| 165 | if [ -f ${New_SUBMIT_DIR}/PARAM/orchidee.default ] ; then |
---|
| 166 | ORCHIDEE_default_KEY=$( grep -e "^${1}\ *=" ${New_SUBMIT_DIR}/PARAM/orchidee.default | gawk -- 'BEGIN {FS="="} {print $2}') |
---|
| 167 | fi |
---|
| 168 | |
---|
| 169 | if [ X"${ORCHIDEE_def_KEY}" != X ] ; then |
---|
| 170 | IGCM_debug_Print 2 "ORCHIDEE : ${1} has already been set in def file." |
---|
| 171 | if [ -f ${New_SUBMIT_DIR}/PARAM/orchidee.default ] ; then |
---|
| 172 | IGCM_debug_Print 2 " default value : ${ORCHIDEE_default_KEY}" |
---|
| 173 | fi |
---|
| 174 | IGCM_debug_Print 2 "ORCHIDEE : ${1} has already been set in run.def file." |
---|
| 175 | IGCM_debug_Print 2 " default value : ${ORCHIDEE_default_KEY}" |
---|
| 176 | IGCM_debug_Print 2 " script value : ${2}" |
---|
| 177 | IGCM_debug_Print 2 " USER value : ${ORCHIDEE_def_KEY}" |
---|
| 178 | IGCM_debug_Print 2 " We will NOT set in again !" |
---|
| 179 | else |
---|
| 180 | echo "${1}= ${2}" >> ${New_SUBMIT_DIR}/PARAM/run.def |
---|
| 181 | echo "" >> ${New_SUBMIT_DIR}/PARAM/run.def |
---|
| 182 | echo "ORCHIDEE_def : ${1} ${2}" |
---|
| 183 | fi |
---|
| 184 | |
---|
| 185 | IGCM_debug_PopStack "ORCHIDEE_def" |
---|
| 186 | return $RET |
---|
| 187 | } |
---|
| 188 | |
---|
| 189 | # Function to grep parameter files in Subjob dirs |
---|
| 190 | # They search for the argmument value in the file. |
---|
| 191 | # The result of the function is given in ${SearchParam} global variable : |
---|
| 192 | # * "line" if the parameter is a vector defined line per line with the form |
---|
| 193 | # PARAM__1=value1 |
---|
| 194 | # PARAM__2=value2 |
---|
| 195 | # etc... |
---|
| 196 | # * "vector" if the parameter is defined with the form |
---|
| 197 | # PARAM=value1[,] value2[,] etc... |
---|
| 198 | # * "value" if the parameter is a single value |
---|
| 199 | # PARAM=value |
---|
| 200 | # * "undefined" if the parameter is not definied in the parameters file |
---|
| 201 | # This should give an error in the script. |
---|
| 202 | |
---|
| 203 | # For run.def : |
---|
| 204 | function ORCHIDEE_grep |
---|
| 205 | { |
---|
| 206 | IGCM_debug_PushStack "ORCHIDEE_grep" |
---|
| 207 | typeset Output |
---|
| 208 | |
---|
| 209 | if [ -f ${SUBMIT_DIR}/PARAM/run.def ] ; then |
---|
| 210 | set +A Output -- $( grep "^${1}__[0-9]*\ *=" ${SUBMIT_DIR}/PARAM/run.def ) |
---|
| 211 | if [ X${Output[0]} != X ] ; then |
---|
| 212 | SearchParam=line |
---|
| 213 | else |
---|
| 214 | unset Output |
---|
| 215 | set +A Output -- $( grep "^${1}\ *=\ *[^[:blank:]][^[:blank:]]*\ [^[:blank:]][^[:blank:]]*.*" ${SUBMIT_DIR}/PARAM/run.def ) |
---|
| 216 | if [ X${Output[0]} != X ] ; then |
---|
| 217 | SearchParam=vector |
---|
| 218 | else |
---|
| 219 | unset Output |
---|
| 220 | set +A Output -- $( grep "^${1}\ *=" ${SUBMIT_DIR}/PARAM/run.def ) |
---|
| 221 | if [ X${Output[0]} != X ] ; then |
---|
| 222 | SearchParam=value |
---|
| 223 | else |
---|
| 224 | unset Output |
---|
| 225 | if [ -f ${SUBMIT_DIR}/PARAM/orchidee.default ] ; then |
---|
| 226 | set +A Output -- $( grep "^${1}__[0-9]*\ *=" ${SUBMIT_DIR}/PARAM/orchidee.default ) |
---|
| 227 | if [ X${Output[0]} != X ] ; then |
---|
| 228 | SearchParam=line |
---|
| 229 | else |
---|
| 230 | unset Output |
---|
| 231 | set +A Output -- $( grep "^${1}\ *=\ *[^[:blank:]][^[:blank:]]*\ [^[:blank:]][^[:blank:]]*.*" ${SUBMIT_DIR}/PARAM/orchidee.default ) |
---|
| 232 | if [ X${Output[0]} != X ] ; then |
---|
| 233 | SearchParam=vector |
---|
| 234 | else |
---|
| 235 | unset Output |
---|
| 236 | set +A Output -- $( grep "^${1}\ *=" ${SUBMIT_DIR}/PARAM/orchidee.default ) |
---|
| 237 | if [ X${Output[0]} != X ] ; then |
---|
| 238 | SearchParam=value |
---|
| 239 | else |
---|
| 240 | SearchParam=undefined |
---|
| 241 | fi |
---|
| 242 | fi |
---|
| 243 | fi |
---|
| 244 | else |
---|
| 245 | SearchParam=undefined |
---|
| 246 | echo "$@ : file not found !!" |
---|
| 247 | fi |
---|
| 248 | fi |
---|
| 249 | fi |
---|
| 250 | fi |
---|
| 251 | fi |
---|
| 252 | IGCM_debug_PopStack "ORCHIDEE_grep" |
---|
| 253 | return $RET |
---|
| 254 | } |
---|
| 255 | |
---|
| 256 | |
---|
| 257 | |
---|