1 | #! /bin/sh |
---|
2 | #+ |
---|
3 | # |
---|
4 | # .. program:: tropflux.sh |
---|
5 | # |
---|
6 | # .. _tropflux.sh: |
---|
7 | # |
---|
8 | # =========== |
---|
9 | # tropflux.sh |
---|
10 | # =========== |
---|
11 | # |
---|
12 | # SYNOPSIS |
---|
13 | # ======== |
---|
14 | # |
---|
15 | # :: |
---|
16 | # |
---|
17 | # $ tropflux.sh -b yyyymmdd -e yyyymmdd |
---|
18 | # |
---|
19 | # DESCRIPTION |
---|
20 | # =========== |
---|
21 | # |
---|
22 | # Run all needed :file:`*.pro` to create the TropFlux dataset between two dates |
---|
23 | # |
---|
24 | # We suppose here that all inputs data are already available localy. |
---|
25 | # |
---|
26 | # .. option:: -b beginning date <yyyymmdd> |
---|
27 | # .. option:: -e end date <yyyymmdd> |
---|
28 | # |
---|
29 | # Some IDL programs are launched here using ${IDL_CMD} command |
---|
30 | # (see :ref:`project_profile.sh` to know how to set this environnement variable). |
---|
31 | # |
---|
32 | # Log file is written on |
---|
33 | # :file:`${PROJECT_LOG}/tropflux.log.{YYYYMMDDTHHMMSSZ}` |
---|
34 | # |
---|
35 | # .. only:: man |
---|
36 | # |
---|
37 | # Figure is visible on PDF and HTML documents only. |
---|
38 | # |
---|
39 | # .. only:: html or latex |
---|
40 | # |
---|
41 | # .. graphviz:: |
---|
42 | # |
---|
43 | # digraph tropflux { |
---|
44 | # |
---|
45 | # file_oaflux [shape=ellipse,fontname=Courier,label="${PROJECT_ID}/lh_oaflux_2004.nc"]; |
---|
46 | |
---|
47 | # log [shape=ellipse,fontname=Courier,label="${PROJECT_LOG}/tropflux.log{YYYYMMDDTHHMMSSZ}"]; |
---|
48 | # |
---|
49 | # tropflux [shape=box, |
---|
50 | # fontname=Courier, |
---|
51 | # color=blue, |
---|
52 | # URL="http://forge.ipsl.jussieu.fr/tropflux/browser/trunk/src/tropflux.sh", |
---|
53 | # label="${PROJECT}/src/tropflux.sh"]; |
---|
54 | # |
---|
55 | # {file_oaflux} -> {tropflux} -> {log fileout} |
---|
56 | # |
---|
57 | # } |
---|
58 | # |
---|
59 | # EXAMPLES |
---|
60 | # ======== |
---|
61 | # |
---|
62 | # You already used :ref:`get_erai.sh` to get ERAI data, etc., |
---|
63 | # during [20000101, 20000302[ and you want to produce NetCDF files:: |
---|
64 | # |
---|
65 | # $ tropflux.sh -b 20000101 -e 20000302 |
---|
66 | # |
---|
67 | # A more global example:: |
---|
68 | # |
---|
69 | # $ tropflux.sh -b 19890101 -e 20091231 |
---|
70 | # |
---|
71 | # And look at log file with :: |
---|
72 | # |
---|
73 | # $ tlogd.sh tropflux |
---|
74 | # |
---|
75 | # and of course on files in ${PROJECT_ID}. |
---|
76 | # |
---|
77 | # SEE ALSO |
---|
78 | # ======== |
---|
79 | # |
---|
80 | # IDL_ |
---|
81 | # |
---|
82 | # .. _IDL: http://www.ittvis.com/ProductServices/IDL.aspx |
---|
83 | # |
---|
84 | # :ref:`project_profile.sh` |
---|
85 | # :ref:`project_init.pro` |
---|
86 | # |
---|
87 | # Previous step : :ref:`get_erai.sh`, :ref:`get_oaflux.sh`, :ref:`get_olr.sh`, |
---|
88 | # :ref:`get_pirata_netcdf.sh`, :ref:`get_swr.sh` |
---|
89 | # |
---|
90 | # Use : |
---|
91 | # :func:`oaflux_mask_30n30s`, :func:`interp_erai_t2m`, |
---|
92 | # :func:`interp_erai_msl`, :func:`interp_erai_dewt`, :func:`interp_erai_lwr`, |
---|
93 | # :func:`interp_erai_sst`, :func:`interp_erai_ws`, :func:`interp_olr_30n30s`, |
---|
94 | # :func:`d2m_to_q2m_erai`, |
---|
95 | # etc. |
---|
96 | # |
---|
97 | # Next step : +validation ++ comparison |
---|
98 | # |
---|
99 | # .. todo:: |
---|
100 | # |
---|
101 | # TODO |
---|
102 | # ==== |
---|
103 | # |
---|
104 | # make it work |
---|
105 | # |
---|
106 | # idl status = 0 even if not ok |
---|
107 | # |
---|
108 | # test if demo mode idl |
---|
109 | # |
---|
110 | # EVOLUTIONS |
---|
111 | # ========== |
---|
112 | # |
---|
113 | # $Id$ |
---|
114 | # |
---|
115 | # $URL$ |
---|
116 | # |
---|
117 | # - pinsard 20120321 |
---|
118 | # |
---|
119 | # * TropFlux_swr_DT_19890101_20071231 replace by tropflux_swr_dt |
---|
120 | # which is now a function |
---|
121 | # * TropFlux_swr_NRT_19890101_20071231 replace by tropflux_swr_nrt |
---|
122 | # which is now a function |
---|
123 | # * TropFlux_swr_BLND_19890101_20071231 replace by tropflux_swr_blnd |
---|
124 | # which is now a function |
---|
125 | # * corrrection of messages when return badly |
---|
126 | # * reorder for gustiness before tropflux_swr_blnd |
---|
127 | # * cronin_gustiness_ncdf is now a function |
---|
128 | # |
---|
129 | # - pinsard 20120320 |
---|
130 | # |
---|
131 | # * handling error of interp_erai_sst (now function) |
---|
132 | # * handling error of interp_erai_ws (now function) |
---|
133 | # * handling error of interp_olr_30n_30s (now function) |
---|
134 | # * handling error of d2m_to_q2m_erai (now function) |
---|
135 | # |
---|
136 | # - pinsard 20120319 |
---|
137 | # |
---|
138 | # * add project_overwrite usage |
---|
139 | # * handling error of interp_erai_msl (now function) |
---|
140 | # * handling error of interp_erai_dewt (now function) |
---|
141 | # * handling error of interp_erai_lwr (now function) |
---|
142 | # |
---|
143 | # - pinsard 20120306 |
---|
144 | # |
---|
145 | # * create a pro IDL program to introduce LOGICAL_PREDICATE |
---|
146 | # thanks to http://www.idlcoyote.com/code_tips/bitwiselogical.html |
---|
147 | # |
---|
148 | # - pinsard 20120305 |
---|
149 | # |
---|
150 | # * creation (draft) |
---|
151 | # * handling error of oaflux_mask_30n30s (now a function) |
---|
152 | # |
---|
153 | #- |
---|
154 | system=$(uname) |
---|
155 | case "${system}" in |
---|
156 | AIX|IRIX64) |
---|
157 | echo "${command} : www : no specific posix checking" |
---|
158 | date_cmd=date |
---|
159 | ;; |
---|
160 | Darwin) |
---|
161 | set -o posix |
---|
162 | date_cmd=gdate |
---|
163 | ;; |
---|
164 | Linux) |
---|
165 | set -o posix |
---|
166 | date_cmd=date |
---|
167 | ;; |
---|
168 | *) |
---|
169 | set -o posix |
---|
170 | ;; |
---|
171 | esac |
---|
172 | unset system |
---|
173 | # |
---|
174 | set -u |
---|
175 | # |
---|
176 | LANG=POSIX |
---|
177 | # |
---|
178 | command=$(basename ${0}) |
---|
179 | log_date=$(date -u +"%Y%m%dT%H%M%SZ") |
---|
180 | # |
---|
181 | usage=" Usage : ${command} [-f] -b yyyymmdd -e yyyymmdd" |
---|
182 | # |
---|
183 | hostname=$(hostname) |
---|
184 | # |
---|
185 | yyyymmddb_min=19790101 |
---|
186 | yyyymmdde_max=20110930 |
---|
187 | # |
---|
188 | # default |
---|
189 | debug=0 |
---|
190 | yyyymmddb=20000101 |
---|
191 | yyyymmdde=20000302 |
---|
192 | # |
---|
193 | minargcount=4 |
---|
194 | if [ ${#} -lt ${minargcount} ] |
---|
195 | then |
---|
196 | echo "${command} : eee : not enought arguments" |
---|
197 | echo "${usage}" |
---|
198 | exit 1 |
---|
199 | fi |
---|
200 | unset minargcount |
---|
201 | # |
---|
202 | while [ ${#} -gt 0 ] |
---|
203 | do |
---|
204 | case ${1} in |
---|
205 | -b) |
---|
206 | # first date to process |
---|
207 | yyyymmddb=${2} |
---|
208 | shift |
---|
209 | ;; |
---|
210 | -e) |
---|
211 | # last date to process |
---|
212 | yyyymmdde=${2} |
---|
213 | shift |
---|
214 | ;; |
---|
215 | -h) |
---|
216 | echo "${usage}" |
---|
217 | exit 0 |
---|
218 | ;; |
---|
219 | *) |
---|
220 | # other choice |
---|
221 | echo "${command} : eee : unknown option ${1}" |
---|
222 | echo "${usage}" |
---|
223 | exit 1 |
---|
224 | ;; |
---|
225 | esac |
---|
226 | # next flag |
---|
227 | shift |
---|
228 | done |
---|
229 | unset usage |
---|
230 | # |
---|
231 | # check parameters |
---|
232 | # and define associated variables |
---|
233 | ${date_cmd} -d "${yyyymmddb}" > /dev/null |
---|
234 | status_date=${?} |
---|
235 | if [ ${status_date} -ne 0 ] |
---|
236 | then |
---|
237 | echo "${command} : eee : yyyymmddb ${yyyymmddb} argument invalid" |
---|
238 | exit 1 |
---|
239 | fi |
---|
240 | unset status_date |
---|
241 | # |
---|
242 | if [[ "${yyyymmddb}" < "${yyyymmddb_min}" ]] |
---|
243 | then |
---|
244 | echo "${command} : eee : yyyymmddb ${yyyymmddb} must be equal or greater than yyyymmddb_min ${yyyymmddb_min}" |
---|
245 | exit 1 |
---|
246 | fi |
---|
247 | # |
---|
248 | ${date_cmd} -d "${yyyymmdde}" > /dev/null |
---|
249 | status_date=${?} |
---|
250 | if [ ${status_date} -ne 0 ] |
---|
251 | then |
---|
252 | echo "${command} : eee : yyyymmdde ${yyyymmdde} argument invalid" |
---|
253 | exit 1 |
---|
254 | fi |
---|
255 | unset status_date |
---|
256 | # |
---|
257 | if [[ "${yyyymmdde}" > "${yyyymmdde_max}" ]] |
---|
258 | then |
---|
259 | echo "${command} : eee : yyyymmdde ${yyyymmdde} must be lower or equal to yyyymmdde_max ${yyyymmdde_max}" |
---|
260 | exit 1 |
---|
261 | fi |
---|
262 | # |
---|
263 | if [[ "${yyyymmdde}" < "${yyyymmddb}" ]] |
---|
264 | then |
---|
265 | echo "${command} : eee : yyyymmdde ${yyyymmdde} must be greater than yyyymmddb ${yyyymmddb}" |
---|
266 | exit 1 |
---|
267 | fi |
---|
268 | # |
---|
269 | if [[ "${yyyymmdde}" = "${yyyymmddb}" ]] |
---|
270 | then |
---|
271 | echo "${command} : eee : yyyymmdde ${yyyymmdde} must be greater than yyyymmddb ${yyyymmddb}" |
---|
272 | exit 1 |
---|
273 | fi |
---|
274 | # |
---|
275 | tool=${IDL_CMD} |
---|
276 | type ${tool} 1> /dev/null 2>&1 |
---|
277 | status=${?} |
---|
278 | if [ ${status} -ne 0 ] |
---|
279 | then |
---|
280 | echo "${command} : eee : tool ${IDL_CMD} not found" |
---|
281 | echo "${command} : eee : check project_profile.sh sequence" |
---|
282 | exit 1 |
---|
283 | fi |
---|
284 | unset status |
---|
285 | unset tool |
---|
286 | # |
---|
287 | # check for write permission on PROJECT_LOG |
---|
288 | if [ ! -w ${PROJECT_LOG} ] |
---|
289 | then |
---|
290 | echo "${command} : eee : ${PROJECT_LOG} not writable" |
---|
291 | exit 1 |
---|
292 | fi |
---|
293 | # |
---|
294 | log=${PROJECT_LOG}/$(basename ${0} .sh).log.${log_date} |
---|
295 | echo "[Context]" 1>> ${log} |
---|
296 | echo "command=$(basename ${0})" 1>>${log} |
---|
297 | echo "hostname=${hostname}" 1>> ${log} |
---|
298 | echo "runtime=${log_date}" 1>> ${log} |
---|
299 | echo "IDL_CMD=${IDL_CMD}" 1>> ${log} |
---|
300 | unset log_date |
---|
301 | echo "" 1>> ${log} |
---|
302 | echo "[Parameters]" 1>> ${log} |
---|
303 | echo "yyyymmddb=${yyyymmddb}" 1>> ${log} |
---|
304 | echo "yyyymmdde=${yyyymmdde}" 1>> ${log} |
---|
305 | echo "" 1>> ${log} |
---|
306 | # |
---|
307 | cat >> ${PROJECT}/src/tropflux_${$}.pro << EOF |
---|
308 | pro tropflux_${$} |
---|
309 | compile_opt idl2, strictarrsubs, logical_predicate |
---|
310 | @cm_project |
---|
311 | ; |
---|
312 | ; define overwrite status |
---|
313 | ; set to 1 to overwrite existing files |
---|
314 | project_overwrite = 1 |
---|
315 | ; |
---|
316 | result = oaflux_mask_30n30s() |
---|
317 | IF result < 0 THEN BEGIN |
---|
318 | msg = 'eee : pb after oaflux_mask_30n30s ' + string(result) |
---|
319 | err = report(msg) |
---|
320 | exit |
---|
321 | ENDIF |
---|
322 | result = interp_erai_dewt(${yyyymmddb}, ${yyyymmdde}) |
---|
323 | IF result < 0 THEN BEGIN |
---|
324 | msg = 'eee : pb after interp_erai_dewt ' + string(result) |
---|
325 | err = report(msg) |
---|
326 | exit |
---|
327 | ENDIF |
---|
328 | result = interp_erai_lwr(${yyyymmddb}, ${yyyymmdde}) |
---|
329 | IF result < 0 THEN BEGIN |
---|
330 | msg = 'eee : pb after interp_erai_lwr ' + string(result) |
---|
331 | err = report(msg) |
---|
332 | exit |
---|
333 | ENDIF |
---|
334 | result = interp_erai_msl(${yyyymmddb}, ${yyyymmdde}) |
---|
335 | IF result < 0 THEN BEGIN |
---|
336 | msg = 'eee : pb after interp_erai_msl ' + string(result) |
---|
337 | err = report(msg) |
---|
338 | exit |
---|
339 | ENDIF |
---|
340 | result = interp_erai_sst(${yyyymmddb}, ${yyyymmdde}) |
---|
341 | IF result < 0 THEN BEGIN |
---|
342 | msg = 'eee : pb after interp_erai_sst ' + string(result) |
---|
343 | err = report(msg) |
---|
344 | exit |
---|
345 | ENDIF |
---|
346 | result = interp_erai_t2m(${yyyymmddb}, ${yyyymmdde}) |
---|
347 | IF result < 0 THEN BEGIN |
---|
348 | msg = 'eee : pb after interp_erai_t2m ' + string(result) |
---|
349 | err = report(msg) |
---|
350 | exit |
---|
351 | ENDIF |
---|
352 | result = interp_erai_ws(${yyyymmddb}, ${yyyymmdde}) |
---|
353 | IF result < 0 THEN BEGIN |
---|
354 | msg = 'eee : pb after interp_erai_ws ' + string(result) |
---|
355 | err = report(msg) |
---|
356 | exit |
---|
357 | ENDIF |
---|
358 | result = interp_olr_30n30s(${yyyymmddb}, ${yyyymmdde}) |
---|
359 | IF result < 0 THEN BEGIN |
---|
360 | msg = 'eee : pb after interp_olr_30n30s ' + string(result) |
---|
361 | err = report(msg) |
---|
362 | exit |
---|
363 | ENDIF |
---|
364 | result = d2m_to_q2m_erai(${yyyymmddb}, ${yyyymmdde}) |
---|
365 | IF result < 0 THEN BEGIN |
---|
366 | msg = 'eee : pb after d2m_to_q2m_erai ' + string(result) |
---|
367 | err = report(msg) |
---|
368 | ;++Program caused arithmetic error: Floating overflow |
---|
369 | ;++ Program caused arithmetic error: Floating illegal operand |
---|
370 | ;++exit |
---|
371 | ENDIF |
---|
372 | result = tropflux_swr_dt(${yyyymmddb}, ${yyyymmdde}) |
---|
373 | IF result < 0 THEN BEGIN |
---|
374 | msg = 'eee : pb after tropflux_swr_dt ' + string(result) |
---|
375 | err = report(msg) |
---|
376 | exit |
---|
377 | ENDIF |
---|
378 | result = tropflux_swr_nrt(${yyyymmddb}, ${yyyymmdde}) |
---|
379 | IF result < 0 THEN BEGIN |
---|
380 | msg = 'eee : pb after tropflux_swr_nrt ' + string(result) |
---|
381 | err = report(msg) |
---|
382 | exit |
---|
383 | ENDIF |
---|
384 | ;sst_correction_ncdf |
---|
385 | result = cronin_gustiness_ncdf(${yyyymmddb}, ${yyyymmdde}) |
---|
386 | IF result < 0 THEN BEGIN |
---|
387 | msg = 'eee : pb after cronin_gustiness_ncdf ' + string(result) |
---|
388 | err = report(msg) |
---|
389 | exit |
---|
390 | result = tropflux_swr_blnd(${yyyymmddb}, ${yyyymmdde}) |
---|
391 | IF result < 0 THEN BEGIN |
---|
392 | msg = 'eee : pb after tropflux_swr_blnd ' + string(result) |
---|
393 | err = report(msg) |
---|
394 | exit |
---|
395 | ;lwr_correction_ncdf |
---|
396 | ;q2m_correction_ncdf |
---|
397 | ;t2m_correction_ncdf |
---|
398 | ;ws_correction_ncdf |
---|
399 | ;.compile TropFlux_19890101_20091231 |
---|
400 | ;tropflux_19890101_20091231 |
---|
401 | ;.compile TropFlux_NRT_ncdf |
---|
402 | ;tropflux_nrt_ncdf |
---|
403 | end |
---|
404 | EOF |
---|
405 | # |
---|
406 | # run IDL or equivalent |
---|
407 | ${IDL_CMD} << EOF >> ${log} 2>&1 |
---|
408 | .compile file_interp |
---|
409 | ; |
---|
410 | tropflux_${$} |
---|
411 | EOF |
---|
412 | status=${?} |
---|
413 | if [ ${status} -ne 0 ] |
---|
414 | then |
---|
415 | echo "${command} : eee: ${IDL_CMD} failed : ${status}" >> ${log} 2>&1 |
---|
416 | cat ${PROJECT}/src/tropflux_${$}.pro >> ${log} 2>&1 |
---|
417 | exit 1 |
---|
418 | fi |
---|
419 | rm ${PROJECT}/src/tropflux_${$}.pro |
---|
420 | unset status |
---|
421 | # |
---|
422 | unset command |
---|
423 | unset log |
---|
424 | unset hostname |
---|
425 | unset usage |
---|
426 | # |
---|
427 | unset date_cmd |
---|
428 | # |
---|
429 | # end |
---|
430 | #++set |
---|
431 | exit |
---|