00001
00002
00004
00005 #include "GnuPlotterEnsembleDataDirectorObserver.h"
00006
00008
00010
00011 GnuPlotterEnsembleDataDirectorObserver::GnuPlotterEnsembleDataDirectorObserver()
00012 {
00013
00014 }
00015
00016 GnuPlotterEnsembleDataDirectorObserver::~GnuPlotterEnsembleDataDirectorObserver()
00017 {
00018
00019 }
00020
00021 void GnuPlotterEnsembleDataDirectorObserver::FixMinimizable(int whichMinimizable)
00022 {
00023 m_iWhichMinimizable = whichMinimizable;
00024 }
00025
00026 void GnuPlotterEnsembleDataDirectorObserver::Update(Subject *theChangedSubject)
00027 {
00028 int i;
00029
00030 CEnsembleCombinationDirector *pDirector = (CEnsembleCombinationDirector *)theChangedSubject;
00031
00032
00033 char titlestring[100];
00034 char commandstring[2000];
00035 sprintf(titlestring,"set title \"%s\"\n",title);
00036 SendPlotCommand(titlestring);
00037 SendPlotCommand("set grid\n");
00038 SendPlotCommand("set xlabel \"time (min)\"\n");
00039
00040 SendPlotCommand("set ylabel \"Concentration/Activity (arb. units)\"\n");
00041
00042
00043 int nTS = pDirector->GetMinimizable(m_iWhichMinimizable)->GetCellObserver()->GetNumberOfTimeSteps();
00044
00045
00046 freopen(buffername,"w",buffer);
00047
00048 std::vector<int> whichSimToPrint;
00049
00050
00051 int nChem = pDirector->GetMinimizable(m_iWhichMinimizable)->GetExperiment()->GetChemicalTimeSeriesData()->GetNChemicals();
00052 int nTimeSeries = pDirector->GetMinimizable(m_iWhichMinimizable)->GetExperiment()->GetChemicalTimeSeriesData()->GetNTimeSeries();
00053 int maxTime = pDirector->GetMinimizable(m_iWhichMinimizable)->GetCellObserver()->GetNumberOfTimeSteps();
00054
00055 std::vector<DataPoint *> nullVector;
00056
00057 for(i = 0; i < nChem; i++)
00058 {
00059 if( (pDirector->GetMinimizable(m_iWhichMinimizable)->GetExperiment()->GetChemicalTimeSeriesData()->GetTimeSeries(i)) != (std::vector<DataPoint *>)0 )
00060 {
00061 whichSimToPrint.push_back(i);
00062 for(int j = 0; j < (pDirector->GetMinimizable(m_iWhichMinimizable)->GetExperiment()->GetChemicalTimeSeriesData()->GetTimeSeries(i)).size(); j++)
00063 {
00064 double time = pDirector->GetMinimizable(m_iWhichMinimizable)->GetExperiment()->GetChemicalTimeSeriesData()->GetTimeSeries(i)[j]->GetTime();
00065 double data = pDirector->GetMinimizable(m_iWhichMinimizable)->GetExperiment()->GetChemicalTimeSeriesData()->GetTimeSeries(i)[j]->GetDatum();
00066 double error = pDirector->GetMinimizable(m_iWhichMinimizable)->GetExperiment()->GetChemicalTimeSeriesData()->GetTimeSeries(i)[j]->GetError();
00067 fprintf(buffer,"%e\t%e\t%e\n",time,data,error);
00068 }
00069 fprintf(buffer,"\n\n");
00070
00071 }
00072 }
00073
00074
00075 for(i = 0; i < whichSimToPrint.size(); i++)
00076 {
00077 for(int t = 0; t < maxTime-1; t++)
00078 {
00079 int target = whichSimToPrint[i];
00080 double time = double (t);
00081 double avg = pDirector->GetDataAverages(m_iWhichMinimizable)[target][t];
00082 double stddev = pDirector->GetDataStdDevs(m_iWhichMinimizable)[target][t];
00083 fprintf(buffer,"%e\t%e\t%e\t%e\n",time,avg,avg+stddev,avg-stddev);
00084 }
00085 fprintf(buffer,"\n\n");
00086 }
00087
00088
00089
00090
00091 char namestring[100];
00092 sprintf(namestring,pDirector->GetMinimizable(m_iWhichMinimizable)->GetExperiment()->GetReactionNetwork()->GetChemical(whichSimToPrint[0])->GetName().c_str());
00093 sprintf(commandstring,"plot \"%s\" index 0 t \"%s\" w errorbars",buffername,namestring);
00094
00095 for(i = 1; i < nTimeSeries; i++)
00096 {
00097 char tempbuffer[200];
00098 sprintf(namestring,pDirector->GetMinimizable(m_iWhichMinimizable)->GetExperiment()->GetReactionNetwork()->GetChemical(whichSimToPrint[i])->GetName().c_str());
00099 sprintf(tempbuffer,",\"%s\" index %i t \"%s\" w errorbars",buffername,i,namestring);
00100 strcat(commandstring,tempbuffer);
00101 }
00102
00103 for(i = nTimeSeries; i < 2*nTimeSeries; i++)
00104 {
00105 char tempbuffer[200];
00106 sprintf(tempbuffer,",\"%s\" index %i notitle w lines lt %i lw 3",buffername,i,i-nTimeSeries+1);
00107 strcat(commandstring,tempbuffer);
00108 for(int j = 3; j < 5; j++)
00109 {
00110 sprintf(tempbuffer,",\"%s\" index %i u 1:%i notitle w lines lt %i",buffername,i,j,i-nTimeSeries+1);
00111 strcat(commandstring,tempbuffer);
00112 }
00113 }
00114 strcat(commandstring,"\n");
00115
00116
00117 #ifdef _WIN32
00118 int iterator = 0;
00119 while(commandstring[iterator] != '\0')
00120 {
00121 if(commandstring[iterator] == '\\') {commandstring[iterator] = '/';}
00122 iterator++;
00123 }
00124 #endif
00125
00126 fflush(buffer);
00127 SendPlotCommand(commandstring);
00128
00129 return;
00130 }