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