#!/usr/local/bin/perl -w

#OPC_fix.pl
#Processes OPC files specified at run time to line up output.
#Output goes to stdout.

$input_file = $ARGV[0];

unless (open(INPUT, $input_file))  {
	print STDOUT ("could not open input file = $input_file", "Error=$!\n")
}

$lines_to_pass = 10;

for($i=1; $i<= $lines_to_pass; $i++) {
	$record =<INPUT>;
	$record =~ tr/\015//;
        print STDOUT ($record);
}

@size = (18,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9);
while (<INPUT>) {
	$record = $_;
	chomp $record;
	$record =~ tr/\015//;
	@data = split /,/, $record;
	unless ($#size == $#data) {
		print STDOUT ("Data records and columns don't match")
	}
		
	for ($i=0; $i<= $#data; $i++)   {
		unless (defined $data[$i] )  {
			$data[$i] = ' ' x $size[$i];
		}
		else   {
			$temp = $data[$i];
			$cnt = $temp =~ tr/0-9//;
			$data[$i] = $data[$i].(" " x ($size[$i] - $cnt));
		}
		print STDOUT ($data[$i]);
	}
	print STDOUT ("\n");
}
	
