source: trunk/src/concat_eraiy.sh @ 202

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