source: CONFIG/UNIFORM/v5/LMDZOR_v5/GENERAL/DRIVER/lmdz.driver @ 1894

Last change on this file since 1894 was 1894, checked in by jgipsl, 12 years ago

Type error in last commit.

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