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

GnuPlotterRunnableObserver.cpp

Go to the documentation of this file.
00001 // GnuPlotterRunnableObserver.cpp: implementation of the GnuPlotterRunnableObserver class.
00002 //
00004 
00005 #include "GnuPlotterRunnableObserver.h"
00006 
00008 // Construction/Destruction
00010 
00011 GnuPlotterRunnableObserver::GnuPlotterRunnableObserver()
00012 {
00013 
00014 }
00015 
00016 GnuPlotterRunnableObserver::~GnuPlotterRunnableObserver()
00017 {
00018 
00019 }
00020 
00021 void GnuPlotterRunnableObserver::AddChemicalNumberToList(int chemNumber)
00022 {
00023         m_viChemNumbers.push_back(chemNumber);
00024 }
00025 
00026 void GnuPlotterRunnableObserver::Update(Subject *theChangedSubject)
00027 {
00028         int i;
00029         // static cast may be dangerous
00030         CRunnable *pRunnable = (CRunnable *)theChangedSubject; 
00031 
00032         // reopen the temp file
00033         freopen(buffername,"w",buffer);
00034 
00035         int maxTime = pRunnable->GetCellObserver()->GetNumberOfTimeSteps();
00036         char titlestring[1000],commandstring[1000];
00037 
00038         // dump the time series data for the chemicals to the temp file
00039         for(i = 0; i < m_viChemNumbers.size(); i++)
00040         {
00041                 for(int t = 0; t < (maxTime-1); t++)
00042                 {
00043                         double time = double (t);
00044                         double sim = pRunnable->GetCellObserver()->GetAverageConcentration()[m_viChemNumbers[i]][t];
00045                         fprintf(buffer,"%e\t\t%e\n",time,sim);
00046                 }
00047                 // pad each series with two newlines
00048                 fprintf(buffer,"\n\n");
00049         }
00050 
00051         sprintf(titlestring,"set title \"%s\"\n",title);
00052         SendPlotCommand(titlestring);
00053         SendPlotCommand("set grid\n");
00054         SendPlotCommand("set xlabel \"time (min)\"\n");
00055         SendPlotCommand("set ylabel \"[Chemical] (molecules)\"\n");
00056         SendPlotCommand("set key\n");
00057         // plot the first chemical manually
00058         char namestring[200];
00059         sprintf(namestring,pRunnable->GetReactionNetwork()->GetChemical(m_viChemNumbers[0])->GetName().c_str());
00060         sprintf(commandstring,"plot \"%s\" index 0 t \"%s\" w lines lw 4",buffername,namestring);
00061         // the rest
00062         for(i = 1; i < m_viChemNumbers.size(); i++)
00063         {
00064                 char tempbuffer[500];
00065                 sprintf(namestring,pRunnable->GetReactionNetwork()->GetChemical(m_viChemNumbers[i])->GetName().c_str());
00066                 sprintf(tempbuffer,",\"%s\" index %i t \"%s\" w lines lw 4",buffername,i,namestring);
00067                 strcat(commandstring,tempbuffer);
00068         }
00069         strcat(commandstring,"\n");
00070         fflush(buffer);
00071         
00072         // change single backslashes to forward slashes to keep windows happy
00073 #ifdef _WIN32
00074         int iterator = 0;
00075         while(commandstring[iterator] != '\0')
00076         {
00077                 if(commandstring[iterator] == '\\') {commandstring[iterator] = '/';}
00078                 iterator++;
00079         }
00080 #endif
00081         
00082         SendPlotCommand(commandstring);
00083 }

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