Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F79182234
test_cst_energy.pl
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Subscribers
None
File Metadata
Details
File Info
Storage
Attached
Created
Sun, Aug 25, 04:08
Size
973 B
Mime Type
text/x-perl
Expires
Tue, Aug 27, 04:08 (2 d)
Engine
blob
Format
Raw Data
Handle
20138393
Attached To
rAKA akantu
test_cst_energy.pl
View Options
#!/usr/bin/perl
use strict;
use feature "say";
sub mean {
my (@table) = @_;
my $sum = 0;
for (@table) { $sum += $_; }
return $sum/($#table + 1);
}
sub variance {
my ($mean, @table) = @_;
my $sum = 0;
for (@table) { $sum += ($_ - $mean)**2; }
return $sum/($#table + 1);
}
my $fh;
my @files = ();
my $filename = shift @ARGV;
my $tol = shift @ARGV;
open($fh, $filename) or die "Cannot open $filename";
my @file = <$fh>;
my @mesure = ();
my $nb_line = 0;
READ: for (@file) {
$nb_line++;
next READ if $nb_line == 1;
my @line = split /,/;
$line[$#line] =~ /([+-]?[0-9]+\.?[0-9]*([eE][+-]?[0-9]+)?)/;
push @mesure, $1;
}
close($fh);
my $mean = mean(@mesure);
my $std_devi = sqrt(variance($mean, @mesure));
if (($std_devi/$mean <= $tol)) {
say "Pass: Mean $mean (std devi $std_devi) -> ".($std_devi/$mean)." <= $tol";
exit 0;
} else {
say "FAIL: Mean $mean (std devi $std_devi) -> ".($std_devi/$mean)." > $tol";
exit 1;
}
Event Timeline
Log In to Comment