source: trunk/src/change_creation_date.sh @ 201

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

add some update data tools

  • Property svn:eol-style set to native
  • Property svn:executable set to *
  • Property svn:keywords set to Id URL
File size: 5.2 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# ::
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 if the dataset based under dirin parameter
36#
37# Log file is written on :file:`${PROJECT_LOG}/change_creation_date.sh.log.{YYYYMMDDTHHMMSSZ}`
38#
39#     .. graphviz::
40#
41#        digraph change_creation_date {
42#
43#           change_creation_date [shape=box,
44#           fontname=Courier,
45#           color=blue,
46#           URL="http://forge.ipsl.jussieu.fr/tropflux/browser/trunk/src/change_creation_date.sh",
47#           label="${PROJECT}/src/change_creation_date.sh"];
48#
49#           {filein} -> {change_creation_date} -> {filein}
50#
51#       }
52#
53# EXAMPLES
54# ========
55#
56# To modify files under /usr/lodyc/incas/fplod/tropflux_d/to_be_published/::
57#
58#  $ change_creation_date.sh -d /usr/lodyc/incas/fplod/tropflux_d/to_be_published/ -c 20130725
59#
60# And look at log file with ::
61#
62#  $ tlogd.sh change_creation_date
63#
64# TIPS
65# ====
66#
67# SEE ALSO
68# ========
69#
70# :ref:`updatedata`
71#
72# :ref:`project_profile.sh`
73#
74# :func:`ncatted <nco:ncatted>`
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# terminology march2013 non normative
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 -c yyyymmdd"
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      -c)
145         yyyymmdd=${2}
146         shift
147      ;;
148      -d)
149         dirin=${2}
150         shift
151      ;;
152      --debug)
153         debug=1
154      ;;
155      *)
156        # anything else
157        echo "${command} : eee : unknown option ${1}"
158        echo "${command} : eee : ${usage}"
159        exit 1
160      ;;
161   esac
162   # next flag
163   shift
164done
165#
166# check parameters
167if [ ! -d ${dirin} ]
168then
169   echo " eee : ${dirin} not found"
170   exit 1
171fi
172#
173# check for permission on dirin
174if [ ! -x ${dirin} ]
175then
176   echo " eee : ${dirin} not reachable"
177   exit 1
178fi
179#++ check yyyymmdd validity
180#
181tool=ncatted
182type ${tool} 1> /dev/null 2>&1
183status=${?}
184if [ ${status} -ne 0 ]
185then
186   echo "${command} : ${LINENO} : eee : tool ${tool} not found"
187   exit 1
188fi
189unset status
190unset tool
191#
192# check for ${PROJECT_LOG} definition
193if [ "${PROJECT_LOG}" = "" ]
194then
195   echo "${command} : ${LINENO} : eee : \${PROJECT_LOG} not defined"
196   exit 1
197fi
198#
199# check for ${PROJECT_LOG} existence
200if [ ! -d ${PROJECT_LOG} ]
201then
202   echo "${command} : eee : ${PROJECT_LOG} not found"
203   exit 1
204fi
205#
206# check for permission access on PROJECT_LOG
207if [ ! -x ${PROJECT_LOG} ]
208then
209   echo "${command} : eee : ${PROJECT_LOG} not reachable"
210   exit 1
211fi
212#
213# check for write permission on PROJECT_LOG
214if [ ! -w ${PROJECT_LOG} ]
215then
216   echo "${command} : eee : ${PROJECT_LOG} not writable"
217   exit 1
218fi
219#
220log=${PROJECT_LOG}/$(basename ${0} .sh).log.${log_date}
221echo "[Context]" 1>> ${log}
222echo "command=$(basename ${0})" 1>>${log}
223echo "hostname=${hostname}" 1>> ${log}
224echo "runtime=${log_date}" 1>> ${log}
225echo "log=${log}" 1>> ${log}
226unset log_date
227#
228echo "" 1>> ${log}
229echo "[Parameters]" 1>> ${log}
230echo "dirin=${dirin}" 1>> ${log}
231echo "yyyymmdd=${yyyymmdd}" 1>> ${log}
232echo "" 1>> ${log}
233#
234# build list files
235varlist="lhf lwr netflux q2m shf sst swr t2m tau taux tauy ws"
236period_list="daily monthly"
237list_filein=""
238for var in $varlist
239do
240     for period in ${period_list}
241     do
242         if [ "${period}" == "daily" ]
243         then
244            suffix=1d
245         else
246            suffix=1m
247         fi
248         filein=${dirin}/${period}/${var}_tropflux_${suffix}_1979_march2013.nc
249         if [ ! -f ${filein} ]
250         then
251             echo " eee : ${filein} not found" 1>> ${log}
252             exit 1
253         else
254             list_filein=${list_filein}" ${filein}"
255         fi
256     done
257     unset period
258done
259unset period_list
260unset var
261unset varlist
262#
263# new creation_date attribute
264for filein in ${list_filein}
265do
266    echo "iii : change creation_date in ${filein}" >> ${log} 2>&1
267    ncatted -O -h -a creation_date,global,o,c,"${yyyymmdd}" ${filein} >> ${log} 2>&1
268    status=${?}
269    if [ ${status} -ne 0 ]
270    then
271        echo "eee : pb with ncatted" >> ${log} 2>&1
272        ncdump -h ${filein} >> ${log} 2>&1
273        exit 1
274    fi
275    unset status
276done
277unset filein
278#
279# cleanning
280#++
281#++ set
282# end
283exit 0
Note: See TracBrowser for help on using the repository browser.