#! /bin/bash
# Last edited on 2014-07-04 14:44:07 by stolfilocal

# Show the time intervals spanned by datafiles.
# Arguments 
# 
#   {DIR} {EX} {CUR} {TINT} {TITLE} {PINIDATE} {PFINDATE}
# 
# where 
# 
#   {DIR} is the dierctory containing the files.
#   {EX} is the exchaneg code, e.g. "BSTP".
#   {CUR} is the currency code, e.g. "USD", "CNY".
#   {TINT} is sampling time interval, e.g. "01h", "01d", etc.
#   {TITLE} is a title for the plot.
#   {PINIDATE} {PFINDATE} are the X-axis range end in the format "{yyyy}-{mm}-{dd}".
# 
# The plot (a PNG image) is written to {stdout}.

dir="$1"; shift
ex="$1"; shift
cur="$1"; shift
tint="$1"; shift
title="$1"; shift
pinidate="$1"; shift
pfindate="$1"; shift

show=SHOW
tmp="/tmp/$$"

( cd ${dir} && ls 20*--20*-${ex}-${cur}-${tint}.txt ) \
  | sed -e 's:[.]txt::' -e 's:[-]: :g' \
  | gawk  '/^20*/ { printf "%s-%s-%s 00:00:00 %s-%s-%s 00:00:00 %s %s %s\n", $1,$2,$3, $4,$5,$6, $7, $8, $9; } ' \
  > ${tmp}.dat

cat ${tmp}.dat 1>&2

${HOME}/projects/bitcoin/00-DATA/plot_time_intervals.sh \
    ${show} \
    "${title}" "${pinidate}" "${pfindate}" \
    ${tmp}.dat "${tint}"
