source: trunk/src/tropflux.sh

Last change on this file was 204, checked in by pinsard, 10 years ago

fix thanks to coding rules; typo

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