forked from rhdunn/rsynth
-
Notifications
You must be signed in to change notification settings - Fork 0
/
tracks
executable file
·82 lines (78 loc) · 1.41 KB
/
tracks
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
#!/usr/local/bin/perl -w
use strict;
use File::Temp qw(tempfile);
my $file = shift;
my $match = @ARGV ? shift : '^f';
open(my $dat,$file) || die "Cannot open $file:$!";
my @labels;
my $sym;
my $ymin = 75;
my $ymax = 95;
SCAN:
while (<$dat>)
{
if (s/^\s*#\s*//)
{
s/\s+$//;
my @lab = split(/\s+/,$_);
push(@labels,[@lab]);
# warn "Possible labels:@lab\n";
$sym = $lab[0] if @lab == 1;
}
else
{
# warn "Data:$_";
s/^\s+//;
s/\s+$//;
my @data = split(/\s+/,$_);
foreach my $lab (@labels)
{
if (@$lab == @data)
{
@labels = @$lab;
last SCAN;
}
}
die "$file:$.:No labels match @data\n";
}
}
my ($fh,$path) = tempfile();
my $lx = 0;
my $x = 0;
my $yp = $ymin;
while (<$dat>)
{
if (/^\s*#/)
{
if (/^\s*#\s+(\S+)\s*$/ && $1 ne $sym)
{
my $xp = ($x+$lx)/2;
printf $fh qq[set label "$sym" at %g,%g center rotate \n],$xp,$yp;
$lx = $x;
$sym = $1;
$yp += 5;
$yp = $ymin if $yp > $ymax;
}
}
else
{
$x++;
}
}
warn "Labels: @labels\n";
print $fh "set data style line\n";
my $i = 1;
my $sep = 'plot';
while (@labels)
{
my $lab = shift(@labels);
if ($lab =~ /$match/o)
{
print $fh qq[$sep "$file" using 0:$i title "$lab"];
$sep = ",\\\n ";
}
$i++;
}
print $fh "\n";
close($fh);
system('gnuplot',-title => "$file /$match/", '-persist',$path);