#! /bin/bash
# Last edited on 2014-03-18 02:34:08 by stolfilocal

# 05 pixels = 01:00

date="2014-03-17"
hubi=1
bstp=0
dinos=1

function tscale(){
  # Prints to {stdout} the H-coordinate corresponing to a given hour number.

  # Scaling parameters:
  tshift="$1"; shift # Reference hour.
  hshift="$1"; shift # H-coordinate of reference hour.

  targ="$1"; shift # Given hour.

  # echo "enter tscale ${tshift} ${hshift} ${targ}" 1>&2

  thscale=2 # Pixels per hour.

  harg=$(( ( ( ${targ} - ${tshift} ) * ${thscale} ) + ${hshift} ))

  printf "%d\n" "${harg}"
  # echo "exit tscale ${harg}" 1>&2
}

function pscale(){
  # Prints to {stdout} the V-coordinate corresponing to a given price.

  # Scaling parameters:
  pmin="$1"; shift # Low reference price.
  vbot="$1"; shift # V-coordinate of the low reference price.
  pmax="$1"; shift # High reference price.
  vtop="$1"; shift # V-coordinate of the high reference price.

  parg="$1"; shift # Given price.

  # echo "enter pscale ${pmin} ${vbot} ${pmax} ${vtop} ${parg}" 1>&2

  pdel=$(( ${pmax} - ${pmin} ));
  prnd=$(( ${pdel} / 2 ))

  varg=$(( ${vbot} - ( ( ( ${parg} - ${pmin} ) * ( ${vbot} - ${vtop} ) + ${prnd} ) / ${pdel} ) ))

  printf "%d\n" "${varg}"
  # echo "exit pscale ${varg}" 1>&2
}

function make_rect_cmds(){
  # Prints to {stdout} the draw commands for a prediction box with label.

  # Hour scaling parameters:
  tshift="$1"; shift # Reference hour.
  hshift="$1"; shift # H-coordinate of reference hour.

  # Price scaling parameters:
  pmin="$1"; shift # Low reference price.
  vbot="$1"; shift # V-coordinate of the low reference price.
  pmax="$1"; shift # High reference price.
  vtop="$1"; shift # V-coordinate of the high reference price.

  krect="$1"; shift # "@" for old rectangle, "+" for new, "=" for predicted.
  trect="$1"; shift # Hour of rectangle center.
  prect="$1"; shift # Predicted price at ${trect}.
  herr="$1"; shift  # Half-width of rectangle (pixels)
  verr="$1"; shift  # Half-height of rectngle (pixels).

  echo "enter make_rect_cmds ${pmin} ${vbot} ${pmax} ${vtop} ${krect} ${hrect} ${prect} ${herr} ${verr}" 1>&2

  hrect=`tscale ${tshift} ${hshift} ${trect}`
  vrect=`pscale ${pmin} ${vbot} ${pmax} ${vtop} ${prect}`
  vrect_top=$(( ${vrect} + ${verr} ))
  vrect_bot=$(( ${vrect} - ${verr} ))
  hrect_lft=$(( ${hrect} - ${herr} ))
  hrect_rht=$(( ${hrect} + ${herr} ))

  if [[ "/${krect}" == "/@" ]]; then
    crect="#aabbcc"
  elif [[ "/${krect}" == "/=" ]]; then
    crect="#ff0088"
  elif [[ "/${krect}" == "/+" ]]; then
    crect="#0088ff"
  else
    echo "** invalid rectange kind" 1>&2 ; exit 1
  fi

  printf "%s %s\n" "-color" "${crect}"
  printf "%s %s\n" "-strokewidth" "3"
  printf "%s %s %s  %s %s  %s %s  %s %s\n" "-Q" \
    "${hrect_rht}" "${vrect_top}" \
    "${hrect_rht}" "${vrect_bot}" \
    "${hrect_lft}" "${vrect_bot}" \
    "${hrect_lft}" "${vrect_top}"
  echo "exit make_rect_cmds" 1>&2
}

