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

Last change on this file since 2600 was 2600, checked in by jgipsl, 6 years ago

Changed to use option "IGCM_comp_modifyXmlFile nonblocker ..." for LMDZ file_def_..xml files. Changed in the corresponding files in PARAM/ the default values according to what was hard coded in lmdz.driver before (name, freq, output_level).

Add save file_def_*lmdz.xml files.

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