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