source: trunk/src/add_19890101.sh

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

fix thanks to coding rules; typo

  • Property svn:eol-style set to native
  • Property svn:executable set to *
  • Property svn:keywords set to Id URL
File size: 9.4 KB
Line 
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#-
197system=$(uname)
198case "${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    ;;
214esac
215unset system
216#
217LANG=POSIX
218#
219set -u
220#
221command=$(basename ${0})
222log_date=$(date -u +"%Y%m%dT%H%M%SZ")
223#
224usage=" Usage : ${command} [--debug]"
225#
226hostname=$(hostname)
227#
228# default
229debug=0
230#
231minargcount=0
232if [ ${#} -lt ${minargcount} ]
233then
234    echo "${command} : eee : not enought arguments"
235    echo "${usage}"
236    exit 1
237fi
238#
239while [ ${#} -gt 0 ]
240do
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
254done
255#
256# check parameters
257# N.A.
258#
259tool=ncrcat
260type ${tool} 1> /dev/null 2>&1
261status=${?}
262if [ ${status} -ne 0 ]
263then
264    echo "${command} : eee : tool ${tool} not found"
265    exit 1
266fi
267unset status
268unset tool
269#
270tool=ncks
271type ${tool} 1> /dev/null 2>&1
272status=${?}
273if [ ${status} -ne 0 ]
274then
275    echo "${command} : eee : tool ${tool} not found"
276    exit 1
277fi
278unset status
279unset tool
280#
281tool=ncatted
282type ${tool} 1> /dev/null 2>&1
283status=${?}
284if [ ${status} -ne 0 ]
285then
286    echo "${command} : eee : tool ${tool} not found"
287    exit 1
288fi
289unset status
290unset tool
291#
292# check for ${PROJECT_LOG} definition
293if [ "${PROJECT_LOG}" = "" ]
294then
295    echo "${command} : eee : \${PROJECT_LOG} not defined"
296    exit 1
297fi
298#
299# check for ${PROJECT_LOG} existence
300if [ ! -d ${PROJECT_LOG} ]
301then
302    echo "${command} : eee : ${PROJECT_LOG} not found"
303    exit 1
304fi
305#
306# check for permission access on PROJECT_LOG
307if [ ! -x ${PROJECT_LOG} ]
308then
309    echo "${command} : eee : ${PROJECT_LOG} not reachable"
310    exit 1
311fi
312#
313# check for write permission on PROJECT_LOG
314if [ ! -w ${PROJECT_LOG} ]
315then
316    echo "${command} : eee : ${PROJECT_LOG} not writable"
317    exit 1
318fi
319#
320log=${PROJECT_LOG}/$(basename ${0} .sh).log.${log_date}
321echo "[Context]" 1>> ${log}
322echo "command=$(basename ${0})" 1>>${log}
323echo "hostname=${hostname}" 1>> ${log}
324echo "runtime=${log_date}" 1>> ${log}
325echo "log=${log}" 1>> ${log}
326unset log_date
327#
328echo "" 1>> ${log}
329echo "[Parameters]" 1>> ${log}
330echo "N.A." 1>> ${log}
331echo "" 1>> ${log}
332#
333filein=${PROJECT_OD}/erai_lwr_19890102_20091231_oafluxgrid.nc
334if [ ! -f ${filein} ]
335then
336    echo " eee : ${filein} not found" 1>> ${log}
337    exit 1
338fi
339fileout=${PROJECT_OD}/erai_lwr_19890101_20091231_oafluxgrid.nc
340if [ -f ${fileout} ]
341then
342    echo "eee : ${fileout} already exists" 1>>${log}
343    exit 1
344fi
345#
346rm -f ${PROJECT_OD}/erai_lwr_step19890101.nc 2> /dev/null
347rm -f ${PROJECT_OD}/erai_lwr_step19890102.nc 2> /dev/null
348#
349# extraction of the first time step 19890102
350ncks -h -d time,0,0 ${filein} ${PROJECT_OD}/erai_lwr_step19890102.nc >> ${log} 2>&1
351status=${?}
352if [ ${status} -ne 0 ]
353then
354    echo "eee : pb with ncks" >> ${log} 2>&1
355    ncdump -h ${filein} >> ${log} 2>&1
356    exit 1
357fi
358unset status
359#
360# ++ check if tt[0] is really 19890102
361#
362# subtract 1 to tt to simulate 19890101
363ncap2 -h -s "tt=tt-1" \
364${PROJECT_OD}/erai_lwr_step19890102.nc \
365${PROJECT_OD}/erai_lwr_step19890101.nc
366status=${?}
367if [ ${status} -ne 0 ]
368then
369    echo "eee : pb with ncap2" >> ${log} 2>&1
370    ncdump -h ${PROJECT_OD}/erai_lwr_step19890102.nc >> ${log} 2>&1
371    exit 1
372fi
373unset status
374ls -l ${PROJECT_OD}/erai_lwr_step19890102.nc >> ${log} 2>&1
375ls -l ${PROJECT_OD}/erai_lwr_step19890101.nc >> ${log} 2>&1
376#
377# ++ check if tt[0] is really 19890101
378#
379rm ${fileout}_bad_timerange 2> /dev/null
380ncrcat -h \
381${PROJECT_OD}/erai_lwr_step19890101.nc \
382${filein} \
383${fileout}_bad_timerange >> ${log} 2>&1
384status=${?}
385if [ ${status} -ne 0 ]
386then
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
391fi
392unset status
393#
394ncatted -h -a timerange,global,o,c,"19890101 - 20091231" \
395${fileout}_bad_timerange \
396${fileout} >> ${log} 2>&1
397status=${?}
398if [ ${status} -ne 0 ]
399then
400    echo "eee : pb with ncatted" >> ${log} 2>&1
401    ncdump -h ${fileout}_bad_timerange >> ${log} 2>&1
402    exit 1
403fi
404unset status
405#
406if [ ${debug} -eq 1 ]
407then
408    ncdump -v tt ${fileout} >> ${log} 2>&1
409fi
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#
416unset fileout
417unset filein
418#++ set
419# end
420exit 0
Note: See TracBrowser for help on using the repository browser.