/
plot.pl
executable file
·90 lines (81 loc) · 2.19 KB
/
plot.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
#!/usr/bin/perl
use strict;
use warnings;
use lib 'lib';
use ReadMatrix qw(real_matrix);
use Data::Dumper;
use Getopt::Long;
use 5.010;
GetOptions("upto=s" => \my $upto)
or warn "some of these options look wrong\n";
my @x;
my @d;
my $isfirst = 1;
for my $d (@ARGV) {
my $number;
if ($d =~ m/(\d+)/) {
$number = $1;
} else {
die "Don't know what to do with $d (doesn't contain a number)";
}
my @files = glob "data/$number/*.dat" or die "No files in `data/$number/*'";
my $i = 0;
for my $fn (@files) {
$fn =~ /(energy|alpha|phi|scale)([\d.]+)\.dat/ or die "can't work with file name `$fn'";
state $what //= $1;
my $datapoint = $2;
if ($what ne $1) {
die "Can't mix different variables on the X axis ($what vs. $1)";
}
if (defined($upto) && ($upto < $datapoint)) {
last;
}
my $m = tpq_for_file($fn);
if ($isfirst) {
push @x, $datapoint;
} else {
if (abs($x[$i]-$datapoint) > 1e5) {
die "Can't merge datasets with different X axes\n"
. " for the ${i}th set I expected $x[$i] and got $datapoint";
}
}
my $agg = 0;
if ($d =~ /uu/) {
$agg += $m->[0][2];
} elsif ($d =~ /dd/) {
$agg += $m->[1][3];
} elsif ($d =~ /ud/) {
$agg += $m->[1][2];
} elsif ($d =~ /du/ ) {
$agg += $m->[0][3];
} elsif ($d =~ /diff/) {
$agg += $m->[0][2] - $m->[1][3];
} elsif ($d =~ /rel/) {
$agg += ($m->[0][2] - $m->[1][3]) / (($m->[0][2] + $m->[1][3]) || 1);
}
push @{$d[$i]}, $agg;
} continue {
$i++;
}
$isfirst = 0;
}
use Data::Dumper;
#print Dumper \@x;
#print Dumper \@d;
for my $i (0..$#x) {
say $x[$i], ' ', join(' ', @{$d[$i]});
}
sub tpq_for_file {
my $fn = shift;
open my $handle, '<', $fn or die "Can't open file `$fn' for reading: $!";
my $m;
while (<$handle>) {
if (/^final tpq/) {
$m = real_matrix($_);
last;
}
}
close $handle or warn $!;
return $m;
}
# vim: sw=4 ts=4 expandtab