source: CONFIG/UNIFORM/v7/ICOLMDZOR_v7/GENERAL/DRIVER/lmdz.driver @ 4323

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