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