source: CONFIG/UNIFORM/v6/LMDZOR_v6/GENERAL/DRIVER/lmdz.driver @ 2598

Last change on this file since 2598 was 2598, checked in by jgipsl, 6 years ago

Adapted LMDZOR_v6 to be used with LMDZ5 testing 2314

lmdz.driver : Modification due to parameter calendar which changed behaviour in LMDZ since rev 2229 in trunk LMDZ. Removed obsolete parameters LMDZ_ecrit_ISCCP and periodav

Copied file_def_xxx_lmdz.xml files from testing 2314 LMDZ/DefListes into GENERAL/PARAM. These files are still modified with option IGCM_comp_modifyXmlFile force. To be modified in next commit.

File size: 33.0 KB
Line 
1#!/bin/ksh
2#-----------------------------------------------------------------
3function ATM_Initialize
4{
5    IGCM_debug_PushStack "ATM_Initialize"
6
7    RESOL_ATM=$( echo $RESOL | awk "-Fx" '{print $2}' | awk "-F-" '{print $1}')
8
9    [ -f ${SUBMIT_DIR}/../.resol ] && eval $(grep RESOL_ATM_3D ${SUBMIT_DIR}/../.resol) || RESOL_ATM_3D=96x95x39
10
11    RESOL_ATM_Z=$( echo ${RESOL_ATM_3D} | awk "-Fx" '{print $3}' )
12    RESOL_ATM_X=$( echo ${RESOL_ATM_3D} | awk "-Fx" '{print $1}' )
13    RESOL_ATM_Y=$( echo ${RESOL_ATM_3D} | awk "-Fx" '{print $2}' )
14    RESOL_ATM_XY="${RESOL_ATM_X}x${RESOL_ATM_Y}"
15
16    ##- LMDZ physics version
17    ##  Read LMDZ_Physics option in lmdz.card, if not present take default value AP (old physics)
18    if [ ! X${lmdz_UserChoices_LMDZ_Physics} = X ] ; then
19        LMDZ_Physics=${lmdz_UserChoices_LMDZ_Physics}
20    else
21        LMDZ_Physics=AP
22    fi
23    echo LMDZ physics version : ${LMDZ_Physics}
24
25    ##- Create_etat0_limit version
26    ##  Define variable CREATE only if it is set in lmdz.card section UserChoices.
27    ##  This variable is only used in lmdz.card to choose input files.
28    if [ ! X${lmdz_UserChoices_CREATE} = X ] ; then
29        IGCM_card_DefineVariableFromOption ${SUBMIT_DIR}/COMP/lmdz.card UserChoices CREATE
30        CREATE=${lmdz_UserChoices_CREATE}
31        echo create_etat0_limit version : ${CREATE}
32    fi
33
34
35    ## - LMDZ choice of config.def file
36    ##   ConfType must be set in lmdz.card
37    ConfType=${lmdz_UserChoices_ConfType}
38
39    ##- LMDZ output level, to be set in lmdz.card
40    if [ X${lmdz_UserChoices_OutLevel} = X ] ; then
41        # OutLevel is not set. Take default value low.
42        OutLevel=low
43    else
44        OutLevel=${lmdz_UserChoices_OutLevel}
45    fi
46
47    ##-- Output frequency purpose ....
48    ##--  Initialisation  ....
49    ok_mensuel=n
50    ok_journe=n
51    ok_hf=n
52    ok_hf3h=n
53    ok_hf3hm=n
54    ok_stn=n
55
56    case ${config_UserChoices_PeriodLength} in
57        1Y|1y|1M|1m) ok_mensuel=y ;;
58        5D|5d|1D|1d) ok_journe=y ;;
59    esac
60
61    for frequency in ${config_ATM_WriteFrequency} ; do
62        case ${frequency} in
63            1M|1m) ok_mensuel=y ;;
64        esac
65        case ${frequency} in
66            5D|5d|1D|1d) ok_journe=y ;;
67        esac
68        case ${frequency} in
69            HF|hf) ok_hf=y ;;
70        esac
71        case ${frequency} in
72            HF3h|hf3h) ok_hf3h=y ;;
73        esac
74        case ${frequency} in
75            HF3hm|hf3hm) ok_hf3hm=y ;;
76        esac
77        case ${frequency} in
78            STN|stn) ok_stn=y ;;
79        esac
80    done
81
82    ## Read LMDZ_NbPeriod_adjust option in lmdz.card
83    if [ X"${lmdz_UserChoices_LMDZ_NbPeriod_adjust}" = X"" ] ; then
84        # The variable is not in lmdz.card, set default value
85        LMDZ_NbPeriod_adjust=0
86    else       
87        LMDZ_NbPeriod_adjust=${lmdz_UserChoices_LMDZ_NbPeriod_adjust}
88    fi
89
90    if [ ${LMDZ_NbPeriod_adjust} -eq 0 ] ; then
91        LMDZ_Bands_file_name=${lmdz_UserChoices_LMDZ_Bands_file_name}
92    fi
93
94
95    ##  Read LMDZ_COSP_OK in lmdz.card
96    if [ ! X${lmdz_UserChoices_LMDZ_COSP_OK} = X ] ; then
97        LMDZ_COSP_OK=${lmdz_UserChoices_LMDZ_COSP_OK}
98    else
99        LMDZ_COSP_OK=n
100    fi
101    ##  Read LMDZ_COSP_monthly in lmdz.card
102    if [ ! X${lmdz_UserChoices_LMDZ_COSP_monthly} = X ] ; then
103        LMDZ_COSP_monthly=${lmdz_UserChoices_LMDZ_COSP_monthly}
104    else
105        LMDZ_COSP_monthly=n
106    fi
107    ##  Read LMDZ_COSP_daily in lmdz.card
108    if [ ! X${lmdz_UserChoices_LMDZ_COSP_daily} = X ] ; then
109        LMDZ_COSP_daily=${lmdz_UserChoices_LMDZ_COSP_daily}
110    else
111        LMDZ_COSP_daily=n
112    fi
113    ##  Read LMDZ_COSP_hf in lmdz.card
114    if [ ! X${lmdz_UserChoices_LMDZ_COSP_hf} = X ] ; then
115        LMDZ_COSP_hf=${lmdz_UserChoices_LMDZ_COSP_hf}
116    else
117        LMDZ_COSP_hf=n
118    fi
119
120    ##  Read LMDZ_NMC_monthly in lmdz.card
121    if [ ! X${lmdz_UserChoices_LMDZ_NMC_monthly} = X ] ; then
122        LMDZ_NMC_monthly=${lmdz_UserChoices_LMDZ_NMC_monthly}
123    else
124        LMDZ_NMC_monthly=n
125    fi
126
127    ## Read LMDZ_NMC_daily in lmdz.card
128    if [ ! X${lmdz_UserChoices_LMDZ_NMC_daily} = X ] ; then
129        LMDZ_NMC_daily=${lmdz_UserChoices_LMDZ_NMC_daily}
130    else
131        LMDZ_NMC_daily=n
132    fi
133   
134    ## Read LMDZ_NMC_hf in lmdz.card
135    if [ ! X${lmdz_UserChoices_LMDZ_NMC_hf} = X ] ; then
136        LMDZ_NMC_hf=${lmdz_UserChoices_LMDZ_NMC_hf}
137    else
138        LMDZ_NMC_hf=n
139    fi
140
141
142    IGCM_debug_PopStack "ATM_Initialize"
143}
144
145#-----------------------------------------------------------------
146function ATM_Update
147{
148    IGCM_debug_PushStack "ATM_Update"
149
150
151    ## Algorithme for special treatment for Bands_xxx file
152    ## For CumulPeriod=1 ;
153    ##        IF NbPeriod_Adjust = 0 ; set LMDZ_adjust=n
154    ##                                IF LMDZ_Bands_file_name was given in lmdz.card THEN Get Bands file directly from server. Store it later with _0 suffix.
155    ##                                IF no LMDZ_Bands_file_name was given, start without Bands file. Store it later with _0 suffix.
156    ##        ELSE set LMDZ_adjust=y ; start without Bands file ; Store it later in PARAM/ directory in submit directory with suffix _1 ;
157    ##
158    ## For CumulPeriod=2 to LMDZ_NbPeriod_adjust ;
159    ##       Get Bands file from PARAM/ in submit directory (CumulPeriod-1) ; set LMDZ_adjust=y ; Store Bands file in PARAM/ ;
160    ##
161    ## For CumulPeriod > LMDZ_NbPeriod_adjust ; LMDZ_adjust=n ; Get Bands file from PARAM/ ; Do not store ;
162
163    if [ ${CumulPeriod} -eq 1 ] ; then
164        if [ ${LMDZ_NbPeriod_adjust} -eq 0 ] ; then
165            if [ ! X${LMDZ_Bands_file_name} = X ] ; then
166                IGCM_sys_Get ${LMDZ_Bands_file_name} Bands_${RESOL_ATM_3D}_${NUM_PROC_ATM}prc.dat
167                IGCM_sys_Chmod u+w Bands_${RESOL_ATM_3D}_${NUM_PROC_ATM}prc.dat
168                IGCM_debug_Print 1 "Bands file forced to ${LMDZ_Bands_file_name} and stored in ${config_UserChoices_JobName}_Bands_${RESOL_ATM_3D}_${NUM_PROC_ATM}prc.dat_0"
169            fi
170        fi
171    fi
172
173    LMDZ_adjust=n
174    [ ${CumulPeriod} -le ${LMDZ_NbPeriod_adjust} ] && LMDZ_adjust=y
175
176    RefPeriod=${LMDZ_NbPeriod_adjust} #0 to use a Bands file from Restart
177    [ ${CumulPeriod} -le ${LMDZ_NbPeriod_adjust} ] && (( RefPeriod = ${CumulPeriod} - 1 )) 
178
179    # Get Bands file from PARAM directory if file exist
180    if ( [ ${CumulPeriod} -gt 1 ] && [ -f ${SUBMIT_DIR}/PARAM/${config_UserChoices_JobName}_Bands_${RESOL_ATM_3D}_${NUM_PROC_ATM}prc.dat_${RefPeriod} ] ) ; then
181        IGCM_sys_Cp ${SUBMIT_DIR}/PARAM/${config_UserChoices_JobName}_Bands_${RESOL_ATM_3D}_${NUM_PROC_ATM}prc.dat_${RefPeriod} Bands_${RESOL_ATM_3D}_${NUM_PROC_ATM}prc.dat
182        IGCM_sys_Chmod u+w Bands_${RESOL_ATM_3D}_${NUM_PROC_ATM}prc.dat
183    fi
184
185    ##-- GHG forcing :
186    ##   If forcing file exist in run directory, read values for the current year
187    ##   and set in config.def. If not use the default value set in config.def
188
189    # Read value for solaire from file SOLARANDVOLCANOES.txt. If file not existing, take DEFAULT value from file.
190    if [ -f SOLARANDVOLCANOES.txt ] ; then
191        value=`grep Annee_${year} SOLARANDVOLCANOES.txt | awk -F= '{print $2}'`
192        if [ X"${value}" = X ] ; then
193            # The grep returned empty variable, stop execution
194            IGCM_debug_Exit "The file SOLARANDVOLCANOES.txt do not contain the current year."
195            IGCM_debug_Verif_Exit
196        fi
197    else
198        value=DEFAULT
199    fi
200    IGCM_comp_modifyDefFile nonblocker config.def solaire $value
201
202
203    # Read value for co2_ppm from file CO2.txt. If file not existing, take DEFAULT value from file.
204    if [ -f CO2.txt ] ; then
205        value=`grep Annee_${year} CO2.txt | awk -F= '{print $2}'`
206        if [ X"${value}" = X ] ; then
207            # The grep returned empty variable, stop execution
208            IGCM_debug_Exit "The file CO2.txt do not contain the current year."
209            IGCM_debug_Verif_Exit
210        fi
211    else
212        value=DEFAULT
213    fi
214    IGCM_comp_modifyDefFile nonblocker config.def co2_ppm $value
215
216
217    # Read value for CH4_ppb from file CH4.txt. If file not existing, take DEFAULT value from file.
218    if [ -f CH4.txt ] ; then
219        value=`grep Annee_${year} CH4.txt | awk -F= '{print $2}'`
220        if [ X"${value}" = X ] ; then
221            # The grep returned empty variable, stop execution
222            IGCM_debug_Exit "The file CH4.txt do not contain the current year."
223            IGCM_debug_Verif_Exit
224        fi
225    else
226        value=DEFAULT
227    fi
228    IGCM_comp_modifyDefFile nonblocker config.def CH4_ppb $value
229
230
231    # Read value for N2O_ppb from file N2O.txt. If file not existing, take DEFAULT value from file.
232    if [ -f N2O.txt ] ; then
233        value=`grep Annee_${year} N2O.txt | awk -F= '{print $2}'`
234        if [ X"${value}" = X ] ; then
235            # The grep returned empty variable, stop execution
236            IGCM_debug_Exit "The file N2O.txt do not contain the current year."
237            IGCM_debug_Verif_Exit
238        fi
239    else
240        value=DEFAULT
241    fi
242    IGCM_comp_modifyDefFile nonblocker config.def N2O_ppb $value
243
244    # Read value for CFC11_ppt from file CFC11.txt. If file not existing, take DEFAULT value from file.
245    if [ -f CFC11.txt ] ; then
246        value=`grep Annee_${year} CFC11.txt | awk -F= '{print $2}'`
247        if [ X"${value}" = X ] ; then
248            # The grep returned empty variable, stop execution
249            IGCM_debug_Exit "The file CFC11.txt do not contain the current year."
250            IGCM_debug_Verif_Exit
251        fi
252    else
253        value=DEFAULT
254    fi
255    IGCM_comp_modifyDefFile nonblocker config.def CFC11_ppt $value
256
257
258    # Read value for CFC12_ppt from file CFC12.txt. If file not existing, take DEFAULT value from file.
259    if [ -f CFC12.txt ] ; then
260        value=`grep Annee_${year} CFC12.txt | awk -F= '{print $2}'`
261        if [ X"${value}" = X ] ; then
262            # The grep returned empty variable, stop execution
263            IGCM_debug_Exit "The file CFC12.txt do not contain the current year."
264            IGCM_debug_Verif_Exit
265        fi
266    else
267        value=DEFAULT
268    fi
269    IGCM_comp_modifyDefFile nonblocker config.def CFC12_ppt $value
270
271
272    ## Coupling Time Step : Take value of FreqCoupling set in oasis.card or if it is not set, take default value 86400
273    LMDZ_t_coupl=${oasis_UserChoices_FreqCoupling:-86400}
274    IGCM_debug_Print 3 "LMDZ_t_coupl "   ${LMDZ_t_coupl}
275    IGCM_comp_modifyDefFile nonblocker config.def t_coupl   ${LMDZ_t_coupl} 
276
277    ##-- Add special treatement for CARBON CYCLE
278    if [ X"${lmdz_UserChoices_CARBON_CYCLE}" = X"control" ] || [ X"${lmdz_UserChoices_CARBON_CYCLE}" = X"historical" ] ; then
279        ATM_Carbon_Update
280    fi
281
282
283    ##-- Set LMDZ_COSP_daily1979=y in section UserChoices in lmdz.card to activate
284    ##   COSP daily output for years 1979 and later (mandatory for historical CMIP5 run).
285    if ([ X"${lmdz_UserChoices_LMDZ_COSP_daily1979}" = X"y" ] &&  [ ${year} -ge 1979 ]) ; then
286        LMDZ_COSP_daily=y
287    fi
288
289    # Default init : files are desactivated
290    IGCM_comp_modifyXmlFile force file_def_histmth_lmdz.xml histmth enabled .FALSE.
291    IGCM_comp_modifyXmlFile force file_def_histday_lmdz.xml histday enabled .FALSE.
292    IGCM_comp_modifyXmlFile force file_def_histhf_lmdz.xml histhf enabled .FALSE.
293    #IGCM_comp_modifyXmlFile force file_def_histhf3h_lmdz.xml histhf3h enabled .FALSE.
294    #IGCM_comp_modifyXmlFile force file_def_histhf3hm_lmdz.xml histhf3hm enabled .FALSE.
295    IGCM_comp_modifyXmlFile force file_def_histstn_lmdz.xml histstn enabled .FALSE.
296    IGCM_comp_modifyXmlFile force file_def_histmthNMC_lmdz.xml histmthNMC enabled .FALSE.
297    IGCM_comp_modifyXmlFile force file_def_histdayNMC_lmdz.xml histdayNMC enabled .FALSE.
298    IGCM_comp_modifyXmlFile force file_def_histhfNMC_lmdz.xml histhfNMC enabled .FALSE.
299    IGCM_comp_modifyXmlFile force file_def_histmthCOSP_lmdz.xml histmthCOSP enabled .FALSE.
300    IGCM_comp_modifyXmlFile force file_def_histdayCOSP_lmdz.xml histdayCOSP enabled .FALSE.
301    IGCM_comp_modifyXmlFile force file_def_histhfCOSP_lmdz.xml histhfCOSP enabled .FALSE.
302
303    # Default output level : 5
304    IGCM_comp_modifyXmlFile force file_def_histmth_lmdz.xml histmth output_level 5
305    IGCM_comp_modifyXmlFile force file_def_histday_lmdz.xml histday output_level 5
306    IGCM_comp_modifyXmlFile force file_def_histhf_lmdz.xml histhf output_level 5
307    #IGCM_comp_modifyXmlFile force file_def_histhf3h_lmdz.xml histhf3h output_level 5
308    #IGCM_comp_modifyXmlFile force file_def_histhf3hm_lmdz.xml histhf3hm output_level 5
309    IGCM_comp_modifyXmlFile force file_def_histstn_lmdz.xml histstn output_level 5
310    IGCM_comp_modifyXmlFile force file_def_histmthNMC_lmdz.xml histmthNMC output_level 5
311    IGCM_comp_modifyXmlFile force file_def_histdayNMC_lmdz.xml histdayNMC output_level 5
312    IGCM_comp_modifyXmlFile force file_def_histhfNMC_lmdz.xml histhfNMC output_level 5
313    IGCM_comp_modifyXmlFile force file_def_histmthCOSP_lmdz.xml histmthCOSP output_level 5
314    IGCM_comp_modifyXmlFile force file_def_histdayCOSP_lmdz.xml histdayCOSP output_level 5
315    IGCM_comp_modifyXmlFile force file_def_histhfCOSP_lmdz.xml histhfCOSP output_level 5
316
317    # FILLING XIOS XMLs
318    if [ X${ok_mensuel} = Xy ] ; then
319        IGCM_comp_modifyXmlFile force file_def_histmth_lmdz.xml histmth enabled .TRUE.
320        IGCM_comp_modifyXmlFile force file_def_histmth_lmdz.xml histmth output_freq 1mo
321        IGCM_comp_modifyXmlFile force file_def_histmth_lmdz.xml histmth name histmth
322    fi
323    if [ X${ok_journe} = Xy ] ; then   
324        IGCM_comp_modifyXmlFile force file_def_histday_lmdz.xml histday enabled .TRUE.
325        IGCM_comp_modifyXmlFile force file_def_histday_lmdz.xml histday output_freq 1d
326        IGCM_comp_modifyXmlFile force file_def_histday_lmdz.xml histday name histday
327        if [ X${OutLevel} = Xlow ] || [ X${OutLevel} = Xmedium ] ; then
328            IGCM_comp_modifyXmlFile force file_def_histday_lmdz.xml histday output_level 2
329        fi
330    fi
331    if [ X${ok_hf} = Xy ] ; then
332        IGCM_comp_modifyXmlFile force file_def_histhf_lmdz.xml histhf enabled .TRUE.
333        IGCM_comp_modifyXmlFile force file_def_histhf_lmdz.xml histhf output_freq 6h
334        IGCM_comp_modifyXmlFile force file_def_histhf_lmdz.xml histhf name histhf
335        if [ X${OutLevel} = Xlow ] ; then
336            IGCM_comp_modifyXmlFile force file_def_histhf_lmdz.xml histhf output_level 5
337        elif [ X${OutLevel} = Xmedium ] ; then
338            IGCM_comp_modifyXmlFile force file_def_histhf_lmdz.xml histhf output_level 6
339        elif [ X${OutLevel} = Xhigh ] ; then
340            IGCM_comp_modifyXmlFile force file_def_histhf_lmdz.xml histhf output_level 7
341        fi
342    fi 
343    if [ X${ok_hf3h} = Xy ] ; then
344        IGCM_comp_modifyXmlFile force file_def_histhf3h_lmdz.xml histhf3h enabled .TRUE.
345        IGCM_comp_modifyXmlFile force file_def_histhf3h_lmdz.xml histhf3h output_freq 3h
346        IGCM_comp_modifyXmlFile force file_def_histhf3h_lmdz.xml histhf3h name histhf3h
347    fi 
348    if [ X${ok_hf3hm} = Xy ] ; then
349        IGCM_comp_modifyXmlFile force file_def_histhf3hm_lmdz.xml histhf3hm enabled .TRUE.
350        IGCM_comp_modifyXmlFile force file_def_histhf3hm_lmdz.xml histhf3hm output_freq 3h
351        IGCM_comp_modifyXmlFile force file_def_histhf3hm_lmdz.xml histhf3hm name histhf3hm
352    fi
353    if [ X${ok_stn} = Xy ] ; then
354        IGCM_comp_modifyXmlFile force file_def_histstn_lmdz.xml histstn enabled .TRUE.
355        IGCM_comp_modifyXmlFile force file_def_histstn_lmdz.xml histstn output_freq 1800s
356        IGCM_comp_modifyXmlFile force file_def_histstn_lmdz.xml histstn name histstn
357    fi
358    if [ X${LMDZ_NMC_monthly} = Xy ] ; then
359        IGCM_comp_modifyXmlFile force file_def_histmthNMC_lmdz.xml histmthNMC enabled .TRUE.
360        IGCM_comp_modifyXmlFile force file_def_histmthNMC_lmdz.xml histmthNMC output_freq 1mo
361        IGCM_comp_modifyXmlFile force file_def_histmthNMC_lmdz.xml histmthNMC name histmthNMC
362    fi
363    if [ X${LMDZ_NMC_daily} = Xy ] ; then
364        IGCM_comp_modifyXmlFile force file_def_histdayNMC_lmdz.xml histdayNMC enabled .TRUE.
365        IGCM_comp_modifyXmlFile force file_def_histdayNMC_lmdz.xml histdayNMC output_freq 1d
366        IGCM_comp_modifyXmlFile force file_def_histdayNMC_lmdz.xml histdayNMC name histdayNMC
367    fi
368    if [ X${LMDZ_NMC_hf} = Xy ] ; then
369        IGCM_comp_modifyXmlFile force file_def_histhfNMC_lmdz.xml histhfNMC enabled .TRUE.
370        IGCM_comp_modifyXmlFile force file_def_histhfNMC_lmdz.xml histhfNMC output_freq 6h
371        IGCM_comp_modifyXmlFile force file_def_histhfNMC_lmdz.xml histhfNMC name histhfNMC
372    fi
373    if [  X${LMDZ_COSP_OK} = Xy ] ; then
374        if [ X${LMDZ_COSP_monthly} = Xy ] ; then
375            IGCM_comp_modifyXmlFile force file_def_histmthCOSP_lmdz.xml histmthCOSP enabled .TRUE.
376            IGCM_comp_modifyXmlFile force file_def_histmthCOSP_lmdz.xml histmthCOSP output_freq 1mo
377            IGCM_comp_modifyXmlFile force file_def_histmthCOSP_lmdz.xml histmthCOSP name histmthCOSP
378        fi
379        if [ X${LMDZ_COSP_daily} = Xy ] ; then
380            IGCM_comp_modifyXmlFile force file_def_histdayCOSP_lmdz.xml histdayCOSP enabled .TRUE.
381            IGCM_comp_modifyXmlFile force file_def_histdayCOSP_lmdz.xml histdayCOSP output_freq 1d
382            IGCM_comp_modifyXmlFile force file_def_histdayCOSP_lmdz.xml histdayCOSP name histdayCOSP
383        fi
384        if [ X${LMDZ_COSP_hf} = Xy ] ; then
385            IGCM_comp_modifyXmlFile force file_def_histhfCOSP_lmdz.xml histhfCOSP enabled .TRUE.
386            IGCM_comp_modifyXmlFile force file_def_histhfCOSP_lmdz.xml histhfCOSP output_freq 6h
387            IGCM_comp_modifyXmlFile force file_def_histhfCOSP_lmdz.xml histhfCOSP name histhfCOSP
388        fi
389    fi
390
391    ## gcm.def parameters :
392    # Modification of variable iphysiq depending on the physics
393    if [ X${LMDZ_Physics} = X"AP" ] ; then
394        if [ ${RESOL_ATM_3D} = 96x95x39 ]; then
395            value=10
396        elif [ ${RESOL_ATM_3D} = 144x142x39 ]; then
397            value=15
398        else
399            IGCM_debug_Print 1 "LMDZ_Physics=${LMDZ_Physics} has not been tested for the current resolution RESOL_ATM_3D=${RESOL_ATM_3D}. "
400            IGCM_debug_Print 1 "iphysiq must be defined for the current combination of resolution and phyiscs package"
401            IGCM_debug_Exit "You need to add a special case in lmdz.driver to handle the above combination."
402        fi
403    elif [ X${LMDZ_Physics} = X"NPv3.1" ] ; then
404        if  [ ${RESOL_ATM_3D} = 96x95x39 ] ; then
405            value=5
406        elif [ ${RESOL_ATM_3D} = 144x142x39 ] ; then
407            value=5
408        else
409            IGCM_debug_Print 1 "LMDZ_Physics=${LMDZ_Physics} has not been tested for the current resolution RESOL_ATM_3D=${RESOL_ATM_3D}. "
410            IGCM_debug_Print 1 "iphysiq must be defined for the current combination of resolution and phyiscs package"
411            IGCM_debug_Exit "You need to add a special case in lmdz.driver to handle the above combination."
412        fi
413    elif [ X${LMDZ_Physics} = X"NPv3.2" ] ; then
414        if [ ${RESOL_ATM_3D} = 96x95x39 ] ; then
415            value=5
416        elif [ ${RESOL_ATM_3D} = 144x142x39 ] ; then
417            value=5
418        elif [ ${RESOL_ATM_3D} = 128x118x39 ] ; then
419            value=15
420        else
421            IGCM_debug_Print 1 "LMDZ_Physics=${LMDZ_Physics} has not been tested for the current resolution RESOL_ATM_3D=${RESOL_ATM_3D}. "
422            IGCM_debug_Print 1 "iphysiq must be defined for the current combination of resolution and phyiscs package"
423            IGCM_debug_Exit "You need to add a special case in lmdz.driver to handle the above combination."
424        fi
425    else
426        # Take default value set in gcm.def
427        value=DEFAULT
428    fi
429    IGCM_comp_modifyDefFile nonblocker gcm.def iphysiq $value
430   
431
432    ## run.def parameters
433
434
435    ##-- Remise ou non a zero de la date initiale de LMDZ pour le fichier run.def
436    if [ ${CumulPeriod} -eq 1 ] ; then
437        IGCM_comp_modifyDefFile blocker run.def raz_date  1
438    else
439        IGCM_comp_modifyDefFile blocker run.def raz_date  0
440    fi
441
442    ##-- Calendar type for LMDZ and create_etat0_limit
443    case ${config_UserChoices_CalendarType} in
444        leap|gregorian)
445            IGCM_comp_modifyDefFile blocker run.def calend  gregorian ;;
446        noleap)
447            IGCM_comp_modifyDefFile blocker run.def calend  earth_365d ;;
448        360d)
449            IGCM_comp_modifyDefFile blocker run.def calend  earth_360d ;;
450        *)
451            IGCM_comp_modifyDefFile blocker run.def calend  earth_360d ;;
452    esac
453
454    IGCM_comp_modifyDefFile blocker run.def dayref    ${InitDay}
455    IGCM_comp_modifyDefFile blocker run.def nday      ${PeriodLengthInDays}
456    IGCM_comp_modifyDefFile nonblocker run.def adjust ${LMDZ_adjust}
457
458    # Set anneeref different for gcm and ce0l
459    # Test if executable create_etat0_limit is present and lmdz.x is not present
460    if [ -f create_etat0_limit* ] || [ -f ce0l* ] && [ ! -f lmdz.x ] ; then
461        # for case ce0l : always take current year
462        IGCM_comp_modifyDefFile blocker run.def anneeref ${year}
463
464        # Temporary, set use_filtre_fft=n because we now use dyn3d for ce0l version where fft is not implemented.
465        # In more recent versions of LMDZ, this will not be needed.
466        IGCM_comp_modifyDefFile force   run.def use_filtre_fft n
467    else
468        # for case gcm : take first year of simulation
469        IGCM_comp_modifyDefFile blocker run.def anneeref ${InitYear}
470    fi
471
472    # Activate creation of file grilles_gcm.nc only at first period
473    if [ ${CumulPeriod} -eq 1 ] ; then
474        IGCM_comp_modifyDefFile nonblocker run.def grilles_gcm_netcdf y
475    else
476        IGCM_comp_modifyDefFile nonblocker run.def grilles_gcm_netcdf n
477    fi
478
479    ## Determine from the variable ListOfComponents in config.card coupling to external models
480    ## and set corresponding parameters in run.def
481    echo ListOfComponents now running : ${config_ListOfComponents[*]}
482
483    if [ X${config_ListOfComponents_SRF} = Xorchidee ] ; then
484        echo "Activate ORCHIDEE, set VEGET=y in run.def"
485        IGCM_comp_modifyDefFile blocker run.def VEGET y
486    else
487        echo "No ORCHIDEE, set VEGET=n in run.def"
488        IGCM_comp_modifyDefFile blocker run.def VEGET n
489    fi
490
491    if [ X${config_ListOfComponents_CPL} = Xoasis ] ; then
492        echo "Activate coupling to ocean, set type_ocean=couple in run.def"
493        IGCM_comp_modifyDefFile blocker run.def type_ocean couple
494    else
495        echo "LMDZ is running in forced mode without ocean model, set type_ocean=force in run.def"
496        IGCM_comp_modifyDefFile blocker run.def type_ocean force
497    fi
498
499    if [ X${config_ListOfComponents_CHM} = Xinca ] ; then
500        echo "Activate coupling to INCA, set type_trac=inca in run.def"
501        IGCM_comp_modifyDefFile blocker run.def type_trac inca
502    elif [ X${config_ListOfComponents_CHM} = Xreprobus ] ; then
503        echo "Activate coupling to REPROBUS, set type_trac=repr in run.def"
504        IGCM_comp_modifyDefFile blocker run.def type_trac repr
505        IGCM_comp_modifyDefFile blocker run.def config_inca none
506    else
507        echo "No coupling to chemistry model, set type_trac=lmdz in run.def"
508        IGCM_comp_modifyDefFile blocker run.def type_trac lmdz
509        IGCM_comp_modifyDefFile blocker run.def config_inca none
510    fi
511
512
513    # config.def : Activate direct radiative effect if ok_ade=y
514    if [ ! X${lmdz_UserChoices_ok_ade} = X ]; then
515        IGCM_comp_modifyDefFile nonblocker config.def ok_ade ${lmdz_UserChoices_ok_ade}
516    else
517        IGCM_comp_modifyDefFile nonblocker config.def ok_ade n
518    fi 
519
520    # config.def : Activate indirect radiative effect if ok_aie=y
521    if [ ! X${lmdz_UserChoices_ok_aie} = X ]; then
522        IGCM_comp_modifyDefFile nonblocker config.def ok_aie ${lmdz_UserChoices_ok_aie}
523    else
524        IGCM_comp_modifyDefFile nonblocker config.def ok_aie n
525    fi 
526
527    # config.def : Activate online aerosol coupled model if aerosol_couple=y
528    if [ ! X${lmdz_UserChoices_aerosol_couple} = X ]; then
529        IGCM_comp_modifyDefFile nonblocker config.def aerosol_couple ${lmdz_UserChoices_aerosol_couple}
530    else
531        IGCM_comp_modifyDefFile nonblocker config.def aerosol_couple n
532    fi 
533
534    # config.def : Activate reading of ozone in climatology if read_climoz=2
535    if [ ! X${lmdz_UserChoices_read_climoz} = X ]; then
536        IGCM_comp_modifyDefFile nonblocker config.def read_climoz ${lmdz_UserChoices_read_climoz}
537    else
538        IGCM_comp_modifyDefFile nonblocker config.def read_climoz 0     
539    fi 
540
541    # config.def : Choose aerosol use in radiative effect
542    #  type of coupled aerosol =1 (default) =2 => bc  only =3 => pom only =4 => seasalt only
543    # =5 => dust only =6 => all aerosol   
544    if [ ! X${lmdz_UserChoices_flag_aerosol} = X ]; then
545        IGCM_comp_modifyDefFile nonblocker config.def flag_aerosol ${lmdz_UserChoices_flag_aerosol}
546    else
547        IGCM_comp_modifyDefFile nonblocker config.def flag_aerosol 0
548    fi 
549
550    # config.def : Activate calcul of Cloud droplet number concentration if ok_cdnc=y
551    if [ ! X${lmdz_UserChoices_ok_cdnc} = X ]; then
552        IGCM_comp_modifyDefFile nonblocker config.def ok_cdnc ${lmdz_UserChoices_ok_cdnc}
553    else
554        IGCM_comp_modifyDefFile nonblocker config.def ok_cdnc n
555    fi 
556
557    # guide.def : Activate nudging if ok_guide=y set in lmdz.card
558    if [ ! X${lmdz_UserChoices_ok_guide} = X ] ; then
559        IGCM_comp_modifyDefFile nonblocker guide.def ok_guide  ${lmdz_UserChoices_ok_guide}
560    else
561        IGCM_comp_modifyDefFile nonblocker guide.def ok_guide n
562    fi
563
564    ## Read ByPass_hgardfou_teta option in lmdz.card --> divide teta* by 2 if [ $ByPass_hgardfou_teta = 1 ]
565    ByPass_hgardfou_teta=${lmdz_UserChoices_ByPass_hgardfou_teta}
566    if [ X"${ByPass_hgardfou_teta}" = X"y" ] ; then
567        awk '{ if ($0 ~ /^teta.*=/) {split($0,a,"=") ; print a[1]"="a[2]/2"."} else print $0}' gcm.def > gcm.def.tmp
568        IGCM_sys_Mv gcm.def.tmp gcm.def
569        echo
570        IGCM_debug_Print 1 "ByPass_hgardfou_teta : ^teta*/2 in gcm.def"
571        echo
572        cat gcm.def
573        ByPass_hgardfou_teta=n
574        IGCM_card_WriteOption ${SUBMIT_DIR}/COMP/lmdz.card UserChoices ByPass_hgardfou_teta "${ByPass_hgardfou_teta}"
575    fi
576
577    ## Read ByPass_hgardfou_mats option in lmdz.card --> purmats=y 2 if [ $ByPass_hgardfou_mats = 1 ]
578    ByPass_hgardfou_mats=${lmdz_UserChoices_ByPass_hgardfou_mats}
579    if [ X"${ByPass_hgardfou_mats}" = X"y" ] ; then
580        sed -e "s/^purmats=.*/purmats=y/" gcm.def > gcm.def.tmp
581        IGCM_sys_Mv gcm.def.tmp gcm.def
582        echo
583        IGCM_debug_Print 1 "ByPass_hgardfou_mats : purmats=y in gcm.def"
584        echo
585        cat gcm.def
586        ByPass_hgardfou_mats=n
587        IGCM_card_WriteOption ${SUBMIT_DIR}/COMP/lmdz.card UserChoices ByPass_hgardfou_mats "${ByPass_hgardfou_mats}"
588    fi
589
590    if [ X${lmdz_UserChoices_XIOS}  = Xy ] ; then
591        # Add include of LMDZ context in iodef.xml
592        # In iodef.xml add on next line after "COMPONENT CONTEXT"
593        #  <context id="LMDZ" src="./context_lmdz.xml"/>
594        echo '<context id="LMDZ" src="./context_lmdz.xml"/>' > add.tmp
595        cp iodef.xml iodef.xml.tmp
596        sed -e "/COMPONENT CONTEXT/r add.tmp" iodef.xml.tmp > iodef.xml
597        rm iodef.xml.tmp add.tmp
598
599        # Set ok_all_xml=y in run.def
600        IGCM_comp_modifyDefFile nonblocker run.def ok_all_xml y
601    else
602        # Deactivate ok_all_xml in run.def
603        IGCM_comp_modifyDefFile nonblocker run.def ok_all_xml n
604    fi
605   
606    IGCM_debug_PopStack "ATM_Update"
607}
608
609#-----------------------------------
610function ATM_Finalize
611{
612    IGCM_debug_PushStack "ATM_Finalize"
613
614    # If the file exist, copy Bands_ file to PARAM/ in submit directory. This file will be used for the simulation.
615    # Copy also the same file into ATM/Restart at ARCHIVE directory for backup.
616    if [ -f Bands_${RESOL_ATM_3D}_${NUM_PROC_ATM}prc.dat ] ; then
617      if [ ${CumulPeriod} -le ${LMDZ_NbPeriod_adjust} ] ; then
618        IGCM_sys_Cp Bands_${RESOL_ATM_3D}_${NUM_PROC_ATM}prc.dat ${SUBMIT_DIR}/PARAM/${config_UserChoices_JobName}_Bands_${RESOL_ATM_3D}_${NUM_PROC_ATM}prc.dat_${CumulPeriod}
619        IGCM_sys_Put_Out Bands_${RESOL_ATM_3D}_${NUM_PROC_ATM}prc.dat ${R_OUT_ATM_R}/${config_UserChoices_JobName}_Bands_${RESOL_ATM_3D}_${NUM_PROC_ATM}prc.dat_${CumulPeriod}
620      elif [ ${CumulPeriod} -eq 1 ] && [ ${LMDZ_NbPeriod_adjust} -eq 0 ] ; then
621        # Special case : first period and no adjust => Save bands file with suffix _0
622        IGCM_sys_Cp Bands_${RESOL_ATM_3D}_${NUM_PROC_ATM}prc.dat ${SUBMIT_DIR}/PARAM/${config_UserChoices_JobName}_Bands_${RESOL_ATM_3D}_${NUM_PROC_ATM}prc.dat_0
623        IGCM_sys_Put_Out Bands_${RESOL_ATM_3D}_${NUM_PROC_ATM}prc.dat ${R_OUT_ATM_R}/${config_UserChoices_JobName}_Bands_${RESOL_ATM_3D}_${NUM_PROC_ATM}prc.dat_0
624      fi
625    fi
626
627    # Add special treatement for CARBON CYCLE
628    if [ X"${lmdz_UserChoices_CARBON_CYCLE}" = X"control" ] || [ X"${lmdz_UserChoices_CARBON_CYCLE}" = X"historical" ] ; then
629        ATM_Carbon_Finalize
630    fi
631
632    echo FINALIZE ATM !
633
634    IGCM_debug_PopStack "ATM_Finalize"
635}
636
637
638
639function ATM_Carbon_Update
640{
641    # This fuction will be called only if CARBON_CYCLE is set to control or historical in lmdz.card
642
643    IGCM_debug_PushStack "ATM_Carbon_Update"
644
645    typeset InitPeriodCo2 InitDateBeginCo2 InitDateEndCo2
646    typeset CO2SBG CO2MBG CO2LU CO2_ppm CO2_ppm_prec fCO2_ff
647    typeset PathCO2log
648    typeset PreviousLinelog LastPeriodDateBegin LastPeriodDateEnd LastDatesPeriod LastPREFIX
649   
650    if ( ${FirstInitialize} && [ X"${config_ATM_Restart}" = X"n" ] ) ; then
651        ##--Initialization of fluxes to an undefined value at the first run
652        UndefinedValueCo2=-9999
653        InitPeriodCo2=0
654        InitDateBeginCo2=${UndefinedValueCo2}
655        InitYearCo2=$(( ${year} - 1 )) 
656        InitDateEndCo2=${InitYearCo2}1231
657        fCO2_ff=${UndefinedValueCo2} 
658        CO2SBG=${UndefinedValueCo2}
659        CO2LU=${UndefinedValueCo2}
660        CO2MBG=${UndefinedValueCo2}
661        CO2_ppm_prec=${UndefinedValueCo2}
662        # Get the initial value of atmosp. pco2
663        CO2_ppm=${lmdz_UserChoices_co2_init}
664       
665        IGCM_sys_Cp ${SUBMIT_DIR}/co2.log.init ${SUBMIT_DIR}/co2.log
666        IGCM_sys_Chmod u+w ${SUBMIT_DIR}/co2.log
667       
668        # Save CO2 values in ExeCpuLog variable contents 5 fields
669        echo "${InitPeriodCo2} ${InitDateBeginCo2} ${InitDateEndCo2} ${CO2_ppm} ${CO2_ppm_prec} ${fCO2_ff} ${CO2MBG} ${CO2SBG} ${CO2LU}" |   \
670            gawk '{printf("  %11d | %15s | %15s | %22.15g | %20.15g | %11.8g | %11.8g | %12.8g | %12.8g \n", \
671                              $1,$2,$3,$4,$5,$6,$7,$8,$9)}' >> ${SUBMIT_DIR}/co2.log
672       
673        # Get the path where the log file co2.log is
674        PathCO2log=${SUBMIT_DIR} 
675        # Get Previous line in co2.log
676        PreviousLinelog=$( tail -1 ${PathCO2log}/co2.log )
677       
678    else
679       
680        # NEW parameter in config.card (even for Overule all restarts, you must modify the line after this comment ):
681        # !! NEW for Carbone cycle !! Path where to find old co2.log file for restart CO2.
682        #SubmitRestartPath=
683        if ( ${FirstInitialize} && [ X"${config_ATM_Restart}" = X"y" ] ) ; then
684            IGCM_card_DefineVariableFromOption ${SUBMIT_DIR}/config.card ATM SubmitRestartPath
685            PathCO2log=${config_ATM_SubmitRestartPath}
686            Date_r=$( IGCM_date_ConvertFormatToGregorian ${config_ATM_RestartDate} )
687            PreviousLinelog=$( grep ${Date_r} ${PathCO2log}/co2.log )
688           
689            IGCM_sys_Cp ${SUBMIT_DIR}/co2.log.init ${SUBMIT_DIR}/co2.log
690            IGCM_sys_Chmod u+w ${SUBMIT_DIR}/co2.log
691           
692            # Save Last Line of control in new co2.log file
693            InitPeriodCo2=0   
694            InitDateBeginCo2=$( echo "${PreviousLinelog[*]}" | gawk -F '|' '{gsub(" ",""); print $2}' )
695            InitDateEndCo2=$( echo "${PreviousLinelog[*]}" | gawk -F '|' '{gsub(" ",""); print $3}' )
696            fCO2_ff=$( echo "${PreviousLinelog[*]}" | gawk -F '|' '{gsub(" ",""); print $6}' )
697            CO2SBG=$( echo "${PreviousLinelog[*]}" | gawk -F '|' '{gsub(" ",""); print $8}' )
698            CO2LU=$( echo "${PreviousLinelog[*]}" | gawk -F '|' '{gsub(" ",""); print $9}' )
699            CO2MBG=$( echo "${PreviousLinelog[*]}" | gawk -F '|' '{gsub(" ",""); print $7}' )
700            CO2_ppm_prec=$( echo "${PreviousLinelog[*]}" | gawk -F '|' '{gsub(" ",""); print $5}' )
701            CO2_ppm=$( echo "${PreviousLinelog[*]}" | gawk -F '|' '{gsub(" ",""); print $4}' )
702           
703            echo "${InitPeriodCo2} ${InitDateBeginCo2} ${InitDateEndCo2} ${CO2_ppm} ${CO2_ppm_prec} ${fCO2_ff} ${CO2MBG} ${CO2SBG} ${CO2LU}" |   \
704                gawk '{printf("  %11d | %15s | %15s | %22.15g | %20.15g | %11.8g | %11.8g | %12.8g | %12.8g \n", \
705                              $1,$2,$3,$4,$5,$6,$7,$8,$9)}' >> ${SUBMIT_DIR}/co2.log
706        else
707           # Get restart line in co2.log
708            PathCO2log=${SUBMIT_DIR}
709            PreviousLinelog=$( tail -1 ${PathCO2log}/co2.log )
710           # Get the value of atmosp. pco2 in co2.log
711            CO2_ppm=$( echo "${PreviousLinelog[*]}" | gawk -F '|' '{gsub(" ",""); print $4}' )
712        fi
713       
714    fi
715   
716    if [ ${lmdz_UserChoices_CARBON_CYCLE} = historical ] ; then
717            # Modify co2_ppm in config.def only for historical run
718            # If not historical run, keep co2_ppm value set earlier by IGCM_comp_modifyDefFile
719        IGCM_comp_modifyDefFile nonblocker config.def co2_ppm     ${CO2_ppm}
720    fi
721    IGCM_debug_PopStack "ATM_Carbon_Update"
722}
723
724
725function ATM_Carbon_Finalize
726{
727    # This fuction will be called only if CARBON_CYCLE is set to control or historical in lmdz.card
728
729    IGCM_debug_PushStack "ATM_Carbon_Finalize"
730
731    typeset CO2SBG_3V CO2SBG CO2MBG CO2SRF CO2LU CO2_ppm CO2_ppm_prec fCO2_ff
732   
733        # Fossil fuel emission
734    if [ ${lmdz_UserChoices_CARBON_CYCLE} = control ] ; then
735            # For Control, no fossil fuel emission :
736        fCO2_ff=0
737        echo "Fossil Fuel for control run  :" ${fCO2_ff}
738    else
739            # For historical, get the fossile fuel file :
740        fCO2_ff=$( gawk "{if (match(\$0,\"${year}\ *${month}\")) {print \$3}}" ${SUBMIT_DIR}/PARAM/CMIP5_gridcar_CO2_emissions_fossil_fuel_Andres_1751-2007_monthly_SC.txt )
741        echo "Fossil Fuel for historical run  :" ${fCO2_ff}
742    fi
743   
744        # Get the value of ocean carbon flux
745    CO2MBG=$( ${SUBMIT_DIR}/COMP/lmdz_analyse_pisces_out.awk ocean.output )
746    CO2MBG=$( echo ${CO2MBG} | sed -e "s/ *//" )
747    echo "Ocean carbon flux  :" ${CO2MBG}
748   
749        # Get the value of land fluxes
750    set +A CO2SBG_3V -- $( ${SUBMIT_DIR}/COMP/lmdz_analyse_stomate_out.awk out_orchidee_0000 )
751    CO2SRF=$( echo ${CO2SBG_3V[0]} | sed -e "s/ *//" )
752    CO2LU=$( echo ${CO2SBG_3V[1]} | sed -e "s/ *//" )
753    CO2SBG=$( echo ${CO2SBG_3V[2]} | sed -e "s/ *//" )
754    echo "Land carbon flux (NEP)         :" ${CO2SRF}
755    echo "LU flux          (FLUC)        :" ${CO2LU}
756    echo "Total Land carbon flux (NBP)   :" ${CO2SBG}
757   
758        # Previous CO2
759    CO2_ppm_prec=$( echo "${PreviousLinelog[*]}" | gawk -F '|' '{gsub(" ",""); print $4}' )
760    echo "Previous CO2  :" ${CO2_ppm_prec}
761   
762        # Formula
763    CO2_ppm=$( echo "${CO2_ppm_prec} + (${fCO2_ff} + ${CO2MBG} + ${CO2SBG}) / 2.12" | bc -l )
764    echo "New CO2  :" ${CO2_ppm}
765   
766        # Save CO2 values in ExeCpuLog variable contents 5 fields
767    echo "${CumulPeriod} ${PeriodDateBegin} ${PeriodDateEnd} ${CO2_ppm} ${CO2_ppm_prec} ${fCO2_ff} ${CO2MBG} ${CO2SBG} ${CO2LU}" |   \
768        gawk '{printf("  %11d | %15s | %15s | %22.15g | %20.15g | %11.8g | %11.8g | %12.8g | %12.8g \n", \
769                           $1,$2,$3,$4,$5,$6,$7,$8,$9)}' >> ${SUBMIT_DIR}/co2.log
770   
771    IGCM_debug_PopStack "ATM_Carbon_Finalize"
772}
Note: See TracBrowser for help on using the repository browser.