source: trunk/src/tropflux.sh @ 174

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

bunch of new functions

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