source: trunk/src/tropflux.sh @ 169

Last change on this file since 169 was 167, checked in by pinsard, 12 years ago

interp_erai_lwr 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: 7.9 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# etc.
94#
95# Next step : +validation ++ comparison
96#
97# .. todo::
98#
99# TODO
100# ====
101#
102# make it work
103#
104# idl status = 0 even if not ok
105#
106# test if demo mode idl
107#
108# EVOLUTIONS
109# ==========
110#
111# $Id$
112#
113# $URL$
114#
115# - pinsard 20120319
116#
117#   * add project_overwrite usage
118#   * handling error of inter_erai_msl (now function)
119#   * handling error of inter_erai_dewt (now function)
120#   * handling error of inter_erai_lwr (now function)
121#
122# - pinsard 20120306
123#
124#   * create a pro IDL program to introduce LOGICAL_PREDICATE
125#     thanks to http://www.idlcoyote.com/code_tips/bitwiselogical.html
126#
127# - pinsard 20120305
128#
129#   * creation (draft)
130#   * handling error of oaflux_mask_30n30s (now a function)
131#
132#-
133system=$(uname)
134case "${system}" in
135   AIX|IRIX64)
136     echo "${command} : www : no specific posix checking"
137     date_cmd=date
138   ;;
139   Darwin)
140     set -o posix
141     date_cmd=gdate
142   ;;
143   Linux)
144     set -o posix
145     date_cmd=date
146   ;;
147   *)
148    set -o posix
149   ;;
150esac
151unset system
152#
153set -u
154#
155LANG=POSIX
156#
157command=$(basename ${0})
158log_date=$(date -u +"%Y%m%dT%H%M%SZ")
159#
160usage=" Usage : ${command} [-f] -b yyyymmdd -e yyyymmdd"
161#
162hostname=$(hostname)
163#
164yyyymmddb_min=19790101
165yyyymmdde_max=20110930
166#
167# default
168debug=0
169yyyymmddb=20000101
170yyyymmdde=20000302
171#
172minargcount=4
173if [ ${#} -lt ${minargcount} ]
174then
175   echo "${command} : eee : not enought arguments"
176   echo "${usage}"
177   exit 1
178fi
179unset minargcount
180#
181while [ ${#} -gt 0 ]
182do
183   case ${1} in
184     -b)
185        # first date to process
186        yyyymmddb=${2}
187        shift
188     ;;
189     -e)
190        # last date to process
191        yyyymmdde=${2}
192        shift
193     ;;
194     -h)
195        echo "${usage}"
196        exit 0
197     ;;
198     *)
199        # other choice
200        echo "${command} : eee : unknown option ${1}"
201        echo "${usage}"
202        exit 1
203     ;;
204   esac
205   # next flag
206   shift
207done
208unset usage
209#
210# check parameters
211# and define associated variables
212${date_cmd} -d "${yyyymmddb}" > /dev/null
213status_date=${?}
214if [ ${status_date} -ne 0 ]
215then
216    echo "${command} : eee : yyyymmddb ${yyyymmddb} argument invalid"
217    exit 1
218fi
219unset status_date
220#
221if [[ "${yyyymmddb}" < "${yyyymmddb_min}" ]]
222then
223    echo "${command} : eee : yyyymmddb ${yyyymmddb} must be equal or greater than yyyymmddb_min ${yyyymmddb_min}"
224    exit 1
225fi
226#
227${date_cmd} -d "${yyyymmdde}" > /dev/null
228status_date=${?}
229if [ ${status_date} -ne 0 ]
230then
231    echo "${command} : eee : yyyymmdde ${yyyymmdde} argument invalid"
232    exit 1
233fi
234unset status_date
235#
236if [[ "${yyyymmdde}" > "${yyyymmdde_max}" ]]
237then
238    echo "${command} : eee : yyyymmdde ${yyyymmdde} must be lower or equal to yyyymmdde_max ${yyyymmdde_max}"
239    exit 1
240fi
241#
242if [[ "${yyyymmdde}" < "${yyyymmddb}" ]]
243then
244    echo "${command} : eee : yyyymmdde ${yyyymmdde} must be greater than yyyymmddb ${yyyymmddb}"
245    exit 1
246fi
247#
248if [[ "${yyyymmdde}" = "${yyyymmddb}" ]]
249then
250     echo "${command} : eee : yyyymmdde ${yyyymmdde} must be greater than yyyymmddb ${yyyymmddb}"
251     exit 1
252fi
253#
254tool=${IDL_CMD}
255type ${tool} 1> /dev/null 2>&1
256status=${?}
257if [ ${status} -ne 0 ]
258then
259   echo "${command} : eee : tool ${IDL_CMD} not found"
260   echo "${command} : eee : check project_profile.sh sequence"
261   exit 1
262fi
263unset status
264unset tool
265#
266# check for write permission on PROJECT_LOG
267if [ ! -w ${PROJECT_LOG} ]
268then
269   echo "${command} : eee : ${PROJECT_LOG} not writable"
270   exit 1
271fi
272#
273log=${PROJECT_LOG}/$(basename ${0} .sh).log.${log_date}
274echo "[Context]" 1>> ${log}
275echo "command=$(basename ${0})" 1>>${log}
276echo "hostname=${hostname}" 1>> ${log}
277echo "runtime=${log_date}" 1>> ${log}
278echo "IDL_CMD=${IDL_CMD}" 1>> ${log}
279unset log_date
280echo "" 1>> ${log}
281echo "[Parameters]" 1>> ${log}
282echo "yyyymmddb=${yyyymmddb}" 1>> ${log}
283echo "yyyymmdde=${yyyymmdde}" 1>> ${log}
284echo "" 1>> ${log}
285#
286cat >> ${PROJECT}/src/tropflux_${$}.pro << EOF
287pro tropflux_${$}
288compile_opt idl2, strictarrsubs, logical_predicate
289@cm_project
290;
291; define overwrite status
292; set to 1 to overwrite existing files
293project_overwrite = 0
294;
295result = oaflux_mask_30n30s()
296IF result < 0 THEN BEGIN
297   msg = 'eee : pb after oaflux_mask_30n30s' + string(result)
298   err = report(msg)
299   exit
300ENDIF
301result = interp_erai_dewt(${yyyymmddb}, ${yyyymmdde})
302IF result < 0 THEN BEGIN
303   msg = 'eee : pb after interp_erai_dewt' + string(result)
304   err = report(msg)
305   exit
306ENDIF
307result = interp_erai_lwr(${yyyymmddb}, ${yyyymmdde})
308IF result < 0 THEN BEGIN
309   msg = 'eee : pb after interp_erai_lwr' + string(result)
310   err = report(msg)
311   exit
312ENDIF
313result = interp_erai_msl(${yyyymmddb}, ${yyyymmdde})
314IF result < 0 THEN BEGIN
315   msg = 'eee : pb after interp_erai_msl' + string(result)
316   err = report(msg)
317   exit
318ENDIF
319;interp_erai_sst_1989_2009
320result = interp_erai_t2m(${yyyymmddb}, ${yyyymmdde})
321IF result < 0 THEN BEGIN
322   msg = 'eee : pb after interp_erai_t2m' + string(result)
323   err = report(msg)
324   exit
325ENDIF
326;interp_erai_ws_1989_2009
327;interp_olr_30n30s_1989_2009
328d2m_to_q2m_erai
329;++Program caused arithmetic error: Floating overflow
330;++ Program caused arithmetic error: Floating illegal operand
331;.compile TropFlux_swr_DT_19890101_20071231
332;tropflux_swr_dt_19890101_20071231
333;.compile TropFlux_swr_NRT_19890101_20091231
334;tropflux_swr_nrt_19890101_20091231
335;.compile TropFlux_swr_BLND_19890101_20091231
336;tropflux_swr_blnd_19890101_20091231
337;lwr_correction_ncdf
338;q2m_correction_ncdf
339;sst_correction_ncdf
340;t2m_correction_ncdf
341;ws_correction_ncdf
342;cronin_gustiness_ncdf
343;.compile TropFlux_19890101_20091231
344;tropflux_19890101_20091231
345;.compile TropFlux_NRT_ncdf
346;tropflux_nrt_ncdf
347end
348EOF
349#
350# run IDL or equivalent
351${IDL_CMD} << EOF >> ${log} 2>&1
352.compile file_interp
353;
354tropflux_${$}
355EOF
356status=${?}
357if [ ${status} -ne 0 ]
358then
359   echo "${command} : eee: ${IDL_CMD} failed : ${status}" >> ${log} 2>&1
360   cat ${PROJECT}/src/tropflux_${$}.pro >> ${log} 2>&1
361   exit 1
362fi
363rm ${PROJECT}/src/tropflux_${$}.pro
364unset status
365#
366unset command
367unset log
368unset hostname
369unset usage
370#
371unset date_cmd
372#
373# end
374#++set
375exit
Note: See TracBrowser for help on using the repository browser.