[153] | 1 | #! /bin/sh |
---|
[151] | 2 | #+ |
---|
| 3 | # |
---|
| 4 | # .. program:: tropflux.sh |
---|
| 5 | # |
---|
| 6 | # .. _tropflux.sh: |
---|
| 7 | # |
---|
| 8 | # =========== |
---|
| 9 | # tropflux.sh |
---|
| 10 | # =========== |
---|
| 11 | # |
---|
| 12 | # SYNOPSIS |
---|
| 13 | # ======== |
---|
| 14 | # |
---|
| 15 | # :: |
---|
| 16 | # |
---|
| 17 | # $ tropflux.sh -b yyyymmdd -e yyyymmdd |
---|
| 18 | # |
---|
| 19 | # DESCRIPTION |
---|
| 20 | # =========== |
---|
| 21 | # |
---|
| 22 | # Run all needed :file:`*.pro` to create the TropFlux dataset between two dates |
---|
| 23 | # |
---|
| 24 | # We suppose here that all inputs data are already available localy. |
---|
| 25 | # |
---|
| 26 | # .. option:: -b beginning date <yyyymmdd> |
---|
| 27 | # .. option:: -e end date <yyyymmdd> |
---|
| 28 | # |
---|
| 29 | # Some IDL programs are launched here using ${IDL_CMD} command |
---|
| 30 | # (see :ref:`project_profile.sh` to know how to set this environnement variable). |
---|
| 31 | # |
---|
| 32 | # Log file is written on |
---|
| 33 | # :file:`${PROJECT_LOG}/tropflux.log.{YYYYMMDDTHHMMSSZ}` |
---|
| 34 | # |
---|
| 35 | # .. only:: man |
---|
| 36 | # |
---|
| 37 | # Figure is visible on PDF and HTML documents only. |
---|
| 38 | # |
---|
| 39 | # .. only:: html or latex |
---|
| 40 | # |
---|
| 41 | # .. graphviz:: |
---|
| 42 | # |
---|
| 43 | # digraph tropflux { |
---|
| 44 | # |
---|
[153] | 45 | # file_oaflux [shape=ellipse,fontname=Courier,label="${PROJECT_ID}/lh_oaflux_2004.nc"]; |
---|
| 46 | |
---|
[151] | 47 | # log [shape=ellipse,fontname=Courier,label="${PROJECT_LOG}/tropflux.log{YYYYMMDDTHHMMSSZ}"]; |
---|
| 48 | # |
---|
| 49 | # tropflux [shape=box, |
---|
| 50 | # fontname=Courier, |
---|
| 51 | # color=blue, |
---|
| 52 | # URL="http://forge.ipsl.jussieu.fr/tropflux/browser/trunk/src/tropflux.sh", |
---|
| 53 | # label="${PROJECT}/src/tropflux.sh"]; |
---|
| 54 | # |
---|
[153] | 55 | # {file_oaflux} -> {tropflux} -> {log fileout} |
---|
[151] | 56 | # |
---|
| 57 | # } |
---|
| 58 | # |
---|
| 59 | # EXAMPLES |
---|
| 60 | # ======== |
---|
| 61 | # |
---|
| 62 | # You already used :ref:`get_erai.sh` to get ERAI data, etc., |
---|
[165] | 63 | # during [20000101, 20000302[ and you want to produce NetCDF files:: |
---|
[151] | 64 | # |
---|
[165] | 65 | # $ tropflux.sh -b 20000101 -e 20000302 |
---|
[151] | 66 | # |
---|
[155] | 67 | # A more global example:: |
---|
| 68 | # |
---|
| 69 | # $ tropflux.sh -b 19890101 -e 20091231 |
---|
| 70 | # |
---|
[151] | 71 | # And look at log file with :: |
---|
| 72 | # |
---|
| 73 | # $ tlogd.sh tropflux |
---|
| 74 | # |
---|
| 75 | # and of course on files in ${PROJECT_ID}. |
---|
| 76 | # |
---|
| 77 | # SEE ALSO |
---|
| 78 | # ======== |
---|
| 79 | # |
---|
| 80 | # IDL_ |
---|
| 81 | # |
---|
| 82 | # .. _IDL: http://www.ittvis.com/ProductServices/IDL.aspx |
---|
| 83 | # |
---|
| 84 | # :ref:`project_profile.sh` |
---|
| 85 | # :ref:`project_init.pro` |
---|
| 86 | # |
---|
| 87 | # Previous step : :ref:`get_erai.sh`, :ref:`get_oaflux.sh`, :ref:`get_olr.sh`, |
---|
| 88 | # :ref:`get_pirata_netcdf.sh`, :ref:`get_swr.sh` |
---|
| 89 | # |
---|
| 90 | # Use : |
---|
[165] | 91 | # :func:`oaflux_mask_30n30s`, :func:`interp_erai_t2m`, |
---|
[167] | 92 | # :func:`interp_erai_msl`, :func:`interp_erai_dewt`, :func:`interp_erai_lwr`, |
---|
| 93 | # etc. |
---|
[151] | 94 | # |
---|
| 95 | # Next step : +validation ++ comparison |
---|
| 96 | # |
---|
| 97 | # .. todo:: |
---|
| 98 | # |
---|
| 99 | # TODO |
---|
| 100 | # ==== |
---|
| 101 | # |
---|
| 102 | # make it work |
---|
| 103 | # |
---|
| 104 | # idl status = 0 even if not ok |
---|
| 105 | # |
---|
| 106 | # test if demo mode idl |
---|
| 107 | # |
---|
| 108 | # EVOLUTIONS |
---|
| 109 | # ========== |
---|
| 110 | # |
---|
| 111 | # $Id$ |
---|
| 112 | # |
---|
| 113 | # $URL$ |
---|
| 114 | # |
---|
[163] | 115 | # - pinsard 20120319 |
---|
| 116 | # |
---|
| 117 | # * add project_overwrite usage |
---|
[165] | 118 | # * handling error of inter_erai_msl (now function) |
---|
[166] | 119 | # * handling error of inter_erai_dewt (now function) |
---|
[167] | 120 | # * handling error of inter_erai_lwr (now function) |
---|
[163] | 121 | # |
---|
[155] | 122 | # - pinsard 20120306 |
---|
| 123 | # |
---|
| 124 | # * create a pro IDL program to introduce LOGICAL_PREDICATE |
---|
| 125 | # thanks to http://www.idlcoyote.com/code_tips/bitwiselogical.html |
---|
| 126 | # |
---|
[151] | 127 | # - pinsard 20120305 |
---|
| 128 | # |
---|
| 129 | # * creation (draft) |
---|
[153] | 130 | # * handling error of oaflux_mask_30n30s (now a function) |
---|
[151] | 131 | # |
---|
| 132 | #- |
---|
| 133 | system=$(uname) |
---|
| 134 | case "${system}" in |
---|
| 135 | AIX|IRIX64) |
---|
| 136 | echo "${command} : www : no specific posix checking" |
---|
| 137 | date_cmd=date |
---|
| 138 | ;; |
---|
| 139 | Darwin) |
---|
| 140 | set -o posix |
---|
| 141 | date_cmd=gdate |
---|
| 142 | ;; |
---|
| 143 | Linux) |
---|
| 144 | set -o posix |
---|
| 145 | date_cmd=date |
---|
| 146 | ;; |
---|
| 147 | *) |
---|
| 148 | set -o posix |
---|
| 149 | ;; |
---|
| 150 | esac |
---|
| 151 | unset system |
---|
| 152 | # |
---|
| 153 | set -u |
---|
| 154 | # |
---|
| 155 | LANG=POSIX |
---|
| 156 | # |
---|
| 157 | command=$(basename ${0}) |
---|
| 158 | log_date=$(date -u +"%Y%m%dT%H%M%SZ") |
---|
| 159 | # |
---|
| 160 | usage=" Usage : ${command} [-f] -b yyyymmdd -e yyyymmdd" |
---|
| 161 | # |
---|
| 162 | hostname=$(hostname) |
---|
| 163 | # |
---|
| 164 | yyyymmddb_min=19790101 |
---|
| 165 | yyyymmdde_max=20110930 |
---|
| 166 | # |
---|
| 167 | # default |
---|
| 168 | debug=0 |
---|
[165] | 169 | yyyymmddb=20000101 |
---|
| 170 | yyyymmdde=20000302 |
---|
[151] | 171 | # |
---|
| 172 | minargcount=4 |
---|
| 173 | if [ ${#} -lt ${minargcount} ] |
---|
| 174 | then |
---|
| 175 | echo "${command} : eee : not enought arguments" |
---|
| 176 | echo "${usage}" |
---|
| 177 | exit 1 |
---|
| 178 | fi |
---|
| 179 | unset minargcount |
---|
| 180 | # |
---|
| 181 | while [ ${#} -gt 0 ] |
---|
| 182 | do |
---|
| 183 | case ${1} in |
---|
| 184 | -b) |
---|
| 185 | # first date to process |
---|
| 186 | yyyymmddb=${2} |
---|
| 187 | shift |
---|
| 188 | ;; |
---|
| 189 | -e) |
---|
| 190 | # last date to process |
---|
| 191 | yyyymmdde=${2} |
---|
| 192 | shift |
---|
| 193 | ;; |
---|
| 194 | -h) |
---|
| 195 | echo "${usage}" |
---|
| 196 | exit 0 |
---|
| 197 | ;; |
---|
| 198 | *) |
---|
| 199 | # other choice |
---|
| 200 | echo "${command} : eee : unknown option ${1}" |
---|
| 201 | echo "${usage}" |
---|
| 202 | exit 1 |
---|
| 203 | ;; |
---|
| 204 | esac |
---|
| 205 | # next flag |
---|
| 206 | shift |
---|
| 207 | done |
---|
| 208 | unset usage |
---|
| 209 | # |
---|
| 210 | # check parameters |
---|
| 211 | # and define associated variables |
---|
| 212 | ${date_cmd} -d "${yyyymmddb}" > /dev/null |
---|
| 213 | status_date=${?} |
---|
| 214 | if [ ${status_date} -ne 0 ] |
---|
| 215 | then |
---|
| 216 | echo "${command} : eee : yyyymmddb ${yyyymmddb} argument invalid" |
---|
| 217 | exit 1 |
---|
| 218 | fi |
---|
| 219 | unset status_date |
---|
| 220 | # |
---|
| 221 | if [[ "${yyyymmddb}" < "${yyyymmddb_min}" ]] |
---|
| 222 | then |
---|
| 223 | echo "${command} : eee : yyyymmddb ${yyyymmddb} must be equal or greater than yyyymmddb_min ${yyyymmddb_min}" |
---|
| 224 | exit 1 |
---|
| 225 | fi |
---|
| 226 | # |
---|
| 227 | ${date_cmd} -d "${yyyymmdde}" > /dev/null |
---|
| 228 | status_date=${?} |
---|
| 229 | if [ ${status_date} -ne 0 ] |
---|
| 230 | then |
---|
| 231 | echo "${command} : eee : yyyymmdde ${yyyymmdde} argument invalid" |
---|
| 232 | exit 1 |
---|
| 233 | fi |
---|
| 234 | unset status_date |
---|
| 235 | # |
---|
| 236 | if [[ "${yyyymmdde}" > "${yyyymmdde_max}" ]] |
---|
| 237 | then |
---|
| 238 | echo "${command} : eee : yyyymmdde ${yyyymmdde} must be lower or equal to yyyymmdde_max ${yyyymmdde_max}" |
---|
| 239 | exit 1 |
---|
| 240 | fi |
---|
| 241 | # |
---|
| 242 | if [[ "${yyyymmdde}" < "${yyyymmddb}" ]] |
---|
| 243 | then |
---|
| 244 | echo "${command} : eee : yyyymmdde ${yyyymmdde} must be greater than yyyymmddb ${yyyymmddb}" |
---|
| 245 | exit 1 |
---|
| 246 | fi |
---|
| 247 | # |
---|
| 248 | if [[ "${yyyymmdde}" = "${yyyymmddb}" ]] |
---|
| 249 | then |
---|
| 250 | echo "${command} : eee : yyyymmdde ${yyyymmdde} must be greater than yyyymmddb ${yyyymmddb}" |
---|
| 251 | exit 1 |
---|
| 252 | fi |
---|
| 253 | # |
---|
| 254 | tool=${IDL_CMD} |
---|
| 255 | type ${tool} 1> /dev/null 2>&1 |
---|
| 256 | status=${?} |
---|
| 257 | if [ ${status} -ne 0 ] |
---|
| 258 | then |
---|
| 259 | echo "${command} : eee : tool ${IDL_CMD} not found" |
---|
| 260 | echo "${command} : eee : check project_profile.sh sequence" |
---|
| 261 | exit 1 |
---|
| 262 | fi |
---|
| 263 | unset status |
---|
| 264 | unset tool |
---|
| 265 | # |
---|
| 266 | # check for write permission on PROJECT_LOG |
---|
| 267 | if [ ! -w ${PROJECT_LOG} ] |
---|
| 268 | then |
---|
| 269 | echo "${command} : eee : ${PROJECT_LOG} not writable" |
---|
| 270 | exit 1 |
---|
| 271 | fi |
---|
| 272 | # |
---|
| 273 | log=${PROJECT_LOG}/$(basename ${0} .sh).log.${log_date} |
---|
| 274 | echo "[Context]" 1>> ${log} |
---|
| 275 | echo "command=$(basename ${0})" 1>>${log} |
---|
| 276 | echo "hostname=${hostname}" 1>> ${log} |
---|
| 277 | echo "runtime=${log_date}" 1>> ${log} |
---|
| 278 | echo "IDL_CMD=${IDL_CMD}" 1>> ${log} |
---|
| 279 | unset log_date |
---|
| 280 | echo "" 1>> ${log} |
---|
| 281 | echo "[Parameters]" 1>> ${log} |
---|
| 282 | echo "yyyymmddb=${yyyymmddb}" 1>> ${log} |
---|
| 283 | echo "yyyymmdde=${yyyymmdde}" 1>> ${log} |
---|
| 284 | echo "" 1>> ${log} |
---|
| 285 | # |
---|
| 286 | cat >> ${PROJECT}/src/tropflux_${$}.pro << EOF |
---|
[155] | 287 | pro tropflux_${$} |
---|
| 288 | compile_opt idl2, strictarrsubs, logical_predicate |
---|
[163] | 289 | @cm_project |
---|
| 290 | ; |
---|
| 291 | ; define overwrite status |
---|
| 292 | ; set to 1 to overwrite existing files |
---|
| 293 | project_overwrite = 0 |
---|
| 294 | ; |
---|
[153] | 295 | result = oaflux_mask_30n30s() |
---|
[155] | 296 | IF result < 0 THEN BEGIN |
---|
| 297 | msg = 'eee : pb after oaflux_mask_30n30s' + string(result) |
---|
[153] | 298 | err = report(msg) |
---|
| 299 | exit |
---|
| 300 | ENDIF |
---|
[166] | 301 | result = interp_erai_dewt(${yyyymmddb}, ${yyyymmdde}) |
---|
| 302 | IF result < 0 THEN BEGIN |
---|
| 303 | msg = 'eee : pb after interp_erai_dewt' + string(result) |
---|
| 304 | err = report(msg) |
---|
| 305 | exit |
---|
| 306 | ENDIF |
---|
[167] | 307 | result = interp_erai_lwr(${yyyymmddb}, ${yyyymmdde}) |
---|
| 308 | IF result < 0 THEN BEGIN |
---|
| 309 | msg = 'eee : pb after interp_erai_lwr' + string(result) |
---|
| 310 | err = report(msg) |
---|
| 311 | exit |
---|
| 312 | ENDIF |
---|
[165] | 313 | result = interp_erai_msl(${yyyymmddb}, ${yyyymmdde}) |
---|
| 314 | IF result < 0 THEN BEGIN |
---|
| 315 | msg = 'eee : pb after interp_erai_msl' + string(result) |
---|
| 316 | err = report(msg) |
---|
| 317 | exit |
---|
| 318 | ENDIF |
---|
[151] | 319 | ;interp_erai_sst_1989_2009 |
---|
[155] | 320 | result = interp_erai_t2m(${yyyymmddb}, ${yyyymmdde}) |
---|
| 321 | IF result < 0 THEN BEGIN |
---|
| 322 | msg = 'eee : pb after interp_erai_t2m' + string(result) |
---|
| 323 | err = report(msg) |
---|
| 324 | exit |
---|
| 325 | ENDIF |
---|
[151] | 326 | ;interp_erai_ws_1989_2009 |
---|
| 327 | ;interp_olr_30n30s_1989_2009 |
---|
[153] | 328 | d2m_to_q2m_erai |
---|
| 329 | ;++Program caused arithmetic error: Floating overflow |
---|
| 330 | ;++ Program caused arithmetic error: Floating illegal operand |
---|
[155] | 331 | ;.compile TropFlux_swr_DT_19890101_20071231 |
---|
| 332 | ;tropflux_swr_dt_19890101_20071231 |
---|
| 333 | ;.compile TropFlux_swr_NRT_19890101_20091231 |
---|
| 334 | ;tropflux_swr_nrt_19890101_20091231 |
---|
| 335 | ;.compile TropFlux_swr_BLND_19890101_20091231 |
---|
| 336 | ;tropflux_swr_blnd_19890101_20091231 |
---|
| 337 | ;lwr_correction_ncdf |
---|
| 338 | ;q2m_correction_ncdf |
---|
| 339 | ;sst_correction_ncdf |
---|
| 340 | ;t2m_correction_ncdf |
---|
| 341 | ;ws_correction_ncdf |
---|
| 342 | ;cronin_gustiness_ncdf |
---|
| 343 | ;.compile TropFlux_19890101_20091231 |
---|
| 344 | ;tropflux_19890101_20091231 |
---|
| 345 | ;.compile TropFlux_NRT_ncdf |
---|
| 346 | ;tropflux_nrt_ncdf |
---|
| 347 | end |
---|
[151] | 348 | EOF |
---|
| 349 | # |
---|
| 350 | # run IDL or equivalent |
---|
| 351 | ${IDL_CMD} << EOF >> ${log} 2>&1 |
---|
[155] | 352 | .compile file_interp |
---|
[163] | 353 | ; |
---|
[155] | 354 | tropflux_${$} |
---|
[151] | 355 | EOF |
---|
| 356 | status=${?} |
---|
| 357 | if [ ${status} -ne 0 ] |
---|
| 358 | then |
---|
| 359 | echo "${command} : eee: ${IDL_CMD} failed : ${status}" >> ${log} 2>&1 |
---|
| 360 | cat ${PROJECT}/src/tropflux_${$}.pro >> ${log} 2>&1 |
---|
| 361 | exit 1 |
---|
| 362 | fi |
---|
| 363 | rm ${PROJECT}/src/tropflux_${$}.pro |
---|
| 364 | unset status |
---|
| 365 | # |
---|
| 366 | unset command |
---|
| 367 | unset log |
---|
| 368 | unset hostname |
---|
| 369 | unset usage |
---|
| 370 | # |
---|
| 371 | unset date_cmd |
---|
| 372 | # |
---|
| 373 | # end |
---|
| 374 | #++set |
---|
| 375 | exit |
---|