00001 #include "GenrPowerListener.h" 00002 using namespace std; 00003 using namespace adevs; 00004 00005 GenrPowerListener::GenrPowerListener(ElectricalModel* model, double cint, string model_name): 00006 EventListener<PortValue<BasicEvent*> >(), 00007 cint(cint), 00008 fout(string(model_name+"_real_power.dat").c_str()), 00009 t_last(0.0), 00010 src(model) 00011 { 00012 stateChange(model,0.0); 00013 } 00014 00015 void GenrPowerListener::stateChange(Atomic<PortValue<BasicEvent*> >* model, double t) 00016 { 00017 if (t == 0.0 || t-t_last >= cint) 00018 { 00019 t_last = t; 00020 fout << t << " "; 00021 unsigned genrs = src->getElectricalData()->getGenrCount(); 00022 for (unsigned i = 0; i < genrs; i++) 00023 { 00024 fout << src->getRealGenrPower(i) << " "; 00025 } 00026 fout << endl; 00027 } 00028 } 00029 00030 GenrPowerListener::~GenrPowerListener() 00031 { 00032 fout.close(); 00033 } 00034