Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100755 91 lines (81 sloc) 2.24 kB
c045172 very basic plotting script
Moritz Lenz authored
1 #!/usr/bin/perl
2 use strict;
3 use warnings;
4 use lib 'lib';
5 use ReadMatrix qw(real_matrix);
6 use Data::Dumper;
e89a1a0 @moritz upto option for plot.pl
authored
7 use Getopt::Long;
3dbf655 [plot.pl] allow plotting of multiple datasets at once
Moritz Lenz authored
8 use 5.010;
c045172 very basic plotting script
Moritz Lenz authored
9
e89a1a0 @moritz upto option for plot.pl
authored
10 GetOptions("upto=s" => \my $upto)
11 or warn "some of these options look wrong\n";
12
3dbf655 [plot.pl] allow plotting of multiple datasets at once
Moritz Lenz authored
13 my @x;
14 my @d;
15 my $isfirst = 1;
16 for my $d (@ARGV) {
bb20c2d plot.pl takes list of up/down specs
Moritz Lenz authored
17 my $number;
18 if ($d =~ m/(\d+)/) {
19 $number = $1;
20 } else {
21 die "Don't know what to do with $d (doesn't contain a number)";
22 }
23
24 my @files = glob "data/$number/*.dat" or die "No files in `data/$number/*'";
c045172 very basic plotting script
Moritz Lenz authored
25
3dbf655 [plot.pl] allow plotting of multiple datasets at once
Moritz Lenz authored
26 my $i = 0;
27 for my $fn (@files) {
8658c9f @moritz [tex] more plots [spin] make scale configurable
authored
28 $fn =~ /(energy|alpha|phi|scale)([\d.]+)\.dat/ or die "can't work with file name `$fn'";
8768cd9 @moritz enable running/plotting over fermi energy
authored
29 state $what //= $1;
30 my $datapoint = $2;
31 if ($what ne $1) {
32 die "Can't mix different variables on the X axis ($what vs. $1)";
33 }
e89a1a0 @moritz upto option for plot.pl
authored
34 if (defined($upto) && ($upto < $datapoint)) {
35 last;
36 }
3dbf655 [plot.pl] allow plotting of multiple datasets at once
Moritz Lenz authored
37 my $m = tpq_for_file($fn);
38 if ($isfirst) {
8768cd9 @moritz enable running/plotting over fermi energy
authored
39 push @x, $datapoint;
3dbf655 [plot.pl] allow plotting of multiple datasets at once
Moritz Lenz authored
40 } else {
8768cd9 @moritz enable running/plotting over fermi energy
authored
41 if (abs($x[$i]-$datapoint) > 1e5) {
3dbf655 [plot.pl] allow plotting of multiple datasets at once
Moritz Lenz authored
42 die "Can't merge datasets with different X axes\n"
8768cd9 @moritz enable running/plotting over fermi energy
authored
43 . " for the ${i}th set I expected $x[$i] and got $datapoint";
3dbf655 [plot.pl] allow plotting of multiple datasets at once
Moritz Lenz authored
44 }
45 }
bb20c2d plot.pl takes list of up/down specs
Moritz Lenz authored
46 my $agg = 0;
9d6e5ed @moritz various fixes, updates, enhancements, changes
authored
47 if ($d =~ /uu/) {
8768cd9 @moritz enable running/plotting over fermi energy
authored
48 $agg += $m->[0][2];
9d6e5ed @moritz various fixes, updates, enhancements, changes
authored
49 } elsif ($d =~ /dd/) {
50 $agg += $m->[1][3];
51 } elsif ($d =~ /ud/) {
52 $agg += $m->[1][2];
53 } elsif ($d =~ /du/ ) {
8768cd9 @moritz enable running/plotting over fermi energy
authored
54 $agg += $m->[0][3];
9d6e5ed @moritz various fixes, updates, enhancements, changes
authored
55 } elsif ($d =~ /diff/) {
ef6449d @moritz make plotting variable parameterizable
authored
56 $agg += $m->[0][2] - $m->[1][3];
9d6e5ed @moritz various fixes, updates, enhancements, changes
authored
57 } elsif ($d =~ /rel/) {
8768cd9 @moritz enable running/plotting over fermi energy
authored
58 $agg += ($m->[0][2] - $m->[1][3]) / (($m->[0][2] + $m->[1][3]) || 1);
59 }
bb20c2d plot.pl takes list of up/down specs
Moritz Lenz authored
60 push @{$d[$i]}, $agg;
3dbf655 [plot.pl] allow plotting of multiple datasets at once
Moritz Lenz authored
61 } continue {
62 $i++;
63 }
64 $isfirst = 0;
65 }
66 use Data::Dumper;
67 #print Dumper \@x;
68 #print Dumper \@d;
69
70 for my $i (0..$#x) {
71 say $x[$i], ' ', join(' ', @{$d[$i]});
c045172 very basic plotting script
Moritz Lenz authored
72
73 }
74
75
76 sub tpq_for_file {
77 my $fn = shift;
78 open my $handle, '<', $fn or die "Can't open file `$fn' for reading: $!";
79 my $m;
80 while (<$handle>) {
81 if (/^final tpq/) {
82 $m = real_matrix($_);
83 last;
84 }
85 }
86 close $handle or warn $!;
87 return $m;
88 }
89
90 # vim: sw=4 ts=4 expandtab
Something went wrong with that request. Please try again.