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

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

modify config.card and lmdz.driver to work without .resol file and to use executable with resolution and option compilation in its name.

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