Jspice3
points.c
Go to the documentation of this file.
1 /***************************************************************************
2 JSPICE3 adaptation of Spice3e2 - Copyright (c) Stephen R. Whiteley 1992
3 Copyright 1990 Regents of the University of California. All rights reserved.
4 Authors: 1985 Wayne A. Christopher
5  1992 Stephen R. Whiteley
6 ****************************************************************************/
7 
8 #include "spice.h"
9 #include "plotdefs.h"
10 
11 /* Returns the minimum and maximum values of a dvec. Returns a pointer to
12  * static data. If real is true look at the real parts, otherwise the imag
13  * parts.
14  */
15 
16 double *
17 ft_minmax(v, real)
18 
19 struct dvec *v;
20 bool real;
21 {
22  static double res[2];
23  int i;
24  double d;
25 
26  if (isreal(v))
27  d = v->v_realdata[0];
28  else if (real)
29  d = realpart(&v->v_compdata[0]);
30  else
31  d = imagpart(&v->v_compdata[0]);
32 
33  res[0] = d;
34  res[1] = d;
35 
36  for (i = 1; i < v->v_length; i++) {
37  if (isreal(v))
38  d = v->v_realdata[i];
39  else if (real)
40  d = realpart(&v->v_compdata[i]);
41  else
42  d = imagpart(&v->v_compdata[i]);
43  if (d < res[0]) res[0] = d;
44  if (d > res[1]) res[1] = d;
45  }
46  return (res);
47 }
48 
49 
50 /* Figure out where a point should go, given the limits of the plotting
51  * area and the type of scale (log or linear).
52  */
53 
54 int
55 ft_findpoint(pt, lims, maxp, minp, islog)
56 
57 double pt, *lims;
58 bool islog;
59 {
60  double tl, th;
61 
62  if (pt < lims[0])
63  pt = lims[0];
64  if (pt > lims[1])
65  pt = lims[1];
66  if (islog) {
67  tl = mylog10(lims[0]);
68  th = mylog10(lims[1]);
69  return (((mylog10(pt) - tl) / (th - tl)) *
70  (maxp - minp) + minp);
71  }
72  else {
73  return (((pt - lims[0]) / (lims[1] - lims[0])) *
74  (maxp - minp) + minp);
75  }
76 }
77 
78 
79 /* Will report the minimum and maximum in "reflection coefficient" space
80  */
81 
82 double *
84 
85 struct dvec *v;
86 bool yval;
87 {
88  static double res[2];
89  int i;
90  double d, d2;
91 
92  if (isreal(v))
93  SMITH_tfm( v->v_realdata[0], 0.0, &d, &d2 );
94  else
95  SMITH_tfm( realpart(&v->v_compdata[0]),
96  imagpart(&v->v_compdata[0]), &d, &d2 );
97  /* we are looking for min/max X or Y ralue */
98  if (yval)
99  d = d2;
100 
101  res[0] = d;
102  res[1] = d;
103 
104  for (i = 1; i < v->v_length; i++) {
105  if (isreal(v))
106  SMITH_tfm( v->v_realdata[i], 0.0, &d, &d2 );
107  else
108  SMITH_tfm( realpart(&v->v_compdata[i]),
109  imagpart(&v->v_compdata[i]), &d, &d2 );
110  /* we are looking for min/max X or Y ralue */
111  if (yval)
112  d = d2;
113 
114  if (d < res[0]) res[0] = d;
115  if (d > res[1]) res[1] = d;
116  }
117  return (res);
118 }
119 
120 
121 SMITH_tfm(re, im, x, y)
122 
123 double re, im;
124 double *x, *y;
125 {
126  double dnom;
127 
128  dnom = (re + 1) * (re + 1) + im * im;
129  *x = (re * re + im * im - 1) / dnom;
130  *y = 2 * im / dnom;
131 }
double * ft_minmax(struct dvec *v, bool real)
Definition: points.c:17
SMITH_tfm(double re, double im, double *x, double *y)
Definition: points.c:121
int ft_findpoint(double pt, double *lims, maxp, minp, bool islog)
Definition: points.c:55
#define isreal(v)
Definition: ftedata.h:54
Definition: ftedata.h:24
#define imagpart(cval)
Definition: cpstd.h:36
#define mylog10(xx)
Definition: ftedefs.h:53
int d
Definition: newgraf.h:132
double * ft_SMITHminmax(struct dvec *v, bool yval)
Definition: points.c:83
int d2
Definition: newgraf.h:134
#define realpart(cval)
Definition: cpstd.h:35