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 | #- |
---|
105 | system=$(uname) |
---|
106 | case "${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 | ;; |
---|
122 | esac |
---|
123 | unset system |
---|
124 | # |
---|
125 | LANG=POSIX |
---|
126 | # |
---|
127 | set -u |
---|
128 | # |
---|
129 | command=$(basename ${0}) |
---|
130 | log_date=$(date -u +"%Y%m%dT%H%M%SZ") |
---|
131 | # |
---|
132 | usage=" Usage : ${command} [--debug] -d dirin -c yyyymmdd" |
---|
133 | # |
---|
134 | hostname=$(hostname) |
---|
135 | # |
---|
136 | # default |
---|
137 | debug=0 |
---|
138 | # |
---|
139 | minargcount=0 |
---|
140 | if [ ${#} -lt ${minargcount} ] |
---|
141 | then |
---|
142 | echo "${command} : eee : not enough arguments" |
---|
143 | echo "${usage}" |
---|
144 | exit 1 |
---|
145 | fi |
---|
146 | # |
---|
147 | while [ ${#} -gt 0 ] |
---|
148 | do |
---|
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 |
---|
170 | done |
---|
171 | # |
---|
172 | # check parameters |
---|
173 | if [ ! -d ${dirin} ] |
---|
174 | then |
---|
175 | echo " eee : ${dirin} not found" |
---|
176 | exit 1 |
---|
177 | fi |
---|
178 | # |
---|
179 | # check for permission on dirin |
---|
180 | if [ ! -x ${dirin} ] |
---|
181 | then |
---|
182 | echo " eee : ${dirin} not reachable" |
---|
183 | exit 1 |
---|
184 | fi |
---|
185 | #++ check yyyymmdd validity |
---|
186 | # |
---|
187 | tool=ncatted |
---|
188 | type ${tool} 1> /dev/null 2>&1 |
---|
189 | status=${?} |
---|
190 | if [ ${status} -ne 0 ] |
---|
191 | then |
---|
192 | echo "${command} : ${LINENO} : eee : tool ${tool} not found" |
---|
193 | exit 1 |
---|
194 | fi |
---|
195 | unset status |
---|
196 | unset tool |
---|
197 | # |
---|
198 | # check for ${PROJECT_LOG} definition |
---|
199 | if [ "${PROJECT_LOG}" = "" ] |
---|
200 | then |
---|
201 | echo "${command} : ${LINENO} : eee : \${PROJECT_LOG} not defined" |
---|
202 | exit 1 |
---|
203 | fi |
---|
204 | # |
---|
205 | # check for ${PROJECT_LOG} existence |
---|
206 | if [ ! -d ${PROJECT_LOG} ] |
---|
207 | then |
---|
208 | echo "${command} : eee : ${PROJECT_LOG} not found" |
---|
209 | exit 1 |
---|
210 | fi |
---|
211 | # |
---|
212 | # check for permission access on PROJECT_LOG |
---|
213 | if [ ! -x ${PROJECT_LOG} ] |
---|
214 | then |
---|
215 | echo "${command} : eee : ${PROJECT_LOG} not reachable" |
---|
216 | exit 1 |
---|
217 | fi |
---|
218 | # |
---|
219 | # check for write permission on PROJECT_LOG |
---|
220 | if [ ! -w ${PROJECT_LOG} ] |
---|
221 | then |
---|
222 | echo "${command} : eee : ${PROJECT_LOG} not writable" |
---|
223 | exit 1 |
---|
224 | fi |
---|
225 | # |
---|
226 | log=${PROJECT_LOG}/$(basename ${0} .sh).log.${log_date} |
---|
227 | echo "[Context]" 1>> ${log} |
---|
228 | echo "command=$(basename ${0})" 1>>${log} |
---|
229 | echo "hostname=${hostname}" 1>> ${log} |
---|
230 | echo "runtime=${log_date}" 1>> ${log} |
---|
231 | echo "log=${log}" 1>> ${log} |
---|
232 | unset log_date |
---|
233 | # |
---|
234 | echo "" 1>> ${log} |
---|
235 | echo "[Parameters]" 1>> ${log} |
---|
236 | echo "dirin=${dirin}" 1>> ${log} |
---|
237 | echo "yyyymmdd=${yyyymmdd}" 1>> ${log} |
---|
238 | echo "" 1>> ${log} |
---|
239 | # |
---|
240 | # build list files |
---|
241 | varlist="lhf lwr netflux q2m shf sst swr t2m tau taux tauy ws" |
---|
242 | period_list="daily monthly" |
---|
243 | list_filein="" |
---|
244 | for var in ${varlist} |
---|
245 | do |
---|
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 |
---|
264 | done |
---|
265 | unset period_list |
---|
266 | unset var |
---|
267 | unset varlist |
---|
268 | # |
---|
269 | # new creation_date attribute |
---|
270 | for filein in ${list_filein} |
---|
271 | do |
---|
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 |
---|
282 | done |
---|
283 | unset filein |
---|
284 | # |
---|
285 | # cleaning |
---|
286 | #++ |
---|
287 | #++ set |
---|
288 | # end |
---|
289 | exit 0 |
---|