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