source: trunk/src/tropflux.sh @ 190

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

add log value in log

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