ATIMA-10
ATIMA perlƒ‰ƒbƒp


#!/usr/bin/perl

package atima;
#ATIMA wrapper
#-------------------------------------
#Usage:
#./atima.pl [name] [thickness] [Z] [Mass] [K]
#
# name : name of defined material by string
# thickness : thickness of material in mg/cm^2
# Z : Z of Projectile by integral
# Mass : Mass of Projectile in amu
# K : Kinetic Energy of Projectile in MeV/amu
#
# Materials should be defined in a file "Materials.STD"
# Format of definition -> see below (in Japanese)
# http://be.nucl.ap.titech.ac.jp/~kawada/sandbox/101.html
#-------------------------------------

use strict;
use warnings;
use List::Util;
use IO::File;



$atima::path_wrapper = "./Qj";
$atima::materials = "Materials.STD";
$atima::communica = "tele.dat";

my ($mName, $mThick, $zPa, $mPa, $ePa) = @ARGV;
if(!defined($ePa)){die "required 5 parameters!\n";}
my @pack = ();
my @com = (2,1.0,41.8,4.0026);
push @pack, \@com;

my $mat = &readMaterials;
my ($nNucl, $component, $density, $fntp, $iGas, $GIp);
unless(&arrayexists($mName, keys(%$mat))){
die "Material \"$mName\" isn't defined!!\n";
}else{
($nNucl, $component, $density, $fntp, $iGas, $GIp) = @{${$mat}{$mName}};
}

#print join("\n",keys(%$mat));

#Pb + HeGas for Testing
#&execATIMA(82.0,82,206.976,1,\@pack,0.0001785,1.0,0.0,10.0);

&execATIMA($ePa, $zPa, $mPa, $nNucl, $component,
$density, $iGas, $fntp, $mThick);


sub execATIMA{
my ($en, $Zpa, $Mpa, $nNucl, $components,
$density, $iGas, $fntpa, $thick) = @_;

my @output = ();

push @output, sprintf("%15.6e\n",$en);
push @output, sprintf("%5d%15.6e\n",$Zpa,$Mpa);
push @output, sprintf("%4d\n",$nNucl);
foreach my $a (keys(%$components)){
my ($Za, $stnr, $IV, $Ma) = @{${$components}{$a}};
push @output,
sprintf("%4d%15.6e%15.6e%15.6e\n",$Za,$stnr,$IV,$Ma);
}
push @output, sprintf("%15.6e%3d%15.6e\n",$density,$iGas,$fntpa);
push @output, sprintf("%15.6e\n",$thick);

my $io = IO::File->new();
$io->open($atima::communica, "w") or die "$!\n";
$io->print(@output);
$io->close;

print `$atima::path_wrapper`;
}


sub readMaterials{
my $io = IO::File->new();
$io->open($atima::materials,"r") or die "$!\n";
my @material = $io->getlines;
$io->close;

my %material = ();

shift @material; shift @material; shift @material;

map{s/^[\s]+//; s/[\s]+/ /g;} @material;
while(my $line = shift @material){
my $name;
if($line=~m/([A-Za-z0-9]+)/){$name = $+;}
my $components = shift @material;
$components =~s/[\s]+//g;
my %component = ();
map{
my $cName = shift @material;
$cName =~s/[\s]+//g;
my ($Z, $M, $stnr, $Ip) = split(/[\s]+/,shift @material);
my @a = ($Z, $stnr, $Ip, $M);
$component{$cName} = \@a;
}1..$components;
my ($density, $fntp, $iGas) = split(/[\s]+/,shift @material);
my $GIp = shift @material;
$GIp =~s/[\s]+//g;

my @b = ($components, \%component, $density, $fntp, $iGas, $GIp);
$material{$name} = \@b;
}

return \%material;
}



sub arrayexists{
my ($key, @target) = @_;
map{
if($key eq $_){return 1;}
} @target;
return 0;
}