source: CONFIG/IPSLCM/IPSLCM5/branches/IPSLCM5_v2/EXP00/COMP/lmdz.driver @ 894

Last change on this file since 894 was 894, checked in by mafoipsl, 15 years ago

Add LMDZ_sed for simplification of .def updates. Keep start and startphy files in ATM/Restart directory. Keep climoz_LMDZ_1995.nc (ie climoz_LMD.nc) from database instead of create it through create_etat0_limit.

File size: 9.6 KB
Line 
1#!/bin/ksh
2#-----------------------------------------------------------------
3function LMDZ_sed
4{
5    IGCM_debug_PushStack "LMDZ_sed"
6
7    sed -e "s/^${2}\ *=.*/${2}= ${3}/" \
8        ${1} > ${1}.tmp
9    RET=$?
10    echo "LMDZ_sed : ${1} ${2} ${3}"
11    \mv ${1}.tmp ${1}
12
13    IGCM_debug_PopStack "LMDZ_sed"
14    return $RET
15}
16
17function ATM_Initialize
18{
19    IGCM_debug_PushStack "ATM_Initialize"
20
21    RESOL_ATM=$( echo $RESOL | awk "-Fx" '{print $2}' | awk "-F-" '{print $1}')
22
23    [ -f ${SUBMIT_DIR}/../.resol ] && eval $(grep RESOL_ATM_3D ${SUBMIT_DIR}/../.resol) || RESOL_ATM_3D=96x95x19
24
25    RESOL_ATM_Z=$( echo ${RESOL_ATM_3D} | awk "-Fx" '{print $3}' )
26
27    ##-- Calendar type for LMDZ
28    case ${config_UserChoices_CalendarType} in
29        leap|gregorian)
30            CalendarTypeForLmdz=earth_366d;;
31        noleap)
32            CalendarTypeForLmdz=earth_365d;;
33        360d)
34            CalendarTypeForLmdz=earth_360d;;
35        *)
36            CalendarTypeForLmdz=earth_360d
37    esac
38
39    ##--Frequency purpose ....
40    ##--  Initialisation  ....
41    OK_instan=n
42    OK_journe=n
43    OK_mensuel=n
44    ok_hf=n
45
46    case ${config_UserChoices_PeriodLength} in
47        1Y|1y|1M|1m) OK_mensuel=y ;;
48        5D|5d|1D|1d) OK_journe=y ;;
49    esac
50
51    for frequency in ${config_ATM_WriteFrequency} ; do
52        case ${frequency} in
53            5D|5d|1D|1d) OK_journe=y ;;
54        esac
55        case ${frequency} in
56            HF|hf) ok_hf=y ;;
57        esac
58    done
59
60    ##--Variables used by LMDZ in physiq.def --
61    PAT_INST=$(        grep -v ^# ${SUBMIT_DIR}/PARAM/physiq.def_L${RESOL_ATM_Z}  | grep 'OK_instan='   )
62    PAT_JOUR=$(        grep -v ^# ${SUBMIT_DIR}/PARAM/physiq.def_L${RESOL_ATM_Z}  | grep 'OK_journe='   )
63    PAT_MOIS=$(        grep -v ^# ${SUBMIT_DIR}/PARAM/physiq.def_L${RESOL_ATM_Z}  | grep 'OK_mensuel='  )
64    PAT_HFRE=$(        grep -v ^# ${SUBMIT_DIR}/PARAM/physiq.def_L${RESOL_ATM_Z}  | grep 'ok_hf='       )
65    PAT_ecrit_mth=$(   grep -v ^# ${SUBMIT_DIR}/PARAM/physiq.def_L${RESOL_ATM_Z}  | grep 'ecrit_mth='   )
66    PAT_ecrit_ISCCP=$( grep -v ^# ${SUBMIT_DIR}/PARAM/physiq.def_L${RESOL_ATM_Z}  | grep 'ecrit_ISCCP=' )
67    ##--Variables used by LMDZ in gcm.def --
68    PAT_iphysiq=$(   grep -v ^# ${SUBMIT_DIR}/PARAM/gcm.def_${RESOL_ATM_3D} | grep iphysiq  )
69    PAT_iperiod=$(   grep -v ^# ${SUBMIT_DIR}/PARAM/gcm.def_${RESOL_ATM_3D} | grep iperiod  )
70    PAT_day_step=$(  grep -v ^# ${SUBMIT_DIR}/PARAM/gcm.def_${RESOL_ATM_3D} | grep day_step )
71
72    ## Read LMDZ_NbPeriod_adjust option in ${compname}.card
73    IGCM_card_DefineVariableFromOption ${SUBMIT_DIR}/COMP/${compname}.card UserChoices LMDZ_NbPeriod_adjust
74    eval LMDZ_NbPeriod_adjust=\${${compname}_UserChoices_LMDZ_NbPeriod_adjust} > /dev/null 2>&1
75
76    if [ ${LMDZ_NbPeriod_adjust} -eq 0 ] ; then
77        IGCM_card_DefineVariableFromOption ${SUBMIT_DIR}/COMP/${compname}.card UserChoices LMDZ_Bands_file_name
78        eval LMDZ_Bands_file_name=\${${compname}_UserChoices_LMDZ_Bands_file_name} > /dev/null 2>&1
79    fi
80
81    ##-- This could be define in lmdz.card, inside section [UserChoices]
82    ##-- Otherwise we get the value in *.def
83    iperiod=$( echo ${PAT_iperiod} | awk -F= '{print $2}' )
84    iphysiq=$( echo ${PAT_iphysiq} | awk -F= '{print $2}' )
85    # day_step : number of steps per day (multiple of iperiod)
86    #(( day_step = 48 * iphysiq ))
87    day_step=$( echo ${PAT_day_step} | awk -F= '{print $2}' )
88
89    IGCM_debug_PopStack "ATM_Initialize"
90}
91
92#-----------------------------------------------------------------
93function ATM_Update
94{
95    IGCM_debug_PushStack "ATM_Update"
96
97    case ${config_UserChoices_PeriodLength} in
98        *Y|*y) 
99               LMDZ_ecrit_mth=30.
100               LMDZ_ecrit_ISCCP=30.
101               LMDZ_periodav=30.
102               if [ "${config_UserChoices_CalendarType}" != "360d" ] ; then
103                  echo Change calendartype in config.card. PeriodLength=1Y allowed only for CalendarType=360d
104                  exit
105               fi
106               ;;
107        *)
108               LMDZ_ecrit_mth=${PeriodLengthInDays}.
109               LMDZ_ecrit_ISCCP=${PeriodLengthInDays}.
110               LMDZ_periodav=${PeriodLengthInDays}.
111               ;;
112    esac
113
114    ##-- Remise ou non a zero de la date initiale de LMDZ pour le fichier run.def
115    if [ ${CumulPeriod} -eq 1 ] ; then
116        RAZ_DATE=1
117    else
118        RAZ_DATE=0
119    fi
120
121    ## algo : For CumulPeriod=1 ;
122    ##        IF NbPeriod_Adjust = 0, Get Bands file directly from server, store it with _0 suffix
123    ##        ELSE LMDZ_adjust=y ; save Bands file on file server ;
124    ##        For CumulPeriod=2 to LMDZ_NbPeriod_adjust ; Get Bands file from server (CumulPeriod-1) ; LMDZ_adjust=y ; save Bands file on file server ;
125    ##        For CumulPeriod > LMDZ_NbPeriod_adjust ; LMDZ_adjust=n ; Get Bands file from server (CumulPeriod=LMDZ_NbPeriod_adjust 0 to force it) ; Use Bands ;
126
127    if [ ${CumulPeriod} -eq 1 ] ; then
128        if [ ${LMDZ_NbPeriod_adjust} -eq 0 ] ; then
129            IGCM_sys_Get ${LMDZ_Bands_file_name} Bands_${RESOL_ATM_3D}_${NUM_PROC_ATM}prc.dat
130            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
131            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"
132        fi
133    fi
134
135    LMDZ_adjust=n
136    [ ${CumulPeriod} -le ${LMDZ_NbPeriod_adjust} ] && LMDZ_adjust=y
137
138    RefPeriod=${LMDZ_NbPeriod_adjust} #0 to use a Bands file from Restart
139    [ ${CumulPeriod} -le ${LMDZ_NbPeriod_adjust} ] && (( RefPeriod = ${CumulPeriod} - 1 )) 
140
141    [ ${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
142
143    ## Mise en forme du fichier physiq.def
144    sed -e "s/${PAT_INST}/OK_instan=${OK_instan}/"                 \
145        -e "s/${PAT_JOUR}/OK_journe=${OK_journe}/"                 \
146        -e "s/${PAT_MOIS}/OK_mensuel=${OK_mensuel}/"               \
147        -e "s/${PAT_HFRE}/ok_hf=${ok_hf}/"                         \
148        -e "s/${PAT_ecrit_mth}/ecrit_mth=${LMDZ_ecrit_mth}/"       \
149        -e "s/${PAT_ecrit_ISCCP}/ecrit_ISCCP=${LMDZ_ecrit_ISCCP}/" \
150        physiq.def > physiq.def.tmp
151    IGCM_sys_Mv physiq.def.tmp physiq.def
152
153    ## Mise en forme du fichier gcm.def
154    sed -e "s/${PAT_day_step}/day_step=${day_step}/"    \
155        -e "s/${PAT_iperiod}/iperiod=${iperiod}/"       \
156        -e "s/${PAT_iphysiq}/iphysiq=${iphysiq}/"       \
157        gcm.def > gcm.def.tmp
158    IGCM_sys_Mv gcm.def.tmp gcm.def
159
160    ## Mise en forme du fichier run.def
161    sed -e "s/_dayref_/${InitDay}/"                    \
162        -e "s/_anneeref_/${InitYear}/"                 \
163        -e "s/_calend_/${CalendarTypeForLmdz}/"        \
164        -e "s/_nday_/${PeriodLengthInDays}/"           \
165        -e "s/_raz_date_/${RAZ_DATE}/"                 \
166        -e "s/_periodav_/${LMDZ_periodav}/"            \
167        -e "s/_adjust_/${LMDZ_adjust}/"                \
168        run.def > run.def.tmp
169    IGCM_sys_Mv run.def.tmp run.def
170
171    ## Read ByPass_hgardfou_teta option in ${compname}.card --> divide teta* by 2 if [ $ByPass_hgardfou_teta = 1 ]
172    IGCM_card_DefineVariableFromOption ${SUBMIT_DIR}/COMP/${compname}.card UserChoices ByPass_hgardfou_teta
173    eval ByPass_hgardfou_teta=\${${compname}_UserChoices_ByPass_hgardfou_teta} > /dev/null 2>&1
174    if [ ${ByPass_hgardfou_teta} = y ] ; then
175        awk '{ if ($0 ~ /^teta.*=/) {split($0,a,"=") ; print a[1]"="a[2]/2"."} else print $0}' gcm.def > gcm.def.tmp
176        IGCM_sys_Mv gcm.def.tmp gcm.def
177        echo
178        IGCM_debug_Print 1 "ByPass_hgardfou_teta : ^teta*/2 in gcm.def"
179        echo
180        cat gcm.def
181        ByPass_hgardfou_teta=n
182        IGCM_card_WriteOption ${SUBMIT_DIR}/COMP/${compname}.card UserChoices ByPass_hgardfou_teta "${ByPass_hgardfou_teta}"
183    fi
184
185    ## Read ByPass_hgardfou_mats option in ${compname}.card --> purmats=y 2 if [ $ByPass_hgardfou_mats = 1 ]
186    IGCM_card_DefineVariableFromOption ${SUBMIT_DIR}/COMP/${compname}.card UserChoices ByPass_hgardfou_mats
187    eval ByPass_hgardfou_mats=\${${compname}_UserChoices_ByPass_hgardfou_mats} > /dev/null 2>&1
188    if [ ${ByPass_hgardfou_mats} = y ] ; then
189        sed -e "s/^purmats=.*/purmats=y/" gcm.def > gcm.def.tmp
190        IGCM_sys_Mv gcm.def.tmp gcm.def
191        echo
192        IGCM_debug_Print 1 "ByPass_hgardfou_mats : purmats=y in gcm.def"
193        echo
194        cat gcm.def
195        ByPass_hgardfou_mats=n
196        IGCM_card_WriteOption ${SUBMIT_DIR}/COMP/${compname}.card UserChoices ByPass_hgardfou_mats "${ByPass_hgardfou_mats}"
197    fi
198
199    if ( ${FirstInitialize} ) ; then
200
201        if ( [ "${config_Restarts_OverRule}" = "n" ] && [ "${config_ATM_Restart}" = "n" ] ); then
202            if [ ${DRYRUN} -le 2 ] ; then
203                ##-- suppression of ozone file construction --
204                cp physiq.def physiq.def.save
205                LMDZ_sed physiq.def read_climoz 0
206                IGCM_sys_Cp ${R_EXE}/create_etat0_limit.e ${RUN_DIR}/.
207                if [ ${DRYRUN} -le 1 ] ; then
208                    ./create_etat0_limit.e
209                    IGCM_sys_Put_Out start.nc    ${R_OUT_ATM_R}/${config_UserChoices_JobName}_${PeriodDateBegin}_start.nc
210                    IGCM_sys_Put_Out startphy.nc ${R_OUT_ATM_R}/${config_UserChoices_JobName}_${PeriodDateBegin}_startphy.nc
211                fi
212                IGCM_sys_Mv physiq.def.save physiq.def
213            else
214                echo "EXECUTION of ./create_etat0_limit.e simulated"
215                echo "EXECUTION of ./create_etat0_limit.e simulated for DRYRUN = " $DRYRUN >> stack
216            fi
217        fi
218
219    fi
220
221    IGCM_debug_PopStack "ATM_Update"
222}
223
224#-----------------------------------
225function ATM_Finalize
226{
227    IGCM_debug_PushStack "ATM_Finalize"
228
229    [ ${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}
230
231    echo FINALIZE ATM !
232
233    IGCM_debug_PopStack "ATM_Finalize"
234}
Note: See TracBrowser for help on using the repository browser.