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