1 | #!/bin/bash |
---|
2 | ## e.g. # LMDZ_launch.bash 19790101000000 19800101000000 28 32:32:39 /d4/lflmd/etudes/WRF_LMDZ/lmdz/AR40.0/control |
---|
3 | ## e.g. # LMDZ_launch.bash 19790101000000 19800101000000 month 32:32:39 /d4/lflmd/etudes/WRF_LMDZ/lmdz/AR40.0/control |
---|
4 | if test $1 = '-h'; then |
---|
5 | echo "*********************************" |
---|
6 | echo "*** Launching LMDZ simulation ***" |
---|
7 | echo "*********************************" |
---|
8 | echo "LMDZ_launch.bash [inidate] [enddate] [freq] [dim] [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 " [dim]: dimensions (dimx:dimy:dimz)" |
---|
13 | echo " [odir]: folder for the outputs)" |
---|
14 | else |
---|
15 | |
---|
16 | seconds_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 | |
---|
47 | create_LMDZnamelist() { |
---|
48 | # Function to create run.def from a LMDZ template |
---|
49 | # nlistmplt: template of the run.def |
---|
50 | # id: initial date (in [YYYY][MM][DD][HH][MI][SS] format) |
---|
51 | # fr: frquency (in days) of the restarts |
---|
52 | |
---|
53 | nlisttmplt=$1 |
---|
54 | id=$2 |
---|
55 | fr=$3 |
---|
56 | |
---|
57 | day=`date -u "+%j" -d"${id:0:8}"` |
---|
58 | |
---|
59 | cp ${nlisttmplt} run.def |
---|
60 | sed -e 's/@freq@/'${fr}'/g' run.def >& tmpA |
---|
61 | sed -e 's/@iyear@/'${id:0:4}'/g' tmpA >& tmpB |
---|
62 | sed -e 's/@iday@/'${day}'/g' tmpB >& run.def |
---|
63 | |
---|
64 | cp config.def.template tmpA |
---|
65 | sed -e 's/@daysmonth@/'${fr}'/g' tmpA >& config.def |
---|
66 | |
---|
67 | rm tmpA tmpB |
---|
68 | } |
---|
69 | |
---|
70 | ######## ####### |
---|
71 | ## MAIN |
---|
72 | ####### |
---|
73 | |
---|
74 | export LD_LIBRARY_PATH=/u/lflmd/bin/gcc_netcdf-4.3.0/lib:${LD_LIBRARY_PATH} |
---|
75 | |
---|
76 | rootsh=`pwd` |
---|
77 | errmsg='ERROR -- error -- ERROR -- error' |
---|
78 | |
---|
79 | inidate=$1 |
---|
80 | enddate=$2 |
---|
81 | freq=$3 |
---|
82 | dim=$4 |
---|
83 | odir=$5 |
---|
84 | |
---|
85 | lmdztmplt='run.def.template' |
---|
86 | |
---|
87 | ####### ###### #### ### ## # |
---|
88 | |
---|
89 | dimx=`echo ${dim} | tr ':' ' ' | awk '{print $1 - 1}'` |
---|
90 | dimy=`echo ${dim} | tr ':' ' ' | awk '{print $2 - 1}'` |
---|
91 | dimz=`echo ${dim} | tr ':' ' ' | awk '{print $3}'` |
---|
92 | |
---|
93 | export PATH=/u/lflmd/bin/gcc_Python-2.7.5/bin:${PATH} |
---|
94 | 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 |
---|
95 | |
---|
96 | if test ! -f ${lmdztmplt}; then |
---|
97 | echo $errmsg |
---|
98 | echo "File '"${lmdztmplt}"' does not exist!!!!" |
---|
99 | exit |
---|
100 | fi |
---|
101 | |
---|
102 | idate=${inidate} |
---|
103 | isubperiod=1 |
---|
104 | |
---|
105 | rm -r ${odir}/lmdzout |
---|
106 | rm run_lmdz_??????????????-??????????????.log |
---|
107 | mkdir -p ${odir}/lmdzout |
---|
108 | |
---|
109 | while test ${idate} -le ${enddate}; do |
---|
110 | if test ${freq} = 'month'; then |
---|
111 | nextdate=`date +%Y%m%d%H%M%S -d"${idate:0:8} 1 month"` |
---|
112 | secmonths=`seconds_between_dates ${idate} ${nextdate}` |
---|
113 | freqV=`expr ${secmonths} / 24 / 3600` |
---|
114 | else |
---|
115 | nextdate=`date +%Y%m%d%H%M%S -d"${idate:0:8} ${freq} days"` |
---|
116 | freqV=${freq} |
---|
117 | fi |
---|
118 | if test ${nextdate} -gt ${enddate}; then break; fi |
---|
119 | period=${idate}'-'${nextdate} |
---|
120 | echo ${isubperiod}" "${period} |
---|
121 | |
---|
122 | create_LMDZnamelist ${lmdztmplt} ${idate} ${freqV} |
---|
123 | |
---|
124 | ./lmdz.exe >& ${odir}/run_lmdz_${period}.log |
---|
125 | elmdz=$? |
---|
126 | |
---|
127 | if test ${elmdz} -ne 0; then |
---|
128 | echo ${errmsg} |
---|
129 | echo " lmdz.exe failed !!!" |
---|
130 | cat run_lmdz_${period}.log |
---|
131 | exit |
---|
132 | fi |
---|
133 | # Moving outputs |
---|
134 | ## |
---|
135 | mv ${odir}/run_lmdz_${period}.log ${odir}/lmdzout/run_lmdz_${period}.log |
---|
136 | mv run.def ${odir}/lmdzout/run.def_${period} |
---|
137 | mv config.def ${odir}/lmdzout/config.def_${period} |
---|
138 | mv histmth.nc ${odir}/lmdzout/histmth_${period}.nc |
---|
139 | mv histday.nc ${odir}/lmdzout/histday_${period}.nc |
---|
140 | mv histins.nc ${odir}/lmdzout/histins_${period}.nc |
---|
141 | |
---|
142 | if test ${isubperiod} -gt 1; then |
---|
143 | mv restartphy.nc ${odir}/lmdzout/restartphy_${period}.nc |
---|
144 | mv restart.nc ${odir}/lmdzout/restart_${period}.nc |
---|
145 | fi |
---|
146 | |
---|
147 | lastdate=${idate} |
---|
148 | idate=${nextdate} |
---|
149 | isubperiod=`expr ${isubperiod} + 1` |
---|
150 | |
---|
151 | # end of dates |
---|
152 | done |
---|
153 | |
---|
154 | isubperiod=`expr ${isubperiod} + 1` |
---|
155 | if test ${nextdate} -gt ${enddate} && test ${idate} -ne ${enddate}; then |
---|
156 | nextdate=${enddate} |
---|
157 | period=${idate}'-'${nextdate} |
---|
158 | echo "last: "${period} |
---|
159 | secmonths=`seconds_between_dates ${idate} ${nextdate}` |
---|
160 | freqV=`expr ${secmonths} / 24 / 3600` |
---|
161 | create_LMDZnamelist ${lmdztmplt} ${idate} ${freqV} |
---|
162 | |
---|
163 | ./lmdz.exe >& ${odir}/run_lmdz_${period}.log |
---|
164 | ewfr=$? |
---|
165 | if test ${ewrf} -ne 0; then |
---|
166 | echo ${errmsg} |
---|
167 | echo " lmdz.exe failed !!!" |
---|
168 | cat run_lmdz_${period}.log |
---|
169 | exit |
---|
170 | fi |
---|
171 | # Moving outputs |
---|
172 | ## |
---|
173 | mv ${odir}/run_lmdz_${period}.log ${odir}/lmdzout/run_lmdz_${period}.log |
---|
174 | mv run.def ${odir}/lmdzout/run.def_${period} |
---|
175 | mv histmth.nc ${odir}/lmdzout/histmth_${period}.nc |
---|
176 | mv histday.nc ${odir}/lmdzout/histday_${period}.nc |
---|
177 | mv histins.nc ${odir}/lmdzout/histins_${period}.nc |
---|
178 | |
---|
179 | if test ${isubperiod} -gt 1; then |
---|
180 | mv restartphy.nc ${odir}/lmdzout/restartphy_${period}.nc |
---|
181 | fi |
---|
182 | fi |
---|
183 | |
---|
184 | # Post-process LMDZ hist files |
---|
185 | ## |
---|
186 | |
---|
187 | for file in ${odir}/lmdzout/hist*.nc; do |
---|
188 | filen=`basename ${file}` |
---|
189 | filenH=`echo ${filen} | tr '.' ' ' | awk '{print $1}'` |
---|
190 | python ${HOME}/PY/WRFLMDZ_regularout.py -f ${file} -d ${dimx},${dimy} -o ${odir}/lmdzout/${filenH}_reg.nc |
---|
191 | rm ${file} |
---|
192 | d1=`echo ${filen} | tr '_' ' ' | awk '{print $2}' | tr '-' ' ' | awk '{print $1}'` |
---|
193 | totsecs=`seconds_between_dates 19491201000000 ${d1}` |
---|
194 | |
---|
195 | python ${HOME}/climatescripts/python/nc_var.py -f ${odir}/lmdzout/${filenH}_reg.nc -o valmod -S sumc,${totsecs} -v time |
---|
196 | 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 |
---|
197 | done |
---|
198 | |
---|
199 | fi |
---|