[88] | 1 | #! /bin/sh |
---|
| 2 | # |
---|
| 3 | #+ |
---|
| 4 | # |
---|
| 5 | # .. program:: add_19890101.sh |
---|
| 6 | # |
---|
| 7 | # .. _add_19890101.sh: |
---|
| 8 | # |
---|
| 9 | # ================== |
---|
| 10 | # add_19890101.sh |
---|
| 11 | # ================== |
---|
| 12 | # |
---|
| 13 | # SYNOPSIS |
---|
| 14 | # ======== |
---|
| 15 | # |
---|
| 16 | # :: |
---|
| 17 | # |
---|
| 18 | # $ add_19890101.sh [--debug] |
---|
| 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 | # Artificialy add 19890101 to lwr interpolated on OAFLUX grid dataset. |
---|
| 28 | # |
---|
| 29 | # :file:`${PROJECT_OD}/erai_lwr_19890102_20091231_oafluxgrid.nc` |
---|
| 30 | # containing |
---|
| 31 | # ++ |
---|
| 32 | # has been produced by |
---|
| 33 | # :ref:`interp_erai_lwr_1989_2009.pro`. |
---|
| 34 | # repeat the first time step in |
---|
| 35 | # |
---|
| 36 | # File :file:`${PROJECT_OD}/erai_lwr_19890101_20091231_oafluxgrid.nc` |
---|
| 37 | # will be written |
---|
| 38 | # if this file not already exists. |
---|
| 39 | # |
---|
| 40 | # This output file |
---|
| 41 | # :file:`${PROJECT_OD}/erai_lwr_19890101_20091231_oafluxgrid.nc` |
---|
| 42 | # must be processed after by |
---|
| 43 | # :ref:`lwr_correction_ncdf.pro`. |
---|
| 44 | # |
---|
| 45 | # Log file is written on :file:`${PROJECT_LOG}/add_19890101.sh.log.{YYYYMMDDTHHMMSSZ}` |
---|
| 46 | # |
---|
| 47 | # .. graphviz:: |
---|
| 48 | # |
---|
| 49 | # digraph add_19890101 { |
---|
| 50 | # |
---|
| 51 | # filein [shape=ellipse,fontname=Courier,label="$PROJECT_OD/erai_lwr_19890102_20091231_oafluxgrid.nc"]; |
---|
| 52 | # fileout [shape=ellipse,fontname=Courier,label="$PROJECT_OD/erai_lwr_19890101_20091231_oafluxgrid.nc"]; |
---|
| 53 | # |
---|
| 54 | # add_19890101 [shape=box, |
---|
| 55 | # fontname=Courier, |
---|
| 56 | # color=blue, |
---|
| 57 | # URL="http://forge.ipsl.jussieu.fr/tropflux/browser/trunk/src/add_19890101.sh", |
---|
| 58 | # label="${PROJECT}/src/add_19890101.sh"]; |
---|
| 59 | # |
---|
| 60 | # {filein} -> {add_19890101} -> {fileout} |
---|
| 61 | # |
---|
| 62 | # } |
---|
| 63 | # |
---|
| 64 | # EXAMPLES |
---|
| 65 | # ======== |
---|
| 66 | # |
---|
| 67 | # To produce $PROJECT_OD/erai_lwr_19890101_20091231_oafluxgrid.nc |
---|
| 68 | # from $PROJECT_OD/erai_lwr_19890102_20091231_oafluxgrid.nc :: |
---|
| 69 | # |
---|
| 70 | # $ add_19890101.sh --debug |
---|
| 71 | # |
---|
| 72 | # And look at log file with :: |
---|
| 73 | # |
---|
| 74 | # $ tlogd.sh add_19890101 |
---|
| 75 | # |
---|
| 76 | # and of course on files in ${PROJECT_OD}. |
---|
| 77 | # |
---|
| 78 | # TIPS |
---|
| 79 | # ==== |
---|
| 80 | # |
---|
| 81 | # To see the 3 first time values in input and files:: |
---|
| 82 | # |
---|
| 83 | # $ ncks -s "%16.10f\n" -v tt -d time,0,2 ${PROJECT_OD}/erai_lwr_19890102_20091231_oafluxgrid.nc |
---|
| 84 | # 14246.0000000005 |
---|
| 85 | # 14247.0000000005 |
---|
| 86 | # 14248.0000000005 |
---|
| 87 | # |
---|
| 88 | # $ ncks -s "%16.10f\n" -v tt -d time,0,2 ${PROJECT_OD}/erai_lwr_19890101_20091231_oafluxgrid.nc |
---|
| 89 | # 14245.0000000005 |
---|
| 90 | # 14246.0000000005 |
---|
| 91 | # 14247.0000000005 |
---|
| 92 | # |
---|
| 93 | # while : |
---|
| 94 | # |
---|
| 95 | # $ idl |
---|
| 96 | # IDl> print, julday(01, 01, 1989,12)-julday(01, 01, 1950,0) |
---|
| 97 | # 14245.500 |
---|
| 98 | # IDL> print, julday(01, 01, 1989,12)-julday(01, 01, 1950,0) +1 |
---|
| 99 | # 14246.500 |
---|
| 100 | # |
---|
| 101 | # SEE ALSO |
---|
| 102 | # ======== |
---|
| 103 | # |
---|
| 104 | # :ref:`project_profile.sh` |
---|
| 105 | # |
---|
| 106 | # :func:`ncks <nco:ncks>` |
---|
| 107 | # :func:`ncrcat <nco:ncrcat>` |
---|
| 108 | # :func:`ncatted <nco:ncatted>` |
---|
| 109 | # :func:`ncap2 <nco:ncap2>` |
---|
| 110 | # |
---|
| 111 | # :ref:`lwr_correction_ncdf.pro` |
---|
| 112 | # |
---|
| 113 | # TODO |
---|
| 114 | # ==== |
---|
| 115 | # |
---|
| 116 | # coding rules |
---|
| 117 | # |
---|
| 118 | # won't it be more conveniant to add this articifial time step in |
---|
| 119 | # the IDL creation tool interp_erai_lwr_1989_2009.pro. |
---|
| 120 | # It will allow to avoid a shell interruption in the IDL processing chain. |
---|
| 121 | # |
---|
| 122 | # improve global attributes with ... creation_date and so on |
---|
| 123 | # |
---|
| 124 | # check if the first time step is really 19890102 in the input file |
---|
| 125 | # |
---|
| 126 | # change tt to ttt to complete time correction |
---|
| 127 | # |
---|
| 128 | # remove hard coded end time |
---|
| 129 | # |
---|
| 130 | # get rid of this long mesage on cratos:: |
---|
| 131 | # |
---|
| 132 | # ncrcat: WARNING Variable lwr has attribute "missing_value" but not "_FillValue". To |
---|
| 133 | # comply with netCDF conventions, NCO ignores values that equal the _FillValue attribu |
---|
| 134 | # te when performing arithmetic. Confusingly, values equal to the missing_value should |
---|
| 135 | # also be neglected. However, it is tedious and (possibly) computationally expensive |
---|
| 136 | # to check each value against multiple missing values during arithmetic on large varia |
---|
| 137 | # bles. So NCO thinks that processing variables with a "missing_value" attribute and n |
---|
| 138 | # o "_FillValue" attribute may produce undesired arithmetic results (i.e., where value |
---|
| 139 | # s that were intended to be neglected were not, in fact, neglected). We suggest you r |
---|
| 140 | # ename all "missing_value" attributes to "_FillValue" or include both "missing_value" |
---|
| 141 | # and "_FillValue" attributes (with the _same values_) for all variables that have ei |
---|
| 142 | # ther attribute. Because it is long, this message is only printed once per operator e |
---|
| 143 | # ven though multiple variables may have the same attribute configuration. More inform |
---|
| 144 | # ation on missing values is given at: |
---|
| 145 | # http://nco.sf.net/nco.html#mss_val |
---|
| 146 | # Examples of renaming attributes are at: |
---|
| 147 | # http://nco.sf.net/nco.html#xmp_ncrename |
---|
| 148 | # |
---|
| 149 | # ... on a déjà une idee de la solution : convention CF et meilleure gestion des |
---|
| 150 | # valeurs manquantes dans les softs IDL !!! |
---|
| 151 | # |
---|
| 152 | # |
---|
| 153 | # EVOLUTIONS |
---|
| 154 | # ========== |
---|
| 155 | # |
---|
| 156 | # $Id$ |
---|
| 157 | # |
---|
| 158 | # $URL$ |
---|
| 159 | # |
---|
| 160 | # - fplod 20110819T091143Z aedon.locean-ipsl.upmc.fr (Darwin) |
---|
| 161 | # |
---|
| 162 | # * creation from pk email 20110811 "lwr first timestep" |
---|
| 163 | # * include time correction and timerange modificaton |
---|
| 164 | # |
---|
| 165 | #- |
---|
| 166 | system=$(uname) |
---|
| 167 | case "${system}" in |
---|
| 168 | AIX|IRIX64) |
---|
| 169 | echo "www : no specific posix checking" |
---|
| 170 | date_cmd=date |
---|
| 171 | ;; |
---|
| 172 | Darwin) |
---|
| 173 | set -o posix |
---|
| 174 | date_cmd=gdate |
---|
| 175 | ;; |
---|
| 176 | Linux) |
---|
| 177 | set -o posix |
---|
| 178 | date_cmd=date |
---|
| 179 | ;; |
---|
| 180 | *) |
---|
| 181 | set -o posix |
---|
| 182 | ;; |
---|
| 183 | esac |
---|
| 184 | unset system |
---|
| 185 | # |
---|
| 186 | LANG=POSIX |
---|
| 187 | # |
---|
[101] | 188 | set -u |
---|
| 189 | # |
---|
[88] | 190 | command=$(basename ${0}) |
---|
| 191 | log_date=$(date -u +"%Y%m%dT%H%M%SZ") |
---|
| 192 | # |
---|
| 193 | usage=" Usage : ${command} [--debug]" |
---|
| 194 | # |
---|
| 195 | hostname=$(hostname) |
---|
| 196 | # |
---|
| 197 | # default |
---|
| 198 | debug=0 |
---|
| 199 | # |
---|
| 200 | minargcount=0 |
---|
| 201 | if [ ${#} -lt ${minargcount} ] |
---|
| 202 | then |
---|
| 203 | echo "${command} : eee : not enought arguments" |
---|
| 204 | echo "${usage}" |
---|
| 205 | exit 1 |
---|
| 206 | fi |
---|
| 207 | # |
---|
[101] | 208 | while [ ${#} -gt 0 ] |
---|
[88] | 209 | do |
---|
| 210 | case ${1} in |
---|
| 211 | --debug) |
---|
| 212 | debug=1 |
---|
| 213 | ;; |
---|
| 214 | *) |
---|
| 215 | # anything else |
---|
| 216 | echo "${command} : eee : unknown option ${1}" |
---|
| 217 | echo "${command} : eee : ${usage}" |
---|
| 218 | exit 1 |
---|
| 219 | ;; |
---|
| 220 | esac |
---|
| 221 | # next flag |
---|
| 222 | shift |
---|
| 223 | done |
---|
| 224 | # |
---|
| 225 | # check parameters |
---|
| 226 | # N.A. |
---|
| 227 | # |
---|
| 228 | tool=ncrcat |
---|
| 229 | type ${tool} 1> /dev/null 2>&1 |
---|
| 230 | status=${?} |
---|
| 231 | if [ ${status} -ne 0 ] |
---|
| 232 | then |
---|
| 233 | echo "${command} : eee : tool ${tool} not found" |
---|
| 234 | exit 1 |
---|
| 235 | fi |
---|
| 236 | unset status |
---|
| 237 | unset tool |
---|
| 238 | # |
---|
| 239 | tool=ncks |
---|
| 240 | type ${tool} 1> /dev/null 2>&1 |
---|
| 241 | status=${?} |
---|
| 242 | if [ ${status} -ne 0 ] |
---|
| 243 | then |
---|
| 244 | echo "${command} : eee : tool ${tool} not found" |
---|
| 245 | exit 1 |
---|
| 246 | fi |
---|
| 247 | unset status |
---|
| 248 | unset tool |
---|
| 249 | # |
---|
| 250 | tool=ncatted |
---|
| 251 | type ${tool} 1> /dev/null 2>&1 |
---|
| 252 | status=${?} |
---|
| 253 | if [ ${status} -ne 0 ] |
---|
| 254 | then |
---|
| 255 | echo "${command} : eee : tool ${tool} not found" |
---|
| 256 | exit 1 |
---|
| 257 | fi |
---|
| 258 | unset status |
---|
| 259 | unset tool |
---|
| 260 | # |
---|
| 261 | # check for ${PROJECT_LOG} definition |
---|
| 262 | if [ "${PROJECT_LOG}" = "" ] |
---|
| 263 | then |
---|
| 264 | echo "${command} : eee : \${PROJECT_LOG} not defined" |
---|
| 265 | exit 1 |
---|
| 266 | fi |
---|
| 267 | # |
---|
| 268 | # check for ${PROJECT_LOG} existence |
---|
| 269 | if [ ! -d ${PROJECT_LOG} ] |
---|
| 270 | then |
---|
| 271 | echo "${command} : eee : ${PROJECT_LOG} not found" |
---|
| 272 | exit 1 |
---|
| 273 | fi |
---|
| 274 | # |
---|
| 275 | # check for permission access on PROJECT_LOG |
---|
| 276 | if [ ! -x ${PROJECT_LOG} ] |
---|
| 277 | then |
---|
| 278 | echo "${command} : eee : ${PROJECT_LOG} not reachable" |
---|
| 279 | exit 1 |
---|
| 280 | fi |
---|
| 281 | # |
---|
| 282 | # check for write permission on PROJECT_LOG |
---|
| 283 | if [ ! -w ${PROJECT_LOG} ] |
---|
| 284 | then |
---|
| 285 | echo "${command} : eee : ${PROJECT_LOG} not writable" |
---|
| 286 | exit 1 |
---|
| 287 | fi |
---|
| 288 | # |
---|
| 289 | log=${PROJECT_LOG}/$(basename ${0} .sh).log.${log_date} |
---|
| 290 | echo "[Context]" 1>> ${log} |
---|
| 291 | echo "command=$(basename ${0})" 1>>${log} |
---|
| 292 | echo "hostname=${hostname}" 1>> ${log} |
---|
| 293 | echo "runtime=${log_date}" 1>> ${log} |
---|
| 294 | unset log_date |
---|
| 295 | # |
---|
| 296 | echo "" 1>> ${log} |
---|
| 297 | echo "[Parameters]" 1>> ${log} |
---|
| 298 | echo "N.A." 1>> ${log} |
---|
| 299 | echo "" 1>> ${log} |
---|
| 300 | # |
---|
| 301 | filein=${PROJECT_OD}/erai_lwr_19890102_20091231_oafluxgrid.nc |
---|
| 302 | if [ ! -f ${filein} ] |
---|
| 303 | then |
---|
| 304 | echo " eee : ${filein} not found" 1>> ${log} |
---|
| 305 | exit 1 |
---|
| 306 | fi |
---|
| 307 | fileout=${PROJECT_OD}/erai_lwr_19890101_20091231_oafluxgrid.nc |
---|
| 308 | if [ -f ${fileout} ] |
---|
| 309 | then |
---|
| 310 | echo "eee : ${fileout} already exists" 1>>${log} |
---|
| 311 | exit 1 |
---|
| 312 | fi |
---|
| 313 | # |
---|
| 314 | rm -f ${PROJECT_OD}/erai_lwr_step19890101.nc 2> /dev/null |
---|
| 315 | rm -f ${PROJECT_OD}/erai_lwr_step19890102.nc 2> /dev/null |
---|
| 316 | # |
---|
| 317 | # extraction of the first time step 19890102 |
---|
| 318 | ncks -h -d time,0,0 ${filein} ${PROJECT_OD}/erai_lwr_step19890102.nc >> ${log} 2>&1 |
---|
| 319 | status=${?} |
---|
| 320 | if [ ${status} -ne 0 ] |
---|
| 321 | then |
---|
| 322 | echo "eee : pb with ncks" >> ${log} 2>&1 |
---|
| 323 | ncdump -h ${filein} >> ${log} 2>&1 |
---|
| 324 | exit 1 |
---|
| 325 | fi |
---|
| 326 | unset status |
---|
| 327 | # |
---|
| 328 | # ++ check if tt[0] is really 19890102 |
---|
| 329 | # |
---|
| 330 | # substract 1 to tt to simulate 19890101 |
---|
| 331 | ncap2 -h -s "tt=tt-1" \ |
---|
| 332 | ${PROJECT_OD}/erai_lwr_step19890102.nc \ |
---|
| 333 | ${PROJECT_OD}/erai_lwr_step19890101.nc |
---|
| 334 | status=${?} |
---|
| 335 | if [ ${status} -ne 0 ] |
---|
| 336 | then |
---|
| 337 | echo "eee : pb with ncap2" >> ${log} 2>&1 |
---|
| 338 | ncdump -h ${PROJECT_OD}/erai_lwr_step19890102.nc >> ${log} 2>&1 |
---|
| 339 | exit 1 |
---|
| 340 | fi |
---|
| 341 | unset status |
---|
| 342 | ls -l ${PROJECT_OD}/erai_lwr_step19890102.nc >> ${log} 2>&1 |
---|
| 343 | ls -l ${PROJECT_OD}/erai_lwr_step19890101.nc >> ${log} 2>&1 |
---|
| 344 | # |
---|
| 345 | # ++ check if tt[0] is really 19890101 |
---|
| 346 | # |
---|
| 347 | rm ${fileout}_bad_timerange 2> /dev/null |
---|
| 348 | ncrcat -h \ |
---|
| 349 | ${PROJECT_OD}/erai_lwr_step19890101.nc \ |
---|
| 350 | ${filein} \ |
---|
| 351 | ${fileout}_bad_timerange >> ${log} 2>&1 |
---|
| 352 | status=${?} |
---|
| 353 | if [ ${status} -ne 0 ] |
---|
| 354 | then |
---|
| 355 | echo "eee : pb with ncrcat" >> ${log} 2>&1 |
---|
| 356 | ncdump -h ${PROJECT_OD}/erai_lwr_step19890101.nc >> ${log} 2>&1 |
---|
| 357 | ncdump -h ${filein} >> ${log} 2>&1 |
---|
| 358 | exit 1 |
---|
| 359 | fi |
---|
| 360 | unset status |
---|
| 361 | # |
---|
| 362 | ncatted -h -a timerange,global,o,c,"19890101 - 20091231" \ |
---|
| 363 | ${fileout}_bad_timerange \ |
---|
| 364 | ${fileout} >> ${log} 2>&1 |
---|
| 365 | status=${?} |
---|
| 366 | if [ ${status} -ne 0 ] |
---|
| 367 | then |
---|
| 368 | echo "eee : pb with ncatted" >> ${log} 2>&1 |
---|
| 369 | ncdump -h ${fileout}_bad_timerange >> ${log} 2>&1 |
---|
| 370 | exit 1 |
---|
| 371 | fi |
---|
| 372 | unset status |
---|
| 373 | # |
---|
| 374 | if [ ${debug} -eq 1 ] |
---|
| 375 | then |
---|
| 376 | ncdump -v tt ${fileout} >> ${log} 2>&1 |
---|
| 377 | fi |
---|
| 378 | # |
---|
| 379 | # cleanning |
---|
| 380 | #++rm -f ${PROJECT_OD}/erai_lwr_step19890101.nc 2> /dev/null |
---|
| 381 | #++rm -f ${PROJECT_OD}/erai_lwr_step19890102.nc 2> /dev/null |
---|
| 382 | #++rm -f ${PROJECT_OD}/${fileout}_bad_timerange 2> /dev/null |
---|
| 383 | # |
---|
| 384 | unset fileout |
---|
| 385 | unset filein |
---|
| 386 | #++ set |
---|
| 387 | # end |
---|
| 388 | exit 0 |
---|