source: lmdz_wrf/trunk/tools/WRF+LMDZ_launch.bash @ 39

Last change on this file since 39 was 29, checked in by lfita, 11 years ago

Adding a series of different files to make automatic the running of simulations:

  • content.txt: file describing the content of the folder

.BASH_

  • blank_WRF.bash: Shell script to prepare WRF folders to run all the WRF framework
  • LMDZ_launch.bash: Shell to run a LMDZ simulation
  • prepare_compilation.bash: Shell to prepare a series of folders to run an experiment
  • WRF_launch.bash: Shell to run a WRF simulation
  • WRF+LMDZ_launch.bash: Shell to run a LMDZ+WRF simulation

.TEMPLATE

  • config.def.template: template file of the LMDZ 'config.def' file
  • namelist.input.template: template of the WRF 'namelist.input'
  • run.def.template: template file of the LMDZ 'run.def' file
  • Property svn:executable set to *
File size: 9.0 KB
Line 
1#!/bin/bash
2## g.e. # WRF+LMDZ_launch.bash 19790101000000 19800101000000 28 /d4/lflmd/etudes/WRF_LMDZ/test_phylmd/AR40.0/control
3## g.e. # WRF+LMDZ_launch.bash 19790101000000 19800101000000 month /d4/lflmd/etudes/WRF_LMDZ/test_phylmd/AR40.0/control
4if test $1 = '-h'; then
5  echo "*************************************"
6  echo "*** Launching WRF+LMDZ simulation ***"
7  echo "*************************************"
8  echo "WRF+LMDZ_launch.bash [inidate] [enddate] [freq] [odir]"
9  echo "  [inidate]: initial date [YYYY][MM][DD][HH][MI][SS]" 
10  echo "  [enddate]: final date [YYYY][MM][DD][HH][MI][SS]"
11  echo "  [freq]: frequency restarts [DD] if it is 'month' real month frequency will be used"
12  echo "  [odir]: folder for the outputs"
13  echo "  [restart]: 'true' for a resume a simulation"
14else
15
16seconds_between_dates() {
17# Functino to provide the seconds between two dates
18  date1=$1
19  date2=$2
20
21  # Date1
22  ##
23  YMD1=${date1:0:8}
24  hours1=${date1:8:2}
25  minutes1=${date1:10:2}
26  seconds1=${date1:12:2}
27  hours1=`(expr $hours1 '*' 3600)`
28  minutes1=`(expr $minutes1 '*' 60)`
29  seconds1=`(expr $hours1 + $minutes1 + $seconds1)`
30  sec1=`(date +%s -u -d"$YMD1 $seconds1 seconds")`
31
32  # Date2
33  ##
34  YMD2=${date2:0:8}
35  hours2=${date2:8:2}
36  minutes2=${date2:10:2}
37  seconds2=${date2:12:2}
38  hours2=`(expr $hours2 '*' 3600)`
39  minutes2=`(expr $minutes2 '*' 60)`
40  seconds2=`(expr $hours2 + $minutes2 + $seconds2)`
41  sec2=`(date +%s -u -d"$YMD2 $seconds2 seconds")`
42  seconds=`(expr $sec2 - $sec1)`
43
44  echo $seconds
45}
46
47create_WRFnamelist() {
48# Function to create namelist.input from a nameslit WRF template
49#   nlistmplt: template of the namelist.input
50#   id: initial date ([YYYYMMDDHHMISS] format)
51#   ed: final date ([YYYYMMDDHHMISS] format)
52#   fr: frquency (in days) of the restarts
53#   it: number of sub-period within the simulation experiment
54
55  nlisttmplt=$1
56  id=$2
57  ed=$3
58  fr=$4
59  it=$5
60
61  frH=`expr ${fr} '*' 24`
62
63  dThist=`cat ${nlisttmplt} | grep history_interval | awk '{print $3}' | tr ',' ' ' |\
64     awk '{print $1*60}'`
65
66  secsPeriod=`seconds_between_dates ${id} ${ed}`
67  Nouts=`expr ${secsPeriod} / ${dThist}`
68
69  cp ${nlisttmplt} namelist.input
70  sed -e 's/@iyear@/'${id:0:4}'/g' namelist.input >& tmpA
71  sed -e 's/@imonth@/'${id:4:2}'/g' tmpA >& tmpB
72  sed -e 's/@iday@/'${id:6:2}'/g' tmpB >& tmpA
73  sed -e 's/@ihour@/'${id:8:2}'/g' tmpA >& tmpB
74  sed -e 's/@iminute@/'${id:10:2}'/g' tmpB >& tmpA
75  sed -e 's/@isecond@/'${id:12:2}'/g' tmpA >& tmpB
76
77  sed -e 's/@eyear@/'${ed:0:4}'/g' tmpB >& tmpA
78  sed -e 's/@emonth@/'${ed:4:2}'/g' tmpA >& tmpB
79  sed -e 's/@eday@/'${ed:6:2}'/g' tmpB >& tmpA
80  sed -e 's/@ehour@/'${ed:8:2}'/g' tmpA >& tmpB
81  sed -e 's/@eminute@/'${ed:10:2}'/g' tmpB >& tmpA
82  sed -e 's/@esecond@/'${ed:12:2}'/g' tmpA >& tmpB
83  sed -e 's/@Nouts@/'${Nouts}'/g' tmpB >& tmpA
84  sed -e 's/@freqH@/'${frH}'/g' tmpA >& tmpB
85  if test ${it} -gt 1; then
86    sed -e 's/@restart@/.true./g' tmpB >& namelist.input
87  else
88    sed -e 's/@restart@/.false./g' tmpB >& namelist.input
89  fi
90
91  rm tmpA tmpB
92}
93
94create_LMDZnamelist() {
95# Function to create run.def from a LMDZ template
96#   nlistmplt: template of the run.def
97#   id: initial date (in [YYYY][MM][DD][HH][MI][SS] format)
98#   fr: frquency (in days) of the restarts
99
100  nlisttmplt=$1
101  id=$2
102  fr=$3
103
104  day=`date -u "+%j" -d"${id:0:8}"`
105
106  cp ${nlisttmplt} run.def
107  sed -e 's/@freq@/'${fr}'/g' run.def >& tmpA
108  sed -e 's/@iyear@/'${id:0:4}'/g' tmpA >& tmpB
109  sed -e 's/@iday@/'${day}'/g' tmpB >& run.def
110
111  cp config.def.template tmpA
112  sed -e 's/@daysmonth@/'${fr}'/g' tmpA >& config.def
113
114  rm tmpA tmpB
115}
116
117########    #######
118## MAIN
119    #######
120
121  rootsh=`pwd`
122  errmsg='ERROR -- error -- ERROR -- error'
123
124  inidate=$1
125  enddate=$2
126  freq=$3
127  odir=$4
128  if test $# -eq 5; then
129    restart=$5
130  else
131    restart='false'
132  fi
133
134  wrftmplt=${odir}'/namelist.input.template'
135  lmdztmplt=${odir}'/run.def.template'
136
137####### ###### #### ### ## #
138
139  export PATH=/u/lflmd/bin/gcc_Python-2.7.5/bin:${PATH}
140  export LD_LIBRARY_PATH=/u/lflmd/bin/gcc_netcdf-4.3.0/lib:/opt/intel/composer_xe_2011_sp1.9.293/compiler/lib/intel64:/opt/intel/composer_xe_2011_sp1.9.293/compiler/lib/intel64:/opt/intel/composer_xe_2011_sp1.9.293/mkl/lib/intel64:/opt/intel/composer_xe_2011_sp1.9.293/tbb/lib/intel64//cc4.1.0_libc2.4_kernel2.6.16.21:/usr/local/lib:/opt/intel/composer_xe_2011_sp1.9.293/debugger/lib/intel64:/opt/intel/composer_xe_2011_sp1.9.293/mpirt/lib/intel64
141
142  if test ! -f ${wrftmplt}; then
143    echo $errmsg
144    echo "File '"${wrftmplt}"' does not exist!!!!"
145    exit
146  fi
147
148  if test ! -f ${lmdztmplt}; then
149    echo $errmsg
150    echo "File '"${lmdztmplt}"' does not exist!!!!"
151    exit
152  fi
153
154  idate=${inidate}
155  isubperiod=1
156
157  if test ${restart} == 'true'; then
158    echo "Continuing the simulation from the last wrfrst"
159  else
160    rm -r ${odir}/wrfout
161    rm -r ${odir}/lmdzout
162    rm run_wrf_??????????????-??????????????.log
163    mkdir -p ${odir}/wrfout
164    mkdir -p ${odir}/lmdzout
165  fi
166
167  while test ${idate} -le ${enddate}; do
168    if test ${freq} = 'month'; then
169      nextdate=`date +%Y%m%d%H%M%S -d"${idate:0:8} 1 month"`
170      secmonths=`seconds_between_dates ${idate} ${nextdate}`
171      freqV=`expr ${secmonths} / 24 / 3600`
172    else
173      nextdate=`date +%Y%m%d%H%M%S -d"${idate:0:8} ${freq} days"`
174      freqV=${freq}
175    fi
176    if test ${nextdate} -gt ${enddate}; then break; fi
177    period=${idate}'-'${nextdate}
178# Checking for restart
179##
180    runperiod=true
181    if test ${restart} == 'true' && test -f ${odir}/wrfout/wrfrst_d01_${nextdate:0:4}-${nextdate:4:2}-${nextdate:6:2}_${nextdate:8:2}:${nextdate:10:2}:${nextdate:12:2}; then
182      runperiod=false
183      cp ${odir}/wrfout/wrfrst_d01_${idate:0:4}-${idate:4:2}-${idate:6:2}_${idate:8:2}:${idate:10:2}:${idate:12:2} ${odir}
184      echo "  resuming the simulation from: "${idate:0:4}-${idate:4:2}-${idate:6:2}_${idate:8:2}:${idate:10:2}:${idate:12:2}
185    else
186      runperiod=true
187    fi
188
189    if ${runperiod}; then
190      echo "    "${isubperiod}" "${period}
191
192      create_WRFnamelist ${wrftmplt} ${idate} ${nextdate} ${freqV} ${isubperiod}
193      create_LMDZnamelist ${lmdztmplt} ${idate} ${freqV}
194
195      ./wrf.exe >& ${odir}/run_wrf_${period}.log
196      ewrf=$?
197
198      if test ${ewrf} -ne 0; then
199        echo ${errmsg}
200        echo "  wrf.exe failed !!!"
201        cat run_wrf_${period}.log
202        exit
203      fi
204# Moving outputs
205##
206      mv namelist.input ${odir}/wrfout/namelist.input_${period}
207      mv namelist.output ${odir}/wrfout/namelist.output_${period}
208      mv wrfout_d* ${odir}/wrfout
209      mv run_wrf_${period}.log ${odir}/wrfout
210      mv run.def ${odir}/lmdzout/run.def_${period}
211      mv histmth.nc ${odir}/lmdzout/histmth_${period}.nc
212      mv histday.nc ${odir}/lmdzout/histday_${period}.nc
213      mv histins.nc ${odir}/lmdzout/histins_${period}.nc
214
215      if test ${isubperiod} -gt 1; then
216        mv wrfrst*${idate:0:4}-${idate:4:2}-${idate:6:2}* ${odir}/wrfout
217      fi
218    fi
219   
220    lastdate=${idate}
221    idate=${nextdate}
222    isubperiod=`expr ${isubperiod} + 1`
223
224# end of dates
225  done
226
227  isubperiod=`expr ${isubperiod} + 1`
228  if test ${nextdate} -gt ${enddate} && test ${idate} -ne ${enddate}; then
229    nextdate=${enddate}
230    period=${idate}'-'${nextdate}
231    echo "last: "${period}
232    secmonths=`seconds_between_dates ${idate} ${nextdate}`
233    freqV=`expr ${secmonths} / 24 / 3600`
234    create_WRFnamelist ${wrftmplt} ${idate} ${nextdate} ${freqV} ${isubperiod}
235    create_LMDZnamelist ${lmdztmplt} ${idate} ${freqV}
236
237    ./wrf.exe >& ${odir}/run_wrf_${period}.log
238    ewrf=$?
239    if test ${ewrf} -ne 0; then
240      echo ${errmsg}
241      echo "  wrf.exe failed !!!"
242      cat run_wrf_${period}.log
243      exit
244    fi
245# Moving outputs
246##
247    mv namelist.input ${odir}/wrfout/namelist.input_${period}
248    mv namelist.output ${odir}/wrfout/namelist.output_${period}
249    mv wrfout_d* ${odir}/wrfout
250    mv run_wrf_${period}.log ${odir}/wrfout
251    mv run.def ${odir}/lmdzout/run.def_${period}
252    mv histmth.nc ${odir}/lmdzout/histmth_${period}.nc
253    mv histday.nc ${odir}/lmdzout/histday_${period}.nc
254    mv histins.nc ${odir}/lmdzout/histins_${period}.nc
255
256    if test ${isubperiod} -gt 1; then
257      mv wrfrst*${idate:0:4}-${idate:4:2}-${idate:6:2}* ${odir}/wrfout
258    fi
259  fi
260
261# Post-process LMDZ hist files
262##
263
264  dimx=`cat ${odir}/wrfout/namelist.input_${period} | grep e_we | awk '{print $3}' | tr ',' ' ' | awk '{print $1 - 1}'`
265  dimy=`cat ${odir}/wrfout/namelist.input_${period} | grep e_sn | awk '{print $3}' | tr ',' ' ' | awk '{print $1 - 1}'`
266  for file in ${odir}/lmdzout/hist*.nc; do
267    filen=`basename ${file}`
268    filenH=`echo ${filen} | tr '.' ' ' | awk '{print $1}'`
269    python ${HOME}/PY/WRFLMDZ_regularout.py -f ${file} -d ${dimx},${dimy} -o ${odir}/lmdzout/${filenH}_reg.nc
270    rm ${file}
271    d1=`echo ${filen} | tr '_' ' ' | awk '{print $2}' | tr '-' ' ' | awk '{print $1}'`
272    totsecs=`seconds_between_dates 19491201000000 ${d1}`
273
274    python ${HOME}/climatescripts/python/nc_var.py -f ${odir}/lmdzout/${filenH}_reg.nc -o valmod -S sumc,${totsecs} -v time
275    python ${HOME}/climatescripts/python/nc_var.py -f ${odir}/lmdzout/${filenH}_reg.nc -o addvattrk -S 'units|seconds!since!1949-12-01!00:00:00|S' -v time
276  done
277
278fi
Note: See TracBrowser for help on using the repository browser.