Updated copyright text/header in most source files.
[geda-gaf/peter-b.git] / gnetlist / scripts / sw2asc.in
blob84fab981a17d422be8bf00028c59f07ba4211253
1 #!@AWK@ -f
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
27 BEGIN {
28   state_wait = 0;
29   state_skip_blank = 1;
30   state_read_data = 2;
31   state = state_wait;
33   analysis_none = 0;
34   analysis_SSS = 1;
35   analysis_SPECTRUM = 2;
36   analysis_FREQCOMP = 3;
37   analysis_TRAN = 4;
38   analysis = analysis_none;
40   progn = "sw2asc";
42   pat = "none";
44   variable_offset = 0;
45   nvars = 0;
47   for(i=1; i<ARGC; i=i+1) {
48     if(ARGV[i] ~ /^(-c)|(--copyright)$/) {
49       copyright();
50       exit 0;
51     } else if(ARGV[i] ~ /^((-h)|(--help))$/) {
52       usage();
53       exit 0;
54     } else if(ARGV[i] ~ /^((-v)|(--version))$/) {
55       copyright();
56       exit 0;
57     } else if(ARGV[i] ~ /^-.*/) {
58       printf("Unknown option: ""%s""\n", ARGV[i]) > "/dev/stderr";
59       usage();
60       close("/dev/stderr");
61       exit 1;
62     } 
63     printf("ARGV[%d] = %s\n", i, ARGV[i]);
64   }
65   infile = ARGV[ARGC-1];
66   
67   copyright();
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;
107   pat = "^[ \t]*time";
110 /^ Run Report$/ {
111   if( debug ) { printf("Start of Run Report\n"); }
112   analysis = analysis_none;
113   fileid = "none";
114   pat = "^this_is_the_run_report$";
117 /\*SWITCAP/ {
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);
123     printf( "" ) > outf;
124     for(i = 1; i <= variable_offset; i = i + 1) {
125       printf("%s ", vnames[i]) >> outf;
126     }
127     printf("\n") >> outf;
128     
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;
133       }
134       printf("\n") >> outf;
135     }
136     close(outf);
138     variable_offset = 0;
139     nvars = 0;
140     for(k in data) { delete data[k]; }
141     num_analysis = num_analysis + 1;
143   } else {
144     if( debug ) { printf("No data to output yet\n"); }
145   }
147   next;
151 state == state_wait {
152   if( $0 ~ pat ) {
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;
157     }
158     
159     nvars = NF;
160     
161     if( debug ) { printf("state_wait:  moving to state_skip_blank\n") };
162     state = state_skip_blank;
163   }
164   next;
167 state == state_skip_blank {
168   if( $0 == "" ) {
169     if( debug) { printf("state_skip_blank:  skipping blank line\n"); }
170     next; 
171   }
172   
173   cnt = 1;
174   if( debug ) { printf("state_skip_blank:  moving to state_read_data\n") };
175   state = state_read_data;
178 state == state_read_data {
179   if( $0 == "" ) {
180     variable_offset = variable_offset + nvars;
181     nvars = 0;
182     if( debug ) { printf("state_read_data:  moving to state_wait\n") };
183     state = state_wait;
184     next;
185   }
187   if( debug > 1 ) { printf("state_read_data: data = %s\n", $0); }
188   for(i=1; i<=NF; i=i+1) {
189     gsub(/d$/, "", $i);
190     data[i+variable_offset ":" cnt] = $i;
191   }
192   cnt = cnt + 1;
193   next;
196 END {
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");
208 function usage() {
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);
214   printf("\n");
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");
220   printf("\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");
228   printf("\n");
229