| 1 |
#!/usr/bin/perl |
| 2 |
# ngspice2genspic - Copyright 2004 Ian Jackson - see below |
| 3 |
# |
| 4 |
# Reads the output from ngspice and outputs a `genspic' file |
| 5 |
# for use with genspic2gnuplot. Takes no arguments or options. |
| 6 |
# |
| 7 |
# Limitations |
| 8 |
# |
| 9 |
# Only frequency (.AC) and transient plots have been tested. |
| 10 |
# |
| 11 |
# Displaying voltages and currents on the same .TRAN graph won't work |
| 12 |
# well because they currently have to have the same Y scale. |
| 13 |
# |
| 14 |
# This whole scheme is very clumsy. There should be a driver program |
| 15 |
# with command-line option parsing. |
| 16 |
|
| 17 |
# This program and its documentation are free software; you can |
| 18 |
# redistribute them and/or modify them under the terms of the GNU |
| 19 |
# General Public License as published by the Free Software Foundation; |
| 20 |
# either version 3, or (at your option) any later version. |
| 21 |
# |
| 22 |
# This program and its documentation are distributed in the hope that |
| 23 |
# they will be useful, but WITHOUT ANY WARRANTY; without even the |
| 24 |
# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR |
| 25 |
# PURPOSE. See the GNU General Public License for more details. |
| 26 |
# |
| 27 |
# You should have received a copy of the GNU General Public License along |
| 28 |
# with this program; if not, consult the Free Software Foundation's |
| 29 |
# website at www.fsf.org, or the GNU Project website at www.gnu.org. |
| 30 |
|
| 31 |
die if @ARGV; |
| 32 |
|
| 33 |
while (<STDIN>) { |
| 34 |
if (m/^Total CPU/) { |
| 35 |
die if $mode ne ''; |
| 36 |
$seentcpu=1; |
| 37 |
} elsif (m/^Current dynamic memory/ || |
| 38 |
m/^Dynamic memory limit/ || |
| 39 |
m/^Level not specified/ || |
| 40 |
m/^Doing analysis/ || |
| 41 |
m/^CPU time since/ || |
| 42 |
m/^Circuit\:/) { |
| 43 |
die if length $mode; |
| 44 |
} elsif (m/\f/) { |
| 45 |
die if m/\S/; |
| 46 |
} elsif (!m/\S/ && $mode eq InitTransSkip) { |
| 47 |
$mode= ''; |
| 48 |
} elsif (m/^Initial Transient/ && $mode eq '') { |
| 49 |
$mode= InitTrans; |
| 50 |
} elsif (m/^Node/ && $mode eq InitTrans) { |
| 51 |
$mode= InitTransSkip; |
| 52 |
} elsif (m/\w/ && $mode eq InitTransSkip) { |
| 53 |
} elsif (m/^\-\-/ && length $mode) { |
| 54 |
} elsif (m/^\s\s+(\w+) Analysis /) { |
| 55 |
if ($mode eq '') { |
| 56 |
$mode= Table; |
| 57 |
$ctable= $1; |
| 58 |
$dokey= 1; |
| 59 |
} else { |
| 60 |
$dokey= 0; |
| 61 |
} |
| 62 |
} elsif (m/^\s\s+/ && ($mode eq Table or !length $mode)) { |
| 63 |
} elsif (m/^Index / && $mode eq Table) { |
| 64 |
s/\s+$//; |
| 65 |
($index,$key,@nowheadings) = split /\s+/, $_; |
| 66 |
$logxy= 0+($key eq 'frequency'); |
| 67 |
} elsif (m/^\d+\s/ && $mode eq Table) { |
| 68 |
($index,$key,@nowcolumns) = split /\s+/, $_; |
| 69 |
shift @nowcolumns if $key =~ s/\,$//; |
| 70 |
$coldata[$index] .= " $key" if $dokey; |
| 71 |
$coldata[$index] .= " @nowcolumns"; |
| 72 |
if (!$index) { |
| 73 |
foreach $c (@nowheadings) { |
| 74 |
$h= 'y'; |
| 75 |
$h= 'y2' if $c =~ m/^ph\(/; |
| 76 |
push @columns, "$h:$c"; |
| 77 |
} |
| 78 |
} |
| 79 |
} elsif (!m/\S/ && $mode eq Table) { |
| 80 |
print "S $ctable $logxy @columns\n" or die $!; |
| 81 |
foreach $l (@coldata) { printf "D%s\n", $l or die $!; } |
| 82 |
print "T\n" or die $!; |
| 83 |
$mode= ''; |
| 84 |
@columns= (); |
| 85 |
@coldata= (); |
| 86 |
} elsif (!m/\S/) { |
| 87 |
$mode= '' if $mode eq InitTransSkip; |
| 88 |
} else { |
| 89 |
die "$mode: $_ ?"; |
| 90 |
} |
| 91 |
} |
| 92 |
die "no plots" unless defined $ctable; |
| 93 |
print "F\n" or die $!; |
| 94 |
|
| 95 |
# $Id: ngspice2genspic,v 1.3 2007-09-21 21:21:15 ianmdlvl Exp $ |