source: CONFIG/IPSLCM/IPSLCM5B/historical/COMP/lmdz.driver @ 1221

Last change on this file since 1221 was 1221, checked in by lfairhead, 11 years ago

I was pretty sure I had committed the right version of these

File size: 10.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 LMDZ_string_sed
17{
18    IGCM_debug_PushStack "LMDZ_string_sed"
19
20    sed -e "s/${2}/${3}/" ${1} > ${1}.tmp
21    RET=$?
22    echo "LMDZ_sed : ${1} ${2} ${3}"
23    \mv ${1}.tmp ${1}
24
25    IGCM_debug_PopStack "LMDZ_string_sed"
26    return $RET
27}
28
29function ATM_Initialize
30{
31    IGCM_debug_PushStack "ATM_Initialize"
32
33    RESOL_ATM=$( echo $RESOL | awk "-Fx" '{print $2}' | awk "-F-" '{print $1}')
34
35    [ -f ${SUBMIT_DIR}/../.resol ] && eval $(grep RESOL_ATM_3D ${SUBMIT_DIR}/../.resol) || RESOL_ATM_3D=96x95x19
36
37    RESOL_ATM_Z=$( echo ${RESOL_ATM_3D} | awk "-Fx" '{print $3}' )
38
39    ##-- Calendar type for LMDZ
40    case ${config_UserChoices_CalendarType} in
41        leap|gregorian)
42            CalendarTypeForLmdz=earth_366d;;
43        noleap)
44            CalendarTypeForLmdz=earth_365d;;
45        360d)
46            CalendarTypeForLmdz=earth_360d;;
47        *)
48            CalendarTypeForLmdz=earth_360d
49    esac
50
51    ##--Frequency purpose ....
52    ##--  Initialisation  ....
53    OK_instan=n
54    OK_journe=n
55    OK_mensuel=n
56    ok_hf=n
57
58    case ${config_UserChoices_PeriodLength} in
59        1Y|1y|1M|1m) OK_mensuel=y ;;
60        5D|5d|1D|1d) OK_journe=y ;;
61    esac
62
63    for frequency in ${config_ATM_WriteFrequency} ; do
64        case ${frequency} in
65            5D|5d|1D|1d) OK_journe=y ;;
66        esac
67        case ${frequency} in
68            HF|hf) 
69                ok_hf=y
70                OK_instan=y
71                ;;
72        esac
73    done
74
75    ## Read LMDZPhysics option in lmdz.card
76    IGCM_card_DefineVariableFromOption ${SUBMIT_DIR}/COMP/lmdz.card UserChoices LMDZ_Physics
77    LMDZ_Physics=${lmdz_UserChoices_LMDZ_Physics}
78
79    ## Read LMDZ_NbPeriod_adjust option in lmdz.card
80    IGCM_card_DefineVariableFromOption ${SUBMIT_DIR}/COMP/lmdz.card UserChoices LMDZ_NbPeriod_adjust
81    LMDZ_NbPeriod_adjust=${lmdz_UserChoices_LMDZ_NbPeriod_adjust}
82
83    if [ ${LMDZ_NbPeriod_adjust} -eq 0 ] ; then
84        IGCM_card_DefineVariableFromOption ${SUBMIT_DIR}/COMP/lmdz.card UserChoices LMDZ_Bands_file_name
85        LMDZ_Bands_file_name=${lmdz_UserChoices_LMDZ_Bands_file_name}
86    fi
87
88    ##  Read LMDZ_Freq_aero and LMDZ_Length_aero in lmdz.card
89    LMDZ_Freq_aero=${lmdz_UserChoices_LMDZ_Freq_aero}
90    LMDZ_Length_aero=${lmdz_UserChoices_LMDZ_Length_aero}
91
92    ##  Read LMDZ_COSP_monthly  LMDZ_COSP_daily and LMDZ_COSP_hf in lmdz.card
93    LMDZ_COSP_OK=${lmdz_UserChoices_LMDZ_COSP_OK}
94    LMDZ_COSP_monthly=${lmdz_UserChoices_LMDZ_COSP_monthly}
95    LMDZ_COSP_daily=${lmdz_UserChoices_LMDZ_COSP_daily}
96    LMDZ_COSP_hf=${lmdz_UserChoices_LMDZ_COSP_hf}
97
98    ##  Read LMDZ_NMC_monthly  LMDZ_NMC_daily and LMDZ_NMC_hf in lmdz.card
99    LMDZ_NMC_monthly=${lmdz_UserChoices_LMDZ_NMC_monthly}
100    LMDZ_NMC_daily=${lmdz_UserChoices_LMDZ_NMC_daily}
101    LMDZ_NMC_hf=${lmdz_UserChoices_LMDZ_NMC_hf}
102
103    IGCM_debug_PopStack "ATM_Initialize"
104}
105
106#-----------------------------------------------------------------
107function ATM_Update
108{
109    IGCM_debug_PushStack "ATM_Update"
110
111    case ${config_UserChoices_PeriodLength} in
112        *Y|*y) 
113#               LMDZ_ecrit_mth=30.
114               LMDZ_ecrit_mth=1mth
115               LMDZ_ecrit_ISCCP=30.
116               LMDZ_periodav=30.
117               if [ "${config_UserChoices_CalendarType}" != "360d" ] ; then
118                  echo Change calendartype in config.card. PeriodLength=1Y allowed only for CalendarType=360d
119                  exit
120               fi
121               ;;
122        *)
123               LMDZ_ecrit_mth="${PeriodLengthInDays}""day"
124               LMDZ_ecrit_ISCCP=${PeriodLengthInDays}.
125               LMDZ_periodav=${PeriodLengthInDays}.
126               ;;
127    esac
128
129    ##-- Remise ou non a zero de la date initiale de LMDZ pour le fichier run.def
130    if [ ${CumulPeriod} -eq 1 ] ; then
131        RAZ_DATE=1
132    else
133        RAZ_DATE=0
134    fi
135
136    ## To have more variables in output files for aerosols. Parameters are set in lmdz.card
137    #if [ ${CumulPeriod}%${LMDZ_Freq_aero} -le ${LMDZ_Length_aero} ]; then
138    #   if [ ${CumulPeriod}%${LMDZ_Freq_aero} -ne 0 ]; then
139    #      lev_histmth=4
140    #   else
141    #      lev_histmth=2   
142    #   fi
143    #else
144    #   lev_histmth=2
145    #fi   
146
147    ## algo : For CumulPeriod=1 ;
148    ##        IF NbPeriod_Adjust = 0, Get Bands file directly from server, store it with _0 suffix
149    ##        ELSE LMDZ_adjust=y ; save Bands file on file server ;
150    ##        For CumulPeriod=2 to LMDZ_NbPeriod_adjust ; Get Bands file from server (CumulPeriod-1) ; LMDZ_adjust=y ; save Bands file on file server ;
151    ##        For CumulPeriod > LMDZ_NbPeriod_adjust ; LMDZ_adjust=n ; Get Bands file from server (CumulPeriod=LMDZ_NbPeriod_adjust 0 to force it) ; Use Bands ;
152
153    if [ ${CumulPeriod} -eq 1 ] ; then
154        if [ ${LMDZ_NbPeriod_adjust} -eq 0 ] ; then
155            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
156            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
157            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"
158        fi
159    fi
160
161    LMDZ_adjust=n
162    [ ${CumulPeriod} -le ${LMDZ_NbPeriod_adjust} ] && LMDZ_adjust=y
163
164    RefPeriod=${LMDZ_NbPeriod_adjust} #0 to use a Bands file from Restart
165    [ ${CumulPeriod} -le ${LMDZ_NbPeriod_adjust} ] && (( RefPeriod = ${CumulPeriod} - 1 )) 
166
167    [ ${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 )
168
169    ##-- GHG forcing for the current year
170    IPCC_SOLAR=`grep Annee_${year} SOLARANDVOLCANOES_1610_2008.txt | awk -F= '{print $2}'`
171    IPCC_CO2=`grep Annee_${year} CO2_1765_2005.txt | awk -F= '{print $2}'`
172    IPCC_CH4=`grep Annee_${year} CH4_1765_2005.txt | awk -F= '{print $2}'`
173    IPCC_N2O=`grep Annee_${year} N2O_1765_2005.txt | awk -F= '{print $2}'`
174    IPCC_CFC11=`grep Annee_${year} CFC11_1765_2005.txt | awk -F= '{print $2}'`
175    IPCC_CFC12=`grep Annee_${year} CFC12_1765_2005.txt | awk -F= '{print $2}'`
176
177    ##-- For historical daily cosp must be output during 1979-2005 period
178    [ ${year} -ge 1979 ] && LMDZ_COSP_daily=y
179
180    ## physiq.def parameters modified from initial physiq_L${RESOL_ATM_Z}
181    LMDZ_sed physiq.def OK_instan   ${OK_instan}
182    LMDZ_sed physiq.def OK_journe   ${OK_journe}
183    LMDZ_sed physiq.def OK_mensuel  ${OK_mensuel}
184    LMDZ_sed physiq.def ok_hf       ${ok_hf}
185#    LMDZ_sed physiq.def ecrit_mth   ${LMDZ_ecrit_mth}
186    LMDZ_string_sed config.def _ecrit-mth_   ${LMDZ_ecrit_mth}
187    LMDZ_sed physiq.def ecrit_ISCCP ${LMDZ_ecrit_ISCCP}
188    LMDZ_sed physiq.def ok_cosp     ${LMDZ_COSP_OK}
189    LMDZ_sed physiq.def ok_mensuelCOSP  ${LMDZ_COSP_monthly}
190    LMDZ_sed physiq.def ok_journeCOSP   ${LMDZ_COSP_daily}
191    LMDZ_sed physiq.def ok_hfCOSP   ${LMDZ_COSP_hf}
192    LMDZ_sed physiq.def ok_histNMC  "${LMDZ_NMC_monthly}, ${LMDZ_NMC_daily}, ${LMDZ_NMC_hf}"
193    LMDZ_sed physiq.def solaire     ${IPCC_SOLAR}
194    LMDZ_sed physiq.def co2_ppm     ${IPCC_CO2}
195    LMDZ_sed physiq.def CH4_ppb     ${IPCC_CH4}
196    LMDZ_sed physiq.def N2O_ppb     ${IPCC_N2O}
197    LMDZ_sed physiq.def CFC11_ppt   ${IPCC_CFC11}
198    LMDZ_sed physiq.def CFC12_ppt   ${IPCC_CFC12}
199
200    ## gcm.def parameters : no change since gcm.def_${RESOL_ATM_3D} is used and already modified
201
202    ## run.def parameters
203    LMDZ_sed run.def dayref   ${InitDay}
204    LMDZ_sed run.def anneeref ${InitYear}
205    LMDZ_sed run.def calend   ${CalendarTypeForLmdz}
206    LMDZ_sed run.def nday     ${PeriodLengthInDays}
207    LMDZ_sed run.def raz_date ${RAZ_DATE}
208    LMDZ_sed run.def periodav ${LMDZ_periodav}
209    LMDZ_sed run.def adjust   ${LMDZ_adjust}
210
211    ## Read ByPass_hgardfou_teta option in lmdz.card --> divide teta* by 2 if [ $ByPass_hgardfou_teta = 1 ]
212    IGCM_card_DefineVariableFromOption ${SUBMIT_DIR}/COMP/lmdz.card UserChoices ByPass_hgardfou_teta
213    ByPass_hgardfou_teta=${lmdz_UserChoices_ByPass_hgardfou_teta}
214    if [ ${ByPass_hgardfou_teta} = y ] ; then
215        awk '{ if ($0 ~ /^teta.*=/) {split($0,a,"=") ; print a[1]"="a[2]/2"."} else print $0}' gcm.def > gcm.def.tmp
216        IGCM_sys_Mv gcm.def.tmp gcm.def
217        echo
218        IGCM_debug_Print 1 "ByPass_hgardfou_teta : ^teta*/2 in gcm.def"
219        echo
220        cat gcm.def
221        ByPass_hgardfou_teta=n
222        IGCM_card_WriteOption ${SUBMIT_DIR}/COMP/lmdz.card UserChoices ByPass_hgardfou_teta "${ByPass_hgardfou_teta}"
223    fi
224
225    ## Read ByPass_hgardfou_mats option in lmdz.card --> purmats=y 2 if [ $ByPass_hgardfou_mats = 1 ]
226    IGCM_card_DefineVariableFromOption ${SUBMIT_DIR}/COMP/lmdz.card UserChoices ByPass_hgardfou_mats
227    ByPass_hgardfou_mats=${lmdz_UserChoices_ByPass_hgardfou_mats}
228    if [ ${ByPass_hgardfou_mats} = y ] ; then
229        sed -e "s/^purmats=.*/purmats=y/" gcm.def > gcm.def.tmp
230        IGCM_sys_Mv gcm.def.tmp gcm.def
231        echo
232        IGCM_debug_Print 1 "ByPass_hgardfou_mats : purmats=y in gcm.def"
233        echo
234        cat gcm.def
235        ByPass_hgardfou_mats=n
236        IGCM_card_WriteOption ${SUBMIT_DIR}/COMP/lmdz.card UserChoices ByPass_hgardfou_mats "${ByPass_hgardfou_mats}"
237    fi
238
239    if ( ${FirstInitialize} ) ; then
240
241        if ( [ "${config_Restarts_OverRule}" = "n" ] && [ "${config_ATM_Restart}" = "n" ] ); then
242            if [ ${DRYRUN} -le 2 ] ; then
243                ##-- suppression of ozone file construction --
244                cp physiq.def physiq.def.save
245                LMDZ_sed physiq.def read_climoz 0
246                IGCM_sys_Cp ${R_EXE}/create_etat0_limit.e ${RUN_DIR}/.
247                if [ ${DRYRUN} -le 1 ] ; then
248                    ${HOST_MPIRUN_COMMAND} -np 1 ./create_etat0_limit.e
249                    IGCM_sys_Put_Out start.nc    ${R_OUT_ATM_R}/${config_UserChoices_JobName}_${PeriodDateBegin}_start.nc
250                    IGCM_sys_Put_Out startphy.nc ${R_OUT_ATM_R}/${config_UserChoices_JobName}_${PeriodDateBegin}_startphy.nc
251                fi
252                IGCM_sys_Mv physiq.def.save physiq.def
253            else
254                echo "EXECUTION of ${HOST_MPIRUN_COMMAND} -np 1 ./create_etat0_limit.e simulated"
255                echo "EXECUTION of ${HOST_MPIRUN_COMMAND} -np 1 ./create_etat0_limit.e simulated for DRYRUN = " $DRYRUN >> stack
256            fi
257        fi
258
259    fi
260
261    IGCM_debug_PopStack "ATM_Update"
262}
263
264#-----------------------------------
265function ATM_Finalize
266{
267    IGCM_debug_PushStack "ATM_Finalize"
268
269    [ ${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}
270
271    echo FINALIZE ATM !
272
273    IGCM_debug_PopStack "ATM_Finalize"
274}
Note: See TracBrowser for help on using the repository browser.