source: CMIP6/C4MIP/hist-bgc/DRIVER/lmdz.driver

Last change on this file was 5989, checked in by cpipsl, 3 years ago

biogeochemically-coupled version of the simulation of the recent past with CO2 concentration prescribed

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