source: CONFIG/UNIFORM/v6/IPSLCM6/GENERAL/DRIVER/lmdz.driver @ 3476

Last change on this file since 3476 was 3476, checked in by aclsce, 6 years ago
  • First commit for CMIP6 experiments (outputs required by CMIP6 DR).
File size: 24.7 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=.FALSE.
50    ok_journe=.FALSE.
51    ok_hf=.FALSE.
52    ok_hf3h=.FALSE.
53    ok_hf3hm=.FALSE.
54    ok_stn=.FALSE.
55
56    if [ X"$( echo ${config_UserChoices_ExpType} | grep CMIP6 )" != "X" ] ; then       
57        ok_mensuel=.FALSE.
58        ok_journe=.FALSE.
59        ok_hf=.FALSE.
60        ok_hf3h=.FALSE.
61        ok_hf3hm=.FALSE.
62        ok_stn=.FALSE.
63    fi
64
65    case ${config_UserChoices_PeriodLength} in
66        1Y|1y|1M|1m) ok_mensuel=.TRUE. ;;
67        5D|5d|1D|1d) ok_journe=.TRUE. ;;
68    esac
69
70    for frequency in ${config_ATM_WriteFrequency} ; do
71        case ${frequency} in
72            1M|1m) ok_mensuel=.TRUE. ;;
73        esac
74        case ${frequency} in
75            5D|5d|1D|1d) ok_journe=.TRUE. ;;
76        esac
77        case ${frequency} in
78            HF|hf) ok_hf=.TRUE. ;;
79        esac
80        case ${frequency} in
81            HF3h|hf3h) ok_hf3h=.TRUE. ;;
82        esac
83        case ${frequency} in
84            HF3hm|hf3hm) ok_hf3hm=.TRUE. ;;
85        esac
86        case ${frequency} in
87            STN|stn) ok_stn=.TRUE. ;;
88        esac
89    done
90
91    ##  Read LMDZ_COSP_OK in lmdz.card
92    if [ X${lmdz_UserChoices_LMDZ_COSP_OK} = Xy ] ; then
93        ##  LMDZ_COSP_OK=y, now read all other COSP variables
94        ##  Read LMDZ_COSP_monthly in lmdz.card
95        if [ X${lmdz_UserChoices_LMDZ_COSP_monthly} = Xy ] ; then
96            LMDZ_COSP_monthly=.TRUE.
97        else
98            LMDZ_COSP_monthly=.FALSE.
99        fi
100        ##  Read LMDZ_COSP_daily in lmdz.card
101        if [ X${lmdz_UserChoices_LMDZ_COSP_daily} = Xy ] ; then
102            LMDZ_COSP_daily=.TRUE.
103        else
104            LMDZ_COSP_daily=.FALSE.
105        fi
106        ##  Read LMDZ_COSP_hf in lmdz.card
107        if [ X${lmdz_UserChoices_LMDZ_COSP_hf} = Xy ] ; then
108            LMDZ_COSP_hf=.TRUE.
109        else
110            LMDZ_COSP_hf=.FALSE.
111        fi
112    else
113        # LMDZ_COSP_OK=n : All cosp output are deactivated
114        LMDZ_COSP_monthly=.FALSE.
115        LMDZ_COSP_daily=.FALSE.
116        LMDZ_COSP_hf=.FALSE.
117    fi 
118
119    ##  Read LMDZ_NMC_monthly in lmdz.card
120    if [ X${lmdz_UserChoices_LMDZ_NMC_monthly} = Xy ] ; then
121        LMDZ_NMC_monthly=.TRUE.
122    else
123        LMDZ_NMC_monthly=.FALSE.
124    fi
125   
126    ## Read LMDZ_NMC_daily in lmdz.card
127    if [ X${lmdz_UserChoices_LMDZ_NMC_daily} = Xy ] ; then
128        LMDZ_NMC_daily=.TRUE.
129    else
130        LMDZ_NMC_daily=.FALSE.
131    fi
132   
133    ## Read LMDZ_NMC_hf in lmdz.card
134    if [ X${lmdz_UserChoices_LMDZ_NMC_hf} = Xy ] ; then
135        LMDZ_NMC_hf=.TRUE.
136    else
137        LMDZ_NMC_hf=.FALSE.
138    fi
139   
140
141    IGCM_debug_PopStack "ATM_Initialize"
142}
143
144#-----------------------------------------------------------------
145function ATM_Update
146{
147    IGCM_debug_PushStack "ATM_Update"
148
149    ##-- GHG forcing :
150    ##   If forcing file exist in run directory, read values for the current year
151    ##   and set in config.def. If not use the default value set in config.def
152
153    # Read value for solaire from file SOLARANDVOLCANOES.txt. If file not existing, take DEFAULT value from file.
154    IGCM_debug_Print 1 "Note that the solaire parameter is here below changed but it is only used by LMDZ for old physics(AP and NPv3.2)"
155    IGCM_debug_Print 1 "For newer physics with iflag_rrtm=1 and ok_suntime_rrtm=y, the solar constant is instead taken from solarforcing.nc file"
156    if [ -f SOLARANDVOLCANOES.txt ] ; then
157        value=`grep Annee_${year} SOLARANDVOLCANOES.txt | awk -F= '{print $2}'`
158        if [ X"${value}" = X ] ; then
159            # The grep returned empty variable, stop execution
160            IGCM_debug_Exit "The file SOLARANDVOLCANOES.txt do not contain the current year."
161            IGCM_debug_Verif_Exit
162        fi
163    else
164        value=DEFAULT
165    fi
166    IGCM_comp_modifyDefFile nonblocker config.def solaire $value
167
168
169    # Read value for co2_ppm from file CO2.txt. If file not existing, take DEFAULT value from file.
170    if [ -f CO2.txt ] ; then
171        value=`grep Annee_${year} CO2.txt | awk -F= '{print $2}'`
172        if [ X"${value}" = X ] ; then
173            # The grep returned empty variable, stop execution
174            IGCM_debug_Exit "The file CO2.txt do not contain the current year."
175            IGCM_debug_Verif_Exit
176        fi
177    else
178        value=DEFAULT
179    fi
180    IGCM_comp_modifyDefFile nonblocker config.def co2_ppm $value
181
182
183    # Read value for CH4_ppb from file CH4.txt. If file not existing, take DEFAULT value from file.
184    if [ -f CH4.txt ] ; then
185        value=`grep Annee_${year} CH4.txt | awk -F= '{print $2}'`
186        if [ X"${value}" = X ] ; then
187            # The grep returned empty variable, stop execution
188            IGCM_debug_Exit "The file CH4.txt do not contain the current year."
189            IGCM_debug_Verif_Exit
190        fi
191    else
192        value=DEFAULT
193    fi
194    IGCM_comp_modifyDefFile nonblocker config.def CH4_ppb $value
195
196
197    # Read value for N2O_ppb from file N2O.txt. If file not existing, take DEFAULT value from file.
198    if [ -f N2O.txt ] ; then
199        value=`grep Annee_${year} N2O.txt | awk -F= '{print $2}'`
200        if [ X"${value}" = X ] ; then
201            # The grep returned empty variable, stop execution
202            IGCM_debug_Exit "The file N2O.txt do not contain the current year."
203            IGCM_debug_Verif_Exit
204        fi
205    else
206        value=DEFAULT
207    fi
208    IGCM_comp_modifyDefFile nonblocker config.def N2O_ppb $value
209
210    # Read value for CFC11_ppt from file CFC11.txt. If file not existing, take DEFAULT value from file.
211    if [ -f CFC11.txt ] ; then
212        value=`grep Annee_${year} CFC11.txt | awk -F= '{print $2}'`
213        if [ X"${value}" = X ] ; then
214            # The grep returned empty variable, stop execution
215            IGCM_debug_Exit "The file CFC11.txt do not contain the current year."
216            IGCM_debug_Verif_Exit
217        fi
218    else
219        value=DEFAULT
220    fi
221    IGCM_comp_modifyDefFile nonblocker config.def CFC11_ppt $value
222
223
224    # Read value for CFC12_ppt from file CFC12.txt. If file not existing, take DEFAULT value from file.
225    if [ -f CFC12.txt ] ; then
226        value=`grep Annee_${year} CFC12.txt | awk -F= '{print $2}'`
227        if [ X"${value}" = X ] ; then
228            # The grep returned empty variable, stop execution
229            IGCM_debug_Exit "The file CFC12.txt do not contain the current year."
230            IGCM_debug_Verif_Exit
231        fi
232    else
233        value=DEFAULT
234    fi
235    IGCM_comp_modifyDefFile nonblocker config.def CFC12_ppt $value
236
237
238    ## Coupling Time Step : Take value of FreqCoupling set in oasis.card or if it is not set, take default value 86400
239    LMDZ_t_coupl=${oasis_UserChoices_FreqCoupling:-86400}
240    IGCM_debug_Print 3 "LMDZ_t_coupl "   ${LMDZ_t_coupl}
241    IGCM_comp_modifyDefFile nonblocker config.def t_coupl   ${LMDZ_t_coupl} 
242
243    ##-- Add special treatement for CARBON CYCLE
244    if [ X"${lmdz_UserChoices_CARBON_CYCLE}" = X"control" ] || [ X"${lmdz_UserChoices_CARBON_CYCLE}" = X"historical" ] ; then
245        ATM_Carbon_Update
246    fi
247
248
249    ##-- Set LMDZ_COSP_daily1979=y in section UserChoices in lmdz.card to activate
250    ##   COSP daily output for years 1979 and later (mandatory for historical CMIP5 run).
251    if ([ X"${lmdz_UserChoices_LMDZ_COSP_daily1979}" = X"y" ] &&  [ ${year} -ge 1979 ]) ; then
252        LMDZ_COSP_daily=.TRUE.
253    fi
254
255    ## Modifiy
256    IGCM_comp_modifyXmlFile nonblocker file_def_histmth_lmdz.xml histmth enabled ${ok_mensuel}
257   
258    IGCM_comp_modifyXmlFile nonblocker file_def_histday_lmdz.xml histday enabled ${ok_journe}
259   
260    if [ X${OutLevel} = Xlow ] || [ X${OutLevel} = Xmedium ] ; then
261        IGCM_comp_modifyXmlFile nonblocker file_def_histday_lmdz.xml histday output_level 2
262    else
263        IGCM_comp_modifyXmlFile nonblocker file_def_histday_lmdz.xml histday output_level 5
264    fi
265   
266    IGCM_comp_modifyXmlFile nonblocker file_def_histhf_lmdz.xml histhf enabled ${ok_hf}
267   
268    if [ X${OutLevel} = Xlow ] ; then
269        IGCM_comp_modifyXmlFile nonblocker file_def_histhf_lmdz.xml histhf output_level 5
270    elif [ X${OutLevel} = Xmedium ] ; then
271        IGCM_comp_modifyXmlFile nonblocker file_def_histhf_lmdz.xml histhf output_level 6
272    elif [ X${OutLevel} = Xhigh ] ; then
273        IGCM_comp_modifyXmlFile nonblocker file_def_histhf_lmdz.xml histhf output_level 7
274    fi
275       
276    IGCM_comp_modifyXmlFile nonblocker file_def_histhf3h_lmdz.xml histhf3h enabled ${ok_hf3h}
277    IGCM_comp_modifyXmlFile nonblocker file_def_histhf3hm_lmdz.xml histhf3hm enabled ${ok_hf3hm}
278
279    IGCM_comp_modifyXmlFile nonblocker file_def_histstn_lmdz.xml histstn enabled ${ok_stn}
280
281    IGCM_comp_modifyXmlFile nonblocker file_def_histmthNMC_lmdz.xml histmthNMC enabled ${LMDZ_NMC_monthly}
282    IGCM_comp_modifyXmlFile nonblocker file_def_histdayNMC_lmdz.xml histdayNMC enabled ${LMDZ_NMC_daily}
283    IGCM_comp_modifyXmlFile nonblocker file_def_histhfNMC_lmdz.xml histhfNMC enabled ${LMDZ_NMC_hf}
284   
285    IGCM_comp_modifyXmlFile nonblocker file_def_histmthCOSP_lmdz.xml histmthCOSP enabled ${LMDZ_COSP_monthly}
286    IGCM_comp_modifyXmlFile nonblocker file_def_histdayCOSP_lmdz.xml histdayCOSP enabled ${LMDZ_COSP_daily}
287    IGCM_comp_modifyXmlFile nonblocker file_def_histhfCOSP_lmdz.xml histhfCOSP enabled ${LMDZ_COSP_hf}
288
289    # Activate the histstrataer output file only for configuration with interactive stratospheric aersols
290    # done by setting the key word LMDZ_strataero=y in lmdz.card
291    if [ X${lmdz_UserChoices_LMDZ_strataero} = Xy ] ; then
292        IGCM_comp_modifyXmlFile nonblocker file_def_histstrataer_lmdz.xml histstrataer enabled .TRUE.
293    else
294        IGCM_comp_modifyXmlFile nonblocker file_def_histstrataer_lmdz.xml histstrataer enabled .FALSE.
295    fi
296
297
298    ## run.def parameters
299
300
301    ##-- Remise ou non a zero de la date initiale de LMDZ pour le fichier run.def
302    if [ ${CumulPeriod} -eq 1 ] ; then
303        IGCM_comp_modifyDefFile blocker run.def raz_date  1
304    else
305        IGCM_comp_modifyDefFile blocker run.def raz_date  0
306    fi
307
308    ##-- Calendar type for LMDZ and create_etat0_limit
309    case ${config_UserChoices_CalendarType} in
310        leap|gregorian)
311            IGCM_comp_modifyDefFile blocker run.def calend  gregorian ;;
312        noleap)
313            IGCM_comp_modifyDefFile blocker run.def calend  earth_365d ;;
314        360d)
315            IGCM_comp_modifyDefFile blocker run.def calend  earth_360d ;;
316        *)
317            IGCM_comp_modifyDefFile blocker run.def calend  earth_360d ;;
318    esac
319
320    IGCM_comp_modifyDefFile blocker run.def dayref    ${InitDay}
321    IGCM_comp_modifyDefFile blocker run.def nday      ${PeriodLengthInDays}
322
323    # Set anneeref different for gcm and ce0l
324    # Test if executable create_etat0_limit is present and lmdz.x is not present
325    if [ -f create_etat0_limit* ] || [ -f ce0l* ] && [ ! -f lmdz.x ] ; then
326        # for case ce0l : always take current year
327        IGCM_comp_modifyDefFile blocker run.def anneeref ${year}
328
329        # Temporary, set use_filtre_fft=n because we now use dyn3d for ce0l version where fft is not implemented.
330        # In more recent versions of LMDZ, this will not be needed.
331        IGCM_comp_modifyDefFile force   run.def use_filtre_fft n
332    else
333        # for case gcm : take first year of simulation
334        IGCM_comp_modifyDefFile blocker run.def anneeref ${InitYear}
335    fi
336
337    ## Determine from the variable ListOfComponents in config.card coupling to external models
338    ## and set corresponding parameters in run.def
339    echo ListOfComponents now running : ${config_ListOfComponents[*]}
340
341    if [ X${config_ListOfComponents_SRF} = Xorchidee ] ; then
342        echo "Activate ORCHIDEE, set VEGET=y in run.def"
343        IGCM_comp_modifyDefFile blocker run.def VEGET y
344    else
345        echo "No ORCHIDEE, set VEGET=n in run.def"
346        IGCM_comp_modifyDefFile blocker run.def VEGET n
347    fi
348
349    if [ X${config_ListOfComponents_CPL} = Xoasis ] ; then
350        echo "Activate coupling to ocean, set type_ocean=couple in run.def"
351        IGCM_comp_modifyDefFile blocker run.def type_ocean couple
352    else
353        echo "LMDZ is running in forced mode without ocean model, set type_ocean=force in run.def"
354        IGCM_comp_modifyDefFile blocker run.def type_ocean force
355    fi
356
357    if [ X${config_ListOfComponents_CHM} = Xinca ] ; then
358        echo "Activate coupling to INCA, set type_trac=inca in run.def"
359        IGCM_comp_modifyDefFile blocker run.def type_trac inca
360    elif [ X${config_ListOfComponents_CHM} = Xreprobus ] ; then
361        echo "Activate coupling to REPROBUS, set type_trac=repr in run.def"
362        IGCM_comp_modifyDefFile blocker run.def type_trac repr
363        IGCM_comp_modifyDefFile blocker run.def config_inca none
364    else
365        echo "No coupling to chemistry model, set type_trac=lmdz in run.def"
366        IGCM_comp_modifyDefFile blocker run.def type_trac lmdz
367        IGCM_comp_modifyDefFile blocker run.def config_inca none
368    fi
369
370
371    # config.def : Activate direct radiative effect if ok_ade=y
372    if [ ! X${lmdz_UserChoices_ok_ade} = X ]; then
373        IGCM_comp_modifyDefFile nonblocker config.def ok_ade ${lmdz_UserChoices_ok_ade}
374    else
375        IGCM_comp_modifyDefFile nonblocker config.def ok_ade n
376    fi 
377
378    # config.def : Activate indirect radiative effect if ok_aie=y
379    if [ ! X${lmdz_UserChoices_ok_aie} = X ]; then
380        IGCM_comp_modifyDefFile nonblocker config.def ok_aie ${lmdz_UserChoices_ok_aie}
381    else
382        IGCM_comp_modifyDefFile nonblocker config.def ok_aie n
383    fi 
384
385    # config.def : Activate online aerosol coupled model if aerosol_couple=y
386    if [ ! X${lmdz_UserChoices_aerosol_couple} = X ]; then
387        IGCM_comp_modifyDefFile nonblocker config.def aerosol_couple ${lmdz_UserChoices_aerosol_couple}
388    else
389        IGCM_comp_modifyDefFile nonblocker config.def aerosol_couple n
390    fi 
391
392    # config.def : Activate reading of ozone in climatology if read_climoz=2
393    if [ ! X${lmdz_UserChoices_read_climoz} = X ]; then
394        IGCM_comp_modifyDefFile nonblocker config.def read_climoz ${lmdz_UserChoices_read_climoz}
395    else
396        IGCM_comp_modifyDefFile nonblocker config.def read_climoz 0     
397    fi 
398
399    # config.def : Choose aerosol use in radiative effect
400    #  type of coupled aerosol =1 (default) =2 => bc  only =3 => pom only =4 => seasalt only
401    # =5 => dust only =6 => all aerosol   
402    if [ ! X${lmdz_UserChoices_flag_aerosol} = X ]; then
403        IGCM_comp_modifyDefFile nonblocker config.def flag_aerosol ${lmdz_UserChoices_flag_aerosol}
404    else
405        IGCM_comp_modifyDefFile nonblocker config.def flag_aerosol 0
406    fi 
407
408    # config.def : Activate calcul of Cloud droplet number concentration if ok_cdnc=y
409    if [ ! X${lmdz_UserChoices_ok_cdnc} = X ]; then
410        IGCM_comp_modifyDefFile nonblocker config.def ok_cdnc ${lmdz_UserChoices_ok_cdnc}
411    else
412        IGCM_comp_modifyDefFile nonblocker config.def ok_cdnc n
413    fi 
414
415    # config.def : Activate COSP
416    if [ ! X${lmdz_UserChoices_LMDZ_COSP_OK} = X ]; then
417        IGCM_comp_modifyDefFile nonblocker config.def ok_cosp ${lmdz_UserChoices_LMDZ_COSP_OK}
418    else
419        IGCM_comp_modifyDefFile nonblocker config.def ok_cosp n
420    fi 
421
422    # config.def : Modify parameter pmagic if it is set in lmdz.card
423    if [ ! X${lmdz_UserChoices_pmagic} = X ]; then
424        IGCM_comp_modifyDefFile nonblocker config.def pmagic ${lmdz_UserChoices_pmagic}
425    else
426        # Take default value set in config.def
427        IGCM_comp_modifyDefFile nonblocker config.def pmagic DEFAULT
428    fi 
429
430    # guide.def : Activate nudging if ok_guide=y set in lmdz.card
431    if [ ! X${lmdz_UserChoices_ok_guide} = X ] ; then
432        IGCM_comp_modifyDefFile nonblocker guide.def ok_guide  ${lmdz_UserChoices_ok_guide}
433    else
434        IGCM_comp_modifyDefFile nonblocker guide.def ok_guide n
435    fi
436
437    ## Read ByPass_hgardfou_teta option in lmdz.card --> divide teta* by 2 if [ $ByPass_hgardfou_teta = 1 ]
438    ByPass_hgardfou_teta=${lmdz_UserChoices_ByPass_hgardfou_teta}
439    if [ X"${ByPass_hgardfou_teta}" = X"y" ] ; then
440        awk '{ if ($0 ~ /^teta.*=/) {split($0,a,"=") ; print a[1]"="a[2]/2"."} else print $0}' gcm.def > gcm.def.tmp
441        IGCM_sys_Mv gcm.def.tmp gcm.def
442        echo
443        IGCM_debug_Print 1 "ByPass_hgardfou_teta : ^teta*/2 in gcm.def"
444        echo
445        cat gcm.def
446        ByPass_hgardfou_teta=n
447        IGCM_card_WriteOption ${SUBMIT_DIR}/COMP/lmdz.card UserChoices ByPass_hgardfou_teta "${ByPass_hgardfou_teta}"
448    fi
449
450    ## Read ByPass_hgardfou_mats option in lmdz.card --> purmats=y 2 if [ $ByPass_hgardfou_mats = 1 ]
451    ByPass_hgardfou_mats=${lmdz_UserChoices_ByPass_hgardfou_mats}
452    if [ X"${ByPass_hgardfou_mats}" = X"y" ] ; then
453        sed -e "s/^purmats=.*/purmats=y/" gcm.def > gcm.def.tmp
454        IGCM_sys_Mv gcm.def.tmp gcm.def
455        echo
456        IGCM_debug_Print 1 "ByPass_hgardfou_mats : purmats=y in gcm.def"
457        echo
458        cat gcm.def
459        ByPass_hgardfou_mats=n
460        IGCM_card_WriteOption ${SUBMIT_DIR}/COMP/lmdz.card UserChoices ByPass_hgardfou_mats "${ByPass_hgardfou_mats}"
461    fi
462
463    # Add include of LMDZ context in iodef.xml
464    # In iodef.xml add on next line after "COMPONENT CONTEXT"
465    #  <context id="LMDZ" src="./context_lmdz.xml"/>
466    echo '<context id="LMDZ" src="./context_lmdz.xml"/>' > add.tmp
467    if [ X"$( echo ${config_UserChoices_ExpType} | grep CMIP6 )" != "X" ] ; then
468        echo '<context id="LMDZ" src="./ping_lmdz.xml"/>' >> add.tmp
469        echo '<context id="LMDZ" src="./dr2xml_lmdz.xml"/>' >> add.tmp
470    fi
471    cp iodef.xml iodef.xml.tmp
472    sed -e "/COMPONENT CONTEXT/r add.tmp" iodef.xml.tmp > iodef.xml
473    rm iodef.xml.tmp add.tmp
474
475    #Long Name as global attribute (if LongName is not empty)
476    if [ ! "X${config_UserChoices_LongName}" = "X" ] ; then
477        listfile=$(ls file_def*lmdz.xml)
478        echo "<variable id=\"LongName\" type=\"string\">${config_UserChoices_LongName}</variable>" > add.tmp
479        for file in ${listfile}
480        do
481            cp ${file} ${file}.tmp
482            sed -e "/<file id/r add.tmp" \
483                ${file}.tmp > ${file}
484            rm ${file}.tmp
485        done
486        rm add.tmp
487    fi
488           
489    IGCM_debug_PopStack "ATM_Update"
490}
491
492#-----------------------------------
493function ATM_Finalize
494{
495    IGCM_debug_PushStack "ATM_Finalize"
496
497    # Add special treatement for CARBON CYCLE
498    if [ X"${lmdz_UserChoices_CARBON_CYCLE}" = X"control" ] || [ X"${lmdz_UserChoices_CARBON_CYCLE}" = X"historical" ] ; then
499        ATM_Carbon_Finalize
500    fi
501
502    echo FINALIZE ATM !
503
504    IGCM_debug_PopStack "ATM_Finalize"
505}
506
507
508
509function ATM_Carbon_Update
510{
511    # This fuction will be called only if CARBON_CYCLE is set to control or historical in lmdz.card
512
513    IGCM_debug_PushStack "ATM_Carbon_Update"
514
515    typeset InitPeriodCo2 InitDateBeginCo2 InitDateEndCo2
516    typeset CO2SBG CO2MBG CO2LU CO2_ppm CO2_ppm_prec fCO2_ff
517    typeset PathCO2log
518    typeset PreviousLinelog LastPeriodDateBegin LastPeriodDateEnd LastDatesPeriod LastPREFIX
519   
520    if ( ${FirstInitialize} && [ X"${config_ATM_Restart}" = X"n" ] ) ; then
521        ##--Initialization of fluxes to an undefined value at the first run
522        UndefinedValueCo2=-9999
523        InitPeriodCo2=0
524        InitDateBeginCo2=${UndefinedValueCo2}
525        InitYearCo2=$(( ${year} - 1 )) 
526        InitDateEndCo2=${InitYearCo2}1231
527        fCO2_ff=${UndefinedValueCo2} 
528        CO2SBG=${UndefinedValueCo2}
529        CO2LU=${UndefinedValueCo2}
530        CO2MBG=${UndefinedValueCo2}
531        CO2_ppm_prec=${UndefinedValueCo2}
532        # Get the initial value of atmosp. pco2
533        CO2_ppm=${lmdz_UserChoices_co2_init}
534       
535        IGCM_sys_Cp ${SUBMIT_DIR}/co2.log.init ${SUBMIT_DIR}/co2.log
536        IGCM_sys_Chmod u+w ${SUBMIT_DIR}/co2.log
537       
538        # Save CO2 values in ExeCpuLog variable contents 5 fields
539        echo "${InitPeriodCo2} ${InitDateBeginCo2} ${InitDateEndCo2} ${CO2_ppm} ${CO2_ppm_prec} ${fCO2_ff} ${CO2MBG} ${CO2SBG} ${CO2LU}" |   \
540            gawk '{printf("  %11d | %15s | %15s | %22.15g | %20.15g | %11.8g | %11.8g | %12.8g | %12.8g \n", \
541                              $1,$2,$3,$4,$5,$6,$7,$8,$9)}' >> ${SUBMIT_DIR}/co2.log
542       
543        # Get the path where the log file co2.log is
544        PathCO2log=${SUBMIT_DIR} 
545        # Get Previous line in co2.log
546        PreviousLinelog=$( tail -1 ${PathCO2log}/co2.log )
547       
548    else
549       
550        # NEW parameter in config.card (even for Overule all restarts, you must modify the line after this comment ):
551        # !! NEW for Carbone cycle !! Path where to find old co2.log file for restart CO2.
552        #SubmitRestartPath=
553        if ( ${FirstInitialize} && [ X"${config_ATM_Restart}" = X"y" ] ) ; then
554            IGCM_card_DefineVariableFromOption ${SUBMIT_DIR}/config.card ATM SubmitRestartPath
555            PathCO2log=${config_ATM_SubmitRestartPath}
556            Date_r=$( IGCM_date_ConvertFormatToGregorian ${config_ATM_RestartDate} )
557            PreviousLinelog=$( grep ${Date_r} ${PathCO2log}/co2.log )
558           
559            IGCM_sys_Cp ${SUBMIT_DIR}/co2.log.init ${SUBMIT_DIR}/co2.log
560            IGCM_sys_Chmod u+w ${SUBMIT_DIR}/co2.log
561           
562            # Save Last Line of control in new co2.log file
563            InitPeriodCo2=0   
564            InitDateBeginCo2=$( echo "${PreviousLinelog[*]}" | gawk -F '|' '{gsub(" ",""); print $2}' )
565            InitDateEndCo2=$( echo "${PreviousLinelog[*]}" | gawk -F '|' '{gsub(" ",""); print $3}' )
566            fCO2_ff=$( echo "${PreviousLinelog[*]}" | gawk -F '|' '{gsub(" ",""); print $6}' )
567            CO2SBG=$( echo "${PreviousLinelog[*]}" | gawk -F '|' '{gsub(" ",""); print $8}' )
568            CO2LU=$( echo "${PreviousLinelog[*]}" | gawk -F '|' '{gsub(" ",""); print $9}' )
569            CO2MBG=$( echo "${PreviousLinelog[*]}" | gawk -F '|' '{gsub(" ",""); print $7}' )
570            CO2_ppm_prec=$( echo "${PreviousLinelog[*]}" | gawk -F '|' '{gsub(" ",""); print $5}' )
571            CO2_ppm=$( echo "${PreviousLinelog[*]}" | gawk -F '|' '{gsub(" ",""); print $4}' )
572           
573            echo "${InitPeriodCo2} ${InitDateBeginCo2} ${InitDateEndCo2} ${CO2_ppm} ${CO2_ppm_prec} ${fCO2_ff} ${CO2MBG} ${CO2SBG} ${CO2LU}" |   \
574                gawk '{printf("  %11d | %15s | %15s | %22.15g | %20.15g | %11.8g | %11.8g | %12.8g | %12.8g \n", \
575                              $1,$2,$3,$4,$5,$6,$7,$8,$9)}' >> ${SUBMIT_DIR}/co2.log
576        else
577           # Get restart line in co2.log
578            PathCO2log=${SUBMIT_DIR}
579            PreviousLinelog=$( tail -1 ${PathCO2log}/co2.log )
580           # Get the value of atmosp. pco2 in co2.log
581            CO2_ppm=$( echo "${PreviousLinelog[*]}" | gawk -F '|' '{gsub(" ",""); print $4}' )
582        fi
583       
584    fi
585   
586    if [ ${lmdz_UserChoices_CARBON_CYCLE} = historical ] ; then
587        # Modify co2_ppm in config.def only for historical run
588        # If not historical run, keep co2_ppm value set earlier by IGCM_comp_modifyDefFile
589        IGCM_comp_modifyDefFile force config.def co2_ppm     ${CO2_ppm}
590    fi
591    IGCM_debug_PopStack "ATM_Carbon_Update"
592}
593
594
595function ATM_Carbon_Finalize
596{
597    # This fuction will be called only if CARBON_CYCLE is set to control or historical in lmdz.card
598
599    IGCM_debug_PushStack "ATM_Carbon_Finalize"
600
601    typeset CO2SBG_3V CO2SBG CO2MBG CO2SRF CO2LU CO2_ppm CO2_ppm_prec fCO2_ff
602   
603        # Fossil fuel emission
604    if [ ${lmdz_UserChoices_CARBON_CYCLE} = control ] ; then
605            # For Control, no fossil fuel emission :
606        fCO2_ff=0
607        echo "Fossil Fuel for control run  :" ${fCO2_ff}
608    else
609            # For historical, get the fossile fuel file :
610        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 )
611        echo "Fossil Fuel for historical run  :" ${fCO2_ff}
612    fi
613   
614        # Get the value of ocean carbon flux
615    CO2MBG=$( ${SUBMIT_DIR}/COMP/lmdz_analyse_pisces_out.awk ocean.output )
616    CO2MBG=$( echo ${CO2MBG} | sed -e "s/ *//" )
617    echo "Ocean carbon flux  :" ${CO2MBG}
618   
619        # Get the value of land fluxes
620    set +A CO2SBG_3V -- $( ${SUBMIT_DIR}/COMP/lmdz_analyse_stomate_out.awk out_orchidee_0000 )
621    CO2SRF=$( echo ${CO2SBG_3V[0]} | sed -e "s/ *//" )
622    CO2LU=$( echo ${CO2SBG_3V[1]} | sed -e "s/ *//" )
623    CO2SBG=$( echo ${CO2SBG_3V[2]} | sed -e "s/ *//" )
624    echo "Land carbon flux (NEP)         :" ${CO2SRF}
625    echo "LU flux          (FLUC)        :" ${CO2LU}
626    echo "Total Land carbon flux (NBP)   :" ${CO2SBG}
627   
628        # Previous CO2
629    CO2_ppm_prec=$( echo "${PreviousLinelog[*]}" | gawk -F '|' '{gsub(" ",""); print $4}' )
630    echo "Previous CO2  :" ${CO2_ppm_prec}
631   
632        # Formula
633    CO2_ppm=$( echo "${CO2_ppm_prec} + (${fCO2_ff} + ${CO2MBG} + ${CO2SBG}) / 2.12" | bc -l )
634    echo "New CO2  :" ${CO2_ppm}
635   
636        # Save CO2 values in ExeCpuLog variable contents 5 fields
637    echo "${CumulPeriod} ${PeriodDateBegin} ${PeriodDateEnd} ${CO2_ppm} ${CO2_ppm_prec} ${fCO2_ff} ${CO2MBG} ${CO2SBG} ${CO2LU}" |   \
638        gawk '{printf("  %11d | %15s | %15s | %22.15g | %20.15g | %11.8g | %11.8g | %12.8g | %12.8g \n", \
639                           $1,$2,$3,$4,$5,$6,$7,$8,$9)}' >> ${SUBMIT_DIR}/co2.log
640   
641    IGCM_debug_PopStack "ATM_Carbon_Finalize"
642}
Note: See TracBrowser for help on using the repository browser.