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
00042
00043
00044
00045 #ifndef GNUGRAPH_H
00046 #define GNUGRAPH_H
00047
00048
00054
00055 static const char header_gnugraph_rcsid[] = "$Id: gnugraph.h,v 1.13 2006/05/16 19:24:26 gourdeau Exp $";
00056
00057 #ifdef _MSC_VER // Microsoft
00058 #pragma warning (disable:4786) // Disable decorated name truncation warnings
00059 #pragma warning (disable:4503) // Disable decorated name truncation warnings
00060 #endif
00061
00062 #if defined(__WIN32__) || defined(_WIN32) || defined(__NT__) || defined(__CYGWIN__)
00063
00064 #define GNUPLOT "wgnuplot.exe"
00065 #define STRICT
00066 #include <windows.h>
00067
00068 #ifdef _MSC_VER
00069 #define snprintf _snprintf
00070 #endif
00071
00072 #else // Unix
00073
00074 #define GNUPLOT "gnuplot"
00075 #include <sys/types.h>
00076 #include <unistd.h>
00077 #endif
00078
00079 #include <stdio.h>
00080 #include <stdexcept>
00081
00082 #include <boost/shared_ptr.hpp>
00083
00084 #define WANT_STRING
00085 #define WANT_STREAM
00086 #define WANT_FSTREAM
00087 #define WANT_MATH
00088
00089 #include "newmatap.h"
00090 #include "newmatio.h"
00091
00092 #ifdef use_namespace
00093 using namespace NEWMAT;
00094 #endif
00095
00096 #include <sys/stat.h>
00097
00098 #include <sstream>
00099 #include <vector>
00100
00101
00102 #define OUT_OF_MEMORY -1
00103 #define X_Y_DATA_NO_MATCH -2
00104 #define LABELS_NBR_NO_MATCH -3
00105
00106
00107
00108 typedef enum {
00109 LINES,
00110 DATAPOINTS,
00111 LINESPOINTS,
00112 IMPULSES,
00113 DOTS,
00114 STEPS,
00115 BOXES
00116 } LineType_en;
00117
00118
00119 #define NCURVESMAX 10 // maximum number of curves in the same Plot2d
00120
00121 class Plot2d;
00122
00127 class GNUcurve {
00128
00129 public:
00130 GNUcurve(const std::vector<double> & x, std::vector<double> & y,
00131 const std::string & label = "", LineType_en enLineType = LINES);
00132 GNUcurve(void);
00133 void dump(void);
00134
00135 std::vector<double> vdX;
00136 std::vector<double> vdY;
00137 std::string clabel;
00138 LineType_en enLineType;
00139 };
00140
00141 typedef boost::shared_ptr<GNUcurve> PSHR_Curve;
00142 typedef std::vector<PSHR_Curve> VectorCurves;
00143
00144
00149 class Plot2d {
00150 public:
00151 Plot2d(void);
00152 void dump(void);
00153 void settitle(const std::string & t);
00154 void setxlabel(const std::string & t);
00155 void setylabel(const std::string & t);
00156 void addcurve(const Matrix & data, const std::string & label = "",
00157 LineType_en enLineType = DATAPOINTS);
00158 void gnuplot(void);
00159 void addcommand(const std::string & gcom);
00160
00161 private:
00162 std::string title;
00163 std::string xlabel;
00164 std::string ylabel;
00165 std::string gnucommand;
00166
00167 VectorCurves vCurves;
00168 };
00169
00174 class Plot3d
00175 {
00176 std::string
00177 title,
00178 xlabel,
00179 ylabel,
00180 zlabel;
00181 public:
00182 Plot3d(){}
00183 void settitle(const std::string & t);
00184 void setxlabel(const std::string & t);
00185 void setylabel(const std::string & t);
00186 void setzlabel(const std::string & t);
00187 void gnuplot(const Matrix & xyz);
00188 };
00189
00190 #define IO_COULD_NOT_OPEN_FILE -1
00191 #define IO_MISMATCH_SIZE -2
00192 #define IO_DATA_EMPTY -3
00193 #define IO_MISMATCH_ELEMENT_NBR -4
00194 #define PROBLEM_FILE_READING -5
00195
00196
00201 class IO_matrix_file {
00202 public:
00203 IO_matrix_file(const std::string & filename);
00204 short write(const std::vector<Matrix> & data);
00205 short write(const std::vector<Matrix> & data, const std::vector<std::string> & title);
00206 short read(std::vector<Matrix> & data);
00207 short read(std::vector<Matrix> & data, std::vector<std::string> & title);
00208 short read_all(std::vector<Matrix> & data, std::vector<std::string> & data_title);
00209 private:
00210 int
00211 position_read,
00212 nb_iterations_write,
00213 nb_iterations_read,
00214 nb_element;
00215 std::string filename;
00216 };
00217
00218
00223 class Plot_file : public IO_matrix_file, Plot2d
00224 {
00225 public:
00226 Plot_file(const std::string & filename);
00227 short graph(const std::string & title_graph, const std::string & label, const short x,
00228 const short y, const short x_start, const short y_start,
00229 const short y_end);
00230 private:
00231 std::vector<Matrix> data_from_file;
00232 std::vector<std::string> data_title;
00233 };
00234
00235
00236
00237 short set_plot2d(const char *title_graph, const char *x_axis_title, const char *y_axis_title,
00238 const char *label, LineType_en enLineType, const Matrix &xdata, const Matrix &ydata,
00239 int start_y, int end_y);
00240
00241 short set_plot2d(const char *title_graph, const char *x_axis_title, const char *y_axis_title,
00242 const vector<char *> label, LineType_en enLineType, const Matrix &xdata,
00243 const Matrix &ydata, const vector<int> & data_select);
00244
00245 short set_plot3d(const Matrix & xyz, const std::string & title_graph, const std::string & x_axis_title,
00246 const std::string & y_axis_title, const std::string & z_axis_title);
00247
00248
00249 #endif
00250