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

Last change on this file since 2288 was 2288, checked in by jgipsl, 10 years ago

Updated iphysiq and nsplit_phys for NPv3.1 and NPv3.2 physics in LMDZ. Only resolution 96x95x39 and 144x142x39 is considered for now.
NPv3.1 for 96x95x39 is not changed.

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