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

GnuPlotterTimeSeriesObserver.cpp

Go to the documentation of this file.
00001 // GnuPlotterTimeSeriesObserver.cpp: implementation of the GnuPlotterTimeSeriesObserver class.
00002 //
00004 
00005 #include "GnuPlotterTimeSeriesObserver.h"
00006 
00008 // Construction/Destruction
00010 
00011 GnuPlotterTimeSeriesObserver::GnuPlotterTimeSeriesObserver()
00012 {
00013 
00014 }
00015 
00016 GnuPlotterTimeSeriesObserver::~GnuPlotterTimeSeriesObserver()
00017 {
00018 
00019 }
00020 
00021 // default behavior is to plot things in terms of (arbitrary) experimental
00022 // units
00023 
00024 void GnuPlotterTimeSeriesObserver::Update(Subject *theChangedSubject)
00025 {
00026         int i;
00027         // static cast may be dangerous
00028         SingleNetworkMinimizable *nM = (SingleNetworkMinimizable *)theChangedSubject;
00029 
00030         // set the plot title
00031         char titlestring[100];
00032         char commandstring[1000];
00033         sprintf(titlestring,"set title \"%s\"\n",title);
00034         SendPlotCommand(titlestring);
00035         SendPlotCommand("set grid\n");
00036         SendPlotCommand("set xlabel \"time (min)\"\n");
00037         //SendPlotCommand("set ylabel \"[Chemical] (molecules)\"\n");
00038         SendPlotCommand("set ylabel \"Concentration/Activity (arb. units)\"\n");
00039 
00040         // write the experimental data to the temporary file
00041         freopen(buffername,"w",buffer);
00042 
00043         std::vector<int> whichSimToPrint;
00044         // dump blocks of data/simulation to files, separated by double newlines
00045         // EXPERIMENT
00046         int nChem = nM->GetExperiment()->GetChemicalTimeSeriesData()->GetNChemicals();
00047         int nTimeSeries = nM->GetExperiment()->GetChemicalTimeSeriesData()->GetNTimeSeries();
00048 
00049         std::vector<DataPoint *> nullVector;
00050 
00051         for(i = 0; i < nChem; i++)
00052         {
00053                 if( (nM->GetExperiment()->GetChemicalTimeSeriesData()->GetTimeSeries(i)) != nullVector )
00054                 {
00055                         whichSimToPrint.push_back(i);
00056                         for(int j = 0; j < (nM->GetExperiment()->GetChemicalTimeSeriesData()->GetTimeSeries(i)).size(); j++)
00057                         {
00058                                 double time = nM->GetExperiment()->GetChemicalTimeSeriesData()->GetTimeSeries(i)[j]->GetTime();
00059                                 double data = nM->GetExperiment()->GetChemicalTimeSeriesData()->GetTimeSeries(i)[j]->GetDatum();
00060                                 double error = nM->GetExperiment()->GetChemicalTimeSeriesData()->GetTimeSeries(i)[j]->GetError();
00061                                 fprintf(buffer,"%e\t%e\t%e\n",time,data,error);
00062                         }
00063                         fprintf(buffer,"\n\n");
00064 
00065                 }
00066         }
00067 
00068         // SIMULATION
00069         int maxTime = nM->GetCellObserver()->GetNumberOfTimeSteps();
00070         for(i = 0; i < whichSimToPrint.size(); i++)
00071         {
00072                 for(int j = 0; j < (maxTime-1); j++)
00073                 {
00074                         int target = whichSimToPrint[i];
00075                         double time = double (j);
00076                         double sim = nM->GetCellObserver()->GetAverageConcentration()[target][j];
00077                         if(nM->GetConversionFactor(target)->IsFactorNeeded())
00078                         {
00079                                 double scale = nM->GetConversionFactor(target)->GetFactorValue();
00080                                 sim = sim*scale;
00081                         }
00082                         fprintf(buffer,"%e\t%e\n",time,sim);
00083                 }
00084                 fprintf(buffer,"\n\n");
00085         }
00086         
00087         // now plot everything
00088         // first block (done this way to keep the commas straight)
00089         char namestring[100];
00090         sprintf(namestring,nM->GetExperiment()->GetReactionNetwork()->GetChemical(whichSimToPrint[0])->GetName().c_str());
00091         sprintf(commandstring,"plot \"%s\" index 0 t \"%s\" w errorbars lw 2 ps 2",buffername,namestring);
00092         // the rest - experiment first
00093         for(i = 1; i < nTimeSeries; i++)
00094         {
00095                 char tempbuffer[200];
00096                 sprintf(namestring,nM->GetExperiment()->GetReactionNetwork()->GetChemical(whichSimToPrint[i])->GetName().c_str());
00097                 sprintf(tempbuffer,",\"%s\" index %i t \"%s\" w errorbars lw 2 ps 2",buffername,i,namestring);
00098                 strcat(commandstring,tempbuffer);
00099         }
00100         for(i = nTimeSeries; i < 2*nTimeSeries; i++)
00101         {
00102                 char tempbuffer[200];
00103                 sprintf(tempbuffer,",\"%s\" index %i notitle w lines lt %i lw 4",buffername,i,i-nTimeSeries+1);
00104                 strcat(commandstring,tempbuffer);
00105         }
00106         strcat(commandstring,"\n");
00107         
00108         // change single backslashes to forward slashes to keep windows happy
00109 #ifdef _WIN32
00110         int iterator = 0;
00111         while(commandstring[iterator] != '\0')
00112         {
00113                 if(commandstring[iterator] == '\\') {commandstring[iterator] = '/';}
00114                 iterator++;
00115         }
00116 #endif
00117 
00118         fflush(buffer);
00119         SendPlotCommand(commandstring);
00120 
00121         return;
00122 }

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