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




my $in = shift(@ARGV);
my $out = shift(@ARGV);

$| = 1;


if(!$in || !$out)	{
	print STDERR "Usage: $0 parameter_file outout_directory\n";
	exit(1);
	}

mkdir($out, 0775);

open(I, $in) or die "No open $in\n";

chdir($out) or die "No chdir $out\n";

my $nmax = 0;
my $c = 0;

while(<I>)	{
	s/(^| )#.*//;
	next if(m/^\s*$/);

	my @a = split(' ', $_);
	my $n = $#a + 1;
	if($n > $nmax)	{ $nmax = $n;}
	elsif($n < $nmax)	{
		print STDERR "#WARN: n<nmax at $.\n";
		next;
		}

	my $i;
	for($i=0; $i<$n; $i++)	{
		open(X, ">>$i") or die "no open $i at $.\n";
		print X $a[$i] . "\n";
		close(X);
		}
	if($c++%30 == 0)	{
		print STDERR $c . " ";
		}
	}
print STDERR "\n";
