#!/usr/bin/perl

# perl/widenbursts: part of meabench, an MEA recording and analysis tool
# Copyright (C) 2000-2002  Daniel Wagenaar (wagenaar@caltech.edu)
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA



sub usage {
  print STDERR <<"EOF";
Usage: widenbursts extrapretime_s extraposttime_s

Reads a burst file (as created by findburst) from stdin, and widens
each burst by extrapretime_s seconds at the beginning, and
extraposttime_s at the end. Output is written to stdout in the format
as per findburst.
EOF
  exit(1);
}

usage() unless 2==scalar@ARGV;

$dtpre = shift @ARGV;
$dtpost = shift @ARGV;

while (<>) {
  chomp;
  s/^ +//; s/ +$//;
  ($t, $dt, @rest) = split;
  $t -= $dtpre;
  $dt += $dtpost+$dtpre;
  if ($t<0) {
    $dt += $t;
    $t = 0;
  }
  print "$t $dt ",join(" ",@rest),"\n";
}
