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

Last change on this file since 4635 was 4635, checked in by acosce, 5 years ago

merge with IPSLCM6.2 lmdz.driver

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