Jspice3
plot5.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: 1987 UCB
5  1992 Stephen R. Whiteley
6 ****************************************************************************/
7 
8 #include "spice.h"
9 #include "plotdev.h"
10 
11 static FILE *plotfile;
12 
13 #define putsi(a) putc((char) (a), plotfile); \
14  putc((char) ((a) >> 8), plotfile)
15 
16 #define SOLID 0
17 static char *linestyle[] = { "solid", "dotted", "longdashed", "shortdashed",
18  "dotdashed" };
19 static int currentlinestyle = SOLID;
20 
21 
22 int
24 {
26  dispdev->numcolors = 2;
27 
28  /* arbitrary drawable area */
29  dispdev->width = 800;
30  dispdev->height = 1050;
31 
32  return(0);
33 }
34 
35 
36 int
38 
39 GRAPH *graph;
40 {
41  plotfile = fopen((char*)graph->devdep, "wb");
42  if (!plotfile) {
43  graph->devdep = (char *) NULL;
44  perror(graph->devdep);
45  return (1);
46  }
47 
48  switch (graph->graphtype) {
49  default:
50  case GR_PLOT:
51  case GR_GRAF:
52  case GR_MPLT:
53  /* square plotting area */
54  graph->absolute.width = dispdev->width;
55  graph->absolute.height = dispdev->width;
56  break;
57  case GR_SCED:
58  /* full page plot */
59  graph->absolute.width = dispdev->width;
60  graph->absolute.height = dispdev->height;
61  break;
62  }
63 
64  putc('s', plotfile);
65  putsi(0);
66  putsi(0);
67  putsi(graph->absolute.width);
68  putsi(graph->absolute.height);
69 
70  /* reasonable values, used in gr_ for placement */
71  graph->fontwidth = 12;
72  graph->fontheight = 24;
73 
74  /* set to NULL so graphdb doesn't incorrectly de-allocate it */
75  graph->devdep = (char *) NULL;
76 
77  return(0);
78 }
79 
80 
81 int
83 
84 {
85  return (0);
86 }
87 
88 
89 int
91 {
92  if (plotfile)
93  fclose(plotfile);
94  return (0);
95 }
96 
97 
98 /* ARGSUSED */
99 int
101 
102 int x, y;
103 {
104  putc('p', plotfile);
105  putsi(x);
106  putsi(y);
107  return (0);
108 }
109 
110 
111 int
112 Plt5_Line(x1, y1, x2, y2)
113 
114 int x1, y1, x2, y2;
115 {
116  putc('l', plotfile);
117  putsi(x1);
118  putsi(y1);
119  putsi(x2);
120  putsi(y2);
121  return (0);
122 }
123 
124 
125 /* ARGSUSED */
126 int
127 Plt5_Box(x1, y1, x2, y2)
128 
129 int x1, y1, x2, y2;
130 {
131  Plt5_Line(x1,y1,x1,y2);
132  Plt5_Line(x1,y2,x2,y2);
133  Plt5_Line(x2,y2,x2,y1);
134  Plt5_Line(x2,y1,x1,y1);
135  return (0);
136 }
137 
138 
139 /* ARGSUSED */
140 int
141 Plt5_Arc(x0, y0, radius, theta1, theta2)
142 
143 int x0, y0, radius;
144 double theta1, theta2;
145 {
146  int xs, ys, xf, yf;
147 
148  xs = radius*sin(theta1);
149  ys = radius*cos(theta1);
150  xf = radius*sin(theta2);
151  yf = radius*cos(theta2);
152  putc('a', plotfile);
153  putsi(x0);
154  putsi(y0);
155  putsi(xs);
156  putsi(ys);
157  putsi(xf);
158  putsi(yf);
159  return (0);
160 }
161 
162 
163 /* ARGSUSED */
164 int
166 
167 POLYGON *p;
168 {
169  return (0);
170 }
171 
172 
173 int
174 Plt5_Text(text, x, y)
175 char *text;
176 int x, y;
177 {
178  int savedlstyle;
179 
180  /* set linestyle to solid
181  * or may get funny color text on some plotters
182  */
183  savedlstyle = currentlinestyle;
185 
186  /* move to (x, y) */
187  putc('m', plotfile);
188  putsi(x);
189  putsi(y);
190 
191  /* use the label option */
192  fprintf(plotfile, "t%s\n", text);
193 
194  /* restore old linestyle */
195  Plt5_SetLinestyle(savedlstyle);
196  return (0);
197 }
198 
199 
200 int
201 Plt5_SetLinestyle(linestyleid)
202 
203 int linestyleid;
204 {
205  if (linestyleid < 0) {
206  internalerror("bad linestyleid");
207  return (1);
208  }
209  if (linestyleid > dispdev->numlinestyles)
210  linestyleid = (linestyleid % dispdev->numlinestyles) + 1;
211 
212  putc('f', plotfile);
213  fprintf(plotfile, "%s\n", linestyle[linestyleid]);
214  currentlinestyle = linestyleid;
215  return (0);
216 }
217 
218 
219 /* ARGSUSED */
220 int
222 
223 int colorid;
224 {
225  return (0);
226 }
227 
228 
229 int
231 
232 {
233  fflush(plotfile);
234  return (0);
235 }
236 
int Plt5_Pixel(int x, int y)
Definition: plot5.c:100
static char * linestyle[]
Definition: plot5.c:17
int Plt5_Init()
Definition: plot5.c:23
int Plt5_Arc(int x0, int y0, int radius, double theta1, double theta2)
Definition: plot5.c:141
int numlinestyles
Definition: plotdev.h:67
internalerror(char *message)
Definition: error.c:91
DISPDEVICE * dispdev
Definition: display.c:112
static int currentlinestyle
Definition: plot5.c:19
Definition: cddefs.h:215
Definition: plotdev.h:14
int Plt5_NewViewport(GRAPH *graph)
Definition: plot5.c:37
#define GR_SCED
Definition: ftegraph.h:23
#define NULL
Definition: spdefs.h:121
int Plt5_Box(int x1, int y1, int x2, int y2)
Definition: plot5.c:127
static FILE * plotfile
Definition: plot5.c:11
#define putsi(a)
Definition: plot5.c:13
double cos()
#define SOLID
Definition: plot5.c:16
Definition: ftegraph.h:29
int Plt5_Polygon(POLYGON *p)
Definition: plot5.c:165
int Plt5_Update()
Definition: plot5.c:230
int Plt5_Text(char *text, int x, int y)
Definition: plot5.c:174
int Plt5_Halt()
Definition: plot5.c:90
void perror()
double sin()
int height
Definition: plotdev.h:66
int numcolors
Definition: plotdev.h:67
int Plt5_SetColor(int colorid)
Definition: plot5.c:221
#define GR_PLOT
Definition: ftegraph.h:20
int Plt5_Line(int x1, int y1, int x2, int y2)
Definition: plot5.c:112
#define GR_MPLT
Definition: ftegraph.h:22
int width
Definition: plotdev.h:66
int Plt5_Close()
Definition: plot5.c:82
int Plt5_SetLinestyle(int linestyleid)
Definition: plot5.c:201
#define GR_GRAF
Definition: ftegraph.h:21