4beb8ff58c2f6c19a45ebf86f8275eae06424ce0
[ctsim.git] / include / ezplot.h
1 /*****************************************************************************
2 **  This is part of the CTSim program
3 **  Copyright (C) 1983-2000 Kevin Rosenberg
4 **
5 **  $Id: ezplot.h,v 1.6 2000/06/18 10:27:11 kevin Exp $
6 **
7 **  This program is free software; you can redistribute it and/or modify
8 **  it under the terms of the GNU General Public License (version 2) as
9 **  published by the Free Software Foundation.
10 **
11 **  This program is distributed in the hope that it will be useful,
12 **  but WITHOUT ANY WARRANTY; without even the implied warranty of
13 **  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 **  GNU General Public License for more details.
15 **
16 **  You should have received a copy of the GNU General Public License
17 **  along with this program; if not, write to the Free Software
18 **  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19 ******************************************************************************/
20
21 /*----------------------------------------------------------------------*/
22 /*                              EZPLOT                                  */
23 /*                                                                      */
24 /*----------------------------------------------------------------------*/
25
26 #ifndef __H_EZPLOT
27 #define __H_EZPLOT
28
29
30 #include <stdio.h>
31 #include <stddef.h>
32 #include "kstddef.h"
33 #include <ctype.h>
34 #include "sgp.h"
35 #include <math.h>
36 #include "kmath.h"
37 #include "cio.h"
38
39 #define MAXLABEL  40            /* maximum length of axis label */
40 #define MAXTITLE  40            /* maximum length of a title */
41 #define MAXLEGEND 20            /* maximum length of a legend */
42 #define MAXCURVES 10            /* maximum number of curves that can be plotted */
43 #define MAXPTS    200           /* max number of points that can be read with
44                                    DATA command in INTERACTIVE mode */
45
46 struct ezp_curve_st {
47         int numpts;
48         double *x, *y;
49         int linestyle;
50         int symbol;
51         int symfreq;
52         int color;
53         char legend[MAXLEGEND+1];
54 };
55
56 #define XBUF_DEF     600
57 #define YBUF_DEF     600
58 #define PRTMODE_DEF  1
59
60 /*----------------------------------------------------------------------*/
61 /*                      Codes from LEX                                  */
62 /*----------------------------------------------------------------------*/
63
64 #define S_DATA          2
65 #define S_HELP          3
66 #define S_EXIT          4
67
68 #define S_SOLID         -10
69 #define S_DASH          -11
70 #define S_NOLINE        -12
71 #define S_BLACK         -13
72 #define S_RED           -14
73 #define S_BLUE          -15
74 #define S_GREEN         -16
75 #define S_PEN           -17
76 #define S_SYMBOL        -18     
77 #define S_EVERY         -19
78 #define S_NONE          -20
79 #define S_CURVES        -21
80 #define S_UNKNOWN       -22
81 #define S_END           -23
82 #define S_LEGEND        -24
83 #define S_XLEGEND       -25
84 #define S_YLEGEND       -26
85 #define S_XLIN          -27
86 #define S_YLIN          -28
87 #define S_XLOG          -29
88 #define S_YLOG          -30
89 #define S_XLABEL        -31
90 #define S_YLABEL        -32
91 #define S_XLENGTH       -33
92 #define S_YLENGTH       -34
93 #define S_XTICKS        -35
94 #define S_YTICKS        -36
95 #define S_ABOVE         -37
96 #define S_LABEL         -38
97 #define S_BELOW         -39
98 #define S_NOLABEL       -40
99 #define S_RIGHT         -41
100 #define S_LEFT          -42
101 #define S_XAUTOSCALE    -43
102 #define S_YAUTOSCALE    -44
103 #define S_XMIN          -45
104 #define S_YMIN          -46
105 #define S_XMAX          -47
106 #define S_YMAX          -48
107 #define S_LXFRAC        -49
108 #define S_LYFRAC        -50
109 #define S_XCROSS        -51
110 #define S_YCROSS        -52
111 #define S_NOXAXIS       -53
112 #define S_NOYAXIS       -54
113 #define S_XPORIGIN      -55
114 #define S_YPORIGIN      -56
115 #define S_TITLE         -57
116 #define S_XTITLE        -58
117 #define S_YTITLE        -59
118 #define S_REPLOT        -60
119 #define S_CLEAR         -61
120 #define S_STORE         -62
121 #define S_RESTORE       -63
122 #define S_USTART        -64
123 #define S_UFINISH       -65
124 #define S_AMARK         -66
125 #define S_NO            -67
126 #define S_INTERACTIVE   -68
127 #define S_UNITS         -69
128 #define S_INCHES        -70     
129 #define S_USER          -71
130
131 #define S_BOX           -100
132 #define S_NOBOX         -101
133 #define S_GRID          -102
134 #define S_NOGRID        -103
135 #define S_MAJOR         -104
136 #define S_MINOR         -105
137 #define S_COLOR         -106
138 #define S_LEGENDBOX     -107
139 #define S_TAG           -108
140
141 #define S_EPSON         -110
142 #define S_CRT           -111
143
144 #define S_TEXTSIZE      -120
145 #define S_XBUF          -121
146 #define S_YBUF          -122
147 #define S_PRTMODE       -123
148
149 /*----------------------------------------------------------------------*/
150 /*                             GLOBAL VARIABLES                         */
151 /*----------------------------------------------------------------------*/
152
153 /* axis definitions */
154 #define LINEAR  1               /* linear axis */
155 #define LOG     2               /* logrithmic axis */
156 #define NOAXIS  3               /* don't plot axis */
157
158 /* tick definitions */
159 #define ABOVE    1
160 #define BELOW    2
161 #define RIGHT    4
162 #define LEFT     8
163
164 /* line types */
165 #define NOLINE  0
166 #define SOLID   1
167 #define DASH    2
168 #define DASH1   10
169 #define DASH2   11
170 #define DASH3   12
171 #define DASH4   13
172
173 /* symbol definitions */
174 #define SB_CROSS    1
175 #define SB_PLUS     2
176 #define SB_BOX      3
177 #define SB_CIRCLE   4
178 #define SB_ERRORBAR 5
179 #define MAXSYMBOL   5
180
181 #define INSIDE   1              /* values of o_legendbox */
182 #define OUTSIDE  2
183 #define NOLEGEND 3
184
185 /*-----------------------------------------------------------------------------
186  *                              GLOBAL VARIABLES
187  *
188  * Naming Convention:
189  *      i_   Internal variable
190  *              Not user changable
191  *      o_   Option variable
192  *              Normal variable that is user modifiable
193  *              These variables must always have a valid value
194  *      d_   Device variable
195  *              Variables controlling devices
196  *      clr_ Color variable
197  *              Holds a color value
198  *      c_   Character string variable
199  *              Contains a character string
200  *      v_   Value variable
201  *              User modifiable variable associated with the set variable (s_)
202  *              These variables do not always have a valid value
203  *              These variables change assumption EZPLOT makes about the plot
204  *      s_   Set variable.
205  *              TRUE if associated value variable (v_) has been set by the user
206  *---------------------------------------------------------------------------*/
207
208
209 struct ezplot_var {
210
211 /*-------------*/
212 /* USER CURVES */
213 /*-------------*/
214
215 struct ezp_curve_st curve[MAXCURVES];
216
217 /*--------------------*/
218 /* INTERNAL VARIABLES */
219 /*--------------------*/
220
221 bool i_plotimmediate;           /* indicates that a call to EZPLOT is a signal
222                                    to print all received arrays.  EZSET uses
223                                    this variable to force EZPLOT to replot 
224                                    its stored curves */
225 int i_numcurves;                /* number of curves received by EZPLOT */
226
227 /*------------------*/
228 /* DEVICE VARIABLES */
229 /*------------------*/
230
231 bool d_usecrt;                  /* TRUE if want to use CRT as output device */ 
232 bool d_useprt;                  /* TRUE if wamt to use printer as output device */
233
234 int d_crtmode;                  /* Controls which crt mode to use for plot */
235 int d_prtmode;                  /* Controls mode of printer output */
236
237 int d_xprtbuf, d_yprtbuf;       /* Size of printer buffer in pixels */
238
239 /*-----------------*/
240 /* COLOR VARIABLES */
241 /*-----------------*/
242
243 int clr_axis;                   /* color of all axis lines */
244 int clr_title;                  /* color of main title */
245 int clr_label;                  /* color of axis labels */
246 int clr_legend;                 /* color of legend box */
247 int clr_grid;                   /* color of grid lines */
248 int clr_number;                 /* color of axis number labels */
249
250 /*------------------*/
251 /* OPTION VARIABLES */
252 /*------------------*/
253
254 int o_reqcurves;                /* # of curves specified in CURVES command */
255                                 /* default value is 1, so that a call to EZPLOT
256                                    will force a plot */
257 bool o_unknowncurves;           /* TRUE when the user specifies that the 
258                                    number of curves is unknown */
259
260 bool o_ustart, o_ufinish;       /* TRUE if user initiates or terminate sgp */
261
262 double o_xporigin, o_yporigin;  /* origin of plot frame in NDC */
263 double o_xlength, o_ylength;    /* length of plot frame in NDC */
264
265 char c_xlabel[MAXLABEL+1];      /* label for x axis */
266 char c_ylabel[MAXLABEL+1];      /* label for y axis */
267 char c_title[MAXTITLE+1];               /* title to print above graph */
268 char c_legend[MAXLEGEND+1];     /* current legend specified */
269
270 int o_linestyle, o_color;       /* style to use for curves all subsequent */
271                                 /* curves to EZPLOT */
272 bool o_xaxis, o_yaxis;          /* Specifies where axis & labels are drawn */
273 bool o_grid;                    /* Flag to draw a grid at major ticks */
274 bool o_box;                     /* Flag to draw a box around the graph */
275
276 int o_xticks, o_yticks;         /* direction to draw tick marks */
277 bool o_xtlabel, o_ytlabel;      /* TRUE if label tick marks */
278
279 int o_xmajortick, o_ymajortick; /* number of major ticks to draw */
280 int o_xminortick, o_yminortick; /* number of minor ticks between major ticks */
281
282 int o_symbol;                   /* Symbol type, (0 = no symbol) */
283 int o_symfreq;                  /* frequency to draw symbols at curve points */
284
285 int o_legendbox;                /* controls whether legend is inside */
286                                 /* or outside of the axis extents */
287 int o_tag;                      /* controls whether to draw tag at end of axes */
288
289 /*-----------------------*/
290 /* VALUE & SET variables */
291 /*-----------------------*/
292
293 double v_xmin, v_xmax, v_ymin, v_ymax;  /* user supplied axis endpoints */
294 bool   s_xmin, s_xmax, s_ymin, s_ymax;  /* TRUE is endpoint has been set */
295
296 double v_xtitle, v_ytitle;      /* NDC position to plot title */
297 bool   s_xtitle, s_ytitle;      /* TRUE if set position for title */
298 double v_xcross, v_ycross;      /* position that axes cross */
299 bool   s_xcross, s_ycross;      /* TRUE if set axes cross position */
300
301 double v_xlegend, v_ylegend;    /* upper-left position of legend box in NDC */
302 bool   s_xlegend, s_ylegend;    /* TRUE if set position of legend box */
303
304 int  v_lxfrac, v_lyfrac;        /* number of digits to right of decimal place */
305 bool s_lxfrac, s_lyfrac;        /* TRUE if set number of fractional digits */
306
307 double v_textsize;              /* size of text in NDC */
308 bool   s_textsize;              /* TRUE if user set size of text */
309
310 };      /* end of EZPLOT VARIABLES */
311
312
313
314 extern struct ezplot_var ez;
315 extern bool ezplot_firstcall;   /* set to false on first call to EZSET or EZPLOT */
316
317
318 /* ezplot.cpp */
319 SGP_ID ezplot(double x[], double y[], int num);
320 void ezinit(void);
321 void ezfree(void);
322 void ezclear(void);
323
324 /* ezset.cpp */
325 int ezset(char *command);
326
327 /* ezplot1d.cpp */
328 void ezplot_1d(double *y, int n);
329
330 /* makefmt.cpp */
331 void make_numfmt(char *fmtstr, int *fldwid, int *nfrac, double min, double max, int nint);
332
333 /* axis.cpp */
334 int axis_scale (double min, double max, int nint, double *minp, double *maxp, int *nintp);
335
336
337
338 #endif