#!/usr/bin/env perl
# Mirror a tabulated function wrt the x=0 axis
# Rok Zitko, rok.zitko@ijs.si, August 2009

use warnings;
use strict;

my @data;

while (<>) {
    if (/^#/) { next; }
    chomp;
    my @vals = split;
    push (@data, [@vals]);
}

my $nr = @data;

for (my $i = $nr-1; $i >= 0; $i--) {
    my $len = @{ $data[$i] };
    for (my $col = 0; $col < $len; $col++) {
	my $val = $data[$i]->[$col];
	if ($col == 0) {
	    $val = -$val;
	}
	print $val;
	if ($col != $len-1) { print " "; }
    }
    print "\n";
}

my $first = ($data[0]->[0] == 0 ? 1 : 0);

for (my $i = $first; $i < $nr; $i++) {
    my $len = @{ $data[$i] };
    for (my $col = 0; $col < $len; $col++) {
	my $val = $data[$i]->[$col];
	print $val;
	if ($col != $len-1) { print " "; }
    }
    print "\n";
}