function annot(){
  # Annotate one image.

  ex="$1"; shift       # Exchange code
  which="$1"; shift    # "check" or "make"

  # Input image:
  iimg="${date}-prediction-check-${ex}"

  # Output image:
  oimg="${date}-prediction-${which}-${ex}"

  # Horizontal scale information
  if [[ "/$1" == "/-hscale" ]]; then
    shift;
    tshift="$1"; shift # Reference hour.
    hshift="$1"; shift # H-coordinate of reference hour.
  else
    echo "** missing \"-hscale\"" 1>&2
    exit 1
  fi

  # Vertical scale information
  if [[ "/$1" == "/-vscale" ]]; then
    shift;
    pmin="$1"; shift # Low reference price.
    vbot="$1"; shift # V-coordinate of the low reference price.
    pmax="$1"; shift # High reference price.
    vtop="$1"; shift # V-coordinate of the high reference price.
  else
    echo "** missing \"-vscale\"" 1>&2
    exit 1
  fi

  # Balloon with time posted ("-tpost") or time valid ("-tpred")
  labt_cmds=( )
  while [[ ( "/$1" == "/-tpost" ) || ( "/$1" == "/-tpred" ) ]]; do
    if [[ "/$1" == "/-tpost" ]]; then clabt="#ff44aa" ; else clabt="#33ddff" ; fi
    shift;

    # Label with time of last prediction:
    mlabt="$1"; shift # Text (eg UTC time) to show in balloon.
    tlabt="$1"; shift # Hour of balloon center.
    vlabt="$1"; shift # V-coordinate of balloon dot.

    hlabt=`tscale ${tshift} ${hshift} ${tlabt}`

    vlabt_dot=${vlabt}
    vlabt_lab=$(( ${vlabt_dot} - 100 ))
    labt_cmds+=( -color "${clabt}" -strokewidth 2 )
    labt_cmds+=( -L ${hlabt} ${vlabt_dot}  ${hlabt} ${vlabt_lab}  "${mlabt}" )
  done
  echo "labt_cmds=( " "${labt_cmds[@]}" " )" 1>&2

  # Prediction boxes:
  rect_cmds=( ) # Commands to draw prediction boxes.
  while [[ "/$1" == "/-rect" ]]; do
    shift;
    krect="$1"; shift # "@" for old, "+" for new, "=" for predicted.
    trect="$1"; shift # Hour of rectangle center.
    prect="$1"; shift # Price of rectangle center.
    herr="$1"; shift  # Half-width of box (pixels).
    verr="$1"; shift  # Half-height of box (pixels).

    hrect=$(( ${hrect} + ${hshift} ))

    rect_cmds+=( `make_rect_cmds ${tshift} ${hshift} ${pmin} ${vbot} ${pmax} ${vtop} "${krect}" ${trect} ${prect} ${herr} ${verr}` )
  done
  echo "rect_cmds=( " "${rect_cmds[@]}" " )" 1>&2

  # Trend lines:
  line_cmds=( )
  while [[ "/$1" == "/-line" ]]; do
    shift;
    kline="$1"; shift # "@" for bad, "+" for new.
    tline1="$1"; shift # Hour of line start.
    pline1="$1"; shift # Price of line start.
    tline2="$1"; shift # Hour of line end.
    pline2="$1"; shift # Price of line end.

    if [[ "/${kline}" == "/@" ]]; then cline="#88664466" ; else cline="#ff550099" ; fi

    hline1=`tscale ${tshift} ${hshift} ${tline1}`
    vline1=`pscale ${pmin} ${vbot} ${pmax} ${vtop} ${pline1}`

    hline2=`tscale ${tshift} ${hshift} ${tline2}`
    vline2=`pscale ${pmin} ${vbot} ${pmax} ${vtop} ${pline2}`

    line_cmds+=( -strokewidth 3 -color "${cline}" )
    line_cmds+=( -S ${hline1} ${vline1} ${hline2} ${vline2} )
  done
  echo "line_cmds=( " "${line_cmds[@]}" " )" 1>&2

  # Decoration
  deco_cmds=( )
  while [[ "/$1" == "/-deco" ]]; do
    shift;
    hpdeco="$1"; shift # H-coordinate of deco (absolute, pixels).
    vpdeco="$1"; shift # V-coordinate of deco (absolute, pixels).
    hadeco="$1"; shift # H-alignment of deco.
    vadeco="$1"; shift # V-alignment of deco.
    imdeco="$1"; shift # Image name of deco.
    mgdeco="$1"; shift # Magnification factor of deco.

    hpdeco=$(( ${hpdeco} + ${hshift} ))

    deco_cmds+=( -I ${hpdeco} ${vpdeco} ${hadeco} ${vadeco} ${imdeco} ${mgdeco} )
  done
  echo "deco_cmds=( " "${deco_cmds[@]}" " )" 1>&2

  # Dots for Slumber Points:
  dot_cmds=( ) # Commands to draw dots at the slumber points and slumber times.
  if [[ "/$1" == "/-dots" ]]; then
    shift;

    vvolb="$1"; shift  # V-coordinate of volume plot baseline (absolute, pixels).
    vdino="$1"; shift  # V-coordinate of dinosaur baseline (absolute, pixels).
    vvolb_dot=${vvolb} # V-coordinate of Slumber Times dots.

    dots=( "$@" ) # hours and prices of "slumber points".

    dot_cmds+=( -strokewidth 20 )
    i=0
    while [[ ${i} -lt ${#dots[@]} ]]; do
      kdot="${dots[${i}]}"; # "@" for False Slumber Point, "+" for True.
      if [[ "/${kdot}" == "/@" ]]; then
        cdot="#88664466"
        idino="lignite-wp-edit-100.png"
      else
        cdot="#0077ff99"
        idino="albertosaurus-wp-edit-100.png"
      fi
      i=$(( ${i} + 1 ))

      tdot="${dots[${i}]}"; # Hour of dot.
      hdot=`tscale ${tshift} ${hshift} ${tdot}`
      i=$(( ${i} + 1 ))

      pdot="${dots[${i}]}"; # Price at dot.
      vdot=`pscale ${pmin} ${vbot} ${pmax} ${vtop} ${pdot}`
      i=$(( ${i} + 1 ))

      sdot="${dots[${i}]}"; # Slumber coeff {Vh/Vd*1000} of dot.
      i=$(( ${i} + 1 ))

      # Compute weight {wtdot} of dot from {Vh/Vd} ratio:
      sref=5.00; # Ratio {Vh/Vd} for {wtdot = 1/sqrt(e) = 0.607}.
      wtmin=0.10; # Min weight
      wtdot=`echo 's='"${sdot}"'; z=s/'"${sref}"'; if(z>80){z=80}; w=e(-0.5*z*z); m='"${wtmin}"'; if(w<m){w=m}; scale=3; w/1.0' | bc -lq`
      lwdot=`echo 'w='"${wtdot}"';r=32.0*sqrt(w); scale=2; r/1.0' | bc -lq`
      echo "sdot = ${sdot} wtdot = ${wtdot} dot diameter (pt) = ${lwdot}" 1>&2

      dot_cmds+=( -color "${cdot}" )
      dot_cmds+=( -strokewidth ${lwdot} -S ${hdot} ${vdot} )
      dot_cmds+=( -strokewidth 8 -S ${hdot} ${vvolb_dot} )

      if [[ ${dinos} -ne 0 ]]; then
        # Dinosaur decoration:
        # Compute a {wtdino = Vh/Vd/sref}, clipped at 1.0:
        wtdino=`echo 's='"${sdot}"'; z=0.5*s/'"${sref}"'; if(z>1.0){z=1.0}; m='"${wtmin}"'; if(z<m){z=m}; scale=3; z/1.0' | bc -lq`
        magdino=`echo 'w='"${wtdino}"'; r=0.55*sqrt(w); scale=2; r/1.0' | bc -lq`
        echo "dino magnification = ${magdino}" 1>&2

        dot_cmds+=( -I ${hdot} ${vdino} 0.5 1.0 ${idino} ${magdino} )
      fi
    done

  fi
  echo "dot_cmds=( " "${dot_cmds[@]}" " )" 1>&2

  set echo

  annotate-pic.sh \
      ${iimg}.png 16 Black Yellow \
      "${deco_cmds[@]}" \
      \
      "${labt_cmds[@]}" \
      \
      "${dot_cmds[@]}" \
      \
      "${rect_cmds[@]}" \
      \
      "${line_cmds[@]}" \
      \
    > ${oimg}-annotated.png
  gimp ${oimg}-annotated.png
}

# echo `pscale 3700 573  4800 111  4400`

# Bitstamp slumber dots are computed from Huobi's by the ratios
#   1 USD = 6.40 CNY for 2014-02-07 -- 2014-02-09
#   1 USD = 6.12 CNY for other days.

hscale_HUBI=( 1819 1789 )
hscale_BSTP=( 1819 1789 )

vscale_HUBI=( 3100  580  4600   97 )
vscale_BSTP=(  400  603   750  100 )

#   -deco 4088  88 0.5 0.5 germanodactylus-wp-edit-200.png 0.60 \
#   -deco 4088 368 0.5 0.5 ophthalmosaurus-wp-edit-200.png 0.60 \
#   -deco 4208 283 0.5 0.5 helix-wp-edit-200.png 0.60 \

if [[ ${hubi} -ne 0 ]]; then
  annot HUBI check \
    -hscale ${hscale_HUBI[@]} \
    -vscale ${vscale_HUBI[@]} \
    \
    -rect "@"   955  4510 8 8 \
    -rect "@"   979  4450 8 8 \
    -rect "@"  1028  4075 8 8 \
    -rect "@"  1051  3970 8 8 \
    -rect "@"  1075  3750 8 8 \
    -rect "@"  1099  3630 8 8 \
    -rect "@"  1123  3915 8 8 \
    -rect "@"  1147  3630 8 8 \
    -rect "@"  1171  3890 8 8 \
    -rect "@"  1195  3775 8 8 \
    -rect "@"  1219  3800 8 8 \
    -rect "@"  1243  3772 8 8 \
    -rect "@"  1267  3396 8 8 \
    -rect "@"  1291  3368 8 8 \
    -rect "@"  1315  3809 8 8 \
    -rect "@"  1339  3807 8 8 \
    -rect "@"  1363  3804 8 8 \
    -rect "@"  1387  3802 8 8 \
    -rect "@"  1387  2781 8 8 \
    -rect "@"  1411  3533 8 8 \
    -rect "@"  1435  3522 8 8 \
    -rect "@"  1459  3515 8 8 \
    -rect "@"  1483  3400 8 8 \
    -rect "@"  1507  3370 8 8 \
    -rect "@"  1531  4050 8 8 \
    -rect "@"  1555  3872 8 8 \
    -rect "@"  1579  3899 8 8 \
    -rect "@"  1603  3891 8 8 \
    -rect "@"  1627  3596 8 8 \
    -rect "@"  1651  3938 8 8 \
    -rect "@"  1675  4073 8 8 \
    -rect "@"  1675  3597 8 8 \
    -rect "@"  1699  3788 8 8 \
    -rect "@"  1723  3783 8 8 \
    -rect "@"  1747  3918 8 8 \
    \
    -rect "="  1843  3674 10 10 \
    \
    -line  "@"   871  4873    883  4780 \
    -line  "@"   883  4780    895  4704 \
    -line  "@"   895  4704    907  4642 \
    -line  "@"   907  4642    919  4592 \
    -line  "@"   919  4592    931  4552 \
    -line  "@"   931  4552    943  4519 \
    -line  "@"   943  4519    955  4492 \
    -line  "@"   955  4492    967  4470 \
    \
    -line  "@"   967  4077    979  4072 \
    -line  "@"   979  4072    991  4066 \
    -line  "@"   991  4066   1003  4060 \
    -line  "@"  1003  4060   1015  4053 \
    -line  "@"  1015  4053   1027  4044 \
    -line  "@"  1027  4044   1039  4035 \
    -line  "@"  1039  4035   1051  4025 \
    -line  "@"  1051  4025   1063  4013 \
    -line  "@"  1063  4013   1075  3999 \
    -line  "@"  1075  3999   1087  3983 \
    -line  "@"  1087  3983   1099  3966 \
    -line  "@"  1099  3966   1111  3946 \
    -line  "@"  1111  3946   1123  3923 \
    -line  "@"  1123  3923   1135  3897 \
    -line  "@"  1135  3897   1147  3868 \
    -line  "@"  1147  3868   1159  3835 \
    -line  "@"  1159  3835   1171  3797 \
    -line  "@"  1171  3797   1183  3754 \
    -line  "@"  1183  3754   1195  3705 \
    -line  "@"  1195  3705   1207  3650 \
    -line  "@"  1207  3650   1219  3587 \
    -line  "@"  1219  3587   1231  3516 \
    -line  "@"  1231  3516   1243  3434 \
    -line  "@"  1243  3434   1255  3342 \
    \
    -line  "@"  1279  3964   1351  3175 \
    \
    -line  "@"  1351  3567   1471  3415 \
    \
    -line  "@"  1495  4045   1507  4026 \
    -line  "@"  1507  4026   1519  4004 \
    -line  "@"  1519  4004   1531  3977 \
    -line  "@"  1531  3977   1543  3945 \
    -line  "@"  1543  3945   1555  3907 \
    -line  "@"  1555  3907   1567  3862 \
    -line  "@"  1567  3862   1579  3808 \
    -line  "@"  1579  3808   1591  3744 \
    -line  "@"  1591  3744   1603  3667 \
    -line  "@"  1603  3667   1615  3576 \
    \
    -line  "@"  1615  3788   1627  3791 \
    -line  "@"  1627  3791   1639  3794 \
    -line  "@"  1639  3794   1651  3799 \
    -line  "@"  1651  3799   1663  3807 \
    -line  "@"  1663  3807   1675  3817 \
    -line  "@"  1675  3817   1687  3831 \
    -line  "@"  1687  3831   1699  3852 \
    -line  "@"  1699  3852   1711  3880 \
    -line  "@"  1711  3880   1723  3921 \
    -line  "@"  1723  3921   1735  3979 \
    \
    -line  "+"  1783  3884   1855  3632 \
    \
    -dots 744 624 \
    "+"   475 5014   3.34 \
    "+"   499 5015   7.27 \
    "+"   523 4966   6.73 \
    "+"   547 4927   2.29 \
    "+"   571 4730   2.54 \
    "+"   595 4839   5.33 \
    "+"   619 5041   8.20 \
    "+"   643 4856  10.00 \
    "+"   667 4829   4.39 \
    "+"   691 4809   8.93 \
    "+"   715 4851   6.32 \
    "+"   739 4873   3.65 \
    "+"   763 4939   7.27 \
    "+"   787 4973   6.82 \
    "+"   811 4898   5.36 \
    "+"   835 4915  14.45 \
    "+"   859 4892  10.19 \
    "+"   883 4782   1.71 \
    "+"   907 4637   2.00 \
    "+"   931 4555   2.92 \
    "+"   955 4492   1.73 \
    "+"   979 4080   3.85 \
    "+"  1003 4139  36.35 \
    "+"  1027 4006   2.03 \
    "+"  1051 3876  20.17 \
    "+"  1075 4008   3.99 \
    "+"  1099 3961   3.21 \
    "+"  1123 3733  26.54 \
    "+"  1147 3905   3.84 \
    "+"  1171 3817   0.99 \
    "+"  1195 3832  17.90 \
    "+"  1219 3530   9.48 \
    "+"  1243 3425   2.36 \
    "+"  1267 3621  13.31 \
    "+"  1291 3810   2.38 \
    "+"  1315 3615   1.41 \
    "+"  1339 3284   2.52 \
    "+"  1363 3543   5.35 \
    "+"  1387 3533   1.63 \
    "+"  1411 3464   4.74 \
    "+"  1435 3479   1.33 \
    "+"  1459 3427   1.59 \
    "+"  1483 3825  51.14 \
    "+"  1507 4040   2.40 \
    "+"  1531 3956   0.88 \
    "+"  1555 3917   1.85 \
    "+"  1579 3802   8.58 \
    "+"  1603 3668   4.36 \
    "+"  1627 3803   4.65 \
    "+"  1651 3784   6.94 \
    "+"  1675 3802   3.71 \
    "+"  1699 3876   6.01 \
    "+"  1723 3918   2.26 \
    "+"  1747 3821   9.67 \
    "+"  1771 3844  12.09 \
    "+"  1795 3842   5.22 \
    "+"  1819 3758   1.48
fi

if [[ ${bstp} -ne 0 ]]; then
  annot BSTP check \
    -hscale ${hscale_BSTP[@]} \
    -vscale ${vscale_BSTP[@]} \
    \
    -rect "@"   955  700 8 8 \
    -rect "@"   979  690 8 8 \
    -rect "@"  1028  640 8 8 \
    -rect "@"  1051  650 8 8 \
    -rect "@"  1075  615 8 8 \
    -rect "@"  1099  600 8 8 \
    -rect "@"  1123  640 8 8 \
    -rect "@"  1147  590 8 8 \
    -rect "@"  1171  635 8 8 \
    -rect "@"  1195  615 8 8 \
    -rect "@"  1219  621 8 8 \
    -rect "@"  1243  616 8 8 \
    -rect "@"  1267  555 8 8 \
    -rect "@"  1291  550 8 8 \
    -rect "@"  1315  622 8 8 \
    -rect "@"  1339  622 8 8 \
    -rect "@"  1363  622 8 8 \
    -rect "@"  1387  621 8 8 \
    -rect "@"  1387  454 8 8 \
    -rect "@"  1411  577 8 8 \
    -rect "@"  1435  575 8 8 \
    -rect "@"  1459  572 8 8 \
    -rect "@"  1483  556 8 8 \
    -rect "@"  1507  551 8 8 \
    -rect "@"  1531  663 8 8 \
    -rect "@"  1555  633 8 8 \
    -rect "@"  1579  637 8 8 \
    -rect "@"  1603  636 8 8 \
    -rect "@"  1627  588 8 8 \
    -rect "@"  1651  656 8 8 \
    -rect "@"  1675  679 8 8 \
    -rect "@"  1675  600 8 8 \
    -rect "@"  1699  631 8 8 \
    -rect "@"  1723  631 8 8 \
    -rect "@"  1747  640 8 8 \
    \
    -line  "@"   871   796    883   781 \
    -line  "@"   883   781    895   768 \
    \
    -line  "@"   895   768    895   735 \
    \
    -line  "@"   895   735    907   725 \
    -line  "@"   907   725    919   717 \
    -line  "@"   919   717    931   711 \
    -line  "@"   931   711    943   706 \
    -line  "@"   943   706    955   701 \
    -line  "@"   955   701    967   698 \
    \
    -line  "@"   967   698    967   677 \
    \
    -line  "@"   967   677    979   670 \
    -line  "@"   979   670    991   663 \
    -line  "@"   991   663   1003   658 \
    -line  "@"  1003   658   1015   654 \
    -line  "@"  1015   654   1027   651 \
    -line  "@"  1027   651   1039   649 \
    -line  "@"  1039   649   1051   646 \
    -line  "@"  1051   646   1063   644 \
    -line  "@"  1063   644   1075   643 \
    -line  "@"  1075   643   1087   642 \
    -line  "@"  1087   642   1099   641 \
    -line  "@"  1099   641   1111   640 \
    -line  "@"  1111   640   1123   640 \
    -line  "@"  1123   640   1135   639 \
    -line  "@"  1135   639   1147   639 \
    -line  "@"  1147   639   1159   638 \
    -line  "@"  1159   638   1171   638 \
    -line  "@"  1171   638   1183   638 \
    -line  "@"  1183   638   1195   638 \
    -line  "@"  1195   638   1207   638 \
    \
    -line  "@"  1279   648   1351   519 \
    \
    -line  "@"  1351   583   1471   558 \
    \
    -line  "@"  1495   682   1507   674 \
    -line  "@"  1507   674   1519   666 \
    -line  "@"  1519   666   1531   660 \
    -line  "@"  1531   660   1543   655 \
    -line  "@"  1543   655   1555   651 \
    -line  "@"  1555   651   1567   647 \
    -line  "@"  1567   647   1579   644 \
    -line  "@"  1579   644   1591   642 \
    -line  "@"  1591   642   1603   639 \
    -line  "@"  1603   639   1615   638 \
    -line  "@"  1615   638   1627   636 \
    -line  "@"  1627   636   1639   635 \
    -line  "@"  1639   635   1651   634 \
    -line  "@"  1651   634   1663   633 \
     \
    -line  "@"  1663   633   1663   621 \
     \
    -line  "@"  1663   621   1675   620 \
    -line  "@"  1675   620   1687   619 \
    \
    -line  "+"  1783   635   1855   593 \
    \
    -dots 744 624 \
    "+"   475  819   3.34 \
    "+"   499  819   7.27 \
    "+"   523  811   6.73 \
    "+"   547  805   2.29 \
    "+"   571  773   2.54 \
    "+"   595  791   5.33 \
    "+"   619  824   8.20 \
    "+"   643  793  10.00 \
    "+"   667  789   4.39 \
    "+"   691  786   8.93 \
    "+"   715  793   6.32 \
    "+"   739  796   3.65 \
    "+"   763  807   7.27 \
    "+"   787  813   6.82 \
    "+"   811  800   5.36 \
    "+"   835  803  14.45 \
    "+"   859  799  10.19 \
    "+"   883  781   1.71 \
    "+"   907  724   2.00 \
    "+"   931  711   2.92 \
    "+"   955  701   1.73 \
    "+"   979  666   3.85 \
    "+"  1003  676  36.35 \
    "+"  1027  654   2.03 \
    "+"  1051  633  20.17 \
    "+"  1075  655   3.99 \
    "+"  1099  647   3.21 \
    "+"  1123  610  26.54 \
    "+"  1147  638   3.84 \
    "+"  1171  624   0.99 \
    "+"  1195  626  17.90 \
    "+"  1219  577   9.48 \
    "+"  1243  560   2.36 \
    "+"  1267  592  13.31 \
    "+"  1291  623   2.38 \
    "+"  1315  591   1.41 \
    "+"  1339  537   2.52 \
    "+"  1363  579   5.35 \
    "+"  1387  577   1.63 \
    "+"  1411  566   4.74 \
    "+"  1435  568   1.33 \
    "+"  1459  560   1.59 \
    "+"  1483  625  51.14 \
    "+"  1507  673   2.40 \
    "+"  1531  659   0.88 \
    "+"  1555  653   1.85 \
    "+"  1579  634   8.58 \
    "+"  1603  611   4.36 \
    "+"  1627  634   4.65 \
    "+"  1651  631   6.94 \
    "+"  1675  621   3.71 \
    "+"  1699  633   6.01 \
    "+"  1723  640   2.26 \
    "+"  1747  624   9.67 \
    "+"  1771  628  12.09 \
    "+"  1795  628   5.22 \
    "+"  1819  614   1.48
fi

# gawk 'BEGIN { t0 = 1723; h0 = 4208; } /^ *$/ { print; next; } /^ *[-]?[0-9]+ *$/{ h = $1; t = t0 + (h - h0)/5; printf "%6d\n", t; next; } //{ printf "**bug [%s]\n", $0 > "/dev/stderr"; exit 1; }'




