source: trunk/src/tropflux.sh @ 151

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

draft for global processing tool

  • Property svn:eol-style set to native
  • Property svn:executable set to *
  • Property svn:keywords set to Id URL
File size: 6.3 KB
Line 
1#! /bin/sh -x
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#           log [shape=ellipse,fontname=Courier,label="${PROJECT_LOG}/tropflux.log{YYYYMMDDTHHMMSSZ}"];
46#
47#           tropflux [shape=box,
48#           fontname=Courier,
49#           color=blue,
50#           URL="http://forge.ipsl.jussieu.fr/tropflux/browser/trunk/src/tropflux.sh",
51#           label="${PROJECT}/src/tropflux.sh"];
52#
53#           {++ mask} -> {tropflux} -> {log ++}
54#
55#         }
56#
57# EXAMPLES
58# ========
59#
60# You already used :ref:`get_erai.sh` to get ERAI data, etc.,
61# during [20060801, 20060802[ and you want to produce NetCDF files::
62#
63#   $ tropflux.sh -b 20060801 -e 20060802
64#
65# And look at log file with ::
66#
67#  $ tlogd.sh tropflux
68#
69# and of course on files in ${PROJECT_ID}.
70#
71# SEE ALSO
72# ========
73#
74# IDL_
75#
76# .. _IDL: http://www.ittvis.com/ProductServices/IDL.aspx
77#
78# :ref:`project_profile.sh`
79# :ref:`project_init.pro`
80#
81# Previous step : :ref:`get_erai.sh`, :ref:`get_oaflux.sh`, :ref:`get_olr.sh`,
82# :ref:`get_pirata_netcdf.sh`, :ref:`get_swr.sh`
83#
84# Use :
85# :ref:`inter_erai_t2m_1989_2009.pro`, etc.
86#
87# Next step : +validation ++ comparison
88#
89# .. todo::
90#
91# TODO
92# ====
93#
94# make it work
95#
96# idl status = 0 even if not ok
97#
98# test if demo mode idl
99#
100# EVOLUTIONS
101# ==========
102#
103# $Id$
104#
105# $URL$
106#
107# - pinsard 20120305
108#
109#   * creation (draft)
110#
111#-
112system=$(uname)
113case "${system}" in
114   AIX|IRIX64)
115     echo "${command} : www : no specific posix checking"
116     date_cmd=date
117   ;;
118   Darwin)
119     set -o posix
120     date_cmd=gdate
121   ;;
122   Linux)
123     set -o posix
124     date_cmd=date
125   ;;
126   *)
127    set -o posix
128   ;;
129esac
130unset system
131#
132set -u
133#
134LANG=POSIX
135#
136command=$(basename ${0})
137log_date=$(date -u +"%Y%m%dT%H%M%SZ")
138#
139usage=" Usage : ${command} [-f] -b yyyymmdd -e yyyymmdd"
140#
141hostname=$(hostname)
142#
143yyyymmddb_min=19790101
144yyyymmdde_max=20110930
145#
146# default
147debug=0
148yyyymmddb=20060420
149yyyymmdde=20060420
150#
151minargcount=4
152if [ ${#} -lt ${minargcount} ]
153then
154   echo "${command} : eee : not enought arguments"
155   echo "${usage}"
156   exit 1
157fi
158unset minargcount
159#
160while [ ${#} -gt 0 ]
161do
162   case ${1} in
163     -b)
164        # first date to process
165        yyyymmddb=${2}
166        shift
167     ;;
168     -e)
169        # last date to process
170        yyyymmdde=${2}
171        shift
172     ;;
173     -h)
174        echo "${usage}"
175        exit 0
176     ;;
177     *)
178        # other choice
179        echo "${command} : eee : unknown option ${1}"
180        echo "${usage}"
181        exit 1
182     ;;
183   esac
184   # next flag
185   shift
186done
187unset usage
188#
189# check parameters
190# and define associated variables
191${date_cmd} -d "${yyyymmddb}" > /dev/null
192status_date=${?}
193if [ ${status_date} -ne 0 ]
194then
195    echo "${command} : eee : yyyymmddb ${yyyymmddb} argument invalid"
196    exit 1
197fi
198unset status_date
199#
200if [[ "${yyyymmddb}" < "${yyyymmddb_min}" ]]
201then
202    echo "${command} : eee : yyyymmddb ${yyyymmddb} must be equal or greater than yyyymmddb_min ${yyyymmddb_min}"
203    exit 1
204fi
205#
206${date_cmd} -d "${yyyymmdde}" > /dev/null
207status_date=${?}
208if [ ${status_date} -ne 0 ]
209then
210    echo "${command} : eee : yyyymmdde ${yyyymmdde} argument invalid"
211    exit 1
212fi
213unset status_date
214#
215if [[ "${yyyymmdde}" > "${yyyymmdde_max}" ]]
216then
217    echo "${command} : eee : yyyymmdde ${yyyymmdde} must be lower or equal to yyyymmdde_max ${yyyymmdde_max}"
218    exit 1
219fi
220#
221if [[ "${yyyymmdde}" < "${yyyymmddb}" ]]
222then
223    echo "${command} : eee : yyyymmdde ${yyyymmdde} must be greater than yyyymmddb ${yyyymmddb}"
224    exit 1
225fi
226#
227if [[ "${yyyymmdde}" = "${yyyymmddb}" ]]
228then
229     echo "${command} : eee : yyyymmdde ${yyyymmdde} must be greater than yyyymmddb ${yyyymmddb}"
230     exit 1
231fi
232#
233tool=${IDL_CMD}
234type ${tool} 1> /dev/null 2>&1
235status=${?}
236if [ ${status} -ne 0 ]
237then
238   echo "${command} : eee : tool ${IDL_CMD} not found"
239   echo "${command} : eee : check project_profile.sh sequence"
240   exit 1
241fi
242unset status
243unset tool
244#
245# check for write permission on PROJECT_LOG
246if [ ! -w ${PROJECT_LOG} ]
247then
248   echo "${command} : eee : ${PROJECT_LOG} not writable"
249   exit 1
250fi
251#
252log=${PROJECT_LOG}/$(basename ${0} .sh).log.${log_date}
253echo "[Context]" 1>> ${log}
254echo "command=$(basename ${0})" 1>>${log}
255echo "hostname=${hostname}" 1>> ${log}
256echo "runtime=${log_date}" 1>> ${log}
257echo "IDL_CMD=${IDL_CMD}" 1>> ${log}
258unset log_date
259echo "" 1>> ${log}
260echo "[Parameters]" 1>> ${log}
261echo "yyyymmddb=${yyyymmddb}" 1>> ${log}
262echo "yyyymmdde=${yyyymmdde}" 1>> ${log}
263echo "" 1>> ${log}
264#
265cat >> ${PROJECT}/src/tropflux_${$}.pro << EOF
266.compile file_interp
267;oaflux_mask_30n30s
268;interp_erai_dewt_1989_2009
269;interp_erai_lwr_1989_2009
270;interp_erai_msl_1989_2009
271;interp_erai_sst_1989_2009
272;interp_erai_t2m_1989_2009
273;interp_erai_ws_1989_2009
274;interp_olr_30n30s_1989_2009
275;d2m_to_q2m_erai
276.compile TropFlux_swr_DT_19890101_20071231
277tropflux_swr_dt_19890101_20071231
278.compile TropFlux_swr_NRT_19890101_20091231
279tropflux_swr_nrt_19890101_20091231
280.compile TropFlux_swr_BLND_19890101_20091231
281tropflux_swr_blnd_19890101_20091231
282lwr_correction_ncdf
283q2m_correction_ncdf
284sst_correction_ncdf
285t2m_correction_ncdf
286ws_correction_ncdf
287cronin_gustiness_ncdf
288.compile TropFlux_19890101_20091231
289tropflux_19890101_20091231
290.compile TropFlux_NRT_ncdf
291tropflux_nrt_ncdf
292EOF
293#
294more ${PROJECT}/src/tropflux_${$}.pro
295read a
296#
297# run IDL or equivalent
298${IDL_CMD} << EOF >> ${log} 2>&1
299@tropflux_${$}
300EOF
301status=${?}
302if [ ${status} -ne 0 ]
303then
304   echo "${command} : eee: ${IDL_CMD} failed : ${status}" >> ${log} 2>&1
305   cat ${PROJECT}/src/tropflux_${$}.pro >> ${log} 2>&1
306   exit 1
307fi
308rm ${PROJECT}/src/tropflux_${$}.pro
309unset status
310#
311unset command
312unset log
313unset hostname
314unset usage
315#
316unset date_cmd
317#
318# end
319#++set
320exit
Note: See TracBrowser for help on using the repository browser.