source: trunk/src/get_oaflux.sh @ 202

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

add log value in log

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