From: ianmdlvl Date: Wed, 24 Mar 2004 23:53:41 +0000 (+0000) Subject: genspic X-Git-Tag: debian_version_4_0_99_0_6~10 X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ian/git?p=chiark-utils.git;a=commitdiff_plain;h=6e7c525d2d9e43a0132c1b59b75685a4bb4be018;ds=sidebyside genspic --- diff --git a/debian/changelog b/debian/changelog index 6e47097..5ff5150 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,5 +1,6 @@ chiark-utils (4.0.99.0.6) unstable; urgency=low + * gnucap2gnuplot split with new genspic intermediate format. * gnucap2gnuplot script. -- diff --git a/scripts/Makefile b/scripts/Makefile index 0d47c5f..9a465f0 100644 --- a/scripts/Makefile +++ b/scripts/Makefile @@ -21,7 +21,7 @@ include ../settings.make -SCRIPTS= palm-datebook-reminders gnucap2gnuplot +SCRIPTS= palm-datebook-reminders gnucap2genspic genspic2gnuplot MANPAGES1= palm-datebook-reminders CSCRIPTS= named-conf diff --git a/scripts/genspic2gnuplot b/scripts/genspic2gnuplot new file mode 100755 index 0000000..86df13e --- /dev/null +++ b/scripts/genspic2gnuplot @@ -0,0 +1,128 @@ +#!/usr/bin/perl +# genspic2gnuplot - Copyright 2004 Ian Jackson - see below +# +# Reads a `genspic' file on stdin. Takes exactly one arg, . +# +# Produces various output files: +# .gnuplots.sh run this to display results +# ,.gnuplot-cmd gnuplot script for displaying: +# ,-.gnuplot-data gnuplot-format input data +# ,gnuplot-fifo working fifo for .gnuplots.sh +# where +# is Freq or Time (according to the type of analysis) +# is the count, starting at 0, of which report this is from gnucap +# is the individual column of Y data +# +# Limitations +# +# There's no easy way to mess with the gnuplot settings. +# +# This whole scheme is very clumsy. There should be a driver program +# with command-line option parsing. + +# This program and its documentation are free software; you can +# redistribute them and/or modify them under the terms of the GNU +# General Public License as published by the Free Software Foundation; +# either version 2, or (at your option) any later version. +# +# This program and its documentation are distributed in the hope that +# they will be useful, but WITHOUT ANY WARRANTY; without even the +# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR +# PURPOSE. See the GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along +# with this program; if not, write to the Free Software Foundation, Inc., +# 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + +die unless @ARGV==1; +die if $ARGV[0] =~ m/^\-/; + +($ofb)= @ARGV; +$sof= "$ofb.gnuplots.sh"; +open A, "> $sof" or die $!; +system 'chmod','+x',"$sof"; $? and die $?; +print A <; +print STDERR ">$c< >@s<\n"; + if ($c eq 'S') { + ($cplot,$logy2,@columns) = @s; + unshift @columns, 'x:'; + @mmm= map { s/^(\w+)\:// or die; $1; } @columns; + open S, "> $ofb,$cplot.gnuplot-cmd" or die $!; + print S < $ofb,$cplot-$yn.gnuplot-data" or die $!; + } + } elsif ($c eq 'T') { + die unless @mmm; + die if @s; + foreach $mmm (keys %min) { + print S "set ${mmm}range [$min{$mmm}:$max{$mmm}]\n" or die $!; + } + $sep= "plot "; + for ($yn=1; $yn<=$#columns; $yn++) { + close "O$yn" or die $!; + $mmm[$yn] =~ m/^y2?$/ or die "$mmm[$yn]"; + $axes= $mmm[$yn]; $axes =~ s/^y$/y1/; + $yoff= 1-$yn; + print S "$sep\\\n". + " '$ofb,$cplot-$yn.gnuplot-data'". + " axes x1$axes title '$columns[$yn]'" + or die $!; + $sep= ','; + } + print S "\n\npause -1\n" or die $!; + close S or die $!; + print A " gnuplot $ofb,$cplot.gnuplot-cmd <\$fi &\n" or die $!; + @mmm=@columns=(); + } elsif ($c eq 'D') { + die unless @mmm; + @numbers= @s; +print STDERR "$#numbers $#columns.\n"; + die unless @numbers == @columns; + for ($yn=0; $yn<=$#columns; $yn++) { + $_= $numbers[$yn]; + $mmm= $mmm[$yn]; + $min{$mmm}= $_ unless exists($min{$mmm}) && $min{$mmm} <= $_; + $max{$mmm}= $_ unless exists($max{$mmm}) && $max{$mmm} >= $_; + if ($yn) { + printf {"O$yn"} "%s %s\n", $numbers[0], $_ + or die $!; + } + } + } elsif ($c eq 'F') { + last; + } else { + die; + } +} + +print A <\$fi +printf 'hit return to quit: ' +read +exec 3>&- +END + or die $!; +close A or die $!; + +print ": generated ; $sof\n" or die $!; + +# $Id: genspic2gnuplot,v 1.1 2004-03-24 23:53:41 ianmdlvl Exp $ diff --git a/scripts/gnucap2genspic b/scripts/gnucap2genspic new file mode 100755 index 0000000..d7eed1e --- /dev/null +++ b/scripts/gnucap2genspic @@ -0,0 +1,109 @@ +#!/usr/bin/perl +# gnucap2genspic - Copyright 2004 Ian Jackson - see below +# +# Reads the output from gnucap and outputs a `genspic' file +# for use with genspic2gnuplot. Takes no arguments or options. +# +# Limitations +# +# Only Freq (.AC) and Time (.TRAN) plots have been tested. If +# other types go wrong they can probably be fixed by adding code for +# them to startplot(). +# +# Displaying voltages and currents on the same .TRAN graph won't work +# well because they currently have to have the same Y scale. This +# could be fixed by assigning carefully to $mmm in startplot(). +# +# This whole scheme is very clumsy. There should be a driver program +# with command-line option parsing. + +# This program and its documentation are free software; you can +# redistribute them and/or modify them under the terms of the GNU +# General Public License as published by the Free Software Foundation; +# either version 2, or (at your option) any later version. +# +# This program and its documentation are distributed in the hope that +# they will be useful, but WITHOUT ANY WARRANTY; without even the +# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR +# PURPOSE. See the GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along +# with this program; if not, write to the Free Software Foundation, Inc., +# 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + +die if @ARGV; + +%facttimes= qw(f 1e-15 + p 1e-12 + n 1e-9 + u 1e-6 + m 1e-3 + K 1e3 + Meg 1e6 + G 1e9 + T 1e12); + +sub startplot () { + $logy2= 0; + for ($yn=1; $yn<=$#columns; $yn++) { + $mmm[$yn]= 'y'; + } + if ($kind eq 'Freq') { + $logy2= 1; + for ($yn=1; $yn<=$#columns; $yn++) { + die unless $columns[$yn] =~ m/.*([MP])\(\d+\)$/i; + $mmm[$yn]= 'y2' if uc $1 eq 'P'; + } + } + printf "S %s %d", $cplot, $logy2 or die $!; + for ($yn=1; $yn<=$#columns; $yn++) { + printf " %s:%s", $mmm[$yn], $columns[$yn] or die $!; + } + print "\n" or die $!; +} +sub endplot () { + return unless defined $kind; + print "T\n" or die $!; +} + +$readahead= ; +for (;;) { + $linesofar= $readahead; + for (;;) { + $readahead= ; + last unless $readahead =~ s/^\+//; + die unless length $linesofar; + $linesofar =~ s/\n$//; + $linesofar .= $readahead; + } + $_= $linesofar; + last unless length; + s/\s+$//; + + if (m/^\#(\w+)/) { + endplot(); + $kind= $1; + @columns= split /\s+/; + $cplot= $kind.($counter{$kind}++); + startplot(); + next; + } elsif (!defined $kind) { + next; + } elsif (s/^\s+//) { + @numbers= split /\s+/; + map { + if (m/^(\-?\d+\.\d*)([A-Za-z]+)$/) { + die "factor $2" unless exists $facttimes{$2}; + $_= $1*$facttimes{$2}; + } + } @numbers; + print "D @numbers\n" or die $!; + } else { + die "$_ ?"; + } +} +die "no plots" unless defined $kind; +endplot(); +print "F\n" or die $!; + +# $Id: gnucap2genspic,v 1.1 2004-03-24 23:53:41 ianmdlvl Exp $ diff --git a/scripts/gnucap2gnuplot b/scripts/gnucap2gnuplot index 7e97b49..d9fc711 100755 --- a/scripts/gnucap2gnuplot +++ b/scripts/gnucap2gnuplot @@ -1,56 +1,4 @@ #!/usr/bin/perl -# This is gnucap2gnuplot, which is Copyright 2004 Ian Jackson. -# It's a script to postprocess the output from gnucap and then run gnuplot. -# -# gnucap2gnuplot and its documentation are free software; you can -# redistribute them and/or modify them under the terms of the GNU -# General Public License as published by the Free Software Foundation; -# either version 2, or (at your option) any later version. -# -# gnucap2gnuplot and its documentation are distributed in the hope that -# they will be useful, but WITHOUT ANY WARRANTY; without even the -# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR -# PURPOSE. See the GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License along -# with this program; if not, write to the Free Software Foundation, Inc., -# 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - -# usage: -# gnucap2gnuplot [] input-file -# -# Input file should be a .cir file (will be put through gnucap) -# or an output file from gnucap. -# -# Produces various output files: -# .gnuplots.sh run this to display results -# ,.gnuplot-cmd gnuplot script for displaying: -# ,-.gnuplot-data gnuplot-format input data -# ,gnuplot-fifo working fifo for .gnuplots.sh -# where -# is Freq or Time (according to the type of analysis) -# is the count, starting at 0, of which report this is from gnucap -# is the individual column of Y data -# -# Options -# -g do run gnucap ) default is run gnucap -# -G don't run gnucap ) if input file ends in .cir -# -o use instead of in output filenames -# If the input file is `-' then you may not specify -g and must use -o. -# -# Limitations -# -# Only Freq (.AC) and Time (.TRAN) plots have been tested. If -# other types go wrong they can probably be fixed by adding code for -# them to startplot(). -# -# Displaying voltages and currents on the same .TRAN graph won't work -# well because they currently have to have the same Y scale. This -# could be fixed by assigning carefully to $mmm in startplot(). -# -# It's a bit clumsy. -# -# There's no easy way to mess with the gnuplot settings. sub fail ($) { die "gnucap2gnuplot: $_[0]\n"; } @@ -80,131 +28,6 @@ if (@ARGV) { fail("you must specify -o... when running from stdin") unless defined $ofb; } -%facttimes= qw(f 1e-15 - p 1e-12 - n 1e-9 - u 1e-6 - m 1e-3 - K 1e3 - Meg 1e6 - G 1e9 - T 1e12); - -$sof= "$ofb.gnuplots.sh"; -open A, "> $sof" or die $!; -system 'chmod','+x',"$sof"; $? and die $?; -print A < $ofb,$cplot.gnuplot-cmd" or die $!; - print S < $ofb,$cplot-$yn.gnuplot-data" or die $!; - } -} -sub endplot () { - return unless defined $kind; - foreach $mmm (keys %min) { - print S "set ${mmm}range [$min{$mmm}:$max{$mmm}]\n" or die $!; - } - $sep= "plot "; - for ($yn=1; $yn<=$#columns; $yn++) { - close "O$yn" or die $!; - $mmm[$yn] =~ m/^y2?$/ or die "$mmm[$yn]"; - $axes= $mmm[$yn]; $axes =~ s/^y$/y1/; - $yoff= 1-$yn; - print S "$sep\\\n". - " '$ofb,$cplot-$yn.gnuplot-data'". - " axes x1$axes title '$columns[$yn]'" - or die $!; - $sep= ','; - } - print S "\n\npause -1\n" or die $!; - close S or die $!; - print A " gnuplot $ofb,$cplot.gnuplot-cmd <\$fi &\n" or die $!; - $kind= undef; -} - -$readahead= ; -for (;;) { - $linesofar= $readahead; - for (;;) { - $readahead= ; - last unless $readahead =~ s/^\+//; - die unless length $linesofar; - $linesofar =~ s/\n$//; - $linesofar .= $readahead; - } - $_= $linesofar; - last unless length; - s/\s+$//; - - if (m/^\#(\w+)/) { - endplot(); - $kind= $1; - @columns= split /\s+/; - $cplot= $kind.($counter{$kind}++); - startplot(); - next; - } elsif (!defined $kind) { - next; - } elsif (s/^\s+//) { - @numbers= split /\s+/; - die unless @numbers == @columns; - for ($yn=0; $yn<=$#columns; $yn++) { - $_= $numbers[$yn]; - if (m/^(\-?\d+\.\d*)([A-Za-z]+)$/) { - die "factor $2" unless exists $facttimes{$2}; - $_= $1*$facttimes{$2}; - $numbers[$yn]= $_; - } - $mmm= $mmm[$yn]; - $min{$mmm}= $_ unless exists($min{$mmm}) && $min{$mmm} <= $_; - $max{$mmm}= $_ unless exists($max{$mmm}) && $max{$mmm} >= $_; - if ($yn) { - printf {"O$yn"} "%s %s\n", $numbers[0], $_ - or die $!; - } - } - } else { - die "$_ ?"; - } -} -die "no plots" unless defined $kind; -endplot(); -print A <\$fi -printf 'hit return to quit: ' -read -exec 3>&- -END - or die $!; -close A or die $!; -$?=0; close STDIN; $? and fail("gnucap failed (code $?)"); $sof= "./$sof" unless $sof =~ m,/,; -print ": generated ; $sof\n" or die $!; -# $Id: gnucap2gnuplot,v 1.3 2004-03-24 01:00:50 ianmdlvl Exp $ +# $Id: gnucap2gnuplot,v 1.4 2004-03-24 23:53:41 ianmdlvl Exp $