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

Last change on this file since 2333 was 2333, checked in by jgipsl, 8 years ago

Update to use IGCM_comp_modifyDefFile instead of local functions LMDZ_sed/LMDZ_sed_default/ORCHIDEE_sed.

Now this configuration must be used with libIGCM trunk rev 1073 or more recent.

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