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., 675 Mass Ave, Cambridge, MA 02139, USA.
23 # This is a script to extract out PRINT data from a SWITCAP simulation
24 # and write it to a format which gwave can read
35 analysis_SPECTRUM = 2;
36 analysis_FREQCOMP = 3;
38 analysis = analysis_none;
47 for(i=1; i<ARGC; i=i+1) {
48 if(ARGV[i] ~ /^(-c)|(--copyright)$/) {
51 } else if(ARGV[i] ~ /^((-h)|(--help))$/) {
54 } else if(ARGV[i] ~ /^((-v)|(--version))$/) {
57 } else if(ARGV[i] ~ /^-.*/) {
58 printf("Unknown option: ""%s""\n", ARGV[i]) > "/dev/stderr";
63 printf("ARGV[%d] = %s\n", i, ARGV[i]);
65 infile = ARGV[ARGC-1];
69 printf("Loading SWITCAP output file [%s]\n", infile);
72 /^ Sinusoidal Steady State/ {
73 if( debug ) { printf("Start of SSS analysis\n"); }
74 analysis = analysis_SSS;
75 cnt_SSS = cnt_SSS + 1;
76 fileid = ".SSS." cnt_SSS;
77 pat = "^[ \t]*frequency";
80 /^ Spectral Analysis$/ {
81 if( debug ) { printf("Start of SPECTRUM analysis\n"); }
82 analysis = analysis_SPECTRUM;
83 cnt_SPECTRUM = cnt_SPECTRUM + 1;
84 fileid = ".SPECTRUM." cnt_SPECTRUM;
85 pat = "^not_implemented_yet$";
86 printf("Ignoring data from SPECTRUM analysis.\n");
87 printf("I haven't fully worked out how to always parse this\n");
88 printf("correctly. Please write code to do this!!!\n\n");
91 /^ Spectral Analysis by Components$/ {
92 if( debug ) { printf("Start of FREQCOMP analysis\n"); }
93 analysis = analysis_FREQCOMP;
94 cnt_FREQCOMP = cnt_FREQCOMP + 1;
95 fileid = ".FREQCOMP." cnt_FREQCOMP;
96 pat = "^not_implemented_yet$";
97 printf("Ignoring data from FREQCOMP analysis.\n");
98 printf("I haven't fully worked out how to always parse this\n");
99 printf("correctly. Please write code to do this!!!\n\n");
102 /^ Transient Analysis$/ {
103 if( debug ) { printf("Start of TRAN analysis\n"); }
104 analysis = analysis_TRAN;
105 cnt_TRAN = cnt_TRAN + 1;
106 fileid = ".TRAN." cnt_TRAN;
111 if( debug ) { printf("Start of Run Report\n"); }
112 analysis = analysis_none;
114 pat = "^this_is_the_run_report$";
118 if( debug ) { printf("Saw *SWITCAP line\n"); }
120 if( variable_offset > 0 ) {
121 outf = infile fileid ".asc";
122 printf("Writing data to ""%s""\n", outf);
124 for(i = 1; i <= variable_offset; i = i + 1) {
125 printf("%s ", vnames[i]) >> outf;
127 printf("\n") >> outf;
129 for(pt = 1; pt < cnt ; pt = pt + 1) {
130 if( debug > 1) { printf("point #%d: ", pt); }
131 for(i = 1; i <= variable_offset; i = i + 1) {
132 printf("%s ", data[i ":" pt]) >> outf;
134 printf("\n") >> outf;
140 for(k in data) { delete data[k]; }
141 num_analysis = num_analysis + 1;
144 if( debug ) { printf("No data to output yet\n"); }
151 state == state_wait {
153 if( debug) { printf("state_wait: Variable start line:"); }
154 for(i=1; i<=NF; i=i+1) {
155 if( debug ) { printf("\tVariable #%d = %s\n", i, $i); }
156 vnames[i + variable_offset] = $i;
161 if( debug ) { printf("state_wait: moving to state_skip_blank\n") };
162 state = state_skip_blank;
167 state == state_skip_blank {
169 if( debug) { printf("state_skip_blank: skipping blank line\n"); }
174 if( debug ) { printf("state_skip_blank: moving to state_read_data\n") };
175 state = state_read_data;
178 state == state_read_data {
180 variable_offset = variable_offset + nvars;
182 if( debug ) { printf("state_read_data: moving to state_wait\n") };
187 if( debug > 1 ) { printf("state_read_data: data = %s\n", $0); }
188 for(i=1; i<=NF; i=i+1) {
190 data[i+variable_offset ":" cnt] = $i;
197 if( debug ) { printf("END. Processed %d analyses.\n", num_analysis); };
201 function copyright() {
202 printf("gEDA/%s version %s\n", progn, "@VERSION@");
203 printf("gEDA/%s comes with ABSOLUTELY NO WARRANTY; see COPYING for more details.\n", progn);
204 printf("This is free software, and you are welcome to redistribute it under certain\n");
205 printf("conditions; please see the COPYING file for more details.\n\n");
209 printf("Usage:\n\n");
210 printf("\t%s -- -c|--copyright\n", progn);
211 printf("\t%s -- -h|--help\n", progn);
212 printf("\t%s -- -v|--version\n", progn);
213 printf("\t%s switcap.out\n", progn);
215 printf("%s process the output file generated by the SWITCAP switched capacitor\n", progn);
216 printf("circuit simulator. Data generated by SWITCAP ""PRINT"" statements is\n");
217 printf("extracted and written to an output file in an ASCII format which can be\n");
218 printf("directly loaded by the gwave waveform viewer or more easily loaded into\n");
219 printf("a tool such as scilab, octave, grace, or matlab.\n");
221 printf("If multiple analyses are in the SWITCAP output file, then they are written\n");
222 printf("to individual files by %s. The output file names are derived from the input\n", progn);
223 printf("file name by appending "".{SSS,TRAN}.#.asc"" to the name of the input file.\n");
224 printf("SSS is used for Sinusoidal Steady State analysis output and TRAN is used for.\n");
225 printf("TRANsient analysis output. # corresponds to the analysis number (ie if you \n");
226 printf("have 3 SSS analyses in your file, you will end up with .SSS.1.asc, .SSS.2.asc,\n");
227 printf("and .SSS.3.asc.\n");