Sophie

Sophie

distrib > Fedora > 18 > x86_64 > media > updates > by-pkgid > 45a94e45036b4f2592a7e2c3922f90c7 > files > 233

adevs-doc-2.6-4.fc18.noarch.rpm

#include "MechPowerListener.h"
using namespace std;
using namespace adevs;

MechPowerListener::MechPowerListener(ElectricalModel* model, double cint, string model_name):
	EventListener<PortValue<BasicEvent*> >(),
	cint(cint),
	fout(string(model_name+"_pm.dat").c_str()),
	t_last(0.0),
	src(model)
{
}

void MechPowerListener::stateChange(Atomic<PortValue<BasicEvent*> >* model, double t)
{
	if (t-t_last >= cint)
	{
		t_last = t;
		fout << t << " ";
		unsigned genrs = src->getElectricalData()->getGenrCount();
		for (unsigned i = 0; i < genrs; i++) 
			fout << src->getMechPower(i) << " ";
		fout << endl;
	}
}

MechPowerListener::~MechPowerListener()
{
	fout.close();
}