source: trunk/src/tropflux.sh @ 180

Last change on this file since 180 was 179, checked in by pinsard, 12 years ago

tropflux_nrt_ncdf is now a function

  • Property svn:eol-style set to native
  • Property svn:executable set to *
  • Property svn:keywords set to Id URL
File size: 11.4 KB
Line 
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`, :func:`sst_correction_ncdf`,
95# :func:`lwr_correction_ncdf`, :func:`q2m_correction_ncdf`,
96# :func:`t2m_correction_ncdf`, :func:`ws_correction_ncdf`,
97# :func:`tropflux_swr_dt`, :func:`tropflux_swr_nrt`, :func:`tropflux_swr_blnd`,
98# :func:`tropflux_nrt_cdf`,
99# etc.
100#
101# Next step : +validation ++ comparison
102#
103# .. todo::
104#
105# TODO
106# ====
107#
108# make it work
109#
110# idl status = 0 even if not ok
111#
112# test if demo mode idl
113#
114# EVOLUTIONS
115# ==========
116#
117# $Id$
118#
119# $URL$
120#
121# - pinsard 20120326
122#
123#   * TropFlux_NRT_ncdf replace by tropflux_nrt_ncdf which is now a function
124#
125# - pinsard 20120322
126#
127#   * handling error of sst_correction_ncdf (now function)
128#   * handling error of lwr_correction_ncdf (now function)
129#   * handling error of q2m_correction_ncdf (now function)
130#   * handling error of t2m_correction_ncdf (now function)
131#   * handling error of ws_correction_ncdf (now function)
132#
133# - pinsard 20120321
134#
135#   * TropFlux_swr_DT_19890101_20071231 replace by tropflux_swr_dt
136#     which is now a function
137#   * TropFlux_swr_NRT_19890101_20071231 replace by tropflux_swr_nrt
138#     which is now a function
139#   * TropFlux_swr_BLND_19890101_20071231 replace by tropflux_swr_blnd
140#     which is now a function
141#   * corrrection of messages when return badly
142#   * reorder for gustiness before tropflux_swr_blnd
143#   * cronin_gustiness_ncdf is now a function
144#
145# - pinsard 20120320
146#
147#   * handling error of interp_erai_sst (now function)
148#   * handling error of interp_erai_ws (now function)
149#   * handling error of interp_olr_30n_30s (now function)
150#   * handling error of d2m_to_q2m_erai (now function)
151#
152# - pinsard 20120319
153#
154#   * add project_overwrite usage
155#   * handling error of interp_erai_msl (now function)
156#   * handling error of interp_erai_dewt (now function)
157#   * handling error of interp_erai_lwr (now function)
158#
159# - pinsard 20120306
160#
161#   * create a pro IDL program to introduce LOGICAL_PREDICATE
162#     thanks to http://www.idlcoyote.com/code_tips/bitwiselogical.html
163#
164# - pinsard 20120305
165#
166#   * creation (draft)
167#   * handling error of oaflux_mask_30n30s (now a function)
168#
169#-
170system=$(uname)
171case "${system}" in
172   AIX|IRIX64)
173     echo "${command} : www : no specific posix checking"
174     date_cmd=date
175   ;;
176   Darwin)
177     set -o posix
178     date_cmd=gdate
179   ;;
180   Linux)
181     set -o posix
182     date_cmd=date
183   ;;
184   *)
185    set -o posix
186   ;;
187esac
188unset system
189#
190set -u
191#
192LANG=POSIX
193#
194command=$(basename ${0})
195log_date=$(date -u +"%Y%m%dT%H%M%SZ")
196#
197usage=" Usage : ${command} [-f] -b yyyymmdd -e yyyymmdd"
198#
199hostname=$(hostname)
200#
201yyyymmddb_min=19790101
202yyyymmdde_max=20110930
203#
204# default
205debug=0
206yyyymmddb=20000101
207yyyymmdde=20000302
208#
209minargcount=4
210if [ ${#} -lt ${minargcount} ]
211then
212   echo "${command} : eee : not enought arguments"
213   echo "${usage}"
214   exit 1
215fi
216unset minargcount
217#
218while [ ${#} -gt 0 ]
219do
220   case ${1} in
221     -b)
222        # first date to process
223        yyyymmddb=${2}
224        shift
225     ;;
226     -e)
227        # last date to process
228        yyyymmdde=${2}
229        shift
230     ;;
231     -h)
232        echo "${usage}"
233        exit 0
234     ;;
235     *)
236        # other choice
237        echo "${command} : eee : unknown option ${1}"
238        echo "${usage}"
239        exit 1
240     ;;
241   esac
242   # next flag
243   shift
244done
245unset usage
246#
247# check parameters
248# and define associated variables
249${date_cmd} -d "${yyyymmddb}" > /dev/null
250status_date=${?}
251if [ ${status_date} -ne 0 ]
252then
253    echo "${command} : eee : yyyymmddb ${yyyymmddb} argument invalid"
254    exit 1
255fi
256unset status_date
257#
258if [[ "${yyyymmddb}" < "${yyyymmddb_min}" ]]
259then
260    echo "${command} : eee : yyyymmddb ${yyyymmddb} must be equal or greater than yyyymmddb_min ${yyyymmddb_min}"
261    exit 1
262fi
263#
264${date_cmd} -d "${yyyymmdde}" > /dev/null
265status_date=${?}
266if [ ${status_date} -ne 0 ]
267then
268    echo "${command} : eee : yyyymmdde ${yyyymmdde} argument invalid"
269    exit 1
270fi
271unset status_date
272#
273if [[ "${yyyymmdde}" > "${yyyymmdde_max}" ]]
274then
275    echo "${command} : eee : yyyymmdde ${yyyymmdde} must be lower or equal to yyyymmdde_max ${yyyymmdde_max}"
276    exit 1
277fi
278#
279if [[ "${yyyymmdde}" < "${yyyymmddb}" ]]
280then
281    echo "${command} : eee : yyyymmdde ${yyyymmdde} must be greater than yyyymmddb ${yyyymmddb}"
282    exit 1
283fi
284#
285if [[ "${yyyymmdde}" = "${yyyymmddb}" ]]
286then
287     echo "${command} : eee : yyyymmdde ${yyyymmdde} must be greater than yyyymmddb ${yyyymmddb}"
288     exit 1
289fi
290#
291tool=${IDL_CMD}
292type ${tool} 1> /dev/null 2>&1
293status=${?}
294if [ ${status} -ne 0 ]
295then
296   echo "${command} : eee : tool ${IDL_CMD} not found"
297   echo "${command} : eee : check project_profile.sh sequence"
298   exit 1
299fi
300unset status
301unset tool
302#
303# check for write permission on PROJECT_LOG
304if [ ! -w ${PROJECT_LOG} ]
305then
306   echo "${command} : eee : ${PROJECT_LOG} not writable"
307   exit 1
308fi
309#
310log=${PROJECT_LOG}/$(basename ${0} .sh).log.${log_date}
311echo "[Context]" 1>> ${log}
312echo "command=$(basename ${0})" 1>>${log}
313echo "hostname=${hostname}" 1>> ${log}
314echo "runtime=${log_date}" 1>> ${log}
315echo "IDL_CMD=${IDL_CMD}" 1>> ${log}
316unset log_date
317echo "" 1>> ${log}
318echo "[Parameters]" 1>> ${log}
319echo "yyyymmddb=${yyyymmddb}" 1>> ${log}
320echo "yyyymmdde=${yyyymmdde}" 1>> ${log}
321echo "" 1>> ${log}
322#
323cat >> ${PROJECT}/src/tropflux_${$}.pro << EOF
324pro tropflux_${$}
325compile_opt idl2, strictarrsubs, logical_predicate
326@cm_project
327;
328; define overwrite status
329; set to 1 to overwrite existing files
330project_overwrite = 1
331;
332result = oaflux_mask_30n30s()
333IF result < 0 THEN BEGIN
334   msg = 'eee : pb after oaflux_mask_30n30s ' + string(result)
335   err = report(msg)
336   exit
337ENDIF
338result = interp_erai_dewt(${yyyymmddb}, ${yyyymmdde})
339IF result < 0 THEN BEGIN
340   msg = 'eee : pb after interp_erai_dewt ' + string(result)
341   err = report(msg)
342   exit
343ENDIF
344result = interp_erai_lwr(${yyyymmddb}, ${yyyymmdde})
345IF result < 0 THEN BEGIN
346   msg = 'eee : pb after interp_erai_lwr ' + string(result)
347   err = report(msg)
348   exit
349ENDIF
350result = interp_erai_msl(${yyyymmddb}, ${yyyymmdde})
351IF result < 0 THEN BEGIN
352   msg = 'eee : pb after interp_erai_msl ' + string(result)
353   err = report(msg)
354   exit
355ENDIF
356result = interp_erai_sst(${yyyymmddb}, ${yyyymmdde})
357IF result < 0 THEN BEGIN
358   msg = 'eee : pb after interp_erai_sst ' + string(result)
359   err = report(msg)
360   exit
361ENDIF
362result = interp_erai_t2m(${yyyymmddb}, ${yyyymmdde})
363IF result < 0 THEN BEGIN
364   msg = 'eee : pb after interp_erai_t2m ' + string(result)
365   err = report(msg)
366   exit
367ENDIF
368result = interp_erai_ws(${yyyymmddb}, ${yyyymmdde})
369IF result < 0 THEN BEGIN
370   msg = 'eee : pb after interp_erai_ws ' + string(result)
371   err = report(msg)
372   exit
373ENDIF
374result = interp_olr_30n30s(${yyyymmddb}, ${yyyymmdde})
375IF result < 0 THEN BEGIN
376   msg = 'eee : pb after interp_olr_30n30s ' + string(result)
377   err = report(msg)
378   exit
379ENDIF
380result = d2m_to_q2m_erai(${yyyymmddb}, ${yyyymmdde})
381IF result < 0 THEN BEGIN
382   msg = 'eee : pb after d2m_to_q2m_erai ' + string(result)
383   err = report(msg)
384   ;++Program caused arithmetic error: Floating overflow
385   ;++ Program caused arithmetic error: Floating illegal operand
386   ;++exit
387ENDIF
388result = tropflux_swr_dt(${yyyymmddb}, ${yyyymmdde})
389IF result < 0 THEN BEGIN
390   msg = 'eee : pb after tropflux_swr_dt ' + string(result)
391   err = report(msg)
392   exit
393ENDIF
394result = tropflux_swr_nrt(${yyyymmddb}, ${yyyymmdde})
395IF result < 0 THEN BEGIN
396   msg = 'eee : pb after tropflux_swr_nrt ' + string(result)
397   err = report(msg)
398   exit
399ENDIF
400result = sst_correction_ncdf(${yyyymmddb}, ${yyyymmdde})
401IF result < 0 THEN BEGIN
402   msg = 'eee : pb after sst_correction_ncdf ' + string(result)
403   err = report(msg)
404   exit
405ENDIF
406result = cronin_gustiness_ncdf(${yyyymmddb}, ${yyyymmdde})
407IF result < 0 THEN BEGIN
408   msg = 'eee : pb after cronin_gustiness_ncdf ' + string(result)
409   err = report(msg)
410   exit
411ENDIF
412result = tropflux_swr_blnd(${yyyymmddb}, ${yyyymmdde})
413IF result < 0 THEN BEGIN
414   msg = 'eee : pb after tropflux_swr_blnd ' + string(result)
415   err = report(msg)
416   exit
417ENDIF
418result = lwr_correction_ncdf(${yyyymmddb}, ${yyyymmdde})
419IF result < 0 THEN BEGIN
420   msg = 'eee : pb after lwr_correction_ncdf ' + string(result)
421   err = report(msg)
422   exit
423ENDIF
424result = q2m_correction_ncdf(${yyyymmddb}, ${yyyymmdde})
425IF result < 0 THEN BEGIN
426   msg = 'eee : pb after q2m_correction_ncdf ' + string(result)
427   err = report(msg)
428   exit
429ENDIF
430result = t2m_correction_ncdf(${yyyymmddb}, ${yyyymmdde})
431IF result < 0 THEN BEGIN
432   msg = 'eee : pb after t2m_correction_ncdf ' + string(result)
433   err = report(msg)
434   exit
435ENDIF
436result = ws_correction_ncdf(${yyyymmddb}, ${yyyymmdde})
437IF result < 0 THEN BEGIN
438   msg = 'eee : pb after ws_correction_ncdf ' + string(result)
439   err = report(msg)
440   exit
441ENDIF
442result = tropflux(${yyyymmddb}, ${yyyymmdde})
443IF result < 0 THEN BEGIN
444   msg = 'eee : pb after tropflux' + string(result)
445   err = report(msg)
446   exit
447ENDIF
448result = tropflux_nrt_ncf(${yyyymmddb}, ${yyyymmdde})
449IF result < 0 THEN BEGIN
450   msg = 'eee : pb after tropflux_nrt_ncdf' + string(result)
451   err = report(msg)
452   exit
453ENDIF
454end
455EOF
456#
457# run IDL or equivalent
458${IDL_CMD} << EOF >> ${log} 2>&1
459.compile file_interp
460;
461tropflux_${$}
462EOF
463status=${?}
464if [ ${status} -ne 0 ]
465then
466   echo "${command} : eee: ${IDL_CMD} failed : ${status}" >> ${log} 2>&1
467   cat ${PROJECT}/src/tropflux_${$}.pro >> ${log} 2>&1
468   exit 1
469fi
470rm ${PROJECT}/src/tropflux_${$}.pro
471unset status
472#
473unset command
474unset log
475unset hostname
476unset usage
477#
478unset date_cmd
479#
480# end
481#++set
482exit
Note: See TracBrowser for help on using the repository browser.