#!/usr/bin/perl

#-- Takes a fission fragment yield data file as (A,Z,TKE,Yield)
#-- and infer the one-dimensional distributions Y(A), Y(Z), Y(TKE), <TKE>(A)

#-- IAEA, CRP on Prompt Fission Neutron Spectra of Actinides
#-- Jan. 2014

#-- ***** Same as yields.pl but for GEF yields output *****

#-- HOW TO USE: ./yieldsGEF.pl < inputFile > outputFile

my @YA   = ();
my @YZ   = ();
my @YTKE = ();

my $aveTKEvsA = ();

while (<>) {

	if (/\*/) { next; }
	($Z1,$Z2,$A1pre,$A2pre,$A1post,$A2post,$I1pre,$I2pre,$TKEpre,$TKEpost) = split;
		
	$YA[$A1pre]++;
	$YA[$A2pre]++;
	
	$YZ[$Z1]++;
	$YZ[$Z2]++;
	
	$YTKE[$TKEpre]++;

	$aveTKEvsA[$A1pre] += $TKEpre;
	$aveTKEvsA[$A2pre] += $TKEpre;
	
	
}

for ($i=50; $i<200; $i++) {
	if ($YA[$i]!=0) {
		$aveTKEvsA[$i] /= $YA[$i];
	}
}

#-- renormalize distributions

print "# Mass Yields Y(A)\n\n";

$sum=0;
foreach $s (@YA) { $sum +=$s; }
#print "$sum\n";
for ($i=50; $i<200; $i++) {
	printf "%3i %12.5e\n", $i, $YA[$i]/$sum*200;
}

print "\n# Charge Yields Y(Z)\n\n";

$sum=0;
foreach $s (@YZ) { $sum +=$s; }
for ($i=20; $i<80; $i++) {
	printf "%3i %12.5e\n", $i, $YZ[$i]/$sum*200;
}


print "\n# Total Kinetic Energy Yields Y(TKE)\n\n";

$sum=0;
foreach $s (@YTKE) { $sum +=$s; }
for ($i=100; $i<240; $i++) {
	printf "%3i %12.5e\n", $i, $YTKE[$i]/$sum*100;
}

print "\n# Average Total Kinetic Energy vs. Fragment Mass <TKE>(A)\n\n";

for ($i=70; $i<180; $i++) {
	printf "%3i %12.5e\n", $i, $aveTKEvsA[$i];
}




