Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages | Examples

Plot.h

Go to the documentation of this file.
00001 //////////////////////////////////////////////////////////////////////////////////////////////////
00002 /*! \file Plot.h
00003 *  \brief Interface to GNUPLOT (http://www.gnuplot.org)
00004 *  \author $Author: jayhawk_hokie $
00005 *  \version $Revision: 1.2 $
00006 *  \date    $Date: 2005/06/10 12:53:29 $
00007 *//////////////////////////////////////////////////////////////////////////////////////////////////
00008 /* 
00009 * \todo figure out if this can be done w/ 1 instance of gnuplot
00010 */
00011 //////////////////////////////////////////////////////////////////////////////////////////////////
00012 
00013 #ifndef __PLOT_H__
00014 #define __PLOT_H__
00015 #include <string.h>
00016 #include <stdio.h>
00017 #include <fstream>
00018 #include <matrix/Matrix.h>
00019 namespace O_SESSAME {
00020 
00021 /*! \brief A Plot object is used to display data in a 2-D or 3-D plot.
00022 * \ingroup Utilities
00023 *
00024 * \detail Using GnuPlot, this class is a C++ interface to plotting. 
00025 * for a list of GnuPlot commands, visit: http://www.duke.edu/~hpgavin/gnuplot.html or
00026 * http://www.cs.uni.edu/Help/gnuplot/
00027 * \todo Finish documenting API
00028 */
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 
00048 /** Use GnuPlot to plot the data in a matrix
00049     * @param _data Matrix of data, the first column is x, and each of the other columns will be plotted on the y-axis
00050     */
00051 static void Plot2D(const Matrix &_data)
00052 {
00053     FILE* pipeVar;
00054     pipeVar = popen("gnuplot","w");
00055         std::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         std::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.2  2005/06/10 12:53:29  jayhawk_hokie
00108 *       Changed header file format to make it easier to link to the spacecraft code by only having to specify dsacss/dep/spacecraft/src (ex. "file.h" changed to <dir/file.h> where dir is a folder in src).
00109 *       
00110 *       Revision 1.1.1.1  2005/04/26 17:41:00  cakinli
00111 *       Adding OpenSESSAME to DSACSS distrib to capture fixed version.
00112 *       
00113 *       Revision 1.6  2003/10/18 21:37:28  rsharo
00114 *       Removed "../utils" from all qmake project paths. Prepended "utils
00115 *       /" to all #include directives for utils. Removed ".h" extensions from STL header
00116 *       s and referenced STL components from "std::" namespace.  Overall, changed to be
00117 *       more portable.
00118 *       
00119 *       Revision 1.5  2003/05/13 18:58:27  nilspace
00120 *       Cleaned up comments.
00121 *       
00122 *       Revision 1.4  2003/05/01 20:28:19  nilspace
00123 *       Added stdio.h to includes.
00124 *       
00125 *       Revision 1.3  2003/04/27 22:04:34  nilspace
00126 *       Created the namespace O_SESSAME.
00127 *       
00128 *       Revision 1.2  2003/04/23 16:28:38  nilspace
00129 *       Added functionality to general plot functions.
00130 *       
00131 *       Revision 1.1  2003/04/08 22:31:25  nilspace
00132 *       Initial Submission.
00133 *       
00134 *       
00135 *
00136 ******************************************************************************/

Generated on Wed Sep 5 12:54:24 2007 for DSACSS Operational Code by  doxygen 1.3.9.1