-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplot
More file actions
executable file
·131 lines (117 loc) · 4.73 KB
/
plot
File metadata and controls
executable file
·131 lines (117 loc) · 4.73 KB
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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
#! /usr/bin/perl
# plot file ... - a command line interface for gnuplot
# (c) R.G. Della Valle 1996
# Modified and adapted by S. Raugei 1997
if( $#ARGV<0 ){
print "plot a command line interface for gnuplot\n\n";
print "Usage: plot item ...\n\n";
print "Item: -pPrinter print (default: postscript)\n";
print " -tTime set visualization time\n";
print " (default 60 seconds)\n";
print " 'X,Y,...' set title for X, Y, plot\n";
print " min:max set range for X, then Y\n";
print " File read X,Y data from File\n";
print " x,y plot column y vs column x\n";
print " y plot column y vs column 1\n";
print " x,y1,y2,... plot y1 vs x, y2 vs x, ...\n\n";
print "Ranges of contiguous columns are represented as i-j.\n";
print "Column 0 stays for the number 0,1,2... of the data.\n";
print "Points are used for all columns by default. Lines or\n";
print "lines+points are specified by - or + signs in front\n";
print "of x (for all columns) or y (for that column only).\n";
print "Printer, title, X range and Y range must appear in\n";
print "the given order. Files and columns may be repeated.\n";
print "Files to be plotted accumulate and remain in effect\n";
print "for all sets of columns immediately following them.\n";
print "Unless redirected, plot's output is piped to gnuplot.\n";
exit;
}
# Variables:
# $hardcopy a valid gnuplot's set term for printing
# @f, $f list of files to be plotted, current file
# @c, $c list of column to be plotted, current column
# $DefStyle default style (for all columns)
# $ColStyle style for the current column only
# $comma used to format the output, is "" or ","
# @l used to split the list of columns
# If output is to a tyy then pipe all output through gnuplot
if( -t STDOUT ){ open( STDOUT, "| gnuplot" ) }
# Argument starts with -p, get printer name (default PostScript, 18pt font)
if( $ARGV[0] =~ /^[+-][ph](.*)/i ){
shift;
$hardcopy = ( $1 ? $1 : "postscript 'Times-Roman' 18")
}
# Argument starts with -t, set the time of vizualization
$time=60;
if( $ARGV[0] =~ /^[+-][t](.*)/i ){
shift;
$time = $1;
}
# If the first argument cannot be anything else, assume it is for titles
if( $ARGV[0] =~ /[,:;`'"?!@#&=%* (){}<>|^]/ &&
$ARGV[0] =~ /[^,:0-9.e+-]/i &&
$ARGV[0] =~ /^([^,]*),?([^,]*),?(.*)$/ ){
shift;
print "set xlabel '$1'\n";
print "set ylabel '$2'\n";
print "set title '$3'\n";
}
print "set zero 1.e-99\n";
# This is the main "plot" statement for gnuplot
print "plot ";
# The next two arguments migth be x and y ranges
if( $ARGV[0] =~ /^[0-9.e+-]*:[0-9.e+-]*$/i ){ print "[", shift, "] " }
if( $ARGV[0] =~ /^[0-9.e+-]*:[0-9.e+-]*$/i ){ print "[", shift, "] " }
# Main loop: all other arguments specify either columns or files
while ( $_ = shift ) {
if( /^[+-]?[0-9][0-9,+-]*$/ ){ &cols() }
else { &file() }
}
&flush();
# Make hardcopy (default PostScript, 18pt font) or pause for 30 seconds,
if( $hardcopy ){
print "\nset term $hardcopy\n";
print "set out 'hardcopy.tmp'\n";
print "replot\n";
print "!print -r hardcopy.tmp\n";
} else {
print "\n pause $time\n";
}
#----------------------------------------------------------------------------
# style(default) - return "lines" or "linespoints" if $_ starts in "-" or "+"
sub style {
if( s/^\-// ){ return "lines" }
elsif( s/^\+// ){ return "linespoints" }
# elsif( s/^\@// ){ return "impulses" }
else { return shift( @_ ) }
}
# cols() - add all column pairs and styles in $_ to @c column list
sub cols {
$DefStyle = &style("points"); # Get default style
s/^([1-9][0-9]*)$/1,$1/; # Turn y into 1,y
while( s/(\d+)-(\d+)/join(',',($1..$2))/e ){}; # Expand i-j ranges
@l = split(',+',$_); # Split at commas
foreach $_ ( @l[1..$#l] ){ # Loop on columns
$ColStyle = &style($DefStyle); # Get column style
push( @c, "$l[0]:$_ with $ColStyle" ); # Add x,y to @c
}
}
# file() - add file $_ to @f file list, flush @c and @l lists if both exist
sub file {
if( @f && @c ){ &flush() }
push( @f, $_ );
}
# flush() - plot all accumulated column pairs and files, and flush both lists
sub flush {
if( ! @c ){ push( @c, "1:2 with points" ) } # Default column pair
foreach $f ( @f ){ # For all files
foreach $c ( @c ){ # For all column pairs
$c =~ /^([0-9]+:[0-9]+)(.*)/; # Title is 'file column'
$t = "using $1 title '$f $1'$2"; # columns title style
print "$comma \\\n '$f' $t"; # file columns title style
$comma = ","; # Use "," after first plot
}
}
undef @f;
undef @c;
}