2 # This is gnucap2gnuplot, which is Copyright 2004 Ian Jackson.
3 # It's a script to postprocess the output from gnucap and then run gnuplot.
5 # gnucap2gnuplot and its documentation are free software; you can
6 # redistribute them and/or modify them under the terms of the GNU
7 # General Public License as published by the Free Software Foundation;
8 # either version 2, or (at your option) any later version.
10 # gnucap2gnuplot and its documentation are distributed in the hope that
11 # they will be useful, but WITHOUT ANY WARRANTY; without even the
12 # implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
13 # PURPOSE. See the GNU General Public License for more details.
15 # You should have received a copy of the GNU General Public License along
16 # with this program; if not, write to the Free Software Foundation, Inc.,
17 # 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20 # gnucap2gnuplot [<options>] input-file
22 # Input file should be a .cir file (will be put through gnucap)
23 # or an output file from gnucap.
25 # Produces various output files:
26 # <input-file>.gnuplots.sh run this to display results
27 # <input-file>,<Kind><N>.gnuplot-cmd gnuplot script for displaying:
28 # <input-file>,<Kind><N>-<M>.gnuplot-data gnuplot-format input data
29 # <input-file>,gnuplot-fifo working fifo for .gnuplots.sh
31 # <Kind> is Freq or Time (according to the type of analysis)
32 # <N> is the count, starting at 0, of which report this is from gnucap
33 # <M> is the individual column of Y data
36 # -g do run gnucap ) default is run gnucap
37 # -G don't run gnucap ) if input file ends in .cir
38 # -o<prefix> use <prefix> instead of <input-file> in output filenames
39 # If the input file is `-' then you may not specify -g and must use -o.
43 # Only Freq (.AC) and Time (.TRAN) plots have been tested. If
44 # other types go wrong they can probably be fixed by adding code for
45 # them to startplot().
47 # Displaying voltages and currents on the same .TRAN graph won't work
48 # well because they currently have to have the same Y scale. This
49 # could be fixed by assigning carefully to $mmm in startplot().
53 # There's no easy way to mess with the gnuplot settings.
55 sub fail ($) { die "gnucap2gnuplot: $_[0]\n"; }
57 while ($ARGV[0] =~ m/^\-./) {
64 } elsif (m/^\-o(.+)$/) {
67 fail("unknown option $_\n");
72 @ARGV==1 or fail("one input file only please");
74 $ofb= $if unless defined $ofb;
75 $rungnucap= $if =~ m/\.cir$/i unless defined $rungnucap;
76 open STDIN, $rungnucap ? "gnucap -b $if |" : "< $if"
77 or fail("open $if: $!");
79 fail("cannot run gnucap on stdin, run it yourself") if $rungnucap;
80 fail("you must specify -o... when running from stdin") unless defined $ofb;
83 %facttimes= qw(f 1e-15
93 $sof= "$ofb.gnuplots.sh";
94 open A, "> $sof" or die $!;
95 system 'chmod','+x',"$sof"; $? and die $?;
105 open S, "> $ofb,$cplot.gnuplot-cmd" or die $!;
107 set data style linespoints
113 for ($yn=1; $yn<=$#columns; $yn++) {
118 if ($kind eq 'Freq') {
119 for ($yn=1; $yn<=$#columns; $yn++) {
120 die unless $columns[$yn] =~ m/.*([MP])\(\d+\)$/;
121 $mmm[$yn]= 'y2' if $1 eq 'P';
123 print S "set logscale xy\n" or die $!;
125 for ($yn=1; $yn<=$#columns; $yn++) {
126 open "O$yn", "> $ofb,$cplot-$yn.gnuplot-data" or die $!;
130 return unless defined $kind;
131 foreach $mmm (keys %min) {
132 print S "set ${mmm}range [$min{$mmm}:$max{$mmm}]\n" or die $!;
135 for ($yn=1; $yn<=$#columns; $yn++) {
136 close "O$yn" or die $!;
137 $mmm[$yn] =~ m/^y2?$/ or die "$mmm[$yn]";
138 $axes= $mmm[$yn]; $axes =~ s/^y$/y1/;
141 " '$ofb,$cplot-$yn.gnuplot-data'".
142 " axes x1$axes title '$columns[$yn]'"
146 print S "\n\npause -1\n" or die $!;
148 print A " gnuplot $ofb,$cplot.gnuplot-cmd <\$fi &\n" or die $!;
157 @columns= split /\s+/;
158 $cplot= $kind.($counter{$kind}++);
161 } elsif (!defined $kind) {
164 @numbers= split /\s+/;
165 die unless @numbers == @columns;
166 for ($yn=0; $yn<=$#columns; $yn++) {
168 if (m/^(\-?\d+\.\d*)([A-Za-z]+)$/) {
169 die "factor $2" unless exists $facttimes{$2};
170 $_= $1*$facttimes{$2};
174 $min{$mmm}= $_ unless exists($min{$mmm}) && $min{$mmm} <= $_;
175 $max{$mmm}= $_ unless exists($max{$mmm}) && $max{$mmm} >= $_;
177 printf {"O$yn"} "%s %s\n", $numbers[0], $_
185 die "no plots" unless defined $kind;
189 printf 'hit return to quit: '
195 $?=0; close STDIN; $? and fail("gnucap failed (code $?)");
196 $sof= "./$sof" unless $sof =~ m,/,;
197 print ": generated ; $sof\n" or die $!;
199 # $Id: gnucap2gnuplot,v 1.2 2004-03-23 23:03:06 ianmdlvl Exp $