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