00001
00002
00008
00009
00010
00012
00013 #ifndef __PLOT_H__
00014 #define __PLOT_H__
00015 #include <string.h>
00016 #include <stdio.h>
00017 #include <fstream.h>
00018 #include "Matrix.h"
00019 namespace O_SESSAME {
00020
00029 class Plot
00030 {
00031 public:
00032 Plot();
00033 virtual ~Plot();
00034 Plot(const Matrix &_data);
00035 Plot(const Matrix &_data, int _cols[], const int &_numCols);
00036 void AddPlot(const Matrix &_data);
00037 void AddPlot(const Matrix &_data, int _cols[], const int &_numCols);
00038
00039 void Title(const char *_titleString);
00040 void Set(const char *_parameterName, const char *_values);
00041 void Command(const char *_stringCommand);
00042 private:
00043 FILE* m_pipeVar;
00044 char* m_dataFilename;
00045
00046 };
00047
00051 static void Plot2D(const Matrix &_data)
00052 {
00053 FILE* pipeVar;
00054 pipeVar = popen("gnuplot","w");
00055 ofstream ofile;
00056 char tmpname[L_tmpnam];
00057 char *filename;
00058 filename = tmpnam(tmpname);
00059 ofile.open(filename);
00060 ofile << _data;
00061 ofile.close();
00062
00063 fprintf(pipeVar, "plot '%s' with linespoints\n", filename);
00064 fflush(pipeVar);
00065 for(int ii = MatrixIndexBase+2;ii < MatrixIndexBase + _data[MatrixColsIndex].getIndexBound();++ii)
00066 {
00067 fprintf(pipeVar, "replot '%s' using 1:%i with linespoints\n", filename, ii);
00068 fflush(pipeVar);
00069 }
00070 fflush(pipeVar);
00071 cout << "Press enter to continue." << flush;
00072 char dummy;
00073 cin >> dummy;
00074 pclose(pipeVar);
00075 return;
00076 }
00077
00078 static void Plot3D(const Matrix &_data)
00079 {
00080 FILE* pipeVar = popen("gnuplot","w");
00081 ofstream ofile;
00082
00083 char tmpname[L_tmpnam];
00084 char *filename;
00085 filename = tmpnam(tmpname);
00086 ofile.open(filename);
00087 ofile << _data;
00088 ofile.close();
00089
00090 fprintf(pipeVar, "splot '%s' with lines\n",filename);
00091 fflush(pipeVar);
00092
00093 cout << "Enter a key and press enter to continue..." << flush;
00094 char dummy;
00095 cin >> dummy;
00096
00097 pclose(pipeVar);
00098 return;
00099 }
00100 }
00101
00102 #endif
00103
00104
00105
00106
00107
00108
00109
00110
00111
00112
00113
00114
00115
00116
00117
00118
00119
00120
00121
00122
00123
00124