source: trunk/src/get_oaflux.sh

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

fix thanks to coding rules; typo

  • Property svn:executable set to *
File size: 4.7 KB
Line 
1#! /bin/sh
2#+
3#
4# .. program:: get_oaflux.sh
5#
6# .. _get_oaflux.sh:
7#
8# =============
9# get_oaflux.sh
10# =============
11#
12# SYNOPSIS
13# ========
14#
15# .. code-block:: bash
16#
17#    get_oaflux.sh
18#
19# DESCRIPTION
20# ===========
21#
22# Put in ${PROJECT_ID} OAFLUX reference file
23#
24# Once this tool executed :func:`oaflux_mask_30n30s` can be launched.
25#
26# Log file is written on
27# :file:`${PROJECT_LOG}/get_oaflux.log.{YYYYMMDDTHHMMSS}Z`.
28#
29#     .. graphviz::
30#
31#        digraph get_oaflux {
32#
33#           oaflux_ref [shape=diamond,
34#           fontname=Courier,
35#           label="ftp://ftp.whoi.edu/pub/science/oaflux/data_v3/monthly/turbulence/lh_oaflux_2004.nc.gz"];
36#
37#           file_oaflux [shape=ellipse,
38#           fontname=Courier,
39#           label="${PROJECT_ID}/lh_oaflux_2004.nc"];
40#
41#           get_oaflux [shape=box,
42#           fontname=Courier,
43#           color=blue,
44#           URL="http://forge.ipsl.jussieu.fr/tropflux/browser/trunk/src/get_oaflux.sh"
45#           label="${PROJECT}/src/get_oaflux.sh"];
46#           get_oaflux [shape=box,
47#           fontname=Courier,
48#           color=blue,
49#           URL="http://forge.ipsl.jussieu.fr/tropflux/browser/trunk/src/get_oaflux.sh"
50#           label="${PROJECT}/src/get_oaflux.sh"];
51#
52#           {oaflux_ref} -> {get_oaflux} -> {file_oaflux}
53#
54#          }
55#
56#
57# EXAMPLES
58# ========
59#
60# If you are working on LOCEAN machine and you don't have any reference data,
61# you just have to run this tool :
62#
63# .. code-block:: bash
64#
65#    get_oaflux.sh
66#
67# And look at log file with :
68#
69# .. code-block:: bash
70#
71#    tlogd.sh get_oaflux
72#
73# and of course on files in ${PROJECT_ID}.
74#
75# TODO
76# ====
77#
78# get
79# ftp://ftp.whoi.edu/pub/science/oaflux/data_v3/daily/radiation_1985-2007/sw_isccp_yyyy.nc.gz
80# and generate ${PROJECT_ID}/swr_oafluxgrid_1985_2007.nc somewhere else
81#
82# SEE ALSO
83# ========
84#
85# :ref:`guide data OAFLUX <data_in_oaflux>`
86#
87# :ref:`project_profile.sh`
88#
89# :func:`oaflux_mask_30n30s`
90#
91# EVOLUTIONS
92# ==========
93#
94# - fplod 20110421T125407Z aedon.locean-ipsl.upmc.fr (Darwin)
95#
96#   * typo
97#
98# - fplod 20101216T152647Z aedon.locean-ipsl.upmc.fr (Darwin)
99#
100#   * creation
101#
102#-
103system=$(uname)
104case "${system}" in
105    AIX|IRIX64)
106        echo "www : no specific posix checking"
107    ;;
108    *)
109        set -o posix
110    ;;
111esac
112unset system
113#
114LANG=POSIX
115#
116command=$(basename ${0})
117log_date=$(date -u +"%Y%m%dT%H%M%SZ")
118#
119usage=" Usage : ${command}"
120#
121hostname=$(hostname)
122#
123# default
124# N.A. because no parameters
125#
126set -u
127#
128# test if wget available
129tool=wget
130type ${tool} 1> /dev/null 2>&1
131status=${?}
132if [ ${status} -ne 0 ]
133then
134    echo "${command} : eee : tool ${tool} not found"
135    exit 1
136fi
137unset status
138unset tool
139#
140# test if gunzip available
141tool=gunzip
142type ${tool} 1> /dev/null 2>&1
143status=${?}
144if [ ${status} -ne 0 ]
145then
146    echo "${command} : eee : tool ${tool} not found"
147    exit 1
148fi
149unset status
150unset tool
151#
152# check for ${PROJECT_LOG} definition
153if [ "${PROJECT_LOG}" = "" ]
154then
155    echo "${command} : eee : \${PROJECT_LOG} not defined"
156    exit 1
157fi
158#
159# check for ${PROJECT_LOG} existence
160if [ ! -d ${PROJECT_LOG} ]
161then
162    echo "${command} : eee : ${PROJECT_LOG} not found"
163    exit 1
164fi
165#
166# check for permission access on PROJECT_LOG
167if [ ! -x ${PROJECT_LOG} ]
168then
169    echo "${command} : eee : ${PROJECT_LOG} not reachable"
170    exit 1
171fi
172#
173# check for write permission on PROJECT_LOG
174if [ ! -w ${PROJECT_LOG} ]
175then
176    echo "${command} : eee : ${PROJECT_LOG} not writable"
177    exit 1
178fi
179#
180log=${PROJECT_LOG}/$(basename ${0} .sh).log.${log_date}
181echo "[Context]" 1>> ${log}
182echo "command=$(basename ${0})" 1>>${log}
183echo "hostname=${hostname}" 1>> ${log}
184echo "runtime=${log_date}" 1>> ${log}
185echo "log=${log}" 1>> ${log}
186unset log_date
187echo "" 1>> ${log}
188#
189fileref=lh_oaflux_2004.nc
190fileref_gz=${fileref}.gz
191locref=ftp://ftp.whoi.edu/pub/science/oaflux/data_v3/monthly/turbulence/
192if  [ -f ${PROJECT_ID}/${fileref} ]
193then
194    echo "${command} : iii : ${PROJECT_ID}/${fileref} exist" 1>> ${log}
195    echo "${command} : iii : nothing done" 1>> ${log}
196else
197    wget --tries=1 --no-verbose -P ${PROJECT_ID} ${locref}/${fileref_gz} 1>> ${log} 2>&1
198    wget_status=${?}
199    if [ ${wget_status} -ne 0 ]
200    then
201        echo "${command} : eee : ${locref}/${fileref_gz} not found" >> ${log} 2>&1
202        # exit 1 #++
203    else
204        echo "${command} : iii : ${locref}/${fileref_gz} found" >> ${log} 2>&1
205    fi
206    unset wget_status
207    #
208    # decompress
209    gunzip ${PROJECT_ID}${fileref_gz}
210    gunzip_status=${?}
211    if [ ${gunzip_status} -ne 0 ]
212    then
213        echo "${command} : eee : ${locref}/${fileref_gz} not found" >> ${log} 2>&1
214        # exit 1 #++
215    else
216        echo "${command} : iii : ${locref}/${fileref_gz} found" >> ${log} 2>&1
217    fi
218fi
219unset fileref
220unset fileref_gz
221unset locref
222#
223unset command
224unset log
225unset hostname
226#
227# end
228exit 0
Note: See TracBrowser for help on using the repository browser.