source: CONFIG/UNIFORM/v6/LMDZOR_v6/GENERAL/DRIVER/lmdz.driver @ 2332

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

Added modifications done in IPSLCM6.

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