#include "ns3/gnuplot.h"
#include "ns3/core-module.h"
#include "ns3/network-module.h"
#include "ns3/csma-module.h"
#include "ns3/internet-module.h"
#include "ns3/point-to-point-module.h"
#include "ns3/applications-module.h"
#include "ns3/ipv4-global-routing-helper.h"
#include "ns3/netanim-module.h"
#include "ns3/node.h"
#include "ns3/names.h"
#include "ns3/gnuplot.h"
#include "_anim.h"
#include "_plot.h"
#include "_callback.h"

using namespace std;
using namespace ns3;

extern datasets_t ds; 

void makePlots()
{
	string fileName;
	string graphicsFileName;
	string plotFileName;
	string plotTitle = "RTT";

	vector<string> nodes;
	nodes.push_back("n0");
	nodes.push_back("s");
	nodes.push_back("n2");
	nodes.push_back("n3");
	nodes.push_back("n4");

	for (unsigned int i = 0; i < nodes.size(); i++)
	{
		fileName = "plot" + nodes.at(i);
		graphicsFileName = fileName + ".png";
		plotFileName = fileName + ".plt";
		Gnuplot plot(graphicsFileName);
		std::cout << plotFileName << std::endl;
		std::cout << nodes.size() << std::endl;
		switch(i)
		{
			case 0:
				{
					ds.n0.SetTitle("RTT");
					ds.n0.SetStyle(Gnuplot2dDataset::LINES_POINTS);
					//Gnuplot plot(graphicsFileName);
					plot.AddDataset(ds.n0);
					break;
				}
			case 1:
				{
					ds.s.SetTitle("RTT");
					ds.s.SetStyle(Gnuplot2dDataset::LINES_POINTS);
					//Gnuplot plot(graphicsFileName);
					plot.AddDataset(ds.s);
					break;
				}
			case 2:
				{
					ds.n2.SetTitle("RTT");
					ds.n2.SetStyle(Gnuplot2dDataset::LINES_POINTS);
					//Gnuplot plot(graphicsFileName);
					plot.AddDataset(ds.n2);
					break;
				}
			case 3:
				{
					ds.n3.SetTitle("RTT");
					ds.n3.SetStyle(Gnuplot2dDataset::LINES_POINTS);
					//Gnuplot plot(graphicsFileName);
					plot.AddDataset(ds.n3);
					break;
				}
			case 4:
				{
					ds.n4.SetTitle("RTT");
					ds.n4.SetStyle(Gnuplot2dDataset::LINES_POINTS);
					//Gnuplot plot(graphicsFileName);
					plot.AddDataset(ds.n4);
					break;
				}
		}
		plot.SetTerminal("png");
		plot.SetLegend("Time (s)", "RTT (ms)");
		ofstream plotFile(plotFileName.c_str());
		plot.GenerateOutput(plotFile);
		plotFile.close();
	}	
}
