00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041 #ifndef GNUGRAPH_H
00042 #define GNUGRAPH_H
00043
00044
00045
00046
00047
00048
00049
00050
00051 static const char header_gnugraph_rcsid[] = "$Id: gnugraph.h,v 1.1 2004/07/20 17:55:24 ejt Exp $";
00052
00053 #if defined(__WIN32__) || defined(_WIN32) || defined(__NT__) || defined(__CYGWIN__)
00054
00055 #define GNUPLOT "wgnuplot.exe"
00056 #define STRICT
00057 #include <windows.h>
00058
00059 #ifdef _MSC_VER
00060 #define snprintf _snprintf
00061 #endif
00062
00063 #else // Unix
00064
00065 #define GNUPLOT "gnuplot"
00066 #include <sys/types.h>
00067 #include <unistd.h>
00068 #endif
00069
00070 #include "robot.h"
00071 #include <sys/stat.h>
00072
00073 #ifdef __WATCOMC__
00074 #include <strstrea.h>
00075 #else
00076 #include <sstream>
00077 #endif
00078 #include <vector>
00079
00080 #ifdef use_namespace
00081 namespace ROBOOP {
00082 using namespace NEWMAT;
00083 #endif
00084
00085 #define OUT_OF_MEMORY -1
00086 #define X_Y_DATA_NO_MATCH -2
00087 #define LABELS_NBR_NO_MATCH -3
00088
00089 short set_plot2d(const char *title_graph, const char *x_axis_title, const char *y_axis_title,
00090 const char *label, int type, const Matrix &xdata, const Matrix &ydata,
00091 int start_y, int end_y);
00092
00093 short set_plot2d(const char *title_graph, const char *x_axis_title, const char *y_axis_title,
00094 const vector<char *>label, int type, const Matrix &xdata, const Matrix &ydata,
00095 const vector<int> & data_select);
00096
00097
00098
00099
00100 #define LINES 0
00101 #define POINTS 1
00102 #define LINESPOINTS 2
00103 #define IMPULSES 3
00104 #define DOTS 4
00105 #define STEPS 5
00106 #define BOXES 6
00107
00108 #define NCURVESMAX 10 // maximum number of curves in the same Plot2d
00109
00110 class Plot2d;
00111
00112
00113
00114
00115
00116 class GNUcurve {
00117 friend class Plot2d;
00118 Matrix xy;
00119 string clabel;
00120 int ctype;
00121
00122 public:
00123 GNUcurve(const Matrix & data, const string & label = "", int type = LINES);
00124 GNUcurve(void);
00125 GNUcurve(const GNUcurve & gnuc);
00126 GNUcurve & operator=(const GNUcurve & gnuc);
00127 void dump(void);
00128 };
00129
00130
00131
00132
00133
00134
00135 class Plot2d {
00136 string
00137 title,
00138 xlabel,
00139 ylabel;
00140 string gnucommand;
00141 int ncurves;
00142 GNUcurve *curves;
00143 public:
00144 Plot2d(void);
00145 ~Plot2d(void);
00146 void dump(void);
00147 void settitle(const string & t);
00148 void setxlabel(const string & t);
00149 void setylabel(const string & t);
00150 void addcurve(const Matrix & data, const string & label = "", int type = LINES);
00151 void gnuplot(void);
00152 void addcommand(const string & gcom);
00153 };
00154
00155 #define IO_COULD_NOT_OPEN_FILE -1
00156 #define IO_MISMATCH_SIZE -2
00157 #define IO_DATA_EMPTY -3
00158 #define IO_MISMATCH_ELEMENT_NBR -4
00159 #define PROBLEM_FILE_READING -5
00160
00161
00162
00163
00164
00165
00166 class IO_matrix_file {
00167 public:
00168 IO_matrix_file(const string & filename);
00169 short write(const vector<Matrix> & data);
00170 short write(const vector<Matrix> & data, const vector<string> & title);
00171 short read(vector<Matrix> & data);
00172 short read(vector<Matrix> & data, vector<string> & title);
00173 short read_all(vector<Matrix> & data, vector<string> & data_title);
00174 private:
00175 int
00176 position_read,
00177 nb_iterations_write,
00178 nb_iterations_read,
00179 nb_element;
00180 string filename;
00181 };
00182
00183
00184
00185
00186
00187
00188 class Plot_file : public IO_matrix_file, Plot2d
00189 {
00190 public:
00191 Plot_file(const string & filename);
00192 short graph(const string & title_graph, const string & label, const short x,
00193 const short y, const short x_start, const short y_start,
00194 const short y_end);
00195 private:
00196 vector<Matrix> data_from_file;
00197 vector<string> data_title;
00198 };
00199
00200 #ifdef use_namespace
00201 }
00202 #endif
00203
00204 #endif
00205