source: trunk/src/tropflux.sh @ 164

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

fix for developper documentation

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