00001
00002
00004
00005 #include "GnuPlotterTimeSeriesSharedBFactorObserver.h"
00006
00008
00010
00011 GnuPlotterTimeSeriesSharedBFactorObserver::GnuPlotterTimeSeriesSharedBFactorObserver()
00012 {
00013
00014 }
00015
00016 GnuPlotterTimeSeriesSharedBFactorObserver::~GnuPlotterTimeSeriesSharedBFactorObserver()
00017 {
00018
00019 }
00020
00021
00022
00023
00024
00025
00026 void GnuPlotterTimeSeriesSharedBFactorObserver::Update(Subject *theChangedSubject)
00027 {
00028
00029 SharedBFactorNetworkMinimizable *nM = (SharedBFactorNetworkMinimizable *)theChangedSubject;
00030
00031
00032 char titlestring[100];
00033 char commandstring[1000];
00034 sprintf(titlestring,"set title \"%s\"\n",title);
00035 SendPlotCommand(titlestring);
00036 SendPlotCommand("set grid\n");
00037 SendPlotCommand("set xlabel \"time (min)\"\n");
00038
00039 SendPlotCommand("set ylabel \"Concentration/Activity (arb. units)\"\n");
00040
00041
00042 freopen(buffername,"w",buffer);
00043
00044 std::vector< std::vector<int> *> whichSimToPrint;
00045
00046
00047 int nExp = nM->GetNExp();
00048 whichSimToPrint.reserve(nExp);
00049
00050 std::vector<DataPoint *> nullVector;
00051 std::vector<int > nChem;
00052 std::vector<int > nTimeSeries;
00053
00054 for(int expCounter=0; expCounter < nExp; expCounter++) {
00055 whichSimToPrint.push_back(new std::vector<int >);
00056 nChem.push_back(nM->GetExperiment(expCounter)->GetChemicalTimeSeriesData()->GetNChemicals());
00057 nTimeSeries.push_back(nM->GetExperiment(expCounter)->GetChemicalTimeSeriesData()->GetNTimeSeries());
00058
00059 for(int i = 0; i < nChem[expCounter]; i++)
00060 {
00061 if( (nM->GetExperiment(expCounter)->GetChemicalTimeSeriesData()->GetTimeSeries(i)) != nullVector )
00062 {
00063 whichSimToPrint[expCounter]->push_back(i);
00064 for(int j = 0; j < (nM->GetExperiment(expCounter)->GetChemicalTimeSeriesData()->GetTimeSeries(i)).size(); j++)
00065 {
00066 double time = nM->GetExperiment(expCounter)->GetChemicalTimeSeriesData()->GetTimeSeries(i)[j]->GetTime();
00067 double data = nM->GetExperiment(expCounter)->GetChemicalTimeSeriesData()->GetTimeSeries(i)[j]->GetDatum();
00068 double error = nM->GetExperiment(expCounter)->GetChemicalTimeSeriesData()->GetTimeSeries(i)[j]->GetError();
00069 fprintf(buffer,"%e\t%e\t%e\n",time,data,error);
00070 }
00071 fprintf(buffer,"\n\n");
00072 }
00073 }
00074
00075
00076 int maxTime = nM->GetCellObserver(expCounter)->GetNumberOfTimeSteps();
00077 for(int i = 0; i < whichSimToPrint[expCounter]->size(); i++)
00078 {
00079 for(int j = 0; j < (maxTime-1); j++)
00080 {
00081 int target = (*whichSimToPrint[expCounter])[i];
00082 double time = double (j);
00083 double sim = nM->GetCellObserver(expCounter)->GetAverageConcentration()[target][j];
00084 if(nM->GetConversionFactor(target)->IsFactorNeeded())
00085 {
00086 double scale = nM->GetConversionFactor(target)->GetFactorValue();
00087 sim = sim*scale;
00088 }
00089 fprintf(buffer,"%e\t%e\n",time,sim);
00090 }
00091 fprintf(buffer,"\n\n");
00092 }
00093 }
00094
00095
00096
00097 int index=0;
00098 char namestring[100];
00099 sprintf(namestring,nM->GetExperiment(0)->GetReactionNetwork()->GetChemical((*whichSimToPrint[0])[0])->GetName().c_str());
00100 sprintf(commandstring,"plot \"%s\" index %i t \"%s\" w errorbars lw 2 ps 2",buffername,index,namestring);
00101 index++;
00102
00103
00104 for(int i = 1; i < nTimeSeries[0]; i++)
00105 {
00106 char tempbuffer[200];
00107 sprintf(namestring,nM->GetExperiment(0)->GetReactionNetwork()->GetChemical((*whichSimToPrint[0])[i])->GetName().c_str());
00108 sprintf(tempbuffer,",\"%s\" index %i t \"%s\" w errorbars lw 2 ps 2",buffername,index,namestring);
00109 strcat(commandstring,tempbuffer);
00110 index++;
00111 }
00112
00113
00114 for(int i = 0; i < nTimeSeries[0]; i++)
00115 {
00116 char tempbuffer[200];
00117 sprintf(tempbuffer,",\"%s\" index %i notitle w lines lt %i lw 4",buffername,index,index-nTimeSeries[0]+1);
00118 strcat(commandstring,tempbuffer);
00119 index++;
00120 }
00121
00122 for (int expCounter=1;expCounter < nExp; expCounter++) {
00123
00124 for(int i = 0; i < nTimeSeries[expCounter]; i++)
00125 {
00126 char tempbuffer[200];
00127 sprintf(namestring,nM->GetExperiment(expCounter)->GetReactionNetwork()->GetChemical((*whichSimToPrint[expCounter])[i])->GetName().c_str());
00128 sprintf(tempbuffer,",\"%s\" index %i t \"%s\" w errorbars lw 2 ps 2",buffername,index,namestring);
00129 strcat(commandstring,tempbuffer);
00130 index++;
00131 }
00132
00133 for(int i = 0; i < nTimeSeries[expCounter]; i++)
00134 {
00135 char tempbuffer[200];
00136 sprintf(tempbuffer,",\"%s\" index %i notitle w lines lt %i lw 4",buffername,index,index-nTimeSeries[expCounter]+1);
00137 strcat(commandstring,tempbuffer);
00138 index++;
00139 }
00140
00141 }
00142
00143 strcat(commandstring,"\n");
00144
00145 #ifdef _WIN32
00146 int iterator = 0;
00147 while(commandstring[iterator] != '\0')
00148 {
00149 if(commandstring[iterator] == '\\') {commandstring[iterator] = '/';}
00150 iterator++;
00151 }
00152 #endif
00153
00154 fflush(buffer);
00155 SendPlotCommand(commandstring);
00156
00157 return;
00158 }