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