source: trunk/src/tropflux.sh @ 170

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

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