source: trunk/src/tropflux.sh @ 175

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

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