1 | #! /bin/sh |
---|
2 | #+ |
---|
3 | # |
---|
4 | # .. program:: get_swr.sh |
---|
5 | # |
---|
6 | # .. _get_swr.sh: |
---|
7 | # |
---|
8 | # ========== |
---|
9 | # get_swr.sh |
---|
10 | # ========== |
---|
11 | # |
---|
12 | # SYNOPSIS |
---|
13 | # ======== |
---|
14 | # |
---|
15 | # .. code-block:: bash |
---|
16 | # |
---|
17 | # get_swr.sh |
---|
18 | # |
---|
19 | # DESCRIPTION |
---|
20 | # =========== |
---|
21 | # |
---|
22 | # ``get_swr.sh`` get SWR reference files. |
---|
23 | # |
---|
24 | # Log file is written on :file:`${PROJECT_LOG}/get_swr.log.{YYYYMMDDTHHMMSSZ}` |
---|
25 | # |
---|
26 | # .. graphviz:: |
---|
27 | # |
---|
28 | # digraph get_swr { |
---|
29 | # |
---|
30 | # swr_ref [shape=diamond, |
---|
31 | # fontname=Courier, |
---|
32 | # label="ftp://ftp.whoi.edu/pub/science/oaflux/data_v3/daily/radiation_1985-2007/sw_icssp_yyyy.nc.gz"]; |
---|
33 | # |
---|
34 | # file_swr [shape=ellipse, |
---|
35 | # fontname=Courier, |
---|
36 | # label="${PROJECT_ID}/sw_icssp_yyyy.nc"]; |
---|
37 | # |
---|
38 | # get_swr [shape=box, |
---|
39 | # fontname=Courier, |
---|
40 | # color=blue, |
---|
41 | # URL="http://forge.ipsl.jussieu.fr/tropflux/browser/trunk/src/get_swr.sh" |
---|
42 | # label="${PROJECT}/src/get_swr.sh"]; |
---|
43 | # |
---|
44 | # {swr_ref} -> {get_swr} -> {file_swr} |
---|
45 | # |
---|
46 | # } |
---|
47 | # |
---|
48 | # EXAMPLES |
---|
49 | # ======== |
---|
50 | # |
---|
51 | # You don't have any RAMA reference data, you just have to run this tool : |
---|
52 | # |
---|
53 | # .. code-block:: bash |
---|
54 | # |
---|
55 | # get_swr.sh |
---|
56 | # |
---|
57 | # And look at log file with : |
---|
58 | # |
---|
59 | # .. code-block:: bash |
---|
60 | # |
---|
61 | # tlogd.sh get_swr |
---|
62 | # |
---|
63 | # and of course on files in ${PROJECT_ID}. |
---|
64 | # |
---|
65 | # SEE ALSO |
---|
66 | # ======== |
---|
67 | # |
---|
68 | # :ref:`data_in_swr` |
---|
69 | # |
---|
70 | # :ref:`project_profile.sh` |
---|
71 | # |
---|
72 | # TODO |
---|
73 | # ==== |
---|
74 | # |
---|
75 | # complete description |
---|
76 | # |
---|
77 | # Eventually: we should retrieve them from ISCCP page |
---|
78 | # (ftp://isccp.giss.nasa.gov/pub/data/FC/ ) and interpolate them we |
---|
79 | # need FD${YYYY}${MM}__${SS}${FF}SFC.EQ files where: |
---|
80 | # |
---|
81 | # - YYYY and MM are year and month |
---|
82 | # - SS is LW (longwave) and SW (shortwave) |
---|
83 | # |
---|
84 | # study wget status (no exit now on non null wget status) |
---|
85 | # |
---|
86 | # chain to concatenation and geobox reduction .. and rename sw\_ to swr file |
---|
87 | # variable name ?? to swr |
---|
88 | # |
---|
89 | # EVOLUTIONS |
---|
90 | # ========== |
---|
91 | # |
---|
92 | # $Id$ |
---|
93 | # |
---|
94 | # $URL$ |
---|
95 | # |
---|
96 | # - fplod 20110811T153513Z aedon.locean-ipsl.upmc.fr (Darwin) |
---|
97 | # |
---|
98 | # * creation |
---|
99 | # |
---|
100 | #- |
---|
101 | system=$(uname) |
---|
102 | case "${system}" in |
---|
103 | AIX|IRIX64) |
---|
104 | echo "www : no specific posix checking" |
---|
105 | date_cmd=date |
---|
106 | ;; |
---|
107 | Darwin) |
---|
108 | set -o posix |
---|
109 | date_cmd=gdate |
---|
110 | ;; |
---|
111 | Linux) |
---|
112 | set -o posix |
---|
113 | date_cmd=date |
---|
114 | ;; |
---|
115 | *) |
---|
116 | set -o posix |
---|
117 | ;; |
---|
118 | esac |
---|
119 | unset system |
---|
120 | # |
---|
121 | LANG=POSIX |
---|
122 | # |
---|
123 | command=$(basename ${0}) |
---|
124 | log_date=$(date -u +"%Y%m%dT%H%M%SZ") |
---|
125 | # |
---|
126 | usage=" Usage : ${command}" |
---|
127 | # |
---|
128 | hostname=$(hostname) |
---|
129 | # |
---|
130 | # default |
---|
131 | # N.A. because no parameters |
---|
132 | # |
---|
133 | set -u |
---|
134 | # |
---|
135 | # test if wget available |
---|
136 | tool=wget |
---|
137 | type ${tool} 1> /dev/null 2>&1 |
---|
138 | status=${?} |
---|
139 | if [ ${status} -ne 0 ] |
---|
140 | then |
---|
141 | echo "${command} : eee : tool ${tool} not found" |
---|
142 | exit 1 |
---|
143 | fi |
---|
144 | unset status |
---|
145 | unset tool |
---|
146 | # |
---|
147 | # check for ${PROJECT_LOG} definition |
---|
148 | if [ "${PROJECT_LOG}" = "" ] |
---|
149 | then |
---|
150 | echo "${command} : eee : \${PROJECT_LOG} not defined" |
---|
151 | exit 1 |
---|
152 | fi |
---|
153 | # |
---|
154 | # check for ${PROJECT_LOG} existence |
---|
155 | if [ ! -d ${PROJECT_LOG} ] |
---|
156 | then |
---|
157 | echo "${command} : eee : ${PROJECT_LOG} not found" |
---|
158 | exit 1 |
---|
159 | fi |
---|
160 | # |
---|
161 | # check for permission access on PROJECT_LOG |
---|
162 | if [ ! -x ${PROJECT_LOG} ] |
---|
163 | then |
---|
164 | echo "${command} : eee : ${PROJECT_LOG} not reachable" |
---|
165 | exit 1 |
---|
166 | fi |
---|
167 | # |
---|
168 | # check for write permission on PROJECT_LOG |
---|
169 | if [ ! -w ${PROJECT_LOG} ] |
---|
170 | then |
---|
171 | echo "${command} : eee : ${PROJECT_LOG} not writable" |
---|
172 | exit 1 |
---|
173 | fi |
---|
174 | # |
---|
175 | log=${PROJECT_LOG}/$(basename ${0} .sh).log.${log_date} |
---|
176 | echo "[Context]" 1>> ${log} |
---|
177 | echo "command=$(basename ${0})" 1>>${log} |
---|
178 | echo "hostname=${hostname}" 1>> ${log} |
---|
179 | echo "runtime=${log_date}" 1>> ${log} |
---|
180 | echo "log=${log}" 1>> ${log} |
---|
181 | unset log_date |
---|
182 | echo "" 1>> ${log} |
---|
183 | # |
---|
184 | yearmin=1985 |
---|
185 | yearmax=2007 |
---|
186 | # |
---|
187 | varlist="sw" |
---|
188 | # |
---|
189 | locref="ftp://ftp.whoi.edu/pub/science/oaflux/data_v3/daily/radiation_1985-2007/" |
---|
190 | # |
---|
191 | list_url="" |
---|
192 | # |
---|
193 | # build URL = f(year,var) |
---|
194 | yyyy=${yearmin} |
---|
195 | while [ ${yyyy} -le ${yearmax} ] |
---|
196 | do |
---|
197 | for var in ${varlist} |
---|
198 | do |
---|
199 | list_url="${list_url} ${locref}/${var}_isccp_${yyyy}.nc.gz" |
---|
200 | done |
---|
201 | unset var |
---|
202 | yyyy=$(( ${yyyy} + 1 )) |
---|
203 | done |
---|
204 | unset varlist |
---|
205 | unset locref |
---|
206 | # |
---|
207 | # if file_gz is not already in ${PROJECT_ID}, get it |
---|
208 | for url in ${list_url} |
---|
209 | do |
---|
210 | file_gz=${PROJECT_ID}/$(basename ${url}) |
---|
211 | file=${PROJECT_ID}/$(basename ${file_gz} .gz) |
---|
212 | if [ ! -f ${file} ] |
---|
213 | then |
---|
214 | if [ ! -f ${file_gz} ] |
---|
215 | then |
---|
216 | wget --tries=1 --no-verbose -P ${PROJECT_ID} \ |
---|
217 | ${url} >> ${log} 2>&1 |
---|
218 | wget_status=${?} |
---|
219 | if [ ${wget_status} -ne 0 ] |
---|
220 | then |
---|
221 | echo "${command} : eee : ${url} not found" >> ${log} 2>&1 |
---|
222 | # ++ exit 1 |
---|
223 | else |
---|
224 | echo "${command} : iii : ${url} found" >> ${log} 2>&1 |
---|
225 | fi |
---|
226 | unset wget_status |
---|
227 | else |
---|
228 | echo "iii : ${file_gz} exists" >> ${log} |
---|
229 | gunzip -c ${file_gz} > ${file} |
---|
230 | fi |
---|
231 | else |
---|
232 | echo "iii : ${file} exists" >> ${log} |
---|
233 | fi |
---|
234 | done |
---|
235 | unset file_gz |
---|
236 | unset file |
---|
237 | unset url |
---|
238 | unset list_url |
---|
239 | # |
---|
240 | unset command |
---|
241 | unset log |
---|
242 | unset hostname |
---|
243 | unset usage |
---|
244 | # |
---|
245 | # end |
---|
246 | set |
---|
247 | exit 0 |
---|