#!/bin/ksh #----------------------------------------------------------------- function LMDZ_sed { IGCM_debug_PushStack "LMDZ_sed" sed -e "s/^${2}\ *=.*/${2}= ${3}/" ${1} > ${1}.tmp RET=$? echo "LMDZ_sed : ${1} ${2} ${3}" \mv ${1}.tmp ${1} IGCM_debug_PopStack "LMDZ_sed" return $RET } function ATM_Initialize { IGCM_debug_PushStack "ATM_Initialize" RESOL_ATM=$( echo $RESOL | awk "-Fx" '{print $2}' | awk "-F-" '{print $1}') [ -f ${SUBMIT_DIR}/../.resol ] && eval $(grep RESOL_ATM_3D ${SUBMIT_DIR}/../.resol) || RESOL_ATM_3D=96x95x19 RESOL_ATM_Z=$( echo ${RESOL_ATM_3D} | awk "-Fx" '{print $3}' ) ##-- Calendar type for LMDZ case ${config_UserChoices_CalendarType} in leap|gregorian) CalendarTypeForLmdz=earth_366d;; noleap) CalendarTypeForLmdz=earth_365d;; 360d) CalendarTypeForLmdz=earth_360d;; *) CalendarTypeForLmdz=earth_360d esac ##-- Output frequency purpose .... ##-- Initialisation .... ok_mensuel=n ok_journe=n ok_hf=n ok_hf3h=n ok_hf3hm=n ok_stn=n case ${config_UserChoices_PeriodLength} in 1Y|1y|1M|1m) ok_mensuel=y ;; 5D|5d|1D|1d) ok_journe=y ;; esac for frequency in ${config_ATM_WriteFrequency} ; do case ${frequency} in 1M|1m) ok_mensuel=y ;; esac case ${frequency} in 5D|5d|1D|1d) ok_journe=y ;; esac case ${frequency} in HF|hf) ok_hf=y ;; esac case ${frequency} in HF3h|hf3h) ok_hf3h=y ;; esac case ${frequency} in HF3hm|hf3hm) ok_hf3hm=y ;; esac case ${frequency} in STN|stn) ok_stn=y ;; esac done ## Read LMDZ_NbPeriod_adjust option in lmdz.card IGCM_card_DefineVariableFromOption ${SUBMIT_DIR}/COMP/lmdz.card UserChoices LMDZ_NbPeriod_adjust LMDZ_NbPeriod_adjust=${lmdz_UserChoices_LMDZ_NbPeriod_adjust} if [ ${LMDZ_NbPeriod_adjust} -eq 0 ] ; then IGCM_card_DefineVariableFromOption ${SUBMIT_DIR}/COMP/lmdz.card UserChoices LMDZ_Bands_file_name LMDZ_Bands_file_name=${lmdz_UserChoices_LMDZ_Bands_file_name} fi ## Read LMDZ_Freq_aero and LMDZ_Length_aero in lmdz.card LMDZ_Freq_aero=${lmdz_UserChoices_LMDZ_Freq_aero} LMDZ_Length_aero=${lmdz_UserChoices_LMDZ_Length_aero} ## Read LMDZ_COSP_monthly LMDZ_COSP_daily and LMDZ_COSP_hf in lmdz.card LMDZ_COSP_OK=${lmdz_UserChoices_LMDZ_COSP_OK} LMDZ_COSP_monthly=${lmdz_UserChoices_LMDZ_COSP_monthly} LMDZ_COSP_daily=${lmdz_UserChoices_LMDZ_COSP_daily} LMDZ_COSP_hf=${lmdz_UserChoices_LMDZ_COSP_hf} ## Read LMDZ_NMC_monthly LMDZ_NMC_daily and LMDZ_NMC_hf in lmdz.card LMDZ_NMC_monthly=${lmdz_UserChoices_LMDZ_NMC_monthly} LMDZ_NMC_daily=${lmdz_UserChoices_LMDZ_NMC_daily} LMDZ_NMC_hf=${lmdz_UserChoices_LMDZ_NMC_hf} IGCM_debug_PopStack "ATM_Initialize" } #----------------------------------------------------------------- function ATM_Update { IGCM_debug_PushStack "ATM_Update" case ${config_UserChoices_PeriodLength} in *Y|*y) LMDZ_ecrit_ISCCP=30. LMDZ_periodav=30. if [ "${config_UserChoices_CalendarType}" != "360d" ] ; then echo Change calendartype in config.card. PeriodLength=1Y allowed only for CalendarType=360d exit fi ;; *) LMDZ_ecrit_ISCCP=${PeriodLengthInDays}. LMDZ_periodav=${PeriodLengthInDays}. ;; esac ##-- Remise ou non a zero de la date initiale de LMDZ pour le fichier run.def if [ ${CumulPeriod} -eq 1 ] ; then RAZ_DATE=1 else RAZ_DATE=0 fi ## algo : For CumulPeriod=1 ; ## IF NbPeriod_Adjust = 0, Get Bands file directly from server, store it with _0 suffix ## ELSE LMDZ_adjust=y ; save Bands file on file server ; ## For CumulPeriod=2 to LMDZ_NbPeriod_adjust ; Get Bands file from server (CumulPeriod-1) ; LMDZ_adjust=y ; save Bands file on file server ; ## For CumulPeriod > LMDZ_NbPeriod_adjust ; LMDZ_adjust=n ; Get Bands file from server (CumulPeriod=LMDZ_NbPeriod_adjust 0 to force it) ; Use Bands ; if [ ${CumulPeriod} -eq 1 ] ; then if [ ${LMDZ_NbPeriod_adjust} -eq 0 ] ; then 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 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 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" fi fi LMDZ_adjust=n [ ${CumulPeriod} -le ${LMDZ_NbPeriod_adjust} ] && LMDZ_adjust=y RefPeriod=${LMDZ_NbPeriod_adjust} #0 to use a Bands file from Restart [ ${CumulPeriod} -le ${LMDZ_NbPeriod_adjust} ] && (( RefPeriod = ${CumulPeriod} - 1 )) [ ${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 ) ##-- GHG forcing : ## If forcing file exist in run directory, read values for the current year and modify physiq.def if [ -f SOLARANDVOLCANOES.txt ] ; then IPCC_SOLAR=`grep Annee_${year} SOLARANDVOLCANOES.txt | awk -F= '{print $2}'` LMDZ_sed physiq.def solaire ${IPCC_SOLAR} fi if [ -f CO2.txt ] ; then IPCC_CO2=`grep Annee_${year} CO2.txt | awk -F= '{print $2}'` LMDZ_sed physiq.def co2_ppm ${IPCC_CO2} fi if [ -f CH4.txt ] ; then IPCC_CH4=`grep Annee_${year} CH4.txt | awk -F= '{print $2}'` LMDZ_sed physiq.def CH4_ppb ${IPCC_CH4} fi if [ -f N2O.txt ] ; then IPCC_N2O=`grep Annee_${year} N2O.txt | awk -F= '{print $2}'` LMDZ_sed physiq.def N2O_ppb ${IPCC_N2O} fi if [ -f CFC11.txt ] ; then IPCC_CFC11=`grep Annee_${year} CFC11.txt | awk -F= '{print $2}'` LMDZ_sed physiq.def CFC11_ppt ${IPCC_CFC11} fi if [ -f CFC12.txt ] ; then IPCC_CFC12=`grep Annee_${year} CFC12.txt | awk -F= '{print $2}'` LMDZ_sed physiq.def CFC12_ppt ${IPCC_CFC12} fi # Add special treatement for CARBON CYCLE if [ ${lmdz_UserChoices_CARBON_CYCLE} = control ] || [ ${lmdz_UserChoices_CARBON_CYCLE} = historical ] ; then typeset InitPeriodCo2 InitDateBeginCo2 InitDateEndCo2 typeset CO2SBG CO2MBG CO2LU CO2_ppm CO2_ppm_prec fCO2_ff typeset PathCO2log typeset PreviousLinelog LastPeriodDateBegin LastPeriodDateEnd LastDatesPeriod LastPREFIX if ( ${FirstInitialize} && [ X"${config_ATM_Restart}" = X"n" ]) ; then ##--Initialization of fluxes to an undefined value at the first run UndefinedValueCo2=-9999 InitPeriodCo2=0 InitDateBeginCo2=${UndefinedValueCo2} InitYearCo2=$(( ${year} - 1 )) InitDateEndCo2=${InitYearCo2}1231 fCO2_ff=${UndefinedValueCo2} CO2SBG=${UndefinedValueCo2} CO2LU=${UndefinedValueCo2} CO2MBG=${UndefinedValueCo2} CO2_ppm_prec=${UndefinedValueCo2} # Get the initial value of atmosp. pco2 CO2_ppm=${lmdz_UserChoices_co2_init} IGCM_sys_Cp ${SUBMIT_DIR}/co2.log.init ${SUBMIT_DIR}/co2.log IGCM_sys_Chmod u+w ${SUBMIT_DIR}/co2.log # Save CO2 values in ExeCpuLog variable contents 5 fields echo "${InitPeriodCo2} ${InitDateBeginCo2} ${InitDateEndCo2} ${CO2_ppm} ${CO2_ppm_prec} ${fCO2_ff} ${CO2MBG} ${CO2SBG} ${CO2LU}" | \ gawk '{printf(" %11d | %15s | %15s | %22.15g | %20.15g | %11.8g | %11.8g | %12.8g | %12.8g \n", \ $1,$2,$3,$4,$5,$6,$7,$8,$9)}' >> ${SUBMIT_DIR}/co2.log # Get the path where the log file co2.log is PathCO2log=${SUBMIT_DIR} # Get Previous line in co2.log PreviousLinelog=$( tail -1 ${PathCO2log}/co2.log ) else # NEW parameter in config.card (even for Overule all restarts, you must modify the line after this comment ): # !! NEW for Carbone cycle !! Path where to find old co2.log file for restart CO2. #SubmitRestartPath= if ( ${FirstInitialize} && [ X"${config_ATM_Restart}" = X"y" ]) ; then IGCM_card_DefineVariableFromOption ${SUBMIT_DIR}/config.card ATM SubmitRestartPath PathCO2log=${config_ATM_SubmitRestartPath} Date_r=$( IGCM_date_ConvertFormatToGregorian ${config_ATM_RestartDate} ) PreviousLinelog=$( grep ${Date_r} ${PathCO2log}/co2.log ) IGCM_sys_Cp ${SUBMIT_DIR}/co2.log.init ${SUBMIT_DIR}/co2.log IGCM_sys_Chmod u+w ${SUBMIT_DIR}/co2.log # Save Last Line of control in new co2.log file InitPeriodCo2=0 InitDateBeginCo2=$( echo "${PreviousLinelog[*]}" | gawk -F '|' '{gsub(" ",""); print $2}' ) InitDateEndCo2=$( echo "${PreviousLinelog[*]}" | gawk -F '|' '{gsub(" ",""); print $3}' ) fCO2_ff=$( echo "${PreviousLinelog[*]}" | gawk -F '|' '{gsub(" ",""); print $6}' ) CO2SBG=$( echo "${PreviousLinelog[*]}" | gawk -F '|' '{gsub(" ",""); print $8}' ) CO2LU=$( echo "${PreviousLinelog[*]}" | gawk -F '|' '{gsub(" ",""); print $9}' ) CO2MBG=$( echo "${PreviousLinelog[*]}" | gawk -F '|' '{gsub(" ",""); print $7}' ) CO2_ppm_prec=$( echo "${PreviousLinelog[*]}" | gawk -F '|' '{gsub(" ",""); print $5}' ) CO2_ppm=$( echo "${PreviousLinelog[*]}" | gawk -F '|' '{gsub(" ",""); print $4}' ) echo "${InitPeriodCo2} ${InitDateBeginCo2} ${InitDateEndCo2} ${CO2_ppm} ${CO2_ppm_prec} ${fCO2_ff} ${CO2MBG} ${CO2SBG} ${CO2LU}" | \ gawk '{printf(" %11d | %15s | %15s | %22.15g | %20.15g | %11.8g | %11.8g | %12.8g | %12.8g \n", \ $1,$2,$3,$4,$5,$6,$7,$8,$9)}' >> ${SUBMIT_DIR}/co2.log else # Get restart line in co2.log PathCO2log=${SUBMIT_DIR} PreviousLinelog=$( tail -1 ${PathCO2log}/co2.log ) # Get the value of atmosp. pco2 in co2.log CO2_ppm=$( echo "${PreviousLinelog[*]}" | gawk -F '|' '{gsub(" ",""); print $4}' ) fi fi if [ ${lmdz_UserChoices_CARBON_CYCLE} = historical ] ; then # Modify co2_ppm in physiq.def only for historical run LMDZ_sed physiq.def co2_ppm ${CO2_ppm} fi fi # end CARBON_CYCLE ##-- Set LMDZ_COSP_daily1979=y in section UserChoices in lmdz.card to activate ## COSP daily output for years 1979 and later (mandatory for historical CMIP5 run). if ([ X"${lmdz_UserChoices_LMDZ_COSP_daily1979}" = X"y" ] && [ ${year} -ge 1979 ]) ; then LMDZ_COSP_daily=y fi ## physiq.def parameters modified from initial physiq_L${RESOL_ATM_Z} # columns in phys_output_filekeys refer to the filenames given in phys_out_filenames in physiq.def : # histmth histday histhf histfh3h histhf3hm histstn LMDZ_sed physiq.def phys_out_filekeys ${ok_mensuel} ${ok_journe} ${ok_hf} ${ok_hf3h} ${ok_hf3hm} ${ok_stn} LMDZ_sed physiq.def ecrit_ISCCP ${LMDZ_ecrit_ISCCP} LMDZ_sed physiq.def ok_cosp ${LMDZ_COSP_OK} LMDZ_sed physiq.def ok_mensuelCOSP ${LMDZ_COSP_monthly} LMDZ_sed physiq.def ok_journeCOSP ${LMDZ_COSP_daily} LMDZ_sed physiq.def ok_hfCOSP ${LMDZ_COSP_hf} LMDZ_sed physiq.def ok_histNMC "${LMDZ_NMC_monthly}, ${LMDZ_NMC_daily}, ${LMDZ_NMC_hf}" ## gcm.def parameters : no change since gcm.def_${RESOL_ATM_3D} is used and already modified ## run.def parameters LMDZ_sed run.def dayref ${InitDay} LMDZ_sed run.def anneeref ${InitYear} LMDZ_sed run.def calend ${CalendarTypeForLmdz} LMDZ_sed run.def nday ${PeriodLengthInDays} LMDZ_sed run.def raz_date ${RAZ_DATE} LMDZ_sed run.def periodav ${LMDZ_periodav} LMDZ_sed run.def adjust ${LMDZ_adjust} ## Read ByPass_hgardfou_teta option in lmdz.card --> divide teta* by 2 if [ $ByPass_hgardfou_teta = 1 ] IGCM_card_DefineVariableFromOption ${SUBMIT_DIR}/COMP/lmdz.card UserChoices ByPass_hgardfou_teta ByPass_hgardfou_teta=${lmdz_UserChoices_ByPass_hgardfou_teta} if [ ${ByPass_hgardfou_teta} = y ] ; then awk '{ if ($0 ~ /^teta.*=/) {split($0,a,"=") ; print a[1]"="a[2]/2"."} else print $0}' gcm.def > gcm.def.tmp IGCM_sys_Mv gcm.def.tmp gcm.def echo IGCM_debug_Print 1 "ByPass_hgardfou_teta : ^teta*/2 in gcm.def" echo cat gcm.def ByPass_hgardfou_teta=n IGCM_card_WriteOption ${SUBMIT_DIR}/COMP/lmdz.card UserChoices ByPass_hgardfou_teta "${ByPass_hgardfou_teta}" fi ## Read ByPass_hgardfou_mats option in lmdz.card --> purmats=y 2 if [ $ByPass_hgardfou_mats = 1 ] IGCM_card_DefineVariableFromOption ${SUBMIT_DIR}/COMP/lmdz.card UserChoices ByPass_hgardfou_mats ByPass_hgardfou_mats=${lmdz_UserChoices_ByPass_hgardfou_mats} if [ ${ByPass_hgardfou_mats} = y ] ; then sed -e "s/^purmats=.*/purmats=y/" gcm.def > gcm.def.tmp IGCM_sys_Mv gcm.def.tmp gcm.def echo IGCM_debug_Print 1 "ByPass_hgardfou_mats : purmats=y in gcm.def" echo cat gcm.def ByPass_hgardfou_mats=n IGCM_card_WriteOption ${SUBMIT_DIR}/COMP/lmdz.card UserChoices ByPass_hgardfou_mats "${ByPass_hgardfou_mats}" fi if ( ${FirstInitialize} ) ; then if ( [ "${config_Restarts_OverRule}" = "n" ] && [ "${config_ATM_Restart}" = "n" ] ); then if [ ${DRYRUN} -le 2 ] ; then ##-- suppression of ozone file construction -- cp physiq.def physiq.def.save LMDZ_sed physiq.def read_climoz 0 IGCM_sys_Cp ${R_EXE}/create_etat0_limit.e ${RUN_DIR}/. if [ ${DRYRUN} -le 1 ] ; then ${HOST_MPIRUN_COMMAND} -np 1 ./create_etat0_limit.e IGCM_sys_Put_Out start.nc ${R_OUT_ATM_R}/${config_UserChoices_JobName}_${PeriodDateBegin}_start.nc IGCM_sys_Put_Out startphy.nc ${R_OUT_ATM_R}/${config_UserChoices_JobName}_${PeriodDateBegin}_startphy.nc fi IGCM_sys_Mv physiq.def.save physiq.def else echo "EXECUTION of ${HOST_MPIRUN_COMMAND} -np 1 ./create_etat0_limit.e simulated" echo "EXECUTION of ${HOST_MPIRUN_COMMAND} -np 1 ./create_etat0_limit.e simulated for DRYRUN = " $DRYRUN >> stack fi fi fi IGCM_debug_PopStack "ATM_Update" } #----------------------------------- function ATM_Finalize { IGCM_debug_PushStack "ATM_Finalize" [ ${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} # Add special treatement for CARBON CYCLE if [ ${lmdz_UserChoices_CARBON_CYCLE} = control ] || [ ${lmdz_UserChoices_CARBON_CYCLE} = historical ] ; then typeset CO2SBG_3V CO2SBG CO2MBG CO2SRF CO2LU CO2_ppm CO2_ppm_prec fCO2_ff # Fossil fuel emission if [ ${lmdz_UserChoices_CARBON_CYCLE} = control ] ; then # For Control, no fossil fuel emission : fCO2_ff=0 echo "Fossil Fuel for control run :" ${fCO2_ff} else # For historical, get the fossile fuel file : 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 ) echo "Fossil Fuel for historical run :" ${fCO2_ff} fi # Get the value of ocean carbon flux CO2MBG=$( ${SUBMIT_DIR}/COMP/lmdz_analyse_pisces_out.awk ocean.output ) CO2MBG=$( echo ${CO2MBG} | sed -e "s/ *//" ) echo "Ocean carbon flux :" ${CO2MBG} # Get the value of land fluxes set +A CO2SBG_3V -- $( ${SUBMIT_DIR}/COMP/lmdz_analyse_stomate_out.awk out_orchidee_0000 ) CO2SRF=$( echo ${CO2SBG_3V[0]} | sed -e "s/ *//" ) CO2LU=$( echo ${CO2SBG_3V[1]} | sed -e "s/ *//" ) CO2SBG=$( echo ${CO2SBG_3V[2]} | sed -e "s/ *//" ) echo "Land carbon flux (NEP) :" ${CO2SRF} echo "LU flux (FLUC) :" ${CO2LU} echo "Total Land carbon flux (NBP) :" ${CO2SBG} # Previous CO2 CO2_ppm_prec=$( echo "${PreviousLinelog[*]}" | gawk -F '|' '{gsub(" ",""); print $4}' ) echo "Previous CO2 :" ${CO2_ppm_prec} # Formula CO2_ppm=$( echo "${CO2_ppm_prec} + (${fCO2_ff} + ${CO2MBG} + ${CO2SBG}) / 2.12" | bc -l ) echo "New CO2 :" ${CO2_ppm} # Save CO2 values in ExeCpuLog variable contents 5 fields echo "${CumulPeriod} ${PeriodDateBegin} ${PeriodDateEnd} ${CO2_ppm} ${CO2_ppm_prec} ${fCO2_ff} ${CO2MBG} ${CO2SBG} ${CO2LU}" | \ gawk '{printf(" %11d | %15s | %15s | %22.15g | %20.15g | %11.8g | %11.8g | %12.8g | %12.8g \n", \ $1,$2,$3,$4,$5,$6,$7,$8,$9)}' >> ${SUBMIT_DIR}/co2.log fi echo FINALIZE ATM ! IGCM_debug_PopStack "ATM_Finalize" }