source: CONFIG/IPSLCM/IPSLCM5A/Chistorical/COMP/lmdz.driver @ 1237

Last change on this file since 1237 was 1237, checked in by mmaipsl, 12 years ago

First CO2 interactive historical scripts.
Please, see https://forge.ipsl.jussieu.fr/igcmg/wiki/IPSLCM5ACo2 for informations.
And follow links in https://forge.ipsl.jussieu.fr/igcmg/wiki/IPSLCM5ACo2#Testsetruns
for example of use.

File size: 14.9 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) 
56                ok_hf=y
57                OK_instan=y
58                ;;
59        esac
60    done
61
62    ## Read LMDZ_NbPeriod_adjust option in lmdz.card
63    IGCM_card_DefineVariableFromOption ${SUBMIT_DIR}/COMP/lmdz.card UserChoices LMDZ_NbPeriod_adjust
64    LMDZ_NbPeriod_adjust=${lmdz_UserChoices_LMDZ_NbPeriod_adjust}
65
66    if [ ${LMDZ_NbPeriod_adjust} -eq 0 ] ; then
67        IGCM_card_DefineVariableFromOption ${SUBMIT_DIR}/COMP/lmdz.card UserChoices LMDZ_Bands_file_name
68        LMDZ_Bands_file_name=${lmdz_UserChoices_LMDZ_Bands_file_name}
69    fi
70
71    ##  Read LMDZ_Freq_aero and LMDZ_Length_aero in lmdz.card
72    LMDZ_Freq_aero=${lmdz_UserChoices_LMDZ_Freq_aero}
73    LMDZ_Length_aero=${lmdz_UserChoices_LMDZ_Length_aero}
74
75    ##  Read LMDZ_COSP_monthly  LMDZ_COSP_daily and LMDZ_COSP_hf in lmdz.card
76    LMDZ_COSP_OK=${lmdz_UserChoices_LMDZ_COSP_OK}
77    LMDZ_COSP_monthly=${lmdz_UserChoices_LMDZ_COSP_monthly}
78    LMDZ_COSP_daily=${lmdz_UserChoices_LMDZ_COSP_daily}
79    LMDZ_COSP_hf=${lmdz_UserChoices_LMDZ_COSP_hf}
80
81    ##  Read LMDZ_NMC_monthly  LMDZ_NMC_daily and LMDZ_NMC_hf in lmdz.card
82    LMDZ_NMC_monthly=${lmdz_UserChoices_LMDZ_NMC_monthly}
83    LMDZ_NMC_daily=${lmdz_UserChoices_LMDZ_NMC_daily}
84    LMDZ_NMC_hf=${lmdz_UserChoices_LMDZ_NMC_hf}
85
86    IGCM_debug_PopStack "ATM_Initialize"
87}
88
89#-----------------------------------------------------------------
90function ATM_Update
91{
92    IGCM_debug_PushStack "ATM_Update"
93
94    typeset CO2SBG CO2MBG CO2LU CO2_ppm CO2_ppm_prec fCO2_ff
95    typeset PreviousLinelog LastPeriodDateBegin LastPeriodDateEnd LastDatesPeriod LastPREFIX
96    typeset PathCO2log Date_r OUT_OCE OUT_SRF
97
98    case ${config_UserChoices_PeriodLength} in
99        *Y|*y) 
100               LMDZ_ecrit_mth=30.
101               LMDZ_ecrit_ISCCP=30.
102               LMDZ_periodav=30.
103               if [ "${config_UserChoices_CalendarType}" != "360d" ] ; then
104                  echo Change calendartype in config.card. PeriodLength=1Y allowed only for CalendarType=360d
105                  exit
106               fi
107               ;;
108        *)
109               LMDZ_ecrit_mth=${PeriodLengthInDays}.
110               LMDZ_ecrit_ISCCP=${PeriodLengthInDays}.
111               LMDZ_periodav=${PeriodLengthInDays}.
112               ;;
113    esac
114
115    ##-- Remise ou non a zero de la date initiale de LMDZ pour le fichier run.def
116    if [ ${CumulPeriod} -eq 1 ] ; then
117        RAZ_DATE=1
118    else
119        RAZ_DATE=0
120    fi
121
122    ## To have more variables in output files for aerosols. Parameters are set in lmdz.card
123    #if [ ${CumulPeriod}%${LMDZ_Freq_aero} -le ${LMDZ_Length_aero} ]; then
124    #   if [ ${CumulPeriod}%${LMDZ_Freq_aero} -ne 0 ]; then
125    #      lev_histmth=4
126    #   else
127    #      lev_histmth=2   
128    #   fi
129    #else
130    #   lev_histmth=2
131    #fi   
132
133    ## algo : For CumulPeriod=1 ;
134    ##        IF NbPeriod_Adjust = 0, Get Bands file directly from server, store it with _0 suffix
135    ##        ELSE LMDZ_adjust=y ; save Bands file on file server ;
136    ##        For CumulPeriod=2 to LMDZ_NbPeriod_adjust ; Get Bands file from server (CumulPeriod-1) ; LMDZ_adjust=y ; save Bands file on file server ;
137    ##        For CumulPeriod > LMDZ_NbPeriod_adjust ; LMDZ_adjust=n ; Get Bands file from server (CumulPeriod=LMDZ_NbPeriod_adjust 0 to force it) ; Use Bands ;
138
139    if [ ${CumulPeriod} -eq 1 ] ; then
140        if [ ${LMDZ_NbPeriod_adjust} -eq 0 ] ; then
141            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
142            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
143            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"
144        fi
145    fi
146
147    LMDZ_adjust=n
148    [ ${CumulPeriod} -le ${LMDZ_NbPeriod_adjust} ] && LMDZ_adjust=y
149
150    RefPeriod=${LMDZ_NbPeriod_adjust} #0 to use a Bands file from Restart
151    [ ${CumulPeriod} -le ${LMDZ_NbPeriod_adjust} ] && (( RefPeriod = ${CumulPeriod} - 1 )) 
152
153    [ ${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 )
154
155    ##-- GHG forcing for the current year
156    IPCC_SOLAR=`grep Annee_${year} SOLARANDVOLCANOES_1610_2008.txt | awk -F= '{print $2}'`
157#    IPCC_CO2=`grep Annee_${year} CO2_1765_2005.txt | awk -F= '{print $2}'`
158    IPCC_CH4=`grep Annee_${year} CH4_1765_2005.txt | awk -F= '{print $2}'`
159    IPCC_N2O=`grep Annee_${year} N2O_1765_2005.txt | awk -F= '{print $2}'`
160    IPCC_CFC11=`grep Annee_${year} CFC11_1765_2005.txt | awk -F= '{print $2}'`
161    IPCC_CFC12=`grep Annee_${year} CFC12_1765_2005.txt | awk -F= '{print $2}'`
162
163    if ( ${FirstInitialize} && [ X"${config_ATM_Restart}" = X"n" ]) ; then
164       
165        fCO2_ff=0
166        CO2SRF=0
167        CO2LU=0
168        CO2MBG=0
169        CO2_ppm=${lmdz_UserChoices_co2_init}
170        CO2_ppm_prec=${lmdz_UserChoices_co2_init}
171       
172        IGCM_sys_Cp ${SUBMIT_DIR}/co2.log.init ${SUBMIT_DIR}/co2.log
173        IGCM_sys_Chmod u+w ${SUBMIT_DIR}/co2.log
174
175        echo "${CumulPeriod} ${PeriodDateBegin} ${PeriodDateEnd} ${CO2_ppm} ${CO2_ppm_prec} ${fCO2_ff} ${CO2MBG} ${CO2SRF} ${CO2LU}" |   \
176             gawk '{printf("  %11d | %15s | %15s | %22.15g | %20.15g | %11.8g | %11.8g | %12.8g | %12.8g \n", \
177                              $1,$2,$3,$4,$5,$6,$7,$8,$9)}' >> ${SUBMIT_DIR}/co2.log
178    else
179#       get the fossile fuel file :
180        fCO2_ff=$( gawk "{if (match(\$0,\"${year}\ *${month}\")) {print \$5}}" ${SUBMIT_DIR}/PARAM/CMIP5_gridcar_CO2_emissions_fossil_fuel_Andres_1751-2007_monthly_SC_grid1x1.txt )
181        fCO2_ff=$( echo "${fCO2_ff} / 1000." | bc -l  )
182        echo "Fossil Fuel for historical run  :" ${fCO2_ff}
183
184        # Get restart line in co2.log
185
186        # NEW parameter in config.card (even for Overule all restarts, you must modify the line after this comment ):
187        # !! NEW for Carbone cycle !! Path where to find old co2.log file for restart CO2.
188        #SubmitRestartPath=
189        if ( ${FirstInitialize} && [ X"${config_ATM_Restart}" = X"y" ]) ; then
190            IGCM_card_DefineVariableFromOption ${SUBMIT_DIR}/config.card ATM SubmitRestartPath
191            PathCO2log=${config_ATM_SubmitRestartPath}
192            Date_r=$( IGCM_date_ConvertFormatToGregorian ${config_ATM_RestartDate} )
193            PreviousLinelog=$( grep ${Date_r} ${PathCO2log}/co2.log )
194            OUT_OCE=${config_OCE_RestartPath}/${config_OCE_RestartJobName}/OCE
195            OUT_SRF=${config_SRF_RestartPath}/${config_SRF_RestartJobName}/SRF
196
197            IGCM_sys_Cp ${SUBMIT_DIR}/co2.log.init ${SUBMIT_DIR}/co2.log
198            IGCM_sys_Chmod u+w ${SUBMIT_DIR}/co2.log
199
200            # Save Last Line of control in new co2.log file
201            echo ${PreviousLinelog} >> ${SUBMIT_DIR}/co2.log
202        else
203            PathCO2log=${SUBMIT_DIR}
204            PreviousLinelog=$( tail -1 ${PathCO2log}/co2.log )
205            OUT_OCE=${R_OUT_OCE}
206            OUT_SRF=${R_OUT_SRF}
207        fi
208
209        # Get Previous period output PREFIX
210        LastPeriodDateBegin=$( echo "${PreviousLinelog[*]}" | gawk -F '|' '{gsub(" ",""); print $2}' )
211        LastPeriodDateEnd=$( echo "${PreviousLinelog[*]}" | gawk -F '|' '{gsub(" ",""); print $3}' )
212        eval LastDatesPeriod=${LastPeriodDateBegin}_${LastPeriodDateEnd} > /dev/null 2>&1
213        # Prefix for save files of this period
214        if ( ${FirstInitialize} && [ X"${config_ATM_Restart}" = X"y" ]) ; then
215            eval LastPREFIX=${config_ATM_RestartJobName}_${LastDatesPeriod}  > /dev/null 2>&1
216        else
217            eval LastPREFIX=${config_UserChoices_JobName}_${LastDatesPeriod}  > /dev/null 2>&1
218        fi
219
220        # Ocean
221        IGCM_sys_TestFileArchive ${OUT_OCE}/Debug/${LastPREFIX}_ocean.output
222        if [ $? = 0 ] ; then
223
224            if [ $DRYRUN -gt 1 ]; then
225                IGCM_sys_Cp ${OUT_OCE}/Debug/${LastPREFIX}_ocean.output ./
226            else
227                IGCM_sys_Get ${OUT_OCE}/Debug/${LastPREFIX}_ocean.output ./
228            fi
229            IGCM_comp_PrepareDeletedFiles ./${LastPREFIX}_ocean.output
230            CO2MBG=$( ${SUBMIT_DIR}/COMP/lmdz_analyse_pisces_out.awk ${LastPREFIX}_ocean.output )
231            CO2MBG=$( echo ${CO2MBG} | sed -e "s/ *//" )
232        else
233            echo "Error : file ${OUT_OCE}/Debug/${LastPREFIX}_ocean.output not found."
234            exit 1
235        fi
236
237        # Surface
238        IGCM_sys_TestFileArchive ${OUT_SRF}/Debug/${LastPREFIX}_out_orchidee_0000
239        if [ $? = 0 ] ; then
240            if [ $DRYRUN -gt 1 ]; then
241                IGCM_sys_Cp ${OUT_SRF}/Debug/${LastPREFIX}_out_orchidee_0000 ./
242            else
243                IGCM_sys_Get ${OUT_SRF}/Debug/${LastPREFIX}_out_orchidee_0000 ./
244            fi
245            IGCM_comp_PrepareDeletedFiles ./${LastPREFIX}_out_orchidee_0000
246            set +A CO2SBG -- $( ${SUBMIT_DIR}/COMP/lmdz_analyse_stomate_out.awk ${LastPREFIX}_out_orchidee_0000 )
247        else
248            echo "Error : file ${OUT_SRF}/Debug/${LastPREFIX}_ocean.output not found."
249            exit 1
250        fi
251        CO2SRF=$( echo ${CO2SBG[0]} | sed -e "s/ *//" )
252        CO2LU=$( echo ${CO2SBG[1]} | sed -e "s/ *//" )
253
254        # Previous CO2
255        CO2_ppm_prec=$( echo "${PreviousLinelog[*]}" | gawk -F '|' '{gsub(" ",""); print $4}' )
256
257        # Formula
258        CO2_ppm=$( echo "${CO2_ppm_prec} + (${fCO2_ff} + ${CO2MBG} + ${CO2SRF} + ${CO2LU}) / 2.12" | bc -l )
259
260        # Save CO2 values in ExeCpuLog variable contents 5 fields
261        echo "${CumulPeriod} ${PeriodDateBegin} ${PeriodDateEnd} ${CO2_ppm} ${CO2_ppm_prec} ${fCO2_ff} ${CO2MBG} ${CO2SRF} ${CO2LU}" |   \
262             gawk '{printf("  %11d | %15s | %15s | %22.15g | %20.15g | %11.8g | %11.8g | %12.8g | %12.8g \n", \
263                              $1,$2,$3,$4,$5,$6,$7,$8,$9)}' >> ${SUBMIT_DIR}/co2.log
264
265    fi
266
267    ##-- For historical daily cosp must be output during 1979-2005 period
268    [ ${year} -ge 1979 ] && LMDZ_COSP_daily=y
269
270    ## physiq.def parameters modified from initial physiq_L${RESOL_ATM_Z}
271    LMDZ_sed physiq.def OK_instan   ${OK_instan}
272    LMDZ_sed physiq.def OK_journe   ${OK_journe}
273    LMDZ_sed physiq.def OK_mensuel  ${OK_mensuel}
274    #LMDZ_sed physiq.def lev_histmth ${lev_histmth}
275    LMDZ_sed physiq.def ok_hf       ${ok_hf}
276    LMDZ_sed physiq.def ecrit_mth   ${LMDZ_ecrit_mth}
277    LMDZ_sed physiq.def ecrit_ISCCP ${LMDZ_ecrit_ISCCP}
278    LMDZ_sed physiq.def ok_cosp     ${LMDZ_COSP_OK}
279    LMDZ_sed physiq.def ok_mensuelCOSP  ${LMDZ_COSP_monthly}
280    LMDZ_sed physiq.def ok_journeCOSP   ${LMDZ_COSP_daily}
281    LMDZ_sed physiq.def ok_hfCOSP   ${LMDZ_COSP_hf}
282    LMDZ_sed physiq.def ok_histNMC  "${LMDZ_NMC_monthly}, ${LMDZ_NMC_daily}, ${LMDZ_NMC_hf}"
283    LMDZ_sed physiq.def solaire     ${IPCC_SOLAR}
284#    LMDZ_sed physiq.def co2_ppm     ${IPCC_CO2}
285    LMDZ_sed physiq.def co2_ppm     ${CO2_ppm}
286    LMDZ_sed physiq.def CH4_ppb     ${IPCC_CH4}
287    LMDZ_sed physiq.def N2O_ppb     ${IPCC_N2O}
288    LMDZ_sed physiq.def CFC11_ppt   ${IPCC_CFC11}
289    LMDZ_sed physiq.def CFC12_ppt   ${IPCC_CFC12}
290
291    ## gcm.def parameters : no change since gcm.def_${RESOL_ATM_3D} is used and already modified
292
293    ## run.def parameters
294    LMDZ_sed run.def dayref   ${InitDay}
295    LMDZ_sed run.def anneeref ${InitYear}
296    LMDZ_sed run.def calend   ${CalendarTypeForLmdz}
297    LMDZ_sed run.def nday     ${PeriodLengthInDays}
298    LMDZ_sed run.def raz_date ${RAZ_DATE}
299    LMDZ_sed run.def periodav ${LMDZ_periodav}
300    LMDZ_sed run.def adjust   ${LMDZ_adjust}
301
302    ## Read ByPass_hgardfou_teta option in lmdz.card --> divide teta* by 2 if [ $ByPass_hgardfou_teta = 1 ]
303    IGCM_card_DefineVariableFromOption ${SUBMIT_DIR}/COMP/lmdz.card UserChoices ByPass_hgardfou_teta
304    ByPass_hgardfou_teta=${lmdz_UserChoices_ByPass_hgardfou_teta}
305    if [ ${ByPass_hgardfou_teta} = y ] ; then
306        awk '{ if ($0 ~ /^teta.*=/) {split($0,a,"=") ; print a[1]"="a[2]/2"."} else print $0}' gcm.def > gcm.def.tmp
307        IGCM_sys_Mv gcm.def.tmp gcm.def
308        echo
309        IGCM_debug_Print 1 "ByPass_hgardfou_teta : ^teta*/2 in gcm.def"
310        echo
311        cat gcm.def
312        ByPass_hgardfou_teta=n
313        IGCM_card_WriteOption ${SUBMIT_DIR}/COMP/lmdz.card UserChoices ByPass_hgardfou_teta "${ByPass_hgardfou_teta}"
314    fi
315
316    ## Read ByPass_hgardfou_mats option in lmdz.card --> purmats=y 2 if [ $ByPass_hgardfou_mats = 1 ]
317    IGCM_card_DefineVariableFromOption ${SUBMIT_DIR}/COMP/lmdz.card UserChoices ByPass_hgardfou_mats
318    ByPass_hgardfou_mats=${lmdz_UserChoices_ByPass_hgardfou_mats}
319    if [ ${ByPass_hgardfou_mats} = y ] ; then
320        sed -e "s/^purmats=.*/purmats=y/" gcm.def > gcm.def.tmp
321        IGCM_sys_Mv gcm.def.tmp gcm.def
322        echo
323        IGCM_debug_Print 1 "ByPass_hgardfou_mats : purmats=y in gcm.def"
324        echo
325        cat gcm.def
326        ByPass_hgardfou_mats=n
327        IGCM_card_WriteOption ${SUBMIT_DIR}/COMP/lmdz.card UserChoices ByPass_hgardfou_mats "${ByPass_hgardfou_mats}"
328    fi
329
330    if ( ${FirstInitialize} ) ; then
331
332        if ( [ "${config_Restarts_OverRule}" = "n" ] && [ "${config_ATM_Restart}" = "n" ] ); then
333            if [ ${DRYRUN} -le 2 ] ; then
334                ##-- suppression of ozone file construction --
335                cp physiq.def physiq.def.save
336                LMDZ_sed physiq.def read_climoz 0
337                IGCM_sys_Cp ${R_EXE}/create_etat0_limit.e ${RUN_DIR}/.
338                if [ ${DRYRUN} -le 1 ] ; then
339                    ${HOST_MPIRUN_COMMAND} -np 1 ./create_etat0_limit.e
340                    IGCM_sys_Put_Out start.nc    ${R_OUT_ATM_R}/${config_UserChoices_JobName}_${PeriodDateBegin}_start.nc
341                    IGCM_sys_Put_Out startphy.nc ${R_OUT_ATM_R}/${config_UserChoices_JobName}_${PeriodDateBegin}_startphy.nc
342                fi
343                IGCM_sys_Mv physiq.def.save physiq.def
344            else
345                echo "EXECUTION of ${HOST_MPIRUN_COMMAND} -np 1 ./create_etat0_limit.e simulated"
346                echo "EXECUTION of ${HOST_MPIRUN_COMMAND} -np 1 ./create_etat0_limit.e simulated for DRYRUN = " $DRYRUN >> stack
347            fi
348        fi
349
350    fi
351
352    IGCM_debug_PopStack "ATM_Update"
353}
354
355#-----------------------------------
356function ATM_Finalize
357{
358    IGCM_debug_PushStack "ATM_Finalize"
359
360    [ ${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}
361
362    echo FINALIZE ATM !
363
364    IGCM_debug_PopStack "ATM_Finalize"
365}
Note: See TracBrowser for help on using the repository browser.