source: lmdz_wrf/trunk/tools/WRF_launch.bash @ 222

Last change on this file since 222 was 29, checked in by lfita, 10 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: 6.7 KB
RevLine 
[29]1#!/bin/bash
2## g.e # WRF_launch.bash 19791201000000 19810101000000 28 /d4/lflmd/etudes/WRF_LMDZ/WaquaL/WRF/control
3## g.e # WRF_launch.bash 19791201000000 19810101000000 month /d4/lflmd/etudes/WRF_LMDZ/WaquaL/WRF/control
4if test $1 = '-h'; then
5  echo "********************************"
6  echo "*** Launching WRF simulation ***"
7  echo "********************************"
8  echo "WRF_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}
94
95########    #######
96## MAIN
97    #######
98
99  rootsh=`pwd`
100  errmsg='ERROR -- error -- ERROR -- error'
101
102  inidate=$1
103  enddate=$2
104  freq=$3
105  odir=$4
106  if test $# -eq 5; then
107    restart=$5
108  else
109    restart='false'
110  fi
111
112  wrftmplt=${odir}'/namelist.input.template'
113
114####### ###### #### ### ## #
115
116  export PATH=/u/lflmd/bin/gcc_Python-2.7.5/bin:${PATH}
117  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
118
119  if test ! -f ${wrftmplt}; then
120    echo $errmsg
121    echo "File '"${wrftmplt}"' does not exist!!!!"
122    exit
123  fi
124
125  cd ${odir}
126  rm namelist.input >& /dev/null
127
128  idate=${inidate}
129  isubperiod=1
130
131  if test ${restart} == 'true'; then
132    echo "Continuing the simulation from the last wrfrst"
133  else
134    rm -r ${odir}/wrfout
135    rm run_wrf_??????????????-??????????????.log
136    mkdir -p ${odir}/wrfout
137  fi
138
139  while test ${idate} -le ${enddate}; do
140    if test ${freq} = 'month'; then
141      nextdate=`date +%Y%m%d%H%M%S -d"${idate:0:8} 1 month"`
142      secmonths=`seconds_between_dates ${idate} ${nextdate}`
143      freqV=`expr ${secmonths} / 24 / 3600`
144    else
145      nextdate=`date +%Y%m%d%H%M%S -d"${idate:0:8} ${freq} days"`
146      freqV=${freq}
147    fi
148    if test ${nextdate} -gt ${enddate}; then break; fi
149    period=${idate}'-'${nextdate}
150# Checking for restart
151##
152    runperiod=true
153    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
154      runperiod=false
155    else
156      echo "  resuming the simulation from: "${idate:0:4}-${idate:4:2}-${idate:6:2}_${idate:8:2}:${idate:10:2}:${idate:12:2}
157      cp ${odir}/wrfout/wrfrst_d01_${idate:0:4}-${idate:4:2}-${idate:6:2}_${idate:8:2}:${idate:10:2}:${idate:12:2} ${odir}
158    fi
159
160    if ${runperiod}; then
161      echo "    "${isubperiod}" "${period}
162
163      create_WRFnamelist ${wrftmplt} ${idate} ${nextdate} ${freqV} ${isubperiod}
164
165      ./wrf.exe >& ${odir}/run_wrf_${period}.log
166      ewrf=$?
167
168      if test ${ewrf} -ne 0; then
169        echo ${errmsg}
170        echo "  wrf.exe failed !!!"
171        cat run_wrf_${period}.log
172        exit
173      fi
174# Moving outputs
175##
176      mv namelist.input ${odir}/wrfout/namelist.input_${period}
177      mv namelist.output ${odir}/wrfout/namelist.output_${period}
178      mv wrfout_d* ${odir}/wrfout
179      mv run_wrf_${period}.log ${odir}/wrfout
180
181      if test ${isubperiod} -gt 1; then
182        mv wrfrst*${idate:0:4}-${idate:4:2}-${idate:6:2}* ${odir}/wrfout
183      fi
184    fi
185   
186    lastdate=${idate}
187    idate=${nextdate}
188    isubperiod=`expr ${isubperiod} + 1`
189
190# end of dates
191  done
192
193  isubperiod=`expr ${isubperiod} + 1`
194  if test ${nextdate} -gt ${enddate} && test ${idate} -ne ${enddate}; then
195    nextdate=${enddate}
196    period=${idate}'-'${nextdate}
197    echo "last: "${period}
198    secmonths=`seconds_between_dates ${idate} ${nextdate}`
199    freqV=`expr ${secmonths} / 24 / 3600`
200    create_WRFnamelist ${wrftmplt} ${idate} ${nextdate} ${freqV} ${isubperiod}
201
202    ./wrf.exe >& ${odir}/run_wrf_${period}.log
203    ewrf=$?
204    if test ${ewrf} -ne 0; then
205      echo ${errmsg}
206      echo "  wrf.exe failed !!!"
207      cat run_wrf_${period}.log
208      exit
209    fi
210# Moving outputs
211##
212    mv namelist.input ${odir}/wrfout/namelist.input_${period}
213    mv namelist.output ${odir}/wrfout/namelist.output_${period}
214    mv wrfout_d* ${odir}/wrfout
215    mv run_wrf_${period}.log ${odir}/wrfout
216
217    if test ${isubperiod} -gt 1; then
218      mv wrfrst*${idate:0:4}-${idate:4:2}-${idate:6:2}* ${odir}/wrfout
219    fi
220  fi
221
222fi
Note: See TracBrowser for help on using the repository browser.