source: trunk/src/add_19890101.sh @ 199

Last change on this file since 199 was 199, checked in by pinsard, 11 years ago

fix svn properties

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