source: tags/ORCHIDEE_1_9_6/ORCHIDEE_OL/FLUXNET/fluxnet.ksh @ 881

Last change on this file since 881 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.2 KB
Line 
1#!/bin/ksh
2
3#D--------------------------------------------------------------------==
4
5function FLUXNET_initialize
6{
7    IGCM_debug_PushStack "FLUXNET_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 fluxnet.card
30
31    # This section groups standard options to be passed to ORCHIDEE.
32    IGCM_card_DefineArrayFromSection ${SUBMIT_DIR}/fluxnet.card UserChoices
33    set +A fluxnet_UserChoices -- ${fluxnet_UserChoices[*]} > /dev/null 2>&1
34    typeset option
35    for option in ${fluxnet_UserChoices[*]} ; do
36        IGCM_card_DefineVariableFromOption ${SUBMIT_DIR}/fluxnet.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"${fluxnet_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) FLUXNET section :
53
54    # This section groups specific options for FLUXNET spinup :
55    # - Fluxnet files path
56    IGCM_card_DefineVariableFromOption ${SUBMIT_DIR}/fluxnet.card FLUXNET FluxnetPath
57
58    # - List of the sites/information to be treated :
59    #   * Number of PFTs
60    IGCM_card_DefineVariableFromOption ${SUBMIT_DIR}/fluxnet.card FLUXNET NbPFTs
61    NbPFTs=${fluxnet_FLUXNET_NbPFTs}
62
63    #   * Number of physical parameters on each sites per PFTs
64    IGCM_card_DefineVariableFromOption ${SUBMIT_DIR}/fluxnet.card FLUXNET NbSitesParam
65    #   * ORCHIDEE name for physical parameters on each sites
66    IGCM_card_DefineArrayFromOption ${SUBMIT_DIR}/fluxnet.card FLUXNET NameSitesParam
67    #   * Sites descriptions
68    #    IGCM_card_DefineArrayFromOption ${SUBMIT_DIR}/fluxnet.card FLUXNET Sites
69
70    IGCM_card_DefineArrayFromOption ${SUBMIT_DIR}/fluxnet.card FLUXNET Groups
71
72    if [ X${fluxnet_FLUXNET_Groups[0]} == X"Option" ] ; then
73        typeset name=fluxnet_FLUXNET_Groups
74        eval unset ${name}
75        eval ${name}[0]=${NULL_STR}
76        set +A ${name} -- Sites
77    fi
78    for group in ${fluxnet_FLUXNET_Groups[*]} ; do
79        IGCM_card_DefineArrayFromOption ${SUBMIT_DIR}/fluxnet.card FLUXNET $group
80    done
81
82    echo ${fluxnet_FLUXNET_Sites[*]}
83
84    # Number of columns by site in variable site : name, filename, length, + ${NbPFTs} PFT
85    NumInfosBySite=$(( 4 + ( NbPFTs * fluxnet_FLUXNET_NbSitesParam ) ))
86
87    # Number of sites :
88    NumSites=$(( ${#fluxnet_FLUXNET_Sites[*]} / NumInfosBySite ))
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}/fluxnet.card SPINUP
98    set +A fluxnet_SPINUP -- ${fluxnet_SPINUP[*]} > /dev/null 2>&1
99    typeset option
100    for option in ${fluxnet_SPINUP[*]} ; do
101        IGCM_card_DefineVariableFromOption ${SUBMIT_DIR}/fluxnet.card SPINUP ${option}
102    done
103
104    # 4) Subjob run.def parametrisation : SubJobParams in fluxnet.card
105    # This section give flags to put in run.def of Subjobs.
106    IGCM_card_DefineArrayFromSection ${SUBMIT_DIR}/fluxnet.card SubJobParams
107    set +A fluxnet_SubJobParams -- ${fluxnet_SubJobParams[*]} > /dev/null 2>&1
108    eval first_option=${fluxnet_SubJobParams[0]} > /dev/null 2>&1
109    if [ X${first_option} != X"Error:" ] ; then
110        typeset option
111        for option in ${fluxnet_SubJobParams[*]} ; do
112            IGCM_card_DefineVariableFromOption ${SUBMIT_DIR}/fluxnet.card SubJobParams ${option}
113        done
114    fi
115
116    IGCM_debug_PopStack "FLUXNET_initialize"
117}
118
119# Function to sed parameter files in Subjob dirs
120# For run.def :
121function ORCHIDEE_def
122{
123    IGCM_debug_PushStack "ORCHIDEE_def"
124   
125    typeset ORCHIDEE_def_KEY ORCHIDEE_default_KEY
126
127    ORCHIDEE_def_KEY=$( grep -e "^${1}\ *=" ${New_SUBMIT_DIR}/PARAM/run.def | gawk -- 'BEGIN {FS="="} {print $2}')
128    if [ -f ${New_SUBMIT_DIR}/PARAM/orchidee.default ] ; then
129        ORCHIDEE_default_KEY=$( grep -e "^${1}\ *=" ${New_SUBMIT_DIR}/PARAM/orchidee.default | gawk -- 'BEGIN {FS="="} {print $2}')
130    fi
131
132    if [ X"${ORCHIDEE_def_KEY}" != X ] ; then
133        IGCM_debug_Print 2 "ORCHIDEE : ${1} has already been set in def file."
134        if [ -f ${New_SUBMIT_DIR}/PARAM/orchidee.default ] ; then
135            IGCM_debug_Print 2 " default value : ${ORCHIDEE_default_KEY}"
136        fi
137        IGCM_debug_Print 2 "ORCHIDEE : ${1} has already been set in run.def file."
138        IGCM_debug_Print 2 " default value : ${ORCHIDEE_default_KEY}"
139        IGCM_debug_Print 2 " script value : ${2}"
140        IGCM_debug_Print 2 " USER value : ${ORCHIDEE_def_KEY}"
141        IGCM_debug_Print 2 " We will NOT set in again !"
142    else
143        echo "${1}= ${2}" >> ${New_SUBMIT_DIR}/PARAM/run.def
144        echo "" >> ${New_SUBMIT_DIR}/PARAM/run.def
145        echo "ORCHIDEE_def : ${1} ${2}"
146    fi
147
148    IGCM_debug_PopStack "ORCHIDEE_def"
149    return $RET
150}
151
152# Function to grep parameter files in Subjob dirs
153# They search for the argmument value in the file.
154# The result of the function is given in ${SearchParam} global variable :
155# * "line" if the parameter is defined with the form
156#   PARAM__1=value1
157#   PARAM__2=value2
158#   etc...
159# * "vector" if the parameter is defined with the form
160#   PARAM=value1 value2 etc...
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
Note: See TracBrowser for help on using the repository browser.