source: CONFIG/UNIFORM/v5/IPSLCM5CHS_v5/GENERAL/DRIVER/lmdz.driver @ 1783

Last change on this file since 1783 was 1783, checked in by jgipsl, 12 years ago
  • Protected usage of some optional variables in lmdz.card (LMDZ_COSP_xx and LMDZ_NMC_xx).
  • Added test in LMDZ_sed if file exists and print out warning. For exemple the file guide.def is not always copied.


File size: 21.8 KB
Line 
1#!/bin/ksh
2#-----------------------------------------------------------------
3function LMDZ_sed
4{
5# Usage : LMDZ_sed filedef var_name myvalue
6#         In file filedef modify the line containing var_name=xxx into var_name=myvalue
7    IGCM_debug_PushStack "LMDZ_sed"
8   
9    # Test if the fichier exist
10    if [ ! -f ${1} ] ; then
11        echo "WARNING : ${1} file does not exist. Following will not be done : LMDZ_sed : ${1} ${2} ${3}"
12        return
13    fi
14
15    sed -e "s/^${2}\ *=.*/${2}= ${3}/" ${1} > ${1}.tmp
16    RET=$?
17    echo "LMDZ_sed : ${1} ${2} ${3}"
18    \mv ${1}.tmp ${1}
19
20    IGCM_debug_PopStack "LMDZ_sed"
21    return $RET
22}
23function LMDZ_sed_default
24{
25# Usage : LMDZ_sed_default filedef var_name
26#         In file filedef modify the line  "var_name=xxx DEFAULT= myvalue"
27#         into "var_name=myvalue"
28    IGCM_debug_PushStack "LMDZ_sed_default"
29
30    DefValue=$( grep ${2} ${1}  | awk -F"DEFAULT.=*" '{print $2}')
31
32    LMDZ_sed  ${1} ${2} $DefValue
33    IGCM_debug_PopStack "LMDZ_sed_default"
34    return $RET
35}
36
37
38function ATM_Initialize
39{
40    IGCM_debug_PushStack "ATM_Initialize"
41
42    RESOL_ATM=$( echo $RESOL | awk "-Fx" '{print $2}' | awk "-F-" '{print $1}')
43
44    [ -f ${SUBMIT_DIR}/../.resol ] && eval $(grep RESOL_ATM_3D ${SUBMIT_DIR}/../.resol) || RESOL_ATM_3D=96x95x19
45
46    RESOL_ATM_Z=$( echo ${RESOL_ATM_3D} | awk "-Fx" '{print $3}' )
47
48    ##-- Calendar type for LMDZ
49    case ${config_UserChoices_CalendarType} in
50        leap|gregorian)
51            CalendarTypeForLmdz=earth_366d;;
52        noleap)
53            CalendarTypeForLmdz=earth_365d;;
54        360d)
55            CalendarTypeForLmdz=earth_360d;;
56        *)
57            CalendarTypeForLmdz=earth_360d
58    esac
59
60    ##- LMDZ physics version
61    ##  Read LMDZ_Physics option in lmdz.card, if not present take default value AP (old physics)
62    if [ ! X${lmdz_UserChoices_LMDZ_Physics} = X ] ; then
63        LMDZ_Physics=${lmdz_UserChoices_LMDZ_Physics}
64    else
65        LMDZ_Physics=AP
66    fi
67    echo LMDZ physics version : ${LMDZ_Physics}
68
69    ##- Create_etat0_limit version
70    ##  Define variable CREATE only if it is set in lmdz.card section UserChoices.
71    ##  This variable is only used in lmdz.card to choose input files.
72    if [ ! X${lmdz_UserChoices_CREATE} = X ] ; then
73        IGCM_card_DefineVariableFromOption ${SUBMIT_DIR}/COMP/lmdz.card UserChoices CREATE
74        CREATE=${lmdz_UserChoices_CREATE}
75        echo create_etat0_limit version : ${CREATE}
76    fi
77
78
79    ## - LMDZ choice of config.def file
80    ##   ConfType must be set in lmdz.card
81    ConfType=${lmdz_UserChoices_ConfType}
82
83    ##- LMDZ output level, to be set in lmdz.card
84    if [ X${lmdz_UserChoices_OutLevel} = X ] ; then
85        # OutLevel is not set. Take default value low.
86        OutLevel=low
87    else
88        OutLevel=${lmdz_UserChoices_OutLevel}
89    fi
90
91    ##-- Output frequency purpose ....
92    ##--  Initialisation  ....
93    ok_mensuel=n
94    ok_journe=n
95    ok_hf=n
96    ok_hf3h=n
97    ok_hf3hm=n
98    ok_stn=n
99
100    case ${config_UserChoices_PeriodLength} in
101        1Y|1y|1M|1m) ok_mensuel=y ;;
102        5D|5d|1D|1d) ok_journe=y ;;
103    esac
104
105    for frequency in ${config_ATM_WriteFrequency} ; do
106        case ${frequency} in
107            1M|1m) ok_mensuel=y ;;
108        esac
109        case ${frequency} in
110            5D|5d|1D|1d) ok_journe=y ;;
111        esac
112        case ${frequency} in
113            HF|hf) ok_hf=y ;;
114        esac
115        case ${frequency} in
116            HF3h|hf3h) ok_hf3h=y ;;
117        esac
118        case ${frequency} in
119            HF3hm|hf3hm) ok_hf3hm=y ;;
120        esac
121        case ${frequency} in
122            STN|stn) ok_stn=y ;;
123        esac
124    done
125
126    ## Read LMDZ_NbPeriod_adjust option in lmdz.card
127    if [ X"${lmdz_UserChoices_LMDZ_NbPeriod_adjust}" = X"" ] ; then
128        # The variable is not in lmdz.card, set default value
129        LMDZ_NbPeriod_adjust=0
130    else       
131        LMDZ_NbPeriod_adjust=${lmdz_UserChoices_LMDZ_NbPeriod_adjust}
132    fi
133
134    if [ ${LMDZ_NbPeriod_adjust} -eq 0 ] ; then
135        LMDZ_Bands_file_name=${lmdz_UserChoices_LMDZ_Bands_file_name}
136    fi
137
138
139    ##  Read LMDZ_COSP_OK in lmdz.card
140    if [ ! X${lmdz_UserChoices_LMDZ_COSP_OK} = X ] ; then
141        LMDZ_COSP_OK=${lmdz_UserChoices_LMDZ_COSP_OK}
142    else
143        LMDZ_COSP_OK=n
144    fi
145    ##  Read LMDZ_COSP_monthly in lmdz.card
146    if [ ! X${lmdz_UserChoices_LMDZ_COSP_monthly} = X ] ; then
147        LMDZ_COSP_monthly=${lmdz_UserChoices_LMDZ_COSP_monthly}
148    else
149        LMDZ_COSP_monthly=n
150    fi
151    ##  Read LMDZ_COSP_daily in lmdz.card
152    if [ ! X${lmdz_UserChoices_LMDZ_COSP_daily} = X ] ; then
153        LMDZ_COSP_daily=${lmdz_UserChoices_LMDZ_COSP_daily}
154    else
155        LMDZ_COSP_daily=n
156    fi
157    ##  Read LMDZ_COSP_hf in lmdz.card
158    if [ ! X${lmdz_UserChoices_LMDZ_COSP_hf} = X ] ; then
159        LMDZ_COSP_hf=${lmdz_UserChoices_LMDZ_COSP_hf}
160    else
161        LMDZ_COSP_hf=n
162    fi
163
164    ##  Read LMDZ_NMC_monthly in lmdz.card
165    if [ ! X${lmdz_UserChoices_LMDZ_NMC_monthly} = X ] ; then
166        LMDZ_NMC_monthly=${lmdz_UserChoices_LMDZ_NMC_monthly}
167    else
168        LMDZ_NMC_monthly=n
169    fi
170
171    ## Read LMDZ_NMC_daily in lmdz.card
172    if [ ! X${lmdz_UserChoices_LMDZ_NMC_daily} = X ] ; then
173        LMDZ_NMC_daily=${lmdz_UserChoices_LMDZ_NMC_daily}
174    else
175        LMDZ_NMC_daily=n
176    fi
177   
178    ## Read LMDZ_NMC_hf in lmdz.card
179    if [ ! X${lmdz_UserChoices_LMDZ_NMC_hf} = X ] ; then
180        LMDZ_NMC_hf=${lmdz_UserChoices_LMDZ_NMC_hf}
181    else
182        LMDZ_NMC_hf=n
183    fi
184
185
186    IGCM_debug_PopStack "ATM_Initialize"
187}
188
189#-----------------------------------------------------------------
190function ATM_Update
191{
192    IGCM_debug_PushStack "ATM_Update"
193
194
195    case ${config_UserChoices_PeriodLength} in
196        *Y|*y) 
197               LMDZ_ecrit_ISCCP=30.
198               LMDZ_periodav=30.
199               if [ "${config_UserChoices_CalendarType}" != "360d" ] ; then
200                  echo Do not consider following warning if your running create_etat0_limit :
201                  echo WARNING !!! For lmdz : calendartype in config.card. PeriodLength=1Y allowed only for CalendarType=360d
202               fi
203               ;;
204        *)
205               LMDZ_ecrit_ISCCP=${PeriodLengthInDays}.
206               LMDZ_periodav=${PeriodLengthInDays}.
207               ;;
208    esac
209 
210    ##-- Remise ou non a zero de la date initiale de LMDZ pour le fichier run.def
211    if [ ${CumulPeriod} -eq 1 ] ; then
212        RAZ_DATE=1
213    else
214        RAZ_DATE=0
215    fi
216
217    ## algo : For CumulPeriod=1 ;
218    ##        IF NbPeriod_Adjust = 0, Get Bands file directly from server, store it with _0 suffix
219    ##        ELSE LMDZ_adjust=y ; save Bands file on file server ;
220    ##        For CumulPeriod=2 to LMDZ_NbPeriod_adjust ; Get Bands file from server (CumulPeriod-1) ; LMDZ_adjust=y ; save Bands file on file server ;
221    ##        For CumulPeriod > LMDZ_NbPeriod_adjust ; LMDZ_adjust=n ; Get Bands file from server (CumulPeriod=LMDZ_NbPeriod_adjust 0 to force it) ; Use Bands ;
222
223    if [ ${CumulPeriod} -eq 1 ] ; then
224        if [ ${LMDZ_NbPeriod_adjust} -eq 0 ] ; then
225            if [ ! X${LMDZ_Bands_file_name} = X ] ; then
226                IGCM_sys_Get ${LMDZ_Bands_file_name} Bands_${RESOL_ATM_3D}_${NUM_PROC_ATM}prc.dat
227                IGCM_sys_Put_Out Bands_${RESOL_ATM_3D}_${NUM_PROC_ATM}prc.dat ${R_OUT_ATM_D}/${config_UserChoices_JobName}_Bands_${RESOL_ATM_3D}_${NUM_PROC_ATM}prc.dat_0
228                IGCM_sys_Chmod u+w Bands_${RESOL_ATM_3D}_${NUM_PROC_ATM}prc.dat
229                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"
230            fi
231        fi
232    fi
233
234    LMDZ_adjust=n
235    [ ${CumulPeriod} -le ${LMDZ_NbPeriod_adjust} ] && LMDZ_adjust=y
236
237    RefPeriod=${LMDZ_NbPeriod_adjust} #0 to use a Bands file from Restart
238    [ ${CumulPeriod} -le ${LMDZ_NbPeriod_adjust} ] && (( RefPeriod = ${CumulPeriod} - 1 )) 
239
240    [ ${CumulPeriod} -gt 1 ] && ( IGCM_sys_Get ${R_OUT_ATM_D}/${config_UserChoices_JobName}_Bands_${RESOL_ATM_3D}_${NUM_PROC_ATM}prc.dat_${RefPeriod} Bands_${RESOL_ATM_3D}_${NUM_PROC_ATM}prc.dat ; IGCM_sys_Chmod u+w Bands_${RESOL_ATM_3D}_${NUM_PROC_ATM}prc.dat )
241
242    ##-- GHG forcing :
243    ##   If forcing file exist in run directory, read values for the current year and modify config.def
244    if [ -f SOLARANDVOLCANOES.txt ] ; then
245        IPCC_SOLAR=`grep Annee_${year} SOLARANDVOLCANOES.txt | awk -F= '{print $2}'`
246        LMDZ_sed config.def solaire     ${IPCC_SOLAR}
247    else
248        LMDZ_sed_default config.def solaire
249    fi
250    if [ -f CO2.txt ] ; then
251        IPCC_CO2=`grep Annee_${year} CO2.txt | awk -F= '{print $2}'`
252        LMDZ_sed config.def co2_ppm     ${IPCC_CO2}
253    else
254        LMDZ_sed_default config.def co2_ppm
255    fi
256
257
258    if [ -f CH4.txt ] ; then
259        IPCC_CH4=`grep Annee_${year} CH4.txt | awk -F= '{print $2}'`
260        LMDZ_sed config.def CH4_ppb     ${IPCC_CH4}
261    else
262        LMDZ_sed_default config.def CH4_ppb
263    fi
264    if [ -f N2O.txt ] ; then
265        IPCC_N2O=`grep Annee_${year} N2O.txt | awk -F= '{print $2}'`
266        LMDZ_sed config.def N2O_ppb     ${IPCC_N2O}
267    else
268        LMDZ_sed_default config.def N2O_ppb
269    fi
270    if [ -f CFC11.txt ] ; then
271        IPCC_CFC11=`grep Annee_${year} CFC11.txt | awk -F= '{print $2}'`
272        LMDZ_sed config.def CFC11_ppt   ${IPCC_CFC11}
273    else
274        LMDZ_sed_default config.def CFC11_ppt
275    fi
276    if [ -f CFC12.txt ] ; then
277        IPCC_CFC12=`grep Annee_${year} CFC12.txt | awk -F= '{print $2}'`
278        LMDZ_sed config.def CFC12_ppt   ${IPCC_CFC12}
279    else
280        LMDZ_sed_default config.def CFC12_ppt
281    fi
282
283
284    ##-- Add special treatement for CARBON CYCLE
285    if [ X"${lmdz_UserChoices_CARBON_CYCLE}" = X"control" ] || [ X"${lmdz_UserChoices_CARBON_CYCLE}" = X"historical" ] ; then
286        ATM_Carbon_Update
287    fi
288
289
290    ##-- Set LMDZ_COSP_daily1979=y in section UserChoices in lmdz.card to activate
291    ##   COSP daily output for years 1979 and later (mandatory for historical CMIP5 run).
292    if ([ X"${lmdz_UserChoices_LMDZ_COSP_daily1979}" = X"y" ] &&  [ ${year} -ge 1979 ]) ; then
293        LMDZ_COSP_daily=y
294    fi
295
296
297    ## output.def parameters
298    #  columns in phys_output_filekeys refer to the filenames given in phys_out_filenames in output.def : 
299    #                                            histmth       histday        histhf    histfh3h   histhf3hm   histstn
300    LMDZ_sed output.def phys_out_filekeys       "${ok_mensuel} ${ok_journe}   ${ok_hf}  ${ok_hf3h} ${ok_hf3hm} ${ok_stn}"
301    LMDZ_sed output.def ecrit_ISCCP ${LMDZ_ecrit_ISCCP}
302    LMDZ_sed output.def ok_cosp     ${LMDZ_COSP_OK}
303    LMDZ_sed output.def ok_mensuelCOSP  ${LMDZ_COSP_monthly}
304    LMDZ_sed output.def ok_journeCOSP   ${LMDZ_COSP_daily}
305    LMDZ_sed output.def ok_hfCOSP   ${LMDZ_COSP_hf}
306    LMDZ_sed output.def ok_histNMC  "${LMDZ_NMC_monthly} ${LMDZ_NMC_daily} ${LMDZ_NMC_hf}"
307
308    ## gcm.def parameters :
309    # Modification only for new physics
310    if [ X${LMDZ_Physics} = X"NPv3.1" ] ; then
311        LMDZ_sed gcm.def iphysiq     5
312    else
313        LMDZ_sed_default gcm.def iphysiq
314    fi
315
316
317    ## run.def parameters
318    LMDZ_sed run.def dayref   ${InitDay}
319    LMDZ_sed run.def anneeref ${InitYear}
320    LMDZ_sed run.def calend   ${CalendarTypeForLmdz}
321    LMDZ_sed run.def nday     ${PeriodLengthInDays}
322    LMDZ_sed run.def raz_date ${RAZ_DATE}
323    LMDZ_sed run.def periodav ${LMDZ_periodav}
324    LMDZ_sed run.def adjust   ${LMDZ_adjust}
325
326
327    ## Determine from the variable ListOfComponents in config.card coupling to external models
328    ## and set corresponding parameters in run.def
329    echo ListOfComponents now running : ${config_ListOfComponents[*]}
330
331    if [ X${config_ListOfComponents_SRF} = Xorchidee ] ; then
332        echo "Activate ORCHIDEE, set VEGET=y in run.def"
333        LMDZ_sed run.def VEGET y
334    else
335        echo "No ORCHIDEE, set VEGET=n in run.def"
336        LMDZ_sed run.def VEGET n
337    fi
338
339    if [ X${config_ListOfComponents_CPL} = Xoasis ] ; then
340        echo "Activate coupling to ocean, set type_ocean=couple in run.def"
341        LMDZ_sed run.def type_ocean couple
342    else
343        echo "LMDZ is running in forced mode without ocean model, set type_ocean=force in run.def"
344        LMDZ_sed run.def type_ocean force
345    fi
346
347    if [ X${config_ListOfComponents_CHM} = Xinca ] ; then
348        echo "Activate coupling to INCA, set type_trac=inca in run.def"
349        LMDZ_sed run.def type_trac inca
350    elif [ X${config_ListOfComponents_CHM} = Xreprobus ] ; then
351        echo "Activate coupling to REPROBUS, set type_trac=repr in run.def"
352        LMDZ_sed run.def type_trac repr
353        LMDZ_sed run.def config_inca none
354    else
355        echo "No coupling to chemistry model, set type_trac=lmdz in run.def"
356        LMDZ_sed run.def type_trac lmdz
357        LMDZ_sed run.def config_inca none
358    fi
359
360
361    # config.def : If running with Reprobus, desactivate ok_ade, ok_aie and read_climoz
362    if [ X${config_ListOfComponents_CHM} = Xreprobus ] || [ X${config_ListOfComponents_CHM} = Xinca ] ; then
363        LMDZ_sed config.def ok_ade n
364        LMDZ_sed config.def ok_aie n
365        LMDZ_sed config.def read_climoz 0
366    else
367        LMDZ_sed config.def ok_ade y
368        LMDZ_sed config.def ok_aie y
369        LMDZ_sed config.def read_climoz 2
370    fi
371
372    # guide.def : Activate nudging if ok_guide=y set in lmdz.card
373    if [ ! X${lmdz_UserChoices_ok_guide} = X ] ; then
374        LMDZ_sed guide.def ok_guide  ${lmdz_UserChoices_ok_guide}
375    else
376        LMDZ_sed guide.def ok_guide n
377    fi
378
379    ## Read ByPass_hgardfou_teta option in lmdz.card --> divide teta* by 2 if [ $ByPass_hgardfou_teta = 1 ]
380    ByPass_hgardfou_teta=${lmdz_UserChoices_ByPass_hgardfou_teta}
381    if [ X"${ByPass_hgardfou_teta}" = X"y" ] ; then
382        awk '{ if ($0 ~ /^teta.*=/) {split($0,a,"=") ; print a[1]"="a[2]/2"."} else print $0}' gcm.def > gcm.def.tmp
383        IGCM_sys_Mv gcm.def.tmp gcm.def
384        echo
385        IGCM_debug_Print 1 "ByPass_hgardfou_teta : ^teta*/2 in gcm.def"
386        echo
387        cat gcm.def
388        ByPass_hgardfou_teta=n
389        IGCM_card_WriteOption ${SUBMIT_DIR}/COMP/lmdz.card UserChoices ByPass_hgardfou_teta "${ByPass_hgardfou_teta}"
390    fi
391
392    ## Read ByPass_hgardfou_mats option in lmdz.card --> purmats=y 2 if [ $ByPass_hgardfou_mats = 1 ]
393    ByPass_hgardfou_mats=${lmdz_UserChoices_ByPass_hgardfou_mats}
394    if [ X"${ByPass_hgardfou_mats}" = X"y" ] ; then
395        sed -e "s/^purmats=.*/purmats=y/" gcm.def > gcm.def.tmp
396        IGCM_sys_Mv gcm.def.tmp gcm.def
397        echo
398        IGCM_debug_Print 1 "ByPass_hgardfou_mats : purmats=y in gcm.def"
399        echo
400        cat gcm.def
401        ByPass_hgardfou_mats=n
402        IGCM_card_WriteOption ${SUBMIT_DIR}/COMP/lmdz.card UserChoices ByPass_hgardfou_mats "${ByPass_hgardfou_mats}"
403    fi
404
405    if ( ${FirstInitialize} ) ; then
406        if [ -f start.nc ] && [ -f startphy.nc ] ; then
407            # The restart files already exist. They have been copied from a previous run or from a CREATE job
408            echo "Restart files for LMDZ have been copied from a previous run"
409        elif [ -f create_etat0_limit* ] || [ -f ce0l* ] && [ ! -f lmdz.x ] ; then
410            # Do nothing because it is the program for creating restart files that is running and not LMDZ
411            echo "create_etat0_limit.e will create initial start files"
412        else
413            # Restart files have to be created
414            echo "Run create_etat0_limit.e to create restart files start.nc and startphy.nc for LMDZ"
415            if [ ${DRYRUN} -le 2 ] ; then
416                ##-- suppression of ozone file construction --
417                cp config.def config.def.save
418                LMDZ_sed config.def read_climoz 0
419                IGCM_sys_Cp ${R_EXE}/create_etat0_limit.e ${RUN_DIR}/.
420                if [ ${DRYRUN} -le 1 ] ; then
421                    ${HOST_MPIRUN_COMMAND} -np 1 ./create_etat0_limit.e
422                    IGCM_sys_Put_Out start.nc    ${R_OUT_ATM_R}/${config_UserChoices_JobName}_${PeriodDateBegin}_start.nc
423                    IGCM_sys_Put_Out startphy.nc ${R_OUT_ATM_R}/${config_UserChoices_JobName}_${PeriodDateBegin}_startphy.nc
424                fi
425                IGCM_sys_Mv config.def.save config.def
426            else
427                echo "EXECUTION of ${HOST_MPIRUN_COMMAND} -np 1 ./create_etat0_limit.e simulated"
428                echo "EXECUTION of ${HOST_MPIRUN_COMMAND} -np 1 ./create_etat0_limit.e simulated for DRYRUN = " $DRYRUN >> stack
429            fi
430        fi
431    fi
432
433    IGCM_debug_PopStack "ATM_Update"
434}
435
436#-----------------------------------
437function ATM_Finalize
438{
439    IGCM_debug_PushStack "ATM_Finalize"
440
441    [ ${CumulPeriod} -le ${LMDZ_NbPeriod_adjust} ] && IGCM_sys_Put_Out Bands_${RESOL_ATM_3D}_${NUM_PROC_ATM}prc.dat ${R_OUT_ATM_D}/${config_UserChoices_JobName}_Bands_${RESOL_ATM_3D}_${NUM_PROC_ATM}prc.dat_${CumulPeriod}
442
443
444    # Add special treatement for CARBON CYCLE
445    if [ X"${lmdz_UserChoices_CARBON_CYCLE}" = X"control" ] || [ X"${lmdz_UserChoices_CARBON_CYCLE}" = X"historical" ] ; then
446        ATM_Carbon_Finalize
447    fi
448
449    echo FINALIZE ATM !
450
451    IGCM_debug_PopStack "ATM_Finalize"
452}
453
454
455
456function ATM_Carbon_Update
457{
458    # This fuction will be called only if CARBON_CYCLE is set to control or historical in lmdz.card
459
460    IGCM_debug_PushStack "ATM_Carbon_Update"
461
462    typeset InitPeriodCo2 InitDateBeginCo2 InitDateEndCo2
463    typeset CO2SBG CO2MBG CO2LU CO2_ppm CO2_ppm_prec fCO2_ff
464    typeset PathCO2log
465    typeset PreviousLinelog LastPeriodDateBegin LastPeriodDateEnd LastDatesPeriod LastPREFIX
466   
467    if ( ${FirstInitialize} && [ X"${config_ATM_Restart}" = X"n" ] ) ; then
468        ##--Initialization of fluxes to an undefined value at the first run
469        UndefinedValueCo2=-9999
470        InitPeriodCo2=0
471        InitDateBeginCo2=${UndefinedValueCo2}
472        InitYearCo2=$(( ${year} - 1 )) 
473        InitDateEndCo2=${InitYearCo2}1231
474        fCO2_ff=${UndefinedValueCo2} 
475        CO2SBG=${UndefinedValueCo2}
476        CO2LU=${UndefinedValueCo2}
477        CO2MBG=${UndefinedValueCo2}
478        CO2_ppm_prec=${UndefinedValueCo2}
479        # Get the initial value of atmosp. pco2
480        CO2_ppm=${lmdz_UserChoices_co2_init}
481       
482        IGCM_sys_Cp ${SUBMIT_DIR}/co2.log.init ${SUBMIT_DIR}/co2.log
483        IGCM_sys_Chmod u+w ${SUBMIT_DIR}/co2.log
484       
485        # Save CO2 values in ExeCpuLog variable contents 5 fields
486        echo "${InitPeriodCo2} ${InitDateBeginCo2} ${InitDateEndCo2} ${CO2_ppm} ${CO2_ppm_prec} ${fCO2_ff} ${CO2MBG} ${CO2SBG} ${CO2LU}" |   \
487            gawk '{printf("  %11d | %15s | %15s | %22.15g | %20.15g | %11.8g | %11.8g | %12.8g | %12.8g \n", \
488                              $1,$2,$3,$4,$5,$6,$7,$8,$9)}' >> ${SUBMIT_DIR}/co2.log
489       
490        # Get the path where the log file co2.log is
491        PathCO2log=${SUBMIT_DIR} 
492        # Get Previous line in co2.log
493        PreviousLinelog=$( tail -1 ${PathCO2log}/co2.log )
494       
495    else
496       
497        # NEW parameter in config.card (even for Overule all restarts, you must modify the line after this comment ):
498        # !! NEW for Carbone cycle !! Path where to find old co2.log file for restart CO2.
499        #SubmitRestartPath=
500        if ( ${FirstInitialize} && [ X"${config_ATM_Restart}" = X"y" ] ) ; then
501            IGCM_card_DefineVariableFromOption ${SUBMIT_DIR}/config.card ATM SubmitRestartPath
502            PathCO2log=${config_ATM_SubmitRestartPath}
503            Date_r=$( IGCM_date_ConvertFormatToGregorian ${config_ATM_RestartDate} )
504            PreviousLinelog=$( grep ${Date_r} ${PathCO2log}/co2.log )
505           
506            IGCM_sys_Cp ${SUBMIT_DIR}/co2.log.init ${SUBMIT_DIR}/co2.log
507            IGCM_sys_Chmod u+w ${SUBMIT_DIR}/co2.log
508           
509            # Save Last Line of control in new co2.log file
510            InitPeriodCo2=0   
511            InitDateBeginCo2=$( echo "${PreviousLinelog[*]}" | gawk -F '|' '{gsub(" ",""); print $2}' )
512            InitDateEndCo2=$( echo "${PreviousLinelog[*]}" | gawk -F '|' '{gsub(" ",""); print $3}' )
513            fCO2_ff=$( echo "${PreviousLinelog[*]}" | gawk -F '|' '{gsub(" ",""); print $6}' )
514            CO2SBG=$( echo "${PreviousLinelog[*]}" | gawk -F '|' '{gsub(" ",""); print $8}' )
515            CO2LU=$( echo "${PreviousLinelog[*]}" | gawk -F '|' '{gsub(" ",""); print $9}' )
516            CO2MBG=$( echo "${PreviousLinelog[*]}" | gawk -F '|' '{gsub(" ",""); print $7}' )
517            CO2_ppm_prec=$( echo "${PreviousLinelog[*]}" | gawk -F '|' '{gsub(" ",""); print $5}' )
518            CO2_ppm=$( echo "${PreviousLinelog[*]}" | gawk -F '|' '{gsub(" ",""); print $4}' )
519           
520            echo "${InitPeriodCo2} ${InitDateBeginCo2} ${InitDateEndCo2} ${CO2_ppm} ${CO2_ppm_prec} ${fCO2_ff} ${CO2MBG} ${CO2SBG} ${CO2LU}" |   \
521                gawk '{printf("  %11d | %15s | %15s | %22.15g | %20.15g | %11.8g | %11.8g | %12.8g | %12.8g \n", \
522                              $1,$2,$3,$4,$5,$6,$7,$8,$9)}' >> ${SUBMIT_DIR}/co2.log
523        else
524           # Get restart line in co2.log
525            PathCO2log=${SUBMIT_DIR}
526            PreviousLinelog=$( tail -1 ${PathCO2log}/co2.log )
527           # Get the value of atmosp. pco2 in co2.log
528            CO2_ppm=$( echo "${PreviousLinelog[*]}" | gawk -F '|' '{gsub(" ",""); print $4}' )
529        fi
530       
531    fi
532   
533    if [ ${lmdz_UserChoices_CARBON_CYCLE} = historical ] ; then
534            # Modify co2_ppm in config.def only for historical run
535            # If not historical run, keep co2_ppm value set earlier by LMDZ_sed
536        LMDZ_sed config.def co2_ppm     ${CO2_ppm}
537    fi
538    IGCM_debug_PopStack "ATM_Carbon_Update"
539}
540
541
542function ATM_Carbon_Finalize
543{
544    # This fuction will be called only if CARBON_CYCLE is set to control or historical in lmdz.card
545
546    IGCM_debug_PushStack "ATM_Carbon_Finalize"
547
548    typeset CO2SBG_3V CO2SBG CO2MBG CO2SRF CO2LU CO2_ppm CO2_ppm_prec fCO2_ff
549   
550        # Fossil fuel emission
551    if [ ${lmdz_UserChoices_CARBON_CYCLE} = control ] ; then
552            # For Control, no fossil fuel emission :
553        fCO2_ff=0
554        echo "Fossil Fuel for control run  :" ${fCO2_ff}
555    else
556            # For historical, get the fossile fuel file :
557        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 )
558        echo "Fossil Fuel for historical run  :" ${fCO2_ff}
559    fi
560   
561        # Get the value of ocean carbon flux
562    CO2MBG=$( ${SUBMIT_DIR}/COMP/lmdz_analyse_pisces_out.awk ocean.output )
563    CO2MBG=$( echo ${CO2MBG} | sed -e "s/ *//" )
564    echo "Ocean carbon flux  :" ${CO2MBG}
565   
566        # Get the value of land fluxes
567    set +A CO2SBG_3V -- $( ${SUBMIT_DIR}/COMP/lmdz_analyse_stomate_out.awk out_orchidee_0000 )
568    CO2SRF=$( echo ${CO2SBG_3V[0]} | sed -e "s/ *//" )
569    CO2LU=$( echo ${CO2SBG_3V[1]} | sed -e "s/ *//" )
570    CO2SBG=$( echo ${CO2SBG_3V[2]} | sed -e "s/ *//" )
571    echo "Land carbon flux (NEP)         :" ${CO2SRF}
572    echo "LU flux          (FLUC)        :" ${CO2LU}
573    echo "Total Land carbon flux (NBP)   :" ${CO2SBG}
574   
575        # Previous CO2
576    CO2_ppm_prec=$( echo "${PreviousLinelog[*]}" | gawk -F '|' '{gsub(" ",""); print $4}' )
577    echo "Previous CO2  :" ${CO2_ppm_prec}
578   
579        # Formula
580    CO2_ppm=$( echo "${CO2_ppm_prec} + (${fCO2_ff} + ${CO2MBG} + ${CO2SBG}) / 2.12" | bc -l )
581    echo "New CO2  :" ${CO2_ppm}
582   
583        # Save CO2 values in ExeCpuLog variable contents 5 fields
584    echo "${CumulPeriod} ${PeriodDateBegin} ${PeriodDateEnd} ${CO2_ppm} ${CO2_ppm_prec} ${fCO2_ff} ${CO2MBG} ${CO2SBG} ${CO2LU}" |   \
585        gawk '{printf("  %11d | %15s | %15s | %22.15g | %20.15g | %11.8g | %11.8g | %12.8g | %12.8g \n", \
586                           $1,$2,$3,$4,$5,$6,$7,$8,$9)}' >> ${SUBMIT_DIR}/co2.log
587   
588    IGCM_debug_PopStack "ATM_Carbon_Finalize"
589}
Note: See TracBrowser for help on using the repository browser.