source: trunk/src/olr_split.sh @ 11

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

smal typo for doc

  • Property svn:executable set to *
  • Property svn:keywords set to Id
File size: 6.4 KB
Line 
1#!/bin/sh
2#+
3#
4# NAME
5# ====
6#
7# olr_split.sh - split OLR mean daily file
8#
9# SYNOPSYS
10# ========
11#
12# ``olr_split.sh [-g] [-r] [-f] [-y year]``
13#
14# DESCRIPTION
15# ===========
16#
17# Split OLR mean daily file by year and reduce geographical domain
18# to [60 ° W, 50 ° E] [30 ° S, 45 ° N].
19#
20# If ``-g`` option is set, there will be no geographical domain reduction.
21#
22# If ``-f`` option is set, previously output files will be overwritten.
23#
24# If ``-r`` option is set, output files will be concatenated in one (might
25# be usefull, combinated with ``-g`` option to check).
26#
27# If ``-y`` option is set with a year, only this year will be splitted.
28#
29# EXAMPLES
30# ========
31#
32# To split ${VARAMMA_ID}/olr.day.mean.nc between [2000,2007] and between
33# [60 ° W, 50 ° E] [30 ° S, 45 ° N]
34# ::
35#
36#  $ olr_split.sh
37#
38# To split ${VARAMMA_ID}/olr.day.mean.nc in 2006 between
39# [60 ° W, 50 ° E] [30 ° S, 45 ° N]
40# ::
41#
42#  $ olr_split.sh -y 2006
43#
44# To split globaly and build a recomposed file
45# ::
46#
47#  $ olr_split.sh -g -r
48#
49# one might compare original and rebuild file
50# ::
51#
52#  $ cdo diffv ${VARAMMA_ID}/olr.day.mean.nc ${VARAMMA_OD}/olr.day.mean_rebuild.nc
53#
54# diff should only show differences in global attributes
55#
56# CAUTIONS
57# ========
58#
59# Does'nt work on zeus because of UDUnits library problems
60#
61# ++++ GROS DOUTE SUR LES LONGITUDES DANS CES FICHIERS +++++++
62#
63# FILES
64# =====
65#
66# original location
67# ~~~~~~~~~~~~~~~~~
68#
69# /usr/home/fplod/incas/varamma/varamma_ws/olr_split.sh sur aedon.locean-ipsl.upmc.fr
70#
71#
72# TODO
73# ====
74#
75# ++ unset
76#
77# ++ option debug/verbose
78#
79# ++ gestion log
80#
81# ++ vérification accès filein
82#
83# ++ found none interactive actionof ncks if output file exists
84#
85# EVOLUTIONS
86# ==========
87#
88#
89# $Id$
90#
91# - fplod 2008-08-14T14:53:04Z aedon.locean-ipsl.upmc.fr (Darwin)
92#
93#   * modify West longitude conversion according to
94#     http://en.wikipedia.org/wiki/Longitude
95# - fplod 2008-08-13T14:26:41Z aedon.locean-ipsl.upmc.fr (Darwin)
96#
97#   * add -f option
98#   * add -y option
99#   * add 180 degre to longitude centered on meridien 0 (<0 =W , >0=E)
100#
101# - fplod 2008-07-24T15:02:12Z aedon.locean-ipsl.upmc.fr (Darwin)
102#
103#   * creation
104#
105#-
106system=$(uname)
107case "${system}" in
108AIX|IRIX64)
109 echo " www : no specific posix checking"
110;;
111*)
112 set -o posix
113;;
114esac
115#
116case $(hostname) in
117zeus.locean-ipsl.upmc.fr|dedale.locean-ipsl.upmc.fr)
118 echo "eee : pb on UDUnits library on zeus"
119 echo "eee : contact system team"
120 exit 1
121;;
122esac
123#
124command=$(basename ${0})
125log_date=$(date -u +"%Y-%m-%dT%H:%M:%SZ")
126#
127usage=" Usage : ${command} [-r] [-g] [-f]"
128#
129# ++ test si ncks available
130#
131# default
132force=0
133latmin=-30
134latmax=45
135lonmin=$((-60 + 360))
136lonmax=50
137global=0
138yearmin=2000
139yearmax=2007
140rebuild=0
141#
142minargcount=0
143if [ ${#} -lt ${minargcount} ]
144then
145 echo "eee : not enought arguments"
146 echo "${usage}"
147 exit 1
148fi
149#
150while [ ! -z "${1}" ] # ++ pb bash
151do
152 case ${1} in
153 -g)
154    global=1
155# ++ comment connaitre la 1er année si -g.
156# dans le README on nous dit que ça commence en 1974 mais il faudrait automatiser
157# ++ idem pour la dernière année
158# pour l'instant forçage
159  yearmin=1974
160  yearmax=2008
161  echo "www : forçage yearmin yearmax : ${yearmin} ${yearmax}"
162 ;;
163 -f)
164    force=1
165 ;;
166 -r)
167    rebuild=1
168 ;;
169 -y)
170    yearmin=${2}
171    yearmax=${yearmin}
172    shift
173 ;;
174 -h)
175    echo "${usage}"
176    exit 0
177 ;;
178 *) # other choice
179    echo "${usage}"
180    exit 1
181 ;;
182 esac
183 shift # next flag
184done
185#
186set -u
187#
188# ++ check validuty of yearmin and yearmax
189#
190# check for ${VARAMMA_LOG} definition
191if [ "${VARAMMA_LOG}" = "" ]
192then
193 echo " eee : \${VARAMMA_LOG} not defined"
194 exit 1
195fi
196#
197# check for ${VARAMMA_LOG} existence
198if [ ! -d ${VARAMMA_LOG} ]
199then
200 echo " eee : ${VARAMMA_LOG} not found"
201 exit 1
202fi
203#
204# check for permission access on VARAMMA_LOG
205if [ ! -x ${VARAMMA_LOG} ]
206then
207 echo " eee : ${VARAMMA_LOG} not reachable"
208 exit 1
209fi
210#
211# check for write permission on VARAMMA_LOG
212if [ ! -w ${VARAMMA_LOG} ]
213then
214 echo " eee : ${VARAMMA_LOG} not writable"
215 exit 1
216fi
217#
218log=${VARAMMA_LOG}/$(basename ${0} .sh).log.${log_date}
219#++echo "command = $(basename ${0})" 1>>${log}
220#++echo "runtime = ${log_date}" 1>> ${log}
221#
222# ++ VARAMMA_ID
223# ++ VARAMMA_OD
224#
225# check for input file
226filein=${VARAMMA_ID}/olr.day.mean.nc
227if [ ! -r ${VARAMMA_ID}/olr.day.mean.nc ]
228then
229   echo "eee : ${filein} not accessible"
230   exit 1
231fi
232#
233# build date string for ncks command
234list_split=""
235iyear=${yearmin}
236while [ ${iyear} -le ${yearmax} ]
237do
238 timemin=$(echo ${iyear} | awk ' {printf "%4.4d-01-01 00:00:00.0",$1}')
239 timemax=$(echo ${iyear} | awk ' {printf "%4.4d-12-31 00:00:00.0",$1}') #++23:59:59
240 echo "iii : extraction ${iyear} from ${filein}" # ++ voir seulement si debug demandé
241 if [ ${global} -eq 0 ]
242 then
243  fileout=${VARAMMA_OD}/$(basename ${filein} .nc)_${iyear}_ng.nc
244 else
245  fileout=${VARAMMA_OD}/$(basename ${filein} .nc)_${iyear}.nc
246 fi
247 if [ -f ${fileout} ]
248 then
249  if [ ${force} -eq 0 ]
250  then
251   echo "eee : ${fileout} already exists"
252   exit 1
253  else
254   # I remove the file because I don't know how to tell ncks to ask interactivily if I want to append, overwrite etc...
255   rm -f ${fileout}
256  fi
257 fi
258 if [ ${global} -eq 0 ]
259 then
260    # build float representation of lat and long limit (for hyperslab)
261    clatmin=$(echo ${latmin} | awk ' {printf "%+3.1f",$1}')
262    clatmax=$(echo ${latmax} | awk ' {printf "%+3.1f",$1}')
263    clonmin=$(echo ${lonmin} | awk ' {printf "%+4.1f",$1}')
264    clonmax=$(echo ${lonmax} | awk ' {printf "%+4.1f",$1}')
265    ncks \
266    --dimension time,"${timemin}","${timemax}" \
267    --dimension lat,"${clatmin}","${clatmax}" \
268    --dimension lon,"${clonmin}","${clonmax}" \
269    ${filein} ${fileout}
270    status_ncks=${?}
271    if [ ${status_ncks} -ne 0 ]
272    then
273       echo "eee : pb with ncks ${filein}"
274       exit 1
275    else
276       list_split="${list_split} ${fileout}"
277    fi
278 else
279    ncks \
280    --dimension time,"${timemin}","${timemax}" \
281    ${filein} ${fileout}
282    status_ncks=${?}
283    if [ ${status_ncks} -ne 0 ]
284    then
285       echo "eee : pb with ncks ${filein}"
286       exit 1
287    else
288       list_split="${list_split} ${fileout}"
289    fi
290 fi
291 iyear=$(( ${iyear} + 1 ))
292done
293#
294echo "iii : list of splitted files : ${list_split}"
295#
296if [ ${rebuild} -eq 1 ]
297then
298# if rebuild is asked, concatenation of all the splitted files
299   filetot=${VARAMMA_OD}/$(basename ${filein} .nc)_rebuild.nc
300   rm -f  ${filetot} 2> /dev/null
301   ncrcat ${list_split} ${filetot}
302   status_ncrcat=${?}
303   if [ ${status_ncrcat} -ne 0 ]
304   then
305      echo "eee : pb with ncrcat"
306      exit 1
307   else
308      echo "iii : rebuild result in ${filetot}"
309   fi
310fi
311#
312# end
313exit 0
Note: See TracBrowser for help on using the repository browser.