#!/usr/bin/perl -w

#
#	collect_data_v5.pl
#
#	Syntax:  collect_data_v5.pl <number of words to read> <output file1>
#
#	7 January 2010 v5:	Change output
# 		Each line of values should look something like this:
# 		10 20 30 40 50 60 70 80 90 1000 1100 1200 1300 1400 1500 1600
# 		
#		The output file needs to be written like this:
# 		10	50	90	1300
# 		20	60	100	1400
# 		30	70	110	1500
# 		40	80	120	1600
#		This v5 is basically just going to run on the output of the v4 program
#
#	7 December 2009 v4: Add input variable to allow specifying which slot to use
#
#	2008 v3: Put board to sleep for a bit at beginning
#
#	6 March 2008 v2: Change to accept the number of words to read
#			on the command line.  Then, issue one write/read
#			command, read the buffers, then issue one more
#			write/read command.
#
#	15 Oct 2007 v1:	Starts a vme write command, then
#			waits for buffer to be full and then
#			reads the buffer, converts to decimal
#			and writes it to a file.  This process
#			can be repeated a number of times.
#			

# Check that have the correct number of strings on the input line
if ($#ARGV != 1)
{
	print "Usage:  collect_data_v5.pl <input file> <output file>\n";
	exit(1);
}

# Get the filenames
$input = $ARGV[0];
$output = $ARGV[1];

open (INFILE, "$input");
open (OUTFILE, ">$output");


# Each line of values should look something like this:
# 10 20 30 40 50 60 70 80 90 1000 1100 1200 1300 1400 1500 1600

# The output file needs to be written like this:
#
# 10	50		90		1300
# 20	60		100		1400
# 30	70		110		1500
# 40	80		120		1600

while ($value=<INFILE>)
{
	chop $value;
 	my @a = split(" ",$value);
	print OUTFILE "$a[0]\t$a[4]\t$a[8]\t$a[12]\n";
	print OUTFILE "$a[1]\t$a[5]\t$a[9]\t$a[13]\n";
	print OUTFILE "$a[2]\t$a[6]\t$a[10]\t$a[14]\n";
	print OUTFILE "$a[3]\t$a[7]\t$a[11]\t$a[15]\n";
}	

close INFILE;
close OUTFILE;

