Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members  

GnuPlotter.cpp

Go to the documentation of this file.
00001 // This plotting program courtesy of M. Rauscher, modifications by K. S. Brown
00002 #include <typeinfo>
00003 #include <math.h>
00004 #include <iostream>
00005 #include <assert.h>
00006 #ifdef _WIN32
00007 #include <windows.h>
00008 #endif //_WIN32
00009 #include "GnuPlotter.h"
00010 #include <string>
00011 #include <stdlib.h>
00012 using namespace std;
00013 
00014 GnuPlotter::GnuPlotter(void) : Observer(), buffername(NULL), gnuplot_pipe(NULL), buffer(NULL)
00015 {
00016         strcpy(title, "");
00017 #ifdef _WIN32
00018                 //gnuplot on dopey.lassp.cornell.edu
00019                 gnuplot_pipe = _popen("C:\\Progra~1\\Gnuplot3.7\\pgnuplot.exe", "w");
00020                 //SendPlotCommand("set terminal windows \"Helvetica\" 18\n");
00021 #else
00022         #ifdef _DEBUG
00023                 char name[128];
00024                 sprintf(name, "tee gnuplot.protocol%d |  gnuplot -geometry 480x360", (int)this);
00025                 gnuplot_pipe = popen(name, "w");
00026         #else
00027                 gnuplot_pipe = popen("gnuplot -geometry 480x360", "w");
00028         #endif // _DEBUG
00029 #endif // _WIN32
00030         if (gnuplot_pipe==NULL) {
00031                 cout << "GnuPlotter::GnuPlotter(): Gnuplot couldn't be opened!" << endl;
00032                 exit(-1);
00033         }
00034 #ifdef _WIN32
00035         buffername=tempnam(NULL, "gnuplotter");
00036         if (buffername==NULL) {
00037                 cout << "GnuPlotter::GnuPlotter(): Buffername couldn't be created!" << endl;
00038                 exit(-1);
00039         }
00040         buffer=fopen(buffername, "w");
00041 #else
00042         strcpy(buffnamevalue, "plots/gnuplotterXXXXXX");
00043         buffername = buffnamevalue;
00044         buffattempt=mkstemp(buffername);
00045         if (buffattempt==-1) {
00046                 cout << "GnuPlotter::GnuPlotter(): Buffername couldn't be created!" << endl;
00047                 exit(-1);
00048         }
00049         buffer=fdopen(buffattempt, "w");
00050 #endif
00051         if (buffer==NULL) {
00052                 cout << "GnuPlotter::GnuPlotter(): Buffer couldn't be created!" << endl;
00053                 exit(-1);
00054         }
00055 }
00056 
00057 GnuPlotter::GnuPlotter(FILE * gplotpipe) : Observer(), buffername(NULL), gnuplot_pipe(gplotpipe)
00058 {
00059     #ifdef _DEBUG
00060                 assert(gnuplot_pipe!=NULL);
00061         #endif //_DEBUG
00062 #ifdef _WIN32
00063         buffername=tempnam(NULL, "gnuplotter");
00064         if (buffername==NULL) {
00065                 cout << "GnuPlotter::GnuPlotter(): Buffername couldn't be created!" << endl;
00066                 exit(-1);
00067         }
00068         buffer=fopen(buffername, "w");
00069 #else
00070         strcpy(buffnamevalue, "plots/gnuplotterXXXXXX");
00071         buffername = buffnamevalue;
00072         buffattempt = mkstemp(buffername);
00073         if (buffattempt==-1) {
00074                 cout << "GnuPlotter::GnuPlotter(): Buffername couldn't be created!" << endl;
00075                 exit(-1);
00076         }
00077         buffer=fdopen(buffattempt, "w");
00078 #endif
00079         if (buffer==NULL) {
00080                 cout << "GnuPlotter::GnuPlotter(): Buffer couldn't be created!" << endl;
00081                 exit(-1);
00082         }
00083 
00084 }
00085 
00086 GnuPlotter::~GnuPlotter(void) { 
00087         if (gnuplot_pipe!=NULL) {
00088                 //cout << "GnuPlotter::~GnuPlotter()" << endl;
00089                 #ifdef _WIN32
00090                         _pclose(gnuplot_pipe);
00091                 #else
00092                         pclose(gnuplot_pipe); 
00093                 #endif //_WIN32
00094         }
00095         if (buffer!=NULL) fclose(buffer);
00096 
00097 }
00098 
00099 bool GnuPlotter::SendPlotCommand(const char* commandstring)
00100 {
00101         if (gnuplot_pipe!=NULL) {
00102                 fprintf(gnuplot_pipe, "%s", commandstring);
00103                 FlushGnuPlotter();
00104                 return(true);
00105         }
00106         else return(false);
00107 }
00108 
00109 

Generated on Mon Nov 3 09:37:51 2003 by doxygen1.2.14 written by Dimitri van Heesch, © 1997-2002