#!/usr/bin/perl

# ----------------------------------------------------------------
# John Kerl
# kerl.john.r@gmail.com
# 2005-06-28
# ----------------------------------------------------------------

# Setup information:
# (1) Obtain my PMATLIB.pm;
# (2) Put PMATLIB.pm somewhere, e.g. the $HOME/bin directory;
# (3) Include that directory in the PERLLIB environment variable.
#     For bash, if PERLLIB exists:         export PERLLIB=$HOME/bin
#     For bash, if PERLLIB does not exist: export PERLLIB=$PERLLIB:$HOME/bin
#     For csh, if PERLLIB exists:          setenv PERLLIB $HOME/bin
#     For csh, if PERLLIB does not exist:  setenv PERLLIB ${PERLLIB}:$HOME/bin
use PMATLIB;

$compute_column_rank = 0;

while (@ARGV) {
	last unless $ARGV[0] =~ m/^-/;

	if (pmatlib_opt(\@ARGV)) {
		;
	}
	elsif ($ARGV[0] eq "-col") {
		$compute_column_rank = 1;
		shift @ARGV;
	}
	else {
		usage();
	}
}

if (@ARGV > 1) {
	usage();
}

@A   = (); $nr = 0; $nc = 0; 

read_matrix(\@A, \$nr, \$nc, $ARGV[0]);
transpose_in_place(\@A, \$nr, \$nc) if $compute_column_rank;
$rank = get_rank(\@A, $nr, $nc);
print "$rank\n";

# ----------------------------------------------------------------
sub usage
{
	# xxx call pml stuff, and include -col.
	die
		"Usage: $0 [options] [input file name]\n" .
		"Options:\n" .
		"  -w:  specify field width\n" .
		"  -p:  specify number of decimal places\n" .
		"  -f:  use %f format\n" .
		"  -d:  use %d format\n";
}
