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

Last change on this file since 2315 was 2315, checked in by sdipsl, 7 years ago

Stack was corrupted. Fix needed for bigbrother

File size: 30.5 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 and modify config.def
282    if [ -f SOLARANDVOLCANOES.txt ] ; then
283        IPCC_SOLAR=`grep Annee_${year} SOLARANDVOLCANOES.txt | awk -F= '{print $2}'`
284        LMDZ_sed config.def solaire     ${IPCC_SOLAR}
285    else
286        LMDZ_sed_default config.def solaire
287    fi
288    if [ -f CO2.txt ] ; then
289        IPCC_CO2=`grep Annee_${year} CO2.txt | awk -F= '{print $2}'`
290        LMDZ_sed config.def co2_ppm     ${IPCC_CO2}
291    else
292        LMDZ_sed_default config.def co2_ppm
293    fi
294
295
296    if [ -f CH4.txt ] ; then
297        IPCC_CH4=`grep Annee_${year} CH4.txt | awk -F= '{print $2}'`
298        LMDZ_sed config.def CH4_ppb     ${IPCC_CH4}
299    else
300        LMDZ_sed_default config.def CH4_ppb
301    fi
302    if [ -f N2O.txt ] ; then
303        IPCC_N2O=`grep Annee_${year} N2O.txt | awk -F= '{print $2}'`
304        LMDZ_sed config.def N2O_ppb     ${IPCC_N2O}
305    else
306        LMDZ_sed_default config.def N2O_ppb
307    fi
308    if [ -f CFC11.txt ] ; then
309        IPCC_CFC11=`grep Annee_${year} CFC11.txt | awk -F= '{print $2}'`
310        LMDZ_sed config.def CFC11_ppt   ${IPCC_CFC11}
311    else
312        LMDZ_sed_default config.def CFC11_ppt
313    fi
314    if [ -f CFC12.txt ] ; then
315        IPCC_CFC12=`grep Annee_${year} CFC12.txt | awk -F= '{print $2}'`
316        LMDZ_sed config.def CFC12_ppt   ${IPCC_CFC12}
317    else
318        LMDZ_sed_default config.def CFC12_ppt
319    fi
320
321    ## Coupling Time Step
322    LMDZ_t_coupl=${oasis_UserChoices_FreqCoupling:-${lmdz_UserChoices_t_coupl}}
323    IGCM_debug_Print 3 "LMDZ_t_coupl "   ${LMDZ_t_coupl}
324    LMDZ_sed config.def t_coupl   ${LMDZ_t_coupl}
325
326    ##-- Add special treatement for CARBON CYCLE
327    if [ X"${lmdz_UserChoices_CARBON_CYCLE}" = X"control" ] || [ X"${lmdz_UserChoices_CARBON_CYCLE}" = X"historical" ] ; then
328        ATM_Carbon_Update
329    fi
330
331
332    ##-- Set LMDZ_COSP_daily1979=y in section UserChoices in lmdz.card to activate
333    ##   COSP daily output for years 1979 and later (mandatory for historical CMIP5 run).
334    if ([ X"${lmdz_UserChoices_LMDZ_COSP_daily1979}" = X"y" ] &&  [ ${year} -ge 1979 ]) ; then
335        LMDZ_COSP_daily=y
336    fi
337
338
339    ## output.def parameters
340    #  columns in phys_output_filekeys refer to the filenames given in phys_out_filenames in output.def : 
341    #                                            histmth       histday        histhf    histfh3h   histhf3hm   histstn
342    LMDZ_sed output.def phys_out_filekeys       "${ok_mensuel} ${ok_journe}   ${ok_hf}  ${ok_hf3h} ${ok_hf3hm} ${ok_stn}"
343    LMDZ_sed output.def ecrit_ISCCP ${LMDZ_ecrit_ISCCP}
344    LMDZ_sed output.def ok_cosp     ${LMDZ_COSP_OK}
345    LMDZ_sed output.def ok_mensuelCOSP  ${LMDZ_COSP_monthly}
346    LMDZ_sed output.def ok_journeCOSP   ${LMDZ_COSP_daily}
347    LMDZ_sed output.def ok_hfCOSP   ${LMDZ_COSP_hf}
348    LMDZ_sed output.def ok_histNMC  "${LMDZ_NMC_monthly} ${LMDZ_NMC_daily} ${LMDZ_NMC_hf}"
349
350    # XIOS XML definition
351    # Default init : files are desactivated
352        LMDZ_sed_xml file_def_histmth_lmdz.xml histmth enabled .FALSE.
353        LMDZ_sed_xml file_def_histday_lmdz.xml histday enabled .FALSE.
354        LMDZ_sed_xml file_def_histhf_lmdz.xml histhf enabled .FALSE.
355        LMDZ_sed_xml file_def_histfh3h_lmdz.xml histfh3h enabled .FALSE.
356        LMDZ_sed_xml file_def_histhf3hm_lmdz.xml histfh3hm enabled .FALSE.
357        LMDZ_sed_xml file_def_histstn_lmdz.xml histstn enabled .FALSE.
358        LMDZ_sed_xml file_def_histmthNMC_lmdz.xml histmthNMC enabled .FALSE.
359        LMDZ_sed_xml file_def_histdayNMC_lmdz.xml histdayNMC enabled .FALSE.
360        LMDZ_sed_xml file_def_histhfNMC_lmdz.xml histhfNMC enabled .FALSE.
361        if [ X${lmdz_UserChoices_XIOS}  = Xy ] ; then
362    # Default output level : 5
363            LMDZ_sed_xml file_def_histmth_lmdz.xml histmth output_level 5
364            LMDZ_sed_xml file_def_histday_lmdz.xml histday output_level 5
365            LMDZ_sed_xml file_def_histhf_lmdz.xml histhf output_level 5
366            LMDZ_sed_xml file_def_histfh3h_lmdz.xml histfh3h output_level 5
367            LMDZ_sed_xml file_def_histhf3hm_lmdz.xml histfh3hm output_level 5
368            LMDZ_sed_xml file_def_histstn_lmdz.xml histstn output_level 5
369            LMDZ_sed_xml file_def_histmthNMC_lmdz.xml histmthNMC output_level 5
370            LMDZ_sed_xml file_def_histdayNMC_lmdz.xml histdayNMC output_level 5
371            LMDZ_sed_xml file_def_histhfNMC_lmdz.xml histhfNMC output_level 5
372     # Filling of XML files
373        if [ X${ok_mensuel} = Xy ] ; then
374            LMDZ_sed_xml file_def_histmth_lmdz.xml histmth enabled .TRUE.
375            LMDZ_sed_xml file_def_histmth_lmdz.xml histmth output_freq 1mo
376            LMDZ_sed_xml file_def_histmth_lmdz.xml histmth name histmth
377        fi
378        if [ X${ok_journe} = Xy ] ; then       
379            LMDZ_sed_xml file_def_histday_lmdz.xml histday enabled .TRUE.
380            LMDZ_sed_xml file_def_histday_lmdz.xml histday output_freq 1d
381            LMDZ_sed_xml file_def_histday_lmdz.xml histday name histday
382            if [ X${OutLevel} = Xlow ] || [ X${OutLevel} = Xmedium ] ; then
383                LMDZ_sed_xml file_def_histday_lmdz.xml histday output_level 2
384            fi
385        fi
386        if [ X${ok_hf} = Xy ] ; then
387            LMDZ_sed_xml file_def_histhf_lmdz.xml histhf enabled .TRUE.
388            LMDZ_sed_xml file_def_histhf_lmdz.xml histhf output_freq 6h
389            LMDZ_sed_xml file_def_histhf_lmdz.xml histhf name histhf
390            if [ X${OutLevel} = Xlow ] ; then
391                LMDZ_sed_xml file_def_histhf_lmdz.xml histhf output_level 2
392            fi
393        fi     
394        if [ X${ok_hf3h} = Xy ] ; then
395            LMDZ_sed_xml file_def_histhf3h_lmdz.xml histhf3h enabled .TRUE.
396            LMDZ_sed_xml file_def_histhf3h_lmdz.xml histhf3h output_freq 3h
397            LMDZ_sed_xml file_def_histhf3h_lmdz.xml histhf3h name histhf3h
398        fi     
399        if [ X${ok_hf3hm} = Xy ] ; then
400            LMDZ_sed_xml file_def_histhf3hm_lmdz.xml histhf3hm enabled .TRUE.
401            LMDZ_sed_xml file_def_histhf3hm_lmdz.xml histhf3hm output_freq 3h
402            LMDZ_sed_xml file_def_histhf3hm_lmdz.xml histhf3hm name histhf3hm
403        fi
404        if [ X${ok_stn} = Xy ] ; then
405            LMDZ_sed_xml file_def_histstn_lmdz.xml histstn enabled .TRUE.
406            LMDZ_sed_xml file_def_histstn_lmdz.xml histstn output_freq 1800s
407            LMDZ_sed_xml file_def_histstn_lmdz.xml histstn name histstn
408        fi
409        if [ X${LMDZ_NMC_monthly} = Xy ] ; then
410            LMDZ_sed_xml file_def_histmthNMC_lmdz.xml histmthNMC enabled .TRUE.
411            LMDZ_sed_xml file_def_histmthNMC_lmdz.xml histmthNMC output_freq 1mo
412            LMDZ_sed_xml file_def_histmthNMC_lmdz.xml histmthNMC name histmthNMC
413        fi
414        if [ X${LMDZ_NMC_daily} = Xy ] ; then
415            LMDZ_sed_xml file_def_histdayNMC_lmdz.xml histdayNMC enabled .TRUE.
416            LMDZ_sed_xml file_def_histdayNMC_lmdz.xml histdayNMC output_freq 1d
417            LMDZ_sed_xml file_def_histdayNMC_lmdz.xml histdayNMC name histdayNMC
418        fi
419        if [ X${LMDZ_NMC_hf} = Xy ] ; then
420            LMDZ_sed_xml file_def_histhfNMC_lmdz.xml histhfNMC enabled .TRUE.
421            LMDZ_sed_xml file_def_histhfNMC_lmdz.xml histhfNMC output_freq 6h
422            LMDZ_sed_xml file_def_histhfNMC_lmdz.xml histhfNMC name histhfNMC
423        fi
424    fi
425
426    ## gcm.def parameters :
427    # Modification only for new physics
428    if [ X${LMDZ_Physics} = X"AP" ] ; then
429        LMDZ_sed gcm.def iphysiq     10
430    else
431        LMDZ_sed_default gcm.def iphysiq
432    fi
433
434
435    ## run.def parameters
436    LMDZ_sed run.def dayref   ${InitDay}
437    LMDZ_sed run.def nday     ${PeriodLengthInDays}
438    LMDZ_sed run.def raz_date ${RAZ_DATE}
439    LMDZ_sed run.def periodav ${LMDZ_periodav}
440    LMDZ_sed run.def adjust   ${LMDZ_adjust}
441
442    # Set anneeref different for gcm and ce0l
443    # Variable calend is different for a run with create_etat0_limit and the gcm
444    # Test if executable create_etat0_limit is present and lmdz.x is not present
445    if [ -f create_etat0_limit* ] || [ -f ce0l* ] && [ ! -f lmdz.x ] ; then
446        # for case ce0l : always take current year
447        LMDZ_sed run.def anneeref ${year}
448        LMDZ_sed run.def calend   ${CalendarTypeForCreate}
449    else
450        # for case gcm : take first year of simulation
451        LMDZ_sed run.def anneeref ${InitYear}
452        LMDZ_sed run.def calend   ${CalendarTypeForLmdz}
453    fi
454
455    # Activate creation of file grilles_gcm.nc only at first period
456    if [ ${CumulPeriod} -eq 1 ] ; then
457        LMDZ_sed run.def grilles_gcm_netcdf y
458    else
459        LMDZ_sed run.def grilles_gcm_netcdf n
460    fi
461
462    ## Determine from the variable ListOfComponents in config.card coupling to external models
463    ## and set corresponding parameters in run.def
464    echo ListOfComponents now running : ${config_ListOfComponents[*]}
465
466    if [ X${config_ListOfComponents_SRF} = Xorchidee ] ; then
467        echo "Activate ORCHIDEE, set VEGET=y in run.def"
468        LMDZ_sed run.def VEGET y
469    else
470        echo "No ORCHIDEE, set VEGET=n in run.def"
471        LMDZ_sed run.def VEGET n
472    fi
473
474    if [ X${config_ListOfComponents_CPL} = Xoasis ] ; then
475        echo "Activate coupling to ocean, set type_ocean=couple in run.def"
476        LMDZ_sed run.def type_ocean couple
477    else
478        echo "LMDZ is running in forced mode without ocean model, set type_ocean=force in run.def"
479        LMDZ_sed run.def type_ocean force
480    fi
481
482    if [ X${config_ListOfComponents_CHM} = Xinca ] ; then
483        echo "Activate coupling to INCA, set type_trac=inca in run.def"
484        LMDZ_sed run.def type_trac inca
485    elif [ X${config_ListOfComponents_CHM} = Xreprobus ] ; then
486        echo "Activate coupling to REPROBUS, set type_trac=repr in run.def"
487        LMDZ_sed run.def type_trac repr
488        LMDZ_sed run.def config_inca none
489    else
490        echo "No coupling to chemistry model, set type_trac=lmdz in run.def"
491        LMDZ_sed run.def type_trac lmdz
492        LMDZ_sed run.def config_inca none
493    fi
494
495
496    # config.def : Activate direct radiative effect if ok_ade=y
497    if [ ! X${lmdz_UserChoices_ok_ade} = X ]; then
498        LMDZ_sed config.def ok_ade ${lmdz_UserChoices_ok_ade}
499    else
500        LMDZ_sed config.def ok_ade n
501    fi 
502
503    # config.def : Activate indirect radiative effect if ok_aie=y
504    if [ ! X${lmdz_UserChoices_ok_aie} = X ]; then
505        LMDZ_sed config.def ok_aie ${lmdz_UserChoices_ok_aie}
506    else
507        LMDZ_sed config.def ok_aie n
508    fi 
509
510    # config.def : Activate online aerosol coupled model if aerosol_couple=y
511    if [ ! X${lmdz_UserChoices_aerosol_couple} = X ]; then
512        LMDZ_sed config.def aerosol_couple ${lmdz_UserChoices_aerosol_couple}
513    else
514        LMDZ_sed config.def aerosol_couple n
515    fi 
516
517    # config.def : Activate reading of ozone in climatology if read_climoz=2
518    if [ ! X${lmdz_UserChoices_read_climoz} = X ]; then
519        LMDZ_sed config.def read_climoz ${lmdz_UserChoices_read_climoz}
520    else
521        LMDZ_sed config.def read_climoz 0       
522    fi 
523
524    # config.def : Choose aerosol use in radiative effect
525    #  type of coupled aerosol =1 (default) =2 => bc  only =3 => pom only =4 => seasalt only
526    # =5 => dust only =6 => all aerosol   
527    if [ ! X${lmdz_UserChoices_flag_aerosol} = X ]; then
528        LMDZ_sed config.def flag_aerosol ${lmdz_UserChoices_flag_aerosol}
529    else
530        LMDZ_sed config.def flag_aerosol 0
531    fi 
532
533    # config.def : Activate calcul of Cloud droplet number concentration if ok_cdnc=y
534    if [ ! X${lmdz_UserChoices_ok_cdnc} = X ]; then
535        LMDZ_sed config.def ok_cdnc ${lmdz_UserChoices_ok_cdnc}
536    else
537        LMDZ_sed config.def ok_cdnc n   
538    fi 
539
540    # guide.def : Activate nudging if ok_guide=y set in lmdz.card
541    if [ ! X${lmdz_UserChoices_ok_guide} = X ] ; then
542        LMDZ_sed guide.def ok_guide  ${lmdz_UserChoices_ok_guide}
543    else
544        LMDZ_sed guide.def ok_guide n
545    fi
546
547    ## Read ByPass_hgardfou_teta option in lmdz.card --> divide teta* by 2 if [ $ByPass_hgardfou_teta = 1 ]
548    ByPass_hgardfou_teta=${lmdz_UserChoices_ByPass_hgardfou_teta}
549    if [ X"${ByPass_hgardfou_teta}" = X"y" ] ; then
550        awk '{ if ($0 ~ /^teta.*=/) {split($0,a,"=") ; print a[1]"="a[2]/2"."} else print $0}' gcm.def > gcm.def.tmp
551        IGCM_sys_Mv gcm.def.tmp gcm.def
552        echo
553        IGCM_debug_Print 1 "ByPass_hgardfou_teta : ^teta*/2 in gcm.def"
554        echo
555        cat gcm.def
556        ByPass_hgardfou_teta=n
557        IGCM_card_WriteOption ${SUBMIT_DIR}/COMP/lmdz.card UserChoices ByPass_hgardfou_teta "${ByPass_hgardfou_teta}"
558    fi
559
560    ## Read ByPass_hgardfou_mats option in lmdz.card --> purmats=y 2 if [ $ByPass_hgardfou_mats = 1 ]
561    ByPass_hgardfou_mats=${lmdz_UserChoices_ByPass_hgardfou_mats}
562    if [ X"${ByPass_hgardfou_mats}" = X"y" ] ; then
563        sed -e "s/^purmats=.*/purmats=y/" gcm.def > gcm.def.tmp
564        IGCM_sys_Mv gcm.def.tmp gcm.def
565        echo
566        IGCM_debug_Print 1 "ByPass_hgardfou_mats : purmats=y in gcm.def"
567        echo
568        cat gcm.def
569        ByPass_hgardfou_mats=n
570        IGCM_card_WriteOption ${SUBMIT_DIR}/COMP/lmdz.card UserChoices ByPass_hgardfou_mats "${ByPass_hgardfou_mats}"
571    fi
572
573    if ( ${FirstInitialize} ) ; then
574        if [ -f start.nc ] && [ -f startphy.nc ] ; then
575            # The restart files already exist. They have been copied from a previous run or from a CREATE job
576            echo "Restart files for LMDZ have been copied from a previous run"
577        elif [ -f create_etat0_limit* ] || [ -f ce0l* ] && [ ! -f lmdz.x ] ; then
578            # Do nothing because it is the program for creating restart files that is running and not LMDZ
579            echo "create_etat0_limit.e will create initial start files"
580        else
581            # Restart files have to be created
582            echo "Run create_etat0_limit.e to create restart files start.nc and startphy.nc for LMDZ"
583            if [ ${DRYRUN} -le 2 ] ; then
584                ##-- suppression of ozone file construction --
585                cp config.def config.def.save
586                LMDZ_sed config.def read_climoz 0
587                IGCM_sys_Cp ${R_EXE}/create_etat0_limit.e ${RUN_DIR}/.
588                if [ ${DRYRUN} -le 1 ] ; then
589                    ${HOST_MPIRUN_COMMAND} -np 1 ./create_etat0_limit.e
590                    IGCM_sys_Put_Out start.nc    ${R_OUT_ATM_R}/${config_UserChoices_JobName}_${PeriodDateBegin}_start.nc
591                    IGCM_sys_Put_Out startphy.nc ${R_OUT_ATM_R}/${config_UserChoices_JobName}_${PeriodDateBegin}_startphy.nc
592                fi
593                IGCM_sys_Mv config.def.save config.def
594            else
595                echo "EXECUTION of ${HOST_MPIRUN_COMMAND} -np 1 ./create_etat0_limit.e simulated"
596                echo "EXECUTION of ${HOST_MPIRUN_COMMAND} -np 1 ./create_etat0_limit.e simulated for DRYRUN = " $DRYRUN >> stack
597            fi
598        fi
599    fi
600
601    if [ X${lmdz_UserChoices_XIOS}  = Xy ] ; then
602    # Add include of LMDZ context in iodef.xml
603    # In iodef.xml add on next line after "COMPONENT CONTEXT"
604    #  <context id="LMDZ" src="./context_lmdz.xml"/>
605        echo '<context id="LMDZ" src="./context_lmdz.xml"/>' > add.tmp
606        cp iodef.xml iodef.xml.tmp
607        sed -e "/COMPONENT CONTEXT/r add.tmp" \
608            iodef.xml.tmp > iodef.xml
609        rm iodef.xml.tmp add.tmp
610    fi
611   
612    IGCM_debug_PopStack "ATM_Update"
613}
614
615#-----------------------------------
616function ATM_Finalize
617{
618    IGCM_debug_PushStack "ATM_Finalize"
619
620    # If the file exist, copy Bands_ file to PARAM/ in submit directory. This file will be used for the simulation.
621    # Copy also the same file into ATM/Restart at ARCHIVE directory for backup.
622    if [ -f Bands_${RESOL_ATM_3D}_${NUM_PROC_ATM}prc.dat ] ; then
623      if [ ${CumulPeriod} -le ${LMDZ_NbPeriod_adjust} ] ; then
624        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}
625        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}
626      elif [ ${CumulPeriod} -eq 1 ] && [ ${LMDZ_NbPeriod_adjust} -eq 0 ] ; then
627        # Special case : first period and no adjust => Save bands file with suffix _0
628        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
629        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
630      fi
631    fi
632
633    # Add special treatement for CARBON CYCLE
634    if [ X"${lmdz_UserChoices_CARBON_CYCLE}" = X"control" ] || [ X"${lmdz_UserChoices_CARBON_CYCLE}" = X"historical" ] ; then
635        ATM_Carbon_Finalize
636    fi
637
638    echo FINALIZE ATM !
639
640    IGCM_debug_PopStack "ATM_Finalize"
641}
642
643
644
645function ATM_Carbon_Update
646{
647    # This fuction will be called only if CARBON_CYCLE is set to control or historical in lmdz.card
648
649    IGCM_debug_PushStack "ATM_Carbon_Update"
650
651    typeset InitPeriodCo2 InitDateBeginCo2 InitDateEndCo2
652    typeset CO2SBG CO2MBG CO2LU CO2_ppm CO2_ppm_prec fCO2_ff
653    typeset PathCO2log
654    typeset PreviousLinelog LastPeriodDateBegin LastPeriodDateEnd LastDatesPeriod LastPREFIX
655   
656    if ( ${FirstInitialize} && [ X"${config_ATM_Restart}" = X"n" ] ) ; then
657        ##--Initialization of fluxes to an undefined value at the first run
658        UndefinedValueCo2=-9999
659        InitPeriodCo2=0
660        InitDateBeginCo2=${UndefinedValueCo2}
661        InitYearCo2=$(( ${year} - 1 )) 
662        InitDateEndCo2=${InitYearCo2}1231
663        fCO2_ff=${UndefinedValueCo2} 
664        CO2SBG=${UndefinedValueCo2}
665        CO2LU=${UndefinedValueCo2}
666        CO2MBG=${UndefinedValueCo2}
667        CO2_ppm_prec=${UndefinedValueCo2}
668        # Get the initial value of atmosp. pco2
669        CO2_ppm=${lmdz_UserChoices_co2_init}
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 CO2 values in ExeCpuLog variable contents 5 fields
675        echo "${InitPeriodCo2} ${InitDateBeginCo2} ${InitDateEndCo2} ${CO2_ppm} ${CO2_ppm_prec} ${fCO2_ff} ${CO2MBG} ${CO2SBG} ${CO2LU}" |   \
676            gawk '{printf("  %11d | %15s | %15s | %22.15g | %20.15g | %11.8g | %11.8g | %12.8g | %12.8g \n", \
677                              $1,$2,$3,$4,$5,$6,$7,$8,$9)}' >> ${SUBMIT_DIR}/co2.log
678       
679        # Get the path where the log file co2.log is
680        PathCO2log=${SUBMIT_DIR} 
681        # Get Previous line in co2.log
682        PreviousLinelog=$( tail -1 ${PathCO2log}/co2.log )
683       
684    else
685       
686        # NEW parameter in config.card (even for Overule all restarts, you must modify the line after this comment ):
687        # !! NEW for Carbone cycle !! Path where to find old co2.log file for restart CO2.
688        #SubmitRestartPath=
689        if ( ${FirstInitialize} && [ X"${config_ATM_Restart}" = X"y" ] ) ; then
690            IGCM_card_DefineVariableFromOption ${SUBMIT_DIR}/config.card ATM SubmitRestartPath
691            PathCO2log=${config_ATM_SubmitRestartPath}
692            Date_r=$( IGCM_date_ConvertFormatToGregorian ${config_ATM_RestartDate} )
693            PreviousLinelog=$( grep ${Date_r} ${PathCO2log}/co2.log )
694           
695            IGCM_sys_Cp ${SUBMIT_DIR}/co2.log.init ${SUBMIT_DIR}/co2.log
696            IGCM_sys_Chmod u+w ${SUBMIT_DIR}/co2.log
697           
698            # Save Last Line of control in new co2.log file
699            InitPeriodCo2=0   
700            InitDateBeginCo2=$( echo "${PreviousLinelog[*]}" | gawk -F '|' '{gsub(" ",""); print $2}' )
701            InitDateEndCo2=$( echo "${PreviousLinelog[*]}" | gawk -F '|' '{gsub(" ",""); print $3}' )
702            fCO2_ff=$( echo "${PreviousLinelog[*]}" | gawk -F '|' '{gsub(" ",""); print $6}' )
703            CO2SBG=$( echo "${PreviousLinelog[*]}" | gawk -F '|' '{gsub(" ",""); print $8}' )
704            CO2LU=$( echo "${PreviousLinelog[*]}" | gawk -F '|' '{gsub(" ",""); print $9}' )
705            CO2MBG=$( echo "${PreviousLinelog[*]}" | gawk -F '|' '{gsub(" ",""); print $7}' )
706            CO2_ppm_prec=$( echo "${PreviousLinelog[*]}" | gawk -F '|' '{gsub(" ",""); print $5}' )
707            CO2_ppm=$( echo "${PreviousLinelog[*]}" | gawk -F '|' '{gsub(" ",""); print $4}' )
708           
709            echo "${InitPeriodCo2} ${InitDateBeginCo2} ${InitDateEndCo2} ${CO2_ppm} ${CO2_ppm_prec} ${fCO2_ff} ${CO2MBG} ${CO2SBG} ${CO2LU}" |   \
710                gawk '{printf("  %11d | %15s | %15s | %22.15g | %20.15g | %11.8g | %11.8g | %12.8g | %12.8g \n", \
711                              $1,$2,$3,$4,$5,$6,$7,$8,$9)}' >> ${SUBMIT_DIR}/co2.log
712        else
713           # Get restart line in co2.log
714            PathCO2log=${SUBMIT_DIR}
715            PreviousLinelog=$( tail -1 ${PathCO2log}/co2.log )
716           # Get the value of atmosp. pco2 in co2.log
717            CO2_ppm=$( echo "${PreviousLinelog[*]}" | gawk -F '|' '{gsub(" ",""); print $4}' )
718        fi
719       
720    fi
721   
722    if [ ${lmdz_UserChoices_CARBON_CYCLE} = historical ] ; then
723            # Modify co2_ppm in config.def only for historical run
724            # If not historical run, keep co2_ppm value set earlier by LMDZ_sed
725        LMDZ_sed config.def co2_ppm     ${CO2_ppm}
726    fi
727    IGCM_debug_PopStack "ATM_Carbon_Update"
728}
729
730
731function ATM_Carbon_Finalize
732{
733    # This fuction will be called only if CARBON_CYCLE is set to control or historical in lmdz.card
734
735    IGCM_debug_PushStack "ATM_Carbon_Finalize"
736
737    typeset CO2SBG_3V CO2SBG CO2MBG CO2SRF CO2LU CO2_ppm CO2_ppm_prec fCO2_ff
738   
739        # Fossil fuel emission
740    if [ ${lmdz_UserChoices_CARBON_CYCLE} = control ] ; then
741            # For Control, no fossil fuel emission :
742        fCO2_ff=0
743        echo "Fossil Fuel for control run  :" ${fCO2_ff}
744    else
745            # For historical, get the fossile fuel file :
746        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 )
747        echo "Fossil Fuel for historical run  :" ${fCO2_ff}
748    fi
749   
750        # Get the value of ocean carbon flux
751    CO2MBG=$( ${SUBMIT_DIR}/COMP/lmdz_analyse_pisces_out.awk ocean.output )
752    CO2MBG=$( echo ${CO2MBG} | sed -e "s/ *//" )
753    echo "Ocean carbon flux  :" ${CO2MBG}
754   
755        # Get the value of land fluxes
756    set +A CO2SBG_3V -- $( ${SUBMIT_DIR}/COMP/lmdz_analyse_stomate_out.awk out_orchidee_0000 )
757    CO2SRF=$( echo ${CO2SBG_3V[0]} | sed -e "s/ *//" )
758    CO2LU=$( echo ${CO2SBG_3V[1]} | sed -e "s/ *//" )
759    CO2SBG=$( echo ${CO2SBG_3V[2]} | sed -e "s/ *//" )
760    echo "Land carbon flux (NEP)         :" ${CO2SRF}
761    echo "LU flux          (FLUC)        :" ${CO2LU}
762    echo "Total Land carbon flux (NBP)   :" ${CO2SBG}
763   
764        # Previous CO2
765    CO2_ppm_prec=$( echo "${PreviousLinelog[*]}" | gawk -F '|' '{gsub(" ",""); print $4}' )
766    echo "Previous CO2  :" ${CO2_ppm_prec}
767   
768        # Formula
769    CO2_ppm=$( echo "${CO2_ppm_prec} + (${fCO2_ff} + ${CO2MBG} + ${CO2SBG}) / 2.12" | bc -l )
770    echo "New CO2  :" ${CO2_ppm}
771   
772        # Save CO2 values in ExeCpuLog variable contents 5 fields
773    echo "${CumulPeriod} ${PeriodDateBegin} ${PeriodDateEnd} ${CO2_ppm} ${CO2_ppm_prec} ${fCO2_ff} ${CO2MBG} ${CO2SBG} ${CO2LU}" |   \
774        gawk '{printf("  %11d | %15s | %15s | %22.15g | %20.15g | %11.8g | %11.8g | %12.8g | %12.8g \n", \
775                           $1,$2,$3,$4,$5,$6,$7,$8,$9)}' >> ${SUBMIT_DIR}/co2.log
776   
777    IGCM_debug_PopStack "ATM_Carbon_Finalize"
778}
Note: See TracBrowser for help on using the repository browser.