source: CONFIG/LMDZOR/branches/LMDZOR_v4/LMDZOR/COMP/lmdz.driver @ 1334

Last change on this file since 1334 was 1334, checked in by jgipsl, 14 years ago

Modified lmdz.driver to read file for GHG forcing not containing year so the same driver could be used for different historical or rcp runs

File size: 10.6 KB
Line 
1# $Id$
2#
3#!/bin/ksh
4#-----------------------------------------------------------------
5function LMDZ_sed
6{
7    IGCM_debug_PushStack "LMDZ_sed"
8
9    sed -e "s/^${2}\ *=.*/${2}= ${3}/" ${1} > ${1}.tmp
10    RET=$?
11    echo "LMDZ_sed : ${1} ${2} ${3}"
12    \mv ${1}.tmp ${1}
13
14    IGCM_debug_PopStack "LMDZ_sed"
15    return $RET
16}
17
18function ATM_Initialize
19{
20    IGCM_debug_PushStack "ATM_Initialize"
21
22    RESOL_ATM=$( echo $RESOL | awk "-F-L" '{print $1}')
23
24    [ -f ${SUBMIT_DIR}/../.resol ] && eval $(grep RESOL_ATM_3D ${SUBMIT_DIR}/../.resol) || RESOL_ATM_3D=96x95x19
25
26    RESOL_ATM_Z=$( echo ${RESOL_ATM_3D} | awk "-Fx" '{print $3}' | awk "-F-" '{print $1}')
27
28    ##-- Calendar type for LMDZ
29    case ${config_UserChoices_CalendarType} in
30        leap|gregorian)
31            CalendarTypeForLmdz=earth_366d;;
32        noleap)
33            CalendarTypeForLmdz=earth_365d;;
34        360d)
35            CalendarTypeForLmdz=earth_360d;;
36        *)
37            CalendarTypeForLmdz=earth_360d
38    esac
39
40    ##- Create_etat0_limit version
41    IGCM_card_DefineVariableFromOption ${SUBMIT_DIR}/COMP/lmdz.card UserChoices CREATE
42    CREATE=${lmdz_UserChoices_CREATE}
43    echo create_etat0_limit version : ${CREATE}
44
45    ##- Default number of processor for lmdz
46    NUM_PROC_ATM=4
47    if [ X"${BATCH_NUM_PROC_TOT}" != X ] ; then
48        NUM_PROC_ATM=${BATCH_NUM_PROC_TOT}
49    fi
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 LMDZ_NbPeriod_adjust option in lmdz.card
76    IGCM_card_DefineVariableFromOption ${SUBMIT_DIR}/COMP/lmdz.card UserChoices LMDZ_NbPeriod_adjust
77    eval LMDZ_NbPeriod_adjust=\${lmdz_UserChoices_LMDZ_NbPeriod_adjust} > /dev/null 2>&1
78
79    if [ ${LMDZ_NbPeriod_adjust} -eq 0 ] ; then
80        IGCM_card_DefineVariableFromOption ${SUBMIT_DIR}/COMP/lmdz.card UserChoices LMDZ_Bands_file_name
81        eval LMDZ_Bands_file_name=\${lmdz_UserChoices_LMDZ_Bands_file_name} > /dev/null 2>&1
82    fi
83
84    ##  Read LMDZ_Freq_aero and LMDZ_Length_aero in lmdz.card
85    eval LMDZ_Freq_aero=\${lmdz_UserChoices_LMDZ_Freq_aero} > /dev/null 2>&1
86    eval LMDZ_Length_aero=\${lmdz_UserChoices_LMDZ_Length_aero} > /dev/null 2>&1
87
88    ##  Read LMDZ_COSP_monthly  LMDZ_COSP_daily and LMDZ_COSP_hf in lmdz.card
89    eval LMDZ_COSP_OK=\${lmdz_UserChoices_LMDZ_COSP_OK} > /dev/null 2>&1
90    eval LMDZ_COSP_monthly=\${lmdz_UserChoices_LMDZ_COSP_monthly} > /dev/null 2>&1
91    eval LMDZ_COSP_daily=\${lmdz_UserChoices_LMDZ_COSP_daily} > /dev/null 2>&1
92    eval LMDZ_COSP_hf=\${lmdz_UserChoices_LMDZ_COSP_hf} > /dev/null 2>&1
93
94    ##  Read LMDZ_NMC_monthly  LMDZ_NMC_daily and LMDZ_NMC_hf in lmdz.card
95    eval LMDZ_NMC_monthly=\${lmdz_UserChoices_LMDZ_NMC_monthly} > /dev/null 2>&1
96    eval LMDZ_NMC_daily=\${lmdz_UserChoices_LMDZ_NMC_daily} > /dev/null 2>&1
97    eval LMDZ_NMC_hf=\${lmdz_UserChoices_LMDZ_NMC_hf} > /dev/null 2>&1
98
99    IGCM_debug_PopStack "ATM_Initialize"
100}
101
102#-----------------------------------------------------------------
103function ATM_Update
104{
105    IGCM_debug_PushStack "ATM_Update"
106
107    case ${config_UserChoices_PeriodLength} in
108        *Y|*y) 
109               LMDZ_ecrit_mth=30.
110               LMDZ_ecrit_ISCCP=30.
111               LMDZ_periodav=30.
112               if [ "${config_UserChoices_CalendarType}" != "360d" ] ; then
113                  echo Change calendartype in config.card. PeriodLength=1Y allowed only for CalendarType=360d
114                  exit
115               fi
116               ;;
117        *)
118               LMDZ_ecrit_mth=${PeriodLengthInDays}.
119               LMDZ_ecrit_ISCCP=${PeriodLengthInDays}.
120               LMDZ_periodav=${PeriodLengthInDays}.
121               ;;
122    esac
123
124    ##-- Remise ou non a zero de la date initiale de LMDZ pour le fichier run.def
125    if [ ${CumulPeriod} -eq 1 ] ; then
126        RAZ_DATE=1
127    else
128        RAZ_DATE=0
129    fi
130
131    ## To have more variables in output files for aerosols. Parameters are set in lmdz.card
132    #if [ ${CumulPeriod}%${LMDZ_Freq_aero} -le ${LMDZ_Length_aero} ]; then
133    #   if [ ${CumulPeriod}%${LMDZ_Freq_aero} -ne 0 ]; then
134    #      lev_histmth=4
135    #   else
136    #      lev_histmth=2   
137    #   fi
138    #else
139    #   lev_histmth=2
140    #fi   
141
142    ## algo : For CumulPeriod=1 ;
143    ##        IF NbPeriod_Adjust = 0, Get Bands file directly from server, store it with _0 suffix
144    ##        ELSE LMDZ_adjust=y ; save Bands file on file server ;
145    ##        For CumulPeriod=2 to LMDZ_NbPeriod_adjust ; Get Bands file from server (CumulPeriod-1) ; LMDZ_adjust=y ; save Bands file on file server ;
146    ##        For CumulPeriod > LMDZ_NbPeriod_adjust ; LMDZ_adjust=n ; Get Bands file from server (CumulPeriod=LMDZ_NbPeriod_adjust 0 to force it) ; Use Bands ;
147
148    if [ ${CumulPeriod} -eq 1 ] ; then
149        if [ ${LMDZ_NbPeriod_adjust} -eq 0 ] ; then
150            if [ ! X${LMDZ_Bands_file_name} = X] ; then
151                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
152                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
153                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"
154            fi
155        fi
156    fi
157
158    LMDZ_adjust=n
159    [ ${CumulPeriod} -le ${LMDZ_NbPeriod_adjust} ] && LMDZ_adjust=y
160
161    RefPeriod=${LMDZ_NbPeriod_adjust} #0 to use a Bands file from Restart
162    [ ${CumulPeriod} -le ${LMDZ_NbPeriod_adjust} ] && (( RefPeriod = ${CumulPeriod} - 1 )) 
163
164    [ ${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 )
165
166    ## physiq.def parameters modified from initial physiq_L${RESOL_ATM_Z}
167    LMDZ_sed physiq.def OK_instan   ${OK_instan}
168    LMDZ_sed physiq.def OK_journe   ${OK_journe}
169    LMDZ_sed physiq.def OK_mensuel  ${OK_mensuel}
170#    LMDZ_sed physiq.def lev_histmth ${lev_histmth}
171    LMDZ_sed physiq.def ok_hf       ${ok_hf}
172    LMDZ_sed physiq.def ecrit_mth   ${LMDZ_ecrit_mth}
173    LMDZ_sed physiq.def ecrit_ISCCP ${LMDZ_ecrit_ISCCP}
174    LMDZ_sed physiq.def ok_cosp     ${LMDZ_COSP_OK}
175    LMDZ_sed physiq.def ok_mensuelCOSP  ${LMDZ_COSP_monthly}
176    LMDZ_sed physiq.def ok_journeCOSP   ${LMDZ_COSP_daily}
177    LMDZ_sed physiq.def ok_hfCOSP   ${LMDZ_COSP_hf}
178    LMDZ_sed physiq.def ok_histNMC  "${LMDZ_NMC_monthly}, ${LMDZ_NMC_daily}, ${LMDZ_NMC_hf}"
179
180    ##-- GHG forcing for the current year if forcing file is availible
181    if [ -f SOLARANDVOLCANOES.txt ] ; then
182        IPCC_SOLAR=`grep Annee_${year} SOLARANDVOLCANOES.txt | awk -F= '{print $2}'`
183        LMDZ_sed physiq.def solaire     ${IPCC_SOLAR}
184    fi
185    if [ -f CO2.txt ] ; then
186        IPCC_CO2=`grep Annee_${year} CO2.txt | awk -F= '{print $2}'`
187        LMDZ_sed physiq.def co2_ppm     ${IPCC_CO2}
188    fi
189    if [ -f CH4.txt ] ; then
190        IPCC_CH4=`grep Annee_${year} CH4.txt | awk -F= '{print $2}'`
191        LMDZ_sed physiq.def CH4_ppb     ${IPCC_CH4}
192    fi
193    if [ -f N2O.txt ] ; then
194        IPCC_N2O=`grep Annee_${year} N2O.txt | awk -F= '{print $2}'`
195        LMDZ_sed physiq.def N2O_ppb     ${IPCC_N2O}
196    fi
197    if [ -f CFC11.txt ] ; then
198        IPCC_CFC11=`grep Annee_${year} CFC11.txt | awk -F= '{print $2}'`
199        LMDZ_sed physiq.def CFC11_ppt   ${IPCC_CFC11}
200    fi
201    if [ -f CFC12.txt ] ; then
202        IPCC_CFC12=`grep Annee_${year} CFC12.txt | awk -F= '{print $2}'`
203        LMDZ_sed physiq.def CFC12_ppt   ${IPCC_CFC12}
204    fi
205
206    ## Other specific parameters to this experience
207    if [ ! X${lmdz_UserChoices_aer_type} = X ] ; then
208        LMDZ_sed physiq.def aer_type ${lmdz_UserChoices_aer_type}
209    fi
210    if [ ! X${lmdz_UserChoices_pmagic} = X ] ; then
211        LMDZ_sed physiq.def pmagic   ${lmdz_UserChoices_pmagic}
212    fi
213
214    if [ ! X${lmdz_UserChoices_ok_guide} = X ] ; then
215        LMDZ_sed guide.def ok_guide  ${lmdz_UserChoices_ok_guide}
216    fi
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# No filtre fft in case of zoom, 280x280x39-ZAf contains zoom
230    if [ ${RESOL_ATM_3D} = "280x280x39-ZAf" ] || [ ${RESOL_ATM_3D} = "360x180x19-ZIn" ] ; then
231         LMDZ_sed run.def use_filtre_fft n
232    fi
233
234    ## Read ByPass_hgardfou_teta option in lmdz.card --> divide teta* by 2 if [ $ByPass_hgardfou_teta = 1 ]
235    IGCM_card_DefineVariableFromOption ${SUBMIT_DIR}/COMP/lmdz.card UserChoices ByPass_hgardfou_teta
236    eval ByPass_hgardfou_teta=\${lmdz_UserChoices_ByPass_hgardfou_teta} > /dev/null 2>&1
237    if [ ${ByPass_hgardfou_teta} = y ] ; then
238        awk '{ if ($0 ~ /^teta.*=/) {split($0,a,"=") ; print a[1]"="a[2]/2"."} else print $0}' gcm.def > gcm.def.tmp
239        IGCM_sys_Mv gcm.def.tmp gcm.def
240        echo
241        IGCM_debug_Print 1 "ByPass_hgardfou_teta : ^teta*/2 in gcm.def"
242        echo
243        cat gcm.def
244        ByPass_hgardfou_teta=n
245        IGCM_card_WriteOption ${SUBMIT_DIR}/COMP/lmdz.card UserChoices ByPass_hgardfou_teta "${ByPass_hgardfou_teta}"
246    fi
247
248    ## Read ByPass_hgardfou_mats option in lmdz.card --> purmats=y 2 if [ $ByPass_hgardfou_mats = 1 ]
249    IGCM_card_DefineVariableFromOption ${SUBMIT_DIR}/COMP/lmdz.card UserChoices ByPass_hgardfou_mats
250    eval ByPass_hgardfou_mats=\${lmdz_UserChoices_ByPass_hgardfou_mats} > /dev/null 2>&1
251    if [ ${ByPass_hgardfou_mats} = y ] ; then
252        sed -e "s/^purmats=.*/purmats=y/" gcm.def > gcm.def.tmp
253        IGCM_sys_Mv gcm.def.tmp gcm.def
254        echo
255        IGCM_debug_Print 1 "ByPass_hgardfou_mats : purmats=y in gcm.def"
256        echo
257        cat gcm.def
258        ByPass_hgardfou_mats=n
259        IGCM_card_WriteOption ${SUBMIT_DIR}/COMP/lmdz.card UserChoices ByPass_hgardfou_mats "${ByPass_hgardfou_mats}"
260    fi
261
262    IGCM_debug_PopStack "ATM_Update"
263}
264
265#-----------------------------------
266function ATM_Finalize
267{
268    IGCM_debug_PushStack "ATM_Finalize"
269
270    [ ${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}
271
272    echo FINALIZE ATM !
273
274    IGCM_debug_PopStack "ATM_Finalize"
275}
Note: See TracBrowser for help on using the repository browser.