source: CONFIG/UNIFORM/v6/LMDZOR_v6.3/GENERAL/DRIVER/lmdz.driver @ 4724

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

Update LMDZOR_v6.3 for LMDZ as done for v6.1.10

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