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

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