/*****************************************************************************
-** This is part of the CTSim program
-** Copyright (C) 1983-2000 Kevin Rosenberg
+** FILE IDENTIFICATION
+**
+** Name: ezplot.h
+** Purpose: Header file for EZplot library
**
-** $Id: ezplot.h,v 1.2 2000/04/28 14:14:16 kevin Exp $
-** $Log: ezplot.h,v $
-** Revision 1.2 2000/04/28 14:14:16 kevin
-** *** empty log message ***
+** This is part of the CTSim program
+** Copyright (c) 1983-2001 Kevin Rosenberg
**
+** $Id: ezplot.h,v 1.26 2001/03/10 23:14:15 kevin Exp $
**
** This program is free software; you can redistribute it and/or modify
** it under the terms of the GNU General Public License (version 2) as
** along with this program; if not, write to the Free Software
** Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
******************************************************************************/
-/*----------------------------------------------------------------------*/
-/* EZPLOT */
-/* */
-/*----------------------------------------------------------------------*/
+
#ifndef __H_EZPLOT
#define __H_EZPLOT
-#include <stdio.h>
+#include <cstdio>
+#include <cctype>
+#include <cmath>
#include <stddef.h>
-#include "kstddef.h"
-#include <ctype.h>
+#include "ctsupport.h"
#include "sgp.h"
-#include <math.h>
-#include "kmath.h"
-#include "cio.h"
-
-#define MAXLABEL 40 /* maximum length of axis label */
-#define MAXTITLE 40 /* maximum length of a title */
-#define MAXLEGEND 20 /* maximum length of a legend */
-#define MAXCURVES 10 /* maximum number of curves that can be plotted */
-#define MAXPTS 200 /* max number of points that can be read with
- DATA command in INTERACTIVE mode */
-
-struct ezp_curve_st {
- int numpts;
- double *x, *y;
- int linestyle;
- int symbol;
- int symfreq;
- int color;
- char legend[MAXLEGEND+1];
+#include "pol.h"
+
+
+class EZPlotCurve {
+public:
+ double *x;
+ double *y;
+ int m_iPointCount;
+
+ EZPlotCurve (const double* x, const double* y, int n);
+
+ ~EZPlotCurve();
};
-#define XBUF_DEF 600
-#define YBUF_DEF XBUF_DEF * (72. / 120.) * 0.75
-#define PRTMODE_DEF 1
-
-/*----------------------------------------------------------------------*/
-/* Codes from LEX */
-/*----------------------------------------------------------------------*/
+//----------------------------------------------------------------------
+// GLOBAL VARIABLES
+//----------------------------------------------------------------------
-#define S_DATA 2
-#define S_HELP 3
-#define S_EXIT 4
-
-#define S_SOLID -10
-#define S_DASH -11
-#define S_NOLINE -12
-#define S_BLACK -13
-#define S_RED -14
-#define S_BLUE -15
-#define S_GREEN -16
-#define S_PEN -17
-#define S_SYMBOL -18
-#define S_EVERY -19
-#define S_NONE -20
-#define S_CURVES -21
-#define S_UNKNOWN -22
-#define S_END -23
-#define S_LEGEND -24
-#define S_XLEGEND -25
-#define S_YLEGEND -26
-#define S_XLIN -27
-#define S_YLIN -28
-#define S_XLOG -29
-#define S_YLOG -30
-#define S_XLABEL -31
-#define S_YLABEL -32
-#define S_XLENGTH -33
-#define S_YLENGTH -34
-#define S_XTICKS -35
-#define S_YTICKS -36
-#define S_ABOVE -37
-#define S_LABEL -38
-#define S_BELOW -39
-#define S_NOLABEL -40
-#define S_RIGHT -41
-#define S_LEFT -42
-#define S_XAUTOSCALE -43
-#define S_YAUTOSCALE -44
-#define S_XMIN -45
-#define S_YMIN -46
-#define S_XMAX -47
-#define S_YMAX -48
-#define S_LXFRAC -49
-#define S_LYFRAC -50
-#define S_XCROSS -51
-#define S_YCROSS -52
-#define S_NOXAXIS -53
-#define S_NOYAXIS -54
-#define S_XPORIGIN -55
-#define S_YPORIGIN -56
-#define S_TITLE -57
-#define S_XTITLE -58
-#define S_YTITLE -59
-#define S_REPLOT -60
-#define S_CLEAR -61
-#define S_STORE -62
-#define S_RESTORE -63
-#define S_USTART -64
-#define S_UFINISH -65
-#define S_AMARK -66
-#define S_NO -67
-#define S_INTERACTIVE -68
-#define S_UNITS -69
-#define S_INCHES -70
-#define S_USER -71
-
-#define S_BOX -100
-#define S_NOBOX -101
-#define S_GRID -102
-#define S_NOGRID -103
-#define S_MAJOR -104
-#define S_MINOR -105
-#define S_COLOR -106
-#define S_LEGENDBOX -107
-#define S_TAG -108
-
-#define S_EPSON -110
-#define S_CRT -111
-
-#define S_TEXTSIZE -120
-#define S_XBUF -121
-#define S_YBUF -122
-#define S_PRTMODE -123
+// axis definitions
+enum {
+ LINEAR = 1, // linear axis
+ LOG, // logrithmic axis
+ NOAXIS, // don't plot axis
+};
-/*----------------------------------------------------------------------*/
-/* GLOBAL VARIABLES */
-/*----------------------------------------------------------------------*/
+// tick definitions
+enum {
+ ABOVE = 1,
+ BELOW,
+ RIGHT,
+ LEFT,
+};
-/* axis definitions */
-#define LINEAR 1 /* linear axis */
-#define LOG 2 /* logrithmic axis */
-#define NOAXIS 3 /* don't plot axis */
+// line types
+enum {
+ NOLINE = 0,
+ SOLID,
+ DASH,
+ DASH1,
+ DASH2,
+ DASH3,
+ DASH4,
+};
-/* tick definitions */
-#define ABOVE 1
-#define BELOW 2
-#define RIGHT 4
-#define LEFT 8
+// symbol definitions
+enum {
+ SB_CROSS = 1,
+ SB_PLUS,
+ SB_BOX,
+ SB_CIRCLE,
+ SB_ERRORBAR,
+ SB_POINT,
+ MAXSYMBOL,
+};
-/* line types */
-#define NOLINE 0
-#define SOLID 1
-#define DASH 2
-#define DASH1 10
-#define DASH2 11
-#define DASH3 12
-#define DASH4 13
+enum {
+ INSIDE = 1, // values of o_legendbox
+ OUTSIDE,
+ NOLEGEND,
+};
-/* symbol definitions */
-#define SB_CROSS 1
-#define SB_PLUS 2
-#define SB_BOX 3
-#define SB_CIRCLE 4
-#define SB_ERRORBAR 5
-#define MAXSYMBOL 5
-#define INSIDE 1 /* values of o_legendbox */
-#define OUTSIDE 2
-#define NOLEGEND 3
+struct KeywordCodeTable {
+ char* keyword;
+ int code;
+};
/*-----------------------------------------------------------------------------
- * GLOBAL VARIABLES
- *
- * Naming Convention:
- * i_ Internal variable
- * Not user changable
- * o_ Option variable
- * Normal variable that is user modifiable
- * These variables must always have a valid value
- * d_ Device variable
- * Variables controlling devices
- * clr_ Color variable
- * Holds a color value
- * c_ Character string variable
- * Contains a character string
- * v_ Value variable
- * User modifiable variable associated with the set variable (s_)
- * These variables do not always have a valid value
- * These variables change assumption EZPLOT makes about the plot
- * s_ Set variable.
- * TRUE if associated value variable (v_) has been set by the user
- *---------------------------------------------------------------------------*/
-
-
-struct ezplot_var {
-
-/*-------------*/
-/* USER CURVES */
-/*-------------*/
-
-struct ezp_curve_st curve[MAXCURVES];
-
-/*--------------------*/
-/* INTERNAL VARIABLES */
-/*--------------------*/
-
-bool i_plotimmediate; /* indicates that a call to EZPLOT is a signal
- to print all received arrays. EZSET uses
- this variable to force EZPLOT to replot
- its stored curves */
-int i_numcurves; /* number of curves received by EZPLOT */
-
-/*------------------*/
-/* DEVICE VARIABLES */
-/*------------------*/
-
-bool d_usecrt; /* TRUE if want to use CRT as output device */
-bool d_useprt; /* TRUE if wamt to use printer as output device */
-
-int d_crtmode; /* Controls which crt mode to use for plot */
-int d_prtmode; /* Controls mode of printer output */
-
-int d_xprtbuf, d_yprtbuf; /* Size of printer buffer in pixels */
-
-/*-----------------*/
-/* COLOR VARIABLES */
-/*-----------------*/
-
-int clr_axis; /* color of all axis lines */
-int clr_title; /* color of main title */
-int clr_label; /* color of axis labels */
-int clr_legend; /* color of legend box */
-int clr_grid; /* color of grid lines */
-int clr_number; /* color of axis number labels */
-
-/*------------------*/
-/* OPTION VARIABLES */
-/*------------------*/
-
-int o_reqcurves; /* # of curves specified in CURVES command */
- /* default value is 1, so that a call to EZPLOT
- will force a plot */
-bool o_unknowncurves; /* TRUE when the user specifies that the
- number of curves is unknown */
-
-bool o_ustart, o_ufinish; /* TRUE if user initiates or terminate sgp */
-
-double o_xporigin, o_yporigin; /* origin of plot frame in NDC */
-double o_xlength, o_ylength; /* length of plot frame in NDC */
-
-char c_xlabel[MAXLABEL+1]; /* label for x axis */
-char c_ylabel[MAXLABEL+1]; /* label for y axis */
-char c_title[MAXTITLE+1]; /* title to print above graph */
-char c_legend[MAXLEGEND+1]; /* current legend specified */
-
-int o_linestyle, o_color; /* style to use for curves all subsequent */
- /* curves to EZPLOT */
-bool o_xaxis, o_yaxis; /* Specifies where axis & labels are drawn */
-bool o_grid; /* Flag to draw a grid at major ticks */
-bool o_box; /* Flag to draw a box around the graph */
-
-int o_xticks, o_yticks; /* direction to draw tick marks */
-bool o_xtlabel, o_ytlabel; /* TRUE if label tick marks */
-
-int o_xmajortick, o_ymajortick; /* number of major ticks to draw */
-int o_xminortick, o_yminortick; /* number of minor ticks between major ticks */
-
-int o_symbol; /* Symbol type, (0 = no symbol) */
-int o_symfreq; /* frequency to draw symbols at curve points */
-
-int o_legendbox; /* controls whether legend is inside */
- /* or outside of the axis extents */
-int o_tag; /* controls whether to draw tag at end of axes */
-
-/*-----------------------*/
-/* VALUE & SET variables */
-/*-----------------------*/
-
-double v_xmin, v_xmax, v_ymin, v_ymax; /* user supplied axis endpoints */
-bool s_xmin, s_xmax, s_ymin, s_ymax; /* TRUE is endpoint has been set */
-
-double v_xtitle, v_ytitle; /* NDC position to plot title */
-bool s_xtitle, s_ytitle; /* TRUE if set position for title */
-double v_xcross, v_ycross; /* position that axes cross */
-bool s_xcross, s_ycross; /* TRUE if set axes cross position */
-
-double v_xlegend, v_ylegend; /* upper-left position of legend box in NDC */
-bool s_xlegend, s_ylegend; /* TRUE if set position of legend box */
-
-int v_lxfrac, v_lyfrac; /* number of digits to right of decimal place */
-bool s_lxfrac, s_lyfrac; /* TRUE if set number of fractional digits */
-
-double v_textsize; /* size of text in NDC */
-bool s_textsize; /* TRUE if user set size of text */
-
-}; /* end of EZPLOT VARIABLES */
-
-
-
-extern struct ezplot_var ez;
-extern bool ezplot_firstcall; /* set to false on first call to EZSET or EZPLOT */
-
-
-/* axis.c */
-int axis_scale(double min, double max, int nint, double *minp, double *maxp, int *nintp);
-/* ezplot.c */
-int ezplot(double x[], double y[], int num);
-void ezinit(void);
-void ezfree(void);
-void ezclear(void);
-/* ezplot1d.c */
-void ezplot_1d(double *y, int n);
-/* ezset.c */
-int ezset(char *command);
-/* makefmt.c */
-void make_numfmt(char *fmtstr, int *fldwid, int *nfrac, double min, double max, int nint);
+* GLOBAL VARIABLES
+*
+* Naming Convention:
+* i_ Internal variable
+* Not user changable
+* o_ Option variable
+* Normal variable that is user modifiable
+* These variables must always have a valid value
+* d_ Device variable
+* Variables controlling devices
+* clr_ Color variable
+* Holds a color value
+* c_ Character string variable
+* Contains a character string
+* v_ Value variable
+* User modifiable variable associated with the set variable (s_)
+* These variables do not always have a valid value
+* These variables change assumption EZPLOT makes about the plot
+* s_ Set variable.
+* TRUE if associated value variable (v_) has been set by the user
+*---------------------------------------------------------------------------*/
+
+#include <vector>
+
+typedef std::vector<EZPlotCurve*>::iterator EZPlotCurveIterator;
+typedef std::vector<EZPlotCurve*>::const_iterator EZPlotCurveConstIterator;
+
+class SGP;
+class EZPlot {
+private:
+ //----------------------------------------------------------------------
+ // POL Codes
+ //----------------------------------------------------------------------
+
+ enum {
+ S_DATA = 2,
+ S_HELP,
+ S_EXIT,
+ S_CURVE,
+ S_SOLID,
+ S_DASH,
+ S_NOLINE,
+ S_BLACK,
+ S_RED,
+ S_GREEN,
+ S_BLUE,
+ S_SYMBOL,
+ S_PEN,
+ S_EVERY,
+ S_NONE,
+ S_LEGEND,
+ S_XLEGEND,
+ S_YLEGEND,
+ S_XLIN,
+ S_YLIN,
+ S_XLOG,
+ S_YLOG,
+ S_XLABEL,
+ S_YLABEL,
+ S_XLENGTH,
+ S_YLENGTH,
+ S_XTICKS,
+ S_YTICKS,
+ S_ABOVE,
+ S_LABEL,
+ S_BELOW,
+ S_NOLABEL,
+ S_RIGHT,
+ S_LEFT,
+ S_XAUTOSCALE,
+ S_YAUTOSCALE,
+ S_XMIN,
+ S_YMIN,
+ S_XMAX,
+ S_YMAX,
+ S_LXFRAC,
+ S_LYFRAC,
+ S_XCROSS,
+ S_YCROSS,
+ S_NOXAXIS,
+ S_NOYAXIS,
+ S_XPORIGIN,
+ S_YPORIGIN,
+ S_TITLE,
+ S_XTITLE,
+ S_YTITLE,
+ S_REPLOT,
+ S_CLEAR,
+ S_STORE,
+ S_RESTORE,
+ S_AMARK,
+ S_NO,
+ S_INTERACTIVE,
+ S_UNITS,
+ S_INCHES,
+ S_USER,
+ S_BOX,
+ S_NOBOX,
+ S_GRID,
+ S_NOGRID,
+ S_MAJOR,
+ S_MINOR,
+ S_COLOR,
+ S_LEGENDBOX,
+ S_TAG,
+ S_TEXTSIZE,
+ };
+
+ static const struct KeywordCodeTable m_sKeywords[];
+ static const int NKEYS;
+
+ std::vector<class EZPlotCurve*> m_vecCurves;
+ std::vector<int> m_veciColor;
+ std::vector<bool> m_vecbColorSet;
+ std::vector<int> m_veciSymbol;
+ std::vector<bool> m_vecbSymbolSet;
+ std::vector<int> m_veciSymbolFreq;
+ std::vector<bool> m_vecbSymbolFreqSet;
+ std::vector<int> m_veciLinestyle;
+ std::vector<bool> m_vecbLinestyleSet;
+ std::vector<std::string> m_vecsLegend;
+ std::vector<bool> m_vecbLegendSet;
+
+ int getColor (unsigned int iCurve) const;
+ int getSymbol (unsigned int iCurve) const;
+ const std::string* getLegend (unsigned int iCurve) const;
+ int getSymbolFreq (unsigned int iCurve) const;
+ int getLinestyle (unsigned int iCurve) const;
+
+ void setColor (unsigned int iCurve, int iColor);
+ void setSymbol (unsigned int iCurve, int iSymbol);
+ void setSymbolFreq (unsigned int iCurve, int iSymbolFreq);
+ void setLinestyle (unsigned int iCurve, int iLinestyle);
+ void setLegend (unsigned int iCurve, const std::string& strLegend);
+ void setLegend (unsigned int iCurve, const char* const pszLegend);
+
+ int m_iCurrentCurve;
+
+ // Colors
+ int clr_axis; // color of all axis lines
+ int clr_title; // color of main title
+ int clr_label; // color of axis labels
+ int clr_legend; // color of legend box
+ int clr_grid; // color of grid lines
+ int clr_number; // color of axis number labels
+
+ // Options
+ double o_xporigin, o_yporigin; // origin of plot frame in NDC
+ double o_xlength, o_ylength; // length of plot frame in NDC
+
+ std::string c_xlabel; // label for x axis
+ std::string c_ylabel; // label for y axis
+ std::string c_title; // title to print above graph
+
+ int o_linestyle, o_color; // style to use for curves all subsequent curves to EZPLOT
+ int o_xaxis, o_yaxis; // Specifies where axis & labels are drawn
+ bool o_grid; // Flag to draw a grid at major ticks
+ bool o_box; // Flag to draw a box around the graph
+
+ int o_xticks, o_yticks; // direction to draw tick marks
+ bool o_xtlabel, o_ytlabel; // TRUE if label tick marks
+
+ int o_xmajortick, o_ymajortick; // number of major ticks to draw
+ int o_xminortick, o_yminortick; // number of minor ticks between major ticks
+
+ int o_symbol; // Symbol type, (0 = no symbol)
+ int o_symfreq; // frequency to draw symbols at curve points
+
+ int o_legendbox; // controls whether legend is inside or outside of the axis extents
+ int o_tag; // controls whether to draw tag at end of axes
+
+ // VALUE & SET variables
+ double v_xmin, v_xmax, v_ymin, v_ymax; // user supplied axis endpoints
+ bool s_xmin, s_xmax, s_ymin, s_ymax; // TRUE is endpoint has been set
+ double v_xtitle, v_ytitle; // NDC position to plot title
+ bool s_xtitle, s_ytitle; // TRUE if set position for title
+ double v_xcross, v_ycross; // position that axes cross
+ bool s_xcross, s_ycross; // TRUE if set axes cross position
+ double v_xlegend, v_ylegend; // upper-left position of legend box in NDC
+ bool s_xlegend, s_ylegend; // TRUE if set position of legend box
+ int v_lxfrac, v_lyfrac; // number of digits to right of decimal place
+ bool s_lxfrac, s_lyfrac; // TRUE if set number of fractional digits
+ double v_textsize; // size of text in NDC
+ bool s_textsize; // TRUE if user set size of text
+
+ // Global variables
+ double charheight; // Height of characters in NDC
+ double charwidth; // Height of characters in NDC
+ double xp_min, xp_max, yp_min, yp_max; // boundry of plot frame in NDC
+ double xa_min, xa_max, ya_min, ya_max; // extent of axes in NDC
+ double xgw_min, xgw_max, ygw_min, ygw_max; // boundary of graph in input coords
+ double xgn_min, xgn_max, ygn_min, ygn_max; // boundy of graph in NDC
+ double xt_min, xt_max, yt_min, yt_max; // boundary of axis ticks
+ double xl_min, xl_max, yl_min, yl_max; // boundary of legend box
+ double title_row; // y-coord of title row
+ double xtl_ofs; // Offset y-coord of x tick labels from axis
+ double ytl_ofs; // Offset x-coord of y tick labels from axis
+ double xlbl_row; // row of x label in world coord
+ double ylbl_col; // column of y label in world coord
+ double xw_tickinc, yw_tickinc; // increment between major ticks in WC
+ double xn_tickinc, yn_tickinc; // increment between major ticks in NDC
+ int x_nint, y_nint; // number of intervals along x & y axes
+ int x_fldwid, x_frac; // numeric field sizes & number of digits
+ int y_fldwid, y_frac; // in fraction of number, used for printf()
+ double xtl_wid, ytl_wid; // length of ticks labels in NDC
+ double tl_height; // height of tick labels in NDC
+ char x_numfmt[20]; // format to print x tick labels
+ char y_numfmt[20]; // format to print y tick labels
+
+ double m_dVP_xmin, m_dVP_ymin;
+ double m_dVP_xmax, m_dVP_ymax;
+ double m_dVP_xscale, m_dVP_yscale;
+ double m_xWorldScale, m_yWorldScale;
+
+ void drawAxes();
+ void symbol (int sym, double symwidth, double symheight);
+ void make_numfmt(char *fmtstr, int *fldwid, int *nfrac, double min, double max, int nint);
+ int axis_scale (double min, double max, int nint, double *minp, double *maxp, int *nintp);
+
+ SGP* m_pSGP;
+ POL m_pol;
+
+ void clearCurves ();
+
+ bool ezcmd (const char* const comm);
+ bool do_cmd(int lx);
+ void bad_option(char *opt);
+ void initPlotSettings();
+
+ void initKeywords ();
+
+ double convertWorldToNDC_X (double x)
+ { return xgn_min + (x - xgw_min) * m_xWorldScale; }
+
+ double convertWorldToNDC_Y (double y)
+ { return ygn_min + (y - ygw_min) * m_yWorldScale; }
+
+ public:
+ EZPlot ();
+ ~EZPlot ();
+
+ bool ezset (const std::string& command);
+ bool ezset (const char* const command);
+
+ void addCurve (const float* x, const double* y, int num);
+ void addCurve (const double* x, const float* y, int num);
+ void addCurve (const double* x, const double* y, int num);
+ void addCurve (const double* y, int n);
+ void addCurve (const float* y, int n);
+
+ void plot (SGP* pSGP);
+};
#endif