source: trunk/src/concat_eraiy.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:: concat_eraiy.sh
6#
7# .. _concat_eraiy.sh:
8#
9# ===============
10# concat_eraiy.sh
11# ===============
12#
13# SYNOPSIS
14# ========
15#
16# .. code-block:: bash
17#
18#    concat_eraiy.sh [--debug] -b yyyymmdd -e yyyymmdd
19#
20# DESCRIPTION
21# ===========
22#
23# .. option:: --debug
24#
25#    If this option is set, :samp:`ncdump -v time` and :samp:`cdo showdate`
26#    will be added to log file
27#
28# .. option:: -b beginning date <yyyymmdd>
29# .. option:: -e end date <yyyymmdd>
30#
31# Concatenate yearly ERA-I files located
32# in :file:`/net/adonis/usr/adonis/varclim/tropflux_v1/input`
33# in ${PROJECT_ID}
34#
35# Log file is written on
36# :file:`${PROJECT_LOG}/concat_eraiy.log.{YYYYMMDDTHHMMSSZ}`
37#
38#     .. graphviz::
39#
40#        digraph concat_eraiy {
41#
42#           filein_d2m [shape=ellipse,
43#           fontname=Courier,
44#           label="cratos:/net/adonis/usr/adonis/varclim/tropflux_v1/input/erai_d2m_yyyy.nc"];
45#           filein_lwr [shape=ellipse,
46#           fontname=Courier,
47#           label="cratos:/net/adonis/usr/adonis/varclim/tropflux_v1/input/erai_lwr_yyyy.nc"];
48#           filein_msl [shape=ellipse,
49#           fontname=Courier,
50#           label="cratos:/net/adonis/usr/adonis/varclim/tropflux_v1/input/erai_msl_yyyy.nc"];
51#           filein_sst [shape=ellipse,
52#           fontname=Courier,
53#           label="cratos:/net/adonis/usr/adonis/varclim/tropflux_v1/input/erai_sst_yyyy.nc"];
54#           filein_t2m [shape=ellipse,
55#           fontname=Courier,
56#           label="cratos:/net/adonis/usr/adonis/varclim/tropflux_v1/input/erai_t2m_yyyy.nc"];
57#           filein_u10 [shape=ellipse,
58#           fontname=Courier,
59#           label="cratos:/net/adonis/usr/adonis/varclim/tropflux_v1/input/erai_u10_yyyy.nc"];
60#           filein_v10 [shape=ellipse,
61#           fontname=Courier,
62#           label="cratos:/net/adonis/usr/adonis/varclim/tropflux_v1/input/erai_v10_yyyy.nc"];
63#
64#           fileout_d2m [shape=ellipse,
65#           fontname=Courier,
66#           label="${PROJECT_ID}/erai_d2m_yyyyb_yyyye.nc"];
67#           fileout_lwr [shape=ellipse,
68#           fontname=Courier,
69#           label="${PROJECT_ID}/erai_lwr_yyyyb_yyyye.nc"];
70#           fileout_msl [shape=ellipse,
71#           fontname=Courier,
72#           label="${PROJECT_ID}/erai_msl_yyyyb_yyyye.nc"];
73#           fileout_sst [shape=ellipse,
74#           fontname=Courier,
75#           label="${PROJECT_ID}/erai_sst_yyyyb_yyyye.nc"];
76#           fileout_t2m [shape=ellipse,
77#           fontname=Courier,
78#           label="${PROJECT_ID}/erai_t2m_yyyyb_yyyye.nc"];
79#           fileout_u10 [shape=ellipse,
80#           fontname=Courier,
81#           label="${PROJECT_ID}/erai_u10_yyyyb_yyyye.nc"];
82#           fileout_v10 [shape=ellipse,
83#           fontname=Courier,
84#           label="${PROJECT_ID}/erai_v10_yyyyb_yyyye.nc"];
85#
86#           concat_eraiy [shape=box,
87#           fontname=Courier,
88#           color=blue,
89#           URL="http://forge.ipsl.jussieu.fr/tropflux/browser/trunk/src/concat_eraiy.sh",
90#           label="${PROJECT}/src/concat_eraiy.sh"];
91#
92#           {filein_d2m filein_lwr filein_msl filein_sst filein_t2m filein_u10 filein_v10} -> {concat_eraiy} -> {fileout_d2m fileout_lwr fileout_sst fileout_t2m fileout_u10 fileout_v10}
93#
94#       }
95#
96# .. caution::
97#
98#    Output files if exist are overwritten.
99#
100# EXAMPLES
101# ========
102#
103# On cratos only if you don't have any ERA-I data,
104# you just have to run this tool :
105#
106# .. code-block:: bash
107#
108#    concat_eraiy.sh -b 19890102 -e 20091231
109#
110# And look at log file with :
111#
112# .. code-block:: bash
113#
114#    tlogd.sh concat_eraiy
115#
116# and of course on files in ${PROJECT_ID}.
117#
118# SEE ALSO
119# ========
120#
121# :ref:`data_in_erai`
122#
123# :ref:`project_profile.sh`
124#
125# Used by :ref:`tropflux.sh`
126#
127# :func:`ncrcat <nco:ncrcat>`
128#
129# :func:`showdate <cdo:showdate>`
130#
131# :func:`interp_erai_dewt`
132# :func:`interp_erai_lwr`
133# :func:`interp_erai_sst`
134# :func:`interp_erai_t2m`
135# :func:`interp_erai_ws`
136#
137# TODO
138# ====
139#
140# pour l'instant à cause de :
141#
142# .. parsed-literal::
143#
144#    has attribute "missing_value" but not "_FillValue"
145#
146# ncrcat renvoie systématiquement un status différent de 0 mais il produit
147# des fichiers
148#
149# donc j'ai pour l'instant court-circuter la sortie en erreur
150# tant que je n'ai pas renommé missing_value ou ajouter _FillValue
151#
152# changement des attributs globaux dans fichiers de sortie
153#
154# catalog
155#
156# improve log
157#
158# handle dd parameter : now from 1 to end of month
159#
160# adjust yyyymmddb_min and yyyymmddb_max
161#
162# trouble with cdo reference (extra %23name in generated url using sphinx1.0.7)
163#
164# coding rules
165#
166# work elsewhere cratos
167#
168# enrich info in log file
169#
170# EVOLUTIONS
171# ==========
172#
173# $Id$
174#
175# $URL$
176#
177# - fplod 20120704T104404Z cratos (Linux)
178#
179#   * creation for new era-i dataset
180#
181#-
182system=$(uname)
183case "${system}" in
184    AIX|IRIX64)
185        echo "www : no specific posix checking"
186        date_cmd=date
187    ;;
188    Darwin)
189        set -o posix
190        date_cmd=gdate
191    ;;
192    Linux)
193        set -o posix
194        date_cmd=date
195    ;;
196    *)
197        set -o posix
198    ;;
199esac
200unset system
201#
202LANG=POSIX
203#
204set -u
205#
206command=$(basename ${0})
207log_date=$(date -u +"%Y%m%dT%H%M%SZ")
208#
209usage=" Usage : ${command} [--debug] -b yyyymmdd -e yyyymmdd"
210#
211hostname=$(hostname)
212#
213yyyymmddb_min=19790101
214yyyymmdde_max=20110930
215#
216# default
217debug=0
218yyyymmddb=19790101
219yyyymmdde=20110930
220#
221minargcount=4
222if [ ${#} -lt ${minargcount} ]
223then
224    echo "${command} : eee : not enough arguments"
225    echo "${usage}"
226    exit 1
227fi
228#
229while [ ${#} -gt 0 ]
230do
231    case ${1} in
232        --debug)
233            debug=1
234        ;;
235        -b)
236            # first date to get
237            yyyymmddb=${2}
238            shift
239        ;;
240        -e)
241            # last date to get
242            yyyymmdde=${2}
243            shift
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#
258${date_cmd} -d "${yyyymmddb}" > /dev/null
259status_date=${?}
260if [ ${status_date} -ne 0 ]
261then
262    echo "${command} : eee : yyyymmddb ${yyyymmddb} argument invalid"
263    exit 1
264fi
265unset status_date
266#
267if [[ "${yyyymmddb}" < "${yyyymmddb_min}" ]]
268then
269    echo "${command} : eee : yyyymmddb ${yyyymmddb} must be equal or greater than ${yyyymmddb_min}"
270    exit 1
271fi
272#
273${date_cmd} -d "${yyyymmdde}" > /dev/null
274status_date=${?}
275if [ ${status_date} -ne 0 ]
276then
277    echo "${command} : eee : yyyymmdde ${yyyymmdde} argument invalid"
278    exit 1
279fi
280unset status_date
281#
282if [[ "${yyyymmdde}" > "${yyyymmdde_max}" ]]
283then
284    echo "${command} : eee : yyyymmdde ${yyyymmdde} must be lower or equal to ${yyyymmdde_max}"
285    exit 1
286fi
287#
288if [[ "${yyyymmdde}" < "${yyyymmddb}" ]]
289then
290    echo "${command} : eee : yyyymmdde ${yyyymmdde} must be equal or greater than yyyymmddb ${yyyymmddb}"
291    exit 1
292fi
293#
294# test if cdo available
295tool=cdo
296type ${tool} 1> /dev/null 2>&1
297status=${?}
298if [ ${status} -ne 0 ]
299then
300    echo "${command} : eee : ${tool} not found"
301    exit 1
302fi
303unset status
304
305# check for ${PROJECT_LOG} definition
306if [ "${PROJECT_LOG}" = "" ]
307then
308    echo "${command} : eee : \${PROJECT_LOG} not defined"
309    exit 1
310fi
311#
312# check for ${PROJECT_LOG} existence
313if [ ! -d ${PROJECT_LOG} ]
314then
315    echo "${command} : eee : ${PROJECT_LOG} not found"
316    exit 1
317fi
318#
319# check for permission access on PROJECT_LOG
320if [ ! -x ${PROJECT_LOG} ]
321then
322    echo "${command} : eee : ${PROJECT_LOG} not reachable"
323    exit 1
324fi
325#
326# check for write permission on PROJECT_LOG
327if [ ! -w ${PROJECT_LOG} ]
328then
329    echo "${command} : eee : ${PROJECT_LOG} not writable"
330    exit 1
331fi
332#
333dirtemp=${PROJECT_LOG}/$(basename ${0} .sh).${log_date}.temp/
334mkdir -p ${dirtemp}
335#
336log=${PROJECT_LOG}/$(basename ${0} .sh).log.${log_date}
337echo "[Context]" 1>> ${log}
338echo "command=$(basename ${0})" 1>>${log}
339echo "hostname=${hostname}" 1>> ${log}
340echo "runtime=${log_date}" 1>> ${log}
341echo "log=${log}" 1>> ${log}
342unset log_date
343#
344echo "" 1>> ${log}
345echo "[Parameters]" 1>> ${log}
346echo "yyyymmddb=${yyyymmddb}" 1>> ${log}
347echo "yyyymmdde=${yyyymmdde}" 1>> ${log}
348echo "" 1>> ${log}
349#
350yyyymin=$(${date_cmd} -d "${yyyymmddb}" +%Y)
351yyyymax=$(${date_cmd} -d "${yyyymmdde}" +%Y)
352dirin=/net/adonis/usr/adonis/varclim/tropflux_v1/input
353# check for dirin existence
354if [ ! -d ${dirin} ]
355then
356    echo "${command} : eee : ${dirin} not found"
357    exit 1
358fi
359#
360# check for permission access on dirin
361if [ ! -x ${dirin} ]
362then
363    echo "${command} : eee : ${dirin} not reachable"
364    exit 1
365fi
366#
367list_var="d2m lwr msl sst t2m u10 v10"
368for var in ${list_var}
369do
370    fileout=${PROJECT_ID}/erai_${var}_${yyyymin}_${yyyymax}.nc
371    if [ ${yyyymin} -eq ${yyyymax} ]
372    then
373        list_filein=${dirin}/erai_${var}_${yyyymin}.nc
374        cp ${list_filein} ${fileout} 1>> ${log} 2>&1
375    else
376        list_filein=$(seq -f "${dirin}/erai_${var}_%g.nc" ${yyyymin} ${yyyymax})
377        # concatenation of files
378        ncrcat -O -o ${fileout} ${list_filein} 1>> ${log} 2>&1
379        status_ncrcat=${?}
380        if [ ${status_ncrcat} -ne 0 ]
381        then
382            echo "${command} : www : pb with ncrcat : ${status_ncrcat} " 2>> ${log}
383            #++exit 1
384        else
385            echo "${command} : iii : ncrcat ok " 1>> ${log}
386            echo "${command} : iii : see ${fileout} " 1>> ${log}
387        fi
388        unset status_ncrcat
389    fi
390    if [ ${debug} -eq 1 ]
391    then
392        ncdump -v time ${fileout} >> ${log} 2>&1
393        cdo showdate ${fileout} >> ${log} 2>&1
394    fi
395    unset list_filein
396    unset fileout
397done
398unset var
399unset list_var
400# end
401exit 0
Note: See TracBrowser for help on using the repository browser.