source: trunk/src/tropflux.sh @ 153

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

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