
# Look at a bunch of bargraph files and figure out the max amongst them all.
# Usage: getmax file file file....
#
# Hacked into existence by Larry McVoy (lm@sun.com now lm@sgi.com).
# Copyright (c) 1994 Larry McVoy.  GPLed software.
# $Id: getmax,v 1.4 1995/09/01 01:23:35 lm Exp $

eval "exec perl -Ss $0 $*"
	if 0;

$max_X = $max_Y = -1000000000;
$min_X = $min_Y = 1000000000;
foreach $file (@ARGV) {
	open(FD, $file);
	while (<FD>) {
		next if /^"/;
		next if /^%/;
		next if /^\s*$/;
		split;
		$min_X = $_[0] if ($_[0] < $min_X);
		$min_Y = $_[1] if ($_[1] < $min_Y);
		$max_X = $_[0] if ($_[0] > $max_X);
		$max_Y = $_[1] if ($_[1] > $max_Y);
	}
	close(FD);
}
$max_X /= 2 if ($half);
foreach $file (@ARGV) {
	open(FD, $file);
	@lines = <FD>;
	open(FD, ">$file") || die "Can't open $file\n";
	if ($graph) {
		print FD "\"%fakemin-X $min_X\n";
		print FD "\"%fakemin-Y $min_Y\n";
		print FD "\"%fakemax-X $max_X\n";
		print FD "\"%fakemax-Y $max_Y\n";
		print FD @lines;
		warn "Max X is $max_X\n" if $v;
		warn "Max Y is $max_Y\n" if $v;
	} else {
		print FD @lines;
		print FD "%fakemax $max_X\n";
		warn "Max X is $max_X\n" if $v;
	}
	close(FD);
}
exit 0;
