#!/usr/bin/perl
# $Id: get_Ea.pl,v 1.1 2006/03/28 13:27:45 skoch Exp $

use strict;
use warnings;
use AFM;

if (scalar(@ARGV) < 2)
{
    die "Not enougn parameters, Usage: get_Ea.pl \$rig \$test\n\n";
}

my $rig = $ARGV[0];
my $test = $ARGV[1];
&check_run($rig);

my $tempfile = $AFM::publicdir.'rig'.$rig.'/'.$rig.'test'.$test.'/iv/tempvariation';

my @list = `/bin/cat $tempfile`;
for (my $x = 0; $x < scalar(@list); $x++)
{
    chomp $list[$x];
}
my @Rlist = `/usr/local/bin/get_ASR_750 $rig $test`;

my @data = ();

for my $y (@list)
{
    for my $str (@Rlist)
    {
	if ($str =~ /^$y\s+/)
	{
	    $str =~ /\d+\s+[\d\.]+\s+[\d\.\-]+\s+([\d\.\-]+)\s+[\d\.\-]+\s+(\d+)/;
	    my $R = $1+0;
	    my $t = $2+0;
	    $t = 1000 / (273.15 + $t);
	    my $tt = 1/$R;
	    my $logR = log $tt;
	    my $st = "$t  $logR";
	    push @data, $st;
	}
    }
}

my $filn = '/tmp/get_Ea_'.$$;
open OUT, "> $filn" or die "Could not open temporary file $filn\n"; 
for my $str (@data)
{
    print OUT $str,"\n";
}
close OUT;

my $str = `/usr/local/bin/activation_energy < $filn`;
print $str;
unlink $filn;
