3 # gEDA - GPL Electronic Design Automation
5 # Copyright (C) 2003-2010 Dan McMahill
7 # This program is free software; you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 2 of the License, or
10 # (at your option) any later version.
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
17 # You should have received a copy of the GNU General Public License
18 # along with this program; if not, write to the Free Software
19 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
24 # This is a script to extract out PRINT data from a SWITCAP simulation
25 # and write it to a format which gwave can read
36 analysis_SPECTRUM = 2;
37 analysis_FREQCOMP = 3;
39 analysis = analysis_none;
48 for(i=1; i<ARGC; i=i+1) {
49 if(ARGV[i] ~ /^(-c)|(--copyright)$/) {
52 } else if(ARGV[i] ~ /^((-h)|(--help))$/) {
55 } else if(ARGV[i] ~ /^((-v)|(--version))$/) {
58 } else if(ARGV[i] ~ /^-.*/) {
59 printf("Unknown option: ""%s""\n", ARGV[i]) > "/dev/stderr";
64 printf("ARGV[%d] = %s\n", i, ARGV[i]);
66 infile = ARGV[ARGC-1];
70 printf("Loading SWITCAP output file [%s]\n", infile);
73 /^ Sinusoidal Steady State/ {
74 if( debug ) { printf("Start of SSS analysis\n"); }
75 analysis = analysis_SSS;
76 cnt_SSS = cnt_SSS + 1;
77 fileid = ".SSS." cnt_SSS;
78 pat = "^[ \t]*frequency";
81 /^ Spectral Analysis$/ {
82 if( debug ) { printf("Start of SPECTRUM analysis\n"); }
83 analysis = analysis_SPECTRUM;
84 cnt_SPECTRUM = cnt_SPECTRUM + 1;
85 fileid = ".SPECTRUM." cnt_SPECTRUM;
86 pat = "^not_implemented_yet$";
87 printf("Ignoring data from SPECTRUM analysis.\n");
88 printf("I haven't fully worked out how to always parse this\n");
89 printf("correctly. Please write code to do this!!!\n\n");
92 /^ Spectral Analysis by Components$/ {
93 if( debug ) { printf("Start of FREQCOMP analysis\n"); }
94 analysis = analysis_FREQCOMP;
95 cnt_FREQCOMP = cnt_FREQCOMP + 1;
96 fileid = ".FREQCOMP." cnt_FREQCOMP;
97 pat = "^not_implemented_yet$";
98 printf("Ignoring data from FREQCOMP analysis.\n");
99 printf("I haven't fully worked out how to always parse this\n");
100 printf("correctly. Please write code to do this!!!\n\n");
103 /^ Transient Analysis$/ {
104 if( debug ) { printf("Start of TRAN analysis\n"); }
105 analysis = analysis_TRAN;
106 cnt_TRAN = cnt_TRAN + 1;
107 fileid = ".TRAN." cnt_TRAN;
112 if( debug ) { printf("Start of Run Report\n"); }
113 analysis = analysis_none;
115 pat = "^this_is_the_run_report$";
119 if( debug ) { printf("Saw *SWITCAP line\n"); }
121 if( variable_offset > 0 ) {
122 outf = infile fileid ".asc";
123 printf("Writing data to ""%s""\n", outf);
125 for(i = 1; i <= variable_offset; i = i + 1) {
126 printf("%s ", vnames[i]) >> outf;
128 printf("\n") >> outf;
130 for(pt = 1; pt < cnt ; pt = pt + 1) {
131 if( debug > 1) { printf("point #%d: ", pt); }
132 for(i = 1; i <= variable_offset; i = i + 1) {
133 printf("%s ", data[i ":" pt]) >> outf;
135 printf("\n") >> outf;
141 for(k in data) { delete data[k]; }
142 num_analysis = num_analysis + 1;
145 if( debug ) { printf("No data to output yet\n"); }
152 state == state_wait {
154 if( debug) { printf("state_wait: Variable start line:"); }
155 for(i=1; i<=NF; i=i+1) {
156 if( debug ) { printf("\tVariable #%d = %s\n", i, $i); }
157 vnames[i + variable_offset] = $i;
162 if( debug ) { printf("state_wait: moving to state_skip_blank\n") };
163 state = state_skip_blank;
168 state == state_skip_blank {
170 if( debug) { printf("state_skip_blank: skipping blank line\n"); }
175 if( debug ) { printf("state_skip_blank: moving to state_read_data\n") };
176 state = state_read_data;
179 state == state_read_data {
181 variable_offset = variable_offset + nvars;
183 if( debug ) { printf("state_read_data: moving to state_wait\n") };
188 if( debug > 1 ) { printf("state_read_data: data = %s\n", $0); }
189 for(i=1; i<=NF; i=i+1) {
191 data[i+variable_offset ":" cnt] = $i;
198 if( debug ) { printf("END. Processed %d analyses.\n", num_analysis); };
202 function copyright() {
203 printf("gEDA/%s version %s\n", progn, "@VERSION@");
204 printf("gEDA/%s comes with ABSOLUTELY NO WARRANTY; see COPYING for more details.\n", progn);
205 printf("This is free software, and you are welcome to redistribute it under certain\n");
206 printf("conditions; please see the COPYING file for more details.\n\n");
210 printf("Usage:\n\n");
211 printf("\t%s -- -c|--copyright\n", progn);
212 printf("\t%s -- -h|--help\n", progn);
213 printf("\t%s -- -v|--version\n", progn);
214 printf("\t%s switcap.out\n", progn);
216 printf("%s process the output file generated by the SWITCAP switched capacitor\n", progn);
217 printf("circuit simulator. Data generated by SWITCAP ""PRINT"" statements is\n");
218 printf("extracted and written to an output file in an ASCII format which can be\n");
219 printf("directly loaded by the gwave waveform viewer or more easily loaded into\n");
220 printf("a tool such as scilab, octave, grace, or matlab.\n");
222 printf("If multiple analyses are in the SWITCAP output file, then they are written\n");
223 printf("to individual files by %s. The output file names are derived from the input\n", progn);
224 printf("file name by appending "".{SSS,TRAN}.#.asc"" to the name of the input file.\n");
225 printf("SSS is used for Sinusoidal Steady State analysis output and TRAN is used for.\n");
226 printf("TRANsient analysis output. # corresponds to the analysis number (ie if you \n");
227 printf("have 3 SSS analyses in your file, you will end up with .SSS.1.asc, .SSS.2.asc,\n");
228 printf("and .SSS.3.asc.\n");