00001
00002
00004
00005 #include "GnuPlotterEnsembleRunDirectorObserver.h"
00006
00008
00010
00011 GnuPlotterEnsembleRunDirectorObserver::GnuPlotterEnsembleRunDirectorObserver()
00012 {
00013
00014 }
00015
00016 GnuPlotterEnsembleRunDirectorObserver::~GnuPlotterEnsembleRunDirectorObserver()
00017 {
00018
00019 }
00020
00021 void GnuPlotterEnsembleRunDirectorObserver::AddChemicalToList(int whichChemical)
00022 {
00023 m_viWhichChemicals.push_back(whichChemical);
00024 }
00025
00026 void GnuPlotterEnsembleRunDirectorObserver::FixRunnable(int whichRunnable)
00027 {
00028 m_iWhichRunnable = whichRunnable;
00029 }
00030
00031 void GnuPlotterEnsembleRunDirectorObserver::Update(Subject *theChangedSubject)
00032 {
00033 int i;
00034
00035 CEnsembleCombinationDirector *pDirector = (CEnsembleCombinationDirector *)theChangedSubject;
00036
00037
00038 char titlestring[100];
00039 char commandstring[2000];
00040 sprintf(titlestring,"set title \"%s\"\n",title);
00041 SendPlotCommand(titlestring);
00042 SendPlotCommand("set grid\n");
00043 SendPlotCommand("set xlabel \"time (min)\"\n");
00044
00045 SendPlotCommand("set ylabel \"Concentration/Activity (arb. units)\"\n");
00046
00047
00048 int nTS = pDirector->GetRunnable(m_iWhichRunnable)->GetCellObserver()->GetNumberOfTimeSteps();
00049
00050
00051 freopen(buffername,"w",buffer);
00052
00053
00054 for(int chemCount = 0; chemCount < m_viWhichChemicals.size(); chemCount++)
00055 {
00056 int cIndex = m_viWhichChemicals[chemCount];
00057 for(int t = 0; t < nTS; t++)
00058 {
00059 double time = (double) t;
00060 double avg = pDirector->GetNoDataAverages(m_iWhichRunnable)[cIndex][t];
00061 double stddev = pDirector->GetNoDataStdDevs(m_iWhichRunnable)[cIndex][t];
00062 fprintf(buffer,"%e\t%e\t%e\t%e\n",time,avg,avg+stddev,avg-stddev);
00063 }
00064 fprintf(buffer,"\n\n");
00065 }
00066
00067
00068
00069 char namestring[500];
00070 char tempbuffer[500];
00071
00072
00073
00074 int cIndex = m_viWhichChemicals[0];
00075 int lineType = 1;
00076 int index = 0;
00077 sprintf(namestring,pDirector->GetRunnable(m_iWhichRunnable)->GetReactionNetwork()->GetChemical(cIndex)->GetName().c_str());
00078 sprintf(commandstring,"plot \"%s\" index %i u 1:%i t \"%s\" w lines lw 3",buffername,index,2,namestring);
00079 for(i = 3; i < 5; i++)
00080 {
00081 sprintf(tempbuffer,",\"%s\" index %i u 1:%i notitle w lines lt %i",buffername,index,i,lineType);
00082 strcat(commandstring,tempbuffer);
00083 }
00084
00085 for(int cCount = 1; cCount < m_viWhichChemicals.size(); cCount++)
00086 {
00087 cIndex = m_viWhichChemicals[cCount];
00088 index++;
00089 lineType++;
00090 sprintf(namestring,pDirector->GetRunnable(m_iWhichRunnable)->GetReactionNetwork()->GetChemical(cIndex)->GetName().c_str());
00091 sprintf(tempbuffer,",\"%s\" index %i u 1:%i t \"%s\" w lines lt %i lw 3",buffername,index,2,namestring,lineType);
00092 strcat(commandstring,tempbuffer);
00093 for(i = 3; i < 5; i++)
00094 {
00095 sprintf(tempbuffer,",\"%s\" index %i u 1:%i notitle w lines lt %i",buffername,index,i,lineType);
00096 strcat(commandstring,tempbuffer);
00097 }
00098 }
00099 strcat(commandstring,"\n");
00100
00101
00102 #ifdef _WIN32
00103 int iterator = 0;
00104 while(commandstring[iterator] != '\0')
00105 {
00106 if(commandstring[iterator] == '\\') {commandstring[iterator] = '/';}
00107 iterator++;
00108 }
00109 #endif
00110
00111 fflush(buffer);
00112 SendPlotCommand(commandstring);
00113
00114 return;
00115
00116 }