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