source: tags/ORCHIDEE_2_1/ORCHIDEE_OL/ENSEMBLE/ensemble.ksh @ 5633

Last change on this file since 5633 was 2324, checked in by josefine.ghattas, 10 years ago

Update beginning of job.
Removed first_group_list never used.

File size: 8.5 KB
Line 
1#!/bin/ksh
2
3#D--------------------------------------------------------------------==
4
5function 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    NumInfosBySite=4
85    (( iphys = 0 ))
86    while [ $iphys -lt ${ensemble_CONFIG_NbSitesParam} ] ; do
87       
88        # Detect if physical parameter has
89        #  array description or line per PFT description in the parameter file
90        SearchParam=""
91        ORCHIDEE_grep ${ensemble_CONFIG_NameSitesParam[${iphys}]}
92        echo 'Param:' ${ensemble_CONFIG_NameSitesParam[${iphys}]}
93        echo 'SearchParam:' ${SearchParam}
94        echo 'nbPFTs:' $NbPFTs
95        case ${SearchParam} in
96            undefined)
97                echo "ERROR : parameter ${ensemble_CONFIG_NameSitesParam[${iphys}]} doesn't exist in run.def parameter file !"
98                echo "You must correct NameSiteParam option in your card file or add new parameter in run.def file"
99                echo "We must STOP here."
100                exit 1
101                ;;
102            value)
103                (( NumInfosBySite = NumInfosBySite + 1 ))
104                ;;
105            line)
106                (( NumInfosBySite = NumInfosBySite + NbPFTs ))
107                ;;
108            vector)
109                (( NumInfosBySite = NumInfosBySite + NbPFTs ))
110                ;;
111        esac
112
113        (( iphys = iphys + 1 ))
114    done
115
116    echo 'NumInfosBySite: ' $NumInfosBySite
117
118
119    # Num of Columns : name, filename, length, + ${NbPFTs} PFT
120    ColumnName=0
121    ColumnFilename=1
122    ColumnYear=2
123    ColumnLength=3
124
125
126
127    # 3) SPINUP section : files path and spinup parameters
128    # This section groups specific options for SPINUP :
129    IGCM_card_DefineArrayFromSection ${SUBMIT_DIR}/ensemble.card SPINUP
130    set +A ensemble_SPINUP -- ${ensemble_SPINUP[*]} > /dev/null 2>&1
131    typeset option
132    for option in ${ensemble_SPINUP[*]} ; do
133        IGCM_card_DefineVariableFromOption ${SUBMIT_DIR}/ensemble.card SPINUP ${option}
134    done
135
136    # 4) Subjob run.def parametrisation : SubJobParams in your card
137    # This section give flags to put in run.def of Subjobs.
138    IGCM_card_DefineArrayFromSection ${SUBMIT_DIR}/ensemble.card SubJobParams
139    set +A ensemble_SubJobParams -- ${ensemble_SubJobParams[*]} > /dev/null 2>&1
140    eval first_option=${ensemble_SubJobParams[0]} > /dev/null 2>&1
141    if [ X${first_option} != X"Error:" ] ; then
142        typeset option
143        for option in ${ensemble_SubJobParams[*]} ; do
144            IGCM_card_DefineVariableFromOption ${SUBMIT_DIR}/ensemble.card SubJobParams ${option}
145        done
146    fi
147
148    IGCM_debug_PopStack "ENSEMBLE_initialize"
149}
150
151# Function to sed parameter files in Subjob dirs
152# For run.def :
153function ORCHIDEE_def
154{
155    IGCM_debug_PushStack "ORCHIDEE_def"
156   
157    typeset ORCHIDEE_def_KEY ORCHIDEE_default_KEY
158
159    ORCHIDEE_def_KEY=$( grep -e "^${1}\ *=" ${New_SUBMIT_DIR}/PARAM/run.def | gawk -- 'BEGIN {FS="="} {print $2}')
160    if [ -f ${New_SUBMIT_DIR}/PARAM/orchidee.default ] ; then
161        ORCHIDEE_default_KEY=$( grep -e "^${1}\ *=" ${New_SUBMIT_DIR}/PARAM/orchidee.default | gawk -- 'BEGIN {FS="="} {print $2}')
162    fi
163
164    if [ X"${ORCHIDEE_def_KEY}" != X ] ; then
165        IGCM_debug_Print 2 "ORCHIDEE : ${1} has already been set in def file."
166        if [ -f ${New_SUBMIT_DIR}/PARAM/orchidee.default ] ; then
167            IGCM_debug_Print 2 " default value : ${ORCHIDEE_default_KEY}"
168        fi
169        IGCM_debug_Print 2 "ORCHIDEE : ${1} has already been set in run.def file."
170        IGCM_debug_Print 2 " default value : ${ORCHIDEE_default_KEY}"
171        IGCM_debug_Print 2 " script value : ${2}"
172        IGCM_debug_Print 2 " USER value : ${ORCHIDEE_def_KEY}"
173        IGCM_debug_Print 2 " We will NOT set in again !"
174    else
175        echo "${1}= ${2}" >> ${New_SUBMIT_DIR}/PARAM/run.def
176        echo "" >> ${New_SUBMIT_DIR}/PARAM/run.def
177        echo "ORCHIDEE_def : ${1} ${2}"
178    fi
179
180    IGCM_debug_PopStack "ORCHIDEE_def"
181    return $RET
182}
183
184# Function to grep parameter files in Subjob dirs
185# They search for the argmument value in the file.
186# The result of the function is given in ${SearchParam} global variable :
187# * "line" if the parameter is a vector defined line per line with the form
188#   PARAM__1=value1
189#   PARAM__2=value2
190#   etc...
191# * "vector" if the parameter is defined with the form
192#   PARAM=value1[,] value2[,] etc...
193# * "value" if the parameter is a single value
194#   PARAM=value
195# * "undefined" if the parameter is not definied in the parameters file
196#   This should give an error in the script.
197
198# For run.def :
199function ORCHIDEE_grep
200{
201    IGCM_debug_PushStack "ORCHIDEE_grep"
202    typeset Output
203
204    if [ -f ${SUBMIT_DIR}/PARAM/run.def ] ; then
205        set +A Output -- $( grep "^${1}__[0-9]*\ *=" ${SUBMIT_DIR}/PARAM/run.def )
206        if [ X${Output[0]} != X ] ; then
207            SearchParam=line
208        else
209            unset Output
210            set +A Output -- $( grep "^${1}\ *=\ *[^[:blank:]][^[:blank:]]*\ [^[:blank:]][^[:blank:]]*.*" ${SUBMIT_DIR}/PARAM/run.def )
211            if [ X${Output[0]} != X ] ; then
212                SearchParam=vector
213            else
214                unset Output
215                set +A Output -- $( grep "^${1}\ *=" ${SUBMIT_DIR}/PARAM/run.def )
216                if [ X${Output[0]} != X ] ; then
217                    SearchParam=value
218                else
219                    unset Output
220                    if [ -f ${SUBMIT_DIR}/PARAM/orchidee.default ] ; then
221                        set +A Output -- $( grep "^${1}__[0-9]*\ *=" ${SUBMIT_DIR}/PARAM/orchidee.default )
222                        if [ X${Output[0]} != X ] ; then
223                            SearchParam=line
224                        else
225                            unset Output
226                            set +A Output -- $( grep "^${1}\ *=\ *[^[:blank:]][^[:blank:]]*\ [^[:blank:]][^[:blank:]]*.*" ${SUBMIT_DIR}/PARAM/orchidee.default )
227                            if [ X${Output[0]} != X ] ; then
228                                SearchParam=vector
229                            else
230                                unset Output
231                                set +A Output -- $( grep "^${1}\ *=" ${SUBMIT_DIR}/PARAM/orchidee.default )
232                                if [ X${Output[0]} != X ] ; then
233                                    SearchParam=value
234                                else
235                                    SearchParam=undefined
236                                fi
237                            fi
238                        fi
239                    else
240                        SearchParam=undefined
241                        echo "$@ : file not found !!"
242                    fi
243                fi
244            fi
245        fi
246    fi
247    IGCM_debug_PopStack "ORCHIDEE_grep"
248    return $RET
249}
250
251
252
Note: See TracBrowser for help on using the repository browser.