source: tags/ORCHIDEE_1_9_5_2/ORCHIDEE_OL/ENSEMBLE/ensemble.ksh

Last change on this file was 133, checked in by martial.mancip, 13 years ago

New ENSEMBLE type global script. Generalization of FLUXNET sites script.

File size: 9.0 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 ensemble.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    # This section is the ENSEMBLE configuration :
54    # - Forcing files path
55    IGCM_card_DefineVariableFromOption ${SUBMIT_DIR}/ensemble.card CONFIG ForcingPath
56
57    # - List of the sites/information to be treated :
58    #   * Number of PFTs
59    IGCM_card_DefineVariableFromOption ${SUBMIT_DIR}/ensemble.card CONFIG NbPFTs
60    NbPFTs=${ensemble_CONFIG_NbPFTs}
61
62    #   * Number of physical parameters on each sites per PFTs
63    IGCM_card_DefineVariableFromOption ${SUBMIT_DIR}/ensemble.card CONFIG NbSitesParam
64    #   * ORCHIDEE name for physical parameters on each sites
65    IGCM_card_DefineArrayFromOption ${SUBMIT_DIR}/ensemble.card CONFIG NameSitesParam
66    #   * Sites descriptions
67    IGCM_card_DefineVariableFromOption ${SUBMIT_DIR}/ensemble.card CONFIG NbSites
68    echo "NbSites : " ${ensemble_CONFIG_NbSites[*]}
69    IGCM_card_DefineArrayFromOption ${SUBMIT_DIR}/ensemble.card CONFIG Sites
70    echo "Sites : " ${ensemble_CONFIG_Sites[*]}
71    #   * Components for each physical parameter described in NameSitesParam
72    IGCM_card_DefineArrayFromOption ${SUBMIT_DIR}/ensemble.card CONFIG CompSitesParam
73
74    echo ${ensemble_CONFIG_Sites[*]}
75
76    # Number of sites :
77    NumSites=${ensemble_CONFIG_NbSites}
78
79    # Number of columns by site in variable site : name, filename, length, + Parameters
80    NumInfosBySite=$(( ${#ensemble_CONFIG_Sites[*]} / NumSites ))
81
82    rest=$(( ${#ensemble_CONFIG_Sites[*]} % NumSites ))
83    if [ rest -ne 0 ] ; then
84        echo "Error CONFIG : number of parameters per site is not correct "
85        echo "Total Number of parameters " ${#ensemble_CONFIG_Sites[*]} " != NumSites " ${NumSites} "x NumInfosBySite " ${NumInfosBySite}
86        echo "rest = " ${rest}
87        exit 1
88    fi
89    # Num of Columns : name, filename, length, + ${NbPFTs} PFT
90    ColumnName=0
91    ColumnFilename=1
92    ColumnYear=2
93    ColumnLength=3
94
95    # 3) SPINUP section : files path and spinup parameters
96    # This section groups specific options for SPINUP :
97    IGCM_card_DefineArrayFromSection ${SUBMIT_DIR}/ensemble.card SPINUP
98    set +A ensemble_SPINUP -- ${ensemble_SPINUP[*]} > /dev/null 2>&1
99    typeset option
100    for option in ${ensemble_SPINUP[*]} ; do
101        IGCM_card_DefineVariableFromOption ${SUBMIT_DIR}/ensemble.card SPINUP ${option}
102    done
103
104    # 4) Subjob orchidee.def parametrisation : SubJobParams in ensemble.card
105    # This section give flags to put in orchidee.def of Subjobs.
106    IGCM_card_DefineArrayFromSection ${SUBMIT_DIR}/ensemble.card SubJobParams
107    set +A ensemble_SubJobParams -- ${ensemble_SubJobParams[*]} > /dev/null 2>&1
108    eval first_option=${ensemble_SubJobParams[0]} > /dev/null 2>&1
109    if [ X${first_option} != X"Error:" ] ; then
110        typeset option
111        for option in ${ensemble_SubJobParams[*]} ; do
112            IGCM_card_DefineVariableFromOption ${SUBMIT_DIR}/ensemble.card SubJobParams ${option}
113        done
114    fi
115
116    IGCM_debug_PopStack "ENSEMBLE_initialize"
117}
118
119# Function to sed parameter files in Subjob dirs
120# For sechiba.def :
121function SECHIBA_sed
122{
123    IGCM_debug_PushStack "SECHIBA_sed"
124   
125    if [ -f ${New_SUBMIT_DIR}/PARAM/sechiba.def ] ; then
126        sed -e "s/^${1}\ *=.*/${1}= ${2}/" \
127            ${New_SUBMIT_DIR}/PARAM/sechiba.def > ${New_SUBMIT_DIR}/PARAM/sechiba.def.tmp
128        RET=$?
129        echo "SECHIBA_sed : ${1} ${2}"
130        \mv ${New_SUBMIT_DIR}/PARAM/sechiba.def.tmp ${New_SUBMIT_DIR}/PARAM/sechiba.def
131    fi
132
133    IGCM_debug_PopStack "SECHIBA_sed"
134    return $RET
135}
136
137# For stomate.def :
138function STOMATE_sed
139{
140    IGCM_debug_PushStack "STOMATE_sed"
141   
142    sed -e "s/^${1}\ *=.*/${1}= ${2}/" \
143        ${New_SUBMIT_DIR}/PARAM/stomate.def > ${New_SUBMIT_DIR}/PARAM/stomate.def.tmp
144    RET=$?
145    echo "STOMATE_sed : ${1} ${2}"
146    \mv ${New_SUBMIT_DIR}/PARAM/stomate.def.tmp ${New_SUBMIT_DIR}/PARAM/stomate.def
147   
148    IGCM_debug_PopStack "STOMATE_sed"
149    return $RET
150}
151
152# For driver.def :
153function DRIVER_sed
154{
155    IGCM_debug_PushStack "DRIVER_sed"
156   
157    if [ -f ${New_SUBMIT_DIR}/PARAM/driver.def ] ; then
158        sed -e "s/^${1}\ *=.*/${1}= ${2}/" \
159            ${New_SUBMIT_DIR}/PARAM/driver.def > ${New_SUBMIT_DIR}/PARAM/driver.def.tmp
160        RET=$?
161        echo "DRIVER_sed : ${1} ${2}"
162        \mv ${New_SUBMIT_DIR}/PARAM/driver.def.tmp ${New_SUBMIT_DIR}/PARAM/driver.def
163    fi
164
165    IGCM_debug_PopStack "DRIVER_sed"
166    return $RET
167}
168
169
170# Function to grep parameter files in Subjob dirs
171# They search for the argmument value in the file.
172# The result of the function is given in ${SearchParam} global variable :
173# * "line" if the parameter is a vector defined line per line with the form
174#   PARAM__1=value1
175#   PARAM__2=value2
176#   etc...
177# * "vector" if the parameter is defined with the form
178#   PARAM=value1[,] value2[,] etc...
179# * "value" if the parameter is a single value
180#   PARAM=value
181# * "undefined" if the parameter is not definied in the parameters file
182#   This should give an error in the script.
183
184# For sechiba.def :
185function SECHIBA_grep
186{
187    IGCM_debug_PushStack "SECHIBA_grep"
188    typeset Output
189    Output[0]=""
190    if [ -f ${New_SUBMIT_DIR}/PARAM/sechiba.def ] ; then
191        set +A Output -- $( grep "^${1}__[0-9]*\ *=" ${New_SUBMIT_DIR}/PARAM/sechiba.def )
192        if [ X${Output[0]} != X ] ; then
193            SearchParam=line
194        else
195            set +A Output -- $( grep "^${1}\ *=\ *[^[:blank:]][^[:blank:]]*\ [^[:blank:]][^[:blank:]]*.*" ${New_SUBMIT_DIR}/PARAM/sechiba.def )
196            if [ X${Output[0]} != X ] ; then
197                SearchParam=vector
198            else
199                set +A Output -- $( grep "^${1}\ *=" ${New_SUBMIT_DIR}/PARAM/sechiba.def )
200                if [ X${Output[0]} != X ] ; then
201                    SearchParam=value
202                else
203                    SearchParam=undefined
204                fi
205            fi
206        fi
207    else
208        SearchParam=undefined
209        echo "$@ : file not found !!"
210    fi
211    IGCM_debug_PopStack "SECHIBA_grep"
212    return $RET
213}
214
215# For stomate.def :
216function STOMATE_grep
217{
218    IGCM_debug_PushStack "STOMATE_grep"
219    typeset Output
220    Output[0]=""
221
222    if [ -f ${New_SUBMIT_DIR}/PARAM/stomate.def ] ; then
223        set +A Output -- $( grep "^${1}__[0-9]*\ *=" ${New_SUBMIT_DIR}/PARAM/stomate.def )
224        if [ X${Output[0]} != X ] ; then
225            SearchParam=line
226        else
227            set +A Output -- $( grep "^${1}\ *=\ *[^[:blank:]][^[:blank:]]*\ [^[:blank:]][^[:blank:]]*.*" ${New_SUBMIT_DIR}/PARAM/stomate.def )
228            if [ X${Output[0]} != X ] ; then
229                SearchParam=vector
230            else
231                set +A Output -- $( grep "^${1}\ *=" ${New_SUBMIT_DIR}/PARAM/stomate.def )
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
244    IGCM_debug_PopStack "STOMATE_grep"
245    return $RET
246}
247
248# For driver.def :
249function DRIVER_grep
250{
251    IGCM_debug_PushStack "DRIVER_grep"
252    typeset Output
253    Output[0]=""
254    if [ -f ${New_SUBMIT_DIR}/PARAM/driver.def ] ; then
255        set +A Output -- $( grep "^${1}__[0-9]*\ *=" ${New_SUBMIT_DIR}/PARAM/driver.def )
256        if [ X${Output[0]} != X ] ; then
257            SearchParam=line
258        else
259            set +A Output -- $( grep "^${1}\ *=\ *[^[:blank:]][^[:blank:]]*\ [^[:blank:]][^[:blank:]]*.*" ${New_SUBMIT_DIR}/PARAM/driver.def )
260            if [ X${Output[0]} != X ] ; then
261                SearchParam=vector
262            else
263                set +A Output -- $( grep "^${1}\ *=" ${New_SUBMIT_DIR}/PARAM/driver.def )
264                if [ X${Output[0]} != X ] ; then
265                    SearchParam=value
266                else
267                    SearchParam=undefined
268                fi
269            fi
270        fi
271    else
272        SearchParam=undefined
273        echo "$@ : file not found !!"
274    fi
275
276    IGCM_debug_PopStack "DRIVER_grep"
277    return $RET
278}
279
Note: See TracBrowser for help on using the repository browser.