#!/usr/bin/perl

# fix-phase.pl
# Read STDIN, take reciprocal if phase > 0.5, and print to STDOUT

# Copyright 2012 John Ackermann   Version: 8 Sep. 2012
# May be freely used provided these notices are retained, and a copy
# of any modified version that's distributed to third persons is sent
# to jra@febo.com

while ($reading=<STDIN>) {

	if (substr($reading,0,1) =~ "[0-9]") {
		($x,$y) = split(/\s/,$reading);
		if ($y >0.5) { 
			$y = 0 - (1 - $y);
			$y = sprintf("%1.*e",9,$y)
			}
		print $x," ",$y,"\n";
	}
	else {
		print $reading;
	}
}

exit 0;
