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

Last change on this file since 4722 was 4722, checked in by jgipsl, 5 years ago

Update LMDZOR_v6.2 with changes done in IPSLCM6.2 and other way around.

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