source: trunk/src/correct_terminology.sh @ 202

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

end of 20130725 update data

  • Property svn:eol-style set to native
  • Property svn:executable set to *
  • Property svn:keywords set to Id URL
File size: 5.4 KB
Line 
1#! /bin/sh
2#
3#+
4#
5# .. program:: correct_terminology.sh
6#
7# .. _correct_terminology.sh:
8#
9# =======================
10# correct_terminology.sh
11# =======================
12#
13# SYNOPSIS
14# ========
15#
16# ::
17#
18#  $ correct_terminology.sh [--debug] -good goodend -bad badend -d directory
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# .. option:: -good goodend
28#
29#    good end part of the name
30#
31# .. option:: -bad badend
32#
33#    bad end part of the name
34#
35# .. option:: -d <dirin>
36#
37#    base location of the dataset to be changed
38#
39# Modify filenames in the dataset based under dirin parameter
40#
41# Log file is written on :file:`${PROJECT_LOG}/correct_terminology.sh.log.{YYYYMMDDTHHMMSSZ}`
42#
43#     .. graphviz::
44#
45#        digraph correct_terminology {
46#
47#           correct_terminology [shape=box,
48#           fontname=Courier,
49#           color=blue,
50#           URL="http://forge.ipsl.jussieu.fr/tropflux/browser/trunk/src/correct_terminology.sh",
51#           label="${PROJECT}/src/correct_terminology.sh"];
52#
53#           {filein} -> {correct_terminology} -> {fileout}
54#
55#       }
56#
57# EXAMPLES
58# ========
59#
60# To modify files under /usr/lodyc/incas/fplod/tropflux_d/to_be_published/ because files are not named
61# :file:`var_tropflux_1d_${yyyy}_{yyyy}.nc` but :file:`var_tropflux_1d_{yyyy}_{month}{yyyy}.nc`::
62#
63#  $ correct_terminology.sh -d /usr/lodyc/incas/fplod/tropflux_d/to_be_published/ -good "1979_2013" -bad "1979_march2013"
64#
65# And look at log file with ::
66#
67#  $ tlogd.sh correct_terminology
68#
69# SEE ALSO
70# ========
71#
72# :ref:`updatedata`
73#
74# :ref:`project_profile.sh`
75#
76# TODO
77# ====
78#
79# coding rules
80#
81# overwrite : may be an other option to avoid scratch
82#
83# debug not used
84#
85# build file name according to time in the file instead of parameter
86#
87# EVOLUTIONS
88# ==========
89#
90# $Id$
91#
92# $URL$
93#
94# - fplod 20130726T112836Z cratos.locean-ipsl.upmc.fr (Linux)
95#
96#   * creation
97#
98#-
99system=$(uname)
100case "${system}" in
101   AIX|IRIX64)
102      echo "www : no specific posix checking"
103      date_cmd=date
104   ;;
105   Darwin)
106      set -o posix
107      date_cmd=gdate
108   ;;
109   Linux)
110      set -o posix
111      date_cmd=date
112   ;;
113   *)
114     set -o posix
115   ;;
116esac
117unset system
118#
119LANG=POSIX
120#
121set -u
122#
123command=$(basename ${0})
124log_date=$(date -u +"%Y%m%dT%H%M%SZ")
125#
126usage=" Usage : ${command} [--debug] -d dirin -good yyyymmdd_yyyymmdd -bad anything"
127#
128hostname=$(hostname)
129#
130# default
131debug=0
132#
133minargcount=0
134if [ ${#} -lt ${minargcount} ]
135then
136   echo "${command} : eee : not enought arguments"
137   echo "${usage}"
138   exit 1
139fi
140#
141while [ ${#} -gt 0 ]
142do
143   case ${1} in
144      -good)
145         goodend=${2}
146         shift
147      ;;
148      -bad)
149         badend=${2}
150         shift
151      ;;
152      -d)
153         dirin=${2}
154         shift
155      ;;
156      --debug)
157         debug=1
158      ;;
159      *)
160        # anything else
161        echo "${command} : eee : unknown option ${1}"
162        echo "${command} : eee : ${usage}"
163        exit 1
164      ;;
165   esac
166   # next flag
167   shift
168done
169#
170# check parameters
171if [ ! -d ${dirin} ]
172then
173   echo " eee : ${dirin} not found"
174   exit 1
175fi
176#
177# check for permission on dirin
178if [ ! -x ${dirin} ]
179then
180   echo " eee : ${dirin} not reachable"
181   exit 1
182fi
183#++ check good validity
184#
185# check for ${PROJECT_LOG} definition
186if [ "${PROJECT_LOG}" = "" ]
187then
188   echo "${command} : ${LINENO} : eee : \${PROJECT_LOG} not defined"
189   exit 1
190fi
191#
192# check for ${PROJECT_LOG} existence
193if [ ! -d ${PROJECT_LOG} ]
194then
195   echo "${command} : eee : ${PROJECT_LOG} not found"
196   exit 1
197fi
198#
199# check for permission access on PROJECT_LOG
200if [ ! -x ${PROJECT_LOG} ]
201then
202   echo "${command} : eee : ${PROJECT_LOG} not reachable"
203   exit 1
204fi
205#
206# check for write permission on PROJECT_LOG
207if [ ! -w ${PROJECT_LOG} ]
208then
209   echo "${command} : eee : ${PROJECT_LOG} not writable"
210   exit 1
211fi
212#
213log=${PROJECT_LOG}/$(basename ${0} .sh).log.${log_date}
214echo "[Context]" 1>> ${log}
215echo "command=$(basename ${0})" 1>>${log}
216echo "hostname=${hostname}" 1>> ${log}
217echo "runtime=${log_date}" 1>> ${log}
218echo "log=${log}" 1>> ${log}
219unset log_date
220#
221echo "" 1>> ${log}
222echo "[Parameters]" 1>> ${log}
223echo "dirin=${dirin}" 1>> ${log}
224echo "good=${goodend}" 1>> ${log}
225echo "bad=${badend}" 1>> ${log}
226echo "" 1>> ${log}
227#
228# build list files
229varlist="lhf lwr netflux q2m shf sst swr t2m tau taux tauy ws"
230period_list="daily monthly"
231list_filein=""
232for var in $varlist
233do
234     for period in ${period_list}
235     do
236         if [ "${period}" == "daily" ]
237         then
238            suffix=1d
239         else
240            suffix=1m
241         fi
242         filein=${dirin}/${period}/${var}_tropflux_${suffix}_${badend}.nc
243         if [ ! -f ${filein} ]
244         then
245             echo " eee : ${filein} not found" 1>> ${log}
246             exit 1
247         else
248             list_filein=${list_filein}" ${filein}"
249         fi
250     done
251     unset period
252done
253unset period_list
254unset var
255unset varlist
256#
257# rename all files
258for filein in ${list_filein}
259do
260    echo "iii : rename ${filein}" >> ${log} 2>&1
261    bfileout=$(basename ${filein} ${badend}.nc)"${goodend}.nc"
262    fileout=$(dirname ${filein})/${bfileout}
263    unset bfileout
264    mv ${filein} ${fileout} >> ${log} 2>&1
265    status=${?}
266    if [ ${status} -ne 0 ]
267    then
268        echo "eee : pb with mv" >> ${log} 2>&1
269        ncdump -h ${filein} >> ${log} 2>&1
270        exit 1
271    fi
272    unset status
273    unset fileout
274done
275unset filein
276#
277# cleanning
278#++
279#++ set
280# end
281exit 0
Note: See TracBrowser for help on using the repository browser.