source: CONFIG/UNIFORM/v6/IPSLCM6/GENERAL/DRIVER/lmdz.driver @ 2275

Last change on this file since 2275 was 2275, checked in by omamce, 10 years ago

O.M. : managing coupling frequency

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