00001
00002
00004
00005 #include "GnuPlotterCostObserver.h"
00006
00008
00010
00011 GnuPlotterCostObserver::GnuPlotterCostObserver()
00012 {
00013
00014 }
00015
00016 GnuPlotterCostObserver::~GnuPlotterCostObserver()
00017 {
00018
00019 }
00020
00021 void GnuPlotterCostObserver::Update(Subject *theChangedSubject)
00022 {
00023
00024 CStochasticSensitivityAnalysis *analysis = (CStochasticSensitivityAnalysis *)theChangedSubject;
00025
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
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
00048 sprintf(commandstring,"plot \"%s\" w linespoints\n",buffername);
00049
00050
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 }