#!/usr/bin/perl -w

use strict;

sub usage{
    print "./FlowInit.pl -s<cube_size> -i<number of cells along x coordinate> -j<number of cells along j coordinate> -k<number of cells along z coordinate> -t<max_type_number> -o<pif filename> -g<gap size>"
}

my $i_max=0;
my $j_max=0;
my $k_max=0;

my $sq_size=3;

my $i=0;
my $j=0;
my $k=0;

my $x_0=0;
my $y_0=0;
my $z_0=0;
my $gap=0;
my $type_max=1;


my $filename="flow_square.pif";
my @typeName=qw(Fluid) ; #type name array

    foreach(@ARGV){
	    if(/^-s(.+)/){$sq_size=$1;}
	    if(/^-g(.+)/){$gap=$1;}
            if(/^-i(.+)/){$i_max=$1;}
	    if(/^-j(.+)/){$j_max=$1;}
	    if(/^-k(.+)/){$k_max=$1;}
	    if(/^-t(.+)/){$type_max=$1;}
	    if(/^-o(.+)/){$filename=$1;}
	    if(/^--help/)
	    {
		usage();
		exit(0);
	    }
	    
    }

open(FILE,">$filename");

my $cell_counter=0;
my $cell_type=1;

my $x_min=0;
my $y_min=0;
my $z_min=0;

my $x_max=0;
my $y_max=0;
my $z_max=0;



for($i=0 ; $i<$i_max; ++$i){
    for($j=0 ; $j<$j_max; ++$j){
	for($k=0 ; $k<$k_max; ++$k){
    
	    $x_min=$x_0+$i*($sq_size+$gap);
	    $y_min=$y_0+$j*($sq_size+$gap);
	    $z_min=$z_0+$k*($sq_size+$gap);
	    $x_max=$x_min+$sq_size;
	    $y_max=$y_min+$sq_size;
	    $z_max=$z_min+$sq_size;
	    print "i=$i j=$j k=$k\n";	    	
	    #print FILE "$cell_counter ".eval(1+int(rand($type_max)))." $x_min $x_max $y_min $y_max $z_min $z_max \n";
	    print FILE "$cell_counter ".$typeName[0]." $x_min $x_max $y_min $y_max $z_min $z_max \n";
	    ++$cell_counter;
	    
	}
    }
}
print "x_dim=".($x_max+2)." y_dim=".($y_max+2)." z_dim=".$z_max."\n";