[88] | 1 | #! /bin/sh |
---|
| 2 | # |
---|
| 3 | #+ |
---|
| 4 | # |
---|
[202] | 5 | # .. program:: correct_terminology.sh |
---|
[88] | 6 | # |
---|
[202] | 7 | # .. _correct_terminology.sh: |
---|
[88] | 8 | # |
---|
[202] | 9 | # ======================= |
---|
| 10 | # correct_terminology.sh |
---|
| 11 | # ======================= |
---|
[88] | 12 | # |
---|
| 13 | # SYNOPSIS |
---|
| 14 | # ======== |
---|
| 15 | # |
---|
| 16 | # :: |
---|
| 17 | # |
---|
[202] | 18 | # $ correct_terminology.sh [--debug] -good goodend -bad badend -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 | # |
---|
[202] | 27 | # .. option:: -good goodend |
---|
[88] | 28 | # |
---|
[202] | 29 | # good end part of the name |
---|
[88] | 30 | # |
---|
[202] | 31 | # .. option:: -bad badend |
---|
[88] | 32 | # |
---|
[202] | 33 | # bad end part of the name |
---|
[88] | 34 | # |
---|
[202] | 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 :file:`${PROJECT_LOG}/correct_terminology.sh.log.{YYYYMMDDTHHMMSSZ}` |
---|
| 42 | # |
---|
[88] | 43 | # .. graphviz:: |
---|
| 44 | # |
---|
[202] | 45 | # digraph correct_terminology { |
---|
[88] | 46 | # |
---|
[202] | 47 | # correct_terminology [shape=box, |
---|
[88] | 48 | # fontname=Courier, |
---|
| 49 | # color=blue, |
---|
[202] | 50 | # URL="http://forge.ipsl.jussieu.fr/tropflux/browser/trunk/src/correct_terminology.sh", |
---|
| 51 | # label="${PROJECT}/src/correct_terminology.sh"]; |
---|
[88] | 52 | # |
---|
[202] | 53 | # {filein} -> {correct_terminology} -> {fileout} |
---|
[88] | 54 | # |
---|
| 55 | # } |
---|
| 56 | # |
---|
| 57 | # EXAMPLES |
---|
| 58 | # ======== |
---|
| 59 | # |
---|
[202] | 60 | # To modify files under /usr/lodyc/incas/fplod/tropflux_d/to_be_published/ because files are not named |
---|
| 61 | # :file:`var_tropflux_1d_${yyyy}_{yyyy}.nc` but :file:`var_tropflux_1d_{yyyy}_{month}{yyyy}.nc`:: |
---|
[88] | 62 | # |
---|
[202] | 63 | # $ correct_terminology.sh -d /usr/lodyc/incas/fplod/tropflux_d/to_be_published/ -good "1979_2013" -bad "1979_march2013" |
---|
[88] | 64 | # |
---|
| 65 | # And look at log file with :: |
---|
| 66 | # |
---|
[202] | 67 | # $ tlogd.sh correct_terminology |
---|
[88] | 68 | # |
---|
| 69 | # SEE ALSO |
---|
| 70 | # ======== |
---|
| 71 | # |
---|
[202] | 72 | # :ref:`updatedata` |
---|
| 73 | # |
---|
[88] | 74 | # :ref:`project_profile.sh` |
---|
| 75 | # |
---|
| 76 | # TODO |
---|
| 77 | # ==== |
---|
| 78 | # |
---|
| 79 | # coding rules |
---|
| 80 | # |
---|
[202] | 81 | # overwrite : may be an other option to avoid scratch |
---|
[88] | 82 | # |
---|
[202] | 83 | # debug not used |
---|
[88] | 84 | # |
---|
[202] | 85 | # build file name according to time in the file instead of parameter |
---|
[88] | 86 | # |
---|
| 87 | # EVOLUTIONS |
---|
| 88 | # ========== |
---|
| 89 | # |
---|
| 90 | # $Id$ |
---|
| 91 | # |
---|
| 92 | # $URL$ |
---|
| 93 | # |
---|
[202] | 94 | # - fplod 20130726T112836Z cratos.locean-ipsl.upmc.fr (Linux) |
---|
[88] | 95 | # |
---|
[202] | 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 | # |
---|
[202] | 126 | usage=" Usage : ${command} [--debug] -d dirin -good yyyymmdd_yyyymmdd -bad anything" |
---|
[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 |
---|
[202] | 144 | -good) |
---|
| 145 | goodend=${2} |
---|
| 146 | shift |
---|
| 147 | ;; |
---|
| 148 | -bad) |
---|
| 149 | badend=${2} |
---|
| 150 | shift |
---|
| 151 | ;; |
---|
| 152 | -d) |
---|
| 153 | dirin=${2} |
---|
| 154 | shift |
---|
| 155 | ;; |
---|
[88] | 156 | --debug) |
---|
| 157 | debug=1 |
---|
| 158 | ;; |
---|
| 159 | *) |
---|
| 160 | # anything else |
---|
| 161 | echo "${command} : eee : unknown option ${1}" |
---|
| 162 | echo "${command} : eee : ${usage}" |
---|
| 163 | exit 1 |
---|
| 164 | ;; |
---|
| 165 | esac |
---|
| 166 | # next flag |
---|
| 167 | shift |
---|
| 168 | done |
---|
| 169 | # |
---|
| 170 | # check parameters |
---|
[202] | 171 | if [ ! -d ${dirin} ] |
---|
[88] | 172 | then |
---|
[202] | 173 | echo " eee : ${dirin} not found" |
---|
[88] | 174 | exit 1 |
---|
| 175 | fi |
---|
| 176 | # |
---|
[202] | 177 | # check for permission on dirin |
---|
| 178 | if [ ! -x ${dirin} ] |
---|
[88] | 179 | then |
---|
[202] | 180 | echo " eee : ${dirin} not reachable" |
---|
[88] | 181 | exit 1 |
---|
| 182 | fi |
---|
[202] | 183 | #++ check good validity |
---|
[88] | 184 | # |
---|
| 185 | # check for ${PROJECT_LOG} definition |
---|
| 186 | if [ "${PROJECT_LOG}" = "" ] |
---|
| 187 | then |
---|
[202] | 188 | echo "${command} : ${LINENO} : eee : \${PROJECT_LOG} not defined" |
---|
[88] | 189 | exit 1 |
---|
| 190 | fi |
---|
| 191 | # |
---|
| 192 | # check for ${PROJECT_LOG} existence |
---|
| 193 | if [ ! -d ${PROJECT_LOG} ] |
---|
| 194 | then |
---|
| 195 | echo "${command} : eee : ${PROJECT_LOG} not found" |
---|
| 196 | exit 1 |
---|
| 197 | fi |
---|
| 198 | # |
---|
| 199 | # check for permission access on PROJECT_LOG |
---|
| 200 | if [ ! -x ${PROJECT_LOG} ] |
---|
| 201 | then |
---|
| 202 | echo "${command} : eee : ${PROJECT_LOG} not reachable" |
---|
| 203 | exit 1 |
---|
| 204 | fi |
---|
| 205 | # |
---|
| 206 | # check for write permission on PROJECT_LOG |
---|
| 207 | if [ ! -w ${PROJECT_LOG} ] |
---|
| 208 | then |
---|
| 209 | echo "${command} : eee : ${PROJECT_LOG} not writable" |
---|
| 210 | exit 1 |
---|
| 211 | fi |
---|
| 212 | # |
---|
| 213 | log=${PROJECT_LOG}/$(basename ${0} .sh).log.${log_date} |
---|
| 214 | echo "[Context]" 1>> ${log} |
---|
| 215 | echo "command=$(basename ${0})" 1>>${log} |
---|
| 216 | echo "hostname=${hostname}" 1>> ${log} |
---|
| 217 | echo "runtime=${log_date}" 1>> ${log} |
---|
[188] | 218 | echo "log=${log}" 1>> ${log} |
---|
[88] | 219 | unset log_date |
---|
| 220 | # |
---|
| 221 | echo "" 1>> ${log} |
---|
| 222 | echo "[Parameters]" 1>> ${log} |
---|
[202] | 223 | echo "dirin=${dirin}" 1>> ${log} |
---|
| 224 | echo "good=${goodend}" 1>> ${log} |
---|
| 225 | echo "bad=${badend}" 1>> ${log} |
---|
[88] | 226 | echo "" 1>> ${log} |
---|
| 227 | # |
---|
[202] | 228 | # build list files |
---|
| 229 | varlist="lhf lwr netflux q2m shf sst swr t2m tau taux tauy ws" |
---|
| 230 | period_list="daily monthly" |
---|
| 231 | list_filein="" |
---|
| 232 | for var in $varlist |
---|
| 233 | do |
---|
| 234 | for period in ${period_list} |
---|
| 235 | do |
---|
| 236 | if [ "${period}" == "daily" ] |
---|
| 237 | then |
---|
| 238 | suffix=1d |
---|
| 239 | else |
---|
| 240 | suffix=1m |
---|
| 241 | fi |
---|
| 242 | filein=${dirin}/${period}/${var}_tropflux_${suffix}_${badend}.nc |
---|
| 243 | if [ ! -f ${filein} ] |
---|
| 244 | then |
---|
| 245 | echo " eee : ${filein} not found" 1>> ${log} |
---|
| 246 | exit 1 |
---|
| 247 | else |
---|
| 248 | list_filein=${list_filein}" ${filein}" |
---|
| 249 | fi |
---|
| 250 | done |
---|
| 251 | unset period |
---|
| 252 | done |
---|
| 253 | unset period_list |
---|
| 254 | unset var |
---|
| 255 | unset varlist |
---|
[88] | 256 | # |
---|
[202] | 257 | # rename all files |
---|
| 258 | for filein in ${list_filein} |
---|
| 259 | do |
---|
| 260 | echo "iii : rename ${filein}" >> ${log} 2>&1 |
---|
| 261 | bfileout=$(basename ${filein} ${badend}.nc)"${goodend}.nc" |
---|
| 262 | fileout=$(dirname ${filein})/${bfileout} |
---|
| 263 | unset bfileout |
---|
| 264 | mv ${filein} ${fileout} >> ${log} 2>&1 |
---|
| 265 | status=${?} |
---|
| 266 | if [ ${status} -ne 0 ] |
---|
| 267 | then |
---|
| 268 | echo "eee : pb with mv" >> ${log} 2>&1 |
---|
| 269 | ncdump -h ${filein} >> ${log} 2>&1 |
---|
| 270 | exit 1 |
---|
| 271 | fi |
---|
| 272 | unset status |
---|
| 273 | unset fileout |
---|
| 274 | done |
---|
| 275 | unset filein |
---|
[88] | 276 | # |
---|
| 277 | # cleanning |
---|
[202] | 278 | #++ |
---|
[88] | 279 | #++ set |
---|
| 280 | # end |
---|
| 281 | exit 0 |
---|