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