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