1 | #!/bin/sh |
---|
2 | #+ |
---|
3 | # |
---|
4 | # NAME |
---|
5 | # ==== |
---|
6 | # |
---|
7 | # olr_split.sh - split OLR mean daily file |
---|
8 | # |
---|
9 | # SYNOPSYS |
---|
10 | # ======== |
---|
11 | # |
---|
12 | # ``olr_split.sh [-g] [-r] [-f] [-y year]`` |
---|
13 | # |
---|
14 | # DESCRIPTION |
---|
15 | # =========== |
---|
16 | # |
---|
17 | # Split OLR mean daily file by year and reduce geographical domain |
---|
18 | # to [60 ° W, 50 ° E] [30 ° S, 45 ° N]. |
---|
19 | # |
---|
20 | # If ``-g`` option is set, there will be no geographical domain reduction. |
---|
21 | # |
---|
22 | # If ``-f`` option is set, previously output files will be overwritten. |
---|
23 | # |
---|
24 | # If ``-r`` option is set, output files will be concatenated in one (might |
---|
25 | # be usefull, combinated with ``-g`` option to check). |
---|
26 | # |
---|
27 | # If ``-y`` option is set with a year, only this year will be splitted. |
---|
28 | # |
---|
29 | # EXAMPLES |
---|
30 | # ======== |
---|
31 | # |
---|
32 | # To split ${VARAMMA_ID}/olr.day.mean.nc between [2000,2007] and between |
---|
33 | # [60 ° W, 50 ° E] [30 ° S, 45 ° N] |
---|
34 | # :: |
---|
35 | # |
---|
36 | # $ olr_split.sh |
---|
37 | # |
---|
38 | # To split ${VARAMMA_ID}/olr.day.mean.nc in 2006 between |
---|
39 | # [60 ° W, 50 ° E] [30 ° S, 45 ° N] |
---|
40 | # :: |
---|
41 | # |
---|
42 | # $ olr_split.sh -y 2006 |
---|
43 | # |
---|
44 | # To split globaly and build a recomposed file |
---|
45 | # :: |
---|
46 | # |
---|
47 | # $ olr_split.sh -g -r |
---|
48 | # |
---|
49 | # one might compare original and rebuild file |
---|
50 | # :: |
---|
51 | # |
---|
52 | # $ cdo diffv ${VARAMMA_ID}/olr.day.mean.nc ${VARAMMA_OD}/olr.day.mean_rebuild.nc |
---|
53 | # |
---|
54 | # diff should only show differences in global attributes |
---|
55 | # |
---|
56 | # CAUTIONS |
---|
57 | # ======== |
---|
58 | # |
---|
59 | # Does'nt work on zeus because of UDUnits library problems |
---|
60 | # |
---|
61 | # ++++ GROS DOUTE SUR LES LONGITUDES DANS CES FICHIERS +++++++ |
---|
62 | # |
---|
63 | # FILES |
---|
64 | # ===== |
---|
65 | # |
---|
66 | # original location |
---|
67 | # ~~~~~~~~~~~~~~~~~ |
---|
68 | # |
---|
69 | # /usr/home/fplod/incas/varamma/varamma_ws/olr_split.sh sur aedon.locean-ipsl.upmc.fr |
---|
70 | # |
---|
71 | # |
---|
72 | # TODO |
---|
73 | # ==== |
---|
74 | # |
---|
75 | # ++ unset |
---|
76 | # |
---|
77 | # ++ option debug/verbose |
---|
78 | # |
---|
79 | # ++ gestion log |
---|
80 | # |
---|
81 | # ++ vérification accès filein |
---|
82 | # |
---|
83 | # ++ found none interactive actionof ncks if output file exists |
---|
84 | # |
---|
85 | # EVOLUTIONS |
---|
86 | # ========== |
---|
87 | # |
---|
88 | # |
---|
89 | # $Id$ |
---|
90 | # |
---|
91 | # - fplod 2008-08-14T14:53:04Z aedon.locean-ipsl.upmc.fr (Darwin) |
---|
92 | # |
---|
93 | # * modify West longitude conversion according to |
---|
94 | # http://en.wikipedia.org/wiki/Longitude |
---|
95 | # - fplod 2008-08-13T14:26:41Z aedon.locean-ipsl.upmc.fr (Darwin) |
---|
96 | # |
---|
97 | # * add -f option |
---|
98 | # * add -y option |
---|
99 | # * add 180 degre to longitude centered on meridien 0 (<0 =W , >0=E) |
---|
100 | # |
---|
101 | # - fplod 2008-07-24T15:02:12Z aedon.locean-ipsl.upmc.fr (Darwin) |
---|
102 | # |
---|
103 | # * creation |
---|
104 | # |
---|
105 | #- |
---|
106 | system=$(uname) |
---|
107 | case "${system}" in |
---|
108 | AIX|IRIX64) |
---|
109 | echo " www : no specific posix checking" |
---|
110 | ;; |
---|
111 | *) |
---|
112 | set -o posix |
---|
113 | ;; |
---|
114 | esac |
---|
115 | # |
---|
116 | case $(hostname) in |
---|
117 | zeus.locean-ipsl.upmc.fr|dedale.locean-ipsl.upmc.fr) |
---|
118 | echo "eee : pb on UDUnits library on zeus" |
---|
119 | echo "eee : contact system team" |
---|
120 | exit 1 |
---|
121 | ;; |
---|
122 | esac |
---|
123 | # |
---|
124 | command=$(basename ${0}) |
---|
125 | log_date=$(date -u +"%Y-%m-%dT%H:%M:%SZ") |
---|
126 | # |
---|
127 | usage=" Usage : ${command} [-r] [-g] [-f]" |
---|
128 | # |
---|
129 | # ++ test si ncks available |
---|
130 | # |
---|
131 | # default |
---|
132 | force=0 |
---|
133 | latmin=-30 |
---|
134 | latmax=45 |
---|
135 | lonmin=$((-60 + 360)) |
---|
136 | lonmax=50 |
---|
137 | global=0 |
---|
138 | yearmin=2000 |
---|
139 | yearmax=2007 |
---|
140 | rebuild=0 |
---|
141 | # |
---|
142 | minargcount=0 |
---|
143 | if [ ${#} -lt ${minargcount} ] |
---|
144 | then |
---|
145 | echo "eee : not enought arguments" |
---|
146 | echo "${usage}" |
---|
147 | exit 1 |
---|
148 | fi |
---|
149 | # |
---|
150 | while [ ! -z "${1}" ] # ++ pb bash |
---|
151 | do |
---|
152 | case ${1} in |
---|
153 | -g) |
---|
154 | global=1 |
---|
155 | # ++ comment connaitre la 1er année si -g. |
---|
156 | # dans le README on nous dit que ça commence en 1974 mais il faudrait automatiser |
---|
157 | # ++ idem pour la dernière année |
---|
158 | # pour l'instant forçage |
---|
159 | yearmin=1974 |
---|
160 | yearmax=2008 |
---|
161 | echo "www : forçage yearmin yearmax : ${yearmin} ${yearmax}" |
---|
162 | ;; |
---|
163 | -f) |
---|
164 | force=1 |
---|
165 | ;; |
---|
166 | -r) |
---|
167 | rebuild=1 |
---|
168 | ;; |
---|
169 | -y) |
---|
170 | yearmin=${2} |
---|
171 | yearmax=${yearmin} |
---|
172 | shift |
---|
173 | ;; |
---|
174 | -h) |
---|
175 | echo "${usage}" |
---|
176 | exit 0 |
---|
177 | ;; |
---|
178 | *) # other choice |
---|
179 | echo "${usage}" |
---|
180 | exit 1 |
---|
181 | ;; |
---|
182 | esac |
---|
183 | shift # next flag |
---|
184 | done |
---|
185 | # |
---|
186 | set -u |
---|
187 | # |
---|
188 | # ++ check validuty of yearmin and yearmax |
---|
189 | # |
---|
190 | # check for ${VARAMMA_LOG} definition |
---|
191 | if [ "${VARAMMA_LOG}" = "" ] |
---|
192 | then |
---|
193 | echo " eee : \${VARAMMA_LOG} not defined" |
---|
194 | exit 1 |
---|
195 | fi |
---|
196 | # |
---|
197 | # check for ${VARAMMA_LOG} existence |
---|
198 | if [ ! -d ${VARAMMA_LOG} ] |
---|
199 | then |
---|
200 | echo " eee : ${VARAMMA_LOG} not found" |
---|
201 | exit 1 |
---|
202 | fi |
---|
203 | # |
---|
204 | # check for permission access on VARAMMA_LOG |
---|
205 | if [ ! -x ${VARAMMA_LOG} ] |
---|
206 | then |
---|
207 | echo " eee : ${VARAMMA_LOG} not reachable" |
---|
208 | exit 1 |
---|
209 | fi |
---|
210 | # |
---|
211 | # check for write permission on VARAMMA_LOG |
---|
212 | if [ ! -w ${VARAMMA_LOG} ] |
---|
213 | then |
---|
214 | echo " eee : ${VARAMMA_LOG} not writable" |
---|
215 | exit 1 |
---|
216 | fi |
---|
217 | # |
---|
218 | log=${VARAMMA_LOG}/$(basename ${0} .sh).log.${log_date} |
---|
219 | #++echo "command = $(basename ${0})" 1>>${log} |
---|
220 | #++echo "runtime = ${log_date}" 1>> ${log} |
---|
221 | # |
---|
222 | # ++ VARAMMA_ID |
---|
223 | # ++ VARAMMA_OD |
---|
224 | # |
---|
225 | # check for input file |
---|
226 | filein=${VARAMMA_ID}/olr.day.mean.nc |
---|
227 | if [ ! -r ${VARAMMA_ID}/olr.day.mean.nc ] |
---|
228 | then |
---|
229 | echo "eee : ${filein} not accessible" |
---|
230 | exit 1 |
---|
231 | fi |
---|
232 | # |
---|
233 | # build date string for ncks command |
---|
234 | list_split="" |
---|
235 | iyear=${yearmin} |
---|
236 | while [ ${iyear} -le ${yearmax} ] |
---|
237 | do |
---|
238 | timemin=$(echo ${iyear} | awk ' {printf "%4.4d-01-01 00:00:00.0",$1}') |
---|
239 | timemax=$(echo ${iyear} | awk ' {printf "%4.4d-12-31 00:00:00.0",$1}') #++23:59:59 |
---|
240 | echo "iii : extraction ${iyear} from ${filein}" # ++ voir seulement si debug demandé |
---|
241 | if [ ${global} -eq 0 ] |
---|
242 | then |
---|
243 | fileout=${VARAMMA_OD}/$(basename ${filein} .nc)_${iyear}_ng.nc |
---|
244 | else |
---|
245 | fileout=${VARAMMA_OD}/$(basename ${filein} .nc)_${iyear}.nc |
---|
246 | fi |
---|
247 | if [ -f ${fileout} ] |
---|
248 | then |
---|
249 | if [ ${force} -eq 0 ] |
---|
250 | then |
---|
251 | echo "eee : ${fileout} already exists" |
---|
252 | exit 1 |
---|
253 | else |
---|
254 | # I remove the file because I don't know how to tell ncks to ask interactivily if I want to append, overwrite etc... |
---|
255 | rm -f ${fileout} |
---|
256 | fi |
---|
257 | fi |
---|
258 | if [ ${global} -eq 0 ] |
---|
259 | then |
---|
260 | # build float representation of lat and long limit (for hyperslab) |
---|
261 | clatmin=$(echo ${latmin} | awk ' {printf "%+3.1f",$1}') |
---|
262 | clatmax=$(echo ${latmax} | awk ' {printf "%+3.1f",$1}') |
---|
263 | clonmin=$(echo ${lonmin} | awk ' {printf "%+4.1f",$1}') |
---|
264 | clonmax=$(echo ${lonmax} | awk ' {printf "%+4.1f",$1}') |
---|
265 | ncks \ |
---|
266 | --dimension time,"${timemin}","${timemax}" \ |
---|
267 | --dimension lat,"${clatmin}","${clatmax}" \ |
---|
268 | --dimension lon,"${clonmin}","${clonmax}" \ |
---|
269 | ${filein} ${fileout} |
---|
270 | status_ncks=${?} |
---|
271 | if [ ${status_ncks} -ne 0 ] |
---|
272 | then |
---|
273 | echo "eee : pb with ncks ${filein}" |
---|
274 | exit 1 |
---|
275 | else |
---|
276 | list_split="${list_split} ${fileout}" |
---|
277 | fi |
---|
278 | else |
---|
279 | ncks \ |
---|
280 | --dimension time,"${timemin}","${timemax}" \ |
---|
281 | ${filein} ${fileout} |
---|
282 | status_ncks=${?} |
---|
283 | if [ ${status_ncks} -ne 0 ] |
---|
284 | then |
---|
285 | echo "eee : pb with ncks ${filein}" |
---|
286 | exit 1 |
---|
287 | else |
---|
288 | list_split="${list_split} ${fileout}" |
---|
289 | fi |
---|
290 | fi |
---|
291 | iyear=$(( ${iyear} + 1 )) |
---|
292 | done |
---|
293 | # |
---|
294 | echo "iii : list of splitted files : ${list_split}" |
---|
295 | # |
---|
296 | if [ ${rebuild} -eq 1 ] |
---|
297 | then |
---|
298 | # if rebuild is asked, concatenation of all the splitted files |
---|
299 | filetot=${VARAMMA_OD}/$(basename ${filein} .nc)_rebuild.nc |
---|
300 | rm -f ${filetot} 2> /dev/null |
---|
301 | ncrcat ${list_split} ${filetot} |
---|
302 | status_ncrcat=${?} |
---|
303 | if [ ${status_ncrcat} -ne 0 ] |
---|
304 | then |
---|
305 | echo "eee : pb with ncrcat" |
---|
306 | exit 1 |
---|
307 | else |
---|
308 | echo "iii : rebuild result in ${filetot}" |
---|
309 | fi |
---|
310 | fi |
---|
311 | # |
---|
312 | # end |
---|
313 | exit 0 |
---|