1 | #! /bin/sh |
---|
2 | # |
---|
3 | #+ |
---|
4 | # |
---|
5 | # .. program:: add_19890101.sh |
---|
6 | # |
---|
7 | # .. _add_19890101.sh: |
---|
8 | # |
---|
9 | # =============== |
---|
10 | # add_19890101.sh |
---|
11 | # =============== |
---|
12 | # |
---|
13 | # SYNOPSIS |
---|
14 | # ======== |
---|
15 | # |
---|
16 | # .. code-block:: bash |
---|
17 | # |
---|
18 | # add_19890101.sh [--debug] |
---|
19 | # |
---|
20 | # DESCRIPTION |
---|
21 | # =========== |
---|
22 | # |
---|
23 | # .. option:: --debug |
---|
24 | # |
---|
25 | # If this option is set, :samp:`ncdump -v tt` will be added to log file |
---|
26 | # |
---|
27 | # Artificially add 19890101 to lwr interpolated on OAFLUX grid dataset. |
---|
28 | # |
---|
29 | # :file:`${PROJECT_OD}/erai_lwr_19890102_20091231_oafluxgrid.nc` |
---|
30 | # containing |
---|
31 | # ++ |
---|
32 | # has been produced by |
---|
33 | # :func:`interp_erai_lwr`. |
---|
34 | # repeat the first time step in |
---|
35 | # |
---|
36 | # File :file:`${PROJECT_OD}/erai_lwr_19890101_20091231_oafluxgrid.nc` |
---|
37 | # will be written |
---|
38 | # if this file not already exists. |
---|
39 | # |
---|
40 | # This output file |
---|
41 | # :file:`${PROJECT_OD}/erai_lwr_19890101_20091231_oafluxgrid.nc` |
---|
42 | # must be processed after by |
---|
43 | # :func:`lwr_correction_ncdf`. |
---|
44 | # |
---|
45 | # Log file is written on |
---|
46 | # :file:`${PROJECT_LOG}/add_19890101.sh.log.{YYYYMMDDTHHMMSS}Z`. |
---|
47 | # |
---|
48 | # .. graphviz:: |
---|
49 | # |
---|
50 | # digraph add_19890101 { |
---|
51 | # |
---|
52 | # filein [shape=ellipse, |
---|
53 | # fontname=Courier, |
---|
54 | # label="${PROJECT_OD}/erai_lwr_19890102_20091231_oafluxgrid.nc"]; |
---|
55 | # |
---|
56 | # fileout [shape=ellipse, |
---|
57 | # fontname=Courier, |
---|
58 | # label="${PROJECT_OD}/erai_lwr_19890101_20091231_oafluxgrid.nc"]; |
---|
59 | # |
---|
60 | # add_19890101 [shape=box, |
---|
61 | # fontname=Courier, |
---|
62 | # color=blue, |
---|
63 | # URL="http://forge.ipsl.jussieu.fr/tropflux/browser/trunk/src/add_19890101.sh", |
---|
64 | # label="${PROJECT}/src/add_19890101.sh"]; |
---|
65 | # |
---|
66 | # {filein} -> {add_19890101} -> {fileout} |
---|
67 | # |
---|
68 | # } |
---|
69 | # |
---|
70 | # EXAMPLES |
---|
71 | # ======== |
---|
72 | # |
---|
73 | # To produce ${PROJECT_OD}/erai_lwr_19890101_20091231_oafluxgrid.nc |
---|
74 | # from ${PROJECT_OD}/erai_lwr_19890102_20091231_oafluxgrid.nc : |
---|
75 | # |
---|
76 | # .. code-block:: bash |
---|
77 | # |
---|
78 | # add_19890101.sh --debug |
---|
79 | # |
---|
80 | # And look at log file with : |
---|
81 | # |
---|
82 | # .. code-block:: bash |
---|
83 | # |
---|
84 | # tlogd.sh add_19890101 |
---|
85 | # |
---|
86 | # and of course on files in ${PROJECT_OD}. |
---|
87 | # |
---|
88 | # TIPS |
---|
89 | # ==== |
---|
90 | # |
---|
91 | # To see the 3 first time values in input and files: |
---|
92 | # |
---|
93 | # .. code-block:: bash |
---|
94 | # |
---|
95 | # ncks -s "%16.10f\n" -v tt -d time,0,2 ${PROJECT_OD}/erai_lwr_19890102_20091231_oafluxgrid.nc |
---|
96 | # |
---|
97 | # .. parsed-literal:: |
---|
98 | # |
---|
99 | # 14246.0000000005 |
---|
100 | # 14247.0000000005 |
---|
101 | # 14248.0000000005 |
---|
102 | # |
---|
103 | # .. code-block:: bash |
---|
104 | # |
---|
105 | # ncks -s "%16.10f\n" -v tt -d time,0,2 ${PROJECT_OD}/erai_lwr_19890101_20091231_oafluxgrid.nc |
---|
106 | # |
---|
107 | # .. parsed-literal:: |
---|
108 | # |
---|
109 | # 14245.0000000005 |
---|
110 | # 14246.0000000005 |
---|
111 | # 14247.0000000005 |
---|
112 | # |
---|
113 | # while : |
---|
114 | # |
---|
115 | # .. code-block:: idl |
---|
116 | # |
---|
117 | # print, julday(01, 01, 1989,12)-julday(01, 01, 1950,0) |
---|
118 | # |
---|
119 | # .. parsed-literal:: |
---|
120 | # |
---|
121 | # 14245.500 |
---|
122 | # |
---|
123 | # .. code-block:: idl |
---|
124 | # |
---|
125 | # print, julday(01, 01, 1989,12)-julday(01, 01, 1950,0) +1 |
---|
126 | # |
---|
127 | # .. parsed-literal:: |
---|
128 | # |
---|
129 | # 14246.500 |
---|
130 | # |
---|
131 | # SEE ALSO |
---|
132 | # ======== |
---|
133 | # |
---|
134 | # :ref:`project_profile.sh` |
---|
135 | # |
---|
136 | # :func:`ncks <nco:ncks>` |
---|
137 | # :func:`ncrcat <nco:ncrcat>` |
---|
138 | # :func:`ncatted <nco:ncatted>` |
---|
139 | # :func:`ncap2 <nco:ncap2>` |
---|
140 | # |
---|
141 | # :ref:`lwr_correction_ncdf.pro` |
---|
142 | # |
---|
143 | # TODO |
---|
144 | # ==== |
---|
145 | # |
---|
146 | # coding rules |
---|
147 | # |
---|
148 | # won't it be more convenient to add this artificial time step in |
---|
149 | # the IDL creation tool interp_erai_lwr_1989_2009.pro. |
---|
150 | # It will allow to avoid a shell interruption in the IDL processing chain. |
---|
151 | # |
---|
152 | # improve global attributes with ... creation_date and so on |
---|
153 | # |
---|
154 | # check if the first time step is really 19890102 in the input file |
---|
155 | # |
---|
156 | # change tt to ttt to complete time correction |
---|
157 | # |
---|
158 | # remove hard coded end time |
---|
159 | # |
---|
160 | # get rid of this long message on cratos: |
---|
161 | # |
---|
162 | # .. parsed-literal:: |
---|
163 | # |
---|
164 | # ncrcat: WARNING Variable lwr has attribute "missing_value" but not "_FillValue". To |
---|
165 | # comply with netCDF conventions, NCO ignores values that equal the _FillValue attribu |
---|
166 | # te when performing arithmetic. Confusingly, values equal to the missing_value should |
---|
167 | # also be neglected. However, it is tedious and (possibly) computationally expensive |
---|
168 | # to check each value against multiple missing values during arithmetic on large varia |
---|
169 | # bles. So NCO thinks that processing variables with a "missing_value" attribute and n |
---|
170 | # o "_FillValue" attribute may produce undesired arithmetic results (i.e., where value |
---|
171 | # s that were intended to be neglected were not, in fact, neglected). We suggest you r |
---|
172 | # ename all "missing_value" attributes to "_FillValue" or include both "missing_value" |
---|
173 | # and "_FillValue" attributes (with the _same values_) for all variables that have ei |
---|
174 | # ther attribute. Because it is long, this message is only printed once per operator e |
---|
175 | # ven though multiple variables may have the same attribute configuration. More inform |
---|
176 | # ation on missing values is given at: |
---|
177 | # http://nco.sf.net/nco.html#mss_val |
---|
178 | # Examples of renaming attributes are at: |
---|
179 | # http://nco.sf.net/nco.html#xmp_ncrename |
---|
180 | # |
---|
181 | # ... on a déjà une idée de la solution : convention CF et meilleure gestion |
---|
182 | # des valeurs manquantes dans les softs IDL !!! |
---|
183 | # |
---|
184 | # EVOLUTIONS |
---|
185 | # ========== |
---|
186 | # |
---|
187 | # $Id$ |
---|
188 | # |
---|
189 | # $URL$ |
---|
190 | # |
---|
191 | # - fplod 20110819T091143Z aedon.locean-ipsl.upmc.fr (Darwin) |
---|
192 | # |
---|
193 | # * creation from pk email 20110811 "lwr first timestep" |
---|
194 | # * include time correction and timerange modification |
---|
195 | # |
---|
196 | #- |
---|
197 | system=$(uname) |
---|
198 | case "${system}" in |
---|
199 | AIX|IRIX64) |
---|
200 | echo "www : no specific posix checking" |
---|
201 | date_cmd=date |
---|
202 | ;; |
---|
203 | Darwin) |
---|
204 | set -o posix |
---|
205 | date_cmd=gdate |
---|
206 | ;; |
---|
207 | Linux) |
---|
208 | set -o posix |
---|
209 | date_cmd=date |
---|
210 | ;; |
---|
211 | *) |
---|
212 | set -o posix |
---|
213 | ;; |
---|
214 | esac |
---|
215 | unset system |
---|
216 | # |
---|
217 | LANG=POSIX |
---|
218 | # |
---|
219 | set -u |
---|
220 | # |
---|
221 | command=$(basename ${0}) |
---|
222 | log_date=$(date -u +"%Y%m%dT%H%M%SZ") |
---|
223 | # |
---|
224 | usage=" Usage : ${command} [--debug]" |
---|
225 | # |
---|
226 | hostname=$(hostname) |
---|
227 | # |
---|
228 | # default |
---|
229 | debug=0 |
---|
230 | # |
---|
231 | minargcount=0 |
---|
232 | if [ ${#} -lt ${minargcount} ] |
---|
233 | then |
---|
234 | echo "${command} : eee : not enought arguments" |
---|
235 | echo "${usage}" |
---|
236 | exit 1 |
---|
237 | fi |
---|
238 | # |
---|
239 | while [ ${#} -gt 0 ] |
---|
240 | do |
---|
241 | case ${1} in |
---|
242 | --debug) |
---|
243 | debug=1 |
---|
244 | ;; |
---|
245 | *) |
---|
246 | # anything else |
---|
247 | echo "${command} : eee : unknown option ${1}" |
---|
248 | echo "${command} : eee : ${usage}" |
---|
249 | exit 1 |
---|
250 | ;; |
---|
251 | esac |
---|
252 | # next flag |
---|
253 | shift |
---|
254 | done |
---|
255 | # |
---|
256 | # check parameters |
---|
257 | # N.A. |
---|
258 | # |
---|
259 | tool=ncrcat |
---|
260 | type ${tool} 1> /dev/null 2>&1 |
---|
261 | status=${?} |
---|
262 | if [ ${status} -ne 0 ] |
---|
263 | then |
---|
264 | echo "${command} : eee : tool ${tool} not found" |
---|
265 | exit 1 |
---|
266 | fi |
---|
267 | unset status |
---|
268 | unset tool |
---|
269 | # |
---|
270 | tool=ncks |
---|
271 | type ${tool} 1> /dev/null 2>&1 |
---|
272 | status=${?} |
---|
273 | if [ ${status} -ne 0 ] |
---|
274 | then |
---|
275 | echo "${command} : eee : tool ${tool} not found" |
---|
276 | exit 1 |
---|
277 | fi |
---|
278 | unset status |
---|
279 | unset tool |
---|
280 | # |
---|
281 | tool=ncatted |
---|
282 | type ${tool} 1> /dev/null 2>&1 |
---|
283 | status=${?} |
---|
284 | if [ ${status} -ne 0 ] |
---|
285 | then |
---|
286 | echo "${command} : eee : tool ${tool} not found" |
---|
287 | exit 1 |
---|
288 | fi |
---|
289 | unset status |
---|
290 | unset tool |
---|
291 | # |
---|
292 | # check for ${PROJECT_LOG} definition |
---|
293 | if [ "${PROJECT_LOG}" = "" ] |
---|
294 | then |
---|
295 | echo "${command} : eee : \${PROJECT_LOG} not defined" |
---|
296 | exit 1 |
---|
297 | fi |
---|
298 | # |
---|
299 | # check for ${PROJECT_LOG} existence |
---|
300 | if [ ! -d ${PROJECT_LOG} ] |
---|
301 | then |
---|
302 | echo "${command} : eee : ${PROJECT_LOG} not found" |
---|
303 | exit 1 |
---|
304 | fi |
---|
305 | # |
---|
306 | # check for permission access on PROJECT_LOG |
---|
307 | if [ ! -x ${PROJECT_LOG} ] |
---|
308 | then |
---|
309 | echo "${command} : eee : ${PROJECT_LOG} not reachable" |
---|
310 | exit 1 |
---|
311 | fi |
---|
312 | # |
---|
313 | # check for write permission on PROJECT_LOG |
---|
314 | if [ ! -w ${PROJECT_LOG} ] |
---|
315 | then |
---|
316 | echo "${command} : eee : ${PROJECT_LOG} not writable" |
---|
317 | exit 1 |
---|
318 | fi |
---|
319 | # |
---|
320 | log=${PROJECT_LOG}/$(basename ${0} .sh).log.${log_date} |
---|
321 | echo "[Context]" 1>> ${log} |
---|
322 | echo "command=$(basename ${0})" 1>>${log} |
---|
323 | echo "hostname=${hostname}" 1>> ${log} |
---|
324 | echo "runtime=${log_date}" 1>> ${log} |
---|
325 | echo "log=${log}" 1>> ${log} |
---|
326 | unset log_date |
---|
327 | # |
---|
328 | echo "" 1>> ${log} |
---|
329 | echo "[Parameters]" 1>> ${log} |
---|
330 | echo "N.A." 1>> ${log} |
---|
331 | echo "" 1>> ${log} |
---|
332 | # |
---|
333 | filein=${PROJECT_OD}/erai_lwr_19890102_20091231_oafluxgrid.nc |
---|
334 | if [ ! -f ${filein} ] |
---|
335 | then |
---|
336 | echo " eee : ${filein} not found" 1>> ${log} |
---|
337 | exit 1 |
---|
338 | fi |
---|
339 | fileout=${PROJECT_OD}/erai_lwr_19890101_20091231_oafluxgrid.nc |
---|
340 | if [ -f ${fileout} ] |
---|
341 | then |
---|
342 | echo "eee : ${fileout} already exists" 1>>${log} |
---|
343 | exit 1 |
---|
344 | fi |
---|
345 | # |
---|
346 | rm -f ${PROJECT_OD}/erai_lwr_step19890101.nc 2> /dev/null |
---|
347 | rm -f ${PROJECT_OD}/erai_lwr_step19890102.nc 2> /dev/null |
---|
348 | # |
---|
349 | # extraction of the first time step 19890102 |
---|
350 | ncks -h -d time,0,0 ${filein} ${PROJECT_OD}/erai_lwr_step19890102.nc >> ${log} 2>&1 |
---|
351 | status=${?} |
---|
352 | if [ ${status} -ne 0 ] |
---|
353 | then |
---|
354 | echo "eee : pb with ncks" >> ${log} 2>&1 |
---|
355 | ncdump -h ${filein} >> ${log} 2>&1 |
---|
356 | exit 1 |
---|
357 | fi |
---|
358 | unset status |
---|
359 | # |
---|
360 | # ++ check if tt[0] is really 19890102 |
---|
361 | # |
---|
362 | # subtract 1 to tt to simulate 19890101 |
---|
363 | ncap2 -h -s "tt=tt-1" \ |
---|
364 | ${PROJECT_OD}/erai_lwr_step19890102.nc \ |
---|
365 | ${PROJECT_OD}/erai_lwr_step19890101.nc |
---|
366 | status=${?} |
---|
367 | if [ ${status} -ne 0 ] |
---|
368 | then |
---|
369 | echo "eee : pb with ncap2" >> ${log} 2>&1 |
---|
370 | ncdump -h ${PROJECT_OD}/erai_lwr_step19890102.nc >> ${log} 2>&1 |
---|
371 | exit 1 |
---|
372 | fi |
---|
373 | unset status |
---|
374 | ls -l ${PROJECT_OD}/erai_lwr_step19890102.nc >> ${log} 2>&1 |
---|
375 | ls -l ${PROJECT_OD}/erai_lwr_step19890101.nc >> ${log} 2>&1 |
---|
376 | # |
---|
377 | # ++ check if tt[0] is really 19890101 |
---|
378 | # |
---|
379 | rm ${fileout}_bad_timerange 2> /dev/null |
---|
380 | ncrcat -h \ |
---|
381 | ${PROJECT_OD}/erai_lwr_step19890101.nc \ |
---|
382 | ${filein} \ |
---|
383 | ${fileout}_bad_timerange >> ${log} 2>&1 |
---|
384 | status=${?} |
---|
385 | if [ ${status} -ne 0 ] |
---|
386 | then |
---|
387 | echo "eee : pb with ncrcat" >> ${log} 2>&1 |
---|
388 | ncdump -h ${PROJECT_OD}/erai_lwr_step19890101.nc >> ${log} 2>&1 |
---|
389 | ncdump -h ${filein} >> ${log} 2>&1 |
---|
390 | exit 1 |
---|
391 | fi |
---|
392 | unset status |
---|
393 | # |
---|
394 | ncatted -h -a timerange,global,o,c,"19890101 - 20091231" \ |
---|
395 | ${fileout}_bad_timerange \ |
---|
396 | ${fileout} >> ${log} 2>&1 |
---|
397 | status=${?} |
---|
398 | if [ ${status} -ne 0 ] |
---|
399 | then |
---|
400 | echo "eee : pb with ncatted" >> ${log} 2>&1 |
---|
401 | ncdump -h ${fileout}_bad_timerange >> ${log} 2>&1 |
---|
402 | exit 1 |
---|
403 | fi |
---|
404 | unset status |
---|
405 | # |
---|
406 | if [ ${debug} -eq 1 ] |
---|
407 | then |
---|
408 | ncdump -v tt ${fileout} >> ${log} 2>&1 |
---|
409 | fi |
---|
410 | # |
---|
411 | # cleaning |
---|
412 | #++rm -f ${PROJECT_OD}/erai_lwr_step19890101.nc 2> /dev/null |
---|
413 | #++rm -f ${PROJECT_OD}/erai_lwr_step19890102.nc 2> /dev/null |
---|
414 | #++rm -f ${PROJECT_OD}/${fileout}_bad_timerange 2> /dev/null |
---|
415 | # |
---|
416 | unset fileout |
---|
417 | unset filein |
---|
418 | #++ set |
---|
419 | # end |
---|
420 | exit 0 |
---|