Jspice3
types.c
Go to the documentation of this file.
1 /***************************************************************************
2 JSPICE3 adaptation of Spice3f2 - Copyright (c) Stephen R. Whiteley 1992
3 Copyright 1990 Regents of the University of California. All rights reserved.
4 Authors: 1986 Wayne A. Christopher
5  1993 Stephen R. Whiteley
6 ****************************************************************************/
7 
8 /*
9  * Stuff to deal with nutmeg "types" for vectors and plots.
10  */
11 
12 #include "spice.h"
13 #include "ftedefs.h"
14 
15 #define NUMTYPES 128 /* If this is too little we can use a list. */
16 #define NUMPLOTTYPES 512 /* Since there may be more than 1 pat/type. */
17 
18 struct type {
19  char *t_name;
20  char *t_abbrev;
21 };
22 
23 /* The stuff for plot names. */
24 
25 struct plotab {
26  char *p_name;
27  char *p_pattern;
28 };
29 
30 /* note: This should correspond to SV_ defined in FTEconstant.h */
31 struct type types[NUMTYPES] = {
32  { "notype", NULL } ,
33  { "time", "S" } ,
34  { "frequency", "Hz" } ,
35  { "voltage", "V" } ,
36  { "current", "A" } ,
37  { "onoise-spectrum", "(V or A)^2/Hz" } ,
38  { "onoise-integrated", "V or A" } ,
39  { "inoise-spectrum", "(V or A)^2/Hz" } ,
40  { "inoise-integrated", "V or A" } ,
41  { "output-noise", NULL } ,
42  { "input-noise", NULL } ,
43 #ifdef notdef
44  { "HD2", NULL } ,
45  { "HD3", NULL } ,
46  { "DIM2", NULL } ,
47  { "SIM2", NULL } ,
48  { "DIM3", NULL } ,
49 #endif
50  { "pole", NULL } ,
51  { "zero", NULL } ,
52  { "s-param", NULL }
53 } ;
54 
55 /* The stuff for plot names. */
56 
58  { "tran", "transient" } ,
59  { "op", "op" } ,
60  { "tf", "function" },
61  { "dc", "d.c." } ,
62  { "dc", "dc" } ,
63  { "dc", "transfer" } ,
64  { "ac", "a.c." } ,
65  { "ac", "ac" } ,
66  { "pz", "pz" } ,
67  { "pz", "p.z." } ,
68  { "pz", "pole-zero"} ,
69  { "disto", "disto" } ,
70  { "dist", "dist" } ,
71  { "noise", "noise" } ,
72  { "sens", "sens" } ,
73  { "sens", "sensitivity" } ,
74  { "sp", "s.p." } ,
75  { "sp", "sp" } ,
76  { "harm", "harm" } ,
77  { "spect", "spect" } ,
78  { "range", "range" } ,
79  { "test", "testrun" }
80 } ;
81 
82 int notypes = 14;
83 int noplotabs = 22;
84 
85 
86 /* A command to define types for vectors and plots. This will generally
87  * be used in the Command: field of the rawfile.
88  * The syntax is "deftype v typename abbrev", where abbrev will be used to
89  * parse things like abbrev(name) and to label axes with M<abbrev>, instead
90  * of numbers. It may be ommitted.
91  * Also, the command "deftype p plottype pattern ..." will assign plottype as
92  * the name to any plot with one of the patterns in its Name: field.
93  */
94 
95 void
97 
98 wordlist *wl;
99 {
100  char *name, *abb;
101  int i;
102 
103  switch (*wl->wl_word) {
104  case 'v':
105  case 'V':
106  wl = wl->wl_next;
107  name = copy(wl->wl_word);
108  wl = wl->wl_next;
109  abb = copy(wl->wl_word);
110  for (i = 0; i < notypes; i++)
111  if (cieq(types[i].t_name, name)) {
112  types[i].t_abbrev = abb;
113  break;
114  }
115  if (notypes >= NUMTYPES - 1) {
116  fprintf(cp_err, "Error: too many types defined\n");
117  return;
118  }
119  types[notypes].t_name = name;
120  types[notypes].t_abbrev = abb;
121  notypes++;
122  break;
123 
124  case 'p':
125  case 'P':
126  wl = wl->wl_next;
127  name = copy(wl->wl_word);
128  wl = wl->wl_next;
129  while (wl) {
130  for (i = 0; i < noplotabs; i++)
131  if (cieq(plotabs[i].p_pattern, wl->wl_word)) {
132  plotabs[i].p_name = name;
133  wl = wl->wl_next;
134  break;
135  }
136  if (i != noplotabs)
137  continue;
138  if (noplotabs >= NUMPLOTTYPES - 1) {
139  fprintf(cp_err, "Error: too many plot abs\n");
140  return;
141  }
142  plotabs[noplotabs].p_name = name;
143  plotabs[noplotabs].p_pattern = copy(wl->wl_word);
144  wl = wl->wl_next;
145  noplotabs++;
146  }
147  break;
148 
149  default:
150  fprintf(cp_err, "Error: missing 'p' or 'v' argument\n");
151  break;
152  }
153  return;
154 }
155 
156 
157 /* Return the abbreviation associated with a number. */
158 
159 char *
160 ft_typabbrev(typenum)
161 int typenum;
162 {
163  if ((typenum < NUMTYPES) && (typenum >= 0))
164  return (types[typenum].t_abbrev);
165  else
166  return (NULL);
167 }
168 
169 
170 /* Return the typename associated with a number. */
171 
172 char *
173 ft_typenames(typenum)
174 int typenum;
175 {
176  if ((typenum < NUMTYPES) && (typenum >= 0))
177  return (types[typenum].t_name);
178  else
179  return (NULL);
180 }
181 
182 
183 /* Return the type number associated with the name. */
184 
185 int
187 
188 char *name;
189 {
190  int i;
191 
192  if (eq(name, "none"))
193  name = "notype";
194  for (i = 0; (i < NUMTYPES) && types[i].t_name; i++)
195  if (cieq(name, types[i].t_name))
196  return (i);
197  return (0);
198 }
199 
200 
201 /* For plots... */
202 
203 char *
205 
206 char *string;
207 {
208  char buf[128];
209  int i;
210 
211  if (!string)
212  return (NULL);
213  for (i = 0; string[i]; i++)
214  buf[i] = isupper(string[i]) ? tolower(string[i]) : string[i];
215  buf[i] = '\0';
216 
217  for (i = 0; plotabs[i].p_name; i++)
218  if (substring(plotabs[i].p_pattern, buf))
219  return (plotabs[i].p_name);
220 
221  return (NULL);
222 }
223 
224 
225 /* Change the type of a vector. */
226 
227 void
229 
230 wordlist *wl;
231 {
232  char *type = wl->wl_word;
233  int tt;
234  struct dvec *v;
235  struct dvlist *dl;
236  char *s;
237 
238  for (tt = 0; ; tt++) {
239  if (!(s = ft_typenames(tt)) || eq(type, s))
240  break;
241  }
242  if (!s) {
243  fprintf(cp_err, "Error: no such type as '%s'\n", type);
244  return;
245  }
246  for (wl = wl->wl_next; wl; wl = wl->wl_next) {
247  v = vec_get(wl->wl_word);
248  if (!v)
249  fprintf(cp_err, "Error: no such vector %s.\n",
250  wl->wl_word);
251  else {
252  if (v->v_link2) {
253  for (dl = v->v_link2; dl; dl = dl->dl_next)
254  dl->dl_dvec->v_type = tt;
255  }
256  else
257  v->v_type = tt;
258  }
259  }
260  return;
261 }
262 
static char buf[MAXPROMPT]
Definition: arg.c:18
#define eq(a, b)
Definition: misc.h:29
char * ft_typenames(int typenum)
Definition: types.c:173
int notypes
Definition: types.c:82
char * p_pattern
Definition: types.c:27
int noplotabs
Definition: types.c:83
struct dvlist * v_link2
Definition: ftedata.h:44
int cieq()
Definition: types.c:25
Definition: cddefs.h:119
Definition: ftedata.h:49
Definition: xforms.c:16
char * ft_plotabbrev(char *string)
Definition: types.c:204
void com_stype(wordlist *wl)
Definition: types.c:228
Definition: library.c:18
#define NUMTYPES
Definition: types.c:15
struct type types[NUMTYPES]
Definition: types.c:31
char * copy()
char * p_name
Definition: types.c:26
struct dvlist * dl_next
Definition: ftedata.h:51
FILE * cp_err
Definition: help.c:101
#define NUMPLOTTYPES
Definition: types.c:16
struct plotab plotabs[NUMPLOTTYPES]
Definition: types.c:57
int substring()
struct dvec * vec_get()
int ft_typnum(char *name)
Definition: types.c:186
#define NULL
Definition: spdefs.h:121
Definition: types.c:18
char * t_name
Definition: types.c:19
Definition: ftedata.h:24
struct dvec * dl_dvec
Definition: ftedata.h:50
struct wl * wl_next
Definition: library.c:20
Definition: cpstd.h:21
int v_type
Definition: ftedata.h:26
char * ft_typabbrev(int typenum)
Definition: types.c:160
char * t_abbrev
Definition: types.c:20
void com_dftype(wordlist *wl)
Definition: types.c:96