Plot.h

Go to the documentation of this file.
00001 
00002 
00008 /* 
00009 * \todo figure out if this can be done w/ 1 instance of gnuplot
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); // pipes are buffered, so flush buffer after you are finished
00071         cout << "Press enter to continue." << flush;
00072         char dummy;
00073         cin >> dummy;
00074         pclose(pipeVar); // close pipe when you are finished with plotting
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); // pipes are buffered, so flush buffer after you are finished
00092         
00093         cout << "Enter a key and press enter to continue..." << flush;
00094         char dummy;
00095         cin >> dummy;
00096         
00097     pclose(pipeVar); // close pipe when you are finished with plotting
00098     return;
00099 }
00100 } // close namespace O_SESSAME
00101 
00102 #endif
00103 
00104 // Do not change the comments below - they will be added automatically by CVS
00105 /*****************************************************************************
00106 *       $Log: Plot.h,v $
00107 *       Revision 1.5  2003/05/13 18:58:27  nilspace
00108 *       Cleaned up comments.
00109 *       
00110 *       Revision 1.4  2003/05/01 20:28:19  nilspace
00111 *       Added stdio.h to includes.
00112 *       
00113 *       Revision 1.3  2003/04/27 22:04:34  nilspace
00114 *       Created the namespace O_SESSAME.
00115 *       
00116 *       Revision 1.2  2003/04/23 16:28:38  nilspace
00117 *       Added functionality to general plot functions.
00118 *       
00119 *       Revision 1.1  2003/04/08 22:31:25  nilspace
00120 *       Initial Submission.
00121 *       
00122 *       
00123 *
00124 ******************************************************************************/

Generated on Wed Aug 6 12:58:50 2003 for Open-Sessame Framework by doxygen1.3