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

GnuPlotterCostObserver.cpp

Go to the documentation of this file.
00001 // GnuPlotterCostObserver.cpp: implementation of the GnuPlotterCostObserver class.
00002 //
00004 
00005 #include "GnuPlotterCostObserver.h"
00006 
00008 // Construction/Destruction
00010 
00011 GnuPlotterCostObserver::GnuPlotterCostObserver()
00012 {
00013 
00014 }
00015 
00016 GnuPlotterCostObserver::~GnuPlotterCostObserver()
00017 {
00018 
00019 }
00020 
00021 void GnuPlotterCostObserver::Update(Subject *theChangedSubject)
00022 {
00023         // static cast may be dangerous
00024         CStochasticSensitivityAnalysis *analysis = (CStochasticSensitivityAnalysis *)theChangedSubject;
00025         // set the plot title
00026         char titlestring[100];
00027         char commandstring[1000];
00028         sprintf(titlestring,"set title \"%s\"\n",title);
00029         SendPlotCommand(titlestring);
00030         SendPlotCommand("set grid\n");
00031         SendPlotCommand("set nokey\n");
00032         SendPlotCommand("set xlabel \"Ensemble Index\"\n");
00033         SendPlotCommand("set ylabel \"Rescaled Cost\"\n");
00034 
00035         // write the data to the temporary file
00036         freopen(buffername,"w",buffer);
00037 
00038         for(int i = 0; i < analysis->GetEnsemble()->size(); i++)
00039         {       
00040                 double cost = analysis->GetEnsemble()->at(i)->GetCost();
00041                 int nResid = analysis->GetEnsemble()->at(i)->GetResidualsSize();
00042                 fprintf(buffer,"%i\t\t%e\n",i,cost*nResid);
00043         }
00044         fprintf(buffer,"\n\n");
00045         fflush(buffer);
00046 
00047         // now start sending plot strings
00048         sprintf(commandstring,"plot \"%s\" w linespoints\n",buffername);
00049 
00050         // change single backslashes to forward slashes to keep windows happy
00051 #ifdef _WIN32
00052         int iterator = 0;
00053         while(commandstring[iterator] != '\0')
00054         {
00055                 if(commandstring[iterator] == '\\') {commandstring[iterator] = '/';}
00056                 iterator++;
00057         }
00058 #endif
00059 
00060         SendPlotCommand(commandstring);
00061 
00062         return;
00063 }

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