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

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