#!/usr/bin/perl -w
use warnings;
use strict;
use GD::Graph::bars;
#-----------------------------------
#Calculo de frecuencias
open(FILE,"$ARGV[0]") || die "File not found\n";
my ($file)= $ARGV[0] =~ /^(.*?)\_TE.txt*$/;
my @lines = <FILE>;
close(FILE);
my $c1 = 0; my $c2 = 0; my $c3 = 0; my $c4 = 0;
my $c5 = 0; my $c6 = 0; my $c7 = 0; my $c8 = 0;
my $c9 = 0; my $c10 = 0; my $c11 = 0; my $c12 = 0;
my $c13 = 0; my $c14 = 0; my $c15 = 0; my $c16 = 0;
my $c17 = 0; my $c18 = 0; my $c19 = 0; my $c20 = 0;
my $c21 = 0; my $c22 = 0; my $c23 = 0; my $c24 = 0;
my $c25 = 0; my $c26 = 0; my $c27 = 0; my $c28 = 0;
foreach my $line (@lines) {
my ($dG) = $line =~ /^.*?\s\d+\s+(\d+.\d+)\s.*$/;
#print "$dG\n ";
next if ! $dG;
my ($lnK) = ($dG)/-(1.9872*298.15);
#print "$lnK\n";
if ( $lnK < -26) { $c1++; }
if (-26 <= $lnK && $lnK < -25) {$c2++;}
if (-25 <= $lnK && $lnK < -24) {$c3++;}
if (-24 <= $lnK && $lnK < -23) {$c4++;}
if (-23 <= $lnK && $lnK < -22) {$c5++;}
if (-22 <= $lnK && $lnK < -21) {$c6++;}
if (-21 <= $lnK && $lnK < -20) {$c7++;}
if (-20 <= $lnK && $lnK < -19) {$c8++;}
if (-19 <= $lnK && $lnK < -18) {$c9++;}
if (-18 <= $lnK && $lnK < -17) {$c10++;}
if (-17 <= $lnK && $lnK < -16) {$c11++;}
if (-16 <= $lnK && $lnK < -15) {$c12++;}
if (-15 <= $lnK && $lnK < -14) {$c13++;}
if (-14 <= $lnK && $lnK < -13) {$c14++;}
if (-13 <= $lnK && $lnK < -12) {$c15++;}
if (-12 <= $lnK && $lnK < -11) {$c16++;}
if (-11 <= $lnK && $lnK < -10) {$c17++;}
if (-10 <= $lnK && $lnK < -9) {$c18++;}
if (-9 <= $lnK && $lnK < -8) {$c19++;}
if (-8 <= $lnK && $lnK < -7) {$c20++;}
if (-7 <= $lnK && $lnK < -6) {$c21++;}
if (-6 <= $lnK && $lnK < -5) {$c22++;}
if (-5 <= $lnK && $lnK < -4) {$c23++;}
if (-4 <= $lnK && $lnK < -3) {$c24++;}
if (-3 <= $lnK && $lnK < -2) {$c25++;}
if (-2 <= $lnK && $lnK < -1) {$c26++;}
if (-1 <= $lnK && $lnK < 0) {$c27++;}
if (0 <= $lnK ) {$c28++;}
}
# print "$c1,$c2,$c3,$c4,$c5,$c6,$c7,$c8,$c9,$c10,$c11,$c12,$c13,$c14,$c15,$c16,$c17,$c18,$c19,$c20,$c21,$c22,$c23,$c24,$c25,$c26,$c27,$c28\n";
#Generando gráfico Frecuencia vs lnK
my @freq2 = ($c1,$c2,$c3,$c4,$c5,$c6,$c7,$c8,
$c9,$c10,$c11,$c12,$c13,$c14,$c15,$c16,
$c17,$c18,$c19,$c20,$c21,$c22,$c23,$c24,
$c25,$c26,$c27,$c28);
my @lnK = ( '[<-26]','[-26,-25]','[-25,-24]','[-24,-23]','[-23,-22]','[-22,-21]','[-21,-20]','[-20,-19]','[-19,-18]','[-18,-17]','[-17,-16]','[-16,-15]','[-15,-14]','[-14,-13]','[-13,-12]','[-12,-11]','[-11,-10]','[-10,-9]','[-9,-8]','[-8,-7]','[-7,-6]','[-6,-5]','[-5,-4]','[-4,-3]','[-3,-2]','[-2,-1]','[-1,0]','[>=0]');
my @graf2 = (\@lnK, \@freq2);
my $grafico2 = GD::Graph::bars->new(1500, 400);
$grafico2->set_legend("$file" );
$grafico2->set(
x_label => 'lnK',
y_label => 'Frequency',
title => "$file",
# shadows
bar_spacing => 8,
shadow_depth => 4,
shadowclr => 'dred',
transparent => 0,
)
or warn $grafico2->error;
my $imagen2 = $grafico2->plot(\@graf2) or die $grafico2->error;
open (OUT, "> $file-lnK.png") or die "couldn't open histo_file.png: $!";
#print "Content-type: image/png\n\n";
print OUT $imagen2->png;
exit;