#!/usr/bin/perl

BEGIN {
#use lib 'd:/Programs/Perl/lib';
#use lib '/home/tkamiya/bin/lib';
my $BaseDir = $ENV{'TkPerlDir'};
#print "\nBaseDir: $BaseDir\n";
@INC = ("$BaseDir/lib", "$BaseDir/VNL", "d:/Programs/Perl/lib", @INC);
}

use strict;

use Utils;

	my $DataDir = ".";
	my $fmask = Deps::MakePath($DataDir, "*.struct");
	my ($StructFile) = glob($fmask);
	unless($StructFile) {
		print("Struct file is not found.\n");
		return 0;
	}
	my ($drive, $directory, $filename, $ext, $lastdir, $filebody) = Deps::SplitFilePath($StructFile);
	my $OutFile = "$filebody.bxsf";
	my $Title   = $filebody;

	my $KListPath = "$filebody.klist";
	my $div = 60;
	my ($nx, $ny, $nz) = (10, 10, 10);
	my ($emin, $emax) = (-2.0, 1.5);
	
	open(OUT, ">$KListPath") or die "$!: Can not write to [$KListPath]\n";

	my $count = 1;
	my $BandName = "";
	for(my $ix = 0 ; $ix <= $nx ; $ix++) {
		for(my $iy = 0 ; $iy <= $ny ; $iy++) {
			for(my $iz = 0 ; $iz <= $nz ; $iz++) {
				if($iz == 0) {
					$BandName = sprintf("B%02d%02d", $ix+1, $iy+1);
				}
				else {
					$BandName = "";
				}

				my $x = $div * $ix / 2 / $nx;
				my $y = $div * $iy / 2 / $ny;
				my $z = $div * $iz / 2 / $nz;
				if($count == 1) {
					printf(OUT "%5s       %3d  %3d  %3d  %3d%4.1f %4.1f %4.1f\n",
						$BandName, $x, $y, $z, $div, 1.0, $emin, $emax);
				}
				else {
					printf(OUT "%5s       %3d  %3d  %3d  %3d%4.1f\n",
						$BandName, $x, $y, $z, $div, 1.0);
				}
				$count++;
			}
		}
	}
	printf(OUT "END\n\n");
	close(OUT);
	exit;
