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