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

Last change on this file was 877, checked in by didier.solyga, 12 years ago

Correct ENSEMBLE scripts and fluxnet.ksh (remove unused parts of the script + correction).

File size: 7.4 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
72    echo ${ensemble_CONFIG_Sites[*]}
73
74    # Number of sites :
75    NumSites=${ensemble_CONFIG_NbSites}
76
77    # Number of columns by site in variable site : name, filename, length, + Parameters
78    NumInfosBySite=$(( ${#ensemble_CONFIG_Sites[*]} / NumSites ))
79
80    rest=$(( ${#ensemble_CONFIG_Sites[*]} % NumSites ))
81    if [ rest -ne 0 ] ; then
82        echo "Error CONFIG : number of parameters per site is not correct "
83        echo "Total Number of parameters " ${#ensemble_CONFIG_Sites[*]} " != NumSites " ${NumSites} "x NumInfosBySite " ${NumInfosBySite}
84        echo "rest = " ${rest}
85        exit 1
86    fi
87    # Num of Columns : name, filename, length, + ${NbPFTs} PFT
88    ColumnName=0
89    ColumnFilename=1
90    ColumnYear=2
91    ColumnLength=3
92
93    # 3) SPINUP section : files path and spinup parameters
94    # This section groups specific options for SPINUP :
95    IGCM_card_DefineArrayFromSection ${SUBMIT_DIR}/ensemble.card SPINUP
96    set +A ensemble_SPINUP -- ${ensemble_SPINUP[*]} > /dev/null 2>&1
97    typeset option
98    for option in ${ensemble_SPINUP[*]} ; do
99        IGCM_card_DefineVariableFromOption ${SUBMIT_DIR}/ensemble.card SPINUP ${option}
100    done
101
102    # 4) Subjob orchidee.def parametrisation : SubJobParams in ensemble.card
103    # This section give flags to put in orchidee.def of Subjobs.
104    IGCM_card_DefineArrayFromSection ${SUBMIT_DIR}/ensemble.card SubJobParams
105    set +A ensemble_SubJobParams -- ${ensemble_SubJobParams[*]} > /dev/null 2>&1
106    eval first_option=${ensemble_SubJobParams[0]} > /dev/null 2>&1
107    if [ X${first_option} != X"Error:" ] ; then
108        typeset option
109        for option in ${ensemble_SubJobParams[*]} ; do
110            IGCM_card_DefineVariableFromOption ${SUBMIT_DIR}/ensemble.card SubJobParams ${option}
111        done
112    fi
113
114    IGCM_debug_PopStack "ENSEMBLE_initialize"
115}
116
117# Function to sed parameter files in Subjob dirs
118# For run.def
119function ORCHIDEE_def
120{
121    IGCM_debug_PushStack "ORCHIDEE_def"
122   
123    typeset ORCHIDEE_def_KEY ORCHIDEE_default_KEY
124
125    ORCHIDEE_def_KEY=$( grep -e "^${1}\ *=" ${New_SUBMIT_DIR}/PARAM/run.def | gawk -- 'BEGIN {FS="="} {print $2}')
126    if [ -f ${New_SUBMIT_DIR}/PARAM/orchidee.default ] ; then
127        ORCHIDEE_default_KEY=$( grep -e "^${1}\ *=" ${New_SUBMIT_DIR}/PARAM/orchidee.default | gawk -- 'BEGIN {FS="="} {print $2}')
128    fi
129
130    if [ X"${ORCHIDEE_def_KEY}" != X ] ; then
131        IGCM_debug_Print 2 "ORCHIDEE : ${1} has already been set in def file."
132        if [ -f ${New_SUBMIT_DIR}/PARAM/orchidee.default ] ; then
133            IGCM_debug_Print 2 " default value : ${ORCHIDEE_default_KEY}"
134        fi
135        IGCM_debug_Print 2 "ORCHIDEE : ${1} has already been set in run.def file."
136        IGCM_debug_Print 2 " default value : ${ORCHIDEE_default_KEY}"
137        IGCM_debug_Print 2 " script value : ${2}"
138        IGCM_debug_Print 2 " USER value : ${ORCHIDEE_def_KEY}"
139        IGCM_debug_Print 2 " We will NOT set in again !"
140    else
141        echo "${1}= ${2}" >> ${New_SUBMIT_DIR}/PARAM/run.def
142        echo "" >> ${New_SUBMIT_DIR}/PARAM/run.def
143        echo "ORCHIDEE_def : ${1} ${2}"
144    fi
145
146    IGCM_debug_PopStack "ORCHIDEE_def"
147    return $RET
148}
149
150# Function to grep parameter files in Subjob dirs
151# They search for the argmument value in the file.
152# The result of the function is given in ${SearchParam} global variable :
153# * "line" if the parameter is a vector defined line per line with the form
154#   PARAM__1=value1
155#   PARAM__2=value2
156#   etc...
157# * "vector" if the parameter is defined with the form
158#   PARAM=value1[,] value2[,] etc...
159# * "value" if the parameter is a single value
160#   PARAM=value
161# * "undefined" if the parameter is not definied in the parameters file
162#   This should give an error in the script.
163
164# For run.def :
165function ORCHIDEE_grep
166{
167    IGCM_debug_PushStack "ORCHIDEE_grep"
168    typeset Output
169
170    if [ -f ${New_SUBMIT_DIR}/PARAM/run.def ] ; then
171        set +A Output -- $( grep "^${1}__[0-9]*\ *=" ${New_SUBMIT_DIR}/PARAM/run.def )
172        if [ X${Output[0]} != X ] ; then
173            SearchParam=line
174        else
175            unset Output
176            set +A Output -- $( grep "^${1}\ *=" ${New_SUBMIT_DIR}/PARAM/run.def )
177            if [ X${Output[0]} != X ] ; then
178                SearchParam=vector
179            else
180                unset Output
181                if [ -f ${New_SUBMIT_DIR}/PARAM/orchidee.default ] ; then
182                    set +A Output -- $( grep "^${1}__[0-9]*\ *=" ${New_SUBMIT_DIR}/PARAM/orchidee.default )
183                    if [ X${Output[0]} != X ] ; then
184                        SearchParam=line
185                    else
186                        unset Output
187                        set +A Output -- $( grep "^${1}\ *=" ${New_SUBMIT_DIR}/PARAM/orchidee.default )
188                        if [ X${Output[0]} != X ] ; then
189                            SearchParam=vector
190                        else
191                            SearchParam=undefined
192                        fi
193                    fi
194                else
195                    SearchParam=undefined
196                    echo "$@ : file not found !!"
197                fi
198            fi
199        fi
200    fi
201
202    IGCM_debug_PopStack "ORCHIDEE_grep"
203    return $RET
204}
205
206
207
Note: See TracBrowser for help on using the repository browser.