source: CMIP5/esmControl/CpiControl1/COMP/lmdz.driver @ 1727

Last change on this file since 1727 was 1353, checked in by cetlod, 13 years ago

Registration of used configuration files for CpiControl1

File size: 13.7 KB
Line 
1#!/bin/ksh
2#-----------------------------------------------------------------
3function LMDZ_sed
4{
5    IGCM_debug_PushStack "LMDZ_sed"
6
7    sed -e "s/^${2}\ *=.*/${2}= ${3}/" ${1} > ${1}.tmp
8    RET=$?
9    echo "LMDZ_sed : ${1} ${2} ${3}"
10    \mv ${1}.tmp ${1}
11
12    IGCM_debug_PopStack "LMDZ_sed"
13    return $RET
14}
15
16function ATM_Initialize
17{
18    IGCM_debug_PushStack "ATM_Initialize"
19
20    RESOL_ATM=$( echo $RESOL | awk "-Fx" '{print $2}' | awk "-F-" '{print $1}')
21
22    [ -f ${SUBMIT_DIR}/../.resol ] && eval $(grep RESOL_ATM_3D ${SUBMIT_DIR}/../.resol) || RESOL_ATM_3D=96x95x19
23
24    RESOL_ATM_Z=$( echo ${RESOL_ATM_3D} | awk "-Fx" '{print $3}' )
25
26    ##-- Calendar type for LMDZ
27    case ${config_UserChoices_CalendarType} in
28        leap|gregorian)
29            CalendarTypeForLmdz=earth_366d;;
30        noleap)
31            CalendarTypeForLmdz=earth_365d;;
32        360d)
33            CalendarTypeForLmdz=earth_360d;;
34        *)
35            CalendarTypeForLmdz=earth_360d
36    esac
37
38    ##--Frequency purpose ....
39    ##--  Initialisation  ....
40    OK_instan=n
41    OK_journe=n
42    OK_mensuel=n
43    ok_hf=n
44
45    case ${config_UserChoices_PeriodLength} in
46        1Y|1y|1M|1m) OK_mensuel=y ;;
47        5D|5d|1D|1d) OK_journe=y ;;
48    esac
49
50    for frequency in ${config_ATM_WriteFrequency} ; do
51        case ${frequency} in
52            5D|5d|1D|1d) OK_journe=y ;;
53        esac
54        case ${frequency} in
55            HF|hf) ok_hf=y ;;
56        esac
57    done
58
59    ## Read LMDZ_NbPeriod_adjust option in lmdz.card
60    IGCM_card_DefineVariableFromOption ${SUBMIT_DIR}/COMP/lmdz.card UserChoices LMDZ_NbPeriod_adjust
61    LMDZ_NbPeriod_adjust=${lmdz_UserChoices_LMDZ_NbPeriod_adjust}
62
63    if [ ${LMDZ_NbPeriod_adjust} -eq 0 ] ; then
64        IGCM_card_DefineVariableFromOption ${SUBMIT_DIR}/COMP/lmdz.card UserChoices LMDZ_Bands_file_name
65        LMDZ_Bands_file_name=${lmdz_UserChoices_LMDZ_Bands_file_name}
66    fi
67
68    ##  Read LMDZ_Freq_aero and LMDZ_Length_aero in lmdz.card
69    LMDZ_Freq_aero=${lmdz_UserChoices_LMDZ_Freq_aero}
70    LMDZ_Length_aero=${lmdz_UserChoices_LMDZ_Length_aero}
71
72    ##  Read LMDZ_COSP_monthly  LMDZ_COSP_daily and LMDZ_COSP_hf in lmdz.card
73    LMDZ_COSP_OK=${lmdz_UserChoices_LMDZ_COSP_OK}
74    LMDZ_COSP_monthly=${lmdz_UserChoices_LMDZ_COSP_monthly}
75    LMDZ_COSP_daily=${lmdz_UserChoices_LMDZ_COSP_daily}
76    LMDZ_COSP_hf=${lmdz_UserChoices_LMDZ_COSP_hf}
77
78    ##  Read LMDZ_NMC_monthly  LMDZ_NMC_daily and LMDZ_NMC_hf in lmdz.card
79    LMDZ_NMC_monthly=${lmdz_UserChoices_LMDZ_NMC_monthly}
80    LMDZ_NMC_daily=${lmdz_UserChoices_LMDZ_NMC_daily}
81    LMDZ_NMC_hf=${lmdz_UserChoices_LMDZ_NMC_hf}
82
83    IGCM_debug_PopStack "ATM_Initialize"
84}
85
86#-----------------------------------------------------------------
87function ATM_Update
88{
89    IGCM_debug_PushStack "ATM_Update"
90
91    typeset CO2SBG CO2MBG CO2LU CO2_ppm CO2_ppm_prec fCO2_ff
92    typeset PreviousLinelog LastPeriodDateBegin LastPeriodDateEnd LastDatesPeriod LastPREFIX
93
94    case ${config_UserChoices_PeriodLength} in
95        *Y|*y) 
96               LMDZ_ecrit_mth=30.
97               LMDZ_ecrit_ISCCP=30.
98               LMDZ_periodav=30.
99               if [ "${config_UserChoices_CalendarType}" != "360d" ] ; then
100                  echo Change calendartype in config.card. PeriodLength=1Y allowed only for CalendarType=360d
101                  exit
102               fi
103               ;;
104        *)
105               LMDZ_ecrit_mth=${PeriodLengthInDays}.
106               LMDZ_ecrit_ISCCP=${PeriodLengthInDays}.
107               LMDZ_periodav=${PeriodLengthInDays}.
108               ;;
109    esac
110
111    ##-- Remise ou non a zero de la date initiale de LMDZ pour le fichier run.def
112    if [ ${CumulPeriod} -eq 1 ] ; then
113        RAZ_DATE=1
114    else
115        RAZ_DATE=0
116    fi
117
118    ## algo : For CumulPeriod=1 ;
119    ##        IF NbPeriod_Adjust = 0, Get Bands file directly from server, store it with _0 suffix
120    ##        ELSE LMDZ_adjust=y ; save Bands file on file server ;
121    ##        For CumulPeriod=2 to LMDZ_NbPeriod_adjust ; Get Bands file from server (CumulPeriod-1) ; LMDZ_adjust=y ; save Bands file on file server ;
122    ##        For CumulPeriod > LMDZ_NbPeriod_adjust ; LMDZ_adjust=n ; Get Bands file from server (CumulPeriod=LMDZ_NbPeriod_adjust 0 to force it) ; Use Bands ;
123
124    if [ ${CumulPeriod} -eq 1 ] ; then
125        if [ ${LMDZ_NbPeriod_adjust} -eq 0 ] ; then
126            IGCM_sys_Get ${LMDZ_Bands_file_name} Bands_${RESOL_ATM_3D}_${NUM_PROC_ATM}prc.dat ; IGCM_sys_Chmod u+w Bands_${RESOL_ATM_3D}_${NUM_PROC_ATM}prc.dat
127            IGCM_sys_Put_Out Bands_${RESOL_ATM_3D}_${NUM_PROC_ATM}prc.dat ${R_OUT_ATM_D}/${config_UserChoices_JobName}_Bands_${RESOL_ATM_3D}_${NUM_PROC_ATM}prc.dat_0
128            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"
129        fi
130    fi
131
132    LMDZ_adjust=n
133    [ ${CumulPeriod} -le ${LMDZ_NbPeriod_adjust} ] && LMDZ_adjust=y
134
135    RefPeriod=${LMDZ_NbPeriod_adjust} #0 to use a Bands file from Restart
136    [ ${CumulPeriod} -le ${LMDZ_NbPeriod_adjust} ] && (( RefPeriod = ${CumulPeriod} - 1 )) 
137
138    [ ${CumulPeriod} -gt 1 ] && ( IGCM_sys_Get ${R_OUT_ATM_D}/${config_UserChoices_JobName}_Bands_${RESOL_ATM_3D}_${NUM_PROC_ATM}prc.dat_${RefPeriod} Bands_${RESOL_ATM_3D}_${NUM_PROC_ATM}prc.dat ; IGCM_sys_Chmod u+w Bands_${RESOL_ATM_3D}_${NUM_PROC_ATM}prc.dat )
139
140     ##-- GHG forcing for the current year
141    if ( ${FirstInitialize} && [ X"${config_ATM_Restart}" = X"n" ]) ; then
142        UndefinedValueCo2=-9999
143        InitPeriodCo2=$(( ${CumulPeriod} - 1 ))
144        InitDateBeginCo2=${UndefinedValueCo2}
145        InitYearCo2=$(( ${year} - 1 ))
146        InitDateEndCo2=${InitYearCo2}1231
147        fCO2_ff=${UndefinedValueCo2}
148        CO2SBG=${UndefinedValueCo2}
149        CO2LU=${UndefinedValueCo2}
150        CO2MBG=${UndefinedValueCo2}
151        CO2_ppm_prec=${UndefinedValueCo2}
152        CO2_ppm=${lmdz_UserChoices_co2_init}
153
154        IGCM_sys_Cp ${SUBMIT_DIR}/co2.log.init ${SUBMIT_DIR}/co2.log
155        IGCM_sys_Chmod u+w ${SUBMIT_DIR}/co2.log
156
157        echo "${InitPeriodCo2} ${InitDateBeginCo2} ${InitDateEndCo2} ${CO2_ppm} ${CO2_ppm_prec} ${fCO2_ff} ${CO2MBG} ${CO2SBG} ${CO2LU}" |   \
158             gawk '{printf("  %11d | %15s | %15s | %22.15g | %20.15g | %11.8g | %11.8g | %12.8g | %12.8g \n", \
159                              $1,$2,$3,$4,$5,$6,$7,$8,$9)}' >> ${SUBMIT_DIR}/co2.log
160
161        PathCO2log=${SUBMIT_DIR}
162        PreviousLinelog=$( tail -1 ${PathCO2log}/co2.log )
163
164    else
165
166        # Get restart line in co2.log
167
168        # NEW parameter in config.card (even for Overule all restarts, you must modify the line after this comment ):
169        # !! NEW for Carbone cycle !! Path where to find old co2.log file for restart CO2.
170        #SubmitRestartPath=
171        if ( ${FirstInitialize} && [ X"${config_ATM_Restart}" = X"y" ]) ; then
172            IGCM_card_DefineVariableFromOption ${SUBMIT_DIR}/config.card ATM SubmitRestartPath
173            PathCO2log=${config_ATM_SubmitRestartPath}
174            Date_r=$( IGCM_date_ConvertFormatToGregorian ${config_ATM_RestartDate} )
175            PreviousLinelog=$( grep ${Date_r} ${PathCO2log}/co2.log )
176
177            IGCM_sys_Cp ${SUBMIT_DIR}/co2.log.init ${SUBMIT_DIR}/co2.log
178            IGCM_sys_Chmod u+w ${SUBMIT_DIR}/co2.log
179
180            # Save Last Line of control in new co2.log file
181            InitPeriodCo2=0
182            InitDateBeginCo2=$( echo "${PreviousLinelog[*]}" | gawk -F '|' '{gsub(" ",""); print $2}' )
183            InitDateEndCo2=$( echo "${PreviousLinelog[*]}" | gawk -F '|' '{gsub(" ",""); print $3}' )
184            fCO2_ff=$( echo "${PreviousLinelog[*]}" | gawk -F '|' '{gsub(" ",""); print $6}' )
185            CO2SBG=$( echo "${PreviousLinelog[*]}" | gawk -F '|' '{gsub(" ",""); print $8}' )
186            CO2LU=$( echo "${PreviousLinelog[*]}" | gawk -F '|' '{gsub(" ",""); print $9}' )
187            CO2MBG=$( echo "${PreviousLinelog[*]}" | gawk -F '|' '{gsub(" ",""); print $7}' )
188            CO2_ppm_prec=$( echo "${PreviousLinelog[*]}" | gawk -F '|' '{gsub(" ",""); print $5}' )
189            CO2_ppm=$( echo "${PreviousLinelog[*]}" | gawk -F '|' '{gsub(" ",""); print $4}' )
190
191            echo "${InitPeriodCo2} ${InitDateBeginCo2} ${InitDateEndCo2} ${CO2_ppm} ${CO2_ppm_prec} ${fCO2_ff} ${CO2MBG} ${CO2SBG} ${CO2LU}" |   \
192                  gawk '{printf("  %11d | %15s | %15s | %22.15g | %20.15g | %11.8g | %11.8g | %12.8g | %12.8g \n", \
193                              $1,$2,$3,$4,$5,$6,$7,$8,$9)}' >> ${SUBMIT_DIR}/co2.log
194
195        else
196            PathCO2log=${SUBMIT_DIR}
197            PreviousLinelog=$( tail -1 ${PathCO2log}/co2.log )
198            CO2_ppm=$( echo "${PreviousLinelog[*]}" | gawk -F '|' '{gsub(" ",""); print $4}' )
199        fi
200
201    fi
202
203    ## physiq.def parameters modified from initial physiq_L${RESOL_ATM_Z}
204    LMDZ_sed physiq.def OK_instan   ${OK_instan}
205    LMDZ_sed physiq.def OK_journe   ${OK_journe}
206    LMDZ_sed physiq.def OK_mensuel  ${OK_mensuel}
207    LMDZ_sed physiq.def ok_hf       ${ok_hf}
208    LMDZ_sed physiq.def ecrit_mth   ${LMDZ_ecrit_mth}
209    LMDZ_sed physiq.def ecrit_ISCCP ${LMDZ_ecrit_ISCCP}
210    LMDZ_sed physiq.def ok_cosp     ${LMDZ_COSP_OK}
211    LMDZ_sed physiq.def ok_mensuelCOSP  ${LMDZ_COSP_monthly}
212    LMDZ_sed physiq.def ok_journeCOSP   ${LMDZ_COSP_daily}
213    LMDZ_sed physiq.def ok_hfCOSP   ${LMDZ_COSP_hf}
214    LMDZ_sed physiq.def ok_histNMC  "${LMDZ_NMC_monthly}, ${LMDZ_NMC_daily}, ${LMDZ_NMC_hf}"
215#   For Control, we won't modify ATM CO2 :
216    LMDZ_sed physiq.def co2_ppm     ${CO2_ppm}
217
218    ## gcm.def parameters : no change since gcm.def_${RESOL_ATM_3D} is used and already modified
219
220    ## run.def parameters
221    LMDZ_sed run.def dayref   ${InitDay}
222    LMDZ_sed run.def anneeref ${InitYear}
223    LMDZ_sed run.def calend   ${CalendarTypeForLmdz}
224    LMDZ_sed run.def nday     ${PeriodLengthInDays}
225    LMDZ_sed run.def raz_date ${RAZ_DATE}
226    LMDZ_sed run.def periodav ${LMDZ_periodav}
227    LMDZ_sed run.def adjust   ${LMDZ_adjust}
228
229    ## Read ByPass_hgardfou_teta option in lmdz.card --> divide teta* by 2 if [ $ByPass_hgardfou_teta = 1 ]
230    IGCM_card_DefineVariableFromOption ${SUBMIT_DIR}/COMP/lmdz.card UserChoices ByPass_hgardfou_teta
231    ByPass_hgardfou_teta=${lmdz_UserChoices_ByPass_hgardfou_teta}
232    if [ ${ByPass_hgardfou_teta} = y ] ; then
233        awk '{ if ($0 ~ /^teta.*=/) {split($0,a,"=") ; print a[1]"="a[2]/2"."} else print $0}' gcm.def > gcm.def.tmp
234        IGCM_sys_Mv gcm.def.tmp gcm.def
235        echo
236        IGCM_debug_Print 1 "ByPass_hgardfou_teta : ^teta*/2 in gcm.def"
237        echo
238        cat gcm.def
239        ByPass_hgardfou_teta=n
240        IGCM_card_WriteOption ${SUBMIT_DIR}/COMP/lmdz.card UserChoices ByPass_hgardfou_teta "${ByPass_hgardfou_teta}"
241    fi
242
243    ## Read ByPass_hgardfou_mats option in lmdz.card --> purmats=y 2 if [ $ByPass_hgardfou_mats = 1 ]
244    IGCM_card_DefineVariableFromOption ${SUBMIT_DIR}/COMP/lmdz.card UserChoices ByPass_hgardfou_mats
245    ByPass_hgardfou_mats=${lmdz_UserChoices_ByPass_hgardfou_mats}
246    if [ ${ByPass_hgardfou_mats} = y ] ; then
247        sed -e "s/^purmats=.*/purmats=y/" gcm.def > gcm.def.tmp
248        IGCM_sys_Mv gcm.def.tmp gcm.def
249        echo
250        IGCM_debug_Print 1 "ByPass_hgardfou_mats : purmats=y in gcm.def"
251        echo
252        cat gcm.def
253        ByPass_hgardfou_mats=n
254        IGCM_card_WriteOption ${SUBMIT_DIR}/COMP/lmdz.card UserChoices ByPass_hgardfou_mats "${ByPass_hgardfou_mats}"
255    fi
256
257    if ( ${FirstInitialize} ) ; then
258
259        if ( [ "${config_Restarts_OverRule}" = "n" ] && [ "${config_ATM_Restart}" = "n" ] ); then
260            if [ ${DRYRUN} -le 2 ] ; then
261                ##-- suppression of ozone file construction --
262                cp physiq.def physiq.def.save
263                LMDZ_sed physiq.def read_climoz 0
264                IGCM_sys_Cp ${R_EXE}/create_etat0_limit.e ${RUN_DIR}/.
265                if [ ${DRYRUN} -le 1 ] ; then
266                    ${HOST_MPIRUN_COMMAND} -np 1 ./create_etat0_limit.e
267                    IGCM_sys_Put_Out start.nc    ${R_OUT_ATM_R}/${config_UserChoices_JobName}_${PeriodDateBegin}_start.nc
268                    IGCM_sys_Put_Out startphy.nc ${R_OUT_ATM_R}/${config_UserChoices_JobName}_${PeriodDateBegin}_startphy.nc
269                fi
270                IGCM_sys_Mv physiq.def.save physiq.def
271            else
272                echo "EXECUTION of ${HOST_MPIRUN_COMMAND} -np 1 ./create_etat0_limit.e simulated"
273                echo "EXECUTION of ${HOST_MPIRUN_COMMAND} -np 1 ./create_etat0_limit.e simulated for DRYRUN = " $DRYRUN >> stack
274            fi
275        fi
276
277    fi
278
279    IGCM_debug_PopStack "ATM_Update"
280}
281
282#-----------------------------------
283function ATM_Finalize
284{
285    IGCM_debug_PushStack "ATM_Finalize"
286
287    [ ${CumulPeriod} -le ${LMDZ_NbPeriod_adjust} ] && IGCM_sys_Put_Out Bands_${RESOL_ATM_3D}_${NUM_PROC_ATM}prc.dat ${R_OUT_ATM_D}/${config_UserChoices_JobName}_Bands_${RESOL_ATM_3D}_${NUM_PROC_ATM}prc.dat_${CumulPeriod}
288
289#   get the fossile fuel file :
290
291    typeset CO2SBG_3V CO2SBG CO2MBG CO2SRF CO2LU CO2_ppm CO2_ppm_prec fCO2_ff
292
293    fCO2_ff=0
294
295    CO2MBG=$( ${SUBMIT_DIR}/COMP/lmdz_analyse_pisces_out.awk ocean.output )
296    CO2MBG=$( echo ${CO2MBG} | sed -e "s/ *//" )
297    echo "Ocean carbon flux  :" ${CO2MBG}
298
299    set +A CO2SBG_3V -- $( ${SUBMIT_DIR}/COMP/lmdz_analyse_stomate_out.awk out_orchidee_0000 )
300    CO2SRF=$( echo ${CO2SBG_3V[0]} | sed -e "s/ *//" )
301    CO2LU=$( echo ${CO2SBG_3V[1]} | sed -e "s/ *//" )
302    CO2SBG=$( echo ${CO2SBG_3V[2]} | sed -e "s/ *//" )
303    echo "Land carbon flux  :" ${CO2SRF}
304    echo "LU flux           :" ${CO2LU}
305    echo "Total Land carbon flux  :" ${CO2SBG}
306
307    # Previous CO2
308    CO2_ppm_prec=$( echo "${PreviousLinelog[*]}" | gawk -F '|' '{gsub(" ",""); print $4}' )
309    echo "Previous CO2  :" ${CO2_ppm_prec}
310
311    # Formula
312    CO2_ppm=$( echo "${CO2_ppm_prec} + (${fCO2_ff} + ${CO2MBG} + ${CO2SBG}) / 2.12" | bc -l )
313    echo "New CO2  :" ${CO2_ppm}
314
315    # Save CO2 values in ExeCpuLog variable contents 5 fields
316    echo "${CumulPeriod} ${PeriodDateBegin} ${PeriodDateEnd} ${CO2_ppm} ${CO2_ppm_prec} ${fCO2_ff} ${CO2MBG} ${CO2SBG} ${CO2LU}" |   \
317         gawk '{printf("  %11d | %15s | %15s | %22.15g | %20.15g | %11.8g | %11.8g | %12.8g | %12.8g \n", \
318                           $1,$2,$3,$4,$5,$6,$7,$8,$9)}' >> ${SUBMIT_DIR}/co2.log
319    echo FINALIZE ATM !
320
321    IGCM_debug_PopStack "ATM_Finalize"
322}
Note: See TracBrowser for help on using the repository browser.