source: trunk/src/tropflux.sh @ 199

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

introduce new erai dataset : new terminology and new time unit and origin

  • Property svn:eol-style set to native
  • Property svn:executable set to *
  • Property svn:keywords set to Id URL
File size: 12.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 [-f] -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# .. option:: -f to overwrite existing files
29#
30# Some IDL programs are launched here using ${IDL_CMD} command
31# (see :ref:`project_profile.sh` to know how to set this environnement variable).
32#
33# Log file is written on
34# :file:`${PROJECT_LOG}/tropflux.log.{YYYYMMDDTHHMMSSZ}`
35#
36# .. only:: man
37#
38#    Figure is visible on PDF and HTML documents only.
39#
40# .. only:: html or latex
41#
42#     .. graphviz::
43#
44#        digraph tropflux {
45#
46#           file_oaflux [shape=ellipse,fontname=Courier,label="${PROJECT_ID}/lh_oaflux_2004.nc"];
47
48#           log [shape=ellipse,fontname=Courier,label="${PROJECT_LOG}/tropflux.log{YYYYMMDDTHHMMSSZ}"];
49#
50#           tropflux [shape=box,
51#           fontname=Courier,
52#           color=blue,
53#           URL="http://forge.ipsl.jussieu.fr/tropflux/browser/trunk/src/tropflux.sh",
54#           label="${PROJECT}/src/tropflux.sh"];
55#
56#           {file_oaflux} -> {tropflux} -> {log fileout}
57#
58#         }
59#
60# EXAMPLES
61# ========
62#
63# You already used :ref:`get_erai.sh` to get ERAI data, etc.,
64# during [20000101, 20000302[ and you want to produce NetCDF files::
65#
66#   $ tropflux.sh -b 20000101 -e 20000302
67#
68# A more global example::
69#
70#   $ tropflux.sh -b 19890101 -e 20091231
71#
72# And look at log file with ::
73#
74#  $ tlogd.sh tropflux
75#
76# and of course on files in ${PROJECT_ID}.
77#
78# SEE ALSO
79# ========
80#
81# IDL_
82#
83# .. _IDL: http://www.ittvis.com/ProductServices/IDL.aspx
84#
85# :ref:`project_profile.sh`
86# :ref:`project_init.pro`
87#
88# Previous step : :ref:`get_erai.sh`, :ref:`get_oaflux.sh`, :ref:`get_olr.sh`,
89# :ref:`get_pirata_netcdf.sh`, :ref:`get_swr.sh`
90#
91# Use :
92# :ref:`concat_eraiy.sh`,
93# :func:`oaflux_mask_30n30s`, :func:`interp_erai_t2m`,
94# :func:`interp_erai_msl`, :func:`interp_erai_dewt`, :func:`interp_erai_lwr`,
95# :func:`interp_erai_sst`, :func:`interp_erai_ws`, :func:`interp_olr_30n30s`,
96# :func:`d2m_to_q2m_erai`, :func:`sst_correction_ncdf`,
97# :func:`lwr_correction_ncdf`, :func:`q2m_correction_ncdf`,
98# :func:`t2m_correction_ncdf`, :func:`ws_correction_ncdf`,
99# :func:`tropflux_swr_dt`, :func:`tropflux_swr_nrt`, :func:`tropflux_swr_blnd`,
100# :func:`tropflux_nrt_ncdf`,:func:`tropflux_wind_stress`
101# etc.
102#
103# Next step : +validation ++ comparison
104#
105# .. todo::
106#
107# TODO
108# ====
109#
110# make it work
111#
112# if yyyymmdd < 20071231, is it meaningfull to call all the functions ?
113#
114# idl status = 0 even if not ok
115#
116# test if demo mode idl
117#
118# EVOLUTIONS
119# ==========
120#
121# $Id$
122#
123# $URL$
124#
125# - fplod 20120704T123711Z cratos (Linux)
126#
127#   * typo
128#   * add usage of concat_eraiy.sh
129#   * really implement -f option
130#
131# - pinsard 20120329
132#
133#   * add tropflux_wind_stress (to be consolidated)
134#
135# - pinsard 20120326
136#
137#   * TropFlux_NRT_ncdf replace by tropflux_nrt_ncdf which is now a function
138#
139# - pinsard 20120322
140#
141#   * handling error of sst_correction_ncdf (now function)
142#   * handling error of lwr_correction_ncdf (now function)
143#   * handling error of q2m_correction_ncdf (now function)
144#   * handling error of t2m_correction_ncdf (now function)
145#   * handling error of ws_correction_ncdf (now function)
146#
147# - pinsard 20120321
148#
149#   * TropFlux_swr_DT_19890101_20071231 replace by tropflux_swr_dt
150#     which is now a function
151#   * TropFlux_swr_NRT_19890101_20071231 replace by tropflux_swr_nrt
152#     which is now a function
153#   * TropFlux_swr_BLND_19890101_20071231 replace by tropflux_swr_blnd
154#     which is now a function
155#   * corrrection of messages when return badly
156#   * reorder for gustiness before tropflux_swr_blnd
157#   * cronin_gustiness_ncdf is now a function
158#
159# - pinsard 20120320
160#
161#   * handling error of interp_erai_sst (now function)
162#   * handling error of interp_erai_ws (now function)
163#   * handling error of interp_olr_30n_30s (now function)
164#   * handling error of d2m_to_q2m_erai (now function)
165#
166# - pinsard 20120319
167#
168#   * add project_overwrite usage
169#   * handling error of interp_erai_msl (now function)
170#   * handling error of interp_erai_dewt (now function)
171#   * handling error of interp_erai_lwr (now function)
172#
173# - pinsard 20120306
174#
175#   * create a pro IDL program to introduce LOGICAL_PREDICATE
176#     thanks to http://www.idlcoyote.com/code_tips/bitwiselogical.html
177#
178# - pinsard 20120305
179#
180#   * creation (draft)
181#   * handling error of oaflux_mask_30n30s (now a function)
182#
183#-
184system=$(uname)
185case "${system}" in
186   AIX|IRIX64)
187     echo "${command} : www : no specific posix checking"
188     date_cmd=date
189   ;;
190   Darwin)
191     set -o posix
192     date_cmd=gdate
193   ;;
194   Linux)
195     set -o posix
196     date_cmd=date
197   ;;
198   *)
199    set -o posix
200   ;;
201esac
202unset system
203#
204set -u
205#
206LANG=POSIX
207#
208command=$(basename ${0})
209log_date=$(date -u +"%Y%m%dT%H%M%SZ")
210#
211usage=" Usage : ${command} [-f] -b yyyymmdd -e yyyymmdd"
212#
213hostname=$(hostname)
214#
215yyyymmddb_min=19790101
216yyyymmdde_max=20110930
217#
218# default
219debug=0
220force=0
221yyyymmddb=20000101
222yyyymmdde=20000302
223#
224minargcount=4
225if [ ${#} -lt ${minargcount} ]
226then
227   echo "${command} : eee : not enought arguments"
228   echo "${usage}"
229   exit 1
230fi
231unset minargcount
232#
233while [ ${#} -gt 0 ]
234do
235   case ${1} in
236     -b)
237        # first date to process
238        yyyymmddb=${2}
239        shift
240     ;;
241     -e)
242        # last date to process
243        yyyymmdde=${2}
244        shift
245     ;;
246     -f)
247        force=1
248     ;;
249     -h)
250        echo "${usage}"
251        exit 0
252     ;;
253     *)
254        # other choice
255        echo "${command} : eee : unknown option ${1}"
256        echo "${usage}"
257        exit 1
258     ;;
259   esac
260   # next flag
261   shift
262done
263unset usage
264#
265# check parameters
266# and define associated variables
267${date_cmd} -d "${yyyymmddb}" > /dev/null
268status_date=${?}
269if [ ${status_date} -ne 0 ]
270then
271    echo "${command} : eee : yyyymmddb ${yyyymmddb} argument invalid"
272    exit 1
273fi
274unset status_date
275#
276if [[ "${yyyymmddb}" < "${yyyymmddb_min}" ]]
277then
278    echo "${command} : eee : yyyymmddb ${yyyymmddb} must be equal or greater than yyyymmddb_min ${yyyymmddb_min}"
279    exit 1
280fi
281#
282${date_cmd} -d "${yyyymmdde}" > /dev/null
283status_date=${?}
284if [ ${status_date} -ne 0 ]
285then
286    echo "${command} : eee : yyyymmdde ${yyyymmdde} argument invalid"
287    exit 1
288fi
289unset status_date
290#
291if [[ "${yyyymmdde}" > "${yyyymmdde_max}" ]]
292then
293    echo "${command} : eee : yyyymmdde ${yyyymmdde} must be lower or equal to yyyymmdde_max ${yyyymmdde_max}"
294    exit 1
295fi
296#
297if [[ "${yyyymmdde}" < "${yyyymmddb}" ]]
298then
299    echo "${command} : eee : yyyymmdde ${yyyymmdde} must be greater than yyyymmddb ${yyyymmddb}"
300    exit 1
301fi
302#
303if [[ "${yyyymmdde}" = "${yyyymmddb}" ]]
304then
305     echo "${command} : eee : yyyymmdde ${yyyymmdde} must be greater than yyyymmddb ${yyyymmddb}"
306     exit 1
307fi
308#
309tool=${IDL_CMD}
310type ${tool} 1> /dev/null 2>&1
311status=${?}
312if [ ${status} -ne 0 ]
313then
314   echo "${command} : eee : tool ${IDL_CMD} not found"
315   echo "${command} : eee : check project_profile.sh sequence"
316   exit 1
317fi
318unset status
319unset tool
320#
321# check for write permission on PROJECT_LOG
322if [ ! -w ${PROJECT_LOG} ]
323then
324   echo "${command} : eee : ${PROJECT_LOG} not writable"
325   exit 1
326fi
327#
328log=${PROJECT_LOG}/$(basename ${0} .sh).log.${log_date}
329echo "[Context]" 1>> ${log}
330echo "command=$(basename ${0})" 1>>${log}
331echo "hostname=${hostname}" 1>> ${log}
332echo "runtime=${log_date}" 1>> ${log}
333echo "log=${log}" 1>> ${log}
334echo "IDL_CMD=${IDL_CMD}" 1>> ${log}
335unset log_date
336echo "" 1>> ${log}
337echo "[Parameters]" 1>> ${log}
338echo "yyyymmddb=${yyyymmddb}" 1>> ${log}
339echo "yyyymmdde=${yyyymmdde}" 1>> ${log}
340echo "" 1>> ${log}
341#
342# prepare era-i files
343concat_eraiy.sh -b ${yyyymmddb} -e ${yyyymmdde}
344# ++ test if ok see TODO in concat_eraiy.sh
345cat >> ${PROJECT}/src/tropflux_${$}.pro << EOF
346pro tropflux_${$}
347compile_opt idl2, strictarrsubs, logical_predicate
348@cm_project
349;
350; define overwrite status
351; set to 1 to overwrite existing files
352project_overwrite = ${force} 
353; define eraitype
354eraitype=2
355;
356result = oaflux_mask_30n30s()
357IF result < 0 THEN BEGIN
358   msg = 'eee : pb after oaflux_mask_30n30s ' + string(result)
359   err = report(msg)
360   exit
361ENDIF
362result = interp_erai_dewt(${yyyymmddb}, ${yyyymmdde}, eraitype)
363IF result < 0 THEN BEGIN
364   msg = 'eee : pb after interp_erai_dewt ' + string(result)
365   err = report(msg)
366   exit
367ENDIF
368result = interp_erai_lwr(${yyyymmddb}, ${yyyymmdde}, eraitype)
369IF result < 0 THEN BEGIN
370   msg = 'eee : pb after interp_erai_lwr ' + string(result)
371   err = report(msg)
372   exit
373ENDIF
374result = interp_erai_msl(${yyyymmddb}, ${yyyymmdde}, eraitype)
375IF result < 0 THEN BEGIN
376   msg = 'eee : pb after interp_erai_msl ' + string(result)
377   err = report(msg)
378   exit
379ENDIF
380result = interp_erai_sst(${yyyymmddb}, ${yyyymmdde}, eraitype)
381IF result < 0 THEN BEGIN
382   msg = 'eee : pb after interp_erai_sst ' + string(result)
383   err = report(msg)
384   exit
385ENDIF
386result = interp_erai_t2m(${yyyymmddb}, ${yyyymmdde}, eraitype)
387IF result < 0 THEN BEGIN
388   msg = 'eee : pb after interp_erai_t2m ' + string(result)
389   err = report(msg)
390   exit
391ENDIF
392result = interp_erai_ws(${yyyymmddb}, ${yyyymmdde}, eraitype)
393IF result < 0 THEN BEGIN
394   msg = 'eee : pb after interp_erai_ws ' + string(result)
395   err = report(msg)
396   exit
397ENDIF
398result = interp_olr_30n30s(${yyyymmddb}, ${yyyymmdde})
399IF result < 0 THEN BEGIN
400   msg = 'eee : pb after interp_olr_30n30s ' + string(result)
401   err = report(msg)
402   exit
403ENDIF
404result = d2m_to_q2m_erai(${yyyymmddb}, ${yyyymmdde})
405IF result < 0 THEN BEGIN
406   msg = 'eee : pb after d2m_to_q2m_erai ' + string(result)
407   err = report(msg)
408   ;++Program caused arithmetic error: Floating overflow
409   ;++ Program caused arithmetic error: Floating illegal operand
410   ;++exit
411ENDIF
412result = tropflux_swr_dt(${yyyymmddb}, ${yyyymmdde})
413IF result < 0 THEN BEGIN
414   msg = 'eee : pb after tropflux_swr_dt ' + string(result)
415   err = report(msg)
416   exit
417ENDIF
418result = tropflux_swr_nrt(${yyyymmddb}, ${yyyymmdde})
419IF result < 0 THEN BEGIN
420   msg = 'eee : pb after tropflux_swr_nrt ' + string(result)
421   err = report(msg)
422   exit
423ENDIF
424result = sst_correction_ncdf(${yyyymmddb}, ${yyyymmdde})
425IF result < 0 THEN BEGIN
426   msg = 'eee : pb after sst_correction_ncdf ' + string(result)
427   err = report(msg)
428   exit
429ENDIF
430result = cronin_gustiness_ncdf(${yyyymmddb}, ${yyyymmdde})
431IF result < 0 THEN BEGIN
432   msg = 'eee : pb after cronin_gustiness_ncdf ' + string(result)
433   err = report(msg)
434   exit
435ENDIF
436result = tropflux_swr_blnd(${yyyymmddb}, ${yyyymmdde})
437IF result < 0 THEN BEGIN
438   msg = 'eee : pb after tropflux_swr_blnd ' + string(result)
439   err = report(msg)
440   exit
441ENDIF
442result = lwr_correction_ncdf(${yyyymmddb}, ${yyyymmdde})
443IF result < 0 THEN BEGIN
444   msg = 'eee : pb after lwr_correction_ncdf ' + string(result)
445   err = report(msg)
446   exit
447ENDIF
448result = q2m_correction_ncdf(${yyyymmddb}, ${yyyymmdde})
449IF result < 0 THEN BEGIN
450   msg = 'eee : pb after q2m_correction_ncdf ' + string(result)
451   err = report(msg)
452   exit
453ENDIF
454result = t2m_correction_ncdf(${yyyymmddb}, ${yyyymmdde})
455IF result < 0 THEN BEGIN
456   msg = 'eee : pb after t2m_correction_ncdf ' + string(result)
457   err = report(msg)
458   exit
459ENDIF
460result = ws_correction_ncdf(${yyyymmddb}, ${yyyymmdde})
461IF result < 0 THEN BEGIN
462   msg = 'eee : pb after ws_correction_ncdf ' + string(result)
463   err = report(msg)
464   exit
465ENDIF
466result = tropflux(${yyyymmddb}, ${yyyymmdde})
467IF result < 0 THEN BEGIN
468   msg = 'eee : pb after tropflux' + string(result)
469   err = report(msg)
470   exit
471ENDIF
472result = tropflux_nrt_ncdf(${yyyymmddb}, ${yyyymmdde})
473IF result < 0 THEN BEGIN
474   msg = 'eee : pb after tropflux_nrt_ncdf' + string(result)
475   err = report(msg)
476   exit
477ENDIF
478result = tropflux_wind_stress(${yyyymmddb}, ${yyyymmdde})
479IF result < 0 THEN BEGIN
480   msg = 'eee : pb after tropflux_wind_stress' + string(result)
481   err = report(msg)
482   exit
483ENDIF
484end
485EOF
486#
487# run IDL or equivalent
488${IDL_CMD} << EOF >> ${log} 2>&1
489.compile file_interp
490;
491tropflux_${$}
492EOF
493status=${?}
494if [ ${status} -ne 0 ]
495then
496   echo "${command} : eee: ${IDL_CMD} failed : ${status}" >> ${log} 2>&1
497   cat ${PROJECT}/src/tropflux_${$}.pro >> ${log} 2>&1
498   exit 1
499fi
500rm ${PROJECT}/src/tropflux_${$}.pro
501unset status
502#
503unset command
504unset log
505unset hostname
506unset usage
507#
508unset date_cmd
509#
510# end
511#++set
512exit
Note: See TracBrowser for help on using the repository browser.