[Avida-SVN] r1988 - branches/energy/source/actions

beckma24 at myxo.css.msu.edu beckma24 at myxo.css.msu.edu
Thu Aug 23 07:33:23 PDT 2007


Author: beckma24
Date: 2007-08-23 10:33:23 -0400 (Thu, 23 Aug 2007)
New Revision: 1988

Modified:
   branches/energy/source/actions/PrintActions.cc
Log:
Added DumpEnergyGrid print action

Modified: branches/energy/source/actions/PrintActions.cc
===================================================================
--- branches/energy/source/actions/PrintActions.cc	2007-08-22 20:15:38 UTC (rev 1987)
+++ branches/energy/source/actions/PrintActions.cc	2007-08-23 14:33:23 UTC (rev 1988)
@@ -2118,6 +2118,35 @@
   }
 };
 
+class cActionDumpEnergyGrid : public cAction
+{
+private:
+  cString m_filename;
+  
+public:
+  cActionDumpEnergyGrid(cWorld* world, const cString& args) : cAction(world, args), m_filename("")
+  {
+    cString largs(args);
+    if (largs.GetSize()) m_filename = largs.PopWord();  
+  }
+  static const cString GetDescription() { return "Arguments: [string fname='']"; }
+  void Process(cAvidaContext& ctx)
+  {
+    cString filename(m_filename);
+    if (filename == "") filename.Set("grid_energy.%d.dat", m_world->GetStats().GetUpdate());
+    ofstream& fp = m_world->GetDataFileOFStream(filename);
+    
+    for (int i = 0; i < m_world->GetPopulation().GetWorldX(); i++) {
+      for (int j = 0; j < m_world->GetPopulation().GetWorldY(); j++) {
+        cPopulationCell& cell = m_world->GetPopulation().GetCell(j * m_world->GetPopulation().GetWorldX() + i);
+        int cell_energy = (cell.IsOccupied()) ? cell.GetOrganism()->GetPhenotype().GetStoredEnergy() : 0.0;
+        fp << cell_energy << " ";
+      }
+      fp << endl;
+    }
+    m_world->GetDataFileManager().Remove(filename);
+  }
+};
 
 class cActionDumpFitnessGrid : public cAction
 {
@@ -2557,6 +2586,7 @@
   action_lib->Register<cActionDumpTaskGrid>("DumpTaskGrid");
   action_lib->Register<cActionDumpDonorGrid>("DumpDonorGrid");
   action_lib->Register<cActionDumpReceiverGrid>("DumpReceiverGrid");
+  action_lib->Register<cActionDumpEnergyGrid>("DumpEnergyGrid");
   
   // Print Settings
   action_lib->Register<cActionSetVerbose>("SetVerbose");




More information about the Avida-cvs mailing list