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

Last change on this file since 2500 was 2500, checked in by sdipsl, 9 years ago

LMDZOR_v6 gets closer to LMDZ latest new physics. Turn on CWRR in orchidee (11 layers).
By default won't run because of lacking physiq.def_L79_NPv5. Get in touch with LMDz team.

File size: 34.7 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
[1923]16    ##-- Calendar type for LMDZ and create_etat0_limit
[697]17    case ${config_UserChoices_CalendarType} in
18        leap|gregorian)
[1923]19            CalendarTypeForLmdz=earth_366d
20            CalendarTypeForCreate=gregorian;;
[697]21        noleap)
[1923]22            CalendarTypeForLmdz=earth_365d
23            CalendarTypeForCreate=${CalendarTypeForLmdz};;
[697]24        360d)
[1923]25            CalendarTypeForLmdz=earth_360d
26            CalendarTypeForCreate=${CalendarTypeForLmdz};;
[697]27        *)
28            CalendarTypeForLmdz=earth_360d
[1923]29            CalendarTypeForCreate=${CalendarTypeForLmdz}
[697]30    esac
31
[1541]32    ##- LMDZ physics version
33    ##  Read LMDZ_Physics option in lmdz.card, if not present take default value AP (old physics)
34    if [ ! X${lmdz_UserChoices_LMDZ_Physics} = X ] ; then
35        LMDZ_Physics=${lmdz_UserChoices_LMDZ_Physics}
36    else
37        LMDZ_Physics=AP
38    fi
39    echo LMDZ physics version : ${LMDZ_Physics}
40
[1643]41    ##- Create_etat0_limit version
[1782]42    ##  Define variable CREATE only if it is set in lmdz.card section UserChoices.
43    ##  This variable is only used in lmdz.card to choose input files.
44    if [ ! X${lmdz_UserChoices_CREATE} = X ] ; then
45        IGCM_card_DefineVariableFromOption ${SUBMIT_DIR}/COMP/lmdz.card UserChoices CREATE
46        CREATE=${lmdz_UserChoices_CREATE}
47        echo create_etat0_limit version : ${CREATE}
48    fi
[1643]49
[1782]50
[1550]51    ## - LMDZ choice of config.def file
52    ##   ConfType must be set in lmdz.card
53    ConfType=${lmdz_UserChoices_ConfType}
[1541]54
[1550]55    ##- LMDZ output level, to be set in lmdz.card
56    if [ X${lmdz_UserChoices_OutLevel} = X ] ; then
57        # OutLevel is not set. Take default value low.
58        OutLevel=low
59    else
60        OutLevel=${lmdz_UserChoices_OutLevel}
61    fi
62
[1539]63    ##-- Output frequency purpose ....
[396]64    ##--  Initialisation  ....
[1539]65    ok_mensuel=n
66    ok_journe=n
[396]67    ok_hf=n
[1539]68    ok_hf3h=n
69    ok_hf3hm=n
70    ok_stn=n
[396]71
72    case ${config_UserChoices_PeriodLength} in
[1539]73        1Y|1y|1M|1m) ok_mensuel=y ;;
74        5D|5d|1D|1d) ok_journe=y ;;
[396]75    esac
76
77    for frequency in ${config_ATM_WriteFrequency} ; do
78        case ${frequency} in
[1539]79            1M|1m) ok_mensuel=y ;;
[396]80        esac
81        case ${frequency} in
[1539]82            5D|5d|1D|1d) ok_journe=y ;;
83        esac
84        case ${frequency} in
[396]85            HF|hf) ok_hf=y ;;
86        esac
[1539]87        case ${frequency} in
88            HF3h|hf3h) ok_hf3h=y ;;
89        esac
90        case ${frequency} in
91            HF3hm|hf3hm) ok_hf3hm=y ;;
92        esac
93        case ${frequency} in
94            STN|stn) ok_stn=y ;;
95        esac
[396]96    done
97
[902]98    ## Read LMDZ_NbPeriod_adjust option in lmdz.card
[1688]99    if [ X"${lmdz_UserChoices_LMDZ_NbPeriod_adjust}" = X"" ] ; then
100        # The variable is not in lmdz.card, set default value
101        LMDZ_NbPeriod_adjust=0
102    else       
103        LMDZ_NbPeriod_adjust=${lmdz_UserChoices_LMDZ_NbPeriod_adjust}
104    fi
[396]105
[815]106    if [ ${LMDZ_NbPeriod_adjust} -eq 0 ] ; then
[1688]107        LMDZ_Bands_file_name=${lmdz_UserChoices_LMDZ_Bands_file_name}
[815]108    fi
109
[912]110
[1783]111    ##  Read LMDZ_COSP_OK in lmdz.card
112    if [ ! X${lmdz_UserChoices_LMDZ_COSP_OK} = X ] ; then
113        LMDZ_COSP_OK=${lmdz_UserChoices_LMDZ_COSP_OK}
114    else
115        LMDZ_COSP_OK=n
116    fi
117    ##  Read LMDZ_COSP_monthly in lmdz.card
118    if [ ! X${lmdz_UserChoices_LMDZ_COSP_monthly} = X ] ; then
119        LMDZ_COSP_monthly=${lmdz_UserChoices_LMDZ_COSP_monthly}
120    else
121        LMDZ_COSP_monthly=n
122    fi
123    ##  Read LMDZ_COSP_daily in lmdz.card
124    if [ ! X${lmdz_UserChoices_LMDZ_COSP_daily} = X ] ; then
125        LMDZ_COSP_daily=${lmdz_UserChoices_LMDZ_COSP_daily}
126    else
127        LMDZ_COSP_daily=n
128    fi
129    ##  Read LMDZ_COSP_hf in lmdz.card
130    if [ ! X${lmdz_UserChoices_LMDZ_COSP_hf} = X ] ; then
131        LMDZ_COSP_hf=${lmdz_UserChoices_LMDZ_COSP_hf}
132    else
133        LMDZ_COSP_hf=n
134    fi
[1000]135
[1783]136    ##  Read LMDZ_NMC_monthly in lmdz.card
137    if [ ! X${lmdz_UserChoices_LMDZ_NMC_monthly} = X ] ; then
138        LMDZ_NMC_monthly=${lmdz_UserChoices_LMDZ_NMC_monthly}
139    else
140        LMDZ_NMC_monthly=n
141    fi
[1000]142
[1783]143    ## Read LMDZ_NMC_daily in lmdz.card
144    if [ ! X${lmdz_UserChoices_LMDZ_NMC_daily} = X ] ; then
145        LMDZ_NMC_daily=${lmdz_UserChoices_LMDZ_NMC_daily}
146    else
147        LMDZ_NMC_daily=n
148    fi
149   
150    ## Read LMDZ_NMC_hf in lmdz.card
151    if [ ! X${lmdz_UserChoices_LMDZ_NMC_hf} = X ] ; then
152        LMDZ_NMC_hf=${lmdz_UserChoices_LMDZ_NMC_hf}
153    else
154        LMDZ_NMC_hf=n
155    fi
156
157
[396]158    IGCM_debug_PopStack "ATM_Initialize"
159}
160
161#-----------------------------------------------------------------
162function ATM_Update
163{
164    IGCM_debug_PushStack "ATM_Update"
165
[1537]166
[749]167    case ${config_UserChoices_PeriodLength} in
168        *Y|*y) 
169               LMDZ_ecrit_ISCCP=30.
170               LMDZ_periodav=30.
[755]171               if [ "${config_UserChoices_CalendarType}" != "360d" ] ; then
[1649]172                  echo Do not consider following warning if your running create_etat0_limit :
[1650]173                  echo WARNING !!! For lmdz : calendartype in config.card. PeriodLength=1Y allowed only for CalendarType=360d
[1649]174               fi
[749]175               ;;
176        *)
177               LMDZ_ecrit_ISCCP=${PeriodLengthInDays}.
178               LMDZ_periodav=${PeriodLengthInDays}.
179               ;;
180    esac
[1546]181 
[396]182    ##-- Remise ou non a zero de la date initiale de LMDZ pour le fichier run.def
183    if [ ${CumulPeriod} -eq 1 ] ; then
184        RAZ_DATE=1
185    else
186        RAZ_DATE=0
187    fi
188
[1892]189    ## Algorithme for special treatment for Bands_xxx file
190    ## For CumulPeriod=1 ;
191    ##        IF NbPeriod_Adjust = 0 ; set LMDZ_adjust=n
192    ##                                IF LMDZ_Bands_file_name was given in lmdz.card THEN Get Bands file directly from server. Store it later with _0 suffix.
193    ##                                IF no LMDZ_Bands_file_name was given, start without Bands file. Store it later with _0 suffix.
194    ##        ELSE set LMDZ_adjust=y ; start without Bands file ; Store it later in PARAM/ directory in submit directory with suffix _1 ;
195    ##
196    ## For CumulPeriod=2 to LMDZ_NbPeriod_adjust ;
197    ##       Get Bands file from PARAM/ in submit directory (CumulPeriod-1) ; set LMDZ_adjust=y ; Store Bands file in PARAM/ ;
198    ##
199    ## For CumulPeriod > LMDZ_NbPeriod_adjust ; LMDZ_adjust=n ; Get Bands file from PARAM/ ; Do not store ;
[815]200
201    if [ ${CumulPeriod} -eq 1 ] ; then
202        if [ ${LMDZ_NbPeriod_adjust} -eq 0 ] ; then
[1778]203            if [ ! X${LMDZ_Bands_file_name} = X ] ; then
[1688]204                IGCM_sys_Get ${LMDZ_Bands_file_name} Bands_${RESOL_ATM_3D}_${NUM_PROC_ATM}prc.dat
205                IGCM_sys_Chmod u+w Bands_${RESOL_ATM_3D}_${NUM_PROC_ATM}prc.dat
206                IGCM_debug_Print 1 "Bands file forced to ${LMDZ_Bands_file_name} and stored in ${config_UserChoices_JobName}_Bands_${RESOL_ATM_3D}_${NUM_PROC_ATM}prc.dat_0"
207            fi
[815]208        fi
209    fi
210
[743]211    LMDZ_adjust=n
212    [ ${CumulPeriod} -le ${LMDZ_NbPeriod_adjust} ] && LMDZ_adjust=y
213
[815]214    RefPeriod=${LMDZ_NbPeriod_adjust} #0 to use a Bands file from Restart
215    [ ${CumulPeriod} -le ${LMDZ_NbPeriod_adjust} ] && (( RefPeriod = ${CumulPeriod} - 1 )) 
[743]216
[1897]217    # Get Bands file from PARAM directory if file exist
[1998]218    if ( [ ${CumulPeriod} -gt 1 ] && [ -f ${SUBMIT_DIR}/PARAM/${config_UserChoices_JobName}_Bands_${RESOL_ATM_3D}_${NUM_PROC_ATM}prc.dat_${RefPeriod} ] ) ; then
[1894]219        IGCM_sys_Cp ${SUBMIT_DIR}/PARAM/${config_UserChoices_JobName}_Bands_${RESOL_ATM_3D}_${NUM_PROC_ATM}prc.dat_${RefPeriod} Bands_${RESOL_ATM_3D}_${NUM_PROC_ATM}prc.dat
[1892]220        IGCM_sys_Chmod u+w Bands_${RESOL_ATM_3D}_${NUM_PROC_ATM}prc.dat
221    fi
[743]222
[1535]223    ##-- GHG forcing :
[2321]224    ##   If forcing file exist in run directory, read values for the current year
225    ##   and set in config.def. If not use the default value set in config.def
[2333]226
227    # Read value for solaire from file SOLARANDVOLCANOES.txt. If file not existing, take DEFAULT value from file.
[1535]228    if [ -f SOLARANDVOLCANOES.txt ] ; then
[2333]229        value=`grep Annee_${year} SOLARANDVOLCANOES.txt | awk -F= '{print $2}'`
230        if [ X"${value}" = X ] ; then
[2321]231            # The grep returned empty variable, stop execution
232            IGCM_debug_Exit "The file SOLARANDVOLCANOES.txt do not contain the current year."
233            IGCM_debug_Verif_Exit
234        fi
[1690]235    else
[2333]236        value=DEFAULT
[1535]237    fi
[2333]238    IGCM_comp_modifyDefFile nonblocker config.def solaire $value
[2321]239
[2333]240
241    # Read value for co2_ppm from file CO2.txt. If file not existing, take DEFAULT value from file.
[1535]242    if [ -f CO2.txt ] ; then
[2333]243        value=`grep Annee_${year} CO2.txt | awk -F= '{print $2}'`
244        if [ X"${value}" = X ] ; then
[2321]245            # The grep returned empty variable, stop execution
246            IGCM_debug_Exit "The file CO2.txt do not contain the current year."
247            IGCM_debug_Verif_Exit
248        fi
[1690]249    else
[2333]250        value=DEFAULT
[1535]251    fi
[2333]252    IGCM_comp_modifyDefFile nonblocker config.def co2_ppm $value
[1690]253
[2333]254
255    # Read value for CH4_ppb from file CH4.txt. If file not existing, take DEFAULT value from file.
[1535]256    if [ -f CH4.txt ] ; then
[2333]257        value=`grep Annee_${year} CH4.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 CH4.txt do not contain the current year."
261            IGCM_debug_Verif_Exit
262        fi
[2333]263    else
264        value=DEFAULT
[1535]265    fi
[2333]266    IGCM_comp_modifyDefFile nonblocker config.def CH4_ppb $value
[2321]267
[2333]268
269    # Read value for N2O_ppb from file N2O.txt. If file not existing, take DEFAULT value from file.
[1535]270    if [ -f N2O.txt ] ; then
[2333]271        value=`grep Annee_${year} N2O.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 N2O.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 N2O_ppb $value
[2321]281
[2333]282    # Read value for CFC11_ppt from file CFC11.txt. If file not existing, take DEFAULT value from file.
[1535]283    if [ -f CFC11.txt ] ; then
[2333]284        value=`grep Annee_${year} CFC11.txt | awk -F= '{print $2}'`
285        if [ X"${value}" = X ] ; then
[2321]286            # The grep returned empty variable, stop execution
287            IGCM_debug_Exit "The file CFC11.txt do not contain the current year."
288            IGCM_debug_Verif_Exit
289        fi
[1690]290    else
[2333]291        value=DEFAULT
[1535]292    fi
[2333]293    IGCM_comp_modifyDefFile nonblocker config.def CFC11_ppt $value
[2321]294
[2333]295
296    # Read value for CFC12_ppt from file CFC12.txt. If file not existing, take DEFAULT value from file.
[1535]297    if [ -f CFC12.txt ] ; then
[2333]298        value=`grep Annee_${year} CFC12.txt | awk -F= '{print $2}'`
299        if [ X"${value}" = X ] ; then
[2321]300            # The grep returned empty variable, stop execution
301            IGCM_debug_Exit "The file CFC12.txt do not contain the current year."
302            IGCM_debug_Verif_Exit
303        fi
[1690]304    else
[2333]305        value=DEFAULT
[1535]306    fi
[2333]307    IGCM_comp_modifyDefFile nonblocker config.def CFC12_ppt $value
[1535]308
[1780]309
[2336]310    ## Coupling Time Step : Take value of FreqCoupling set in oasis.card or if it is not set, take default value 86400
311    LMDZ_t_coupl=${oasis_UserChoices_FreqCoupling:-86400}
[2332]312    IGCM_debug_Print 3 "LMDZ_t_coupl "   ${LMDZ_t_coupl}
[2333]313    IGCM_comp_modifyDefFile nonblocker config.def t_coupl   ${LMDZ_t_coupl} 
[2332]314
[1780]315    ##-- Add special treatement for CARBON CYCLE
[1546]316    if [ X"${lmdz_UserChoices_CARBON_CYCLE}" = X"control" ] || [ X"${lmdz_UserChoices_CARBON_CYCLE}" = X"historical" ] ; then
[1780]317        ATM_Carbon_Update
318    fi
[1537]319
320
[1538]321    ##-- Set LMDZ_COSP_daily1979=y in section UserChoices in lmdz.card to activate
322    ##   COSP daily output for years 1979 and later (mandatory for historical CMIP5 run).
323    if ([ X"${lmdz_UserChoices_LMDZ_COSP_daily1979}" = X"y" ] &&  [ ${year} -ge 1979 ]) ; then
324        LMDZ_COSP_daily=y
325    fi
[1537]326
[1538]327
[1540]328    ## output.def parameters
[1546]329    #  columns in phys_output_filekeys refer to the filenames given in phys_out_filenames in output.def : 
[2342]330    #                                            histmth       histday        histhf    histhf3h   histhf3hm   histstn
[2333]331    IGCM_comp_modifyDefFile nonblocker output.def phys_out_filekeys "${ok_mensuel} ${ok_journe}   ${ok_hf}  ${ok_hf3h} ${ok_hf3hm} ${ok_stn}"
332    IGCM_comp_modifyDefFile nonblocker output.def ecrit_ISCCP ${LMDZ_ecrit_ISCCP}
333    IGCM_comp_modifyDefFile nonblocker output.def ok_cosp     ${LMDZ_COSP_OK}
334    IGCM_comp_modifyDefFile nonblocker output.def ok_mensuelCOSP  ${LMDZ_COSP_monthly}
335    IGCM_comp_modifyDefFile nonblocker output.def ok_journeCOSP   ${LMDZ_COSP_daily}
336    IGCM_comp_modifyDefFile nonblocker output.def ok_hfCOSP   ${LMDZ_COSP_hf}
337    IGCM_comp_modifyDefFile nonblocker output.def ok_histNMC  "${LMDZ_NMC_monthly} ${LMDZ_NMC_daily} ${LMDZ_NMC_hf}"
[396]338
[2332]339    # XIOS XML definition
[2480]340    if [ X${lmdz_UserChoices_XIOS}  = Xy ] ; then
[2332]341    # Default init : files are desactivated
[2341]342        IGCM_comp_modifyXmlFile force file_def_histmth_lmdz.xml histmth enabled .FALSE.
343        IGCM_comp_modifyXmlFile force file_def_histday_lmdz.xml histday enabled .FALSE.
344        IGCM_comp_modifyXmlFile force file_def_histhf_lmdz.xml histhf enabled .FALSE.
[2342]345#       IGCM_comp_modifyXmlFile force file_def_histhf3h_lmdz.xml histhf3h enabled .FALSE.
346#       IGCM_comp_modifyXmlFile force file_def_histhf3hm_lmdz.xml histhf3hm enabled .FALSE.
[2341]347        IGCM_comp_modifyXmlFile force file_def_histstn_lmdz.xml histstn enabled .FALSE.
348        IGCM_comp_modifyXmlFile force file_def_histmthNMC_lmdz.xml histmthNMC enabled .FALSE.
349        IGCM_comp_modifyXmlFile force file_def_histdayNMC_lmdz.xml histdayNMC enabled .FALSE.
350        IGCM_comp_modifyXmlFile force file_def_histhfNMC_lmdz.xml histhfNMC enabled .FALSE.
[2500]351        IGCM_comp_modifyXmlFile force file_def_histmthCOSP_lmdz.xml histmthCOSP enabled .FALSE.
352        IGCM_comp_modifyXmlFile force file_def_histdayCOSP_lmdz.xml histdayCOSP enabled .FALSE.
353        IGCM_comp_modifyXmlFile force file_def_histhfCOSP_lmdz.xml histhfCOSP enabled .FALSE.
[2480]354
[2332]355    # Default output level : 5
[2480]356        IGCM_comp_modifyXmlFile force file_def_histmth_lmdz.xml histmth output_level 5
357        IGCM_comp_modifyXmlFile force file_def_histday_lmdz.xml histday output_level 5
358        IGCM_comp_modifyXmlFile force file_def_histhf_lmdz.xml histhf output_level 5
359#       IGCM_comp_modifyXmlFile force file_def_histhf3h_lmdz.xml histhf3h output_level 5
360#       IGCM_comp_modifyXmlFile force file_def_histhf3hm_lmdz.xml histhf3hm output_level 5
361        IGCM_comp_modifyXmlFile force file_def_histstn_lmdz.xml histstn output_level 5
362        IGCM_comp_modifyXmlFile force file_def_histmthNMC_lmdz.xml histmthNMC output_level 5
363        IGCM_comp_modifyXmlFile force file_def_histdayNMC_lmdz.xml histdayNMC output_level 5
364        IGCM_comp_modifyXmlFile force file_def_histhfNMC_lmdz.xml histhfNMC output_level 5
[2500]365        IGCM_comp_modifyXmlFile force file_def_histmthCOSP_lmdz.xml histmthCOSP output_level 5
366        IGCM_comp_modifyXmlFile force file_def_histdayCOSP_lmdz.xml histdayCOSP output_level 5
367        IGCM_comp_modifyXmlFile force file_def_histhfCOSP_lmdz.xml histhfCOSP output_level 5
[2332]368     # Filling of XML files
369        if [ X${ok_mensuel} = Xy ] ; then
[2341]370            IGCM_comp_modifyXmlFile force file_def_histmth_lmdz.xml histmth enabled .TRUE.
371            IGCM_comp_modifyXmlFile force file_def_histmth_lmdz.xml histmth output_freq 1mo
372            IGCM_comp_modifyXmlFile force file_def_histmth_lmdz.xml histmth name histmth
[2332]373        fi
374        if [ X${ok_journe} = Xy ] ; then       
[2341]375            IGCM_comp_modifyXmlFile force file_def_histday_lmdz.xml histday enabled .TRUE.
376            IGCM_comp_modifyXmlFile force file_def_histday_lmdz.xml histday output_freq 1d
377            IGCM_comp_modifyXmlFile force file_def_histday_lmdz.xml histday name histday
[2332]378            if [ X${OutLevel} = Xlow ] || [ X${OutLevel} = Xmedium ] ; then
[2341]379                IGCM_comp_modifyXmlFile force file_def_histday_lmdz.xml histday output_level 2
[2332]380            fi
381        fi
382        if [ X${ok_hf} = Xy ] ; then
[2341]383            IGCM_comp_modifyXmlFile force file_def_histhf_lmdz.xml histhf enabled .TRUE.
384            IGCM_comp_modifyXmlFile force file_def_histhf_lmdz.xml histhf output_freq 6h
385            IGCM_comp_modifyXmlFile force file_def_histhf_lmdz.xml histhf name histhf
[2332]386            if [ X${OutLevel} = Xlow ] ; then
[2341]387                IGCM_comp_modifyXmlFile force file_def_histhf_lmdz.xml histhf output_level 2
[2332]388            fi
389        fi     
[2342]390#       if [ X${ok_hf3h} = Xy ] ; then
391#           IGCM_comp_modifyXmlFile force file_def_histhf3h_lmdz.xml histhf3h enabled .TRUE.
392#           IGCM_comp_modifyXmlFile force file_def_histhf3h_lmdz.xml histhf3h output_freq 3h
393#           IGCM_comp_modifyXmlFile force file_def_histhf3h_lmdz.xml histhf3h name histhf3h
394#       fi     
395#       if [ X${ok_hf3hm} = Xy ] ; then
396#           IGCM_comp_modifyXmlFile force file_def_histhf3hm_lmdz.xml histhf3hm enabled .TRUE.
397#           IGCM_comp_modifyXmlFile force file_def_histhf3hm_lmdz.xml histhf3hm output_freq 3h
398#           IGCM_comp_modifyXmlFile force file_def_histhf3hm_lmdz.xml histhf3hm name histhf3hm
399#       fi
[2332]400        if [ X${ok_stn} = Xy ] ; then
[2341]401            IGCM_comp_modifyXmlFile force file_def_histstn_lmdz.xml histstn enabled .TRUE.
402            IGCM_comp_modifyXmlFile force file_def_histstn_lmdz.xml histstn output_freq 1800s
403            IGCM_comp_modifyXmlFile force file_def_histstn_lmdz.xml histstn name histstn
[2332]404        fi
405        if [ X${LMDZ_NMC_monthly} = Xy ] ; then
[2341]406            IGCM_comp_modifyXmlFile force file_def_histmthNMC_lmdz.xml histmthNMC enabled .TRUE.
407            IGCM_comp_modifyXmlFile force file_def_histmthNMC_lmdz.xml histmthNMC output_freq 1mo
408            IGCM_comp_modifyXmlFile force file_def_histmthNMC_lmdz.xml histmthNMC name histmthNMC
[2332]409        fi
410        if [ X${LMDZ_NMC_daily} = Xy ] ; then
[2341]411            IGCM_comp_modifyXmlFile force file_def_histdayNMC_lmdz.xml histdayNMC enabled .TRUE.
412            IGCM_comp_modifyXmlFile force file_def_histdayNMC_lmdz.xml histdayNMC output_freq 1d
413            IGCM_comp_modifyXmlFile force file_def_histdayNMC_lmdz.xml histdayNMC name histdayNMC
[2332]414        fi
415        if [ X${LMDZ_NMC_hf} = Xy ] ; then
[2341]416            IGCM_comp_modifyXmlFile force file_def_histhfNMC_lmdz.xml histhfNMC enabled .TRUE.
417            IGCM_comp_modifyXmlFile force file_def_histhfNMC_lmdz.xml histhfNMC output_freq 6h
418            IGCM_comp_modifyXmlFile force file_def_histhfNMC_lmdz.xml histhfNMC name histhfNMC
[2332]419        fi
[2500]420        if [ X${LMDZ_COSP_monthly} = Xy ] ; then
421            IGCM_comp_modifyXmlFile force file_def_histmthCOSP_lmdz.xml histmthCOSP enabled .TRUE.
422            IGCM_comp_modifyXmlFile force file_def_histmthCOSP_lmdz.xml histmthCOSP output_freq 1mo
423            IGCM_comp_modifyXmlFile force file_def_histmthCOSP_lmdz.xml histmthCOSP name histmthCOSP
424        fi
425        if [ X${LMDZ_COSP_daily} = Xy ] ; then
426            IGCM_comp_modifyXmlFile force file_def_histdayCOSP_lmdz.xml histdayCOSP enabled .TRUE.
427            IGCM_comp_modifyXmlFile force file_def_histdayCOSP_lmdz.xml histdayCOSP output_freq 1d
428            IGCM_comp_modifyXmlFile force file_def_histdayCOSP_lmdz.xml histdayCOSP name histdayCOSP
429        fi
430        if [ X${LMDZ_COSP_hf} = Xy ] ; then
431            IGCM_comp_modifyXmlFile force file_def_histhfCOSP_lmdz.xml histhfCOSP enabled .TRUE.
432            IGCM_comp_modifyXmlFile force file_def_histhfCOSP_lmdz.xml histhfCOSP output_freq 6h
433            IGCM_comp_modifyXmlFile force file_def_histhfCOSP_lmdz.xml histhfCOSP name histhfCOSP
434        fi
435
[2332]436    fi
437
[1544]438    ## gcm.def parameters :
[2333]439    # Modification of variable iphysiq depending on the physics
[2332]440    if [ X${LMDZ_Physics} = X"AP" ] ; then
[2470]441        if [ ${RESOL_ATM_3D} = 96x95x39 ]; then
442            value=10
443        elif [ ${RESOL_ATM_3D} = 144x142x39 ]; then
444            value=15
445        else
446            IGCM_debug_Print 1 "LMDZ_Physics=${LMDZ_Physics} has not been tested for the current resolution RESOL_ATM_3D=${RESOL_ATM_3D}. "
447            IGCM_debug_Print 1 "iphysiq must be defined for the current combination of resolution and phyiscs package"
448            IGCM_debug_Exit "You need to add a special case in lmdz.driver to handle the above combination."
449        fi
450    elif [ X${LMDZ_Physics} = X"NPv3.1" ] ; then
451        if  [ ${RESOL_ATM_3D} = 96x95x39 ] ; then
452            value=5
453        elif [ ${RESOL_ATM_3D} = 144x142x39 ] ; then
454            value=5
455        else
456            IGCM_debug_Print 1 "LMDZ_Physics=${LMDZ_Physics} has not been tested for the current resolution RESOL_ATM_3D=${RESOL_ATM_3D}. "
457            IGCM_debug_Print 1 "iphysiq must be defined for the current combination of resolution and phyiscs package"
458            IGCM_debug_Exit "You need to add a special case in lmdz.driver to handle the above combination."
459        fi
460    elif [ X${LMDZ_Physics} = X"NPv3.2" ] ; then
461        if [ ${RESOL_ATM_3D} = 96x95x39 ] ; then
462            value=5
463        elif [ ${RESOL_ATM_3D} = 144x142x39 ] ; then
464            value=5
465        elif [ ${RESOL_ATM_3D} = 128x118x39 ] ; then
466            value=15
467        else
468            IGCM_debug_Print 1 "LMDZ_Physics=${LMDZ_Physics} has not been tested for the current resolution RESOL_ATM_3D=${RESOL_ATM_3D}. "
469            IGCM_debug_Print 1 "iphysiq must be defined for the current combination of resolution and phyiscs package"
470            IGCM_debug_Exit "You need to add a special case in lmdz.driver to handle the above combination."
471        fi
[2500]472    elif [ X${LMDZ_Physics} = X"NPv5" ] ; then
473        if [ ${RESOL_ATM_3D} = 144x142x79 ] ; then
474            value=5
475        fi
[1690]476    else
[2470]477        # Take default value set in gcm.def
[2333]478        value=DEFAULT
[1544]479    fi
[2333]480    IGCM_comp_modifyDefFile nonblocker gcm.def iphysiq $value
[2470]481   
[396]482
[911]483    ## run.def parameters
[2333]484    IGCM_comp_modifyDefFile blocker run.def dayref   ${InitDay}
485    IGCM_comp_modifyDefFile blocker run.def nday     ${PeriodLengthInDays}
486    IGCM_comp_modifyDefFile blocker run.def raz_date ${RAZ_DATE}
487    IGCM_comp_modifyDefFile blocker run.def periodav ${LMDZ_periodav}
488    IGCM_comp_modifyDefFile nonblocker run.def adjust   ${LMDZ_adjust}
[396]489
[1804]490    # Set anneeref different for gcm and ce0l
[1923]491    # Variable calend is different for a run with create_etat0_limit and the gcm
[1804]492    # Test if executable create_etat0_limit is present and lmdz.x is not present
493    if [ -f create_etat0_limit* ] || [ -f ce0l* ] && [ ! -f lmdz.x ] ; then
494        # for case ce0l : always take current year
[2333]495        IGCM_comp_modifyDefFile blocker run.def anneeref ${year}
496        IGCM_comp_modifyDefFile blocker run.def calend   ${CalendarTypeForCreate}
[2480]497
498        # Temporary, set use_filtre_fft=n because we now use dyn3d for ce0l version where fft is not implemented.
499        # In more recent versions of LMDZ, this will not be needed.
500        IGCM_comp_modifyDefFile force   run.def use_filtre_fft n
[1804]501    else
502        # for case gcm : take first year of simulation
[2333]503        IGCM_comp_modifyDefFile blocker run.def anneeref ${InitYear}
504        IGCM_comp_modifyDefFile blocker run.def calend   ${CalendarTypeForLmdz}
[1804]505    fi
[1643]506
[1804]507    # Activate creation of file grilles_gcm.nc only at first period
508    if [ ${CumulPeriod} -eq 1 ] ; then
[2333]509        IGCM_comp_modifyDefFile nonblocker run.def grilles_gcm_netcdf y
[1804]510    else
[2333]511        IGCM_comp_modifyDefFile nonblocker run.def grilles_gcm_netcdf n
[1804]512    fi
513
[1650]514    ## Determine from the variable ListOfComponents in config.card coupling to external models
515    ## and set corresponding parameters in run.def
516    echo ListOfComponents now running : ${config_ListOfComponents[*]}
517
518    if [ X${config_ListOfComponents_SRF} = Xorchidee ] ; then
519        echo "Activate ORCHIDEE, set VEGET=y in run.def"
[2333]520        IGCM_comp_modifyDefFile blocker run.def VEGET y
[1650]521    else
522        echo "No ORCHIDEE, set VEGET=n in run.def"
[2333]523        IGCM_comp_modifyDefFile blocker run.def VEGET n
[1650]524    fi
525
526    if [ X${config_ListOfComponents_CPL} = Xoasis ] ; then
527        echo "Activate coupling to ocean, set type_ocean=couple in run.def"
[2333]528        IGCM_comp_modifyDefFile blocker run.def type_ocean couple
[1650]529    else
530        echo "LMDZ is running in forced mode without ocean model, set type_ocean=force in run.def"
[2333]531        IGCM_comp_modifyDefFile blocker run.def type_ocean force
[1650]532    fi
533
534    if [ X${config_ListOfComponents_CHM} = Xinca ] ; then
535        echo "Activate coupling to INCA, set type_trac=inca in run.def"
[2333]536        IGCM_comp_modifyDefFile blocker run.def type_trac inca
[1650]537    elif [ X${config_ListOfComponents_CHM} = Xreprobus ] ; then
538        echo "Activate coupling to REPROBUS, set type_trac=repr in run.def"
[2333]539        IGCM_comp_modifyDefFile blocker run.def type_trac repr
540        IGCM_comp_modifyDefFile blocker run.def config_inca none
[1650]541    else
542        echo "No coupling to chemistry model, set type_trac=lmdz in run.def"
[2333]543        IGCM_comp_modifyDefFile blocker run.def type_trac lmdz
544        IGCM_comp_modifyDefFile blocker run.def config_inca none
[1650]545    fi
546
547
[2015]548    # config.def : Activate direct radiative effect if ok_ade=y
549    if [ ! X${lmdz_UserChoices_ok_ade} = X ]; then
[2333]550        IGCM_comp_modifyDefFile nonblocker config.def ok_ade ${lmdz_UserChoices_ok_ade}
[2015]551    else
[2333]552        IGCM_comp_modifyDefFile nonblocker config.def ok_ade n
[2015]553    fi 
554
555    # config.def : Activate indirect radiative effect if ok_aie=y
556    if [ ! X${lmdz_UserChoices_ok_aie} = X ]; then
[2333]557        IGCM_comp_modifyDefFile nonblocker config.def ok_aie ${lmdz_UserChoices_ok_aie}
[2015]558    else
[2333]559        IGCM_comp_modifyDefFile nonblocker config.def ok_aie n
[2015]560    fi 
[1816]561
[2015]562    # config.def : Activate online aerosol coupled model if aerosol_couple=y
563    if [ ! X${lmdz_UserChoices_aerosol_couple} = X ]; then
[2333]564        IGCM_comp_modifyDefFile nonblocker config.def aerosol_couple ${lmdz_UserChoices_aerosol_couple}
[1686]565    else
[2333]566        IGCM_comp_modifyDefFile nonblocker config.def aerosol_couple n
[2015]567    fi 
[1686]568
[2015]569    # config.def : Activate reading of ozone in climatology if read_climoz=2
570    if [ ! X${lmdz_UserChoices_read_climoz} = X ]; then
[2333]571        IGCM_comp_modifyDefFile nonblocker config.def read_climoz ${lmdz_UserChoices_read_climoz}
[2015]572    else
[2333]573        IGCM_comp_modifyDefFile nonblocker config.def read_climoz 0     
[2015]574    fi 
575
576    # config.def : Choose aerosol use in radiative effect
577    #  type of coupled aerosol =1 (default) =2 => bc  only =3 => pom only =4 => seasalt only
578    # =5 => dust only =6 => all aerosol   
579    if [ ! X${lmdz_UserChoices_flag_aerosol} = X ]; then
[2333]580        IGCM_comp_modifyDefFile nonblocker config.def flag_aerosol ${lmdz_UserChoices_flag_aerosol}
[2015]581    else
[2333]582        IGCM_comp_modifyDefFile nonblocker config.def flag_aerosol 0
[2015]583    fi 
584
585    # config.def : Activate calcul of Cloud droplet number concentration if ok_cdnc=y
586    if [ ! X${lmdz_UserChoices_ok_cdnc} = X ]; then
[2333]587        IGCM_comp_modifyDefFile nonblocker config.def ok_cdnc ${lmdz_UserChoices_ok_cdnc}
[2015]588    else
[2333]589        IGCM_comp_modifyDefFile nonblocker config.def ok_cdnc n
[2015]590    fi 
591
[1690]592    # guide.def : Activate nudging if ok_guide=y set in lmdz.card
[1643]593    if [ ! X${lmdz_UserChoices_ok_guide} = X ] ; then
[2333]594        IGCM_comp_modifyDefFile nonblocker guide.def ok_guide  ${lmdz_UserChoices_ok_guide}
[1690]595    else
[2333]596        IGCM_comp_modifyDefFile nonblocker guide.def ok_guide n
[1643]597    fi
598
[902]599    ## Read ByPass_hgardfou_teta option in lmdz.card --> divide teta* by 2 if [ $ByPass_hgardfou_teta = 1 ]
[1172]600    ByPass_hgardfou_teta=${lmdz_UserChoices_ByPass_hgardfou_teta}
[1688]601    if [ X"${ByPass_hgardfou_teta}" = X"y" ] ; then
[396]602        awk '{ if ($0 ~ /^teta.*=/) {split($0,a,"=") ; print a[1]"="a[2]/2"."} else print $0}' gcm.def > gcm.def.tmp
603        IGCM_sys_Mv gcm.def.tmp gcm.def
604        echo
605        IGCM_debug_Print 1 "ByPass_hgardfou_teta : ^teta*/2 in gcm.def"
606        echo
607        cat gcm.def
608        ByPass_hgardfou_teta=n
[902]609        IGCM_card_WriteOption ${SUBMIT_DIR}/COMP/lmdz.card UserChoices ByPass_hgardfou_teta "${ByPass_hgardfou_teta}"
[396]610    fi
611
[902]612    ## Read ByPass_hgardfou_mats option in lmdz.card --> purmats=y 2 if [ $ByPass_hgardfou_mats = 1 ]
[1172]613    ByPass_hgardfou_mats=${lmdz_UserChoices_ByPass_hgardfou_mats}
[1688]614    if [ X"${ByPass_hgardfou_mats}" = X"y" ] ; then
[396]615        sed -e "s/^purmats=.*/purmats=y/" gcm.def > gcm.def.tmp
616        IGCM_sys_Mv gcm.def.tmp gcm.def
617        echo
618        IGCM_debug_Print 1 "ByPass_hgardfou_mats : purmats=y in gcm.def"
619        echo
620        cat gcm.def
621        ByPass_hgardfou_mats=n
[902]622        IGCM_card_WriteOption ${SUBMIT_DIR}/COMP/lmdz.card UserChoices ByPass_hgardfou_mats "${ByPass_hgardfou_mats}"
[396]623    fi
624
[2332]625    if [ X${lmdz_UserChoices_XIOS}  = Xy ] ; then
[2238]626    # Add include of LMDZ context in iodef.xml
627    # In iodef.xml add on next line after "COMPONENT CONTEXT"
628    #  <context id="LMDZ" src="./context_lmdz.xml"/>
[2332]629        echo '<context id="LMDZ" src="./context_lmdz.xml"/>' > add.tmp
630        cp iodef.xml iodef.xml.tmp
631        sed -e "/COMPONENT CONTEXT/r add.tmp" \
632            iodef.xml.tmp > iodef.xml
633        rm iodef.xml.tmp add.tmp
[2476]634
635        # Set ok_all_xml=y in run.def
636        IGCM_comp_modifyDefFile nonblocker run.def ok_all_xml y
637    else
638        # Deactivate ok_all_xml in run.def
639        IGCM_comp_modifyDefFile nonblocker run.def ok_all_xml n
[2332]640    fi
641   
[396]642    IGCM_debug_PopStack "ATM_Update"
643}
644
645#-----------------------------------
646function ATM_Finalize
647{
648    IGCM_debug_PushStack "ATM_Finalize"
649
[1897]650    # If the file exist, copy Bands_ file to PARAM/ in submit directory. This file will be used for the simulation.
[1892]651    # Copy also the same file into ATM/Restart at ARCHIVE directory for backup.
[1897]652    if [ -f Bands_${RESOL_ATM_3D}_${NUM_PROC_ATM}prc.dat ] ; then
653      if [ ${CumulPeriod} -le ${LMDZ_NbPeriod_adjust} ] ; then
654        IGCM_sys_Cp Bands_${RESOL_ATM_3D}_${NUM_PROC_ATM}prc.dat ${SUBMIT_DIR}/PARAM/${config_UserChoices_JobName}_Bands_${RESOL_ATM_3D}_${NUM_PROC_ATM}prc.dat_${CumulPeriod}
655        IGCM_sys_Put_Out Bands_${RESOL_ATM_3D}_${NUM_PROC_ATM}prc.dat ${R_OUT_ATM_R}/${config_UserChoices_JobName}_Bands_${RESOL_ATM_3D}_${NUM_PROC_ATM}prc.dat_${CumulPeriod}
656      elif [ ${CumulPeriod} -eq 1 ] && [ ${LMDZ_NbPeriod_adjust} -eq 0 ] ; then
657        # Special case : first period and no adjust => Save bands file with suffix _0
658        IGCM_sys_Cp Bands_${RESOL_ATM_3D}_${NUM_PROC_ATM}prc.dat ${SUBMIT_DIR}/PARAM/${config_UserChoices_JobName}_Bands_${RESOL_ATM_3D}_${NUM_PROC_ATM}prc.dat_0
659        IGCM_sys_Put_Out Bands_${RESOL_ATM_3D}_${NUM_PROC_ATM}prc.dat ${R_OUT_ATM_R}/${config_UserChoices_JobName}_Bands_${RESOL_ATM_3D}_${NUM_PROC_ATM}prc.dat_0
660      fi
[1892]661    fi
[396]662
[1537]663    # Add special treatement for CARBON CYCLE
[1546]664    if [ X"${lmdz_UserChoices_CARBON_CYCLE}" = X"control" ] || [ X"${lmdz_UserChoices_CARBON_CYCLE}" = X"historical" ] ; then
[1780]665        ATM_Carbon_Finalize
666    fi
[1537]667
[1780]668    echo FINALIZE ATM !
[1537]669
[1780]670    IGCM_debug_PopStack "ATM_Finalize"
671}
[1537]672
673
674
[1780]675function ATM_Carbon_Update
676{
677    # This fuction will be called only if CARBON_CYCLE is set to control or historical in lmdz.card
[1537]678
[1780]679    IGCM_debug_PushStack "ATM_Carbon_Update"
680
681    typeset InitPeriodCo2 InitDateBeginCo2 InitDateEndCo2
682    typeset CO2SBG CO2MBG CO2LU CO2_ppm CO2_ppm_prec fCO2_ff
683    typeset PathCO2log
684    typeset PreviousLinelog LastPeriodDateBegin LastPeriodDateEnd LastDatesPeriod LastPREFIX
685   
686    if ( ${FirstInitialize} && [ X"${config_ATM_Restart}" = X"n" ] ) ; then
687        ##--Initialization of fluxes to an undefined value at the first run
688        UndefinedValueCo2=-9999
689        InitPeriodCo2=0
690        InitDateBeginCo2=${UndefinedValueCo2}
691        InitYearCo2=$(( ${year} - 1 )) 
692        InitDateEndCo2=${InitYearCo2}1231
693        fCO2_ff=${UndefinedValueCo2} 
694        CO2SBG=${UndefinedValueCo2}
695        CO2LU=${UndefinedValueCo2}
696        CO2MBG=${UndefinedValueCo2}
697        CO2_ppm_prec=${UndefinedValueCo2}
698        # Get the initial value of atmosp. pco2
699        CO2_ppm=${lmdz_UserChoices_co2_init}
700       
701        IGCM_sys_Cp ${SUBMIT_DIR}/co2.log.init ${SUBMIT_DIR}/co2.log
702        IGCM_sys_Chmod u+w ${SUBMIT_DIR}/co2.log
703       
[1537]704        # Save CO2 values in ExeCpuLog variable contents 5 fields
[1780]705        echo "${InitPeriodCo2} ${InitDateBeginCo2} ${InitDateEndCo2} ${CO2_ppm} ${CO2_ppm_prec} ${fCO2_ff} ${CO2MBG} ${CO2SBG} ${CO2LU}" |   \
[1537]706            gawk '{printf("  %11d | %15s | %15s | %22.15g | %20.15g | %11.8g | %11.8g | %12.8g | %12.8g \n", \
[1780]707                              $1,$2,$3,$4,$5,$6,$7,$8,$9)}' >> ${SUBMIT_DIR}/co2.log
708       
709        # Get the path where the log file co2.log is
710        PathCO2log=${SUBMIT_DIR} 
711        # Get Previous line in co2.log
712        PreviousLinelog=$( tail -1 ${PathCO2log}/co2.log )
713       
714    else
715       
716        # NEW parameter in config.card (even for Overule all restarts, you must modify the line after this comment ):
717        # !! NEW for Carbone cycle !! Path where to find old co2.log file for restart CO2.
718        #SubmitRestartPath=
719        if ( ${FirstInitialize} && [ X"${config_ATM_Restart}" = X"y" ] ) ; then
720            IGCM_card_DefineVariableFromOption ${SUBMIT_DIR}/config.card ATM SubmitRestartPath
721            PathCO2log=${config_ATM_SubmitRestartPath}
722            Date_r=$( IGCM_date_ConvertFormatToGregorian ${config_ATM_RestartDate} )
723            PreviousLinelog=$( grep ${Date_r} ${PathCO2log}/co2.log )
724           
725            IGCM_sys_Cp ${SUBMIT_DIR}/co2.log.init ${SUBMIT_DIR}/co2.log
726            IGCM_sys_Chmod u+w ${SUBMIT_DIR}/co2.log
727           
728            # Save Last Line of control in new co2.log file
729            InitPeriodCo2=0   
730            InitDateBeginCo2=$( echo "${PreviousLinelog[*]}" | gawk -F '|' '{gsub(" ",""); print $2}' )
731            InitDateEndCo2=$( echo "${PreviousLinelog[*]}" | gawk -F '|' '{gsub(" ",""); print $3}' )
732            fCO2_ff=$( echo "${PreviousLinelog[*]}" | gawk -F '|' '{gsub(" ",""); print $6}' )
733            CO2SBG=$( echo "${PreviousLinelog[*]}" | gawk -F '|' '{gsub(" ",""); print $8}' )
734            CO2LU=$( echo "${PreviousLinelog[*]}" | gawk -F '|' '{gsub(" ",""); print $9}' )
735            CO2MBG=$( echo "${PreviousLinelog[*]}" | gawk -F '|' '{gsub(" ",""); print $7}' )
736            CO2_ppm_prec=$( echo "${PreviousLinelog[*]}" | gawk -F '|' '{gsub(" ",""); print $5}' )
737            CO2_ppm=$( echo "${PreviousLinelog[*]}" | gawk -F '|' '{gsub(" ",""); print $4}' )
738           
739            echo "${InitPeriodCo2} ${InitDateBeginCo2} ${InitDateEndCo2} ${CO2_ppm} ${CO2_ppm_prec} ${fCO2_ff} ${CO2MBG} ${CO2SBG} ${CO2LU}" |   \
740                gawk '{printf("  %11d | %15s | %15s | %22.15g | %20.15g | %11.8g | %11.8g | %12.8g | %12.8g \n", \
741                              $1,$2,$3,$4,$5,$6,$7,$8,$9)}' >> ${SUBMIT_DIR}/co2.log
742        else
743           # Get restart line in co2.log
744            PathCO2log=${SUBMIT_DIR}
745            PreviousLinelog=$( tail -1 ${PathCO2log}/co2.log )
746           # Get the value of atmosp. pco2 in co2.log
747            CO2_ppm=$( echo "${PreviousLinelog[*]}" | gawk -F '|' '{gsub(" ",""); print $4}' )
748        fi
749       
[1537]750    fi
[1780]751   
752    if [ ${lmdz_UserChoices_CARBON_CYCLE} = historical ] ; then
753            # Modify co2_ppm in config.def only for historical run
[2333]754            # If not historical run, keep co2_ppm value set earlier by IGCM_comp_modifyDefFile
755        IGCM_comp_modifyDefFile nonblocker config.def co2_ppm     ${CO2_ppm}
[1780]756    fi
757    IGCM_debug_PopStack "ATM_Carbon_Update"
758}
[1537]759
[396]760
[1780]761function ATM_Carbon_Finalize
762{
763    # This fuction will be called only if CARBON_CYCLE is set to control or historical in lmdz.card
764
765    IGCM_debug_PushStack "ATM_Carbon_Finalize"
766
767    typeset CO2SBG_3V CO2SBG CO2MBG CO2SRF CO2LU CO2_ppm CO2_ppm_prec fCO2_ff
768   
769        # Fossil fuel emission
770    if [ ${lmdz_UserChoices_CARBON_CYCLE} = control ] ; then
771            # For Control, no fossil fuel emission :
772        fCO2_ff=0
773        echo "Fossil Fuel for control run  :" ${fCO2_ff}
774    else
775            # For historical, get the fossile fuel file :
776        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 )
777        echo "Fossil Fuel for historical run  :" ${fCO2_ff}
778    fi
779   
780        # Get the value of ocean carbon flux
781    CO2MBG=$( ${SUBMIT_DIR}/COMP/lmdz_analyse_pisces_out.awk ocean.output )
782    CO2MBG=$( echo ${CO2MBG} | sed -e "s/ *//" )
783    echo "Ocean carbon flux  :" ${CO2MBG}
784   
785        # Get the value of land fluxes
786    set +A CO2SBG_3V -- $( ${SUBMIT_DIR}/COMP/lmdz_analyse_stomate_out.awk out_orchidee_0000 )
787    CO2SRF=$( echo ${CO2SBG_3V[0]} | sed -e "s/ *//" )
788    CO2LU=$( echo ${CO2SBG_3V[1]} | sed -e "s/ *//" )
789    CO2SBG=$( echo ${CO2SBG_3V[2]} | sed -e "s/ *//" )
790    echo "Land carbon flux (NEP)         :" ${CO2SRF}
791    echo "LU flux          (FLUC)        :" ${CO2LU}
792    echo "Total Land carbon flux (NBP)   :" ${CO2SBG}
793   
794        # Previous CO2
795    CO2_ppm_prec=$( echo "${PreviousLinelog[*]}" | gawk -F '|' '{gsub(" ",""); print $4}' )
796    echo "Previous CO2  :" ${CO2_ppm_prec}
797   
798        # Formula
799    CO2_ppm=$( echo "${CO2_ppm_prec} + (${fCO2_ff} + ${CO2MBG} + ${CO2SBG}) / 2.12" | bc -l )
800    echo "New CO2  :" ${CO2_ppm}
801   
802        # Save CO2 values in ExeCpuLog variable contents 5 fields
803    echo "${CumulPeriod} ${PeriodDateBegin} ${PeriodDateEnd} ${CO2_ppm} ${CO2_ppm_prec} ${fCO2_ff} ${CO2MBG} ${CO2SBG} ${CO2LU}" |   \
804        gawk '{printf("  %11d | %15s | %15s | %22.15g | %20.15g | %11.8g | %11.8g | %12.8g | %12.8g \n", \
805                           $1,$2,$3,$4,$5,$6,$7,$8,$9)}' >> ${SUBMIT_DIR}/co2.log
806   
807    IGCM_debug_PopStack "ATM_Carbon_Finalize"
[396]808}
Note: See TracBrowser for help on using the repository browser.