[Avida-cvs] [Avida2-svn] r314 - in trunk: Avida2.xcodeproj source/bindings/Boost.Python source/cpu source/event source/main source/testsuites/unit_testsuites source/viewers

brysonda@myxo.css.msu.edu brysonda at myxo.css.msu.edu
Thu Sep 15 19:21:09 PDT 2005


Author: brysonda
Date: 2005-09-15 22:10:20 -0400 (Thu, 15 Sep 2005)
New Revision: 314

Added:
   trunk/source/main/cAnalyze.cc
   trunk/source/main/cAnalyze.h
   trunk/source/main/cAnalyzeCommand.h
   trunk/source/main/cAnalyzeCommandDef.h
   trunk/source/main/cAnalyzeCommandDefBase.h
   trunk/source/main/cAnalyzeFlowCommand.h
   trunk/source/main/cAnalyzeFlowCommandDef.h
   trunk/source/main/cAnalyzeFunction.h
   trunk/source/main/cAnalyzeGenotype.cc
   trunk/source/main/cAnalyzeGenotype.h
   trunk/source/main/cAnalyzeUtil.cc
   trunk/source/main/cAnalyzeUtil.h
   trunk/source/main/cAvidaDriver_Analyze.cc
   trunk/source/main/cAvidaDriver_Analyze.h
   trunk/source/main/cAvidaDriver_Base.cc
   trunk/source/main/cAvidaDriver_Base.h
   trunk/source/main/cAvidaDriver_Population.cc
   trunk/source/main/cAvidaDriver_Population.h
   trunk/source/main/cAvidaTriggers.h
   trunk/source/main/cBirthChamber.cc
   trunk/source/main/cBirthChamber.h
   trunk/source/main/cCallbackUtil.cc
   trunk/source/main/cCallbackUtil.h
   trunk/source/main/cConfig.cc
   trunk/source/main/cConfig.h
   trunk/source/main/cEnvironment.cc
   trunk/source/main/cEnvironment.h
   trunk/source/main/cPopulationInterface.cc
   trunk/source/main/cPopulationInterface.h
Removed:
   trunk/source/main/analyze.cc
   trunk/source/main/analyze.hh
   trunk/source/main/analyze_command.hh
   trunk/source/main/analyze_command_def.hh
   trunk/source/main/analyze_command_def_base.hh
   trunk/source/main/analyze_flow_command.hh
   trunk/source/main/analyze_flow_command_def.hh
   trunk/source/main/analyze_function.hh
   trunk/source/main/analyze_genotype.cc
   trunk/source/main/analyze_genotype.hh
   trunk/source/main/analyze_util.cc
   trunk/source/main/analyze_util.hh
   trunk/source/main/avida_driver_analyze.cc
   trunk/source/main/avida_driver_analyze.hh
   trunk/source/main/avida_driver_base.cc
   trunk/source/main/avida_driver_base.hh
   trunk/source/main/avida_driver_population.cc
   trunk/source/main/avida_driver_population.hh
   trunk/source/main/avida_triggers.hh
   trunk/source/main/birth_chamber.cc
   trunk/source/main/birth_chamber.hh
   trunk/source/main/callback_util.cc
   trunk/source/main/callback_util.hh
   trunk/source/main/config.cc
   trunk/source/main/config.hh
   trunk/source/main/environment.cc
   trunk/source/main/environment.hh
   trunk/source/main/population_interface.cc
   trunk/source/main/population_interface.hh
Modified:
   trunk/Avida2.xcodeproj/project.pbxproj
   trunk/source/bindings/Boost.Python/analyze.pyste
   trunk/source/bindings/Boost.Python/analyze_command.pyste
   trunk/source/bindings/Boost.Python/analyze_command_def.pyste
   trunk/source/bindings/Boost.Python/analyze_command_def_base.pyste
   trunk/source/bindings/Boost.Python/analyze_flow_command.pyste
   trunk/source/bindings/Boost.Python/analyze_flow_command_def.pyste
   trunk/source/bindings/Boost.Python/analyze_function.pyste
   trunk/source/bindings/Boost.Python/analyze_genotype.pyste
   trunk/source/bindings/Boost.Python/analyze_util.pyste
   trunk/source/bindings/Boost.Python/avida.pyste
   trunk/source/bindings/Boost.Python/avida_driver_analyze.pyste
   trunk/source/bindings/Boost.Python/avida_driver_base.pyste
   trunk/source/bindings/Boost.Python/avida_driver_population.pyste
   trunk/source/bindings/Boost.Python/avida_triggers.pyste
   trunk/source/bindings/Boost.Python/birth_chamber.pyste
   trunk/source/bindings/Boost.Python/callback_util.pyste
   trunk/source/bindings/Boost.Python/config.pyste
   trunk/source/bindings/Boost.Python/environment.pyste
   trunk/source/bindings/Boost.Python/organism.pyste
   trunk/source/bindings/Boost.Python/phenotype.pyste
   trunk/source/bindings/Boost.Python/population.pyste
   trunk/source/bindings/Boost.Python/population_interface-fixups.hh
   trunk/source/bindings/Boost.Python/py_avida_driver-fixups.cc
   trunk/source/bindings/Boost.Python/py_avida_driver.hh
   trunk/source/bindings/Boost.Python/tList_instantiations.hh
   trunk/source/bindings/Boost.Python/test_cpu.pyste
   trunk/source/cpu/cHardware4Stack.cc
   trunk/source/cpu/cHardwareCPU.cc
   trunk/source/cpu/cHardwareSMT.cc
   trunk/source/cpu/cHardwareUtil.cc
   trunk/source/cpu/cTestCPU.cc
   trunk/source/cpu/cTestUtil.cc
   trunk/source/event/cPopulationEventFactory.cc
   trunk/source/main/CMakeLists.txt
   trunk/source/main/avida.cc
   trunk/source/main/genebank.cc
   trunk/source/main/genotype.cc
   trunk/source/main/inject_genebank.cc
   trunk/source/main/inject_genotype.cc
   trunk/source/main/landscape.cc
   trunk/source/main/lineage_control.cc
   trunk/source/main/main_sub.pri
   trunk/source/main/mx_code_array.cc
   trunk/source/main/organism.cc
   trunk/source/main/organism.hh
   trunk/source/main/phenotype.cc
   trunk/source/main/population.cc
   trunk/source/main/population.hh
   trunk/source/main/population_cell.cc
   trunk/source/main/primitive.cc
   trunk/source/main/resource.cc
   trunk/source/main/resource_count.cc
   trunk/source/main/spatial_res_count.cc
   trunk/source/main/species_control.cc
   trunk/source/main/stats.cc
   trunk/source/testsuites/unit_testsuites/analyze.t.cc
   trunk/source/testsuites/unit_testsuites/analyze_command.t.cc
   trunk/source/testsuites/unit_testsuites/analyze_command_def.t.cc
   trunk/source/testsuites/unit_testsuites/analyze_command_def_base.t.cc
   trunk/source/testsuites/unit_testsuites/analyze_flow_command.t.cc
   trunk/source/testsuites/unit_testsuites/analyze_flow_command_def.t.cc
   trunk/source/testsuites/unit_testsuites/analyze_function.t.cc
   trunk/source/testsuites/unit_testsuites/analyze_genotype.t.cc
   trunk/source/testsuites/unit_testsuites/analyze_util.t.cc
   trunk/source/testsuites/unit_testsuites/avida_driver_analyze.t.cc
   trunk/source/testsuites/unit_testsuites/avida_driver_base.t.cc
   trunk/source/testsuites/unit_testsuites/avida_driver_population.t.cc
   trunk/source/testsuites/unit_testsuites/avida_triggers.t.cc
   trunk/source/testsuites/unit_testsuites/birth_chamber.t.cc
   trunk/source/testsuites/unit_testsuites/callback_util.t.cc
   trunk/source/testsuites/unit_testsuites/config.t.cc
   trunk/source/testsuites/unit_testsuites/environment.t.cc
   trunk/source/testsuites/unit_testsuites/population_interface.t.cc
   trunk/source/viewers/bar_screen.cc
   trunk/source/viewers/environment_screen.cc
   trunk/source/viewers/options_screen.cc
   trunk/source/viewers/stats_screen.cc
   trunk/source/viewers/symbol_util.cc
   trunk/source/viewers/view.cc
   trunk/source/viewers/viewer.cc
   trunk/source/viewers/viewer.hh
   trunk/source/viewers/zoom_screen.cc
Log:
Begin renaming files under main with the new naming conventions.

Modified: trunk/Avida2.xcodeproj/project.pbxproj
===================================================================
--- trunk/Avida2.xcodeproj/project.pbxproj	2005-09-15 23:16:19 UTC (rev 313)
+++ trunk/Avida2.xcodeproj/project.pbxproj	2005-09-16 02:10:20 UTC (rev 314)
@@ -8,23 +8,13 @@
 
 /* Begin PBXBuildFile section */
 		700E2996085A1F6000CF158A /* primitive in CopyFiles */ = {isa = PBXBuildFile; fileRef = DCC3164D07626CF3008F7A48 /* primitive */; };
-		700E2AF6085DE50C00CF158A /* analyze_genotype.cc in Sources */ = {isa = PBXBuildFile; fileRef = DCC310980762539E008F7A48 /* analyze_genotype.cc */; };
-		700E2AF7085DE50C00CF158A /* analyze_util.cc in Sources */ = {isa = PBXBuildFile; fileRef = DCC3109A0762539E008F7A48 /* analyze_util.cc */; };
 		700E2AF8085DE50C00CF158A /* avida.cc in Sources */ = {isa = PBXBuildFile; fileRef = DCC3109C0762539E008F7A48 /* avida.cc */; };
-		700E2AF9085DE50C00CF158A /* avida_driver_analyze.cc in Sources */ = {isa = PBXBuildFile; fileRef = DCC3109E0762539E008F7A48 /* avida_driver_analyze.cc */; };
-		700E2AFA085DE50C00CF158A /* avida_driver_base.cc in Sources */ = {isa = PBXBuildFile; fileRef = DCC310A00762539E008F7A48 /* avida_driver_base.cc */; };
-		700E2AFB085DE50C00CF158A /* avida_driver_population.cc in Sources */ = {isa = PBXBuildFile; fileRef = DCC310A20762539E008F7A48 /* avida_driver_population.cc */; };
-		700E2AFC085DE50C00CF158A /* birth_chamber.cc in Sources */ = {isa = PBXBuildFile; fileRef = DCC310A50762539E008F7A48 /* birth_chamber.cc */; };
-		700E2AFD085DE50C00CF158A /* callback_util.cc in Sources */ = {isa = PBXBuildFile; fileRef = DCC310A70762539E008F7A48 /* callback_util.cc */; };
-		700E2AFE085DE50C00CF158A /* config.cc in Sources */ = {isa = PBXBuildFile; fileRef = DCC310AA0762539E008F7A48 /* config.cc */; };
-		700E2AFF085DE50C00CF158A /* environment.cc in Sources */ = {isa = PBXBuildFile; fileRef = DCC310AC0762539E008F7A48 /* environment.cc */; };
 		700E2B00085DE50C00CF158A /* fitness_matrix.cc in Sources */ = {isa = PBXBuildFile; fileRef = DCC310AE0762539E008F7A48 /* fitness_matrix.cc */; };
 		700E2B01085DE50C00CF158A /* genebank.cc in Sources */ = {isa = PBXBuildFile; fileRef = DCC310C50762539E008F7A48 /* genebank.cc */; };
 		700E2B02085DE50C00CF158A /* genome.cc in Sources */ = {isa = PBXBuildFile; fileRef = DCC310C70762539E008F7A48 /* genome.cc */; };
 		700E2B03085DE50C00CF158A /* genome_util.cc in Sources */ = {isa = PBXBuildFile; fileRef = DCC310C90762539E008F7A48 /* genome_util.cc */; };
 		700E2B04085DE50C00CF158A /* genotype.cc in Sources */ = {isa = PBXBuildFile; fileRef = DCC310CB0762539E008F7A48 /* genotype.cc */; };
 		700E2B05085DE50C00CF158A /* genotype_birth_data.cc in Sources */ = {isa = PBXBuildFile; fileRef = DCC310CE0762539E008F7A48 /* genotype_birth_data.cc */; };
-		700E2B06085DE50C00CF158A /* analyze.cc in Sources */ = {isa = PBXBuildFile; fileRef = DCC310900762539E008F7A48 /* analyze.cc */; };
 		700E2B07085DE50C00CF158A /* genotype_control.cc in Sources */ = {isa = PBXBuildFile; fileRef = DCC310D00762539E008F7A48 /* genotype_control.cc */; };
 		700E2B08085DE50C00CF158A /* genotype_test_data.cc in Sources */ = {isa = PBXBuildFile; fileRef = DCC310D30762539E008F7A48 /* genotype_test_data.cc */; };
 		700E2B09085DE50C00CF158A /* inject_genebank.cc in Sources */ = {isa = PBXBuildFile; fileRef = DCC310D50762539E008F7A48 /* inject_genebank.cc */; };
@@ -47,7 +37,6 @@
 		700E2B1A085DE50C00CF158A /* organism.cc in Sources */ = {isa = PBXBuildFile; fileRef = DCC310FF0762539E008F7A48 /* organism.cc */; };
 		700E2B1B085DE50C00CF158A /* phenotype.cc in Sources */ = {isa = PBXBuildFile; fileRef = DCC311010762539E008F7A48 /* phenotype.cc */; };
 		700E2B1C085DE50C00CF158A /* population.cc in Sources */ = {isa = PBXBuildFile; fileRef = DCC311030762539E008F7A48 /* population.cc */; };
-		700E2B1D085DE50C00CF158A /* population_interface.cc in Sources */ = {isa = PBXBuildFile; fileRef = DCC311070762539E008F7A48 /* population_interface.cc */; };
 		700E2B1E085DE50C00CF158A /* population_cell.cc in Sources */ = {isa = PBXBuildFile; fileRef = DCC311050762539E008F7A48 /* population_cell.cc */; };
 		700E2B1F085DE50C00CF158A /* reaction.cc in Sources */ = {isa = PBXBuildFile; fileRef = DCC3110B0762539E008F7A48 /* reaction.cc */; };
 		700E2B20085DE50C00CF158A /* reaction_lib.cc in Sources */ = {isa = PBXBuildFile; fileRef = DCC3110D0762539E008F7A48 /* reaction_lib.cc */; };
@@ -117,6 +106,28 @@
 		700E2B7C085DE50C00CF158A /* genesis.smt in CopyFiles */ = {isa = PBXBuildFile; fileRef = 706D33100854A7D700D7DC8F /* genesis.smt */; };
 		700E2B7D085DE50C00CF158A /* inst_set.smt in CopyFiles */ = {isa = PBXBuildFile; fileRef = 706D33270854A90D00D7DC8F /* inst_set.smt */; };
 		700E2B87085DE54400CF158A /* viewer in CopyFiles */ = {isa = PBXBuildFile; fileRef = 700E2B83085DE50C00CF158A /* viewer */; };
+		702D4EFE08DA5341007BA469 /* cAvidaDriver_Analyze.cc in Sources */ = {isa = PBXBuildFile; fileRef = 702D4EF908DA5341007BA469 /* cAvidaDriver_Analyze.cc */; };
+		702D4EFF08DA5341007BA469 /* cAvidaDriver_Base.cc in Sources */ = {isa = PBXBuildFile; fileRef = 702D4EFA08DA5341007BA469 /* cAvidaDriver_Base.cc */; };
+		702D4F0008DA5341007BA469 /* cAvidaDriver_Population.cc in Sources */ = {isa = PBXBuildFile; fileRef = 702D4EFB08DA5341007BA469 /* cAvidaDriver_Population.cc */; };
+		702D4F0108DA5341007BA469 /* cEnvironment.cc in Sources */ = {isa = PBXBuildFile; fileRef = 702D4EFC08DA5341007BA469 /* cEnvironment.cc */; };
+		702D4F0208DA5341007BA469 /* cPopulationInterface.cc in Sources */ = {isa = PBXBuildFile; fileRef = 702D4EFD08DA5341007BA469 /* cPopulationInterface.cc */; };
+		702D4F0308DA5341007BA469 /* cAvidaDriver_Analyze.cc in Sources */ = {isa = PBXBuildFile; fileRef = 702D4EF908DA5341007BA469 /* cAvidaDriver_Analyze.cc */; };
+		702D4F0408DA5341007BA469 /* cAvidaDriver_Base.cc in Sources */ = {isa = PBXBuildFile; fileRef = 702D4EFA08DA5341007BA469 /* cAvidaDriver_Base.cc */; };
+		702D4F0508DA5341007BA469 /* cAvidaDriver_Population.cc in Sources */ = {isa = PBXBuildFile; fileRef = 702D4EFB08DA5341007BA469 /* cAvidaDriver_Population.cc */; };
+		702D4F0608DA5341007BA469 /* cEnvironment.cc in Sources */ = {isa = PBXBuildFile; fileRef = 702D4EFC08DA5341007BA469 /* cEnvironment.cc */; };
+		702D4F0708DA5341007BA469 /* cPopulationInterface.cc in Sources */ = {isa = PBXBuildFile; fileRef = 702D4EFD08DA5341007BA469 /* cPopulationInterface.cc */; };
+		702D4F4208DA61FE007BA469 /* cAnalyze.cc in Sources */ = {isa = PBXBuildFile; fileRef = 702D4F3C08DA61FE007BA469 /* cAnalyze.cc */; };
+		702D4F4308DA61FE007BA469 /* cAnalyzeGenotype.cc in Sources */ = {isa = PBXBuildFile; fileRef = 702D4F3D08DA61FE007BA469 /* cAnalyzeGenotype.cc */; };
+		702D4F4408DA61FE007BA469 /* cAnalyzeUtil.cc in Sources */ = {isa = PBXBuildFile; fileRef = 702D4F3E08DA61FE007BA469 /* cAnalyzeUtil.cc */; };
+		702D4F4508DA61FE007BA469 /* cBirthChamber.cc in Sources */ = {isa = PBXBuildFile; fileRef = 702D4F3F08DA61FE007BA469 /* cBirthChamber.cc */; };
+		702D4F4608DA61FE007BA469 /* cCallbackUtil.cc in Sources */ = {isa = PBXBuildFile; fileRef = 702D4F4008DA61FE007BA469 /* cCallbackUtil.cc */; };
+		702D4F4708DA61FE007BA469 /* cConfig.cc in Sources */ = {isa = PBXBuildFile; fileRef = 702D4F4108DA61FE007BA469 /* cConfig.cc */; };
+		702D4F4808DA61FE007BA469 /* cAnalyze.cc in Sources */ = {isa = PBXBuildFile; fileRef = 702D4F3C08DA61FE007BA469 /* cAnalyze.cc */; };
+		702D4F4908DA61FE007BA469 /* cAnalyzeGenotype.cc in Sources */ = {isa = PBXBuildFile; fileRef = 702D4F3D08DA61FE007BA469 /* cAnalyzeGenotype.cc */; };
+		702D4F4A08DA61FE007BA469 /* cAnalyzeUtil.cc in Sources */ = {isa = PBXBuildFile; fileRef = 702D4F3E08DA61FE007BA469 /* cAnalyzeUtil.cc */; };
+		702D4F4B08DA61FE007BA469 /* cBirthChamber.cc in Sources */ = {isa = PBXBuildFile; fileRef = 702D4F3F08DA61FE007BA469 /* cBirthChamber.cc */; };
+		702D4F4C08DA61FE007BA469 /* cCallbackUtil.cc in Sources */ = {isa = PBXBuildFile; fileRef = 702D4F4008DA61FE007BA469 /* cCallbackUtil.cc */; };
+		702D4F4D08DA61FE007BA469 /* cConfig.cc in Sources */ = {isa = PBXBuildFile; fileRef = 702D4F4108DA61FE007BA469 /* cConfig.cc */; };
 		70486BA00826722F009328F0 /* analyze.cfg in CopyFiles */ = {isa = PBXBuildFile; fileRef = DCC3114B0762539E008F7A48 /* analyze.cfg */; };
 		70486BA10826722F009328F0 /* environment.cfg in CopyFiles */ = {isa = PBXBuildFile; fileRef = DCC311800762539F008F7A48 /* environment.cfg */; };
 		70486BA20826722F009328F0 /* events.cfg in CopyFiles */ = {isa = PBXBuildFile; fileRef = DCC311810762539F008F7A48 /* events.cfg */; };
@@ -200,23 +211,13 @@
 		70D46936085F61DF004C8409 /* triostr.c in Sources */ = {isa = PBXBuildFile; fileRef = DCC31474076253A1008F7A48 /* triostr.c */; };
 		70FB868708BFA02D00BDF589 /* tHashTable.hh in CopyFiles */ = {isa = PBXBuildFile; fileRef = 70FB868608BFA02D00BDF589 /* tHashTable.hh */; };
 		70FB868808BFA02D00BDF589 /* tHashTable.hh in CopyFiles */ = {isa = PBXBuildFile; fileRef = 70FB868608BFA02D00BDF589 /* tHashTable.hh */; };
-		DCC3165F0762852D008F7A48 /* analyze_genotype.cc in Sources */ = {isa = PBXBuildFile; fileRef = DCC310980762539E008F7A48 /* analyze_genotype.cc */; };
-		DCC316600762852F008F7A48 /* analyze_util.cc in Sources */ = {isa = PBXBuildFile; fileRef = DCC3109A0762539E008F7A48 /* analyze_util.cc */; };
 		DCC3166107628531008F7A48 /* avida.cc in Sources */ = {isa = PBXBuildFile; fileRef = DCC3109C0762539E008F7A48 /* avida.cc */; };
-		DCC3166207628532008F7A48 /* avida_driver_analyze.cc in Sources */ = {isa = PBXBuildFile; fileRef = DCC3109E0762539E008F7A48 /* avida_driver_analyze.cc */; };
-		DCC3166307628533008F7A48 /* avida_driver_base.cc in Sources */ = {isa = PBXBuildFile; fileRef = DCC310A00762539E008F7A48 /* avida_driver_base.cc */; };
-		DCC3166407628534008F7A48 /* avida_driver_population.cc in Sources */ = {isa = PBXBuildFile; fileRef = DCC310A20762539E008F7A48 /* avida_driver_population.cc */; };
-		DCC3166507628535008F7A48 /* birth_chamber.cc in Sources */ = {isa = PBXBuildFile; fileRef = DCC310A50762539E008F7A48 /* birth_chamber.cc */; };
-		DCC3166607628536008F7A48 /* callback_util.cc in Sources */ = {isa = PBXBuildFile; fileRef = DCC310A70762539E008F7A48 /* callback_util.cc */; };
-		DCC3166707628537008F7A48 /* config.cc in Sources */ = {isa = PBXBuildFile; fileRef = DCC310AA0762539E008F7A48 /* config.cc */; };
-		DCC3166807628538008F7A48 /* environment.cc in Sources */ = {isa = PBXBuildFile; fileRef = DCC310AC0762539E008F7A48 /* environment.cc */; };
 		DCC3166907628539008F7A48 /* fitness_matrix.cc in Sources */ = {isa = PBXBuildFile; fileRef = DCC310AE0762539E008F7A48 /* fitness_matrix.cc */; };
 		DCC3166A0762853A008F7A48 /* genebank.cc in Sources */ = {isa = PBXBuildFile; fileRef = DCC310C50762539E008F7A48 /* genebank.cc */; };
 		DCC3166B0762853B008F7A48 /* genome.cc in Sources */ = {isa = PBXBuildFile; fileRef = DCC310C70762539E008F7A48 /* genome.cc */; };
 		DCC3166C0762853D008F7A48 /* genome_util.cc in Sources */ = {isa = PBXBuildFile; fileRef = DCC310C90762539E008F7A48 /* genome_util.cc */; };
 		DCC3166D0762853E008F7A48 /* genotype.cc in Sources */ = {isa = PBXBuildFile; fileRef = DCC310CB0762539E008F7A48 /* genotype.cc */; };
 		DCC3166E0762853F008F7A48 /* genotype_birth_data.cc in Sources */ = {isa = PBXBuildFile; fileRef = DCC310CE0762539E008F7A48 /* genotype_birth_data.cc */; };
-		DCC3166F07628559008F7A48 /* analyze.cc in Sources */ = {isa = PBXBuildFile; fileRef = DCC310900762539E008F7A48 /* analyze.cc */; };
 		DCC316700762855C008F7A48 /* genotype_control.cc in Sources */ = {isa = PBXBuildFile; fileRef = DCC310D00762539E008F7A48 /* genotype_control.cc */; };
 		DCC316710762855D008F7A48 /* genotype_test_data.cc in Sources */ = {isa = PBXBuildFile; fileRef = DCC310D30762539E008F7A48 /* genotype_test_data.cc */; };
 		DCC316720762855E008F7A48 /* inject_genebank.cc in Sources */ = {isa = PBXBuildFile; fileRef = DCC310D50762539E008F7A48 /* inject_genebank.cc */; };
@@ -239,7 +240,6 @@
 		DCC3168307628570008F7A48 /* organism.cc in Sources */ = {isa = PBXBuildFile; fileRef = DCC310FF0762539E008F7A48 /* organism.cc */; };
 		DCC3168407628571008F7A48 /* phenotype.cc in Sources */ = {isa = PBXBuildFile; fileRef = DCC311010762539E008F7A48 /* phenotype.cc */; };
 		DCC3168507628572008F7A48 /* population.cc in Sources */ = {isa = PBXBuildFile; fileRef = DCC311030762539E008F7A48 /* population.cc */; };
-		DCC3168607628573008F7A48 /* population_interface.cc in Sources */ = {isa = PBXBuildFile; fileRef = DCC311070762539E008F7A48 /* population_interface.cc */; };
 		DCC3168707628574008F7A48 /* population_cell.cc in Sources */ = {isa = PBXBuildFile; fileRef = DCC311050762539E008F7A48 /* population_cell.cc */; };
 		DCC3168807628577008F7A48 /* reaction.cc in Sources */ = {isa = PBXBuildFile; fileRef = DCC3110B0762539E008F7A48 /* reaction.cc */; };
 		DCC3168907628578008F7A48 /* reaction_lib.cc in Sources */ = {isa = PBXBuildFile; fileRef = DCC3110D0762539E008F7A48 /* reaction_lib.cc */; };
@@ -379,6 +379,35 @@
 /* Begin PBXFileReference section */
 		700E28CF0859FFD700CF158A /* tObjectFactory.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = tObjectFactory.h; sourceTree = "<group>"; };
 		700E2B83085DE50C00CF158A /* viewer */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = viewer; sourceTree = BUILT_PRODUCTS_DIR; };
+		702D4EF208DA5328007BA469 /* cAvidaDriver_Analyze.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = cAvidaDriver_Analyze.h; sourceTree = "<group>"; };
+		702D4EF308DA5328007BA469 /* cAvidaDriver_Base.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = cAvidaDriver_Base.h; sourceTree = "<group>"; };
+		702D4EF408DA5328007BA469 /* cAvidaDriver_Population.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = cAvidaDriver_Population.h; sourceTree = "<group>"; };
+		702D4EF508DA5328007BA469 /* cEnvironment.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = cEnvironment.h; sourceTree = "<group>"; };
+		702D4EF608DA5328007BA469 /* cPopulationInterface.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = cPopulationInterface.h; sourceTree = "<group>"; };
+		702D4EF908DA5341007BA469 /* cAvidaDriver_Analyze.cc */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; path = cAvidaDriver_Analyze.cc; sourceTree = "<group>"; };
+		702D4EFA08DA5341007BA469 /* cAvidaDriver_Base.cc */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; path = cAvidaDriver_Base.cc; sourceTree = "<group>"; };
+		702D4EFB08DA5341007BA469 /* cAvidaDriver_Population.cc */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; path = cAvidaDriver_Population.cc; sourceTree = "<group>"; };
+		702D4EFC08DA5341007BA469 /* cEnvironment.cc */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; path = cEnvironment.cc; sourceTree = "<group>"; };
+		702D4EFD08DA5341007BA469 /* cPopulationInterface.cc */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; path = cPopulationInterface.cc; sourceTree = "<group>"; };
+		702D4F2F08DA61E2007BA469 /* cAnalyze.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = cAnalyze.h; sourceTree = "<group>"; };
+		702D4F3008DA61E2007BA469 /* cAnalyzeCommand.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = cAnalyzeCommand.h; sourceTree = "<group>"; };
+		702D4F3108DA61E2007BA469 /* cAnalyzeCommandDef.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = cAnalyzeCommandDef.h; sourceTree = "<group>"; };
+		702D4F3208DA61E2007BA469 /* cAnalyzeCommandDefBase.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = cAnalyzeCommandDefBase.h; sourceTree = "<group>"; };
+		702D4F3308DA61E2007BA469 /* cAnalyzeFlowCommand.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = cAnalyzeFlowCommand.h; sourceTree = "<group>"; };
+		702D4F3408DA61E2007BA469 /* cAnalyzeFlowCommandDef.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = cAnalyzeFlowCommandDef.h; sourceTree = "<group>"; };
+		702D4F3508DA61E2007BA469 /* cAnalyzeFunction.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = cAnalyzeFunction.h; sourceTree = "<group>"; };
+		702D4F3608DA61E2007BA469 /* cAnalyzeGenotype.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = cAnalyzeGenotype.h; sourceTree = "<group>"; };
+		702D4F3708DA61E2007BA469 /* cAnalyzeUtil.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = cAnalyzeUtil.h; sourceTree = "<group>"; };
+		702D4F3808DA61E2007BA469 /* cAvidaTriggers.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = cAvidaTriggers.h; sourceTree = "<group>"; };
+		702D4F3908DA61E2007BA469 /* cBirthChamber.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = cBirthChamber.h; sourceTree = "<group>"; };
+		702D4F3A08DA61E2007BA469 /* cCallbackUtil.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = cCallbackUtil.h; sourceTree = "<group>"; };
+		702D4F3B08DA61E2007BA469 /* cConfig.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = cConfig.h; sourceTree = "<group>"; };
+		702D4F3C08DA61FE007BA469 /* cAnalyze.cc */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; path = cAnalyze.cc; sourceTree = "<group>"; };
+		702D4F3D08DA61FE007BA469 /* cAnalyzeGenotype.cc */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; path = cAnalyzeGenotype.cc; sourceTree = "<group>"; };
+		702D4F3E08DA61FE007BA469 /* cAnalyzeUtil.cc */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; path = cAnalyzeUtil.cc; sourceTree = "<group>"; };
+		702D4F3F08DA61FE007BA469 /* cBirthChamber.cc */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; path = cBirthChamber.cc; sourceTree = "<group>"; };
+		702D4F4008DA61FE007BA469 /* cCallbackUtil.cc */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; path = cCallbackUtil.cc; sourceTree = "<group>"; };
+		702D4F4108DA61FE007BA469 /* cConfig.cc */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; path = cConfig.cc; sourceTree = "<group>"; };
 		703F684207B437B800C1CA76 /* status.xml */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = text.xml; path = status.xml; sourceTree = "<group>"; };
 		70658C59085DF67D00486BED /* libncurses.5.4.dylib */ = {isa = PBXFileReference; lastKnownFileType = "compiled.mach-o.dylib"; name = libncurses.5.4.dylib; path = /usr/lib/libncurses.5.4.dylib; sourceTree = "<absolute>"; };
 		706D30CC0852328F00D7DC8F /* tInstLib.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = tInstLib.h; sourceTree = "<group>"; };
@@ -862,36 +891,9 @@
 		DCC30FCF0762539D008F7A48 /* Doxyfile */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = text; path = Doxyfile; sourceTree = "<group>"; };
 		DCC30FEB0762539D008F7A48 /* CMakeLists.txt */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = text; path = CMakeLists.txt; sourceTree = "<group>"; };
 		DCC30FF00762539D008F7A48 /* event.pri */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = text; path = event.pri; sourceTree = "<group>"; };
-		DCC310900762539E008F7A48 /* analyze.cc */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; path = analyze.cc; sourceTree = "<group>"; };
-		DCC310910762539E008F7A48 /* analyze.hh */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.h; path = analyze.hh; sourceTree = "<group>"; };
-		DCC310920762539E008F7A48 /* analyze_command.hh */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.h; path = analyze_command.hh; sourceTree = "<group>"; };
-		DCC310930762539E008F7A48 /* analyze_command_def.hh */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.h; path = analyze_command_def.hh; sourceTree = "<group>"; };
-		DCC310940762539E008F7A48 /* analyze_command_def_base.hh */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.h; path = analyze_command_def_base.hh; sourceTree = "<group>"; };
-		DCC310950762539E008F7A48 /* analyze_flow_command.hh */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.h; path = analyze_flow_command.hh; sourceTree = "<group>"; };
-		DCC310960762539E008F7A48 /* analyze_flow_command_def.hh */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.h; path = analyze_flow_command_def.hh; sourceTree = "<group>"; };
-		DCC310970762539E008F7A48 /* analyze_function.hh */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.h; path = analyze_function.hh; sourceTree = "<group>"; };
-		DCC310980762539E008F7A48 /* analyze_genotype.cc */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; path = analyze_genotype.cc; sourceTree = "<group>"; };
-		DCC310990762539E008F7A48 /* analyze_genotype.hh */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.h; path = analyze_genotype.hh; sourceTree = "<group>"; };
-		DCC3109A0762539E008F7A48 /* analyze_util.cc */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; path = analyze_util.cc; sourceTree = "<group>"; };
-		DCC3109B0762539E008F7A48 /* analyze_util.hh */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.h; path = analyze_util.hh; sourceTree = "<group>"; };
 		DCC3109C0762539E008F7A48 /* avida.cc */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; path = avida.cc; sourceTree = "<group>"; };
 		DCC3109D0762539E008F7A48 /* avida.hh */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.h; path = avida.hh; sourceTree = "<group>"; };
-		DCC3109E0762539E008F7A48 /* avida_driver_analyze.cc */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; path = avida_driver_analyze.cc; sourceTree = "<group>"; };
-		DCC3109F0762539E008F7A48 /* avida_driver_analyze.hh */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.h; path = avida_driver_analyze.hh; sourceTree = "<group>"; };
-		DCC310A00762539E008F7A48 /* avida_driver_base.cc */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; path = avida_driver_base.cc; sourceTree = "<group>"; };
-		DCC310A10762539E008F7A48 /* avida_driver_base.hh */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.h; path = avida_driver_base.hh; sourceTree = "<group>"; };
-		DCC310A20762539E008F7A48 /* avida_driver_population.cc */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; path = avida_driver_population.cc; sourceTree = "<group>"; };
-		DCC310A30762539E008F7A48 /* avida_driver_population.hh */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.h; path = avida_driver_population.hh; sourceTree = "<group>"; };
-		DCC310A40762539E008F7A48 /* avida_triggers.hh */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.h; path = avida_triggers.hh; sourceTree = "<group>"; };
-		DCC310A50762539E008F7A48 /* birth_chamber.cc */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; path = birth_chamber.cc; sourceTree = "<group>"; };
-		DCC310A60762539E008F7A48 /* birth_chamber.hh */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.h; path = birth_chamber.hh; sourceTree = "<group>"; };
-		DCC310A70762539E008F7A48 /* callback_util.cc */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; path = callback_util.cc; sourceTree = "<group>"; };
-		DCC310A80762539E008F7A48 /* callback_util.hh */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.h; path = callback_util.hh; sourceTree = "<group>"; };
 		DCC310A90762539E008F7A48 /* CMakeLists.txt */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = text; path = CMakeLists.txt; sourceTree = "<group>"; };
-		DCC310AA0762539E008F7A48 /* config.cc */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; path = config.cc; sourceTree = "<group>"; };
-		DCC310AB0762539E008F7A48 /* config.hh */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.h; path = config.hh; sourceTree = "<group>"; };
-		DCC310AC0762539E008F7A48 /* environment.cc */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; path = environment.cc; sourceTree = "<group>"; };
-		DCC310AD0762539E008F7A48 /* environment.hh */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.h; path = environment.hh; sourceTree = "<group>"; };
 		DCC310AE0762539E008F7A48 /* fitness_matrix.cc */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; path = fitness_matrix.cc; sourceTree = "<group>"; };
 		DCC310AF0762539E008F7A48 /* fitness_matrix.hh */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.h; path = fitness_matrix.hh; sourceTree = "<group>"; };
 		DCC310C50762539E008F7A48 /* genebank.cc */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; path = genebank.cc; sourceTree = "<group>"; };
@@ -959,8 +961,6 @@
 		DCC311040762539E008F7A48 /* population.hh */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.h; path = population.hh; sourceTree = "<group>"; };
 		DCC311050762539E008F7A48 /* population_cell.cc */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; path = population_cell.cc; sourceTree = "<group>"; };
 		DCC311060762539E008F7A48 /* population_cell.hh */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.h; path = population_cell.hh; sourceTree = "<group>"; };
-		DCC311070762539E008F7A48 /* population_interface.cc */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; path = population_interface.cc; sourceTree = "<group>"; };
-		DCC311080762539E008F7A48 /* population_interface.hh */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.h; path = population_interface.hh; sourceTree = "<group>"; };
 		DCC311090762539E008F7A48 /* primitive.cc */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; path = primitive.cc; sourceTree = "<group>"; };
 		DCC3110A0762539E008F7A48 /* primitive.hh */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.h; path = primitive.hh; sourceTree = "<group>"; };
 		DCC3110B0762539E008F7A48 /* reaction.cc */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; path = reaction.cc; sourceTree = "<group>"; };
@@ -2047,36 +2047,38 @@
 		DCC310040762539D008F7A48 /* main */ = {
 			isa = PBXGroup;
 			children = (
-				DCC310900762539E008F7A48 /* analyze.cc */,
-				DCC310910762539E008F7A48 /* analyze.hh */,
-				DCC310920762539E008F7A48 /* analyze_command.hh */,
-				DCC310930762539E008F7A48 /* analyze_command_def.hh */,
-				DCC310940762539E008F7A48 /* analyze_command_def_base.hh */,
-				DCC310950762539E008F7A48 /* analyze_flow_command.hh */,
-				DCC310960762539E008F7A48 /* analyze_flow_command_def.hh */,
-				DCC310970762539E008F7A48 /* analyze_function.hh */,
-				DCC310980762539E008F7A48 /* analyze_genotype.cc */,
-				DCC310990762539E008F7A48 /* analyze_genotype.hh */,
-				DCC3109A0762539E008F7A48 /* analyze_util.cc */,
-				DCC3109B0762539E008F7A48 /* analyze_util.hh */,
+				702D4F3C08DA61FE007BA469 /* cAnalyze.cc */,
+				702D4F3D08DA61FE007BA469 /* cAnalyzeGenotype.cc */,
+				702D4F3E08DA61FE007BA469 /* cAnalyzeUtil.cc */,
+				702D4F3F08DA61FE007BA469 /* cBirthChamber.cc */,
+				702D4F4008DA61FE007BA469 /* cCallbackUtil.cc */,
+				702D4F4108DA61FE007BA469 /* cConfig.cc */,
+				702D4F2F08DA61E2007BA469 /* cAnalyze.h */,
+				702D4F3008DA61E2007BA469 /* cAnalyzeCommand.h */,
+				702D4F3108DA61E2007BA469 /* cAnalyzeCommandDef.h */,
+				702D4F3208DA61E2007BA469 /* cAnalyzeCommandDefBase.h */,
+				702D4F3308DA61E2007BA469 /* cAnalyzeFlowCommand.h */,
+				702D4F3408DA61E2007BA469 /* cAnalyzeFlowCommandDef.h */,
+				702D4F3508DA61E2007BA469 /* cAnalyzeFunction.h */,
+				702D4F3608DA61E2007BA469 /* cAnalyzeGenotype.h */,
+				702D4F3708DA61E2007BA469 /* cAnalyzeUtil.h */,
+				702D4F3808DA61E2007BA469 /* cAvidaTriggers.h */,
+				702D4F3908DA61E2007BA469 /* cBirthChamber.h */,
+				702D4F3A08DA61E2007BA469 /* cCallbackUtil.h */,
+				702D4F3B08DA61E2007BA469 /* cConfig.h */,
+				702D4EF908DA5341007BA469 /* cAvidaDriver_Analyze.cc */,
+				702D4EFA08DA5341007BA469 /* cAvidaDriver_Base.cc */,
+				702D4EFB08DA5341007BA469 /* cAvidaDriver_Population.cc */,
+				702D4EFC08DA5341007BA469 /* cEnvironment.cc */,
+				702D4EFD08DA5341007BA469 /* cPopulationInterface.cc */,
+				702D4EF208DA5328007BA469 /* cAvidaDriver_Analyze.h */,
+				702D4EF308DA5328007BA469 /* cAvidaDriver_Base.h */,
+				702D4EF408DA5328007BA469 /* cAvidaDriver_Population.h */,
+				702D4EF508DA5328007BA469 /* cEnvironment.h */,
+				702D4EF608DA5328007BA469 /* cPopulationInterface.h */,
 				DCC3109C0762539E008F7A48 /* avida.cc */,
 				DCC3109D0762539E008F7A48 /* avida.hh */,
-				DCC3109E0762539E008F7A48 /* avida_driver_analyze.cc */,
-				DCC3109F0762539E008F7A48 /* avida_driver_analyze.hh */,
-				DCC310A00762539E008F7A48 /* avida_driver_base.cc */,
-				DCC310A10762539E008F7A48 /* avida_driver_base.hh */,
-				DCC310A20762539E008F7A48 /* avida_driver_population.cc */,
-				DCC310A30762539E008F7A48 /* avida_driver_population.hh */,
-				DCC310A40762539E008F7A48 /* avida_triggers.hh */,
-				DCC310A50762539E008F7A48 /* birth_chamber.cc */,
-				DCC310A60762539E008F7A48 /* birth_chamber.hh */,
-				DCC310A70762539E008F7A48 /* callback_util.cc */,
-				DCC310A80762539E008F7A48 /* callback_util.hh */,
 				DCC310A90762539E008F7A48 /* CMakeLists.txt */,
-				DCC310AA0762539E008F7A48 /* config.cc */,
-				DCC310AB0762539E008F7A48 /* config.hh */,
-				DCC310AC0762539E008F7A48 /* environment.cc */,
-				DCC310AD0762539E008F7A48 /* environment.hh */,
 				DCC310AE0762539E008F7A48 /* fitness_matrix.cc */,
 				DCC310AF0762539E008F7A48 /* fitness_matrix.hh */,
 				DCC310B00762539E008F7A48 /* functional_testsuites */,
@@ -2145,8 +2147,6 @@
 				DCC311040762539E008F7A48 /* population.hh */,
 				DCC311050762539E008F7A48 /* population_cell.cc */,
 				DCC311060762539E008F7A48 /* population_cell.hh */,
-				DCC311070762539E008F7A48 /* population_interface.cc */,
-				DCC311080762539E008F7A48 /* population_interface.hh */,
 				DCC311090762539E008F7A48 /* primitive.cc */,
 				DCC3110A0762539E008F7A48 /* primitive.hh */,
 				DCC3110B0762539E008F7A48 /* reaction.cc */,
@@ -3043,23 +3043,13 @@
 			isa = PBXSourcesBuildPhase;
 			buildActionMask = 2147483647;
 			files = (
-				700E2AF6085DE50C00CF158A /* analyze_genotype.cc in Sources */,
-				700E2AF7085DE50C00CF158A /* analyze_util.cc in Sources */,
 				700E2AF8085DE50C00CF158A /* avida.cc in Sources */,
-				700E2AF9085DE50C00CF158A /* avida_driver_analyze.cc in Sources */,
-				700E2AFA085DE50C00CF158A /* avida_driver_base.cc in Sources */,
-				700E2AFB085DE50C00CF158A /* avida_driver_population.cc in Sources */,
-				700E2AFC085DE50C00CF158A /* birth_chamber.cc in Sources */,
-				700E2AFD085DE50C00CF158A /* callback_util.cc in Sources */,
-				700E2AFE085DE50C00CF158A /* config.cc in Sources */,
-				700E2AFF085DE50C00CF158A /* environment.cc in Sources */,
 				700E2B00085DE50C00CF158A /* fitness_matrix.cc in Sources */,
 				700E2B01085DE50C00CF158A /* genebank.cc in Sources */,
 				700E2B02085DE50C00CF158A /* genome.cc in Sources */,
 				700E2B03085DE50C00CF158A /* genome_util.cc in Sources */,
 				700E2B04085DE50C00CF158A /* genotype.cc in Sources */,
 				700E2B05085DE50C00CF158A /* genotype_birth_data.cc in Sources */,
-				700E2B06085DE50C00CF158A /* analyze.cc in Sources */,
 				700E2B07085DE50C00CF158A /* genotype_control.cc in Sources */,
 				700E2B08085DE50C00CF158A /* genotype_test_data.cc in Sources */,
 				700E2B09085DE50C00CF158A /* inject_genebank.cc in Sources */,
@@ -3082,7 +3072,6 @@
 				700E2B1A085DE50C00CF158A /* organism.cc in Sources */,
 				700E2B1B085DE50C00CF158A /* phenotype.cc in Sources */,
 				700E2B1C085DE50C00CF158A /* population.cc in Sources */,
-				700E2B1D085DE50C00CF158A /* population_interface.cc in Sources */,
 				700E2B1E085DE50C00CF158A /* population_cell.cc in Sources */,
 				700E2B1F085DE50C00CF158A /* reaction.cc in Sources */,
 				700E2B20085DE50C00CF158A /* reaction_lib.cc in Sources */,
@@ -3174,6 +3163,17 @@
 				70C1F19A08C6A11100F50912 /* cEventListIterator.cc in Sources */,
 				70C1F19B08C6A11100F50912 /* cEventTriggers.cc in Sources */,
 				70C1F19C08C6A11100F50912 /* cPopulationEventFactory.cc in Sources */,
+				702D4F0308DA5341007BA469 /* cAvidaDriver_Analyze.cc in Sources */,
+				702D4F0408DA5341007BA469 /* cAvidaDriver_Base.cc in Sources */,
+				702D4F0508DA5341007BA469 /* cAvidaDriver_Population.cc in Sources */,
+				702D4F0608DA5341007BA469 /* cEnvironment.cc in Sources */,
+				702D4F0708DA5341007BA469 /* cPopulationInterface.cc in Sources */,
+				702D4F4808DA61FE007BA469 /* cAnalyze.cc in Sources */,
+				702D4F4908DA61FE007BA469 /* cAnalyzeGenotype.cc in Sources */,
+				702D4F4A08DA61FE007BA469 /* cAnalyzeUtil.cc in Sources */,
+				702D4F4B08DA61FE007BA469 /* cBirthChamber.cc in Sources */,
+				702D4F4C08DA61FE007BA469 /* cCallbackUtil.cc in Sources */,
+				702D4F4D08DA61FE007BA469 /* cConfig.cc in Sources */,
 			);
 			runOnlyForDeploymentPostprocessing = 0;
 		};
@@ -3181,23 +3181,13 @@
 			isa = PBXSourcesBuildPhase;
 			buildActionMask = 2147483647;
 			files = (
-				DCC3165F0762852D008F7A48 /* analyze_genotype.cc in Sources */,
-				DCC316600762852F008F7A48 /* analyze_util.cc in Sources */,
 				DCC3166107628531008F7A48 /* avida.cc in Sources */,
-				DCC3166207628532008F7A48 /* avida_driver_analyze.cc in Sources */,
-				DCC3166307628533008F7A48 /* avida_driver_base.cc in Sources */,
-				DCC3166407628534008F7A48 /* avida_driver_population.cc in Sources */,
-				DCC3166507628535008F7A48 /* birth_chamber.cc in Sources */,
-				DCC3166607628536008F7A48 /* callback_util.cc in Sources */,
-				DCC3166707628537008F7A48 /* config.cc in Sources */,
-				DCC3166807628538008F7A48 /* environment.cc in Sources */,
 				DCC3166907628539008F7A48 /* fitness_matrix.cc in Sources */,
 				DCC3166A0762853A008F7A48 /* genebank.cc in Sources */,
 				DCC3166B0762853B008F7A48 /* genome.cc in Sources */,
 				DCC3166C0762853D008F7A48 /* genome_util.cc in Sources */,
 				DCC3166D0762853E008F7A48 /* genotype.cc in Sources */,
 				DCC3166E0762853F008F7A48 /* genotype_birth_data.cc in Sources */,
-				DCC3166F07628559008F7A48 /* analyze.cc in Sources */,
 				DCC316700762855C008F7A48 /* genotype_control.cc in Sources */,
 				DCC316710762855D008F7A48 /* genotype_test_data.cc in Sources */,
 				DCC316720762855E008F7A48 /* inject_genebank.cc in Sources */,
@@ -3220,7 +3210,6 @@
 				DCC3168307628570008F7A48 /* organism.cc in Sources */,
 				DCC3168407628571008F7A48 /* phenotype.cc in Sources */,
 				DCC3168507628572008F7A48 /* population.cc in Sources */,
-				DCC3168607628573008F7A48 /* population_interface.cc in Sources */,
 				DCC3168707628574008F7A48 /* population_cell.cc in Sources */,
 				DCC3168807628577008F7A48 /* reaction.cc in Sources */,
 				DCC3168907628578008F7A48 /* reaction_lib.cc in Sources */,
@@ -3302,6 +3291,17 @@
 				70C1F19508C6A11100F50912 /* cEventListIterator.cc in Sources */,
 				70C1F19608C6A11100F50912 /* cEventTriggers.cc in Sources */,
 				70C1F19708C6A11100F50912 /* cPopulationEventFactory.cc in Sources */,
+				702D4EFE08DA5341007BA469 /* cAvidaDriver_Analyze.cc in Sources */,
+				702D4EFF08DA5341007BA469 /* cAvidaDriver_Base.cc in Sources */,
+				702D4F0008DA5341007BA469 /* cAvidaDriver_Population.cc in Sources */,
+				702D4F0108DA5341007BA469 /* cEnvironment.cc in Sources */,
+				702D4F0208DA5341007BA469 /* cPopulationInterface.cc in Sources */,
+				702D4F4208DA61FE007BA469 /* cAnalyze.cc in Sources */,
+				702D4F4308DA61FE007BA469 /* cAnalyzeGenotype.cc in Sources */,
+				702D4F4408DA61FE007BA469 /* cAnalyzeUtil.cc in Sources */,
+				702D4F4508DA61FE007BA469 /* cBirthChamber.cc in Sources */,
+				702D4F4608DA61FE007BA469 /* cCallbackUtil.cc in Sources */,
+				702D4F4708DA61FE007BA469 /* cConfig.cc in Sources */,
 			);
 			runOnlyForDeploymentPostprocessing = 0;
 		};

Modified: trunk/source/bindings/Boost.Python/analyze.pyste
===================================================================
--- trunk/source/bindings/Boost.Python/analyze.pyste	2005-09-15 23:16:19 UTC (rev 313)
+++ trunk/source/bindings/Boost.Python/analyze.pyste	2005-09-16 02:10:20 UTC (rev 314)
@@ -1,7 +1,7 @@
-Include("environment.hh")
+Include("cEnvironment.h")
 
-Include("environment.hh")
+Include("cEnvironment.h")
 
-cAnalyze = Class("cAnalyze", "analyze.hh")
+cAnalyze = Class("cAnalyze", "cAnalyze.h")
 
 # vim: set ft=python:

Modified: trunk/source/bindings/Boost.Python/analyze_command.pyste
===================================================================
--- trunk/source/bindings/Boost.Python/analyze_command.pyste	2005-09-15 23:16:19 UTC (rev 313)
+++ trunk/source/bindings/Boost.Python/analyze_command.pyste	2005-09-16 02:10:20 UTC (rev 314)
@@ -1,7 +1,7 @@
 
 Include("tList.hh")
 
-cAnalyzeCommand = Class("cAnalyzeCommand", "analyze_command.hh")
+cAnalyzeCommand = Class("cAnalyzeCommand", "cAnalyzeCommand.h")
 set_policy(cAnalyzeCommand.GetCommandList, return_internal_reference())
 
 # vim: set ft=python:

Modified: trunk/source/bindings/Boost.Python/analyze_command_def.pyste
===================================================================
--- trunk/source/bindings/Boost.Python/analyze_command_def.pyste	2005-09-15 23:16:19 UTC (rev 313)
+++ trunk/source/bindings/Boost.Python/analyze_command_def.pyste	2005-09-16 02:10:20 UTC (rev 314)
@@ -1,4 +1,4 @@
 Import("analyze_command_def_base.pyste")
-cAnalyzeCommandDef = Class("cAnalyzeCommandDef", "analyze_command_def.hh")
+cAnalyzeCommandDef = Class("cAnalyzeCommandDef", "cAnalyzeCommandDef.h")
 
 # vim: set ft=python:

Modified: trunk/source/bindings/Boost.Python/analyze_command_def_base.pyste
===================================================================
--- trunk/source/bindings/Boost.Python/analyze_command_def_base.pyste	2005-09-15 23:16:19 UTC (rev 313)
+++ trunk/source/bindings/Boost.Python/analyze_command_def_base.pyste	2005-09-16 02:10:20 UTC (rev 314)
@@ -1,6 +1,6 @@
-Include("analyze.hh")
-Include("analyze_command.hh")
+Include("cAnalyze.h")
+Include("cAnalyzeCommand.h")
 
-cAnalyzeCommandDefBase = Class("cAnalyzeCommandDefBase", "analyze_command_def_base.hh")
+cAnalyzeCommandDefBase = Class("cAnalyzeCommandDefBase", "cAnalyzeCommandDefBase.h")
 
 # vim: set ft=python:

Modified: trunk/source/bindings/Boost.Python/analyze_flow_command.pyste
===================================================================
--- trunk/source/bindings/Boost.Python/analyze_flow_command.pyste	2005-09-15 23:16:19 UTC (rev 313)
+++ trunk/source/bindings/Boost.Python/analyze_flow_command.pyste	2005-09-16 02:10:20 UTC (rev 314)
@@ -1,7 +1,7 @@
 
 Import("analyze_command.pyste")
 
-cAnalyzeFlowCommand = Class("cAnalyzeFlowCommand", "analyze_flow_command.hh")
+cAnalyzeFlowCommand = Class("cAnalyzeFlowCommand", "cAnalyzeFlowCommand.h")
 set_policy(cAnalyzeFlowCommand.GetCommandList, return_internal_reference())
 
 # vim: set ft=python:

Modified: trunk/source/bindings/Boost.Python/analyze_flow_command_def.pyste
===================================================================
--- trunk/source/bindings/Boost.Python/analyze_flow_command_def.pyste	2005-09-15 23:16:19 UTC (rev 313)
+++ trunk/source/bindings/Boost.Python/analyze_flow_command_def.pyste	2005-09-16 02:10:20 UTC (rev 314)
@@ -1,4 +1,4 @@
 Import("analyze_command_def_base.pyste")
-cAnalyzeFlowCommandDef = Class("cAnalyzeFlowCommandDef", "analyze_flow_command_def.hh")
+cAnalyzeFlowCommandDef = Class("cAnalyzeFlowCommandDef", "cAnalyzeFlowCommandDef.h")
 
 # vim: set ft=python:

Modified: trunk/source/bindings/Boost.Python/analyze_function.pyste
===================================================================
--- trunk/source/bindings/Boost.Python/analyze_function.pyste	2005-09-15 23:16:19 UTC (rev 313)
+++ trunk/source/bindings/Boost.Python/analyze_function.pyste	2005-09-16 02:10:20 UTC (rev 314)
@@ -1,5 +1,5 @@
 
-cAnalyzeFunction = Class("cAnalyzeFunction", "analyze_function.hh")
+cAnalyzeFunction = Class("cAnalyzeFunction", "cAnalyzeFunction.h")
 set_policy(cAnalyzeFunction.GetCommandList, return_internal_reference())
 
 # vim: set ft=python:

Modified: trunk/source/bindings/Boost.Python/analyze_genotype.pyste
===================================================================
--- trunk/source/bindings/Boost.Python/analyze_genotype.pyste	2005-09-15 23:16:19 UTC (rev 313)
+++ trunk/source/bindings/Boost.Python/analyze_genotype.pyste	2005-09-16 02:10:20 UTC (rev 314)
@@ -1,5 +1,5 @@
 Include("inst_set.hh")
 
-cAnalyzeGenotype = Class("cAnalyzeGenotype", "analyze_genotype.hh")
+cAnalyzeGenotype = Class("cAnalyzeGenotype", "cAnalyzeGenotype.h")
 
 # vim: set ft=python:

Modified: trunk/source/bindings/Boost.Python/analyze_util.pyste
===================================================================
--- trunk/source/bindings/Boost.Python/analyze_util.pyste	2005-09-15 23:16:19 UTC (rev 313)
+++ trunk/source/bindings/Boost.Python/analyze_util.pyste	2005-09-16 02:10:20 UTC (rev 314)
@@ -2,6 +2,6 @@
 Include("genome.hh")
 Include("inst_set.hh")
 
-cAnalyzeUtil = Class("cAnalyzeUtil", "analyze_util.hh")
+cAnalyzeUtil = Class("cAnalyzeUtil", "cAnalyzeUtil.h")
 
 # vim: set ft=python:

Modified: trunk/source/bindings/Boost.Python/avida.pyste
===================================================================
--- trunk/source/bindings/Boost.Python/avida.pyste	2005-09-15 23:16:19 UTC (rev 313)
+++ trunk/source/bindings/Boost.Python/avida.pyste	2005-09-16 02:10:20 UTC (rev 314)
@@ -1,9 +1,9 @@
 declaration_code("""
 #ifndef ENVIRONMENT_HH
-#include "environment.hh"
+#include "cEnvironment.h"
 #endif
 #ifndef POPULATION_INTERFACE_HH
-#include "population_interface.hh"
+#include "cPopulationInterface.h"
 #endif
 """)
 

Modified: trunk/source/bindings/Boost.Python/avida_driver_analyze.pyste
===================================================================
--- trunk/source/bindings/Boost.Python/avida_driver_analyze.pyste	2005-09-15 23:16:19 UTC (rev 313)
+++ trunk/source/bindings/Boost.Python/avida_driver_analyze.pyste	2005-09-16 02:10:20 UTC (rev 314)
@@ -1,8 +1,8 @@
 Import("avida_driver_base.pyste")
 
-Include("environment.hh")
+Include("cEnvironment.h")
 Include("string.hh")
 
-cAvidaDriver_Analyze = Class("cAvidaDriver_Analyze", "avida_driver_analyze.hh")
+cAvidaDriver_Analyze = Class("cAvidaDriver_Analyze", "cAvidaDriver_Analyze.h")
 
 # vim: set ft=python:

Modified: trunk/source/bindings/Boost.Python/avida_driver_base.pyste
===================================================================
--- trunk/source/bindings/Boost.Python/avida_driver_base.pyste	2005-09-15 23:16:19 UTC (rev 313)
+++ trunk/source/bindings/Boost.Python/avida_driver_base.pyste	2005-09-16 02:10:20 UTC (rev 314)
@@ -4,6 +4,6 @@
 #endif
 """)
 
-cAvidaDriver_Base = Class("cAvidaDriver_Base", "avida_driver_base.hh")
+cAvidaDriver_Base = Class("cAvidaDriver_Base", "cAvidaDriver_Base.h")
 
 # vim: set ft=python:

Modified: trunk/source/bindings/Boost.Python/avida_driver_population.pyste
===================================================================
--- trunk/source/bindings/Boost.Python/avida_driver_population.pyste	2005-09-15 23:16:19 UTC (rev 313)
+++ trunk/source/bindings/Boost.Python/avida_driver_population.pyste	2005-09-16 02:10:20 UTC (rev 314)
@@ -1,11 +1,11 @@
 
 Include("change_list.hh")
-Include("environment.hh")
+Include("cEnvironment.h")
 Include("population.hh")
 
 Import("avida_driver_base.pyste")
 
-cAvidaDriver_Population = Class("cAvidaDriver_Population", "avida_driver_population.hh")
+cAvidaDriver_Population = Class("cAvidaDriver_Population", "cAvidaDriver_Population.h")
 set_policy(cAvidaDriver_Population.GetPopulation, return_internal_reference())
 
 exclude(cAvidaDriver_Population.GetChangeList)

Modified: trunk/source/bindings/Boost.Python/avida_triggers.pyste
===================================================================
--- trunk/source/bindings/Boost.Python/avida_triggers.pyste	2005-09-15 23:16:19 UTC (rev 313)
+++ trunk/source/bindings/Boost.Python/avida_triggers.pyste	2005-09-16 02:10:20 UTC (rev 314)
@@ -1,6 +1,6 @@
 
 Import("event_triggers.pyste")
 
-cAvidaTriggers = Class("cAvidaTriggers", "avida_triggers.hh")
+cAvidaTriggers = Class("cAvidaTriggers", "cAvidaTriggers.h")
 
 # vim: set ft=python:

Modified: trunk/source/bindings/Boost.Python/birth_chamber.pyste
===================================================================
--- trunk/source/bindings/Boost.Python/birth_chamber.pyste	2005-09-15 23:16:19 UTC (rev 313)
+++ trunk/source/bindings/Boost.Python/birth_chamber.pyste	2005-09-16 02:10:20 UTC (rev 314)
@@ -2,6 +2,6 @@
 Include("organism.hh")
 Include("genebank.hh")
 
-cBirthChamber = Class("cBirthChamber", "birth_chamber.hh")
+cBirthChamber = Class("cBirthChamber", "cBirthChamber.h")
 
 # vim: set ft=python:

Modified: trunk/source/bindings/Boost.Python/callback_util.pyste
===================================================================
--- trunk/source/bindings/Boost.Python/callback_util.pyste	2005-09-15 23:16:19 UTC (rev 313)
+++ trunk/source/bindings/Boost.Python/callback_util.pyste	2005-09-16 02:10:20 UTC (rev 314)
@@ -1,4 +1,4 @@
 
-cCallbackUtil = Class("cCallbackUtil", "callback_util.hh")
+cCallbackUtil = Class("cCallbackUtil", "cCallbackUtil.h")
 
 # vim: set ft=python:

Modified: trunk/source/bindings/Boost.Python/config.pyste
===================================================================
--- trunk/source/bindings/Boost.Python/config.pyste	2005-09-15 23:16:19 UTC (rev 313)
+++ trunk/source/bindings/Boost.Python/config.pyste	2005-09-16 02:10:20 UTC (rev 314)
@@ -1,5 +1,5 @@
 
-cConfig = Class("cConfig", "config.hh")
+cConfig = Class("cConfig", "cConfig.h")
 
 set_policy(cConfig.GetDefaultDir, return_value_policy(reference_existing_object))
 set_policy(cConfig.GetGenesisFilename, return_value_policy(reference_existing_object))

Modified: trunk/source/bindings/Boost.Python/environment.pyste
===================================================================
--- trunk/source/bindings/Boost.Python/environment.pyste	2005-09-15 23:16:19 UTC (rev 313)
+++ trunk/source/bindings/Boost.Python/environment.pyste	2005-09-16 02:10:20 UTC (rev 314)
@@ -1,7 +1,7 @@
 
 Include("reaction_result.hh")
 
-cEnvironment = Class("cEnvironment", "environment.hh")
+cEnvironment = Class("cEnvironment", "cEnvironment.h")
 
 set_policy(cEnvironment.GetResourceLib, return_internal_reference())
 set_policy(cEnvironment.GetReactionLib, return_internal_reference())

Modified: trunk/source/bindings/Boost.Python/organism.pyste
===================================================================
--- trunk/source/bindings/Boost.Python/organism.pyste	2005-09-15 23:16:19 UTC (rev 313)
+++ trunk/source/bindings/Boost.Python/organism.pyste	2005-09-16 02:10:20 UTC (rev 314)
@@ -1,5 +1,5 @@
 
-Include("environment.hh")
+Include("cEnvironment.h")
 Include("inject_genotype.hh")
 Include("cHardwareBase.h")
 Include("cCodeLabel.h")

Modified: trunk/source/bindings/Boost.Python/phenotype.pyste
===================================================================
--- trunk/source/bindings/Boost.Python/phenotype.pyste	2005-09-15 23:16:19 UTC (rev 313)
+++ trunk/source/bindings/Boost.Python/phenotype.pyste	2005-09-16 02:10:20 UTC (rev 314)
@@ -1,5 +1,5 @@
 
-Include("environment.hh")
+Include("cEnvironment.h")
 Include("tBuffer.hh")
 
 cPhenotype = Class("cPhenotype", "phenotype.hh")

Modified: trunk/source/bindings/Boost.Python/population.pyste
===================================================================
--- trunk/source/bindings/Boost.Python/population.pyste	2005-09-15 23:16:19 UTC (rev 313)
+++ trunk/source/bindings/Boost.Python/population.pyste	2005-09-16 02:10:20 UTC (rev 314)
@@ -1,6 +1,6 @@
 
 Include("change_list.hh")
-Include("environment.hh")
+Include("cEnvironment.h")
 Include("genebank.hh" )
 Include("inject_genebank.hh")
 Include("lineage_control.hh")

Modified: trunk/source/bindings/Boost.Python/population_interface-fixups.hh
===================================================================
--- trunk/source/bindings/Boost.Python/population_interface-fixups.hh	2005-09-15 23:16:19 UTC (rev 313)
+++ trunk/source/bindings/Boost.Python/population_interface-fixups.hh	2005-09-16 02:10:20 UTC (rev 314)
@@ -2,10 +2,10 @@
 #define POPULATION_INTERFACE_FIXUPS_HH
 
 #ifndef POPULATION_INTERFACE_HH
-#include "population_interface.hh"
+#include "cPopulationInterface.h"
 #endif
 #ifndef CALLBACK_UTIL_HH
-#include "callback_util.hh"
+#include "cCallbackUtil.h"
 #endif
 
 inline void BuildTestPopInterface(cPopulationInterface &test_interface){

Modified: trunk/source/bindings/Boost.Python/py_avida_driver-fixups.cc
===================================================================
--- trunk/source/bindings/Boost.Python/py_avida_driver-fixups.cc	2005-09-15 23:16:19 UTC (rev 313)
+++ trunk/source/bindings/Boost.Python/py_avida_driver-fixups.cc	2005-09-16 02:10:20 UTC (rev 314)
@@ -3,7 +3,7 @@
 
 #include "cpu/cHardwareBase.h"
 #include "cpu/cHardwareFactory.h"
-#include "main/config.hh"
+#include "main/cConfig.h"
 #include "main/genebank.hh"
 #include "main/genotype.hh"
 #include "main/organism.hh"

Modified: trunk/source/bindings/Boost.Python/py_avida_driver.hh
===================================================================
--- trunk/source/bindings/Boost.Python/py_avida_driver.hh	2005-09-15 23:16:19 UTC (rev 313)
+++ trunk/source/bindings/Boost.Python/py_avida_driver.hh	2005-09-16 02:10:20 UTC (rev 314)
@@ -2,10 +2,10 @@
 #define PY_AVIDA_DRIVER_HH
 
 #ifndef AVIDA_DRIVER_POPULATION_HH
-#include "avida_driver_population.hh"
+#include "cAvidaDriver_Population.h"
 #endif
 #ifndef ENVIRONMENT_HH
-#include "environment.hh"
+#include "cEnvironment.h"
 #endif
 
 class cChangeList;

Modified: trunk/source/bindings/Boost.Python/tList_instantiations.hh
===================================================================
--- trunk/source/bindings/Boost.Python/tList_instantiations.hh	2005-09-15 23:16:19 UTC (rev 313)
+++ trunk/source/bindings/Boost.Python/tList_instantiations.hh	2005-09-16 02:10:20 UTC (rev 314)
@@ -1,5 +1,5 @@
-#include "analyze_command.hh"
-#include "analyze_genotype.hh"
+#include "cAnalyzeCommand.h"
+#include "cAnalyzeGenotype.h"
 #include "mutation.hh"
 #include "population_cell.hh"
 #include "reaction_process.hh"

Modified: trunk/source/bindings/Boost.Python/test_cpu.pyste
===================================================================
--- trunk/source/bindings/Boost.Python/test_cpu.pyste	2005-09-15 23:16:19 UTC (rev 313)
+++ trunk/source/bindings/Boost.Python/test_cpu.pyste	2005-09-16 02:10:20 UTC (rev 314)
@@ -1,9 +1,9 @@
 
 Include("cCPUTestInfo.h")
-Include("environment.hh")
+Include("cEnvironment.h")
 Include("genome.hh")
 Include("inst_set.hh")
-Include("population_interface.hh")
+Include("cPopulationInterface.h")
 Include("resource_count.hh")
 
 cTestCPU = Class("cTestCPU", "test_cpu-fixups.hh")

Modified: trunk/source/cpu/cHardware4Stack.cc
===================================================================
--- trunk/source/cpu/cHardware4Stack.cc	2005-09-15 23:16:19 UTC (rev 313)
+++ trunk/source/cpu/cHardware4Stack.cc	2005-09-16 02:10:20 UTC (rev 314)
@@ -9,7 +9,7 @@
 
 #include "cHardware4Stack.h"
 
-#include "config.hh"
+#include "cConfig.h"
 #include "cCPUTestInfo.h"
 #include "functions.hh"
 #include "genome_util.hh"

Modified: trunk/source/cpu/cHardwareCPU.cc
===================================================================
--- trunk/source/cpu/cHardwareCPU.cc	2005-09-15 23:16:19 UTC (rev 313)
+++ trunk/source/cpu/cHardwareCPU.cc	2005-09-16 02:10:20 UTC (rev 314)
@@ -7,7 +7,7 @@
 
 #include "cHardwareCPU.h"
 
-#include "config.hh"
+#include "cConfig.h"
 #include "cCPUTestInfo.h"
 #include "functions.hh"
 #include "genome_util.hh"

Modified: trunk/source/cpu/cHardwareSMT.cc
===================================================================
--- trunk/source/cpu/cHardwareSMT.cc	2005-09-15 23:16:19 UTC (rev 313)
+++ trunk/source/cpu/cHardwareSMT.cc	2005-09-16 02:10:20 UTC (rev 314)
@@ -9,7 +9,7 @@
 
 #include "cHardwareSMT.h"
 
-#include "config.hh"
+#include "cConfig.h"
 #include "cCPUTestInfo.h"
 #include "functions.hh"
 #include "genome_util.hh"

Modified: trunk/source/cpu/cHardwareUtil.cc
===================================================================
--- trunk/source/cpu/cHardwareUtil.cc	2005-09-15 23:16:19 UTC (rev 313)
+++ trunk/source/cpu/cHardwareUtil.cc	2005-09-16 02:10:20 UTC (rev 314)
@@ -10,7 +10,7 @@
 #endif
 
 #ifndef CONFIG_HH
-#include "config.hh"
+#include "cConfig.h"
 #endif
 #ifndef HARDWARE_UTIL_HH
 #include "cHardwareBase.h"

Modified: trunk/source/cpu/cTestCPU.cc
===================================================================
--- trunk/source/cpu/cTestCPU.cc	2005-09-15 23:16:19 UTC (rev 313)
+++ trunk/source/cpu/cTestCPU.cc	2005-09-16 02:10:20 UTC (rev 314)
@@ -8,8 +8,8 @@
 #include "cTestCPU.h"
 
 #include "cCPUTestInfo.h"
-#include "config.hh"
-#include "environment.hh"
+#include "cConfig.h"
+#include "cEnvironment.h"
 #include "functions.hh"
 #include "cHardwareBase.h"
 #include "cHardwareStatusPrinter.h"
@@ -17,7 +17,7 @@
 #include "inst_util.hh"
 #include "organism.hh"
 #include "phenotype.hh"
-#include "population_interface.hh"
+#include "cPopulationInterface.h"
 #include "resource_count.hh"
 #include "resource_lib.hh"
 #include "resource.hh"

Modified: trunk/source/cpu/cTestUtil.cc
===================================================================
--- trunk/source/cpu/cTestUtil.cc	2005-09-15 23:16:19 UTC (rev 313)
+++ trunk/source/cpu/cTestUtil.cc	2005-09-16 02:10:20 UTC (rev 314)
@@ -8,7 +8,7 @@
 #include "cTestUtil.h"
 
 #include "cCPUTestInfo.h"
-#include "environment.hh"
+#include "cEnvironment.h"
 #include "genome.hh"
 #include "genotype.hh"
 #include "cHardwareBase.h"

Modified: trunk/source/event/cPopulationEventFactory.cc
===================================================================
--- trunk/source/event/cPopulationEventFactory.cc	2005-09-15 23:16:19 UTC (rev 313)
+++ trunk/source/event/cPopulationEventFactory.cc	2005-09-16 02:10:20 UTC (rev 314)
@@ -10,19 +10,19 @@
 #endif
 
 #ifndef ANALYZE_UTIL_HH
-#include "analyze_util.hh"
+#include "cAnalyzeUtil.h"
 #endif
 #ifndef AVIDA_HH
 #include "avida.hh"
 #endif
 #ifndef AVIDA_DRIVER_BASE_HH
-#include "avida_driver_base.hh"
+#include "cAvidaDriver_Base.h"
 #endif
 #ifndef CONFIG_HH
-#include "config.hh"
+#include "cConfig.h"
 #endif
 #ifndef ENVIRONMENT_HH
-#include "environment.hh"
+#include "cEnvironment.h"
 #endif
 #ifndef EVENT_HH
 #include "cEvent.h"

Modified: trunk/source/main/CMakeLists.txt
===================================================================
--- trunk/source/main/CMakeLists.txt	2005-09-15 23:16:19 UTC (rev 313)
+++ trunk/source/main/CMakeLists.txt	2005-09-16 02:10:20 UTC (rev 314)
@@ -1,17 +1,17 @@
 INCLUDE_DIRECTORIES(${ALL_INC_DIRS})
 
 SET(libmain_a_SOURCES
-  analyze.cc
-  analyze_genotype.cc
-  analyze_util.cc
+  cAnalyze.cc
+  cAnalyzeGenotype.cc
+  cAnalyzeUtil.cc
   avida.cc
-  avida_driver_analyze.cc
-  avida_driver_base.cc
-  avida_driver_population.cc
-  birth_chamber.cc
-  callback_util.cc
-  config.cc
-  environment.cc
+  cAvidaDriver_Analyze.cc
+  cAvidaDriver_Base.cc
+  cAvidaDriver_Population.cc
+  cBirthChamber.cc
+  cCallbackUtil.cc
+  cConfig.cc
+  cEnvironment.cc
   fitness_matrix.cc
   genebank.cc
   genome.cc
@@ -41,7 +41,7 @@
   phenotype.cc
   population.cc
   population_cell.cc
-  population_interface.cc
+  cPopulationInterface.cc
   reaction.cc
   reaction_lib.cc
   reaction_process.cc

Deleted: trunk/source/main/analyze.cc
===================================================================
--- trunk/source/main/analyze.cc	2005-09-15 23:16:19 UTC (rev 313)
+++ trunk/source/main/analyze.cc	2005-09-16 02:10:20 UTC (rev 314)
@@ -1,7073 +0,0 @@
-//////////////////////////////////////////////////////////////////////////////
-// Copyright (C) 1993 - 2003 California Institute of Technology             //
-//                                                                          //
-// Read the COPYING and README files, or contact 'avida at alife.org',         //
-// before continuing.  SOME RESTRICTIONS MAY APPLY TO USE OF THIS FILE.     //
-//////////////////////////////////////////////////////////////////////////////
-
-#include <fstream>
-#include <sstream>
-#include <string>
-#include <queue>
-#include <stack>
-
-#include "analyze.hh"
-
-#include "analyze_command.hh"
-#include "analyze_command_def.hh"
-#include "analyze_command_def_base.hh"
-#include "analyze_flow_command.hh"
-#include "analyze_flow_command_def.hh"
-#include "analyze_function.hh"
-#include "analyze_genotype.hh"
-#include "config.hh"
-#include "data_file.hh"
-#include "environment.hh"
-#include "fitness_matrix.hh"
-#include "genome_util.hh"
-#include "cHardwareBase.h"
-#include "cHardwareStatusPrinter.h"
-#include "cHardwareUtil.h"
-#include "help_manager.hh"
-#include "init_file.hh"
-#include "inst_set.hh"
-#include "inst_util.hh"
-#include "landscape.hh"
-#include "phenotype.hh"
-#include "species.hh"
-#include "tArgDataEntry.hh"
-#include "task_entry.hh"
-#include "tDataEntry.hh"
-#include "tDataEntryCommand.hh"
-#include "tMatrix.hh"
-#include "cTestCPU.h"
-#include "cCPUTestInfo.h"
-#include "cTestUtil.h"
-#include "resource.hh"
-#include "tHashTable.hh"
-#ifdef WIN32
-#  include "win32_mkdir_hack.hh"
-#endif
-
-extern "C" {
-#include <errno.h>
-#include <sys/stat.h>
-}
-
-using namespace std;
-
-//////////////
-//  cAnalyze
-//////////////
-
-cAnalyze::cAnalyze(cString filename, cEnvironment *environment)
-: cur_batch(0)
-, d_environment(environment)
-, verbose(false)
-, interactive_depth(0)
-, inst_set(cHardwareUtil::DefaultInstSet(cConfig::GetInstFilename()))
-{
-  random.ResetSeed(cConfig::GetRandSeed());
-  
-  for (int i = 0; i < MAX_BATCHES; i++) {
-    batch[i].Name().Set("Batch%d", i);
-  }
-  
-  // Initialize the time oriented resource list to be just the initial
-  // concentrations of the resources in the environment.  This will only
-  // be changed if LOAD_RESOURCES analyze command is called.  If there is
-  // no resources in the environment or there is no environment, the list
-  // is empty and will cause an assert to be thrown in FindResource function.
-  const cResourceLib &resource_lib = environment->GetResourceLib();
-  if(environment != NULL && resource_lib.GetSize() > 0) {
-    vector<double> r;
-    for(int i=0; i<resource_lib.GetSize(); i++) {
-      cResource *resource = resource_lib.GetResource(i);
-      assert(resource);
-      r.push_back(resource->GetInitial());
-    }
-    resources.push_back(make_pair(0, r));
-  }
-  FillResources(0);
-  
-  cInitFile analyze_file(filename);
-  analyze_file.Load();
-  analyze_file.Compress();
-  analyze_file.Close();
-  
-  LoadCommandList(analyze_file, command_list);
-  ProcessCommands(command_list);
-  
-  return;
-}
-
-cAnalyze::~cAnalyze()
-{
-  data_file_manager.FlushAll();
-  while (genotype_data_list.GetSize()) delete genotype_data_list.Pop();
-  while (command_list.GetSize()) delete command_list.Pop();
-  while (function_list.GetSize()) delete function_list.Pop();
-}
-
-
-//////////////// Loading methods...
-
-void cAnalyze::LoadOrganism(cString cur_string)
-{
-  // LOAD_ORGANISM command...
-  
-  cString filename = cur_string.PopWord();
-  
-  cout << "Loading: " << filename << endl;
-  
-  // Setup the genome...
-  cGenome genome( cInstUtil::LoadGenome(filename, inst_set) );
-  
-  // Construct the new genotype..
-  cAnalyzeGenotype * genotype = new cAnalyzeGenotype(genome, inst_set);
-  
-  // Determine the organism's original name -- strip off directory...
-  while (filename.Find('/') != -1) filename.Pop('/');
-  while (filename.Find('\\') != -1) filename.Pop('\\');
-  filename.Replace(".gen", "");  // Remove the .gen from the filename.
-  genotype->SetName(filename);
-  
-  // And save it in the current batch.
-  batch[cur_batch].List().PushRear(genotype);
-  
-  // Adjust the flags on this batch
-  batch[cur_batch].SetLineage(false);
-  batch[cur_batch].SetAligned(false);
-}
-
-void cAnalyze::LoadBasicDump(cString cur_string)
-{
-  // LOAD_BASE_DUMP
-  
-  cString filename = cur_string.PopWord();
-  
-  cout << "Loading: " << filename << endl;
-  
-  cInitFile input_file(filename);
-  if (!input_file.IsOpen()) {
-    cerr << "Error: Cannot load file: \"" << filename << "\"." << endl;
-    exit(1);
-  }
-  input_file.Load();
-  input_file.Compress();
-  input_file.Close();
-  
-  // Setup the genome...
-  
-  for (int line_id = 0; line_id < input_file.GetNumLines(); line_id++) {
-    cString cur_line = input_file.GetLine(line_id);
-    
-    // Setup the genotype for this line...
-    cAnalyzeGenotype * genotype =
-      new cAnalyzeGenotype(cur_line.PopWord(), inst_set);
-    int num_cpus = cur_line.PopWord().AsInt();
-    int id_num = cur_line.PopWord().AsInt();
-    cString name = cStringUtil::Stringf("org-%d", id_num);
-    
-    genotype->SetNumCPUs(num_cpus);
-    genotype->SetID(id_num);
-    genotype->SetName(name);
-    
-    // Add this genotype to the proper batch.
-    batch[cur_batch].List().PushRear(genotype);
-  }
-  
-  // Adjust the flags on this batch
-  batch[cur_batch].SetLineage(false);
-  batch[cur_batch].SetAligned(false);
-}
-
-void cAnalyze::LoadDetailDump(cString cur_string)
-{
-  cout << "Warning: Use of LoadDetailDump() is deprecated.  Use \"LOAD\" instead." << endl;  
-  // LOAD_DETAIL_DUMP
-  
-  cString filename = cur_string.PopWord();
-  
-  cout << "Loading: " << filename << endl;
-  
-  cInitFile input_file(filename);
-  if (!input_file.IsOpen()) {
-    cerr << "Error: Cannot load file: \"" << filename << "\"." << endl;
-    exit(1);
-  }
-  input_file.Load();
-  input_file.Compress();
-  input_file.Close();
-  
-  // Setup the genome...
-  
-  for (int line_id = 0; line_id < input_file.GetNumLines(); line_id++) {
-    cString cur_line = input_file.GetLine(line_id);
-    
-    // Setup the genotype for this line...
-    
-    int id_num      = cur_line.PopWord().AsInt();
-    int parent_id   = cur_line.PopWord().AsInt();
-    int parent_dist = cur_line.PopWord().AsInt();
-    int num_cpus    = cur_line.PopWord().AsInt();
-    int total_cpus  = cur_line.PopWord().AsInt();
-    int length      = cur_line.PopWord().AsInt();
-    double merit    = cur_line.PopWord().AsDouble();
-    int gest_time   = cur_line.PopWord().AsInt();
-    double fitness  = cur_line.PopWord().AsDouble();
-    int update_born = cur_line.PopWord().AsInt();
-    int update_dead = cur_line.PopWord().AsInt();
-    int depth       = cur_line.PopWord().AsInt();
-    cString name = cStringUtil::Stringf("org-%d", id_num);
-    
-    cAnalyzeGenotype * genotype =
-      new cAnalyzeGenotype(cur_line.PopWord(), inst_set);
-    
-    genotype->SetID(id_num);
-    genotype->SetParentID(parent_id);
-    genotype->SetParentDist(parent_dist);
-    genotype->SetNumCPUs(num_cpus);
-    genotype->SetTotalCPUs(total_cpus);
-    genotype->SetLength(length);
-    genotype->SetMerit(merit);
-    genotype->SetGestTime(gest_time);
-    genotype->SetFitness(fitness);
-    genotype->SetUpdateBorn(update_born);
-    genotype->SetUpdateDead(update_dead);
-    genotype->SetDepth(depth);
-    genotype->SetName(name);
-    
-    // Add this genotype to the proper batch.
-    batch[cur_batch].List().PushRear(genotype);
-  }
-  
-  // Adjust the flags on this batch
-  batch[cur_batch].SetLineage(false);
-  batch[cur_batch].SetAligned(false);
-}
-
-void cAnalyze::LoadMultiDetail(cString cur_string)
-{
-  // LOAD_MULTI_DETAIL
-  
-  int start_UD = cur_string.PopWord().AsInt();
-  int step_UD = cur_string.PopWord().AsInt();
-  int stop_UD = cur_string.PopWord().AsInt();
-  cString data_directory = PopDirectory(cur_string, "./");
-  cur_batch = cur_string.PopWord().AsInt();
-  
-  if (step_UD == 0) {
-    cerr << "Error: LOAD_MULTI_DETAIL must have a non-zero value for step."
-    << endl;
-    return;
-  }
-  
-  int num_steps = (stop_UD - start_UD) / step_UD + 1;
-  if (num_steps > 1000) {
-    cerr << "Warning: Loading over 1000 files in LOAD_MULTI_DETAIL!"
-    << endl;
-  }
-  
-  if (verbose == true) {
-    cout << "Loading in " << num_steps
-    << " detail files from update " << start_UD
-    << " to update " << stop_UD
-    << endl;
-  } else {
-    cout << "Running LOAD_MULTI_DETAIL" << endl;
-  }
-  
-  for (int cur_UD = start_UD; cur_UD <= stop_UD; cur_UD += step_UD) {
-    cString filename = cStringUtil::Stringf("detail_pop.%d", cur_UD);
-    
-    cout << "Loading '" << filename
-      << "' into batch " << cur_batch
-      << endl;
-    
-    cInitFile input_file(filename);
-    if (!input_file.IsOpen()) {
-      cerr << "Error: Cannot load file: \"" << filename << "\"." << endl;
-      exit(1);
-    }
-    input_file.Load();
-    input_file.Compress();
-    input_file.Close();
-    
-    // Setup the genome...
-    
-    for (int line_id = 0; line_id < input_file.GetNumLines(); line_id++) {
-      cString cur_line = input_file.GetLine(line_id);
-      
-      // Setup the genotype for this line...
-      
-      int id_num      = cur_line.PopWord().AsInt();
-      int parent_id   = cur_line.PopWord().AsInt();
-      int parent_dist = cur_line.PopWord().AsInt();
-      int num_cpus    = cur_line.PopWord().AsInt();
-      int total_cpus  = cur_line.PopWord().AsInt();
-      int length      = cur_line.PopWord().AsInt();
-      double merit    = cur_line.PopWord().AsDouble();
-      int gest_time   = cur_line.PopWord().AsInt();
-      double fitness  = cur_line.PopWord().AsDouble();
-      int update_born = cur_line.PopWord().AsInt();
-      int update_dead = cur_line.PopWord().AsInt();
-      int depth       = cur_line.PopWord().AsInt();
-      cString name = cStringUtil::Stringf("org-%d", id_num);
-      
-      cAnalyzeGenotype * genotype =
-        new cAnalyzeGenotype(cur_line.PopWord(), inst_set);
-      
-      genotype->SetID(id_num);
-      genotype->SetParentID(parent_id);
-      genotype->SetParentDist(parent_dist);
-      genotype->SetNumCPUs(num_cpus);
-      genotype->SetTotalCPUs(total_cpus);
-      genotype->SetLength(length);
-      genotype->SetMerit(merit);
-      genotype->SetGestTime(gest_time);
-      genotype->SetFitness(fitness);
-      genotype->SetUpdateBorn(update_born);
-      genotype->SetUpdateDead(update_dead);
-      genotype->SetDepth(depth);
-      genotype->SetName(name);
-      
-      // Add this genotype to the proper batch.
-      batch[cur_batch].List().PushRear(genotype);
-    }
-    
-    // Adjust the flags on this batch
-    batch[cur_batch].SetLineage(false);
-    batch[cur_batch].SetAligned(false);
-    
-    cur_batch++;
-  }
-}
-
-void cAnalyze::LoadSequence(cString cur_string)
-{
-  // LOAD_SEQUENCE
-  
-  static int sequence_count = 1;
-  cString sequence = cur_string.PopWord();
-  cString seq_name = cur_string.PopWord();
-  
-  cout << "Loading: " << sequence << endl;
-  
-  // Setup the genotype...
-  cAnalyzeGenotype * genotype = new cAnalyzeGenotype(sequence, inst_set);
-  
-  genotype->SetNumCPUs(1);      // Initialize to a single organism.
-  if (seq_name == "") {
-    seq_name = cStringUtil::Stringf("org-Seq%d", sequence_count);
-  }
-  genotype->SetName(seq_name);
-  sequence_count++;
-  
-  // Add this genotype to the proper batch.
-  batch[cur_batch].List().PushRear(genotype);
-  
-  // Adjust the flags on this batch
-  batch[cur_batch].SetLineage(false);
-  batch[cur_batch].SetAligned(false);
-}
-
-void cAnalyze::LoadDominant(cString cur_string)
-{
-  (void) cur_string;
-  cerr << "Warning: \"LOAD_DOMINANT\" not implmented yet!"<<endl;
-}
-
-// Clears the current time oriented list of resources and loads in a new one
-// from a file specified by the user, or resource.dat by default.
-void cAnalyze::LoadResources(cString cur_string)
-{
-  resources.clear();
-  
-  int words = cur_string.CountNumWords();
-  
-  cString filename = "resource.dat";
-  if(words >= 1) {
-    filename = cur_string.PopWord();
-  }
-  
-  cout << "Loading Resources from: " << filename << endl;
-  
-  // Process the resource.dat, currently assuming this is the only possible
-  // input file
-  ifstream resourceFile(filename, ios::in);
-  assert(resourceFile);
-  
-  // Read in each line of the resource file and process it
-  char line[2048];
-  while(!resourceFile.eof()) {
-    resourceFile.getline(line, 2047);
-    if(line[0] == '\0') { continue; }
-    
-    // Get rid of the whitespace at the beginning of the stream, then 
-    // see if the line begins with a #, if so move on to the next line.
-    stringstream ss;
-    ss << line; ss >> ws; if(ss.peek() == '#') { continue; }
-    
-    // Read the update number from the stream
-    int update;
-    ss >> update; assert(ss.good());
-    
-    // Read in the concentration values for the current update and put them
-    // into a temporary vector.
-    double x;
-    vector<double> tempValues;
-    // Loop until the stream is no longer valid, which means either all the
-    // data has been processed or a non-numeric was encountered.  Currently
-    // assuming a non-numeric is a comment denoting the rest of the line as
-    // not informational.
-    while(true) {
-      ss >> ws; ss >> x;
-      tempValues.push_back(x);
-      if(!ss.good()) { ss.clear(); break; }
-    }
-    // Can't have no resources, so assert
-    if(tempValues.empty()) { assert(0); }
-    // add the update to the list of updates.  Also assuming the values
-    // in the file are already sorted.  If this turns out not to be the
-    // case you will need to sort on resources[i].first
-    resources.push_back(make_pair(update, tempValues));
-  }
-  resourceFile.close();
-  
-  return;
-}
-
-
-// Looks up the resource concentrations that are the closest to the
-// given update and then fill in those concentrations into the environment.
-void cAnalyze::FillResources(int update)
-{
-  // There must be some resources for at least one update
-  //assert(!resources.empty());
-  if(resources.empty()) { return; }
-  
-  int which = -1;
-  // Assuming resource vector is sorted by update, front to back
-  if(update <= resources[0].first) {
-    which = 0;
-  } else if(update >= resources.back().first) {
-    which = resources.size() - 1;
-  } else {
-    // Find the update that is closest to the born update
-    for(unsigned int i=0; i<resources.size()-1; i++) {
-      if(update > resources[i+1].first) { continue; }
-      if(update - resources[i].first <=
-         resources[i+1].first - update) {
-        which = i;
-      } else {
-        which = i + 1;
-      }
-      break;
-    }
-  }
-  if(which < 0) { assert(0); }
-  
-  //cResourceLib &resLib = environment.GetResourceLib();
-  // The resources from the file and the original resources from
-  // environment.cfg must be the same size.
-  //assert((unsigned int)resLib.GetSize() == resources[which].second.size());
-  // Set the resource concentrations to the values for the appropriate
-  // update
-  //for(unsigned int i=0; i<resources[which].second.size(); i++) {
-  //  cResource *res = resLib.GetResource(i);
-  //  assert(res);
-  //  res->SetInitial(resources[which].second[i]);
-  //}
-  
-tArray<double> temp(resources[which].second.size());
-for(unsigned int i=0; i<resources[which].second.size(); i++) {
-  temp[i] = resources[which].second[i];
-}
-cTestCPU::SetupResourceArray(temp);
-
-return;
-}
-
-double cAnalyze::AnalyzeEntropy(cAnalyzeGenotype * genotype, double mu) 
-{
-  double entropy = 0.0;
-
-  // If the fitness is 0, the entropy is the length of genotype ...
-  genotype->Recalculate();
-  if (genotype->GetFitness() == 0) {
-    return genotype->GetLength();
-  }
-
-  // Calculate the stats for the genotype we're working with ...
-  const int num_insts = inst_set.GetSize();
-  const int num_lines = genotype->GetLength();
-  const cGenome & base_genome = genotype->GetGenome();
-  cGenome mod_genome(base_genome);
-  double base_fitness = genotype->GetFitness();
-  
-  // Loop through all the lines of code, testing all mutations...
-  tArray<double> test_fitness(num_insts);
-  tArray<double> prob(num_insts);
-  for (int line_no = 0; line_no < num_lines; line_no ++) {
-    int cur_inst = base_genome[line_no].GetOp();
-    
-    // Test fitness of each mutant.
-    for (int mod_inst = 0; mod_inst < num_insts; mod_inst++) {
-      mod_genome[line_no].SetOp(mod_inst);
-      cAnalyzeGenotype test_genotype(mod_genome, inst_set);
-      test_genotype.Recalculate();
-      // Ajust fitness ...
-      if (test_genotype.GetFitness() <= base_fitness) {
-	test_fitness[mod_inst] = test_genotype.GetFitness();
-      } else {
-	test_fitness[mod_inst] = base_fitness;
-      }
-    }
-    
-    // Calculate probabilities at mut-sel balance
-    double w_bar = 1;
-    
-    // Normalize fitness values
-    double maxFitness = 0.0;
-    for(int i=0; i<num_insts; i++) {
-      if(test_fitness[i] > maxFitness) {
-	maxFitness = test_fitness[i];
-      }
-    }
-    
-   
-    for(int i=0; i<num_insts; i++) {
-      test_fitness[i] /= maxFitness;
-    }
-       
-    while(1) {
-      double sum = 0.0;
-      for (int mod_inst = 0; mod_inst < num_insts; mod_inst ++) {
-	prob[mod_inst] = (mu * w_bar) / 
-	  ((double)num_insts * 
-	   (w_bar + test_fitness[mod_inst] * mu - test_fitness[mod_inst]));
-	sum = sum + prob[mod_inst];
-      }
-      if ((sum-1.0)*(sum-1.0) <= 0.0001) 
-	break;
-      else
-	w_bar = w_bar - 0.000001;
-    }
-    
-    // Calculate entropy ...
-    double this_entropy = 0.0;
-    for (int i = 0; i < num_insts; i ++) {
-      this_entropy += prob[i] * log((double) 1.0/prob[i]) / log ((double) num_insts);
-    }
-    entropy += this_entropy;
-    
-    // Reset the mod_genome back to the original sequence.
-    mod_genome[line_no].SetOp(cur_inst);
-  }
-  return entropy;
-}
-
-double cAnalyze::AnalyzeEntropyGivenParent(cAnalyzeGenotype * genotype,
-					   cAnalyzeGenotype * parent, double mut_rate)
-{
-  double entropy = 0.0;
-
-  // Calculate the stats for the genotype we're working with ...
-  genotype->Recalculate();
-  const int num_insts = inst_set.GetSize();
-  const int num_lines = genotype->GetLength();
-  const cGenome & base_genome = genotype->GetGenome();
-  const cGenome & parent_genome = parent->GetGenome();
-  cGenome mod_genome(base_genome);
-
-  // Loop through all the lines of code, testing all mutations ...
-  tArray<double> test_fitness(num_insts);
-  tArray<double> prob(num_insts);
-  for (int line_no = 0; line_no < num_lines; line_no ++) {
-    int cur_inst = base_genome[line_no].GetOp();
-    int parent_inst = parent_genome[line_no].GetOp();
-
-    // Test fitness of each mutant.
-    for (int mod_inst = 0; mod_inst < num_insts; mod_inst++) {
-      mod_genome[line_no].SetOp(mod_inst);
-      cAnalyzeGenotype test_genotype(mod_genome, inst_set);
-      test_genotype.Recalculate();
-      test_fitness[mod_inst] = test_genotype.GetFitness();
-    }
-
-
-    // Calculate probabilities at mut-sel balance
-    double w_bar = 1;
-    
-    // Normalize fitness values, assert if they are all zero
-    double maxFitness = 0.0;
-    for(int i=0; i<num_insts; i++) {
-      if ( i == parent_inst) { continue; }
-      if (test_fitness[i] > maxFitness) {
-	maxFitness = test_fitness[i];
-      }
-    }
-    
-    if(maxFitness > 0) {
-      for(int i = 0; i < num_insts; i ++) {
-	if (i == parent_inst) { continue; }
-	test_fitness[i] /= maxFitness;
-      }
-    } else {
-      // every other inst is equally likely to be mutated to
-      for (int i = 0; i < num_insts; i ++) {
-	if (i == parent_inst) { continue; }
-	test_fitness[i] = 1;
-      }
-    }
-    
-    double double_num_insts = num_insts * 1.0;
-    while(1) {
-      double sum = 0.0;
-      for (int mod_inst = 0; mod_inst < num_insts; mod_inst ++) {
-	if (mod_inst == parent_inst) { continue; }
-	prob[mod_inst] = (mut_rate * w_bar) / 
-	  (double_num_insts-2) / 
-	   (w_bar + test_fitness[mod_inst] * mut_rate * (double_num_insts-1) / (double_num_insts - 2) 
-	    - test_fitness[mod_inst]);
-	sum = sum + prob[mod_inst];
-      }
-      if ((sum-1.0)*(sum-1.0) <= 0.0001) 
-	break;
-      else
-	w_bar = w_bar - 0.000001;
-    }
-    
-    // Calculate entropy ...
-    double this_entropy = 0.0;
-    this_entropy -= (1.0 - mut_rate) * log(1.0 - mut_rate) / log(static_cast<double>(num_insts));
-    for (int i = 0; i < num_insts; i ++) {
-      if (i == parent_inst) { continue; }
-      prob[i] = prob[i] * mut_rate;
-      this_entropy += prob[i] * log(static_cast<double>(1.0/prob[i])) / log (static_cast<double>(num_insts));
-    }
-    entropy += this_entropy;
-
-    // Reset the mod_genome back to the base_genome.
-    mod_genome[line_no].SetOp(cur_inst);
-  }
-  return entropy;
-}
-
-double cAnalyze::IncreasedInfo(cAnalyzeGenotype * genotype1,
-			       cAnalyzeGenotype * genotype2,
-			       double mu) 
-{
-  double increased_info = 0.0;
-
-  // Calculate the stats for the genotypes we're working with ...
-  if ( genotype1->GetLength() != genotype2->GetLength() ) {
-    cerr << "Error: Two genotypes don't have same length.(cAnalyze::IncreasedInfo)" << endl;
-    exit(1);
-  }
-
-  genotype1->Recalculate();
-  if (genotype1->GetFitness() == 0) {
-    return 0.0;
-  }
-
-  const int num_insts = inst_set.GetSize();
-  const int num_lines = genotype1->GetLength();
-  const cGenome & genotype1_base_genome = genotype1->GetGenome();
-  cGenome genotype1_mod_genome(genotype1_base_genome);
-  double genotype1_base_fitness = genotype1->GetFitness();
-  vector<double> genotype1_info(num_lines, 0.0);
-  
-  // Loop through all the lines of code, calculate genotype1 information
-  tArray<double> test_fitness(num_insts);
-  tArray<double> prob(num_insts);
-  for (int line_no = 0; line_no < num_lines; line_no ++) {
-    int cur_inst = genotype1_base_genome[line_no].GetOp();
-    
-    // Test fitness of each mutant.
-    for (int mod_inst = 0; mod_inst < num_insts; mod_inst++) {
-      genotype1_mod_genome[line_no].SetOp(mod_inst);
-      cAnalyzeGenotype test_genotype(genotype1_mod_genome, inst_set);
-      test_genotype.Recalculate();
-      // Ajust fitness ...
-      if (test_genotype.GetFitness() <= genotype1_base_fitness) {
-	test_fitness[mod_inst] = test_genotype.GetFitness();
-      } else {
-	test_fitness[mod_inst] = genotype1_base_fitness;
-      }
-    }
-    
-    // Calculate probabilities at mut-sel balance
-    double w_bar = 1;
-    
-    // Normalize fitness values
-    double maxFitness = 0.0;
-    for(int i=0; i<num_insts; i++) {
-      if(test_fitness[i] > maxFitness) {
-	maxFitness = test_fitness[i];
-      }
-    }
-    
-    for(int i=0; i<num_insts; i++) {
-      test_fitness[i] /= maxFitness;
-    }
-    
-    while(1) {
-      double sum = 0.0;
-      for (int mod_inst = 0; mod_inst < num_insts; mod_inst ++) {
-	prob[mod_inst] = (mu * w_bar) / 
-	  ((double)num_insts * 
-	   (w_bar + test_fitness[mod_inst] * mu - test_fitness[mod_inst]));
-	sum = sum + prob[mod_inst];
-      }
-      if ((sum-1.0)*(sum-1.0) <= 0.0001) 
-	break;
-      else
-	w_bar = w_bar - 0.000001;
-    }
-    
-    // Calculate entropy ...
-    double this_entropy = 0.0;
-    for (int i = 0; i < num_insts; i ++) {
-      this_entropy += prob[i] * log((double) 1.0/prob[i]) / log ((double) num_insts);
-    }
-    genotype1_info[line_no] = 1 - this_entropy;
-    
-    // Reset the mod_genome back to the original sequence.
-    genotype1_mod_genome[line_no].SetOp(cur_inst);
-  }
-
-  genotype2->Recalculate();
-  if (genotype2->GetFitness() == 0) {
-    for (int line_no = 0; line_no < num_lines; ++ line_no) {
-      increased_info += genotype1_info[line_no];
-    }
-    return increased_info;
-  }
-    
-  const cGenome & genotype2_base_genome = genotype2->GetGenome();
-  cGenome genotype2_mod_genome(genotype2_base_genome);
-  double genotype2_base_fitness = genotype2->GetFitness();
-
-  // Loop through all the lines of code, calculate increased information
-  for (int line_no = 0; line_no < num_lines; line_no ++) {
-    int cur_inst = genotype2_base_genome[line_no].GetOp();
-    
-    // Test fitness of each mutant.
-    for (int mod_inst = 0; mod_inst < num_insts; mod_inst++) {
-      genotype2_mod_genome[line_no].SetOp(mod_inst);
-      cAnalyzeGenotype test_genotype(genotype2_mod_genome, inst_set);
-      test_genotype.Recalculate();
-      // Ajust fitness ...
-      if (test_genotype.GetFitness() <= genotype2_base_fitness) {
-	test_fitness[mod_inst] = test_genotype.GetFitness();
-      } else {
-	test_fitness[mod_inst] = genotype2_base_fitness;
-      }
-    }
-    
-    // Calculate probabilities at mut-sel balance
-    double w_bar = 1;
-    
-    // Normalize fitness values, assert if they are all zero
-    double maxFitness = 0.0;
-    for(int i=0; i<num_insts; i++) {
-      if(test_fitness[i] > maxFitness) {
-	maxFitness = test_fitness[i];
-      }
-    }
-    
-    for(int i=0; i<num_insts; i++) {
-      test_fitness[i] /= maxFitness;
-    }
-    
-    while(1) {
-      double sum = 0.0;
-      for (int mod_inst = 0; mod_inst < num_insts; mod_inst ++) {
-	prob[mod_inst] = (mu * w_bar) / 
-	  ((double)num_insts * 
-	   (w_bar + test_fitness[mod_inst] * mu - test_fitness[mod_inst]));
-	sum = sum + prob[mod_inst];
-      }
-      if ((sum-1.0)*(sum-1.0) <= 0.0001) 
-	break;
-      else
-	w_bar = w_bar - 0.000001;
-    }
-    
-    // Calculate entropy ...
-    double this_entropy = 0.0;
-    for (int i = 0; i < num_insts; i ++) {
-      this_entropy += prob[i] * log((double) 1.0/prob[i]) / log ((double) num_insts);
-    }
-    
-    // Compare information 
-    if (genotype1_info[line_no] > 1 - this_entropy) {
-      increased_info += genotype1_info[line_no] - (1 - this_entropy);
-    } // else increasing is 0, do nothing
-    
-    // Reset the mod_genome back to the original sequence.
-    genotype2_mod_genome[line_no].SetOp(cur_inst);
-  }
-
-
-  return increased_info;
-}
-
-void cAnalyze::LoadFile(cString cur_string)
-{
-  // LOAD
-  
-  cString filename = cur_string.PopWord();
-  
-  cout << "Loading: " << filename << endl;
-  
-  cInitFile input_file(filename);
-  if (!input_file.IsOpen()) {
-    cerr << "Error: Cannot load file: \"" << filename << "\"." << endl;
-    exit(1);
-  }
-  input_file.Load();
-  input_file.ReadHeader();
-  input_file.Compress();
-  input_file.Close();
-  
-  const cString filetype = input_file.GetFiletype();
-  if (filetype != "population_data" &&  // Depricated
-      filetype != "genotype_data") {
-    cerr << "Error: Cannot load files of type \"" << filetype << "\"." << endl;
-    exit(1);
-  }
-  
-  if (verbose == true) {
-    cout << "Loading file of type: " << filetype << endl;
-  }
-  
-  
-  // Construct a linked list of data types that can be loaded...
-  tList< tDataEntryCommand<cAnalyzeGenotype> > output_list;
-  tListIterator< tDataEntryCommand<cAnalyzeGenotype> > output_it(output_list);
-  LoadGenotypeDataList(input_file.GetFormat(), output_list);
-  bool id_inc = input_file.GetFormat().HasString("id");
-  
-  // Setup the genome...
-  cGenome default_genome(1);
-  int load_count = 0;
-  
-  for (int line_id = 0; line_id < input_file.GetNumLines(); line_id++) {
-    cString cur_line = input_file.GetLine(line_id);
-    
-    cAnalyzeGenotype * genotype =
-      new cAnalyzeGenotype(default_genome, inst_set);
-    
-    output_it.Reset();
-    tDataEntryCommand<cAnalyzeGenotype> * data_command = NULL;
-    while ((data_command = output_it.Next()) != NULL) {
-      data_command->SetTarget(genotype);
-      //        genotype->SetSpecialArgs(data_command->GetArgs());
-      data_command->SetValue(cur_line.PopWord());
-    }
-    
-    // Give this genotype a name.  Base it on the ID if possible.
-    if (id_inc == false) {
-      cString name = cStringUtil::Stringf("org-%d", load_count++);
-      genotype->SetName(name);
-    }
-    else {
-      cString name = cStringUtil::Stringf("org-%d", genotype->GetID());
-      genotype->SetName(name);
-    }
-    
-    // Add this genotype to the proper batch.
-    batch[cur_batch].List().PushRear(genotype);
-  }
-  
-  // Adjust the flags on this batch
-  batch[cur_batch].SetLineage(false);
-  batch[cur_batch].SetAligned(false);
-}
-
-
-//////////////// Reduction....
-
-void cAnalyze::FindGenotype(cString cur_string)
-{
-  // If no arguments are passed in, just find max num_cpus.
-  if (cur_string.GetSize() == 0) cur_string = "num_cpus";
-  
-  if (verbose == true) {
-    cout << "Reducing batch " << cur_batch << " to genotypes: ";
-  }
-  
-  tListPlus<cAnalyzeGenotype> & gen_list = batch[cur_batch].List();
-  tListPlus<cAnalyzeGenotype> found_list;
-  while (cur_string.CountNumWords() > 0) {
-    cString gen_desc(cur_string.PopWord());
-    if (verbose) cout << gen_desc << " ";
-    
-    // Determine by lin_type which genotype were are tracking...
-    cAnalyzeGenotype * found_gen = PopGenotype(gen_desc, cur_batch);
-    
-    if (found_gen == NULL) {
-      cerr << "  Warning: genotype not found!" << endl;
-      continue;
-    }
-    
-    // Save this genotype...
-    found_list.Push(found_gen);
-  }
-  cout << endl;
-  
-  // Delete all genotypes other than the ones found!
-  while (gen_list.GetSize() > 0) delete gen_list.Pop();
-  
-  // And fill it back in with the good stuff.
-  while (found_list.GetSize() > 0) gen_list.Push(found_list.Pop());
-  
-  // Adjust the flags on this batch
-  batch[cur_batch].SetLineage(false);
-  batch[cur_batch].SetAligned(false);
-}
-
-void cAnalyze::FindOrganism(cString cur_string)
-{
-  // At least one argument is rquired.
-  if (cur_string.GetSize() == 0) {
-    cerr << "Error: At least one argument is required in FIND_ORGANISM." << endl;
-    return;
-  }
-  
-  if (verbose == true) {
-    cout << "Reducing batch " << cur_batch << " to organisms: " << endl;
-  }
-  
-  tListPlus<cAnalyzeGenotype> & gen_list = batch[cur_batch].List();
-  tListPlus<cAnalyzeGenotype> found_list;
-  
-  tArray<int> new_counts(gen_list.GetSize());
-  new_counts.SetAll(0);
-  
-  while (cur_string.CountNumWords() > 0) {
-    cString org_desc(cur_string.PopWord());
-    if (verbose) cout << org_desc << " ";
-    
-    // Determine by org_desc which genotype were are tracking...
-    if (org_desc == "random") {
-      bool found = false; 
-      int num_orgs = gen_list.Count(&cAnalyzeGenotype::GetNumCPUs);
-      while (found != true) {
-      	int org_chosen = random.GetUInt(num_orgs);
-      	cAnalyzeGenotype * found_genotype = 
-          gen_list.FindSummedValue(org_chosen, &cAnalyzeGenotype::GetNumCPUs);
-        if ( found_genotype->GetNumCPUs() != 0 && found_genotype->GetViable()) {
-          found_genotype->SetNumCPUs(found_genotype->GetNumCPUs()-1);
-          new_counts[gen_list.FindPosPtr(found_genotype)] +=1;
-          cout << "Found genotype " << gen_list.FindPosPtr(found_genotype) << endl;
-          found = true;
-        }
-      }
-    }
-    
-    // pick a random organisms, with replacement!
-    if (org_desc == "randomWR") {
-      bool found = false;
-      int num_orgs = gen_list.Count(&cAnalyzeGenotype::GetNumCPUs);
-      while (found != true) {
-        int org_chosen = random.GetUInt(num_orgs);
-        cAnalyzeGenotype * found_genotype =
-          gen_list.FindSummedValue(org_chosen, &cAnalyzeGenotype::GetNumCPUs);
-        if ( found_genotype->GetNumCPUs() != 0 && found_genotype->GetViable()) {
-          new_counts[gen_list.FindPosPtr(found_genotype)] +=1;
-          cout << "Found genotype " << gen_list.FindPosPtr(found_genotype) << endl;
-          found = true;
-        }
-      }
-    }
-  }
-  
-  int pos_count = 0;
-  cAnalyzeGenotype * genotype = NULL;
-  tListIterator<cAnalyzeGenotype> batch_it(batch[cur_batch].List());
-  
-  while ((genotype = batch_it.Next()) != NULL) {
-    genotype->SetNumCPUs(new_counts[pos_count]);
-    if (genotype->GetNumCPUs() == 0) batch_it.Remove();
-    else cout << "Genotype " << pos_count << " has " << new_counts[pos_count] << " organisms." << endl;
-    pos_count++;
-  }
-  
-  // Adjust the flags on this batch
-  batch[cur_batch].SetLineage(false);
-  batch[cur_batch].SetAligned(false);
-}
-
-void cAnalyze::FindLineage(cString cur_string)
-{
-  cString lin_type = "num_cpus";
-  if (cur_string.CountNumWords() > 0) lin_type = cur_string.PopWord();
-  
-  if (verbose == true) {
-    cout << "Reducing batch " << cur_batch
-    << " to " << lin_type << " lineage " << endl;
-  } else cout << "Performing lineage scan..." << endl;
-  
-  
-  // Determine by lin_type which genotype we are tracking...
-  cAnalyzeGenotype * found_gen = PopGenotype(lin_type, cur_batch);
-  
-  if (found_gen == NULL) {
-    cerr << "  Warning: Genotype " << lin_type
-    << " not found.  Lineage scan aborted." << endl;
-    return;
-  }
-  
-  // Otherwise, trace back through the id numbers to mark all of those
-  // in the ancestral lineage...
-  
-  // Construct a list of genotypes found...
-  
-  tListPlus<cAnalyzeGenotype> found_list;
-  found_list.Push(found_gen);
-  int next_id = found_gen->GetParentID();
-  bool found = true;
-  while (found == true) {
-    found = false;
-    
-    tListIterator<cAnalyzeGenotype> batch_it(batch[cur_batch].List());
-    while ((found_gen = batch_it.Next()) != NULL) {
-      if (found_gen->GetID() == next_id) {
-        batch_it.Remove();
-        found_list.Push(found_gen);
-        next_id = found_gen->GetParentID();
-        found = true;
-        break;
-      }
-    }
-  }
-  
-  // We now have all of the genotypes in this lineage, delete everything
-  // else.
-  
-  const int total_removed = batch[cur_batch].List().GetSize();
-  while (batch[cur_batch].List().GetSize() > 0) {
-    delete batch[cur_batch].List().Pop();
-  }
-  
-  // And fill it back in with the good stuff.
-  int total_kept = found_list.GetSize();
-  while (found_list.GetSize() > 0) {
-    batch[cur_batch].List().PushRear(found_list.Pop());
-  }
-  
-  if (verbose == true) {
-    cout << "  Lineage has " << total_kept << " genotypes; "
-    << total_removed << " were removed." << endl;
-  }
-  
-  // Adjust the flags on this batch
-  batch[cur_batch].SetLineage(true);
-  batch[cur_batch].SetAligned(false);
-}
-
-void cAnalyze::FindSexLineage(cString cur_string)
-{
-  
-  // detemine the method for construicting a lineage 
-  // by defauly, find the lineage of the final dominant
-  cString lin_type = "num_cpus";
-  if (cur_string.CountNumWords() > 0) lin_type = cur_string.PopWord();
-  
-  // parent_method determins which of the two parental lineages to use
-  // "rec_region_size" : 
-  //		"mother" (dominant parent) is the parent contributing
-  // 		more to the offspring genome (default)
-  // "genome_size" : 
-  //		"mother" (dominant parent) is the longer parent 
-  cString parent_method = "rec_region_size";
-  if (cur_string.CountNumWords() > 0) parent_method = cur_string.PopWord();
-  
-  if (verbose == true) {
-    cout << "Reducing batch " << cur_batch
-    << " to " << lin_type << " sexual lineage " 
-    << " using " << parent_method << " criteria." << endl;
-  } else cout << "Performing sexual lineage scan..." << endl;
-  
-  
-  // Determine by lin_type which genotype we are tracking...
-  cAnalyzeGenotype * found_gen = PopGenotype(lin_type, cur_batch);
-  
-  cAnalyzeGenotype * found_dad;
-  cAnalyzeGenotype * found_mom;
-  cAnalyzeGenotype * found_temp;
-  
-  if (found_gen == NULL) {
-    cerr << "  Warning: Genotype " << lin_type
-    << " not found.  Sexual lineage scan aborted." << endl;
-    return;
-  }
-  
-  // Otherwise, trace back through the id numbers to mark all of those
-  // in the ancestral lineage...
-  
-  // Construct a list of genotypes found...
-  
-  tListPlus<cAnalyzeGenotype> found_list;
-  found_list.Push(found_gen);
-  int next_id1 = found_gen->GetParentID();
-  int next_id2 = found_gen->GetParent2ID();
-  
-  bool found_m = true;
-  bool found_d = true;
-  
-  while (found_m == true & found_d == true) {
-    
-    //cout << "Searching for mom=" << next_id1
-    //	 << " and dad=" << next_id2 << endl;
-    found_m = false;
-    found_d = false;
-    
-    // Look for the father first....
-    tListIterator<cAnalyzeGenotype> batch_it(batch[cur_batch].List());
-    batch_it.Reset();
-    while ((found_dad = batch_it.Next()) != NULL) {
-      // Check if the father is found...
-      if (found_dad->GetID() == next_id2) {
-        //cout << "Found dad!" << endl;
-        batch_it.Remove();
-        found_list.Push(found_dad);
-        found_d = true; 
-        break;
-      }
-    }
-    
-    // dad may have already been found, check the find list!
-    if (found_d == false) {
-      tListIterator<cAnalyzeGenotype> found_it(found_list);
-      while ((found_dad = found_it.Next()) != NULL) {
-        if (found_dad->GetID() == next_id2) {
-          //cout << "Found dad in found list!" << endl;
-          found_d = true;
-          break;
-        }
-      }
-    } 
-    
-    // Next, look for the mother...
-    batch_it.Reset();
-    while ((found_mom = batch_it.Next()) != NULL) {
-      if (found_mom->GetID() == next_id1) {
-        //cout << "Found mom!" << endl;
-        batch_it.Remove();
-        found_list.Push(found_mom);
-        // if finding lineages by parental length, may have to swap 
-        if (parent_method == "genome_size" & 
-            found_mom->GetLength() < found_dad->GetLength()) { 
-          //cout << "Swapping parents!" << endl;
-          found_temp = found_mom; 
-          found_mom = found_dad; 
-          found_dad = found_temp; 
-        } 	
-        next_id1 = found_mom->GetParentID();
-        next_id2 = found_mom->GetParent2ID();
-        found_m = true;
-        break;
-      }
-    }
-    
-    // If the mother was not found, it may already have been placed in the
-    // found list as a father... 
-    if (found_m == false) {
-      tListIterator<cAnalyzeGenotype> found_it(found_list);
-      while ((found_mom = found_it.Next()) != NULL) {
-        if (found_mom->GetID() == next_id1) {
-          //cout << "Found mom as dad!" << endl;
-          // Don't move to found list, since its already there, but update
-          // to the next ids.
-          // if finding lineages by parental length, may have to swap 
-          if (parent_method == "genome_size" & 
-              found_mom->GetLength() < found_dad->GetLength()) {
-            //cout << "Swapping parents!" << endl;
-            found_temp = found_mom; 
-            found_mom = found_dad;  
-            found_dad = found_temp;
-          }
-          next_id1 = found_mom->GetParentID();
-          next_id2 = found_mom->GetParent2ID();
-          found_m = true;
-          break;
-        }
-      }
-    }    
-  }
-  
-  // We now have all of the genotypes in this lineage, delete everything
-  // else.
-  
-  const int total_removed = batch[cur_batch].List().GetSize();
-  while (batch[cur_batch].List().GetSize() > 0) {
-    delete batch[cur_batch].List().Pop();
-  }
-  
-  // And fill it back in with the good stuff.
-  int total_kept = found_list.GetSize();
-  while (found_list.GetSize() > 0) {
-    batch[cur_batch].List().PushRear(found_list.Pop());
-  }
-  
-  if (verbose == true) {
-    cout << "  Sexual lineage has " << total_kept << " genotypes; "
-    << total_removed << " were removed." << endl;
-  }
-  
-  // Adjust the flags on this batch
-  batch[cur_batch].SetLineage(false);
-  batch[cur_batch].SetAligned(false);
-}
-
-void cAnalyze::FindClade(cString cur_string)
-{
-  if (cur_string.GetSize() == 0) {
-    cerr << "  Warning: No clade specified for FIND_CLADE.  Aborting." << endl;
-    return;
-  }
-  
-  cString clade_type( cur_string.PopWord() );
-  
-  if (verbose == true) {
-    cout << "Reducing batch " << cur_batch
-    << " to clade " << clade_type << "." << endl;
-  } else cout << "Performing clade scan..." << endl;
-  
-  
-  // Determine by clade_type which genotype we are tracking...
-  cAnalyzeGenotype * found_gen = PopGenotype(clade_type, cur_batch);
-  
-  if (found_gen == NULL) {
-    cerr << "  Warning: Ancestral genotype " << clade_type
-    << " not found.  Clade scan aborted." << endl;
-    return;
-  }
-  
-  // Do this the brute force way... scan for one step at a time.
-  
-  // Construct a list of genotypes found...
-  
-  tListPlus<cAnalyzeGenotype> found_list; // Found and finished.
-  tListPlus<cAnalyzeGenotype> scan_list;  // Found, but need to scan for children.
-  scan_list.Push(found_gen);
-  
-  // Keep going as long as there is something in the scan list...
-  while (scan_list.GetSize() > 0) {
-    // Move the next genotype from the scan list to the found_list.
-    found_gen = scan_list.Pop();
-    int parent_id = found_gen->GetID();
-    found_list.Push(found_gen);
-    
-    // Seach for all of the children of this genotype...
-    tListIterator<cAnalyzeGenotype> batch_it(batch[cur_batch].List());
-    while ((found_gen = batch_it.Next()) != NULL) {
-      // If we found a child, place it into the scan list.
-      if (found_gen->GetParentID() == parent_id) {
-        batch_it.Remove();
-        scan_list.Push(found_gen);
-      }
-    }
-  }
-  
-  // We now have all of the genotypes in this clade, delete everything else.
-  
-  const int total_removed = batch[cur_batch].List().GetSize();
-  while (batch[cur_batch].List().GetSize() > 0) {
-    delete batch[cur_batch].List().Pop();
-  }
-  
-  // And fill it back in with the good stuff.
-  int total_kept = found_list.GetSize();
-  while (found_list.GetSize() > 0) {
-    batch[cur_batch].List().PushRear(found_list.Pop());
-  }
-  
-  if (verbose == true) {
-    cout << "  Clade has " << total_kept << " genotypes; "
-    << total_removed << " were removed." << endl;
-  }
-  
-  // Adjust the flags on this batch
-  batch[cur_batch].SetLineage(false);
-  batch[cur_batch].SetAligned(false);
-}
-
-void cAnalyze::SampleOrganisms(cString cur_string)
-{
-  double fraction = cur_string.PopWord().AsDouble();
-  int init_genotypes = batch[cur_batch].List().GetSize();
-  
-  double test_viable = 0; 
-  if (cur_string.GetSize() > 0) {
-    test_viable = cur_string.PopWord().AsDouble();
-  }
-  
-  if (verbose == true) {
-    cout << "Sampling " << fraction << " organisms from batch "
-    << cur_batch << "." << endl;
-  }
-  else cout << "Sampling Organisms..." << endl;
-  
-  int old_total = 0;
-  int new_total = 0;
-  
-  cAnalyzeGenotype * genotype = NULL;
-  tListIterator<cAnalyzeGenotype> batch_it(batch[cur_batch].List());
-  
-  // of only interested in viables, remove them first. 
-  if (test_viable==1) {
-    while ((genotype = batch_it.Next()) != NULL) {
-      if ((genotype->GetViable())==0) { 
-        batch_it.Remove();
-        delete genotype;
-      } 
-    } 
-  } 
-  
-  batch_it.Reset();
-  
-  while ((genotype = batch_it.Next()) != NULL) {
-    const int old_count = genotype->GetNumCPUs();
-    const int new_count = random.GetRandBinomial(old_count, fraction);
-    old_total += old_count;
-    new_total += new_count;
-    
-    if (new_count == 0) {
-      batch_it.Remove();
-      delete genotype;
-    } else {
-      genotype->SetNumCPUs(new_count);
-    }
-  }
-  
-  int num_genotypes = batch[cur_batch].List().GetSize();
-  if (verbose) {
-    cout << "  Removed " << old_total - new_total
-    << " organisms (" << init_genotypes - num_genotypes
-    << " genotypes); " << new_total
-    << " orgs (" << num_genotypes << " gens) remaining."
-    << endl;
-  }
-  
-  // Adjust the flags on this batch
-  batch[cur_batch].SetLineage(false);
-  batch[cur_batch].SetAligned(false);
-}
-
-
-void cAnalyze::SampleGenotypes(cString cur_string)
-{
-  double fraction = cur_string.PopWord().AsDouble();
-  int init_genotypes = batch[cur_batch].List().GetSize();
-  
-  double test_viable = 0;
-  if (cur_string.GetSize() > 0) {
-    test_viable = cur_string.PopWord().AsDouble();
-  }
-  
-  if (verbose == true) {
-    cout << "Sampling " << fraction << " genotypes from batch "
-    << cur_batch << "." << endl;
-  }
-  else cout << "Sampling Genotypes..." << endl;
-  
-  double frac_remove = 1.0 - fraction;
-  
-  cAnalyzeGenotype * genotype = NULL;
-  
-  tListIterator<cAnalyzeGenotype> batch_it(batch[cur_batch].List());
-  while ((genotype = batch_it.Next()) != NULL) {
-    if (random.P(frac_remove) || ((genotype->GetViable())==0 && test_viable==1) ) {
-      batch_it.Remove();
-      delete genotype;
-    }
-  }
-  
-  int num_genotypes = batch[cur_batch].List().GetSize();
-  if (verbose == true) {
-    cout << "  Removed " << init_genotypes - num_genotypes
-    << " genotypes; " << num_genotypes << " remaining."
-    << endl;
-  }
-  
-  // Adjust the flags on this batch
-  batch[cur_batch].SetLineage(false);
-  batch[cur_batch].SetAligned(false);
-}
-
-void cAnalyze::KeepTopGenotypes(cString cur_string)
-{
-  const int num_kept = cur_string.PopWord().AsInt();
-  const int num_genotypes = batch[cur_batch].List().GetSize();
-  const int num_removed = num_genotypes - num_kept;
-  
-  for (int i = 0; i < num_removed; i++) {
-    delete batch[cur_batch].List().PopRear();
-  }
-  
-  // Adjust the flags on this batch
-  // batch[cur_batch].SetLineage(false); // Should not destroy a lineage...
-  batch[cur_batch].SetAligned(false);
-}
-
-
-
-//////////////// Output Commands...
-
-void cAnalyze::CommandPrint(cString cur_string)
-{
-  if (verbose == true) cout << "Printing batch " << cur_batch << endl;
-  else cout << "Printing organisms..." << endl;
-  
-  cString directory = PopDirectory(cur_string, "genebank/");
-  
-  tListIterator<cAnalyzeGenotype> batch_it(batch[cur_batch].List());
-  cAnalyzeGenotype * genotype = NULL;
-  while ((genotype = batch_it.Next()) != NULL) {
-    cString filename(directory);
-    
-    if (cur_string.GetSize() > 0) {
-      filename += cur_string.PopWord();
-    }
-    else { 
-      filename += genotype->GetName();
-      filename += ".gen";
-    }
-    
-    cTestUtil::PrintGenome(genotype->GetGenome(), filename);
-    if (verbose) cout << "Printing: " << filename << endl;
-  }
-}
-
-void cAnalyze::CommandTrace(cString cur_string)
-{
-  if (verbose == true) cout << "Tracing batch " << cur_batch << endl;
-  else cout << "Tracing organisms..." << endl;
-  
-  int words = cur_string.CountNumWords();
-  
-  cString dir = cur_string.PopWord();
-  cString defaultDirectory = "genebank/";
-  cString directory = PopDirectory(dir, defaultDirectory);
-  
-  int useResources = 0;
-  if(words >= 2) {
-    useResources = cur_string.PopWord().AsInt();
-    // All non-zero values are considered false
-    if(useResources != 0 && useResources != 1) {
-      useResources = 0;
-    }
-  }
-  
-  bool backupUsage;
-  tArray<double> backupResources;
-  
-  if(useResources) {
-    // Backup test cpu data
-    backupUsage = cTestCPU::UseResources();
-    backupResources = cTestCPU::GetResources();
-    
-    cTestCPU::UseResources() = true;
-  }
-  
-  tListIterator<cAnalyzeGenotype> batch_it(batch[cur_batch].List());
-  cAnalyzeGenotype * genotype = NULL;
-  while ((genotype = batch_it.Next()) != NULL) {
-    cString filename(directory);
-    filename += genotype->GetName();
-    filename += ".trace";
-    
-    if (genotype->GetGenome().GetSize() == 0) {
-      break;
-    }
-    
-    // Build the hardware status printer for tracing.
-    ofstream trace_fp;
-    trace_fp.open(filename);
-    assert (trace_fp.good() == true); // Unable to open trace file.
-    cHardwareStatusPrinter trace_printer(trace_fp);
-
-    // Build the test info for printing.
-    cCPUTestInfo test_info;
-    test_info.TestThreads();
-    test_info.SetTraceExecution(&trace_printer);
-    
-    cTestCPU::TestGenome(test_info, genotype->GetGenome());
-    
-    if (verbose) cout << "  Tracing: " << filename << endl;
-    trace_fp.close();
-  }
-  
-  if(useResources) {
-    // Set the test cpu back to the state it was in before we messed with it
-    cTestCPU::UseResources() = backupUsage;
-    cTestCPU::SetupResourceArray(backupResources);
-  }
-  
-  return;
-}
-
-void cAnalyze::CommandPrintTasks(cString cur_string)
-{
-  if (verbose == true) cout << "Printing tasks in batch " << cur_batch << endl;
-  else cout << "Printing tasks..." << endl;
-  
-  // Load in the variables...
-  cString filename("tasks.dat");
-  if (cur_string.GetSize() != 0) filename = cur_string.PopWord();
-  
-  ofstream & fp = data_file_manager.GetOFStream(filename);
-  
-  // Loop through all of the genotypes in this batch...
-  tListIterator<cAnalyzeGenotype> batch_it(batch[cur_batch].List());
-  cAnalyzeGenotype * genotype = NULL;
-  while ((genotype = batch_it.Next()) != NULL) {
-    fp << genotype->GetID() << " ";
-    genotype->PrintTasks(fp);
-    fp << endl;
-  }
-}
-
-void cAnalyze::CommandDetail(cString cur_string)
-{
-  if (verbose == true) cout << "Detailing batch " << cur_batch << endl;
-  else cout << "Detailing..." << endl;
-  
-  // Load in the variables...
-  cString filename("detail.dat");
-  if (cur_string.GetSize() != 0) filename = cur_string.PopWord();
-  
-  // Construct a linked list of details needed...
-  tList< tDataEntryCommand<cAnalyzeGenotype> > output_list;
-  tListIterator< tDataEntryCommand<cAnalyzeGenotype> > output_it(output_list);
-  LoadGenotypeDataList(cur_string, output_list);
-  
-  // Determine the file type...
-  int file_type = FILE_TYPE_TEXT;
-  cString file_extension(filename);
-  while (file_extension.Find('.') != -1) file_extension.Pop('.');
-  if (file_extension == "html") file_type = FILE_TYPE_HTML;
-  
-  // Setup the file...
-  if (filename == "cout") {
-    CommandDetail_Header(cout, file_type, output_it);
-    CommandDetail_Body(cout, file_type, output_it);
-  } else {
-    ofstream & fp = data_file_manager.GetOFStream(filename);
-    CommandDetail_Header(fp, file_type, output_it);
-    CommandDetail_Body(fp, file_type, output_it);
-  }
-  
-  // And clean up...
-  while (output_list.GetSize() != 0) delete output_list.Pop();
-}
-
-
-void cAnalyze::CommandDetailTimeline(cString cur_string)
-{
-  if (verbose == true) cout << "Detailing batch "
-    << cur_batch << " based on time" << endl;
-  else cout << "Detailing..." << endl;
-  
-  // Load in the variables...
-  cString filename("detail_timeline.dat");
-  int time_step = 100;
-  int max_time = 100000;
-  if (cur_string.GetSize() != 0) filename = cur_string.PopWord();
-  if (cur_string.GetSize() != 0) time_step = cur_string.PopWord().AsInt();
-  if (cur_string.GetSize() != 0) max_time = cur_string.PopWord().AsInt();
-  
-  if (verbose == true) {
-    cout << "  Time step = " << time_step << endl
-    << "  Max time = " << max_time << endl;
-  }
-  
-  // Construct a linked list of details needed...
-  tList< tDataEntryCommand<cAnalyzeGenotype> > output_list;
-  tListIterator< tDataEntryCommand<cAnalyzeGenotype> > output_it(output_list);
-  LoadGenotypeDataList(cur_string, output_list);
-  
-  // Determine the file type...
-  int file_type = FILE_TYPE_TEXT;
-  cString file_extension(filename);
-  while (file_extension.Find('.') != -1) file_extension.Pop('.');
-  if (file_extension == "html") file_type = FILE_TYPE_HTML;
-  
-  // Setup the file...
-  if (filename == "cout") {
-    CommandDetail_Header(cout, file_type, output_it, time_step);
-    CommandDetail_Body(cout, file_type, output_it, time_step, max_time);
-  } else {
-    ofstream & fp = data_file_manager.GetOFStream(filename);
-    CommandDetail_Header(fp, file_type, output_it, time_step);
-    CommandDetail_Body(fp, file_type, output_it, time_step, max_time);
-  }
-  
-  // And clean up...
-  while (output_list.GetSize() != 0) delete output_list.Pop();
-}
-
-
-void cAnalyze::CommandDetail_Header(ostream & fp, int format_type,
-                                    tListIterator< tDataEntryCommand<cAnalyzeGenotype> > & output_it,
-                                    int time_step)
-{
-  // Write out the header on the file
-  if (format_type == FILE_TYPE_TEXT) {
-    fp << "#filetype genotype_data" << endl;
-    fp << "#format ";
-    if (time_step > 0) fp << "update ";
-    while (output_it.Next() != NULL) {
-      const cString & entry_name = output_it.Get()->GetName();
-      fp << entry_name << " ";
-    }
-    fp << endl << endl;
-    
-    // Give the more human-readable legend.
-    fp << "# Legend:" << endl;
-    int count = 0;
-    if (time_step > 0) fp << "# " << ++count << ": Update" << endl;
-    while (output_it.Next() != NULL) {
-      const cString & entry_desc = output_it.Get()->GetDesc();
-      fp << "# " << ++count << ": " << entry_desc << endl;
-    }
-    fp << endl;
-  } else { // if (format_type == FILE_TYPE_HTML) {
-    fp << "<html>" << endl
-    << "<body bgcolor=\"#FFFFFF\"" << endl
-    << " text=\"#000000\"" << endl
-    << " link=\"#0000AA\"" << endl
-    << " alink=\"#0000FF\"" << endl
-    << " vlink=\"#000044\">" << endl
-    << endl
-    << "<h1 align=center>Run " << batch[cur_batch].Name() << endl
-    << endl
-    << "<center>" << endl
-    << "<table border=1 cellpadding=2><tr>" << endl;
-    
-    if (time_step > 0) fp << "<th bgcolor=\"#AAAAFF\">Update ";
-    while (output_it.Next() != NULL) {
-      const cString & entry_desc = output_it.Get()->GetDesc();
-      fp << "<th bgcolor=\"#AAAAFF\">" << entry_desc << " ";
-    }
-    fp << "</tr>" << endl;
-    
-  }
-  
-  }
-
-
-void cAnalyze::CommandDetail_Body(ostream & fp, int format_type,
-                                  tListIterator< tDataEntryCommand<cAnalyzeGenotype> > & output_it,
-                                  int time_step, int max_time)
-{
-  // Loop through all of the genotypes in this batch...
-  tListIterator<cAnalyzeGenotype> batch_it(batch[cur_batch].List());
-  cAnalyzeGenotype * cur_genotype = batch_it.Next();
-  cAnalyzeGenotype * next_genotype = batch_it.Next();
-  cAnalyzeGenotype * prev_genotype = NULL;
-  
-  int cur_time = 0;
-  while (cur_genotype != NULL && cur_time <= max_time) {
-    output_it.Reset();
-    tDataEntryCommand<cAnalyzeGenotype> * data_command = NULL;
-    if (format_type == FILE_TYPE_HTML) {
-      fp << "<tr>";
-      if (time_step > 0) fp << "<td>" << cur_time << " ";
-    }
-    else if (time_step > 0) {  // TEXT file, printing times...
-      fp << cur_time << " ";
-    }
-    
-    while ((data_command = output_it.Next()) != NULL) {
-      data_command->SetTarget(cur_genotype);
-      cur_genotype->SetSpecialArgs(data_command->GetArgs());
-      if (format_type == FILE_TYPE_HTML) {
-        int compare = 0;
-        if (prev_genotype) {
-          prev_genotype->SetSpecialArgs(data_command->GetArgs());
-          compare = data_command->Compare(prev_genotype);
-        }
-        data_command->HTMLPrint(fp, compare);
-      }
-      else {  // if (format_type == FILE_TYPE_TEXT) {
-        fp << data_command->GetEntry() << " ";
-      }
-      }
-    if (format_type == FILE_TYPE_HTML) fp << "</tr>";
-    fp << endl;
-    
-    cur_time += time_step;
-    if (time_step > 0) {
-      while (next_genotype && next_genotype->GetUpdateBorn() < cur_time) {
-        prev_genotype = cur_genotype;
-        cur_genotype = next_genotype;
-        next_genotype = batch_it.Next();
-      }
-    }
-    else {
-      // Always moveon if we're not basing this on time, or if we've run out
-      // of genotypes.
-      prev_genotype = cur_genotype;
-      cur_genotype = next_genotype;
-      next_genotype = batch_it.Next();
-    }
-    
-    }
-  
-  // If in HTML mode, we need to end the file...
-  if (format_type == FILE_TYPE_HTML) {
-    fp << "</table>" << endl
-    << "</center>" << endl;
-  }
-}
-
-void cAnalyze::CommandDetailAverage_Body(ostream & fp, int num_outputs,
-                                         tListIterator< tDataEntryCommand<cAnalyzeGenotype> > & output_it)
-{
-  // Loop through all of the genotypes in this batch...
-  tListIterator<cAnalyzeGenotype> batch_it(batch[cur_batch].List());
-  cAnalyzeGenotype * cur_genotype = batch_it.Next();
-  cAnalyzeGenotype * next_genotype = batch_it.Next();
-  cAnalyzeGenotype * prev_genotype = NULL;
-  
-  tArray<cDoubleSum> output_counts(num_outputs);
-  for (int i = 0; i < num_outputs; i++) { output_counts[i].Clear();} 
-  int count; 
-  while (cur_genotype != NULL) { 
-    count = 0; 
-    output_it.Reset();
-    tDataEntryCommand<cAnalyzeGenotype> * data_command = NULL;
-    while ((data_command = output_it.Next()) != NULL) {
-      data_command->SetTarget(cur_genotype);
-      cur_genotype->SetSpecialArgs(data_command->GetArgs());
-      for (int j = 0; j < cur_genotype->GetNumCPUs(); j++) { 
-        output_counts[count].Add((double) data_command->GetEntry().AsString().AsDouble()); 
-      } 	
-      count++;
-    }
-    
-    prev_genotype = cur_genotype;
-    cur_genotype = next_genotype;
-    next_genotype = batch_it.Next();
-  }
-  fp << batch[cur_batch].Name() << " "; 
-  for (int i = 0; i < num_outputs; i++) {  
-    fp << output_counts[i].Average() << " ";
-  } 
-  fp << endl;   
-}
-
-void cAnalyze::CommandDetailAverage(cString cur_string) 
-{ 
-  if (verbose == true) cout << "Average detailing batch " << cur_batch << endl;
-  else cout << "Detailing..." << endl;
-  
-  // Load in the variables...
-  cString filename("detail.dat");
-  if (cur_string.GetSize() != 0) filename = cur_string.PopWord();
-  
-  // Construct a linked list of details needed...
-  tList< tDataEntryCommand<cAnalyzeGenotype> > output_list;
-  tListIterator< tDataEntryCommand<cAnalyzeGenotype> > output_it(output_list);
-  LoadGenotypeDataList(cur_string, output_list);
-  
-  // check if file is already in use.
-  bool file_active = data_file_manager.IsOpen(filename);
-  
-  ofstream & fp = data_file_manager.GetOFStream(filename);
-  
-  // if it's a new file print out the header
-  if (file_active == false) {
-    CommandDetail_Header(fp, FILE_TYPE_TEXT, output_it);
-  } 
-  CommandDetailAverage_Body(fp, cur_string.CountNumWords(), output_it);
-  
-  while (output_list.GetSize() != 0) delete output_list.Pop();
-  
-} 
-
-void cAnalyze::CommandDetailBatches(cString cur_string)
-{
-  // Load in the variables...
-  cString keyword("num_cpus");
-  cString filename("detail_batch.dat");
-  if (cur_string.GetSize() != 0) keyword = cur_string.PopWord();
-  if (cur_string.GetSize() != 0) filename = cur_string.PopWord();
-  
-  if (verbose == true) cout << "Detailing batches for " << keyword << endl;
-  else cout << "Detailing Batches..." << endl;
-  
-  // Scan the functions list for the keyword we need...
-  SetupGenotypeDataList();
-  tListIterator< tDataEntryBase<cAnalyzeGenotype> >
-    output_it(genotype_data_list);
-  
-  // Divide up the keyword into its acrual entry and its arguments...
-  cString cur_args = keyword;
-  cString cur_entry = cur_args.Pop(':');
-  
-  // Find its associated command...
-  tDataEntryCommand<cAnalyzeGenotype> * cur_command = NULL;
-  bool found = false;
-  while (output_it.Next() != NULL) {
-    if (output_it.Get()->GetName() == cur_entry) {
-      cur_command = new tDataEntryCommand<cAnalyzeGenotype>
-      (output_it.Get(), cur_args);
-      found = true;
-      break;
-    }
-  }
-  if (found == false) {
-    cout << "Error: Unknown data type: " << cur_entry << endl;
-    return;
-  }
-  
-  
-  // Determine the file type...
-  int file_type = FILE_TYPE_TEXT;
-  cString file_extension(filename);
-  while (file_extension.Find('.') != -1) file_extension.Pop('.');
-  if (file_extension == "html") file_type = FILE_TYPE_HTML;
-  
-  ofstream & fp = data_file_manager.GetOFStream(filename);
-  
-  // Write out the header on the file
-  if (file_type == FILE_TYPE_TEXT) {
-    fp << "#filetype batch_data" << endl
-    << "#format batch_id " << keyword << endl
-    << endl;
-    
-    // Give the more human-readable legend.
-    fp << "# Legend:" << endl
-      << "#  Column 1 = Batch ID" << endl
-      << "#  Remaining entries: " << cur_command->GetDesc() << endl
-      << endl;
-    
-  } else { // if (file_type == FILE_TYPE_HTML) {
-    fp << "<html>" << endl
-    << "<body bgcolor=\"#FFFFFF\"" << endl
-    << " text=\"#000000\"" << endl
-    << " link=\"#0000AA\"" << endl
-    << " alink=\"#0000FF\"" << endl
-    << " vlink=\"#000044\">" << endl
-    << endl
-    << "<h1 align=center> Distribution of " << cur_command->GetDesc()
-    << endl << endl
-    << "<center>" << endl
-    << "<table border=1 cellpadding=2>" << endl
-    << "<tr><th bgcolor=\"#AAAAFF\">" << cur_command->GetDesc() << "</tr>"
-    << endl;
-  }
-  
-  
-  // Loop through all of the batches...
-  for (int i = 0; i < MAX_BATCHES; i++) {
-    if (batch[i].List().GetSize() == 0) continue;
-    
-    if (file_type == FILE_TYPE_HTML) fp << "<tr><td>";
-    fp << i << " ";
-    
-    tListIterator<cAnalyzeGenotype> batch_it(batch[i].List());
-    cAnalyzeGenotype * genotype = NULL;
-    while ((genotype = batch_it.Next()) != NULL) {
-      output_it.Reset();
-      if (file_type == FILE_TYPE_HTML) fp << "<td>";
-      
-      cur_command->SetTarget(genotype);
-      genotype->SetSpecialArgs(cur_command->GetArgs());
-      if (file_type == FILE_TYPE_HTML) {
-        cur_command->HTMLPrint(fp, 0);
-      }
-      else {  // if (file_type == FILE_TYPE_TEXT) {
-        fp << cur_command->GetEntry() << " ";
-      }
-      }
-    if (file_type == FILE_TYPE_HTML) fp << "</tr>";
-    fp << endl;
-    }
-  
-  // If in HTML mode, we need to end the file...
-  if (file_type == FILE_TYPE_HTML) {
-    fp << "</table>" << endl
-    << "</center>" << endl;
-  }
-  
-  delete cur_command;
-  }
-
-
-
-void cAnalyze::CommandDetailIndex(cString cur_string)
-{
-  cout << "Creating a Detail Index..." << endl;
-  
-  // A filename and min and max batches must be included.
-  if (cur_string.CountNumWords() < 3) {
-    cerr << "Error: must include filename, and min and max batch numbers."
-    << endl;
-    exit(1);
-  }
-  
-  // Load in the variables...
-  cString filename(cur_string.PopWord());
-  int min_batch = cur_string.PopWord().AsInt();
-  int max_batch = cur_string.PopWord().AsInt();
-  
-  if (max_batch < min_batch) {
-    cerr << "Error: min_batch=" << min_batch
-    << ", max_batch=" << max_batch << "  (incorrect order?)" << endl;
-    exit(1);
-  }
-  
-  // Construct a linked list of details needed...
-  tList< tDataEntryBase<cAnalyzeGenotype> > output_list;
-  tListIterator< tDataEntryBase<cAnalyzeGenotype> > output_it(output_list);
-  
-  // For the moment, just put everything into the output list.
-  SetupGenotypeDataList();
-  
-  // If no args were given, load all of the stats.
-  if (cur_string.CountNumWords() == 0) {
-    tListIterator< tDataEntryBase<cAnalyzeGenotype> >
-    genotype_data_it(genotype_data_list);
-    while (genotype_data_it.Next() != NULL) {
-      output_list.PushRear(genotype_data_it.Get());
-    }
-  }
-  // Otherwise, load only those listed.
-  else {
-    while (cur_string.GetSize() != 0) {
-      // Setup the next entry
-      cString cur_entry = cur_string.PopWord();
-      bool found_entry = false;
-      
-      // Scan the genotype data list for the current entry
-      tListIterator< tDataEntryBase<cAnalyzeGenotype> >
-        genotype_data_it(genotype_data_list);
-      
-      while (genotype_data_it.Next() != NULL) {
-        if (genotype_data_it.Get()->GetName() == cur_entry) {
-          output_list.PushRear(genotype_data_it.Get());
-          found_entry = true;
-          break;
-        }
-      }
-      
-      // If the entry was not found, give a warning.
-      if (found_entry == false) {
-        int best_match = 1000;
-        cString best_entry;
-        
-        genotype_data_it.Reset();
-        while (genotype_data_it.Next() != NULL) {
-          const cString & test_str = genotype_data_it.Get()->GetName();
-          const int test_dist = cStringUtil::EditDistance(test_str, cur_entry);
-          if (test_dist < best_match) {
-            best_match = test_dist;
-            best_entry = test_str;
-          }
-        }	
-        
-        cerr << "Warning: Format entry \"" << cur_entry
-          << "\" not found.  Best match is \""
-          << best_entry << "\"." << endl;
-      }
-      
-    }
-  }
-  
-  // Setup the file...
-  ofstream fp;
-  fp.open(filename);
-  
-  // Determine the file type...
-  int file_type = FILE_TYPE_TEXT;
-  while (filename.Find('.') != -1) filename.Pop('.'); // Grab only extension
-  if (filename == "html") file_type = FILE_TYPE_HTML;
-  
-  // Write out the header on the file
-  if (file_type == FILE_TYPE_TEXT) {
-    fp << "#filetype genotype_data" << endl;
-    fp << "#format ";
-    while (output_it.Next() != NULL) {
-      const cString & entry_name = output_it.Get()->GetName();
-      fp << entry_name << " ";
-    }
-    fp << endl << endl;
-    
-    // Give the more human-readable legend.
-    fp << "# Legend:" << endl;
-    fp << "# 1: Batch Name" << endl;
-    int count = 1;
-    while (output_it.Next() != NULL) {
-      const cString & entry_desc = output_it.Get()->GetDesc();
-      fp << "# " << ++count << ": " << entry_desc << endl;
-    }
-    fp << endl;
-  } else { // if (file_type == FILE_TYPE_HTML) {
-    fp << "<html>" << endl
-    << "<body bgcolor=\"#FFFFFF\"" << endl
-    << " text=\"#000000\"" << endl
-    << " link=\"#0000AA\"" << endl
-    << " alink=\"#0000FF\"" << endl
-    << " vlink=\"#000044\">" << endl
-    << endl
-    << "<h1 align=center>Batch Index" << endl
-    << endl
-    << "<center>" << endl
-    << "<table border=1 cellpadding=2><tr>" << endl;
-    
-    fp << "<th bgcolor=\"#AAAAFF\">Batch ";
-    while (output_it.Next() != NULL) {
-      const cString & entry_desc = output_it.Get()->GetDesc();
-      fp << "<th bgcolor=\"#AAAAFF\">" << entry_desc << " ";
-    }
-    fp << "</tr>" << endl;
-    
-  }
-  
-  // Loop through all of the batchs...
-  for (int batch_id = min_batch; batch_id <= max_batch; batch_id++) {
-    cAnalyzeGenotype * genotype = batch[batch_id].List().GetFirst();
-    if (genotype == NULL) continue;
-    output_it.Reset();
-    tDataEntryBase<cAnalyzeGenotype> * data_entry = NULL;
-    const cString & batch_name = batch[batch_id].Name();
-    if (file_type == FILE_TYPE_HTML) {
-      fp << "<tr><th><a href=lineage." << batch_name << ".html>"
-      << batch_name << "</a> ";
-    }
-    else {
-      fp << batch_name << " ";
-    }
-    
-    while ((data_entry = output_it.Next()) != NULL) {
-      data_entry->SetTarget(genotype);
-      if (file_type == FILE_TYPE_HTML) {
-        fp << "<td align=center><a href=\""
-        << data_entry->GetName() << "." << batch_name << ".png\">"
-        << *data_entry << "</a> ";
-      }
-      else {  // if (file_type == FILE_TYPE_TEXT) {
-        fp << *data_entry << " ";
-      }
-      }
-    if (file_type == FILE_TYPE_HTML) fp << "</tr>";
-    fp << endl;
-    }
-  
-  // If in HTML mode, we need to end the file...
-  if (file_type == FILE_TYPE_HTML) {
-    fp << "</table>" << endl
-    << "</center>" << endl;
-  }
-}
-
-void cAnalyze::CommandHistogram(cString cur_string)
-{
-  if (verbose == true) cout << "Histogram batch " << cur_batch << endl;
-  else cout << "Histograming..." << endl;
-  
-  // Load in the variables...
-  cString filename("histogram.dat");
-  if (cur_string.GetSize() != 0) filename = cur_string.PopWord();
-  
-  // Construct a linked list of details needed...
-  tList< tDataEntryCommand<cAnalyzeGenotype> > output_list;
-  tListIterator< tDataEntryCommand<cAnalyzeGenotype> > output_it(output_list);
-  LoadGenotypeDataList(cur_string, output_list);
-  
-  // Determine the file type...
-  int file_type = FILE_TYPE_TEXT;
-  cString file_extension(filename);
-  while (file_extension.Find('.') != -1) file_extension.Pop('.');
-  if (file_extension == "html") file_type = FILE_TYPE_HTML;
-  
-  // Setup the file...
-  if (filename == "cout") {
-    CommandHistogram_Header(cout, file_type, output_it);
-    CommandHistogram_Body(cout, file_type, output_it);
-  } else {
-    ofstream & fp = data_file_manager.GetOFStream(filename);
-    CommandHistogram_Header(fp, file_type, output_it);
-    CommandHistogram_Body(fp, file_type, output_it);
-  }
-  
-  // And clean up...
-  while (output_list.GetSize() != 0) delete output_list.Pop();
-}
-
-void cAnalyze::CommandHistogram_Header(ostream & fp, int format_type,
-       tListIterator< tDataEntryCommand<cAnalyzeGenotype> > & output_it)
-{
-  // Write out the header on the file
-  if (format_type == FILE_TYPE_TEXT) {
-    fp << "#filetype histogram_data" << endl;
-    fp << "#format ";
-    while (output_it.Next() != NULL) {
-      const cString & entry_name = output_it.Get()->GetName();
-      fp << entry_name << " ";
-    }
-    fp << endl << endl;
-    
-    // Give the more human-readable legend.
-    fp << "# Histograms:" << endl;
-    int count = 0;
-    while (output_it.Next() != NULL) {
-      const cString & entry_desc = output_it.Get()->GetDesc();
-      fp << "# " << ++count << ": " << entry_desc << endl;
-    }
-    fp << endl;
-  } else { // if (format_type == FILE_TYPE_HTML) {
-    fp << "<html>" << endl
-       << "<body bgcolor=\"#FFFFFF\"" << endl
-       << " text=\"#000000\"" << endl
-       << " link=\"#0000AA\"" << endl
-       << " alink=\"#0000FF\"" << endl
-       << " vlink=\"#000044\">" << endl
-       << endl
-       << "<h1 align=center>Histograms for " << batch[cur_batch].Name()
-       << "</h1>" << endl
-       << endl
-       << "<center>" << endl
-       << "<table border=1 cellpadding=2><tr>" << endl;
-    
-    while (output_it.Next() != NULL) {
-      const cString & entry_desc = output_it.Get()->GetDesc();
-      const cString & entry_name = output_it.Get()->GetName();
-      fp << "<tr><th bgcolor=\"#AAAAFF\"><a href=\"#"
-	 << entry_name << "\">"
-	 << entry_desc << "</a></tr>";
-    }
-    fp << "</tr></table>" << endl;    
-  }
-}
-
-
-void cAnalyze::CommandHistogram_Body(ostream & fp, int format_type,
-	     tListIterator< tDataEntryCommand<cAnalyzeGenotype> > & output_it)
-{
-  output_it.Reset();
-  tDataEntryCommand<cAnalyzeGenotype> * data_command = NULL;
-    
-  while ((data_command = output_it.Next()) != NULL) {
-    if (format_type == FILE_TYPE_TEXT) {
-      fp << "# --- " << data_command->GetDesc() << " ---" << endl;
-    } else {
-      fp << "<table cellpadding=3>" << endl
-	 << "<tr><th colspan=3><a name=\"" << data_command->GetName() << "\">"
-	 << data_command->GetDesc() << "</th></tr>" << endl;
-    }
-
-    tDictionary<int> count_dict;
-
-    // Loop through all genotypes in this batch to collect the info we need.
-    tListIterator<cAnalyzeGenotype> batch_it(batch[cur_batch].List());
-    cAnalyzeGenotype * cur_genotype;
-    while ((cur_genotype = batch_it.Next()) != NULL) {
-      data_command->SetTarget(cur_genotype);
-      const cString cur_name(data_command->GetEntry().AsString());
-      int count = 0;
-      count_dict.Find(cur_name, count);
-      count += cur_genotype->GetNumCPUs();
-      count_dict.SetValue(cur_name, count);
-    }
-
-    tList<cString> name_list;
-    tList<int> count_list;
-    count_dict.AsLists(name_list, count_list);
-
-    // Figure out the maximum count and the maximum widths...
-    int max_count = 0;
-    int max_name_width = 0;
-    int max_count_width = 0;
-    tListIterator<int> count_it(count_list);
-    tListIterator<cString> name_it(name_list);
-    while (count_it.Next() != NULL) {
-      const cString cur_name( *(name_it.Next()) );
-      const int cur_count = *(count_it.Get());
-      const int name_width = cur_name.GetSize();
-      const int count_width = cStringUtil::Stringf("%d", cur_count).GetSize();
-      if (cur_count > max_count) max_count = cur_count;
-      if (name_width > max_name_width) max_name_width = name_width;
-      if (count_width > max_count_width) max_count_width = count_width;
-    }
-
-    // Do some final calculations now that we know the maximums...
-    const int max_stars = 75 - max_name_width - max_count_width;
-
-    // Now print everything out...
-    count_it.Reset();
-    name_it.Reset();
-    while (count_it.Next() != NULL) {
-      const cString cur_name( *(name_it.Next()) );
-      const int cur_count = *(count_it.Get());
-      if (cur_count == 0) continue;
-      int num_stars = (cur_count * max_stars) / max_count;
-
-      if (format_type == FILE_TYPE_TEXT) {
-	fp << setw(max_name_width) << cur_name << "  " 
-	   << setw(max_count_width) << cur_count << "  ";
-	for (int i = 0; i < num_stars; i++) { fp << '#'; }
-	fp << endl;
-      } else { // FILE_TYPE_HTML
-	fp << "<tr><td>" << cur_name
-	   << "<td>" << cur_count
-	   << "<td>";
-	for (int i = 0; i < num_stars; i++) { fp << '#'; }
-	fp << "</tr>" << endl;
-      }
-    }
-
-    if (format_type == FILE_TYPE_TEXT) {
-      // Skip a line between histograms...
-      fp << endl;
-    } else {
-      fp << "</table><br><br>" << endl << endl;;
-    }
-  }
-  
-  // If in HTML mode, we need to end the file...
-  if (format_type == FILE_TYPE_HTML) {
-    fp << "</table>" << endl
-    << "</center>" << endl;
-  }
-}
-
-
-///// Population Analysis Commands ////
-
-void cAnalyze::CommandPrintPhenotypes(cString cur_string)
-{
-  if (verbose == true) cout << "Printing phenotypes in batch "
-    << cur_batch << endl;
-  else cout << "Printing phenotypes..." << endl;
-  
-  // Load in the variables...
-  cString filename("phenotype.dat");
-  if (cur_string.GetSize() != 0) filename = cur_string.PopWord();
-  
-  // Make sure we have at least one genotype...
-  if (batch[cur_batch].List().GetSize() == 0) return;
-  
-  // Setup the phenotype categories...
-  const int num_tasks = batch[cur_batch].List().GetFirst()->GetNumTasks();
-  const int num_phenotypes = 1 << (num_tasks + 1);
-  tArray<int> phenotype_counts(num_phenotypes);
-  tArray<int> genotype_counts(num_phenotypes);
-  tArray<double> total_length(num_phenotypes);
-  tArray<double> total_gest(num_phenotypes);
-  
-  phenotype_counts.SetAll(0);
-  genotype_counts.SetAll(0);
-  total_length.SetAll(0.0);
-  total_gest.SetAll(0.0);
-  
-  // Loop through all of the genotypes in this batch...
-  tListIterator<cAnalyzeGenotype> batch_it(batch[cur_batch].List());
-  cAnalyzeGenotype * genotype = NULL;
-  while ((genotype = batch_it.Next()) != NULL) {
-    int phen_id = 0;
-    if (genotype->GetViable() == true) phen_id++;
-    for (int i = 0; i < num_tasks; i++) {
-      if (genotype->GetTaskCount(i) > 0)  phen_id += 1 << (i+1);
-    }
-    phenotype_counts[phen_id] += genotype->GetNumCPUs();
-    genotype_counts[phen_id]++;
-    total_length[phen_id] += genotype->GetNumCPUs() * genotype->GetLength();
-    total_gest[phen_id] += genotype->GetNumCPUs() * genotype->GetGestTime();
-  }
-  
-  // Print out the results...
-  
-  ofstream & fp = data_file_manager.GetOFStream(filename);
-  
-  fp << "# 1: Number of organisms of this phenotype" << endl
-    << "# 2: Number of genotypes of this phenotye" << endl
-    << "# 3: Average Genome Length" << endl
-    << "# 4: Average Gestation Time" << endl
-    << "# 5: Viability of Phenotype" << endl
-    << "# 6+: Tasks performed in this phenotype" << endl
-    << endl;
-  
-  // @CAO Lets do this inefficiently for the moment, but print out the
-  // phenotypes in order.
-  
-  while (true) {
-    // Find the next phenotype to print...
-    int max_count = phenotype_counts[0];
-    int max_position = 0;
-    for (int i = 0; i < num_phenotypes; i++) {
-      if (phenotype_counts[i] > max_count) {
-        max_count = phenotype_counts[i];
-        max_position = i;
-      }
-    }
-    
-    if (max_count == 0) break; // we're done!
-    
-    fp << phenotype_counts[max_position] << " "
-      << genotype_counts[max_position] << " "
-      << total_length[max_position] / phenotype_counts[max_position] << " "
-      << total_gest[max_position] / phenotype_counts[max_position] << " "
-      << (max_position & 1) << "  ";
-    for (int i = 1; i <= num_tasks; i++) {
-      if ((max_position >> i) & 1 > 0) fp << "1 ";
-      else fp << "0 ";
-    }
-    fp << endl;
-    phenotype_counts[max_position] = 0;
-  }
-  
-  fp.close();
-}
-
-
-// Print various diversity metrics from the current batch of genotypes...
-void cAnalyze::CommandPrintDiversity(cString cur_string)
-{
-  if (verbose == true) cout << "Printing diversity data for batch "
-    << cur_batch << endl;
-  else cout << "Printing diversity data..." << endl;
-  
-  // Load in the variables...
-  cString filename("diversity.dat");
-  if (cur_string.GetSize() != 0) filename = cur_string.PopWord();
-  
-  // Make sure we have at least one genotype...
-  if (batch[cur_batch].List().GetSize() == 0) return;
-  
-  // Setup the task categories...
-  const int num_tasks = batch[cur_batch].List().GetFirst()->GetNumTasks();
-  tArray<int> task_count(num_tasks);
-  tArray<int> task_gen_count(num_tasks);
-  tArray<double> task_gen_dist(num_tasks);
-  tArray<double> task_site_entropy(num_tasks);
-  task_count.SetAll(0);
-  task_gen_count.SetAll(0);
-  
-  // We must determine the average hamming distance between genotypes in
-  // this batch that perform each task.  Levenstein distance would be ideal,
-  // but takes a while, so we'll do it this way first.  For the calculations,
-  // we need to know home many times each instruction appears at each
-  // position for each genotype collection that performs a particular task.
-  const int num_insts = inst_set.GetSize();
-  const int max_length = BatchUtil_GetMaxLength();
-  tMatrix<int> inst_freq(max_length, num_insts+1);
-  
-  for (int task_id = 0; task_id < num_tasks; task_id++) {
-    inst_freq.SetAll(0);
-    
-    // Loop through all genotypes, singling out those that do current task...
-    tListIterator<cAnalyzeGenotype> batch_it(batch[cur_batch].List());
-    cAnalyzeGenotype * genotype = NULL;
-    while ((genotype = batch_it.Next()) != NULL) {
-      if (genotype->GetTaskCount(task_id) == 0) continue;
-      
-      const cGenome & genome = genotype->GetGenome();
-      const int num_cpus = genotype->GetNumCPUs();
-      task_count[task_id] += num_cpus;
-      task_gen_count[task_id]++;
-      for (int i = 0; i < genotype->GetLength(); i++) {
-        inst_freq( i, genome[i].GetOp() ) += num_cpus;
-      }
-      for (int i = genotype->GetLength(); i < max_length; i++) {
-        inst_freq(i, num_insts) += num_cpus; // Entry for "past genome end"
-      }
-    }
-    
-    // Analyze the data for this entry...
-    const int cur_count = task_count[task_id];
-    const int total_pairs = cur_count * (cur_count - 1) / 2;
-    int total_dist = 0;
-    double total_ent = 0;
-    for (int pos = 0; pos < max_length; pos++) {
-      // Calculate distance component...
-      for (int inst1 = 0; inst1 < num_insts; inst1++) {
-        if (inst_freq(pos, inst1) == 0) continue;
-        for (int inst2 = inst1+1; inst2 <= num_insts; inst2++) {
-          total_dist += inst_freq(pos, inst1) * inst_freq(pos, inst2);
-        }
-      }
-      
-      // Calculate entropy component...
-      for (int i = 0; i <= num_insts; i++) {
-        const int cur_freq = inst_freq(pos, i);
-        if (cur_freq == 0) continue;
-        const double p = ((double) cur_freq) / (double) cur_count;
-        total_ent -= p * log(p);
-      }
-    }
-    
-    task_gen_dist[task_id] = ((double) total_dist) / (double) total_pairs;
-    task_site_entropy[task_id] = total_ent;
-  }
-  
-  // Print out the results...
-  cDataFile & df = data_file_manager.Get(filename);
-  
-  for (int i = 0; i < num_tasks; i++) {
-    df.Write(i,                    "# 1: Task ID");
-    df.Write(task_count[i],        "# 2: Number of organisms performing task");
-    df.Write(task_gen_count[i],    "# 3: Number of genotypes performing task");
-    df.Write(task_gen_dist[i],     "# 4: Average distance between genotypes performing task");
-    df.Write(task_site_entropy[i], "# 5: Total per-site entropy of genotypes performing task");
-    df.Endl();
-  }
-}
-
-
-void cAnalyze::PhyloCommunityComplexity(cString cur_string)
-{
-
-  /////////////////////////////////////////////////////////////////////////
-  // Calculate the mutual information between all genotypes and environment
-  /////////////////////////////////////////////////////////////////////////
-
-  cout << "Analyze biocomplexity of current population about environment ...\n";
-
-  // Get the number of genotypes that are gonna be analyzed.
-  int max_genotypes = cur_string.PopWord().AsInt();
-
-  // Get update
-  int update = cur_string.PopWord().AsInt();
-
-  // Get the directory  
-  cString dir = cur_string.PopWord();
-  cString defaultDir = "community_cpx/";
-  cString directory = PopDirectory(dir, defaultDir);
-
-  // Get the file name that saves the result 
-  cString filename = cur_string.PopWord();
-  if (filename.IsEmpty()) {
-    filename = "community.complexity.dat";
-  }
-
-  filename.Set("%s%s", directory(), filename.GetData());
-  ofstream cpx_fp(filename());
-
-  cpx_fp << "# Legend:" << endl;
-  cpx_fp << "# 1: Genotype ID" << endl;
-  cpx_fp << "# 2: Entropy given Known Genotypes" << endl;
-  cpx_fp << "# 3: Entropy given Both Known Genotypes and Env" << endl;
-  cpx_fp << "# 4: New Information about Environment" << endl;
-  cpx_fp << "# 5: Total Complexity" << endl;
-  cpx_fp << endl;
-
-  /////////////////////////////////////////////////////////////////////////////////
-  // Loop through all of the genotypes in all batches and build id vs. genotype map
-
-  map<int, cAnalyzeGenotype *> genotype_database;
-  for (int i = 0; i < MAX_BATCHES; ++ i) {
-    tListIterator<cAnalyzeGenotype> batch_it(batch[i].List());
-    cAnalyzeGenotype * genotype = NULL;
-    while ((genotype = batch_it.Next()) != NULL) {
-      genotype_database.insert(make_pair(genotype->GetID(), genotype));
-    }
-  }
-
-  ////////////////////////////////////////////////
-  // Check if all the genotypes having same length
-
-  int length_genome;
-  if (genotype_database.size() > 0) {
-    length_genome = genotype_database.begin()->second->GetLength();
-  }
-  map<int, cAnalyzeGenotype *>::iterator gen_iterator = genotype_database.begin();
-  for (; gen_iterator != genotype_database.end(); ++ gen_iterator) {
-    if (gen_iterator->second->GetLength() != length_genome) {
-      cerr << "Genotype " << gen_iterator->first << " has different genome length." << endl;
-      exit(1);
-    }
-  }
-
-  ///////////////////////
-  // Backup test CPU data
-  bool backupUsage = cTestCPU::UseResources();
-  tArray<double> backupResources(cTestCPU::GetResources());
-  cTestCPU::UseResources() = true;
-  FillResources(update);
-
-  ///////////////////////////////////////////////////////////////////////
-  // Choose the first n most abundant genotypes and put them in community
-
-  vector<cAnalyzeGenotype *> community;
-  cAnalyzeGenotype * genotype = NULL;
-  tListIterator<cAnalyzeGenotype> batch_it(batch[cur_batch].List());
-
-  while (((genotype = batch_it.Next()) != NULL) && (community.size() < max_genotypes)) {
-    community.push_back(genotype);
-  }
-    
-  ///////////////////////////
-  // Measure hamming distance
-
-  int size_community = community.size();
-  if (size_community == 0) {
-    cerr << "There is no genotype in this community." << endl;
-    cpx_fp.close();
-    exit(1);
-  }
-  typedef pair<int,int> gen_pair;
-  map<gen_pair, int> hamming_dist;
-  
-  for (int i = 0; i< size_community; ++ i) {
-    for (int j = i+1; j < size_community; ++ j) {
-      int dist = cGenomeUtil::FindHammingDistance(community[i]->GetGenome(),
-						  community[j]->GetGenome());
-      int id1 = community[i]->GetID();
-      int id2 = community[j]->GetID();
-
-      hamming_dist.insert(make_pair(gen_pair(id1, id2), dist));
-      hamming_dist.insert(make_pair(gen_pair(id2, id1), dist));
-    }
-  }
-
-  //////////////////////////////////
-  // Get Most Recent Common Ancestor
-
-  map<gen_pair, cAnalyzeGenotype *> mrca;
-  map<gen_pair, int> raw_dist;
-  for (int i = 0; i< size_community; ++ i) {
-    for (int j = i+1; j < size_community; ++ j) {
-				    
-      cAnalyzeGenotype * lineage1_genotype = community[i];
-      cAnalyzeGenotype * lineage2_genotype = community[j];
-      int total_dist = 0;
-
-      while (lineage1_genotype->GetID() != lineage2_genotype->GetID()) {
-	if (lineage1_genotype->GetID() > lineage2_genotype->GetID()) {
-	  int parent_id = lineage1_genotype->GetParentID();
-	  cAnalyzeGenotype * parent = genotype_database.find(parent_id)->second;
-
-	  total_dist += cGenomeUtil::FindHammingDistance(lineage1_genotype->GetGenome(),
-							 parent->GetGenome());
-	  lineage1_genotype = parent;
-	} else {
-	  int parent_id = lineage2_genotype->GetParentID();
-	  cAnalyzeGenotype * parent = genotype_database.find(parent_id)->second;
-	  total_dist += cGenomeUtil::FindHammingDistance(lineage2_genotype->GetGenome(),
-							 parent->GetGenome());
-      
-	  lineage2_genotype = parent;
-	}
-      }
-
-      int id1 = community[i]->GetID();
-      int id2 = community[j]->GetID();
-      mrca.insert(make_pair(gen_pair(id1, id2), lineage1_genotype));
-      mrca.insert(make_pair(gen_pair(id2, id1), lineage1_genotype));
-      raw_dist.insert(make_pair(gen_pair(id1, id2), total_dist));
-      raw_dist.insert(make_pair(gen_pair(id2, id1), total_dist));
-    }
-  }
-
-  /*
-  ////////////////////////////////////////////////////////////////////////////////////////////
-  // Sort the genotype that is next genotype is the most closest one to all previous genotypes
-
-  vector<cAnalyzeGenotype *> sorted_community;
-  vector<cAnalyzeGenotype *> left_genotypes = community;
-
-  // Put the first genotype in left to sorted.
-  sorted_community.push_back(*left_genotypes.begin());
-  left_genotypes.erase(left_genotypes.begin());
-
-  while (left_genotypes.size() > 0) {
-    int min_total_hamming = size_community * length_genome;
-    int index_next;
-
-    for (int next = 0; next < left_genotypes.size(); ++ next) {
-      int total_hamming = 0;
-      int id1 = left_genotypes[next]->GetID();
-      
-      for (int given = 0; given < sorted_community.size(); ++ given) {
-	int id2 = sorted_community[given]->GetID();
-	total_hamming += hamming_dist.find(gen_pair(id1, id2))->second;
-      }
-
-      if (total_hamming < min_total_hamming) {
-	min_total_hamming = total_hamming;
-	index_next = next;
-      }
-    }
-
-    sorted_community.push_back(left_genotypes[index_next]);
-    left_genotypes.erase(left_genotypes.begin() + index_next);
-  }
-
-  */
-
-  vector<cAnalyzeGenotype *> sorted_community = community;
-  /////////////////////////////////////////////
-  // Loop through genotypes in sorted community
-
-  double complexity = 0.0;
-  vector<cAnalyzeGenotype *> given_genotypes;
-  int num_insts = inst_set.GetSize();
-
-  for (int i = 0; i < size_community; ++ i) {
-    genotype = sorted_community[i];
-
-    // Skip the dead organisms
-    genotype->Recalculate();
-    if (genotype->GetFitness() == 0) {
-      continue;
-    }
-
-    vector<double> one_line_prob(num_insts, 0.0);
-    vector< vector<double> > prob(length_genome, one_line_prob);
-
-    cout << endl << genotype->GetID() << endl;
-
-    /*if (given_genotypes.size() >= 2) {
-
-      ///////////////////////////////////////////////////////////////////
-      // Look for two given genotypes that has minimun depth dist with it
-
-      cAnalyzeGenotype * min_depth_gen = given_genotypes[0];
-      cAnalyzeGenotype * tmrca = mrca.find(gen_pair(genotype->GetID(), 
-						    given_genotypes[0]->GetID()))->second;
-      int min_depth_dist = genotype->GetDepth() + given_genotypes[0]->GetDepth() - 2 * tmrca->GetDepth();
-      
-      cAnalyzeGenotype * second_min_gen = given_genotypes[1];
-      tmrca = mrca.find(gen_pair(genotype->GetID(), given_genotypes[1]->GetID()))->second;
-      int second_min_depth = genotype->GetDepth() + given_genotypes[1]->GetDepth() - 2 * tmrca->GetDepth();
-
-      for (int i = 2; i < given_genotypes.size(); ++ i) {
-	cAnalyzeGenotype * given_genotype = given_genotypes[i];
-	cAnalyzeGenotype * tmrca = mrca.find(gen_pair(genotype->GetID(),
-						      given_genotype->GetID()))->second;
-	int dist = genotype->GetDepth() + given_genotype->GetDepth() - 2 * tmrca->GetDepth();
-
-	if (dist < min_depth_dist) {
-	  second_min_depth = min_depth_dist;
-	  second_min_gen = min_depth_gen;
-	  min_depth_dist = dist;
-	  min_depth_gen = given_genotype;
-	} else if (dist >= min_depth_dist && dist < second_min_depth) {
-	  second_min_depth = dist;
-	  second_min_gen = given_genotype;
-	}
-      }
-
-      const cGenome & given_genome1 = min_depth_gen->GetGenome();
-      const cGenome & given_genome2 = second_min_gen->GetGenome();
-      for (int line = 0; line < length_genome; ++ line) {
-	int given_inst = given_genome1[line].GetOp();
-	prob[line][given_inst] += pow(1 - 1.0/length_genome, min_depth_dist);
-	given_inst = given_genome2[line].GetOp();
-	prob[line][given_inst] += pow(1 - 1.0/length_genome, min_depth_dist);
-      }
-
-      cpx_fp << genotype->GetID() << " " << min_depth_dist << " " << second_min_depth 
-	     << " " << raw_dist.find(gen_pair(genotype->GetID(), min_depth_gen->GetID()))->second
-	     << " " << raw_dist.find(gen_pair(genotype->GetID(), second_min_gen->GetID()))->second
-	     << " ";
-      
-	
-    } else  if (given_genotypes.size() == 1) {
-      //////////////////////////////////////////////////////
-      // Calculate the probability of each inst at each line
-      cAnalyzeGenotype * tmrca = mrca.find(gen_pair(genotype->GetID(), 
-						    given_genotypes[0]->GetID()))->second;
-      int dist = genotype->GetDepth() + given_genotypes[0]->GetDepth() - 2 * tmrca->GetDepth();
-      const cGenome & given_genome = given_genotypes[0]->GetGenome();
-
-      for (int line = 0; line < length_genome; ++ line) {
-	int given_inst = given_genome[line].GetOp();
-	prob[line][given_inst] += pow(1 - 1.0/length_genome, dist);
-      }
-      
-      cpx_fp << genotype->GetID() << " " << dist << " " 
-	     << raw_dist.find(gen_pair(genotype->GetID(), given_genotypes[0]->GetID()))->second << " ";
-    } else {
-      cpx_fp << genotype->GetID() << " ";
-      }*/
-
-    if (given_genotypes.size() >= 1) {
-      //////////////////////////////////////////////////
-      // Look for a genotype that is closest to this one
-      
-      cAnalyzeGenotype * min_depth_gen = given_genotypes[0];
-      cAnalyzeGenotype * tmrca = mrca.find(gen_pair(genotype->GetID(), 
-						    given_genotypes[0]->GetID()))->second;
-      int min_depth_dist = genotype->GetDepth() + given_genotypes[0]->GetDepth() - 2 * tmrca->GetDepth();
-
-      for (int i = 1; i < given_genotypes.size() ; ++ i) {
-	cAnalyzeGenotype * given_genotype = given_genotypes[i];
-	cAnalyzeGenotype * tmrca = mrca.find(gen_pair(genotype->GetID(),
-						      given_genotype->GetID()))->second;
-	int dist = genotype->GetDepth() + given_genotype->GetDepth() - 2 * tmrca->GetDepth();
-	
-	if (dist < min_depth_dist) {
-	  min_depth_dist = dist;
-	  min_depth_gen = given_genotype;
-	}
-      }
-
-      const cGenome & given_genome = min_depth_gen->GetGenome();
-      const cGenome & base_genome = genotype->GetGenome();
-      cGenome mod_genome(base_genome);
-      for (int line = 0; line < length_genome; ++ line) {
-	int given_inst = given_genome[line].GetOp();
-	mod_genome = base_genome;
-	mod_genome[line].SetOp(given_inst);
-	cAnalyzeGenotype test_genotype(mod_genome, inst_set);
-	test_genotype.Recalculate();
-
-	// Only when given inst make the genotype alive
-	if (test_genotype.GetFitness() > 0) {
-	  prob[line][given_inst] += pow(1 - 1.0/length_genome, min_depth_dist);
-	}
-      }
-      
-      cpx_fp << genotype->GetID() << " " << min_depth_dist << " " 
-	     << raw_dist.find(gen_pair(genotype->GetID(), min_depth_gen->GetID()))->second << " "
-	     << hamming_dist.find(gen_pair(genotype->GetID(), min_depth_gen->GetID()))->second << "   ";
-    } else {
-      cpx_fp << genotype->GetID() << " ";
-    }
-
-    ///////////////////////////////////////////////////////////////////
-    // Point mutation at all lines of code to look for neutral mutation
-    // and the mutations that can make organism alive
-    cout << "Test point mutation." << endl;
-    vector<bool> one_line_neutral(num_insts, false);
-    vector< vector<bool> > neutral_mut(length_genome, one_line_neutral);
-    vector< vector<bool> > alive_mut(length_genome, one_line_neutral);
-//     if (verbose == true) {
-//       PrintTestCPUResources("");
-//     }
-
-    genotype->Recalculate();
-    double base_fitness = genotype->GetFitness();
-    cout << base_fitness << endl;
-    const cGenome & base_genome = genotype->GetGenome();
-    cGenome mod_genome(base_genome);
-      
-    for (int line = 0; line < length_genome; ++ line) {
-      int cur_inst = base_genome[line].GetOp();
-      
-      for (int mod_inst = 0; mod_inst < num_insts; ++ mod_inst) {
-	mod_genome[line].SetOp(mod_inst);
-	cAnalyzeGenotype test_genotype(mod_genome, inst_set);
-	test_genotype.Recalculate();
-	if (test_genotype.GetFitness() >= base_fitness) {
-	  neutral_mut[line][mod_inst] = true;
-	} 
-	if (test_genotype.GetFitness() > 0) {
-	  alive_mut[line][mod_inst] = true;
-	}
-      }
-      
-      mod_genome[line].SetOp(cur_inst);
-    }
-
-    /////////////////////////////////////////
-    // Normalize the probability at each line
-    vector< vector<double> > prob_before_env(length_genome, one_line_prob);
-
-    for (int line = 0; line < length_genome; ++ line) {
-      double cur_total_prob = 0.0;
-      int num_alive = 0;
-      for (int inst = 0; inst < num_insts; ++ inst) {
-	if (alive_mut[line][inst] == true) {
-	  cur_total_prob += prob[line][inst];
-	  num_alive ++;
-	}
-      }
-      if (cur_total_prob > 1) {
-	cout << "Total probability at " << line << " is greater than 0." << endl;
-	exit(1);
-      }
-      double left_prob = 1 - cur_total_prob;
-
-      for (int inst = 0; inst < num_insts; ++ inst) {
-	if (alive_mut[line][inst] == true) {
-	  prob_before_env[line][inst] = prob[line][inst] + left_prob / num_alive;
-	} else {
-	  prob_before_env[line][inst] = 0;
-	}	
-      }
-      
-    }
-
-    /////////////////////////////////
-    // Calculate entropy of each line  
-    vector<double> entropy(length_genome, 0.0);
-    for (int line = 0; line < length_genome; ++ line) {
-      double sum = 0;
-      for (int inst = 0; inst < num_insts; ++ inst) {
-	sum += prob_before_env[line][inst];
-	if (prob_before_env[line][inst] > 0) {
-	  entropy[line] -= prob_before_env[line][inst] * log(prob_before_env[line][inst]) / log(num_insts*1.0);
-	}
-      }
-      if (sum > 1.001 || sum < 0.999) {
-	cout << "Sum of probability is not 1 at line " << line << endl;
-	exit(1);
-      }
-    }
-
-
-    /////////////////////////////////////////////////////
-    // Redistribute the probability of insts at each line
-    vector< vector<double> > prob_given_env(length_genome, one_line_prob);
-    
-    for (int line = 0; line < length_genome; ++ line) {
-      double total_prob = 0.0;
-      int num_neutral = 0;
-      for (int inst = 0; inst < num_insts; ++ inst) {
-	if (neutral_mut[line][inst] == true) {
-	  num_neutral ++;
-	  total_prob += prob[line][inst];
-	}
-      }
-
-      double left = 1 - total_prob;
-
-      for (int inst = 0; inst < num_insts; ++ inst) {
-	if (neutral_mut[line][inst] == true) {
-	  prob_given_env[line][inst] = prob[line][inst] + left / num_neutral;
-	} else {
-	  prob_given_env[line][inst] = 0.0;
-	}
-      }
-      
-    }
-
-    ////////////////////////////////////////////////
-    // Calculate the entropy given environment
-
-    vector<double> entropy_given_env(length_genome, 0.0);
-    for (int line = 0; line < length_genome; ++ line) {
-      double sum = 0;
-      for (int inst = 0; inst < num_insts; ++ inst) {
-	sum += prob_given_env[line][inst];
-	if (prob_given_env[line][inst] > 0) {
-	  entropy_given_env[line] -= prob_given_env[line][inst] * log(prob_given_env[line][inst]) / 
-	                             log(num_insts*1.0);
-	}
-      }
-      if (sum > 1.001 || sum < 0.999) {
-	cout << "Sum of probability is not 1 at line " << line << " " << sum << endl;
-	exit(1);
-      }
-    }
-
-
-    ///////////////////////////////////////////////////////////////////////////
-    // Calculate the information between genotype and env given other genotypes
-    double information = 0.0;
-    double entropy_before = 0.0;
-    double entropy_after = 0.0;
-    for (int line = 0; line < length_genome; ++ line) {
-      entropy_before += entropy[line];
-      entropy_after += entropy_given_env[line];
-
-      if (entropy[line] >= entropy_given_env[line]) {
-	information += entropy[line] - entropy_given_env[line];	
-      } else {    // Negative information is because given condition is not related with this genotype  ...
-	
-	// Count the number of insts that can make genotype alive
-	int num_inst_alive = 0;
-	for (int inst = 0; inst < num_insts; ++ inst) {
-	  if (alive_mut[line][inst] == true) {
-	    num_inst_alive ++;
-	  }
-	}
-	
-	double entropy_before = - log(1.0/num_inst_alive) / log(num_insts*1.0);
-	information += entropy_before - entropy_given_env[line];
-	if (information < 0) {
-	  cout << "Negative information at site " << line << endl;
-	  exit(1);
-	}
-      }
-      
-    }
-    complexity += information;
-
-    cpx_fp << entropy_before << " " << entropy_after << " "
-	   << information << " " << complexity << "   ";
-
-    genotype->PrintTasks(cpx_fp, 0, -1);
-    cpx_fp << endl; 
-
-    /////////////////////////////////////////////////////////////
-    // This genotype becomes the given condition of next genotype
-
-    given_genotypes.push_back(genotype);
-    
-  }
-
-  // Set the test CPU back to the state it was 
-  cTestCPU::UseResources() = backupUsage;
-  cTestCPU::SetupResourceArray(backupResources);
-    
-  cpx_fp.close();
-  return;
-	 
-}
-
-void cAnalyze::CommunityComplexity(cString cur_string)
-{
-  /////////////////////////////////////////////////////////////////////
-  // Calculate the mutual information between community and environment
-  /////////////////////////////////////////////////////////////////////
-
-  cout << "Analyze community complexity of current population about environment with Charles method ...\n";
-
-  // Get the number of genotypes that are gonna be analyzed.
-  int max_genotypes = cur_string.PopWord().AsInt();
-
-  // Get update
-  int update = cur_string.PopWord().AsInt();
-
-  // Get the directory  
-  cString dir = cur_string.PopWord();
-  cString defaultDir = "community_cpx/";
-  cString directory = PopDirectory(dir, defaultDir);
-
-  // Get the file name that saves the result 
-  cString filename = cur_string.PopWord();
-  if (filename.IsEmpty()) {
-    filename = "community.complexity.dat";
-  }
-
-  filename.Set("%s%s", directory(), filename.GetData());
-  ofstream cpx_fp(filename());
-
-  cpx_fp << "# Legend:" << endl;
-  cpx_fp << "# 1: Genotype ID" << endl;
-  cpx_fp << "# 2: Entropy given Known Genotypes" << endl;
-  cpx_fp << "# 3: Entropy given Both Known Genotypes and Env" << endl;
-  cpx_fp << "# 4: New Information about Environment" << endl;
-  cpx_fp << "# 5: Total Complexity" << endl;
-  cpx_fp << "# 6: Hamming Distance to Closest Given Genotype" << endl;
-  cpx_fp << "# 7 - : Tasks Implemented" << endl;
-  cpx_fp << endl;
-
-  ///////////////////////
-  // Backup test CPU data
-  bool backupUsage = cTestCPU::UseResources();
-  tArray<double> backupResources(cTestCPU::GetResources());
-  cTestCPU::UseResources() = true;
-  FillResources(update);
-
-  ///////////////////////////////////////////////////////////////////////
-  // Choose the first n most abundant genotypes and put them in community
-
-  vector<cAnalyzeGenotype *> community;
-  cAnalyzeGenotype * genotype = NULL;
-  tListIterator<cAnalyzeGenotype> batch_it(batch[cur_batch].List());
-
-  while (((genotype = batch_it.Next()) != NULL) && (community.size() < max_genotypes)) {
-    community.push_back(genotype);
-  }
-
-  //////////////////////////////////////////////////////
-  // Test point mutation of each genotype in environment
-
-  int num_insts = inst_set.GetSize();
-  map<int, tMatrix<double> > point_mut; 
-  int size_community = community.size();
-  int length_genome;
-  if (size_community > 1) {
-    length_genome = community[0]->GetLength();
-  }
-
-  for (int i = 0; i < size_community; ++ i) {
-    genotype = community[i];
-    
-    ///////////////////////////////////////////////////////////////////
-    // Point mutation at all lines of code to look for neutral mutation
-    cout << "Test point mutation for genotype " << genotype->GetID() << endl;
-    tMatrix<double> prob(length_genome, num_insts);
-//     if (verbose == true) {
-//       PrintTestCPUResources("");
-//     }
-
-    genotype->Recalculate();
-    double base_fitness = genotype->GetFitness();
-    const cGenome & base_genome = genotype->GetGenome();
-    cGenome mod_genome(base_genome);
-      
-    for (int line = 0; line < length_genome; ++ line) {
-      int cur_inst = base_genome[line].GetOp();
-      int num_neutral = 0;
-
-      for (int mod_inst = 0; mod_inst < num_insts; ++ mod_inst) {
-	mod_genome[line].SetOp(mod_inst);
-	cAnalyzeGenotype test_genotype(mod_genome, inst_set);
-	test_genotype.Recalculate();
-	if (test_genotype.GetFitness() >= base_fitness) {
-	  prob[line][mod_inst] = 1.0;
-	  num_neutral ++;
-	} else {
-	  prob[line][mod_inst] = 0.0;
-	}
-      }
-
-      for (int mod_inst = 0; mod_inst < num_insts; ++ mod_inst) {
-	prob[line][mod_inst] /= num_neutral;
-      }
-   
-      
-      mod_genome[line].SetOp(cur_inst);
-    }
-
-    point_mut.insert(make_pair(genotype->GetID(), prob));
-  }
-
-  //////////////////////////////////////
-  // Loop through genotypes in community
-
-  double complexity = 0.0;
-  double complexity2 = 0.0;
-  vector<cAnalyzeGenotype *> given_genotypes;
-
-  // Calculate the complexity of the first gentoype
-  genotype = community[0];
-  double oo_initial_entropy = length_genome;
-  double oo_conditional_entropy = 0.0;
-  tMatrix<double> this_prob = point_mut.find(genotype->GetID())->second;
-
-  for (int line = 0; line < length_genome; ++ line) {
-    double oneline_entropy = 0.0;
-    for (int inst = 0; inst < num_insts; ++ inst) {
-      if (this_prob[line][inst] > 0) {
-	oneline_entropy -= this_prob[line][inst] * (log(this_prob[line][inst]) /
-						    log(1.0*num_insts));
-      }
-    }
-    oo_conditional_entropy += oneline_entropy;
-  }
-  double new_info = oo_initial_entropy - oo_conditional_entropy;
-  complexity += new_info;
-  complexity2 += new_info;
-  given_genotypes.push_back(genotype);
-  cpx_fp << genotype->GetID() << " " 
-	 << oo_initial_entropy << " " 
-	 << oo_conditional_entropy << " "
-	 << new_info << " " 
-	 << complexity << "   "
-	 << 0 << "   ";
-  genotype->Recalculate();
-  genotype->PrintTasks(cpx_fp, 0, -1);
-  cpx_fp << endl;
-
-  // New information in other genotypes in community ...
-  for (int i = 1; i < size_community; ++ i) {
-    genotype = community[i];
-    if (genotype->GetLength() != length_genome) {
-      cerr << "Genotypes in the community do not same genome length.\n";
-      cpx_fp.close();
-      exit(1);
-    }
-
-    // Skip the dead organisms
-    genotype->Recalculate();
-    cout << genotype->GetID() << " " << genotype->GetFitness() << endl;
-    if (genotype->GetFitness() == 0) {
-      continue;
-    }
-
-    double min_new_info = length_genome; 
-    double oo_initial_entropy, oo_conditional_entropy;
-    cAnalyzeGenotype * used_genotype;
-    tMatrix<double> this_prob = point_mut.find(genotype->GetID())->second;
-
-    // For any given genotype, calculate the new information in genotype
-    for (int j = 0; j < given_genotypes.size(); ++ j) {
-
-      tMatrix<double> given_prob = point_mut.find(given_genotypes[j]->GetID())->second;
-      double new_info = 0.0;
-      double total_initial_entropy = 0.0;
-      double total_conditional_entropy = 0.0;
-
-      for (int line = 0; line < length_genome; ++ line) {
-
-	// H(genotype|known_genotype)    
-	double prob_overlap = 0;
-	for (int inst = 0; inst < num_insts; ++ inst) {
-	  if (this_prob[line][inst] < given_prob[line][inst]) {
-	    prob_overlap += this_prob[line][inst];
-	  } else {
-	    prob_overlap += given_prob[line][inst];
-	  }
-	}
-
-	double given_site_entropy = 0.0;
-	for (int inst = 0; inst < num_insts; ++ inst) {
-	  if (given_prob[line][inst] > 0) {
-	    given_site_entropy -= given_prob[line][inst] * (log(given_prob[line][inst]) /
-							 log(1.0*num_insts));
-	  }
-	}
-	
-
-	double entropy_overlap = 0.0;
-	if (prob_overlap > 0 &&  (1 - prob_overlap > 0)) {
-	  entropy_overlap = (- prob_overlap * log(prob_overlap) 
-			     - (1-prob_overlap) * log(1 - prob_overlap)) / log(1.0*num_insts);
-	} else {
-	  entropy_overlap = 0; 
-	}
-
-	double initial_entropy = prob_overlap * given_site_entropy 
-                             + (1 - prob_overlap) * 1 + entropy_overlap;
-	total_initial_entropy += initial_entropy;
-
-	// H(genotype|E, known_genotype) = H(genotype|Env)
-	double conditional_entropy = 0.0;
-	for (int inst = 0; inst < num_insts; ++ inst) {
-	  if (this_prob[line][inst] > 0) {
-	    conditional_entropy -= this_prob[line][inst] * (log(this_prob[line][inst]) / 
-							    log(1.0*num_insts));
-	  }
-	}
-	total_conditional_entropy += conditional_entropy;
-
-	if (conditional_entropy > initial_entropy + 0.00001) {
-	  cerr << "Negative Information.\n";
-	  cout << line << endl;
-	  for (int inst = 0; inst < num_insts; ++ inst) {
-	    cout << this_prob[line][inst] << " ";
-	  }
-	  cout << endl;
-	  for (int inst = 0; inst < num_insts; ++ inst) {
-	    cout << given_prob[line][inst] << " ";
-	  }
-	  cout << endl;
-
-	  exit(1);
-	}
-
-	new_info += initial_entropy - conditional_entropy;
-      }
-     
-      if (new_info < min_new_info) {
-	min_new_info = new_info;
-	oo_initial_entropy = total_initial_entropy;
-	oo_conditional_entropy = total_conditional_entropy;
-	used_genotype = given_genotypes[j];
-      }
-
-    }
-    complexity += min_new_info;
-    cpx_fp << genotype->GetID() << " " 
-	   << oo_initial_entropy << " "
-	   << oo_conditional_entropy << " "
-	   << min_new_info << " " << complexity << "   ";
-
-    cpx_fp << cGenomeUtil::FindHammingDistance(genotype->GetGenome(),
-					       used_genotype->GetGenome()) << "   ";
-    
-    
-    genotype->PrintTasks(cpx_fp, 0, -1);
-    cpx_fp << endl;
-    given_genotypes.push_back(genotype);
-  }
-  
-  
-  // Set the test CPU back to the state it was 
-  cTestCPU::UseResources() = backupUsage;
-  cTestCPU::SetupResourceArray(backupResources);
-    
-  cpx_fp.close();
-  return;
-
-    
-  
-}
-
-void cAnalyze::CommandLandscape(cString cur_string)
-{
-  if (verbose == true) cout << "Landscaping batch " << cur_batch << endl;
-  else cout << "Landscapping..." << endl;
-  
-  // Load in the variables...
-  cString filename;
-  if (cur_string.GetSize() != 0) filename = cur_string.PopWord();
-  int dist = 1;
-  if (cur_string.GetSize() != 0) dist = cur_string.PopWord().AsInt();
-  int num_test = 0;
-  if (cur_string.GetSize() != 0) num_test=cur_string.PopWord().AsInt();
-  
-  // If we're given a file, write to it.
-  ofstream & fp = data_file_manager.GetOFStream(filename);
-  
-  // Loop through all of the genotypes in this batch...
-  tListIterator<cAnalyzeGenotype> batch_it(batch[cur_batch].List());
-  cAnalyzeGenotype * genotype = NULL;
-  while ((genotype = batch_it.Next()) != NULL) {
-    cLandscape landscape(genotype->GetGenome(), inst_set);
-    if (num_test == 0) landscape.Process(dist);
-    else landscape.RandomProcess(num_test,dist,num_test,num_test*2);
-    landscape.PrintStats(fp);
-  }
-}
-
-void cAnalyze::AnalyzeEpistasis(cString cur_string)
-{
-  if (verbose == true) cout << "Epistasis on " << cur_batch << endl;
-  else cout << "Calculating epistasis values..." << endl;
-  
-  // Load in the variables...
-  cString filename;
-  if (cur_string.GetSize() != 0) filename = cur_string.PopWord();
-  int test_num = 1;
-  if (cur_string.GetSize() != 0) test_num = cur_string.PopWord().AsInt();
-  
-  // If we're given a file, write to it.
-  ofstream & fp = data_file_manager.GetOFStream(filename);
-  
-  // Loop through all of the genotypes in this batch...
-  tListIterator<cAnalyzeGenotype> batch_it(batch[cur_batch].List());
-  cAnalyzeGenotype * genotype = NULL;
-  while ((genotype = batch_it.Next()) != NULL) {
-    cLandscape landscape(genotype->GetGenome(), inst_set);
-    if (test_num == 1)  landscape.TestAllPairs(fp);
-    else 		landscape.TestPairs(test_num,fp); 
-    landscape.PrintStats(fp);
-  }
-}
-
-
-// This command will take the current batch and analyze how well organisms
-// cross-over with each other, both across the population and between mates.
-
-void cAnalyze::AnalyzeMateSelection(cString cur_string)
-{
-  int sample_size = 10000;
-  if (cur_string.GetSize() != 0) sample_size = cur_string.PopWord().AsInt();
-  cString filename("none");
-  if (cur_string.GetSize() != 0) filename = cur_string.PopWord();
-  double min_swap_frac = 0.0;
-  if (cur_string.GetSize() != 0) min_swap_frac=cur_string.PopWord().AsDouble();
-  double max_swap_frac = 1.0 - min_swap_frac;
-
-  cout << "Analyzing Mate Selection... " << endl;
-
-  // Do some quick tests before moving on...
-  if (min_swap_frac < 0.0 || min_swap_frac >= 0.5) {
-    cerr << "ERROR: Minimum swap fraction out of range [0.0, 0.5)." << endl;
-  }
-  
-  // Next, we create an array that contains pointers to all of the organisms
-  // in this batch.  Note that we want to select genotypes based on their
-  // abundance, so they will have one entry in the array per organism.  Note
-  // that we only consider viable genotypes.
-
-  // Start by counting the total number of organisms (and do other such
-  // data collection...
-  tHashTable<int, int> mate_id_counts;
-
-  int org_count = 0;
-  int gen_count = 0;
-  cAnalyzeGenotype * genotype = NULL;
-  tListIterator<cAnalyzeGenotype> list_it(batch[cur_batch].List());
-  while ((genotype = list_it.Next()) != NULL) {
-    if (genotype->GetViable() == false || genotype->GetNumCPUs() == 0) {
-      continue;
-    }
-    gen_count++;
-    org_count += genotype->GetNumCPUs();
-
-    // Keep track of how many organisms have each mate id...
-    int mate_id = genotype->GetMateID();
-    int count = 0;
-    mate_id_counts.Find(mate_id, count);
-    count += genotype->GetNumCPUs();
-    mate_id_counts.SetValue(mate_id, count);
-  }
-
-  // Create an array of the correct size.
-  tArray<cAnalyzeGenotype *> genotype_array(org_count);
-
-  // And insert all of the organisms into the array.
-  int cur_pos = 0;
-  while ((genotype = list_it.Next()) != NULL) {
-    if (genotype->GetViable() == false) continue;
-    int cur_count = genotype->GetNumCPUs();
-    for (int i = 0; i < cur_count; i++) {
-      genotype_array[cur_pos++] = genotype;
-    }
-  }
-  
-
-  // Setup some variables to collect statistics.
-  int total_matches_tested = 0;
-  int fail_count = 0;
-  int match_fail_count = 0;
-
-  // Loop through all of the tests, picking random organisms each time and
-  // performing a random cross test.
-  cAnalyzeGenotype * genotype2 = NULL;
-  for (int test_id = 0; test_id < sample_size; test_id++) {
-    genotype = genotype_array[ g_random.GetUInt(org_count) ];
-    genotype2 = genotype_array[ g_random.GetUInt(org_count) ];
-
-    // Stop immediately if we're comparing a genotype to itself.
-    if (genotype == genotype2) {
-      total_matches_tested++;
-      continue;
-    }
-
-    // Setup the random parameters for this test.
-    cCPUMemory test_genome0 = genotype->GetGenome(); 
-    cCPUMemory test_genome1 = genotype2->GetGenome(); 
-
-    double start_frac = -1.0;
-    double end_frac = -1.0;
-    double swap_frac = -1.0;
-    while (swap_frac < min_swap_frac || swap_frac > max_swap_frac) {
-      start_frac = g_random.GetDouble();
-      end_frac = g_random.GetDouble();
-      if (start_frac > end_frac) nFunctions::Swap(start_frac, end_frac);
-      swap_frac = end_frac - start_frac;
-    }
-          
-    int start0 = (int) (start_frac * (double) test_genome0.GetSize());
-    int end0   = (int) (end_frac * (double) test_genome0.GetSize());
-    int size0 = end0 - start0;
-
-    int start1 = (int) (start_frac * (double) test_genome1.GetSize());
-    int end1   = (int) (end_frac * (double) test_genome1.GetSize());
-    int size1 = end1 - start1;
-
-    int new_size0 = test_genome0.GetSize() - size0 + size1;   
-    int new_size1 = test_genome1.GetSize() - size1 + size0;
-
-    // Setup some statistics for this particular test.
-    bool cross_viable = true;
-    bool same_mate_id = ( genotype->GetMateID() == genotype2->GetMateID() );
-    if (same_mate_id == true) total_matches_tested++;
-
-    // Don't Crossover if offspring will be illegal!!!
-    if (new_size0 < MIN_CREATURE_SIZE || new_size0 > MAX_CREATURE_SIZE || 
-	new_size1 < MIN_CREATURE_SIZE || new_size1 > MAX_CREATURE_SIZE) { 
-      fail_count++; 
-      if (same_mate_id == true) match_fail_count++;
-      continue; 
-    } 
-
-    // Do the replacement...  We're only going to test genome0, so we only
-    // need to modify that one.
-    cGenome cross1 = cGenomeUtil::Crop(test_genome1, start1, end1);
-    test_genome0.Replace(start0, size0, cross1);
-
-    // Do the test.
-    cCPUTestInfo test_info;
-          
-    // Run each side, and determine viability...
-    cTestCPU::TestGenome(test_info, test_genome0);
-    if( test_info.IsViable() == false ) {
-      fail_count++;
-      if (same_mate_id == true) match_fail_count++;
-    }
-  }
-
-  // Do some calculations on the sizes of the mate groups...
-  const int num_mate_groups = mate_id_counts.GetSize();
-
-  // Collect lists on all of the mate groups for the calculations...
-  tList<int> key_list;
-  tList<int> count_list;
-  mate_id_counts.AsLists(key_list, count_list);
-  tListIterator<int> count_it(count_list);
-
-  int max_group_size = 0;
-  double mate_id_entropy = 0.0;
-  while (count_it.Next() != NULL) {
-    int cur_count = *(count_it.Get());
-    double cur_frac = ((double) cur_count) / ((double) org_count);
-    if (cur_count > max_group_size) max_group_size = cur_count;
-    mate_id_entropy -= cur_frac * log(cur_frac);
-  }
-  
-  // Calculate the final answer
-  double fail_frac = (double) fail_count / (double) sample_size;
-  double match_fail_frac =
-    (double) match_fail_count / (double) total_matches_tested;
-  cout << "  ave fraction failed = " << fail_frac << endl
-       << "  ave matches failed = " << match_fail_frac << endl
-       << "  total mate matches = " <<  total_matches_tested
-       << " / " << sample_size<< endl;
-
-  if (filename == "none") return;
-  
-  cDataFile & df = data_file_manager.Get(filename);
-  df.WriteComment( "Mate selection information" );
-  df.WriteTimeStamp();  
-  
-  df.Write(fail_frac,       "Average fraction failed");
-  df.Write(match_fail_frac, "Average fraction of mate matches failed");
-  df.Write(sample_size, "Total number of crossovers tested");
-  df.Write(total_matches_tested, "Number of crossovers with matching mate IDs");
-  df.Write(gen_count, "Number of genotypes in test batch");
-  df.Write(org_count, "Number of organisms in test batch");
-  df.Write(num_mate_groups, "Number of distinct mate IDs");
-  df.Write(max_group_size, "Size of the largest distinct mate ID group");
-  df.Write(mate_id_entropy, "Diversity of mate IDs (entropy)");
-  df.Endl();
-}
-
-  
-void cAnalyze::CommandFitnessMatrix(cString cur_string)
-{
-  if (verbose == true) cout << "Calculating fitness matrix for batch " << cur_batch << endl;
-  else cout << "Calculating fitness matrix..." << endl;
-  
-  cout << "Warning: considering only first genotype of the batch!" << endl;
-  
-  // Load in the variables...
-  int depth_limit = 4;
-  if (cur_string.GetSize() != 0) depth_limit = cur_string.PopWord().AsInt();
-  
-  double fitness_threshold_ratio = .9;
-  if (cur_string.GetSize() != 0) fitness_threshold_ratio = cur_string.PopWord().AsDouble();
-  
-  int ham_thresh  = 1;
-  if (cur_string.GetSize() != 0) ham_thresh = cur_string.PopWord().AsInt();
-  
-  double error_rate_min = 0.005;
-  if (cur_string.GetSize() != 0) error_rate_min = cur_string.PopWord().AsDouble();
-  
-  double error_rate_max = 0.05;
-  if (cur_string.GetSize() != 0) error_rate_max = cur_string.PopWord().AsDouble();
-  
-  double error_rate_step = 0.005;
-  if (cur_string.GetSize() != 0) error_rate_step = cur_string.PopWord().AsDouble();
-  
-  double vect_fmax = 1.1;
-  if (cur_string.GetSize() != 0) vect_fmax = cur_string.PopWord().AsDouble();
-  
-  double vect_fstep = .1;
-  if (cur_string.GetSize() != 0) vect_fstep = cur_string.PopWord().AsDouble();
-  
-  int diag_iters = 200;
-  if (cur_string.GetSize() != 0) diag_iters = cur_string.PopWord().AsInt();
-  
-  int write_ham_vector = 0;
-  if (cur_string.GetSize() != 0) write_ham_vector = cur_string.PopWord().AsInt();
-  
-  int write_full_vector = 0;
-  if (cur_string.GetSize() != 0) write_full_vector = cur_string.PopWord().AsInt();
-  
-  // Consider only the first genotypes in this batch...
-  tListIterator<cAnalyzeGenotype> batch_it(batch[cur_batch].List());
-  cAnalyzeGenotype * genotype = batch_it.Next();
-  
-  cFitnessMatrix matrix( genotype->GetGenome(), &inst_set);
-  
-  matrix.CalcFitnessMatrix( depth_limit, fitness_threshold_ratio, ham_thresh, error_rate_min, error_rate_max, error_rate_step, vect_fmax, vect_fstep, diag_iters, write_ham_vector, write_full_vector );
-}
-
-
-void cAnalyze::CommandMapTasks(cString cur_string)
-{
-  cout << "Constructing genotype-phenotype maps..." << endl;
-  
-  // Load in the variables...
-  cString directory = PopDirectory(cur_string, "phenotype/");
-  int print_mode = 0;   // 0=Normal, 1=Boolean results
-  int file_type = FILE_TYPE_TEXT;
-  
-  // HTML special flags...
-  bool link_maps = false;  // Should muliple maps be linked together?
-  bool link_insts = false; // Should links be made to instruction descs?
-  
-  // Collect any other format information needed...
-  tList< tDataEntryCommand<cAnalyzeGenotype> > output_list;
-  tListIterator< tDataEntryCommand<cAnalyzeGenotype> > output_it(output_list);
-  
-  cStringList arg_list(cur_string);
-  
-  cout << "Found " << arg_list.GetSize() << " args." << endl;
-  
-  // Check for some command specific variables.
-  if (arg_list.PopString("0") != "") print_mode = 0;
-  if (arg_list.PopString("1") != "") print_mode = 1;
-  if (arg_list.PopString("text") != "") file_type = FILE_TYPE_TEXT;
-  if (arg_list.PopString("html") != "") file_type = FILE_TYPE_HTML;
-  if (arg_list.PopString("link_maps") != "") link_maps = true;
-  if (arg_list.PopString("link_insts") != "") link_insts = true;
-  
-  cout << "There are " << arg_list.GetSize() << " column args." << endl;
-  
-  LoadGenotypeDataList(arg_list, output_list);
-  
-  cout << "Args are loaded." << endl;
-  
-  const int num_cols = output_list.GetSize();
-  
-  // Give some information in verbose mode.
-  if (verbose == true) {
-    cout << "  outputing as ";
-    if (print_mode == 1) cout << "boolean ";
-    if (file_type == FILE_TYPE_TEXT) {
-      cout << "text files." << endl;
-    } else { // if (file_type == FILE_TYPE_HTML) {
-      cout << "HTML files";
-      if (link_maps == true) cout << "; linking files together";
-      if (link_maps == true) cout << "; linking inst names to descs";
-      cout << "." << endl;
-    }
-    cout << "  Format: ";
-    
-    output_it.Reset();
-    while (output_it.Next() != NULL) {
-      cout << output_it.Get()->GetName() << " ";
-    }
-    cout << endl;
-  }
-  
-  
-  ///////////////////////////////////////////////////////
-  // Loop through all of the genotypes in this batch...
-  
-  tListIterator<cAnalyzeGenotype> batch_it(batch[cur_batch].List());
-  cAnalyzeGenotype * genotype = NULL;
-  while ((genotype = batch_it.Next()) != NULL) {
-    if (verbose == true) cout << "  Mapping " << genotype->GetName() << endl;
-    
-    // Construct this filename...
-    cString filename;
-    if (file_type == FILE_TYPE_TEXT) {
-      filename.Set("%stasksites.%s.dat", directory(), genotype->GetName()());
-    } else {   //  if (file_type == FILE_TYPE_HTML) {
-      filename.Set("%stasksites.%s.html", directory(), genotype->GetName()());
-    }
-    ofstream fp(filename());
-    
-    // Construct linked filenames...
-    cString next_file("");
-    cString prev_file("");
-    if (link_maps == true) {
-      // Check the next genotype on the list...
-      if (batch_it.Next() != NULL) {
-        next_file.Set("tasksites.%s.html", batch_it.Get()->GetName()());
-      }
-      batch_it.Prev();  // Put the list back where it was...
-      
-      // Check the previous genotype on the list...
-      if (batch_it.Prev() != NULL) {
-        prev_file.Set("tasksites.%s.html", batch_it.Get()->GetName()());
-      }
-      batch_it.Next();  // Put the list back where it was...
-    }
-    
-    // Calculate the stats for the genotype we're working with...
-    genotype->Recalculate();
-    
-    // Headers...
-    if (file_type == FILE_TYPE_TEXT) {
-      fp << "-1 "  << batch[cur_batch].Name() << " "
-      << genotype->GetID() << " ";
-      
-      tDataEntryCommand<cAnalyzeGenotype> * data_command = NULL;
-      while ((data_command = output_it.Next()) != NULL) {
-        data_command->SetTarget(genotype);
-        fp << data_command->GetEntry() << " ";
-      }
-      fp << endl;
-      
-    } else { // if (file_type == FILE_TYPE_HTML) {
-             // Mark file as html
-      fp << "<html>" << endl;
-      
-      // Setup any javascript macros needed...
-      fp << "<head>" << endl;
-      if (link_insts == true) {
-        fp << "<script language=\"javascript\">" << endl
-        << "function Inst(inst_name)" << endl
-        << "{" << endl
-        << "var filename = \"help.\" + inst_name + \".html\";" << endl
-        << "newwin = window.open(filename, 'Instruction', "
-        << "'toolbar=0,status=0,location=0,directories=0,menubar=0,"
-        << "scrollbars=1,height=150,width=300');" << endl
-        << "newwin.focus();" << endl
-        << "}" << endl
-        << "</script>" << endl;
-      }
-      fp << "</head>" << endl;
-      
-      // Setup the body...
-      fp << "<body bgcolor=\"#FFFFFF\"" << endl
-        << " text=\"#000000\"" << endl
-        << " link=\"#0000AA\"" << endl
-        << " alink=\"#0000FF\"" << endl
-        << " vlink=\"#000044\">" << endl
-        << endl
-        << "<h1 align=center>Run " << batch[cur_batch].Name()
-        << ", ID " << genotype->GetID() << "</h1>" << endl
-        << "<center>" << endl
-        << endl;
-      
-      // Links?
-      fp << "<table width=90%><tr><td align=left>";
-      if (prev_file != "") fp << "<a href=\"" << prev_file << "\">Prev</a>";
-      else fp << "&nbsp;";
-      fp << "<td align=right>";
-      if (next_file != "") fp << "<a href=\"" << next_file << "\">Next</a>";
-      else fp << "&nbsp;";
-      fp << "</tr></table>" << endl;
-      
-      // The table
-      fp << "<table border=1 cellpadding=2>" << endl;
-      
-      // The headings...///
-      fp << "<tr><td colspan=3> ";
-      output_it.Reset();
-      while (output_it.Next() != NULL) {
-        fp << "<th>" << output_it.Get()->GetDesc() << " ";
-      }
-      fp << "</tr>" << endl;
-      
-      // The base creature...
-      fp << "<tr><th colspan=3>Base Creature";
-      tDataEntryCommand<cAnalyzeGenotype> * data_command = NULL;
-      cAnalyzeGenotype null_genotype("a", inst_set);
-      while ((data_command = output_it.Next()) != NULL) {
-        data_command->SetTarget(genotype);
-        genotype->SetSpecialArgs(data_command->GetArgs());
-        if (data_command->Compare(&null_genotype) > 0) {
-          fp << "<th bgcolor=\"#00FF00\">";
-        }
-        else  fp << "<th bgcolor=\"#FF0000\">";
-        
-        if (data_command->HasArg("blank") == true) fp << "&nbsp;" << " ";
-        else fp << data_command->GetEntry() << " ";
-      }
-      fp << "</tr>" << endl;
-    }
-    
-    
-    const int max_line = genotype->GetLength();
-    const cGenome & base_genome = genotype->GetGenome();
-    cGenome mod_genome(base_genome);
-    
-    // Keep track of the number of failues/successes for attributes...
-    int * col_pass_count = new int[num_cols];
-    int * col_fail_count = new int[num_cols];
-    for (int i = 0; i < num_cols; i++) {
-      col_pass_count[i] = 0;
-      col_fail_count[i] = 0;
-    }
-    
-    cInstSet map_inst_set(inst_set);
-    // Locate instruction corresponding to "NULL" in the instruction library.
-    {
-      const cInstruction inst_lib_null_inst = map_inst_set.GetInstLib()->GetInst("NULL");
-      if(inst_lib_null_inst == map_inst_set.GetInstLib()->GetInstError()){
-        cout << "<cAnalyze::CommandMapTasks> got error:" << endl;
-        cout << " --- instruction \"NULL\" isn't in the instruction library;" << endl;
-        cout << " --- get somebody to map a function to \"NULL\" in the library." << endl;
-        cout << " --- (probably to class method \"cHardware-of-some-type::initInstLib\"" << endl;
-        cout << " --- in file named \"cpu/hardware-of-some-type.cc\".)" << endl;
-        cout << " --- bailing-out." << endl;
-        exit(1);
-      }
-      // Add mapping to located instruction. 
-      map_inst_set.Add2(inst_lib_null_inst.GetOp());
-    }
-    const cInstruction null_inst = map_inst_set.GetInst("NULL");
-    
-    // Loop through all the lines of code, testing the removal of each.
-    for (int line_num = 0; line_num < max_line; line_num++) {
-      int cur_inst = base_genome[line_num].GetOp();
-      char cur_symbol = base_genome[line_num].GetSymbol();
-      
-      mod_genome[line_num] = null_inst;
-      cAnalyzeGenotype test_genotype(mod_genome, map_inst_set);
-      test_genotype.Recalculate();
-      
-      if (file_type == FILE_TYPE_HTML) fp << "<tr><td align=right>";
-      fp << (line_num + 1) << " ";
-      if (file_type == FILE_TYPE_HTML) fp << "<td align=center>";
-      fp << cur_symbol << " ";
-      if (file_type == FILE_TYPE_HTML) fp << "<td align=center>";
-      if (link_insts == true) {
-        fp << "<a href=\"javascript:Inst('"
-        << map_inst_set.GetName(cur_inst)
-        << "')\">";
-      }
-      fp << map_inst_set.GetName(cur_inst) << " ";
-      if (link_insts == true) fp << "</a>";
-      
-      
-      // Print the individual columns...
-      output_it.Reset();
-      tDataEntryCommand<cAnalyzeGenotype> * data_command = NULL;
-      int cur_col = 0;
-      while ((data_command = output_it.Next()) != NULL) {
-        data_command->SetTarget(&test_genotype);
-        test_genotype.SetSpecialArgs(data_command->GetArgs());
-        int compare = data_command->Compare(genotype);
-        if (file_type == FILE_TYPE_HTML) {
-          data_command->HTMLPrint(fp, compare,
-                                  !(data_command->HasArg("blank")));
-        } 
-        else fp << data_command->GetEntry() << " ";
-        
-        if (compare == -2) col_fail_count[cur_col]++;
-        else if (compare == 2) col_pass_count[cur_col]++;
-        cur_col++;
-      }
-      if (file_type == FILE_TYPE_HTML) fp << "</tr>";
-      fp << endl;
-      
-      // Reset the mod_genome back to the original sequence.
-      mod_genome[line_num].SetOp(cur_inst);
-    }
-    
-    
-    // Construct the final line of the table with all totals...
-    if (file_type == FILE_TYPE_HTML) {
-      fp << "<tr><th colspan=3>Totals";
-      
-      for (int i = 0; i < num_cols; i++) {
-        if (col_pass_count[i] > 0) {
-          fp << "<th bgcolor=\"#00FF00\">" << col_pass_count[i];
-        }
-        else if (col_fail_count[i] > 0) {
-          fp << "<th bgcolor=\"#FF0000\">" << col_fail_count[i];
-        }
-        else fp << "<th>0";
-      }
-      fp << "</tr>" << endl;
-      
-      // And close everything up...
-      fp << "</table>" << endl
-        << "</center>" << endl;
-    }
-    
-    delete [] col_pass_count;
-    delete [] col_fail_count;
-    
-    }
-}
-
-void cAnalyze::CommandAverageModularity(cString cur_string)
-{
-  cout << "Average Modularity calculations" << endl;
-  
-  // Load in the variables...
-  cString filename = cur_string.PopWord();
-  //    cString filename = "average.dat";
-  
-  int print_mode = 0;   // 0=Normal, 1=Boolean results
-  
-  // Collect any other format information needed...
-  tList< tDataEntryCommand<cAnalyzeGenotype> > output_list;
-  tListIterator< tDataEntryCommand<cAnalyzeGenotype> > output_it(output_list);
-  
-  cStringList arg_list(cur_string);
-  
-  cout << "Found " << arg_list.GetSize() << " args." << endl;
-  
-  // Check for some command specific variables.
-  if (arg_list.PopString("0") != "") print_mode = 0;
-  if (arg_list.PopString("1") != "") print_mode = 1;
-  
-  cout << "There are " << arg_list.GetSize() << " column args." << endl;
-  
-  LoadGenotypeDataList(arg_list, output_list);
-  
-  cout << "Args are loaded." << endl;
-  
-  const int num_cols = output_list.GetSize();
-  
-  // Give some information in verbose mode.
-  if (verbose == true) {
-    cout << "  outputing as ";
-    if (print_mode == 1) cout << "boolean ";
-    cout << "text files." << endl;
-    cout << "  Format: ";
-    
-    output_it.Reset();
-    while (output_it.Next() != NULL) {
-      cout << output_it.Get()->GetName() << " ";
-    }
-    cout << endl;
-  }
-  
-  ofstream & fp = data_file_manager.GetOFStream(filename);
-  
-  // printing the headers
-  // not done by default since many dumps may be analyzed at the same time
-  // and results would be put in the same file
-  if (arg_list.GetSize()==0) {
-    // Headers
-    fp << "# Avida analyze modularity data" << endl;
-    fp << "# 1: organism length" << endl;
-    fp << "# 2: number of tasks done" << endl;
-    fp << "# 3: number of sites used in tasks" << endl;
-    fp << "# 4: proportion of sites used in tasks" << endl;
-    fp << "# 5: average number of tasks done per site" << endl;
-    fp << "# 6: average number sites per task done" << endl;
-    fp << "# 7: average number tasks per site per task" << endl;
-    fp << "# 8: average proportion of the non-overlaping region of a task" << endl;
-    fp << "# 9-17: average StDev in positions used for task 1-9" << endl;
-    fp << "# 18-26: average number of sites necessary for each of the tasks" << endl;
-    fp << "# 27-36: number of sites involved in 0-9 tasks" << endl;
-    fp << "# 37-45: average task length (distance from first to last inst used)" << endl;
-    fp << endl;
-    return;
-  }        
-  
-  // initialize various variables used in calculations
-  
-  int num_orgs = 0;		// number of organisms in the dump
-  
-  double  av_length = 0; 	// average organism length
-  double  av_task = 0; 	// average # of tasks done
-  double  av_inst = 0; 	// average # instructions used in tasks
-  double  av_inst_len = 0; 	// proportion of sites used for tasks
-  double  av_site_task = 0; 	// average number of sites per task
-  double  av_task_site = 0;   // average number of tasks per site
-  double  av_t_s_norm = 0;	// average number of tasks per site per task
-  double  av_task_overlap = 0; // average overlap between tasks
-  
-  // average StDev in positions used for a task
-  tArray<double> std_task_position(num_cols);
-  std_task_position.SetAll(0.0);
-  
-  // # of organisms actually doing a task
-  tArray<double> org_task(num_cols);
-  org_task.SetAll(0.0);
-  
-  // av. # of sites necessary for each of the tasks
-  tArray<double> av_num_inst(num_cols);
-  av_num_inst.SetAll(0.0);
-  
-  // number of sites involved in 0-9 tasks 
-  tArray<double> av_inst_task(num_cols+1);
-  av_inst_task.SetAll(0.0);
-  
-  // av. # task length (distance from first to last site used)
-  tArray<double> av_task_length(num_cols);
-  av_task_length.SetAll(0.0);
-  
-  
-  ///////////////////////////////////////////////////////
-  // Loop through all of the genotypes in this batch...
-  ///////////////////////////////////////////////////////
-  
-  tListIterator<cAnalyzeGenotype> batch_it(batch[cur_batch].List());
-  cAnalyzeGenotype * genotype = NULL;
-  
-  // would like to test oly the viable ones, but they can be non-viable
-  // and still reproduce and do tasks
-  // while ((genotype = batch_it.Next()) != NULL && genotype->GetViable()) {
-  while ((genotype = batch_it.Next()) != NULL) {
-    
-    int num_cpus = genotype->GetNumCPUs();
-    
-    if (verbose == true) cout << "  Mapping " << genotype->GetName() << endl;
-    
-    // Calculate the stats for the genotype we're working with...
-    genotype->Recalculate();
-    
-    // Check if the organism does any tasks. 
-    int does_tasks = 0;
-    for (int i = 0; i < num_cols; i++) {
-      if (genotype->GetTaskCount(i) > 0)  does_tasks = 1;
-    }
-    
-    // Don't calculate the modularity if the organism doesn't reproduce
-    // i.e. if the fitness is 0 
-    if (genotype->GetFitness() != 0 && does_tasks != 0) {
-      num_orgs = num_orgs + num_cpus;
-      
-      const int max_line = genotype->GetLength();
-      const cGenome & base_genome = genotype->GetGenome();
-      cGenome mod_genome(base_genome);
-      
-      // Create and initialize the modularity matrix
-      tMatrix<int> mod_matrix(num_cols, max_line);
-      mod_matrix.SetAll(0);
-      
-      // Create and initialize the task overalp matrix
-      tMatrix<int> task_overlap(num_cols, num_cols);
-      task_overlap.SetAll(0);
-      
-      // Create an initialize the counters for modularity
-      tArray<int> num_task(max_line); // number of tasks instruction is used in
-      tArray<int> num_inst(num_cols); // number of instructions involved in a task
-      tArray<int> sum(num_cols); 	    // helps with StDev calculations
-      tArray<int> sumsq(num_cols);    // helps with StDev calculations
-      tArray<int> inst_task(num_cols+1); // # of inst's involved in 0,1,2,3... tasks
-      tArray<int> task_length(num_cols);    // ditance between first and last inst involved in a task
-      
-      num_task.SetAll(0);
-      num_inst.SetAll(0);
-      sum.SetAll(0);
-      sumsq.SetAll(0);
-      inst_task.SetAll(0);
-      task_length.SetAll(0);
-      
-      int total_task = 0;        // total number of tasks done
-      int total_inst = 0;        // total number of instructions involved in tasks
-      int total_all = 0;         // sum of mod_matrix
-      double sum_task_overlap = 0;// task overlap for for this geneome
-        
-        cInstSet map_inst_set(inst_set);
-        
-        // Locate instruction corresponding to "NULL" in the instruction library.
-        {
-          const cInstruction inst_lib_null_inst = map_inst_set.GetInstLib()->GetInst("NULL");
-          if(inst_lib_null_inst == map_inst_set.GetInstLib()->GetInstError()){
-            cout << "<cAnalyze::CommandMapTasks> got error:" << endl;
-            cout << " --- instruction \"NULL\" isn't in the instruction library;" << endl;
-            cout << " --- get somebody to map a function to \"NULL\" in the library." << endl;
-            cout << " --- (probably to class method \"cHardware-of-some-type::initInstLib\"" << endl;
-            cout << " --- in file named \"cpu/hardware-of-some-type.cc\".)" << endl;
-            cout << " --- bailing-out." << endl;
-            exit(1);
-          }
-          // Add mapping to located instruction. 
-          map_inst_set.Add2(inst_lib_null_inst.GetOp());
-        }
-        const cInstruction null_inst = map_inst_set.GetInst("NULL");
-        
-        // Loop through all the lines of code, testing the removal of each.
-        for (int line_num = 0; line_num < max_line; line_num++) {
-          int cur_inst = base_genome[line_num].GetOp();
-          
-          mod_genome[line_num] = null_inst;
-          cAnalyzeGenotype test_genotype(mod_genome, map_inst_set);
-          cAnalyzeGenotype old_genotype(base_genome, map_inst_set);
-          test_genotype.Recalculate();
-          
-          // Print the individual columns...
-          output_it.Reset();
-          tDataEntryCommand<cAnalyzeGenotype> * data_command = NULL;
-          int cur_col = 0;
-          while ((data_command = output_it.Next()) != NULL) {
-            data_command->SetTarget(&test_genotype);
-            test_genotype.SetSpecialArgs(data_command->GetArgs());
-            // This is done so that under 'binary' option it marks
-            // the task as being influenced by the mutation iff
-            // it is completely knocked out, not just decreased
-            genotype->SetSpecialArgs(data_command->GetArgs());
-            
-            int compare = data_command->Compare(genotype);
-            
-            // If knocking out an instruction stops the expression of a
-            // particular task, mark that in the modularity matrix
-            // and add it to two counts
-            // Only do the checking if the test_genotype replicate, i.e.
-            // if it's fitness is not zeros
-            
-            if (compare < 0  && test_genotype.GetFitness() != 0) {
-              mod_matrix(cur_col,line_num) = 1;
-              num_inst[cur_col]++;
-              num_task[line_num]++;
-            }
-            cur_col++;
-          }
-          
-          // Reset the mod_genome back to the original sequence.
-          mod_genome[line_num].SetOp(cur_inst);
-        } // end of genotype-phenotype mapping for a single organism
-        
-        for (int i = 0; i < num_cols; i++) {if (num_inst[i] != 0) total_task++;}
-        for (int i = 0; i < max_line; i++) {if (num_task[i] != 0) total_inst++;}
-        for (int i = 0; i < num_cols; i++) {total_all = total_all + num_inst[i];}
-        
-        // Add the values to the av_ variables, used for calculating the average
-        // in order to weigh them by abundance, multiply everything by num_cpus
-        
-        av_length = av_length + max_line*num_cpus;
-        av_task = av_task + total_task*num_cpus;
-        av_inst = av_inst + total_inst*num_cpus;
-        av_inst_len = av_inst_len + (double) total_inst*num_cpus/max_line;
-        
-        if (total_task !=0)  av_site_task = av_site_task + num_cpus * (double) total_all/total_task; 
-        if (total_inst !=0)  av_task_site = av_task_site + num_cpus * (double) total_all/total_inst; 
-        if (total_inst !=0 && total_task !=0) {
-          av_t_s_norm = av_t_s_norm + num_cpus * (double) total_all/(total_inst*total_task); 
-        }
-        
-        for (int i = 0; i < num_cols; i++) { 
-          if (num_inst[i] > 0) {
-            av_num_inst[i] = av_num_inst[i] + num_inst[i] * num_cpus;
-            org_task[i] = org_task[i] + num_cpus;   // count how many are actually doing the task
-          }
-        }	
-        
-        // calculate average task overlap
-        // first construct num_task x num_task matrix with number of sites overlapping
-        for (int i = 0; i < max_line; i++) {
-          for (int j = 0; j < num_cols; j++) {
-            for (int k = j; k < num_cols; k++) {
-              if (mod_matrix(j,i)>0 && mod_matrix(k,i)>0) {
-                task_overlap(j,k)++;
-                if (j!=k) task_overlap(k,j)++;
-              }               
-            }
-          }
-        }
-        
-        // go though the task_overlap matrix, add and average everything up. 
-        if (total_task > 1) {
-          for (int i = 0; i < num_cols; i++) {
-            double overlap_per_task = 0;                 
-            for (int j = 0; j < num_cols; j++) {
-              if (i!=j) {overlap_per_task = overlap_per_task + task_overlap(i,j);}
-            }
-            if (task_overlap(i,i) !=0){
-              sum_task_overlap = sum_task_overlap + overlap_per_task / (task_overlap(i,i) * (total_task-1));   
-            }
-          }
-        }
-        
-        // now, divide that by number of tasks done and add to the grand sum, weigthed by num_cpus 
-        if (total_task!=0) {
-          av_task_overlap = av_task_overlap + num_cpus * (double) sum_task_overlap/total_task ;
-        }
-        // calculate the first/last postion of a task, the task "spread"
-        // starting from the top look for the fist command that matters for a task
-        
-        for (int i = 0; i < num_cols; i++) { 
-          int j = 0; 
-          while (j < max_line) {
-            if (mod_matrix(i,j) > 0 && task_length[i] == 0 ) {
-              task_length[i] = j;
-              break;
-            }
-            j++;
-          }
-        }
-        
-        // starting frm the bottom look for the last command that matters for a task
-        // and substract it from the first to get the task length
-        // add one in order to account for both the beginning and the end instruction
-        for (int i = 0; i < num_cols; i++) { 
-          int j = max_line - 1; 
-          while (j > -1) {
-            if (mod_matrix(i,j) > 0) {
-              task_length[i] = j - task_length[i] + 1;
-              break;
-            }
-            j--;
-          }
-        }
-        // add the task lengths to the average for the batch
-        // weigthed by the number of cpus for that genotype 
-        for (int i = 0; i < num_cols; i++) { 
-          av_task_length[i] = av_task_length[i] +  num_cpus * task_length[i];
-        }
-        
-        // calculate the Standard Deviation in the mean position of the task
-        for (int i = 0; i < num_cols; i++) { 
-          for (int j = 0; j < max_line; j++) { 
-            if (mod_matrix(i,j)>0) sum[i] = sum[i] + j;
-          }		
-        }
-        
-        double temp = 0;
-        for (int i = 0; i < num_cols; i++) {
-          if (num_inst[i]>1) { 
-            double av_sum = sum[i]/num_inst[i];
-            for (int j = 0; j < max_line; j++) {
-              if (mod_matrix(i,j)>0) temp = (av_sum - j)*(av_sum - j);
-            }
-            std_task_position[i] = std_task_position[i] + sqrt(temp/(num_inst[i]-1))*num_cpus;
-          } 
-        } 
-        
-        for (int i = 0; i < max_line; i++) { inst_task[num_task[i]]++ ;}
-        for (int i = 0; i < num_cols+1; i++) { av_inst_task[i] = av_inst_task[i] + inst_task[i] * num_cpus;}
-        
-    }
-  }  // this is the end of the loop going though all the organisms
-  
-  // make sure there are some organisms doing task in this batch
-  // if not, return all zeros
-  
-  if (num_orgs != 0) { 
-    fp << (double) av_length/num_orgs  << " ";  	// 1: average length
-    fp << (double) av_task/num_orgs << " ";		// 2: av. number of tasks done
-    fp << (double) av_inst/num_orgs << " ";		// 3: av. number of sites used for tasks
-    fp << (double) av_inst_len/num_orgs << " ";		// 4: proportion of sites used for tasks
-    fp << (double) av_task_site/num_orgs << " ";	// 5: av. number of tasks per site
-    fp << (double) av_site_task/num_orgs << " ";	// 6: av. number of sites per task
-    fp << (double) av_t_s_norm/num_orgs << " ";		// 7: av. number of tasks per site per task
-    fp << (double) 1 - av_task_overlap/num_orgs << " ";        // 8: av. proportion of a task that DOESN'T overlap
-    for (int i = 0; i < num_cols; i++) {
-      if (org_task[i] > 0) fp << std_task_position[i]/org_task[i]  << " ";
-      else fp << 0 << " ";
-    }
-    for (int i = 0; i < num_cols; i++) {
-      if (org_task[i] > 0) fp << (double) av_num_inst[i]/org_task[i]  << " ";
-      else fp << 0 << " ";
-    }
-    for (int i = 0; i < num_cols+1; i++) { fp << (double) av_inst_task[i]/num_orgs  << " ";}
-    for (int i = 0; i < num_cols; i++) { fp << (double) av_task_length[i]/num_orgs  << " ";}
-    fp << endl;
-  }
-  
-  else {
-    for (int i = 0; i < 8+4*num_cols+1; i++) {fp << "0 ";}
-    fp << endl;
-  }
-  }
-
-
-void cAnalyze::CommandMapMutations(cString cur_string)
-{
-  cout << "Constructing genome mutations maps..." << endl;
-  
-  // Load in the variables...
-  cString directory = PopDirectory(cur_string, "mutations/");
-  int file_type = FILE_TYPE_TEXT;
-  
-  cStringList arg_list(cur_string);
-  
-  // Check for some command specific variables.
-  if (arg_list.PopString("text") != "") file_type = FILE_TYPE_TEXT;
-  if (arg_list.PopString("html") != "") file_type = FILE_TYPE_HTML;
-  
-  // Give some information in verbose mode.
-  if (verbose == true) {
-    cout << "  outputing as ";
-    if (file_type == FILE_TYPE_TEXT) cout << "text files." << endl;
-    else cout << "HTML files." << endl;
-  }
-  
-  
-  ///////////////////////////////////////////////////////
-  // Loop through all of the genotypes in this batch...
-  
-  tListIterator<cAnalyzeGenotype> batch_it(batch[cur_batch].List());
-  cAnalyzeGenotype * genotype = NULL;
-  while ((genotype = batch_it.Next()) != NULL) {
-    if (verbose == true) {
-      cout << "  Creating mutation map for " << genotype->GetName() << endl;
-    }
-    
-    // Construct this filename...
-    cString filename;
-    if (file_type == FILE_TYPE_TEXT) {
-      filename.Set("%smut_map.%s.dat", directory(), genotype->GetName()());
-    } else {   //  if (file_type == FILE_TYPE_HTML) {
-      filename.Set("%smut_map.%s.html", directory(), genotype->GetName()());
-    }
-    ofstream fp(filename());
-    
-    // Calculate the stats for the genotype we're working with...
-    genotype->Recalculate();
-    const double base_fitness = genotype->GetFitness();
-    const int num_insts = inst_set.GetSize();
-    
-    // Headers...
-    if (file_type == FILE_TYPE_TEXT) {
-      fp << "# 1: Genome instruction ID (pre-mutation)" << endl;
-      for (int i = 0; i < num_insts; i++) {
-        fp << "# " << i+1 <<": Fit if mutated to '"
-        << inst_set.GetName(i) << "'" << endl;
-      }
-      fp << "# " << num_insts + 2 << ": Knockout" << endl;
-      fp << "# " << num_insts + 3 << ": Fraction Lethal" << endl;
-      fp << "# " << num_insts + 4 << ": Fraction Detremental" << endl;
-      fp << "# " << num_insts + 5 << ": Fraction Neutral" << endl;
-      fp << "# " << num_insts + 6 << ": Fraction Beneficial" << endl;
-      fp << "# " << num_insts + 7 << ": Average Fitness" << endl;
-      fp << "# " << num_insts + 8 << ": Expected Entropy" << endl;
-      fp << "# " << num_insts + 9 << ": Original Instruction Name" << endl;
-      fp << endl;
-      
-    } else { // if (file_type == FILE_TYPE_HTML) {
-             // Mark file as html
-      fp << "<html>" << endl;
-      
-      // Setup the body...
-      fp << "<body bgcolor=\"#FFFFFF\"" << endl
-        << " text=\"#000000\"" << endl
-        << " link=\"#0000AA\"" << endl
-        << " alink=\"#0000FF\"" << endl
-        << " vlink=\"#000044\">" << endl
-        << endl
-        << "<h1 align=center>Mutation Map for Run " << batch[cur_batch].Name()
-        << ", ID " << genotype->GetID() << "</h1>" << endl
-        << "<center>" << endl
-        << endl;
-      
-      // The main chart...
-      fp << "<table border=1 cellpadding=2>" << endl;
-      
-      // The headings...///
-      fp << "<tr><th>Genome ";
-      for (int i = 0; i < num_insts; i++) {
-        fp << "<th>" << inst_set.GetName(i) << " ";
-      }
-      fp << "<th>Knockout ";
-      fp << "<th>Frac. Lethal ";
-      fp << "<th>Frac. Detremental ";
-      fp << "<th>Frac. Neutral ";
-      fp << "<th>Frac. Beneficial ";
-      fp << "<th>Ave. Fitness ";
-      fp << "<th>Expected Entropy ";
-      fp << "</tr>" << endl << endl;
-    }
-    
-    const int max_line = genotype->GetLength();
-    const cGenome & base_genome = genotype->GetGenome();
-    cGenome mod_genome(base_genome);
-    
-    // Keep track of the number of mutations in each category...
-    int total_dead = 0, total_neg = 0, total_neut = 0, total_pos = 0;
-    double total_fitness = 0.0;
-    tArray<double> col_fitness(num_insts + 1);
-    col_fitness.SetAll(0.0);
-    
-    // Build an empty instruction into the an instruction library.
-    cInstSet map_inst_set(inst_set);
-    // Locate instruction corresponding to "NULL" in the instruction library.
-    {
-      const cInstruction inst_lib_null_inst = map_inst_set.GetInstLib()->GetInst("NULL");
-      if (inst_lib_null_inst == map_inst_set.GetInstLib()->GetInstError()){
-        cout << "<cAnalyze::CommandMapMutations> got error:" << endl;
-        cout << " --- instruction \"NULL\" isn't in the instruction library;" << endl;
-        cout << " --- get somebody to map a function to \"NULL\" in the library." << endl;
-        cout << " --- (probably to class method \"cHardware-of-some-type::initInstLib\"" << endl;
-        cout << " --- in file named \"cpu/hardware-of-some-type.cc\".)" << endl;
-        cout << " --- bailing-out." << endl;
-        exit(1);
-      }
-      // Add mapping to located instruction. 
-      map_inst_set.Add2(inst_lib_null_inst.GetOp());
-    }
-    const cInstruction null_inst = map_inst_set.GetInst("NULL");
-    
-    cString color_string;  // For coloring cells...
-    
-    // Loop through all the lines of code, testing all mutations...
-    for (int line_num = 0; line_num < max_line; line_num++) {
-      int cur_inst = base_genome[line_num].GetOp();
-      char cur_symbol = base_genome[line_num].GetSymbol();
-      int row_dead = 0, row_neg = 0, row_neut = 0, row_pos = 0;
-      double row_fitness = 0.0;
-      
-      // Column 1... the original instruction in the geneome.
-      if (file_type == FILE_TYPE_HTML) {
-        fp << "<tr><td align=right>" << inst_set.GetName(cur_inst)
-        << " (" << cur_symbol << ") ";
-      } else {
-        fp << cur_inst << " ";
-      }
-      
-      // Columns 2 to D+1 (the possible mutations)
-      for (int mod_inst = 0; mod_inst < num_insts; mod_inst++) 
-      {
-        if (mod_inst == cur_inst) {
-          if (file_type == FILE_TYPE_HTML) {
-            color_string = "#FFFFFF";
-            fp << "<th bgcolor=\"" << color_string << "\">";
-          }
-        }
-        else {
-          mod_genome[line_num].SetOp(mod_inst);
-          cAnalyzeGenotype test_genotype(mod_genome, inst_set);
-          test_genotype.Recalculate();
-          const double test_fitness = test_genotype.GetFitness() / base_fitness;
-          row_fitness += test_fitness;
-          total_fitness += test_fitness;
-          col_fitness[mod_inst] += test_fitness;
-
-          // Categorize this mutation...
-          if (test_fitness == 1.0) {           // Neutral Mutation...
-            row_neut++;
-            total_neut++;
-            if (file_type == FILE_TYPE_HTML) color_string = "#FFFFFF";
-          } else if (test_fitness == 0.0) {    // Lethal Mutation...
-            row_dead++;
-            total_dead++;
-            if (file_type == FILE_TYPE_HTML) color_string = "#FF0000";
-          } else if (test_fitness < 1.0) {     // Detrimental Mutation...
-            row_neg++;
-            total_neg++;
-            if (file_type == FILE_TYPE_HTML) color_string = "#FFFF00";
-          } else {                             // Beneficial Mutation...
-            row_pos++;
-            total_pos++;
-            if (file_type == FILE_TYPE_HTML) color_string = "#00FF00";
-          }
-          
-          // Write out this cell...
-          if (file_type == FILE_TYPE_HTML) {
-            fp << "<th bgcolor=\"" << color_string << "\">";
-          }
-          fp << test_fitness << " ";
-        }
-      }
-      
-      // Column: Knockout
-      mod_genome[line_num] = null_inst;
-      cAnalyzeGenotype test_genotype(mod_genome, map_inst_set);
-      test_genotype.Recalculate();
-      const double test_fitness = test_genotype.GetFitness() / base_fitness;
-      col_fitness[num_insts] += test_fitness;
-      
-      // Categorize this mutation if its in HTML mode (color only)...
-      if (file_type == FILE_TYPE_HTML) {
-        if (test_fitness == 1.0) color_string = "#FFFFFF";
-        else if (test_fitness == 0.0) color_string = "#FF0000";
-        else if (test_fitness < 1.0) color_string = "#FFFF00";
-        else color_string = "#00FF00";
-        
-        fp << "<th bgcolor=\"" << color_string << "\">";
-      }
-      
-      fp << test_fitness << " ";
-      
-      // Fraction Columns...
-      if (file_type == FILE_TYPE_HTML) fp << "<th bgcolor=\"#FF0000\">";
-      fp << (double) row_dead / (double) (num_insts-1) << " ";
-      
-      if (file_type == FILE_TYPE_HTML) fp << "<th bgcolor=\"#FFFF00\">";
-      fp << (double) row_neg / (double) (num_insts-1) << " ";
-      
-      if (file_type == FILE_TYPE_HTML) fp << "<th bgcolor=\"#FFFFFF\">";
-      fp << (double) row_neut / (double) (num_insts-1) << " ";
-      
-      if (file_type == FILE_TYPE_HTML) fp << "<th bgcolor=\"#00FF00\">";
-      fp << (double) row_pos / (double) (num_insts-1) << " ";
-      
-      
-      // Column: Average Fitness
-      if (file_type == FILE_TYPE_HTML) fp << "<th>";
-      fp << row_fitness / (double) (num_insts-1) << " ";
-      
-      // Column: Expected Entropy  @CAO Implement!
-      if (file_type == FILE_TYPE_HTML) fp << "<th>";
-      fp << 0.0 << " ";
-      
-      // End this row...
-      if (file_type == FILE_TYPE_HTML) fp << "</tr>";
-      fp << endl;
-      
-      // Reset the mod_genome back to the original sequence.
-      mod_genome[line_num].SetOp(cur_inst);
-    }
-    
-    
-    // Construct the final line of the table with all totals...
-    if (file_type == FILE_TYPE_HTML) {
-      fp << "<tr><th>Totals";
-      
-      // Instructions + Knockout
-      for (int i = 0; i <= num_insts; i++) {
-        fp << "<th>" << col_fitness[i] / max_line << " ";
-      }
-      
-      int total_tests = max_line * (num_insts-1);
-      fp << "<th>" << (double) total_dead / (double) total_tests << " ";
-      fp << "<th>" << (double) total_neg / (double) total_tests << " ";
-      fp << "<th>" << (double) total_neut / (double) total_tests << " ";
-      fp << "<th>" << (double) total_pos / (double) total_tests << " ";
-      fp << "<th>" << total_fitness / (double) total_tests << " ";
-      fp << "<th>" << 0.0 << " ";
-      
-      
-      // And close everything up...
-      fp << "</table>" << endl
-        << "</center>" << endl;
-    }
-    
-    }
-    }
-
-
-void cAnalyze::CommandMapDepth(cString cur_string)
-{
-  cout << "Constructing depth map..." << endl;
-  
-  cString filename("depth_map.dat");
-  if (cur_string.GetSize() != 0) filename = cur_string.PopWord();  
-  
-  int min_batch = 0;
-  int max_batch = cur_batch - 1;
-  
-  if (cur_string.GetSize() != 0) min_batch = cur_string.PopWord().AsInt();
-  if (cur_string.GetSize() != 0) max_batch = cur_string.PopWord().AsInt();
-  
-  // First, scan all of the batches to find the maximum depth.
-  int max_depth = -1;
-  cAnalyzeGenotype * genotype;
-  for (int i = min_batch; i <= max_batch; i++) {
-    tListIterator<cAnalyzeGenotype> list_it(batch[i].List());
-    while ((genotype = list_it.Next()) != NULL) {
-      if (genotype->GetDepth() > max_depth) max_depth = genotype->GetDepth();
-    }
-  }
-  
-  cout << "max_depth = " << max_depth << endl;
-  
-  ofstream & fp = data_file_manager.GetOFStream(filename);
-  
-  cout << "Output to " << filename << endl;
-  tArray<int> depth_array(max_depth+1);
-  for (cur_batch = min_batch; cur_batch <= max_batch; cur_batch++) {
-    depth_array.SetAll(0);
-    tListIterator<cAnalyzeGenotype> list_it(batch[cur_batch].List());
-    while ((genotype = list_it.Next()) != NULL) {
-      const int cur_depth = genotype->GetDepth();
-      const int cur_count = genotype->GetNumCPUs();
-      depth_array[cur_depth] += cur_count;
-    }
-    
-    for (int i = 0; i <= max_depth; i++) {
-      fp << depth_array[i] << " ";
-    }
-    fp << endl;
-  }
-}
-
-void cAnalyze::CommandHamming(cString cur_string)
-{
-  cString filename("hamming.dat");
-  if (cur_string.GetSize() != 0) filename = cur_string.PopWord();
-  
-  int batch1 = PopBatch(cur_string.PopWord());
-  int batch2 = PopBatch(cur_string.PopWord());
-  
-  // We want batch2 to be the larger one for efficiency...
-  if (batch[batch1].List().GetSize() > batch[batch2].List().GetSize()) {
-    int tmp = batch1;  batch1 = batch2;  batch2 = tmp;
-  }
-  
-  if (verbose == false) {
-    cout << "Calculating Hamming Distance... ";
-    cout.flush();
-  } else {
-    cout << "Calculating Hamming Distance between batches "
-    << batch1 << " and " << batch2 << endl;
-    cout.flush();
-  }
-  
-  // Setup some variables;
-  cAnalyzeGenotype * genotype1 = NULL;
-  cAnalyzeGenotype * genotype2 = NULL;
-  int total_dist = 0;
-  int total_count = 0;
-  
-  tListIterator<cAnalyzeGenotype> list1_it(batch[batch1].List());
-  tListIterator<cAnalyzeGenotype> list2_it(batch[batch2].List());
-  
-  while ((genotype1 = list1_it.Next()) != NULL) {
-    list2_it.Reset();
-    while ((genotype2 = list2_it.Next()) != NULL) {
-      // Determine the counts...
-      const int count1 = genotype1->GetNumCPUs();
-      const int count2 = genotype2->GetNumCPUs();
-      const int num_pairs = (genotype1 == genotype2) ?
-        ((count1 - 1) * (count2 - 1)) : (count1 * count2);
-      if (num_pairs == 0) continue;
-      
-      // And do the tests...
-      const int dist =
-        cGenomeUtil::FindHammingDistance(genotype1->GetGenome(),
-                                         genotype2->GetGenome());
-      total_dist += dist * num_pairs;
-      total_count += num_pairs;
-    }
-  }
-  
-  
-  // Calculate the final answer
-  double ave_dist = (double) total_dist / (double) total_count;
-  cout << " ave distance = " << ave_dist << endl;
-  
-  cDataFile & df = data_file_manager.Get(filename);
-  
-  df.WriteComment( "Hamming distance information" );
-  df.WriteTimeStamp();  
-  
-  df.Write(batch[batch1].Name(), "Name of First Batch");
-  df.Write(batch[batch2].Name(), "Name of Second Batch");
-  df.Write(ave_dist,             "Average Hamming Distance");
-  df.Write(total_count,          "Total Pairs Test");
-  df.Endl();
-}
-
-void cAnalyze::CommandLevenstein(cString cur_string)
-{
-  cString filename("lev.dat");
-  if (cur_string.GetSize() != 0) filename = cur_string.PopWord();
-  
-  int batch1 = PopBatch(cur_string.PopWord());
-  int batch2 = PopBatch(cur_string.PopWord());
-  
-  // We want batch2 to be the larger one for efficiency...
-  if (batch[batch1].List().GetSize() > batch[batch2].List().GetSize()) {
-    int tmp = batch1;  batch1 = batch2;  batch2 = tmp;
-  }
-  
-  if (verbose == false) {
-    cout << "Calculating Levenstein Distance... ";
-    cout.flush();
-  } else {
-    cout << "Calculating Levenstein Distance between batch "
-    << batch1 << " and " << batch2 << endl;
-    cout.flush();
-  }
-  
-  // Setup some variables;
-  cAnalyzeGenotype * genotype1 = NULL;
-  cAnalyzeGenotype * genotype2 = NULL;
-  int total_dist = 0;
-  int total_count = 0;
-  
-  tListIterator<cAnalyzeGenotype> list1_it(batch[batch1].List());
-  tListIterator<cAnalyzeGenotype> list2_it(batch[batch2].List());
-  
-  // Loop through all of the genotypes in each batch...
-  while ((genotype1 = list1_it.Next()) != NULL) {
-    list2_it.Reset();
-    while ((genotype2 = list2_it.Next()) != NULL) {
-      // Determine the counts...
-      const int count1 = genotype1->GetNumCPUs();
-      const int count2 = genotype2->GetNumCPUs();
-      const int num_pairs = (genotype1 == genotype2) ?
-        ((count1 - 1) * (count2 - 1)) : (count1 * count2);
-      if (num_pairs == 0) continue;
-      
-      // And do the tests...
-      const int dist = cGenomeUtil::FindEditDistance(genotype1->GetGenome(),
-                                                     genotype2->GetGenome());
-      total_dist += dist * num_pairs;
-      total_count += num_pairs;
-    }
-  }
-  
-  // Calculate the final answer
-  double ave_dist = (double) total_dist / (double) total_count;
-  cout << " ave distance = " << ave_dist << endl;
-  
-  cDataFile & df = data_file_manager.Get(filename);
-  
-  df.WriteComment( "Levenstein distance information" );
-  df.WriteTimeStamp();  
-  
-  df.Write(batch[batch1].Name(), "Name of First Batch");
-  df.Write(batch[batch2].Name(), "Name of Second Batch");
-  df.Write(ave_dist,             "Average Levenstein Distance");
-  df.Write(total_count,          "Total Pairs Test");
-  df.Endl();
-}
-
-void cAnalyze::CommandSpecies(cString cur_string)
-{
-  cString filename("species.dat");
-  if (cur_string.GetSize() != 0) filename = cur_string.PopWord();
-  
-  int batch1 = PopBatch(cur_string.PopWord());
-  int batch2 = PopBatch(cur_string.PopWord());
-  int num_compare = PopBatch(cur_string.PopWord());
-  
-  // We want batch2 to be the larger one for efficiency...
-  if (batch[batch1].List().GetSize() > batch[batch2].List().GetSize()) {
-    int tmp = batch1;  batch1 = batch2;  batch2 = tmp;
-  }
-  
-  if (verbose == false) cout << "Calculating Species Distance... " << endl;
-  else cout << "Calculating Species Distance between batch "
-    << batch1 << " and " << batch2 << endl;
-  
-  // Setup some variables;
-  cAnalyzeGenotype * genotype1 = NULL;
-  cAnalyzeGenotype * genotype2 = NULL;
-  int total_fail = 0;
-  int total_count = 0;
-  
-  tListIterator<cAnalyzeGenotype> list1_it(batch[batch1].List());
-  tListIterator<cAnalyzeGenotype> list2_it(batch[batch2].List());
-  
-  // Loop through all of the genotypes in each batch...
-  while ((genotype1 = list1_it.Next()) != NULL) {
-    list2_it.Reset();
-    while ((genotype2 = list2_it.Next()) != NULL) {
-      // Determine the counts...
-      const int count1 = genotype1->GetNumCPUs();
-      const int count2 = genotype2->GetNumCPUs();
-      int num_pairs = count1 * count2; 
-      int fail_count = 0;
-      bool cross1_viable = true;
-      bool cross2_viable = true;
-      
-      
-      if (genotype1 == genotype2) {
-        total_count += num_pairs * 2 * num_compare;
-      }
-      else {	
-        assert(num_compare!=0);
-        // And do the tests...
-        for (int iter=1; iter < num_compare; iter++) {
-          cCPUMemory test_genome0 = genotype1->GetGenome(); 
-          cCPUMemory test_genome1 = genotype2->GetGenome(); 
-          
-          double start_frac = g_random.GetDouble();
-          double end_frac = g_random.GetDouble();
-          if (start_frac > end_frac) nFunctions::Swap(start_frac, end_frac);
-          
-          int start0 = (int) (start_frac * (double) test_genome0.GetSize());
-          int end0   = (int) (end_frac * (double) test_genome0.GetSize());
-          int start1 = (int) (start_frac * (double) test_genome1.GetSize());
-          int end1   = (int) (end_frac * (double) test_genome1.GetSize());
-          assert( start0 >= 0  &&  start0 < test_genome0.GetSize() );
-          assert( end0   >= 0  &&  end0   < test_genome0.GetSize() );
-          assert( start1 >= 0  &&  start1 < test_genome1.GetSize() );
-          assert( end1   >= 0  &&  end1   < test_genome1.GetSize() );
-          
-          // Calculate size of sections crossing over...    
-          int size0 = end0 - start0;
-          int size1 = end1 - start1;
-          
-          int new_size0 = test_genome0.GetSize() - size0 + size1;   
-          int new_size1 = test_genome1.GetSize() - size1 + size0;
-          
-          // Don't Crossover if offspring will be illegal!!!
-          if (new_size0 < MIN_CREATURE_SIZE || new_size0 > MAX_CREATURE_SIZE || 
-              new_size1 < MIN_CREATURE_SIZE || new_size1 > MAX_CREATURE_SIZE) { 
-            fail_count +=2; 
-            break; 
-          } 
-          
-	  // Swap the components
-	  cGenome cross0 = cGenomeUtil::Crop(test_genome0, start0, end0);
-	  cGenome cross1 = cGenomeUtil::Crop(test_genome1, start1, end1);
-	  test_genome0.Replace(start0, size0, cross1);
-	  test_genome1.Replace(start1, size1, cross0);
-          
-	  // Run each side, and determine viability...
-          cCPUTestInfo test_info;
-          cTestCPU::TestGenome(test_info, test_genome0);
-          cross1_viable = test_info.IsViable();
-          
-          cTestCPU::TestGenome(test_info, test_genome1);
-          cross2_viable = test_info.IsViable();
-          
-          if (cross1_viable == false) fail_count++;   
-          if (cross2_viable == false) fail_count++;
-        }
-        
-        total_fail += fail_count * num_pairs;
-        total_count += num_pairs * 2 * num_compare;
-      }
-    }
-  }
-  // Calculate the final answer
-  double ave_dist = (double) total_fail / (double) total_count;
-  cout << "  ave distance = " << ave_dist
-    << " in " << total_count
-    << " tests." << endl; 
-  
-  cDataFile & df = data_file_manager.Get(filename);
-  
-  df.WriteComment( "Species information" );
-  df.WriteTimeStamp();  
-  
-  df.Write(batch[batch1].Name(), "Name of First Batch");
-  df.Write(batch[batch2].Name(), "Name of Second Batch");
-  df.Write(ave_dist,             "Average Species Distance");
-  df.Write(total_count,          "Total Recombinants tested");
-  df.Endl();
-}
-
-void cAnalyze::CommandRecombine(cString cur_string)
-{
-  int batch1 = PopBatch(cur_string.PopWord());
-  int batch2 = PopBatch(cur_string.PopWord());
-  int batch3 = PopBatch(cur_string.PopWord());
-  int num_compare = PopBatch(cur_string.PopWord());
-  
-  // We want batch2 to be the larger one for efficiency...
-  if (batch[batch1].List().GetSize() > batch[batch2].List().GetSize()) {
-    int tmp = batch1;  batch1 = batch2;  batch2 = tmp;
-  }
-  
-  if (verbose == false) cout << "Creating recombinants...  " << endl;
-  else cout << "Creating recombinants between batch "
-    << batch1 << " and " << batch2 << endl;
-  
-  // Setup some variables;
-  cAnalyzeGenotype * genotype1 = NULL;
-  cAnalyzeGenotype * genotype2 = NULL;
-  
-  tListIterator<cAnalyzeGenotype> list1_it(batch[batch1].List());
-  tListIterator<cAnalyzeGenotype> list2_it(batch[batch2].List());
-  
-  // Loop through all of the genotypes in each batch...
-  while ((genotype1 = list1_it.Next()) != NULL) {
-    list2_it.Reset();
-    while ((genotype2 = list2_it.Next()) != NULL) {
-      // Determine the counts...
-      int fail_count = 0;
-      
-      
-      assert(num_compare!=0);
-      // And do the tests...
-      for (int iter=1; iter < num_compare; iter++) {
-        cCPUMemory test_genome0 = genotype1->GetGenome(); 
-        cCPUMemory test_genome1 = genotype2->GetGenome(); 
-        
-        double start_frac = g_random.GetDouble();
-        double end_frac = g_random.GetDouble();
-        if (start_frac > end_frac) nFunctions::Swap(start_frac, end_frac);
-        
-        int start0 = (int) (start_frac * (double) test_genome0.GetSize());
-        int end0   = (int) (end_frac * (double) test_genome0.GetSize());
-        int start1 = (int) (start_frac * (double) test_genome1.GetSize());
-        int end1   = (int) (end_frac * (double) test_genome1.GetSize());
-        assert( start0 >= 0  &&  start0 < test_genome0.GetSize() );
-        assert( end0   >= 0  &&  end0   < test_genome0.GetSize() );
-        assert( start1 >= 0  &&  start1 < test_genome1.GetSize() );
-        assert( end1   >= 0  &&  end1   < test_genome1.GetSize() );
-        
-        // Calculate size of sections crossing over...    
-        int size0 = end0 - start0;
-        int size1 = end1 - start1;
-        
-        int new_size0 = test_genome0.GetSize() - size0 + size1;   
-        int new_size1 = test_genome1.GetSize() - size1 + size0;
-        
-        // Don't Crossover if offspring will be illegal!!!
-        if (new_size0 < MIN_CREATURE_SIZE || new_size0 > MAX_CREATURE_SIZE || 
-            new_size1 < MIN_CREATURE_SIZE || new_size1 > MAX_CREATURE_SIZE) { 
-          fail_count +=2; 
-          break; 
-        } 
-        
-        if (size0 > 0 && size1 > 0) {
-          cGenome cross0 = cGenomeUtil::Crop(test_genome0, start0, end0);
-          cGenome cross1 = cGenomeUtil::Crop(test_genome1, start1, end1);
-          test_genome0.Replace(start0, size0, cross1);
-          test_genome1.Replace(start1, size1, cross0);
-        }
-        else if (size0 > 0) {
-          cGenome cross0 = cGenomeUtil::Crop(test_genome0, start0, end0);
-          test_genome1.Replace(start1, size1, cross0);
-        }
-        else if (size1 > 0) {
-          cGenome cross1 = cGenomeUtil::Crop(test_genome1, start1, end1);
-          test_genome0.Replace(start0, size0, cross1);
-        }
-        
-        cAnalyzeGenotype * new_genotype0 = new cAnalyzeGenotype(test_genome0, inst_set); 
-        cAnalyzeGenotype * new_genotype1 = new cAnalyzeGenotype(test_genome1, inst_set); 
-        new_genotype0->SetNumCPUs(1); 
-        new_genotype1->SetNumCPUs(1); 
-        new_genotype0->SetID(0);
-        new_genotype1->SetID(0);
-        new_genotype0->SetName("noname");
-        new_genotype1->SetName("noname");
-        
-        batch[batch3].List().PushRear(new_genotype0);
-        batch[batch3].List().PushRear(new_genotype1); 
-        
-        //batch[batch3].List().PushRear(new cAnalyzeGenotype(test_genome0, inst_set));
-        //batch[batch3].List().PushRear(new cAnalyzeGenotype(test_genome1, inst_set));
-        
-      }
-    }
-  }
-}
-
-void cAnalyze::CommandAlign(cString cur_string)
-{
-  // Align does not need any args yet.
-  (void) cur_string;
-  
-  cout << "Aligning sequences..." << endl;
-  
-  if (batch[cur_batch].IsLineage() == false && verbose == true) {
-    cerr << "  Warning: sequences may not be a consecutive lineage."
-    << endl;
-  }
-  
-  // Create an array of all the sequences we need to align.
-  tListPlus<cAnalyzeGenotype> & glist = batch[cur_batch].List();
-  tListIterator<cAnalyzeGenotype> batch_it(glist);
-  const int num_sequences = glist.GetSize();
-  cString * sequences = new cString[num_sequences];
-  
-  // Move through each sequence an update it.
-  batch_it.Reset();
-  cString diff_info;
-  for (int i = 0; i < num_sequences; i++) {
-    sequences[i] = batch_it.Next()->GetGenome().AsString();
-    if (i == 0) continue;
-    // Track of the number of insertions and deletions to shift properly.
-    int num_ins = 0;
-    int num_del = 0;
-    
-    // Compare each string to the previous.
-    cStringUtil::EditDistance(sequences[i], sequences[i-1], diff_info, '_');
-    while (diff_info.GetSize() != 0) {
-      cString cur_mut = diff_info.Pop(',');
-      const char mut_type = cur_mut[0];
-      cur_mut.ClipFront(1); cur_mut.ClipEnd(1);
-      int position = cur_mut.AsInt();
-      
-      // Nothing to do with Mutations
-      if (mut_type == 'M') continue;
-      
-      // Handle insertions...
-      if (mut_type == 'I') {
-        // Loop back and insert an '_' into all previous sequences.
-        for (int j = 0; j < i; j++) {
-          sequences[j].Insert('_', position + num_del);
-        }
-        num_ins++;
-      }
-      
-      // Handle Deletions...
-      else if (mut_type == 'D') {
-        // Insert '_' into the current sequence at the point of deletions.
-        sequences[i].Insert("_", position + num_ins);
-        num_del++;
-      }
-      
-    }
-  }
-  
-  batch_it.Reset();
-  for (int i = 0; i < num_sequences; i++) {
-    batch_it.Next()->SetAlignedSequence(sequences[i]);
-  }
-  
-  // Cleanup
-  delete [] sequences;
-  
-  // Adjust the flags on this batch
-  // batch[cur_batch].SetLineage(false);
-  batch[cur_batch].SetAligned(true);
-}
-
-// Now this command do not consider changing environment 
-// and only work for lineage and fixed-length runs.
-void cAnalyze::AnalyzeNewInfo(cString cur_string)
-{
-  cout << "Analyze new information in child about environment ..." << endl;
-  
-  // Load in the variables
-  int words = cur_string.CountNumWords();
-  if (words < 1) {
-    cout << "This command requires mutation rate, skipping." << endl;
-    return;
-  }
-  
-  // Get the mutation rate ...
-  double mu = cur_string.PopWord().AsDouble();
-  
-  // Create the directory using the string given as the second argument
-  cString dir = cur_string.PopWord();
-  cString defaultDir = "newinfo/";
-  cString directory = PopDirectory(dir, defaultDir);
-  
-  ///////////////////////////////////////////////////////
-  // Loop through all of the genotypes in this batch...
-  
-  cString newinfo_fn;
-  ofstream newinfo_fp;
-  if (batch[cur_batch].IsLineage() == true) {
-    newinfo_fn.Set("%s%s.newinfo.dat", directory(), "lineage");
-    newinfo_fp.open(newinfo_fn);
-  } else {
-    cout << "This command requires the lineage in the batch, skipping.\n";
-    return;
-  }
-  newinfo_fp << "# Legend:" << endl;
-  newinfo_fp << "# 1:Child Genotype ID" << endl;
-  newinfo_fp << "# 2:Parent Genotype ID" << endl;
-  newinfo_fp << "# 3:Information of Child about Environment I(C:E)" << endl;
-  newinfo_fp << "# 4:Information of Parent about Environment I(P:E)" << endl;
-  newinfo_fp << "# 5:I(C:E)-I(P:E)" << endl;
-  newinfo_fp << "# 6:Information Gained in Child" << endl;
-  newinfo_fp << "# 7:Information Decreased in Child" << endl;
-  newinfo_fp << "# 8:Net Increasing of Information in Child" << endl;
-  newinfo_fp << endl; 
-  
-  tListIterator<cAnalyzeGenotype> batch_it(batch[cur_batch].List());
-  cAnalyzeGenotype * parent_genotype = batch_it.Next();
-  if (parent_genotype == NULL) {
-    newinfo_fp.close();
-    return;
-  }
-  cAnalyzeGenotype * child_genotype = NULL;
-  double I_P_E; // Information of parent about environment
-  double H_P_E = AnalyzeEntropy(parent_genotype, mu);
-  I_P_E = parent_genotype->GetLength() - H_P_E;
-
-  while ((child_genotype = batch_it.Next()) != NULL) {
-    
-    if (verbose == true) {
-      cout << "Analyze new information for " << child_genotype->GetName() << endl;
-    }
-    
-    // Information of parent about its environment should not be zero.
-    if (I_P_E == 0) {
-      cerr << "Error: Information between parent and its enviroment is zero."
-	   << "(cAnalyze::AnalyzeNewInfo)" << endl;
-      exit(1);
-    }
-
-    double H_C_E = AnalyzeEntropy(child_genotype, mu);
-    double I_C_E = child_genotype->GetLength() - H_C_E;
-    double net_gain = I_C_E - I_P_E;
-    
-    // Increased information in child compared to parent
-    double child_increased_info = IncreasedInfo(child_genotype, parent_genotype, mu);
-    
-    // Lost information in child compared to parent
-    double child_lost_info = IncreasedInfo(parent_genotype, child_genotype, mu);
-
-    // Write information to file ...
-    newinfo_fp << child_genotype->GetID() << " ";
-    newinfo_fp << parent_genotype->GetID() << " ";
-    newinfo_fp << I_C_E << " ";
-    newinfo_fp << I_P_E << " ";
-    newinfo_fp << net_gain << " ";
-    newinfo_fp << child_increased_info << " ";
-    newinfo_fp << child_lost_info << " ";
-    newinfo_fp << child_increased_info - child_lost_info << endl;
-    
-    parent_genotype = child_genotype;
-    I_P_E = I_C_E;
-  }
-  
-  newinfo_fp.close();
-  return;
-}
-
-
-
-void cAnalyze::WriteClone(cString cur_string)
-{
-  // Load in the variables...
-  cString filename("clone.dat");
-  int num_cells = -1;
-  if (cur_string.GetSize() != 0) filename = cur_string.PopWord();
-  if (cur_string.GetSize() != 0) num_cells = cur_string.PopWord().AsInt();
-  
-  
-  ofstream & fp = data_file_manager.GetOFStream(filename);
-  
-  // Start up again at update zero...
-  fp << "0 ";
-  
-  // Setup the genebank sizes of lists to all be zero.
-  fp << MAX_CREATURE_SIZE << " ";
-  for (int i = 0; i < MAX_CREATURE_SIZE; i++) {
-    fp << "0 ";
-  }
-  
-  // Save the individual genotypes
-  fp << batch[cur_batch].List().GetSize() << " ";
-  
-  int org_count = 0;
-  tListIterator<cAnalyzeGenotype> batch_it(batch[cur_batch].List());
-  cAnalyzeGenotype * genotype = NULL;
-  while ((genotype = batch_it.Next()) != NULL) {
-    org_count += genotype->GetNumCPUs();
-    const int length = genotype->GetLength();
-    const cGenome & genome = genotype->GetGenome();
-    
-    fp << genotype->GetID() << " "
-      << length << " ";
-    
-    for (int i = 0; i < length; i++) {
-      fp << genome[i].GetOp() << " ";
-    }
-  }
-  
-  // Write out the current state of the grid.
-  
-  if (num_cells == 0) num_cells = org_count;
-  fp << num_cells << " ";
-  
-  batch_it.Reset();
-  while ((genotype = batch_it.Next()) != NULL) {
-    for (int i = 0; i < genotype->GetNumCPUs(); i++) {
-      fp << genotype->GetID() << " ";
-    }
-  }
-  
-  // Fill out the remainder of the grid with -1
-  for (int i = org_count; i < num_cells; i++) {
-    fp << "-1 ";
-  }
-}
-
-
-void cAnalyze::WriteInjectEvents(cString cur_string)
-{
-  // Load in the variables...
-  cString filename("events_inj.cfg");
-  int start_cell = 0;
-  int lineage = 0;
-  if (cur_string.GetSize() != 0) filename = cur_string.PopWord();
-  if (cur_string.GetSize() != 0) start_cell = cur_string.PopWord().AsInt();
-  if (cur_string.GetSize() != 0) lineage = cur_string.PopWord().AsInt();
-  
-  ofstream & fp = data_file_manager.GetOFStream(filename);
-  
-  int org_count = 0;
-  tListIterator<cAnalyzeGenotype> batch_it(batch[cur_batch].List());
-  cAnalyzeGenotype * genotype = NULL;
-  while ((genotype = batch_it.Next()) != NULL) {
-    const int cur_count = genotype->GetNumCPUs();
-    org_count += cur_count;
-    const cGenome & genome = genotype->GetGenome();
-    
-    fp << "u 0 inject_sequence "
-      << genome.AsString() << " "
-      << start_cell << " "
-      << start_cell + cur_count << " "
-      << genotype->GetMerit() << " "
-      << lineage << " "
-      << endl;
-    start_cell += cur_count;
-  }
-}
-
-
-void cAnalyze::WriteCompetition(cString cur_string)
-{
-  cout << "Writing Competition events..." << endl;
-  
-  // Load in the variables...
-  int join_UD = 0;
-  double start_merit = 50000;
-  cString filename("events_comp.cfg");
-  int batch_A = cur_batch - 1;
-  int batch_B = cur_batch;
-  int grid_side = -1;
-  int lineage = 0;
-  
-  // Make sure we have reasonable default batches.
-  if (cur_batch == 0) { batch_A = 0; batch_B = 1; }
-  
-  if (cur_string.GetSize() != 0) join_UD = cur_string.PopWord().AsInt();
-  if (cur_string.GetSize() != 0) start_merit = cur_string.PopWord().AsDouble();
-  if (cur_string.GetSize() != 0) filename = cur_string.PopWord();
-  if (cur_string.GetSize() != 0) batch_A = cur_string.PopWord().AsInt();
-  if (cur_string.GetSize() != 0) batch_B = cur_string.PopWord().AsInt();
-  if (cur_string.GetSize() != 0) grid_side = cur_string.PopWord().AsInt();
-  if (cur_string.GetSize() != 0) lineage = cur_string.PopWord().AsInt();
-  
-  // Check inputs...
-  if (join_UD < 0) join_UD = 0;
-  if (batch_A < 0 || batch_B < 0) {
-    cerr << "Error: Batch IDs must be positive!" << endl;
-    return;
-  }
-  
-  ofstream & fp = data_file_manager.GetOFStream(filename);
-  
-  // Count the number of organisms in each batch...
-  cAnalyzeGenotype * genotype = NULL;
-  
-  int org_count_A = 0;
-  tListIterator<cAnalyzeGenotype> batchA_it(batch[batch_A].List());
-  while ((genotype = batchA_it.Next()) != NULL) {
-    org_count_A += genotype->GetNumCPUs();
-  }
-  
-  int org_count_B = 0;
-  tListIterator<cAnalyzeGenotype> batchB_it(batch[batch_B].List());
-  while ((genotype = batchB_it.Next()) != NULL) {
-    org_count_B += genotype->GetNumCPUs();
-  }
-  
-  int max_count = Max(org_count_A, org_count_B);
-  if (max_count > 10000) {
-    cout << "Warning: more than 10,000 organisms in sub-population!" << endl;
-  }
-  
-  if (grid_side <= 0) {
-    for (grid_side = 5; grid_side < 100; grid_side += 5) {
-      if (grid_side * grid_side >= max_count) break;
-    }
-    if (verbose == true) {
-      cout << "...assuming population size "
-      << grid_side << "x" << grid_side << "." << endl;
-    }
-  }
-  
-  
-  int pop_size = grid_side * grid_side;
-  
-  int inject_pos = 0;
-  while ((genotype = batchA_it.Next()) != NULL) {
-    const int cur_count = genotype->GetNumCPUs();
-    const cGenome & genome = genotype->GetGenome();
-    double cur_merit = start_merit;
-    if (cur_merit < 0) cur_merit = genotype->GetMerit();
-    fp << "u 0 inject_sequence "
-      << genome.AsString() << " "
-      << inject_pos << " "
-      << inject_pos + cur_count << " "
-      << cur_merit << " "
-      << lineage << " "
-      << endl;
-    inject_pos += cur_count;
-  }
-  
-  inject_pos = pop_size;
-  while ((genotype = batchB_it.Next()) != NULL) {
-    const int cur_count = genotype->GetNumCPUs();
-    const cGenome & genome = genotype->GetGenome();
-    double cur_merit = start_merit;
-    if (cur_merit < 0) cur_merit = genotype->GetMerit();
-    fp << "u 0 inject_sequence "
-      << genome.AsString() << " "
-      << inject_pos << " "
-      << inject_pos + cur_count << " "
-      << cur_merit << " "
-      << lineage+1 << " "
-      << endl;
-    inject_pos += cur_count;
-  }
-  
-  fp << "u 0 sever_grid_row" << grid_side << endl;
-  fp << "u " << join_UD << " join_grid_row " << grid_side << endl;
-}
-
-
-void cAnalyze::AnalyzeMuts(cString cur_string)
-{
-  cout << "Analyzing Mutations" << endl;
-  
-  // Make sure we have everything we need.
-  if (batch[cur_batch].IsAligned() == false) {
-    cout << "  Error: sequences not aligned." << endl;
-    return;
-  }
-  
-  // Setup variables...
-  cString filename("analyze_muts.dat");
-  bool all_combos = false;
-  if (cur_string.GetSize() != 0) filename = cur_string.PopWord();
-  if (cur_string.GetSize() != 0) all_combos = cur_string.PopWord().AsInt();
-  
-  tListPlus<cAnalyzeGenotype> & gen_list = batch[cur_batch].List();
-  tListIterator<cAnalyzeGenotype> batch_it(batch[cur_batch].List());
-  
-  const int num_sequences = gen_list.GetSize();
-  const int sequence_length =
-    gen_list.GetFirst()->GetAlignedSequence().GetSize();
-  cString * sequences = new cString[num_sequences];
-  int * mut_count = new int[sequence_length];
-  for (int i = 0; i < sequence_length; i++) mut_count[i] = 0;
-  
-  // Load in the sequences
-  batch_it.Reset();
-  int count = 0;
-  while (batch_it.Next() != NULL) {
-    sequences[count] = batch_it.Get()->GetAlignedSequence();
-    count++;
-  }
-  
-  // Count the number of changes at each site...
-  for (int i = 1; i < num_sequences; i++) {       // For each pair...
-    cString & seq1 = sequences[i-1];
-    cString & seq2 = sequences[i];
-    for (int j = 0; j < sequence_length; j++) {   // For each site...
-      if (seq1[j] != seq2[j]) mut_count[j]++;
-    }
-  }
-  
-  // Grab the two strings we're actively going to be working with.
-  cString & first_seq = sequences[0];
-  cString & last_seq = sequences[num_sequences - 1];
-  
-  // Print out the header...
-  ofstream & fp = data_file_manager.GetOFStream(filename);
-  fp << "# " << sequences[0] << endl;
-  fp << "# " << sequences[num_sequences - 1] << endl;
-  fp << "# ";
-  for (int i = 0; i < sequence_length; i++) {
-    if (mut_count[i] == 0) fp << " ";
-    else if (mut_count[i] > 9) fp << "+";
-    else fp << mut_count[i];
-  }
-  fp << endl;
-  fp << "# ";
-  for (int i = 0; i < sequence_length; i++) {
-    if (first_seq[i] == last_seq[i]) fp << " ";
-    else fp << "^";
-  }
-  fp << endl << endl;
-  
-  // Count the number of diffs between the two strings we're interested in.
-  const int total_diffs = cStringUtil::Distance(first_seq, last_seq);
-  if (verbose) cout << "  " << total_diffs << " mutations being tested."
-    << endl;
-  
-  // Locate each difference.
-  int * mut_positions = new int[total_diffs];
-  int cur_mut = 0;
-  for (int i = 0; i < first_seq.GetSize(); i++) {
-    if (first_seq[i] != last_seq[i]) {
-      mut_positions[cur_mut] = i;
-      cur_mut++;
-    }
-  }
-  
-  // The number of mutations we need to deal with will tell us how much
-  // we can attempt to do. (@CAO should be able to overide defaults)
-  bool scan_combos = true;  // Scan all possible combos of mutations?
-  bool detail_muts = true;  // Collect detailed info on all mutations?
-  bool print_all = true;    // Print everything we collect without digestion?
-  if (total_diffs > 30) scan_combos = false;
-  if (total_diffs > 20) detail_muts = false;
-  if (total_diffs > 10) print_all = false;
-  
-  // Start moving through the difference combinations...
-  if (scan_combos) {
-    const int total_combos = 1 << total_diffs;
-    cout << "  Scanning through " << total_combos << " combos." << endl;
-    
-    double * total_fitness = new double[total_diffs + 1];
-    double * total_sqr_fitness = new double[total_diffs + 1];
-    double * max_fitness = new double[total_diffs + 1];
-    cString * max_sequence = new cString[total_diffs + 1];
-    int * test_count = new int[total_diffs + 1];
-    for (int i = 0; i <= total_diffs; i++) {
-      total_fitness[i] = 0.0;
-      total_sqr_fitness[i] = 0.0;
-      max_fitness[i] = 0.0;
-      test_count[i] = 0;
-    }
-    
-    // Loop through all of the combos...
-    const int combo_step = total_combos / 79;
-    for (int combo_id = 0; combo_id < total_combos; combo_id++) {
-      if (combo_id % combo_step == 0) {
-        cout << '.';
-        cout.flush();
-      }
-      // Start at the first sequence and add needed changes...
-      cString test_sequence = first_seq;
-      int diff_count = 0;
-      for (int mut_id = 0; mut_id < total_diffs; mut_id++) {
-        if ((combo_id >> mut_id) & 1) {
-          const int cur_pos = mut_positions[mut_id];
-          test_sequence[cur_pos] = last_seq.GetData()[cur_pos];
-          diff_count++;
-        }
-      }
-      
-      // Determine the fitness of the current sequence...
-      cGenome test_genome(test_sequence);
-      cCPUTestInfo test_info;
-      test_info.TestThreads();
-      cTestCPU::TestGenome(test_info, test_genome);
-      const double fitness = test_info.GetGenotypeFitness();
-      
-      //cAnalyzeGenotype test_genotype(test_sequence);
-      //test_genotype.Recalculate();
-      //const double fitness = test_genotype.GetFitness();
-      
-      total_fitness[diff_count] += fitness;
-      total_sqr_fitness[diff_count] += fitness * fitness;
-      if (fitness > max_fitness[diff_count]) {
-        max_fitness[diff_count] = fitness;
-        max_sequence[diff_count] = test_sequence;
-        //  	cout << endl
-        //  	     << max_sequence[diff_count] << " "
-        //  	     << test_info.GetGenotypeMerit() << " "
-        //  	     << fitness << " "
-        //  	     << combo_id << endl;
-      }
-      test_count[diff_count]++;
-    }
-    
-    // Output the results...
-    
-    for (int i = 0; i <= total_diffs; i++) {
-      cAnalyzeGenotype max_genotype(max_sequence[i], inst_set);
-      max_genotype.Recalculate();
-      fp << i                                         << " "  //  1
-        << test_count[i]                             << " "  //  2
-        << total_fitness[i] / (double) test_count[i] << " "  //  3
-        << max_fitness[i]                            << " "  //  4
-        << max_genotype.GetMerit()                   << " "  //  5
-        << max_genotype.GetGestTime()                << " "  //  6
-        << max_genotype.GetLength()                  << " "  //  7
-        << max_genotype.GetCopyLength()              << " "  //  8
-        << max_genotype.GetExeLength()               << " "; //  9
-      max_genotype.PrintTasks(fp, 3,12);
-      fp << max_sequence[i] << endl;
-    }
-    
-    // Cleanup
-    delete [] total_fitness;
-    delete [] total_sqr_fitness;
-    delete [] max_fitness;
-    delete [] max_sequence;
-    delete [] test_count;
-  }
-  // If we can't scan through all combos, give wanring.
-  else {
-    cerr << "  Warning: too many mutations (" << total_diffs
-    << ") to scan through combos." << endl;
-  }
-  
-  
-  // Cleanup...
-  delete [] sequences;
-  delete [] mut_count;
-  delete [] mut_positions;
-}
-
-void cAnalyze::AnalyzeInstructions(cString cur_string)
-{
-  if (verbose == true) {
-    cout << "Analyzing Instructions in batch " << cur_batch << endl;
-  }
-  else cout << "Analyzeing Instructions..." << endl;
-  
-  // Load in the variables...
-  cString filename("inst_analyze.dat");
-  if (cur_string.GetSize() != 0) filename = cur_string.PopWord();
-  const int num_insts = inst_set.GetSize();
-  
-  // Setup the file...
-  ofstream fp(filename);
-  
-  // Determine the file type...
-  int file_type = FILE_TYPE_TEXT;
-  while (filename.Find('.') != -1) filename.Pop('.');
-  if (filename == "html") file_type = FILE_TYPE_HTML;
-  
-  // If we're in HTML mode, setup the header...
-  if (file_type == FILE_TYPE_HTML) {
-    // Document header...
-    fp << "<html>" << endl
-    << "<body bgcolor=\"#FFFFFF\"" << endl
-    << " text=\"#000000\"" << endl
-    << " link=\"#0000AA\"" << endl
-    << " alink=\"#0000FF\"" << endl
-    << " vlink=\"#000044\">" << endl
-    << endl
-    << "<h1 align=center>Instruction Chart: "
-    << batch[cur_batch].Name() << endl
-    << "<br><br>" << endl
-    << endl;
-    
-    // Instruction key...
-    const int num_cols = 6;
-    const int num_rows = ((num_insts - 1) / num_cols) + 1;
-    fp << "<table border=2 cellpadding=3>" << endl
-      << "<tr bgcolor=\"#AAAAFF\"><th colspan=6>Instruction Set Legend</tr>"
-      << endl;
-    for (int i = 0; i < num_rows; i++) {
-      fp << "<tr>";
-      for (int j = 0; j < num_cols; j++) {
-        const int inst_id = i + j * num_rows;
-        if (inst_id < num_insts) {
-          cInstruction cur_inst(inst_id);
-          fp << "<td><b>" << cur_inst.GetSymbol() << "</b> : "
-            << inst_set.GetName(inst_id) << " ";
-        }
-        else {
-          fp << "<td>&nbsp; ";
-        }
-      }
-      fp << "</tr>" << endl;
-    }
-    fp << "</table>" << endl
-      << "<br><br><br>" << endl;
-    
-    // Main table header...
-    fp << "<center>" << endl
-      << "<table border=1 cellpadding=2>" << endl
-      << "<tr><th bgcolor=\"#AAAAFF\">Run # <th bgcolor=\"#AAAAFF\">Length"
-      << endl;
-    for (int i = 0; i < num_insts; i++) {
-      cInstruction cur_inst(i);
-      fp << "<th bgcolor=\"#AAAAFF\">" << cur_inst.GetSymbol() << " ";
-    }
-    fp << "</tr>" << endl;
-  }
-  else { // if (file_type == FILE_TYPE_TEXT) {
-    fp << "#RUN_NAME  LENGTH  ";
-    for (int i = 0; i < num_insts; i++) {
-      cInstruction cur_inst(i);
-      fp << cur_inst.GetSymbol() << ":" << inst_set.GetName(i) << " ";
-    }
-    fp << endl;
-  }
-  
-  // Figure out how often we expect each instruction to appear...
-  const double exp_freq = 1.0 / (double) num_insts;
-  const double min_freq = exp_freq * 0.5;
-  const double max_freq = exp_freq * 2.0;
-  
-  double total_length = 0.0;
-  tArray<double> total_freq(num_insts);
-  for (int i = 0; i < num_insts; i++) total_freq[i] = 0.0;
-  
-  // Loop through all of the genotypes in this batch...
-  tListIterator<cAnalyzeGenotype> batch_it(batch[cur_batch].List());
-  cAnalyzeGenotype * genotype = NULL;
-  while ((genotype = batch_it.Next()) != NULL) {
-    // Setup for counting...
-    tArray<int> inst_bin(num_insts);
-    for (int i = 0; i < num_insts; i++) inst_bin[i] = 0;
-    
-    // Count it up!
-    const int genome_size = genotype->GetLength();
-    for (int i = 0; i < genome_size; i++) {
-      const int inst_id = genotype->GetGenome()[i].GetOp();
-      inst_bin[inst_id]++;
-    }
-    
-    // Print it out...
-    if (file_type == FILE_TYPE_HTML) fp << "<tr><th>";
-    fp << genotype->GetName() << " ";
-    if (file_type == FILE_TYPE_HTML) fp << "<td align=center>";
-    total_length += genome_size;
-    fp << genome_size << " ";
-    for (int i = 0; i < num_insts; i++) {
-      const double inst_freq = ((double) inst_bin[i]) / (double) genome_size;
-      total_freq[i] += inst_freq;
-      if (file_type == FILE_TYPE_HTML) {
-        if (inst_freq == 0.0) fp << "<td bgcolor=\"FFAAAA\">";
-        else if (inst_freq < min_freq) fp << "<td bgcolor=\"FFFFAA\">";
-        else if (inst_freq < max_freq) fp << "<td bgcolor=\"AAAAFF\">";
-        else fp << "<td bgcolor=\"AAFFAA\">";
-      }
-      fp << cStringUtil::Stringf("%04.3f", inst_freq) << " ";
-    }
-    if (file_type == FILE_TYPE_HTML) fp << "</tr>";
-    fp << endl;
-  }
-  
-  if (file_type == FILE_TYPE_HTML) {
-    int num_genomes = batch[cur_batch].List().GetSize();
-    fp << "<tr><th>Average <th>" << total_length / num_genomes << " ";
-    for (int i = 0; i < num_insts; i++) {
-      double inst_freq = total_freq[i] / num_genomes;
-      if (inst_freq == 0.0) fp << "<td bgcolor=\"FF0000\">";
-      else if (inst_freq < min_freq) fp << "<td bgcolor=\"FFFF00\">";
-      else if (inst_freq < max_freq) fp << "<td bgcolor=\"0000FF\">";
-      else fp << "<td bgcolor=\"00FF00\">";
-      fp << cStringUtil::Stringf("%04.3f", inst_freq) << " ";
-    }
-    fp << "</tr>" << endl
-      << "</table></center>" << endl;
-  }
-  }
-
-void cAnalyze::AnalyzeInstPop(cString cur_string)
-{
-  if (verbose == true) {
-    cout << "Analyzing Instructions in batch " << cur_batch << endl;
-  }
-  else cout << "Analyzeing Instructions..." << endl;
-  
-  // Load in the variables...
-  cString filename("inst_analyze.dat");
-  if (cur_string.GetSize() != 0) filename = cur_string.PopWord();
-  const int num_insts = inst_set.GetSize();
-  
-  // Setup the file...
-  ofstream fp(filename);
-  
-  for (int i = 0; i < num_insts; i++) {
-    cInstruction cur_inst(i);
-    fp << cur_inst.GetSymbol() << ":" << inst_set.GetName(i) << " ";
-  }
-  fp << endl;
-  
-  double total_length = 0.0;
-  tArray<double> total_freq(num_insts);
-  for (int i = 0; i < num_insts; i++) total_freq[i] = 0.0;
-  int num_orgs = 0; 
-  
-  // Loop through all of the genotypes in this batch...
-  tListIterator<cAnalyzeGenotype> batch_it(batch[cur_batch].List());
-  cAnalyzeGenotype * genotype = NULL;
-  while ((genotype = batch_it.Next()) != NULL) {
-    
-    num_orgs++; 
-    
-    // Setup for counting...
-    tArray<int> inst_bin(num_insts);
-    for (int i = 0; i < num_insts; i++) inst_bin[i] = 0;
-    
-    // Count it up!
-    const int genome_size = genotype->GetLength();
-    for (int i = 0; i < genome_size; i++) {
-      const int inst_id = genotype->GetGenome()[i].GetOp();
-      inst_bin[inst_id]++;
-    }
-    total_length += genome_size;
-    for (int i = 0; i < num_insts; i++) {
-      const double inst_freq = ((double) inst_bin[i]) / (double) genome_size;
-      total_freq[i] += inst_freq;
-    }
-  }
-  // Print it out...
-  //    fp << total_length/num_orgs  << " ";
-  for (int i = 0; i < num_insts; i++) {
-    fp << cStringUtil::Stringf("%04.3f", total_freq[i]/num_orgs) << " ";
-  }
-  fp << endl;
-  
-}
-
-void cAnalyze::AnalyzeBranching(cString cur_string)
-{
-  if (verbose == true) {
-    cout << "Analyzing branching patterns in batch " << cur_batch << endl;
-  }
-  else cout << "Analyzeing Branches..." << endl;
-  
-  // Load in the variables...
-  cString filename("branch_analyze.dat");
-  if (cur_string.GetSize() != 0) filename = cur_string.PopWord();
-  
-  // Setup the file...
-  ofstream fp(filename);
-  
-  // UNFINISHED!
-  // const int num_insts = inst_set.GetSize();
-}
-
-void cAnalyze::AnalyzeMutationTraceback(cString cur_string)
-{
-  if (verbose == true) {
-    cout << "Analyzing mutation traceback in batch " << cur_batch << endl;
-  }
-  else cout << "Analyzing mutation traceback..." << endl;
-  
-  // This works best on lineages, so warn if we don't have one.
-  if (batch[cur_batch].IsLineage() == false && verbose == true) {
-    cerr << "  Warning: trying to traceback mutations outside of lineage."
-    << endl;
-  }
-  
-  if (batch[cur_batch].List().GetSize() == 0) {
-    cerr << "Error: Trying to traceback mutations with no genotypes in batch."
-    << endl;
-    return;
-  }
-  
-  // Make sure all genotypes are the same length.
-  int size = -1;
-  tListIterator<cAnalyzeGenotype> batch_it(batch[cur_batch].List());
-  cAnalyzeGenotype * genotype = NULL;
-  while ((genotype = batch_it.Next()) != NULL) {
-    if (size == -1) size = genotype->GetLength();
-    if (size != genotype->GetLength()) {
-      cerr << "  Error: Trying to traceback mutations in genotypes of differing lengths." << endl;
-      cerr << "  Aborting." << endl;
-      return;
-    }
-  }
-  
-  // Setup variables...
-  cString filename("analyze_traceback.dat");
-  if (cur_string.GetSize() != 0) filename = cur_string.PopWord();
-  
-  // Setup a genome to store the previous values before mutations.
-  tArray<int> prev_inst(size);
-  prev_inst.SetAll(-1);  // -1 indicates never changed.
-  
-  // Open the output file...
-  ofstream fp(filename);
-  
-  // Loop through all of the genotypes again, testing mutation reversions.
-  cAnalyzeGenotype * prev_genotype = batch_it.Next();
-  while ((genotype = batch_it.Next()) != NULL) {
-    continue;
-    // Check to see if any sites have changed...
-    for (int i = 0; i < size; i++) {
-      if (genotype->GetGenome()[i] != prev_genotype->GetGenome()[i]) {
-        prev_inst[i] = prev_genotype->GetGenome()[i].GetOp();
-      }
-    }
-    
-    // Next, determine the fraction of mutations that are currently adaptive.
-    int num_beneficial = 0;
-    int num_neutral = 0;
-    int num_detrimental = 0;
-    int num_static = 0;      // Sites that were never mutated.
-    
-    cGenome test_genome = genotype->GetGenome();
-    cCPUTestInfo test_info;
-    cTestCPU::TestGenome(test_info, test_genome);
-    const double base_fitness = test_info.GetGenotypeFitness();
-    
-    for (int i = 0; i < size; i++) {
-      if (prev_inst[i] == -1) num_static++;
-      else {
-        test_genome[i].SetOp(prev_inst[i]);
-        cTestCPU::TestGenome(test_info, test_genome);
-        const double cur_fitness = test_info.GetGenotypeFitness();
-        if (cur_fitness > base_fitness) num_detrimental++;
-        else if (cur_fitness < base_fitness) num_beneficial++;
-        else num_neutral++;
-        test_genome[i] = genotype->GetGenome()[i];
-      }      
-    }
-    
-    fp << genotype->GetDepth() << " "
-      << num_beneficial << " "
-      << num_neutral << " "
-      << num_detrimental << " "
-      << num_static << " "
-      << endl;
-    
-    prev_genotype = genotype;
-  }
-}
-
-void cAnalyze::AnalyzeComplexity(cString cur_string)
-{
-  cout << "Analyzing genome complexity..." << endl;
-  
-  // Load in the variables...
-  // This command requires at least on arguement
-  int words = cur_string.CountNumWords();
-  if(words < 1) {
-    cout << "AnalyzeComplexity has no parameters, skipping." << endl;
-    return;
-  }
-  
-  // Get the mutation rate arguement
-  double mut_rate = cur_string.PopWord().AsDouble();
-  
-  // Create the directory using the string given as the second arguement
-  cString dir = cur_string.PopWord();
-  cString defaultDirectory = "complexity/";
-  cString directory = PopDirectory(dir, defaultDirectory);
-  
-  // Default for usage of resources is false
-  int useResources = 0;
-  // resource usage flag is an optional arguement, but is always the 3rd arg
-  if(words >= 3) {
-    useResources = cur_string.PopWord().AsInt();
-    // All non-zero values are considered false
-    if(useResources != 0 && useResources != 1) {
-      useResources = 0;
-    }
-  }
-  
-  // Batch frequency begins with the first organism, but then skips that 
-  // amount ahead in the batch.  It defaults to 1, so that default analyzes
-  // all the organisms in the batch.  It is always the 4th arg.
-  int batchFrequency = 1;
-  if(words == 4) {
-    batchFrequency = cur_string.PopWord().AsInt();
-    if(batchFrequency <= 0) {
-      batchFrequency = 1;
-    }
-  }
-  
-  // These are used to backup the state of the environment and resource_count
-  // for the test cpu, and will be reset to their original values at the end
-  bool backupUsage;
-  tArray<double> backupResources;
-  
-  if(useResources) {
-    // Backup test cpu data
-    backupUsage = cTestCPU::UseResources();
-    backupResources = cTestCPU::GetResources();
-    
-    cTestCPU::UseResources() = true;
-  }
-  
-  ///////////////////////////////////////////////////////
-  // Loop through all of the genotypes in this batch...
-  
-  tListIterator<cAnalyzeGenotype> batch_it(batch[cur_batch].List());
-  cAnalyzeGenotype * genotype = NULL;
-  
-  
-  bool islineage = false;
-  cString lineage_filename;
-  ofstream lineage_fp;
-  ofstream non_lineage_fp;
-  if (batch[cur_batch].IsLineage() == true) {
-    lineage_filename.Set("%s%s.complexity.dat", directory(), "lineage");
-    lineage_fp.open(lineage_filename);
-    islineage = true;
-  } else {
-    cString non_lineage_file;
-    non_lineage_file.Set("%s%s.complexity.dat", directory(), "nonlineage");
-    non_lineage_fp.open(non_lineage_file);
-    islineage = false;
-  }
-  
-  while ((genotype = batch_it.Next()) != NULL) {
-    if (verbose == true) {
-      cout << "  Analyzing complexity for " << genotype->GetName() << endl;
-    }
-    
-    // Construct this filename...
-    cString filename;
-    filename.Set("%s%s.complexity.dat", directory(), genotype->GetName()());
-    ofstream fp(filename());
-    if (islineage) {
-      lineage_fp << genotype->GetID() << " ";
-    } else {
-      non_lineage_fp << genotype->GetID() << " ";
-    }
-    
-    int updateBorn = -1;
-    if(useResources) {
-      updateBorn = genotype->GetUpdateBorn();
-      FillResources(updateBorn);
-    }
-    
-    // Calculate the stats for the genotype we're working with ...
-    genotype->Recalculate();
-    cout << genotype->GetFitness() << endl;
-    const int num_insts = inst_set.GetSize();
-    const int max_line = genotype->GetLength();
-    const cGenome & base_genome = genotype->GetGenome();
-    cGenome mod_genome(base_genome);
-    
-    // Loop through all the lines of code, testing all mutations...
-    tArray<double> test_fitness(num_insts);
-    tArray<double> prob(num_insts);
-    for (int line_num = 0; line_num < max_line; line_num++) {
-      int cur_inst = base_genome[line_num].GetOp();
-      //char cur_symbol = base_genome[line_num].GetSymbol();
-      
-      // Column 1 ... the original instruction in the genome.
-      fp << cur_inst << " ";
-      
-      // Test fitness of each mutant.
-      for (int mod_inst = 0; mod_inst < num_insts; mod_inst++) {
-        mod_genome[line_num].SetOp(mod_inst);
-        cAnalyzeGenotype test_genotype(mod_genome, inst_set);
-        test_genotype.Recalculate();
-        test_fitness[mod_inst] = test_genotype.GetFitness();
-      }
-      
-      // Ajust fitness
-      double cur_inst_fitness = test_fitness[cur_inst];
-      for (int mod_inst = 0; mod_inst < num_insts; mod_inst++) {
-        if (test_fitness[mod_inst] > cur_inst_fitness)
-          test_fitness[mod_inst] = cur_inst_fitness;
-        test_fitness[mod_inst] = test_fitness[mod_inst] / cur_inst_fitness;
-      }
-      
-      // Calculate probabilities at mut-sel balance
-      double w_bar = 1;
-      
-      // Normalize fitness values, assert if they are all zero
-      double maxFitness = 0.0;
-      for(int i=0; i<num_insts; i++) {
-        if(test_fitness[i] > maxFitness) {
-          maxFitness = test_fitness[i];
-        }
-      }
-      
-      if(maxFitness > 0) {
-        for(int i=0; i<num_insts; i++) {
-          test_fitness[i] /= maxFitness;
-        }
-      } else {
-        fp << "All zero fitness, ERROR." << endl;
-        continue;
-      }
-      
-      while(1) {
-        double sum = 0.0;
-        for (int mod_inst = 0; mod_inst < num_insts; mod_inst ++) {
-          prob[mod_inst] = (mut_rate * w_bar) /
-          ((double)num_insts * (w_bar + test_fitness[mod_inst] * mut_rate - test_fitness[mod_inst]));
-          sum = sum + prob[mod_inst];
-        }
-        if ((sum-1.0)*(sum-1.0) <= 0.0001) 
-          break;
-        else
-          w_bar = w_bar - 0.000001;
-      }
-      // Write probability
-      for (int mod_inst = 0; mod_inst < num_insts; mod_inst ++) {
-        fp << prob[mod_inst] << " ";
-      }
-      
-      // Calculate complexity
-      double entropy = 0;
-      for (int i = 0; i < num_insts; i ++) {
-        entropy += prob[i] * log((double) 1.0/prob[i]) / log ((double) num_insts);
-      }
-      double complexity = 1 - entropy;
-      fp << complexity << endl;
-      
-      if (islineage) {
-        lineage_fp << complexity << " ";
-      } else {
-        non_lineage_fp << complexity << " ";
-      }
-      
-      // Reset the mod_genome back to the original sequence.
-      mod_genome[line_num].SetOp(cur_inst);
-    }
-    fp.close();
-    if (islineage) {
-      lineage_fp << endl;
-    } else {
-      non_lineage_fp << endl;
-    }
-    
-    // Always grabs the first one
-    // Skip i-1 times, so that the beginning of the loop will grab the ith one
-    // where i is the batchFrequency
-    for(int count=0; genotype != NULL && count < batchFrequency - 1; count++) {
-      genotype = batch_it.Next();
-      if(genotype != NULL && verbose == true) {
-        cout << "Skipping: " << genotype->GetName() << endl;
-      }
-    }
-    if(genotype == NULL) { break; }
-  }
-  if (islineage) {
-    lineage_fp.close();
-  } else {
-    non_lineage_fp.close();
-  }
-  
-  if(useResources) {
-    // Set the test cpu back to the state it was in before we messed with it
-    cTestCPU::UseResources() = backupUsage;
-    cTestCPU::SetupResourceArray(backupResources);
-  }
-  
-  return;
-}
-
-void cAnalyze::AnalyzePopComplexity(cString cur_string)
-{
-  cout << "Analyzing population complexity ..." << endl;
-  
-  // Load in the variables...
-  //int batch_size = cur_string.PopWord().AsInt();
-  //int sample_size = cur_string.PopWord().AsInt();
-  cString directory = PopDirectory(cur_string, "pop_complexity/");
-  cString file = cur_string;
-  
-  // Get sample index...
-  /*if (sample_size > batch_size) {
-    cout << " Sample size is greater than batch size." << endl;
-  return;
-  }
-int *index_array;
-int *flag_array;
-index_array = (int*) malloc (batch_size*sizeof(int));
-flag_array = (int*) malloc (batch_size*sizeof(int));
-for (int i=0; i<batch_size; i++) {
-  index_array[i] = i;
-  flag_array[i] = 0;
-}
-int max_num = batch_size;
-cRandom random;
-for (int i=0; i<sample_size; i++) {
-  int index = random.GetUInt(max_num);
-  flag_array[index_array[index]] = 1;
-  index_array[index] = index_array[max_num-1];
-  max_num--;
-}*/
-  
-  // Construct filename...
-  cString filename;
-  filename.Set("%spop%s.complexity.dat", directory(), file());
-  ofstream fp(filename());
-  
-  //////////////////////////////////////////////////////////
-  // Loop through all of the genotypes in this batch ...
-  
-  tListIterator<cAnalyzeGenotype> batch_it(batch[cur_batch].List());
-  cAnalyzeGenotype * genotype = NULL;
-  
-  
-  genotype = batch_it.Next();
-  
-  
-  if (genotype == NULL) return;
-  int seq_length = genotype->GetLength();
-  const int num_insts = inst_set.GetSize();
-  tMatrix<int> inst_stat(seq_length, num_insts);
-  
-  // Initializing inst_stat ...
-  for (int line_num = 0; line_num < seq_length; line_num ++) 
-    for (int inst_num = 0; inst_num < num_insts; inst_num ++) 
-      inst_stat(line_num, inst_num) = 0;
-
-  int num_cpus = 0;
-  int actural_samples = 0;
-  while (genotype != NULL) {
-    num_cpus = genotype->GetNumCPUs();
-    const cGenome & base_genome = genotype->GetGenome();
-    for (int i=0; i<num_cpus; i++) {   // Stat on every organism with same genotype.
-                                       //if (flag_array[organism_index] == 0) {
-                                       //organism_index++;
-                                       //continue;
-                                       //}
-      for (int line_num = 0; line_num < seq_length; line_num ++) {
-        int cur_inst = base_genome[line_num].GetOp();
-        inst_stat(line_num, cur_inst) ++;
-      }
-      //organism_index++;
-      actural_samples++;
-    }
-    genotype = batch_it.Next();
-  }
-
-
-
-// Calculate complexity
-for (int line_num = 0; line_num < seq_length; line_num ++) {
-  double entropy = 0.0;
-  for (int inst_num = 0; inst_num < num_insts; inst_num ++) {
-    if (inst_stat(line_num, inst_num) == 0) continue;
-    float prob = (float) (inst_stat(line_num, inst_num)) / (float) (actural_samples);
-    entropy += prob * log((double) 1.0/prob) / log((double) num_insts);
-  }
-  double complexity = 1 - entropy;
-  fp << complexity << " ";
-};
-fp << endl;
-fp.close();
-//free(index_array);
-//free(flag_array);
-return;
-}
-
-
-void cAnalyze::EnvironmentSetup(cString cur_string)
-{
-  cout << "Running environment command: " << endl
-  << "  " << cur_string << endl;
-  
-  cTestCPU::GetEnvironment()->LoadLine(cur_string);
-}
-
-
-void cAnalyze::CommandHelpfile(cString cur_string)
-{
-  cout << "Printing helpfiles in: " << cur_string << endl;
-  
-  cHelpManager help_control;
-  if (verbose == true) help_control.SetVerbose();
-  while (cur_string.GetSize() > 0) {
-    help_control.LoadFile(cur_string.PopWord());
-  }
-  
-  help_control.PrintHTML();
-}
-
-void cAnalyze::CommandDocfile(cString cur_string)
-{
-  cout << "Printing documentation files in: " << cur_string << endl;
-  
-  cHelpManager help_control;
-  if (verbose == true) help_control.SetVerbose();
-  while (cur_string.GetSize() > 0) {
-    help_control.LoadFile(cur_string.PopWord());
-  }
-  
-  help_control.PrintHTML();
-}
-
-
-
-//////////////// Control...
-
-void cAnalyze::VarSet(cString cur_string)
-{
-  cString var = cur_string.PopWord();
-  
-  if (cur_string.GetSize() == 0) {
-    cerr << "Error: No variable provided in SET command" << endl;
-    return;
-  }
-  
-  cString & cur_variable = GetVariable(var);
-  cur_variable = cur_string.PopWord();
-  
-  if (verbose == true) {
-    cout << "Setting " << var << " to " << cur_variable << endl;
-  }
-}
-
-void cAnalyze::BatchSet(cString cur_string)
-{
-  int next_batch = 0;
-  if (cur_string.CountNumWords() > 0) {
-    next_batch = cur_string.PopWord().AsInt();
-  }
-  if (verbose) cout << "Setting current batch to " << next_batch << endl;
-  if (next_batch >= MAX_BATCHES) {
-    cerr << "  Error: max batches is " << MAX_BATCHES << endl;
-    exit(1);
-  } else {
-    cur_batch = next_batch;
-  }
-}
-
-void cAnalyze::BatchName(cString cur_string)
-{
-  if (cur_string.CountNumWords() == 0) {
-    if (verbose) cout << "  Warning: No name given in NAME_BATCH!" << endl;
-    return;
-  }
-  
-  batch[cur_batch].Name() = cur_string.PopWord();
-}
-
-void cAnalyze::BatchTag(cString cur_string)
-{
-  if (cur_string.CountNumWords() == 0) {
-    if (verbose) cout << "  Warning: No tag given in TAG_BATCH!" << endl;
-    return;
-  }
-  
-  if (verbose == true) {
-    cout << "Tagging batch " << cur_batch
-    << " with tag '" << cur_string << "'" << endl;
-  }
-  
-  tListIterator<cAnalyzeGenotype> batch_it(batch[cur_batch].List());
-  cAnalyzeGenotype * genotype = NULL;
-  while ((genotype = batch_it.Next()) != NULL) {
-    genotype->SetTag(cur_string);
-  }
-  
-}
-
-void cAnalyze::BatchPurge(cString cur_string)
-{
-  int batch_id = cur_batch;
-  if (cur_string.CountNumWords() > 0) batch_id = cur_string.PopWord().AsInt();
-  
-  if (verbose) cout << "Purging batch " << batch_id << endl;
-  
-  while (batch[batch_id].List().GetSize() > 0) {
-    delete batch[batch_id].List().Pop();
-  }
-  
-  batch[batch_id].SetLineage(false);
-  batch[batch_id].SetAligned(false);
-}
-
-void cAnalyze::BatchDuplicate(cString cur_string)
-{
-  if (cur_string.GetSize() == 0) {
-    cerr << "Duplicate Error: Must include from ID!" << endl;
-    exit(1);
-  }
-  int batch_from = cur_string.PopWord().AsInt();
-  
-  int batch_to = cur_batch;
-  if (cur_string.GetSize() > 0) batch_to = cur_string.PopWord().AsInt();
-  
-  if (verbose == true) {
-    cout << "Duplicating from batch " << batch_from
-    << " to batch " << batch_to << "." << endl;
-  }
-  
-  tListIterator<cAnalyzeGenotype> batch_from_it(batch[batch_from].List());
-  cAnalyzeGenotype * genotype = NULL;
-  while ((genotype = batch_from_it.Next()) != NULL) {
-    cAnalyzeGenotype * new_genotype = new cAnalyzeGenotype(*genotype);
-    batch[batch_to].List().PushRear(new_genotype);
-  }
-  
-  batch[batch_to].SetLineage(false);
-  batch[batch_to].SetAligned(false);
-}
-
-void cAnalyze::BatchRecalculate(cString cur_string)
-{
-  int words = cur_string.CountNumWords();
-  int useResources = 0;
-  int update = -1;
-  if(words >= 1) {
-    useResources = cur_string.PopWord().AsInt();
-    // All non-zero values are considered false
-    if(useResources != 0 && useResources != 1) {
-      useResources = 0;
-    }
-  }
-  if (words >= 2) {
-    update = cur_string.PopWord().AsInt();
-  }
-  
-  bool backupUsage;
-  tArray<double> backupResources;
-  
-  if(useResources) {
-    // Backup test cpu data
-    backupUsage = cTestCPU::UseResources();
-    backupResources = cTestCPU::GetResources();
-    
-    cTestCPU::UseResources() = true;
-  }
-  
-  if (verbose == true) {
-    cout << "Running batch " << cur_batch << " through test CPUs..." << endl;
-  } else cout << "Running through test CPUs..." << endl;
-  
-  if (verbose == true && batch[cur_batch].IsLineage() == false) {
-    cerr << "  Warning: batch may not be a linege; "
-    << "parent and ancestor distances may not be correct" << endl;
-  }
-  
-  if (useResources && update > -1) {
-    FillResources(update);
-  }
-
-  tListIterator<cAnalyzeGenotype> batch_it(batch[cur_batch].List());
-  cAnalyzeGenotype * genotype = NULL;
-  cAnalyzeGenotype * last_genotype = NULL;
-  while ((genotype = batch_it.Next()) != NULL) {
-    
-    // If use resources, load proper resource according to update_born
-    if(useResources && update == -1) {
-      int updateBorn = -1;
-      updateBorn = genotype->GetUpdateBorn();
-      FillResources(updateBorn);
-    }
-    
-    // If the previous genotype was the parent of this one, pass in a pointer
-    // to it for improved recalculate (such as distance to parent, etc.)
-//     if (verbose == true) {
-//       PrintTestCPUResources("");
-//     }
-    if (last_genotype != NULL &&
-        genotype->GetParentID() == last_genotype->GetID()) {
-      genotype->Recalculate(last_genotype);
-    }
-    else genotype->Recalculate();
-    last_genotype = genotype;
-  }
-  
-  if(useResources) {
-    // Set the test cpu back to the state it was in before we messed with it
-    cTestCPU::UseResources() = backupUsage;
-    cTestCPU::SetupResourceArray(backupResources);
-  }
-  
-  return;
-}
-
-void cAnalyze::BatchRename(cString cur_string)
-{
-  if (verbose == false) cout << "Renaming organisms..." << endl;
-  else cout << "Renaming organisms in batch " << cur_batch << endl;
-  
-  // If a number is given with rename, start at that number...
-  
-  int id_num = cur_string.PopWord().AsInt();
-  tListIterator<cAnalyzeGenotype> batch_it(batch[cur_batch].List());
-  cAnalyzeGenotype * genotype = NULL;
-  while ((genotype = batch_it.Next()) != NULL) {
-    cString name = cStringUtil::Stringf("org-%d", id_num);
-    genotype->SetID(id_num);
-    genotype->SetName(name);
-    id_num++;
-  }
-}
-
-void cAnalyze::PrintStatus(cString cur_string)
-{
-  // No Args needed...
-  (void) cur_string;
-  
-  cout << "Status Report:" << endl;
-  for (int i = 0; i < MAX_BATCHES; i++) {
-    if (i == cur_batch || batch[i].List().GetSize() > 0) {
-      cout << "  Batch " << i << " -- "
-      << batch[i].List().GetSize() << " genotypes.";
-      if (i == cur_batch) cout << "  <current>";
-      if (batch[i].IsLineage() == true) cout << "  <lineage>";
-      if (batch[i].IsAligned() == true) cout << "  <aligned>";
-      
-      cout << endl;
-    }
-  }
-}
-
-void cAnalyze::PrintDebug(cString cur_string)
-{
-  cerr << "Debug Args: " << cur_string << endl;
-}
-
-void cAnalyze::ToggleVerbose(cString cur_string)
-{
-  // No Args needed...
-  (void) cur_string;
-  
-  if (verbose == false) {
-    cout << "Using verbose log messages..." << endl;
-    verbose = true;
-  } else {
-    cout << "Using non-verbose log messages..." << endl;
-    verbose = false;
-  }
-}
-
-void cAnalyze::IncludeFile(cString cur_string)
-{
-  while (cur_string.GetSize() > 0) {
-    cString filename = cur_string.PopWord();
-    
-    cInitFile include_file(filename);
-    include_file.Load();
-    include_file.Compress();
-    include_file.Close();
-    
-    tList<cAnalyzeCommand> include_list;
-    LoadCommandList(include_file, include_list);
-    ProcessCommands(include_list);
-  }
-}
-
-void cAnalyze::CommandSystem(cString cur_string)
-{
-  cout << "Running System Command: " << cur_string << endl;
-  
-  system(cur_string());
-}
-
-void cAnalyze::CommandInteractive(cString cur_string)
-{
-  // No Args needed...
-  (void) cur_string;
-  
-  RunInteractive();
-}
-
-void cAnalyze::PrintTestCPUResources(cString cur_string)
-{
-  cout << "TestCPU is using resources: ";
-  cout << cTestCPU::UseResources() << endl;
-  cout << "Resources currently in TestCPU: ";
-  const tArray<double> &quantity = cTestCPU::GetResources();
-  for(int i=0; i<quantity.GetSize(); i++) {
-    cout << quantity.ElementAt(i) << " ";
-  }
-  cout << endl;
-  
-  return;
-}
-
-void cAnalyze::FunctionCreate(cString cur_string,
-                              tList<cAnalyzeCommand> & clist)
-{
-  int num_args = cur_string.CountNumWords();
-  if (num_args < 1) {
-    cerr << "Error: Must provide function name when creating function.";
-    exit(1);
-  }
-  
-  cString fun_name = cur_string.PopWord();
-  fun_name.ToUpper();
-  
-  if (FindAnalyzeCommandDef(fun_name) != NULL) {
-    cerr << "Error: Cannot create function '" << fun_name
-    << "'; already exists." << endl;
-    exit(1);
-  }
-  
-  if (verbose) cout << "Creating function: " << fun_name << endl;
-  
-  // Create the new function...
-  cAnalyzeFunction * new_function = new cAnalyzeFunction(fun_name);
-  while (clist.GetSize() > 0) {
-    new_function->GetCommandList()->PushRear(clist.Pop());
-  }
-  
-  // Save the function on the new list...
-  function_list.PushRear(new_function);
-}
-
-bool cAnalyze::FunctionRun(const cString & fun_name, cString args)
-{
-  if (verbose) {
-    cout << "Running function: " << fun_name << endl;
-    // << " with args: " << args << endl;
-  }
-  
-  // Find the function we're about to run...
-  cAnalyzeFunction * found_function = NULL;
-  tListIterator<cAnalyzeFunction> function_it(function_list);
-  while (function_it.Next() != NULL) {
-    if (function_it.Get()->GetName() == fun_name) {
-      found_function = function_it.Get();
-      break;
-    }
-  }
-  
-  // If we were unable to find the command we're looking for, return false.
-  if (found_function == NULL) return false;
-  
-  // Back up the local variables
-  cString backup_arg_vars[10];
-  cString backup_local_vars[26];
-  for (int i = 0; i < 10; i++) backup_arg_vars[i] = arg_variables[i];
-  for (int i = 0; i < 26; i++) backup_local_vars[i] = local_variables[i];
-  
-  // Set the arg variables to the passed-in args...
-  arg_variables[0] = fun_name;
-  for (int i = 1; i < 10; i++) arg_variables[i] = args.PopWord();
-  for (int i = 0; i < 26; i++) local_variables[i] = "";
-  
-  ProcessCommands(*(found_function->GetCommandList()));
-  
-  // Restore the local variables
-  for (int i = 0; i < 10; i++) arg_variables[i] = backup_arg_vars[i];
-  for (int i = 0; i < 26; i++) local_variables[i] = backup_local_vars[i];
-  
-  return true;
-}
-
-
-int cAnalyze::BatchUtil_GetMaxLength(int batch_id)
-{
-  if (batch_id < 0) batch_id = cur_batch;
-  
-  int max_length = 0;
-  
-  tListIterator<cAnalyzeGenotype> batch_it(batch[batch_id].List());
-  cAnalyzeGenotype * genotype = NULL;
-  while ((genotype = batch_it.Next()) != NULL) {
-    if (genotype->GetLength() > max_length) max_length = genotype->GetLength();
-  }
-  
-  return max_length;
-}
-
-
-void cAnalyze::CommandForeach(cString cur_string,
-                              tList<cAnalyzeCommand> & clist)
-{
-  if (verbose) cout << "Initiating Foreach loop..." << endl;
-  
-  cString var = cur_string.PopWord();
-  int num_args = cur_string.CountNumWords();
-  
-  cString & cur_variable = GetVariable(var);
-  
-  for (int i = 0; i < num_args; i++) {
-    cur_variable = cur_string.PopWord();
-    
-    if (verbose == true) {
-      cout << "Foreach: setting " << var << " to " << cur_variable << endl;
-    }
-    ProcessCommands(clist);
-  }
-  
-  if (verbose == true) {
-    cout << "Ending Foreach on " << var << endl;
-  }
-}
-
-
-void cAnalyze::CommandForRange(cString cur_string,
-                               tList<cAnalyzeCommand> & clist)
-{
-  if (verbose) cout << "Initiating FORRANGE loop..." << endl;
-  
-  int num_args = cur_string.CountNumWords();
-  if (num_args < 3) {
-    cerr << "  Error: Must give variable, min and max with FORRANGE!"
-    << endl;
-    exit(1);
-  }
-  
-  cString var = cur_string.PopWord();
-  double min_val = cur_string.PopWord().AsDouble();
-  double max_val = cur_string.PopWord().AsDouble();
-  double step_val = 1.0;
-  if (num_args >=4 ) step_val = cur_string.PopWord().AsDouble();
-  
-  cString & cur_variable = GetVariable(var);
-  
-  // Seperate out all ints from not all ints...
-  if (min_val == (double) ((int) min_val) &&
-      max_val == (double) ((int) max_val) &&
-      step_val == (double) ((int) step_val)) {
-    for (int i = (int) min_val; i <= (int) max_val; i += (int) step_val) {
-      cur_variable.Set("%d", i);
-      
-      if (verbose == true) {
-        cout << "FORRANGE: setting " << var << " to " << cur_variable << endl;
-      }
-      ProcessCommands(clist);
-    }
-  } else {
-    for (double i = min_val; i <= max_val; i += step_val) {
-      cur_variable.Set("%f", i);
-      
-      if (verbose == true) {
-        cout << "FORRANGE: setting " << var << " to " << cur_variable << endl;
-      }
-      ProcessCommands(clist);
-    }
-  }
-  
-  if (verbose == true) {
-    cout << "Ending FORRANGE on " << var << endl;
-  }
-}
-
-
-///////////////////  Private Methods ///////////////////////////
-
-cString cAnalyze::PopDirectory(cString & in_string,
-                               const cString & default_dir)
-{
-  // Determing the directory name
-  cString directory(default_dir);
-  if (in_string.GetSize() != 0) directory = in_string.PopWord();
-  
-  // Make sure the directory ends in a slash.  If not, add one.
-  int last_pos = directory.GetSize() - 1;
-  if (directory[last_pos] != '/' && directory[last_pos] != '\\') {
-    directory += '/';
-  }
-  
-  // Make sure the directory exists.
-  FILE *fp = fopen ( directory(), "r" );
-  if ( fp == 0 ){
-    if ( errno == ENOENT ){
-      cerr << "Directory '" << directory
-      << "' does not exist.  Creating..." << endl;
-      if ( mkdir( directory(), (S_IRWXU|S_IRWXG|S_IRWXO) ) )
-        cerr << " Error creating '" << directory << "'" << endl;
-    }
-    else cerr << " Error opening '" << directory << "'" << endl;
-  }
-  
-  return directory;
-}
-
-int cAnalyze::PopBatch(const cString & in_string)
-{
-  int batch = cur_batch;
-  if (in_string.GetSize() != 0 && in_string != "current") {
-    batch = in_string.AsInt();
-  }
-  
-  return batch;
-}
-
-cAnalyzeGenotype * cAnalyze::PopGenotype(cString gen_desc, int batch_id)
-{
-  if (batch_id == -1) batch_id = cur_batch;
-  tListPlus<cAnalyzeGenotype> & gen_list = batch[batch_id].List();
-  gen_desc.ToLower();
-  
-  cAnalyzeGenotype * found_gen = NULL;
-  if (gen_desc == "num_cpus")
-    found_gen = gen_list.PopIntMax(&cAnalyzeGenotype::GetNumCPUs);
-  else if (gen_desc == "total_cpus")
-    found_gen = gen_list.PopIntMax(&cAnalyzeGenotype::GetTotalCPUs);
-  else if (gen_desc == "merit")
-    found_gen = gen_list.PopDoubleMax(&cAnalyzeGenotype::GetMerit);
-  else if (gen_desc == "fitness")
-    found_gen = gen_list.PopDoubleMax(&cAnalyzeGenotype::GetFitness);
-  else if (gen_desc.IsNumeric(0))
-    found_gen = gen_list.PopIntValue(&cAnalyzeGenotype::GetID,
-                                     gen_desc.AsInt());
-  else if (gen_desc == "random") {
-    int gen_pos = random.GetUInt(gen_list.GetSize());
-    found_gen = gen_list.PopPos(gen_pos);
-  }
-  else {
-    cout << "  Error: unknown type " << gen_desc << endl;
-    exit(1);
-  }
-  
-  return found_gen;
-}
-
-
-cString & cAnalyze::GetVariable(const cString & var)
-{
-  if (var.GetSize() != 1 ||
-      (var.IsLetter(0) == false && var.IsNumeric(0) == false)) {
-    cerr << "Error: Illegal variable " << var << " being used." << endl;
-    exit(1);
-  }
-  
-  if (var.IsLowerLetter(0) == true) {
-    int var_id = (int) (var[0] - 'a');
-    return variables[var_id];
-  }
-  else if (var.IsUpperLetter(0) == true) {
-    int var_id = (int) (var[0] - 'A');
-    return local_variables[var_id];
-  }
-  // Otherwise it must be a number...
-  int var_id = (int) (var[0] - '0');
-  return arg_variables[var_id];
-}
-
-
-void cAnalyze::LoadCommandList(cInitFile & init_file,
-                               tList<cAnalyzeCommand> & clist)
-{
-  while (init_file.GetLineNum() < init_file.GetNumLines()) {
-    cString cur_string = init_file.GetNextLine();
-    cString command = cur_string.PopWord();
-    command.ToUpper();
-    
-    cAnalyzeCommand * cur_command;
-    cAnalyzeCommandDefBase * command_def = FindAnalyzeCommandDef(command);
-    if (command == "END") {
-      // We are done with this section of code; break out...
-      break;
-    }
-    else if (command_def != NULL && command_def->IsFlowCommand() == true) {
-      // This code has a body to it... fill it out!
-      cur_command = new cAnalyzeFlowCommand(command, cur_string);
-      LoadCommandList( init_file, *(cur_command->GetCommandList()) );
-    }
-    else {
-      // This is a normal command...
-      cur_command = new cAnalyzeCommand(command, cur_string);
-    }
-    
-    clist.PushRear(cur_command);
-  }
-}
-
-void cAnalyze::InteractiveLoadCommandList(tList<cAnalyzeCommand> & clist)
-{
-  interactive_depth++;
-  char text_input[2048];
-  while (true) {
-    for (int i = 0; i <= interactive_depth; i++) {
-      cout << ">>";
-    }
-    cout << " ";
-    cout.flush();
-    cin.getline(text_input, 2048);
-    cString cur_input(text_input);
-    cString command = cur_input.PopWord();
-    command.ToUpper();
-    
-    cAnalyzeCommand * cur_command;
-    cAnalyzeCommandDefBase * command_def = FindAnalyzeCommandDef(command);
-    if (command == "END") {
-      // We are done with this section of code; break out...
-      break;
-    }
-    else if (command_def != NULL && command_def->IsFlowCommand() == true) {
-      // This code has a body to it... fill it out!
-      cur_command = new cAnalyzeFlowCommand(command, cur_input);
-      InteractiveLoadCommandList(*(cur_command->GetCommandList()));
-    }
-    else {
-      // This is a normal command...
-      cur_command = new cAnalyzeCommand(command, cur_input);
-    }
-    
-    clist.PushRear(cur_command);
-  }
-  interactive_depth--;
-}
-
-void cAnalyze::PreProcessArgs(cString & args)
-{
-  int pos = 0;
-  int search_start = 0;
-  while ((pos = args.Find('$', search_start)) != -1) {
-    // Setup the variable name that was found...
-    char varlet = args[pos+1];
-    cString varname("$");
-    varname += varlet;
-    
-    // Determine the variable and act on it.
-    int varsize = 0;
-    if (varlet == '$') {
-      args.Clip(pos+1, 1);
-      varsize = 1;
-    }
-    else if (varlet >= 'a' && varlet <= 'z') {
-      int var_id = (int) (varlet - 'a');
-      args.Replace(varname, variables[var_id], pos);
-      varsize = variables[var_id].GetSize();
-    }
-    else if (varlet >= 'A' && varlet <= 'Z') {
-      int var_id = (int) (varlet - 'A');
-      args.Replace(varname, local_variables[var_id], pos);
-      varsize = local_variables[var_id].GetSize();
-    }
-    else if (varlet >= '0' && varlet <= '9') {
-      int var_id = (int) (varlet - '0');
-      args.Replace(varname, arg_variables[var_id], pos);
-      varsize = arg_variables[var_id].GetSize();
-    }
-    search_start = pos + varsize;
-  }
-}
-
-void cAnalyze::ProcessCommands(tList<cAnalyzeCommand> & clist)
-{
-  // Process the command list...
-  tListIterator<cAnalyzeCommand> command_it(clist);
-  command_it.Reset();
-  cAnalyzeCommand * cur_command = NULL;
-  while ((cur_command = command_it.Next()) != NULL) {
-    cString command = cur_command->GetCommand();
-    cString args = cur_command->GetArgs();
-    PreProcessArgs(args);
-    
-    cAnalyzeCommandDefBase * command_fun = FindAnalyzeCommandDef(command);
-    
-    if (command_fun != NULL) command_fun->Run(this, args, *cur_command);
-    else if (FunctionRun(command, args) == true) {
-      // Found a defined function by this name.
-    }
-    else {
-      cerr << "Error: Unknown analysis keyword '" << command << "'." << endl;
-      exit(1);
-    }
-    
-  }
-}
-
-void cAnalyze::SetupGenotypeDataList()
-{
-  if (genotype_data_list.GetSize() != 0) return; // List already setup.
-  
-  genotype_data_list.PushRear(new tDataEntry<cAnalyzeGenotype, bool>
-                              ("viable",      "Is Viable (0/1)", &cAnalyzeGenotype::GetViable,
-                               &cAnalyzeGenotype::SetViable));
-  genotype_data_list.PushRear(new tDataEntry<cAnalyzeGenotype, int>
-                              ("id",          "Genome ID",       &cAnalyzeGenotype::GetID,
-                               &cAnalyzeGenotype::SetID));
-  genotype_data_list.PushRear(new tDataEntry<cAnalyzeGenotype, const cString &>
-                              ("tag",         "Genotype Tag",    &cAnalyzeGenotype::GetTag,
-                               &cAnalyzeGenotype::SetTag,
-                               &cAnalyzeGenotype::CompareNULL, "(none)", ""));
-  genotype_data_list.PushRear(new tDataEntry<cAnalyzeGenotype, int>
-                              ("parent_id",   "Parent ID",       &cAnalyzeGenotype::GetParentID,
-                               &cAnalyzeGenotype::SetParentID));
-  genotype_data_list.PushRear(new tDataEntry<cAnalyzeGenotype, int>
-                              ("parent2_id",  "Second Parent ID (for sexual genotypes)",
-                               &cAnalyzeGenotype::GetParent2ID, &cAnalyzeGenotype::SetParent2ID));
-  genotype_data_list.PushRear(new tDataEntry<cAnalyzeGenotype, int>
-                              ("parent_dist", "Parent Distance", &cAnalyzeGenotype::GetParentDist,
-                               &cAnalyzeGenotype::SetParentDist));
-  genotype_data_list.PushRear(new tDataEntry<cAnalyzeGenotype, int>
-                              ("ancestor_dist","Ancestor Distance",&cAnalyzeGenotype::GetAncestorDist,
-                               &cAnalyzeGenotype::SetAncestorDist));
-  genotype_data_list.PushRear(new tDataEntry<cAnalyzeGenotype, int>
-                              ("lineage", "Unique Lineage Label",&cAnalyzeGenotype::GetLineageLabel,
-                               &cAnalyzeGenotype::SetLineageLabel));
-  genotype_data_list.PushRear(new tDataEntry<cAnalyzeGenotype, int>
-                              ("num_cpus",    "Number of CPUs",  &cAnalyzeGenotype::GetNumCPUs,
-                               &cAnalyzeGenotype::SetNumCPUs));
-  genotype_data_list.PushRear(new tDataEntry<cAnalyzeGenotype, int>
-                              ("total_cpus",  "Total CPUs Ever", &cAnalyzeGenotype::GetTotalCPUs,
-                               &cAnalyzeGenotype::SetTotalCPUs));
-  genotype_data_list.PushRear(new tDataEntry<cAnalyzeGenotype, int>
-                              ("length",      "Genome Length",   &cAnalyzeGenotype::GetLength,
-                               &cAnalyzeGenotype::SetLength, &cAnalyzeGenotype::CompareLength));
-  genotype_data_list.PushRear(new tDataEntry<cAnalyzeGenotype, int>
-                              ("copy_length", "Copied Length",   &cAnalyzeGenotype::GetCopyLength,
-                               &cAnalyzeGenotype::SetCopyLength));
-  genotype_data_list.PushRear(new tDataEntry<cAnalyzeGenotype, int>
-                              ("exe_length",  "Executed Length", &cAnalyzeGenotype::GetExeLength,
-                               &cAnalyzeGenotype::SetExeLength));
-  genotype_data_list.PushRear(new tDataEntry<cAnalyzeGenotype, double>
-                              ("merit",       "Merit",           &cAnalyzeGenotype::GetMerit,
-                               &cAnalyzeGenotype::SetMerit, &cAnalyzeGenotype::CompareMerit));
-  genotype_data_list.PushRear(new tDataEntry<cAnalyzeGenotype, double>
-                              ("comp_merit",  "Computational Merit", &cAnalyzeGenotype::GetCompMerit,
-                               (void (cAnalyzeGenotype::*)(double)) NULL, &cAnalyzeGenotype::CompareCompMerit));
-  genotype_data_list.PushRear(new tDataEntry<cAnalyzeGenotype, double>
-                              ("comp_merit_ratio", "Computational Merit Ratio",
-                               &cAnalyzeGenotype::GetCompMeritRatio,
-                               (void (cAnalyzeGenotype::*)(double)) NULL,
-                               &cAnalyzeGenotype::CompareCompMerit));
-  genotype_data_list.PushRear(new tDataEntry<cAnalyzeGenotype, int>
-                              ("gest_time",   "Gestation Time",  &cAnalyzeGenotype::GetGestTime,
-                               &cAnalyzeGenotype::SetGestTime,
-                               &cAnalyzeGenotype::CompareGestTime, "Inf."));
-  genotype_data_list.PushRear(new tDataEntry<cAnalyzeGenotype, double>
-                              ("efficiency",  "Rep. Efficiency", &cAnalyzeGenotype::GetEfficiency,
-                               (void (cAnalyzeGenotype::*)(double)) NULL,
-                               &cAnalyzeGenotype::CompareEfficiency));
-  genotype_data_list.PushRear(new tDataEntry<cAnalyzeGenotype, double>
-                              ("efficiency_ratio", "Rep. Efficiency Ratio",
-                               &cAnalyzeGenotype::GetEfficiencyRatio,
-                               (void (cAnalyzeGenotype::*)(double)) NULL,
-                               &cAnalyzeGenotype::CompareEfficiency));
-  genotype_data_list.PushRear(new tDataEntry<cAnalyzeGenotype, double>
-                              ("fitness",     "Fitness",         &cAnalyzeGenotype::GetFitness,
-                               &cAnalyzeGenotype::SetFitness, &cAnalyzeGenotype::CompareFitness));
-  genotype_data_list.PushRear(new tDataEntry<cAnalyzeGenotype, double>
-                              ("div_type",     "Divide Type",    &cAnalyzeGenotype::GetDivType,
-                               &cAnalyzeGenotype::SetDivType));
-  genotype_data_list.PushRear(new tDataEntry<cAnalyzeGenotype, int>
-                              ("mate_id",     "Mate Selection ID Number",  &cAnalyzeGenotype::GetMateID,
-                               &cAnalyzeGenotype::SetMateID));
-  genotype_data_list.PushRear(new tDataEntry<cAnalyzeGenotype, double>
-                              ("fitness_ratio", "Fitness Ratio", &cAnalyzeGenotype::GetFitnessRatio,
-                               (void (cAnalyzeGenotype::*)(double)) NULL,
-                               &cAnalyzeGenotype::CompareFitness));
-  genotype_data_list.PushRear(new tDataEntry<cAnalyzeGenotype, int>
-                              ("update_born", "Update Born",     &cAnalyzeGenotype::GetUpdateBorn,
-                               &cAnalyzeGenotype::SetUpdateBorn));
-  genotype_data_list.PushRear(new tDataEntry<cAnalyzeGenotype, int>
-                              ("update_dead", "Update Dead",     &cAnalyzeGenotype::GetUpdateDead,
-                               &cAnalyzeGenotype::SetUpdateDead));
-  genotype_data_list.PushRear(new tDataEntry<cAnalyzeGenotype, int>
-                              ("depth",       "Tree Depth",      &cAnalyzeGenotype::GetDepth,
-                               &cAnalyzeGenotype::SetDepth));
-  genotype_data_list.PushRear(new tDataEntry<cAnalyzeGenotype, double>
-                              ("frac_dead",   "Fraction Mutations Lethal",
-                               &cAnalyzeGenotype::GetFracDead,
-                               (void (cAnalyzeGenotype::*)(double)) NULL));
-  genotype_data_list.PushRear(new tDataEntry<cAnalyzeGenotype, double>
-                              ("frac_neg",   "Fraction Mutations Detrimental",
-                               &cAnalyzeGenotype::GetFracNeg,
-                               (void (cAnalyzeGenotype::*)(double)) NULL));
-  genotype_data_list.PushRear(new tDataEntry<cAnalyzeGenotype, double>
-                              ("frac_neut",   "Fraction Mutations Neutral",
-                               &cAnalyzeGenotype::GetFracNeut,
-                               (void (cAnalyzeGenotype::*)(double)) NULL));
-  genotype_data_list.PushRear(new tDataEntry<cAnalyzeGenotype, double>
-                              ("frac_pos",   "Fraction Mutations Beneficial",
-                               &cAnalyzeGenotype::GetFracPos,
-                               (void (cAnalyzeGenotype::*)(double)) NULL));
-  genotype_data_list.PushRear(new tDataEntry<cAnalyzeGenotype, const cString &>
-                              ("parent_muts", "Mutations from Parent",
-                               &cAnalyzeGenotype::GetParentMuts, &cAnalyzeGenotype::SetParentMuts,
-                               &cAnalyzeGenotype::CompareNULL, "(none)", ""));
-  genotype_data_list.PushRear(new tDataEntry<cAnalyzeGenotype, const cString &>
-                              ("task_order", "Task Performance Order",
-                               &cAnalyzeGenotype::GetTaskOrder, &cAnalyzeGenotype::SetTaskOrder,
-                               &cAnalyzeGenotype::CompareNULL, "(none)", ""));
-  genotype_data_list.PushRear(new tDataEntry<cAnalyzeGenotype, cString>
-                              ("sequence",    "Genome Sequence",
-                               &cAnalyzeGenotype::GetSequence, &cAnalyzeGenotype::SetSequence, 
-                               &cAnalyzeGenotype::CompareNULL, "(N/A)", ""));
-  genotype_data_list.PushRear(new tDataEntry<cAnalyzeGenotype, const cString &>
-                              ("alignment",   "Aligned Sequence",
-                               &cAnalyzeGenotype::GetAlignedSequence,
-                               &cAnalyzeGenotype::SetAlignedSequence,
-                               &cAnalyzeGenotype::CompareNULL, "(N/A)", ""));
-  
-  genotype_data_list.PushRear(new tDataEntry<cAnalyzeGenotype, cString>
-                              ("task_list",    "List of all tasks performed",
-                               &cAnalyzeGenotype::GetTaskList,
-                               (void (cAnalyzeGenotype::*)(cString)) NULL,
-                               &cAnalyzeGenotype::CompareNULL, "(N/A)", ""));
-  
-  genotype_data_list.PushRear(new tDataEntry<cAnalyzeGenotype, cString>
-                              ("link.tasksites", "Phenotype Map", &cAnalyzeGenotype::GetMapLink,
-                               (void (cAnalyzeGenotype::*)(cString)) NULL));
-  genotype_data_list.PushRear(new tDataEntry<cAnalyzeGenotype, cString>
-                              ("html.sequence",  "Genome Sequence",
-                               &cAnalyzeGenotype::GetHTMLSequence,
-                               (void (cAnalyzeGenotype::*)(cString)) NULL,
-                               &cAnalyzeGenotype::CompareNULL, "(N/A)", ""));
-  
-  const cTaskLib & task_lib = cTestCPU::GetEnvironment()->GetTaskLib();
-  for (int i = 0; i < task_lib.GetSize(); i++) {
-    cString t_name, t_desc;
-    t_name.Set("task.%d", i);
-    t_desc = task_lib.GetTask(i).GetDesc();
-    genotype_data_list.PushRear(new tArgDataEntry<cAnalyzeGenotype, int, int>
-                                (t_name, t_desc, &cAnalyzeGenotype::GetTaskCount, i,
-                                 &cAnalyzeGenotype::CompareTaskCount));
-  }
-  
-  // The remaining values should actually go in a seperate list called
-  // "population_data_list", but for the moment we're going to put them
-  // here so that we only need to worry about a single system to load and
-  // save genotype information.
-  genotype_data_list.PushRear(new tDataEntry<cAnalyzeGenotype, int>
-                              ("update",       "Update Output",
-                               &cAnalyzeGenotype::GetUpdateDead, &cAnalyzeGenotype::SetUpdateDead));
-  genotype_data_list.PushRear(new tDataEntry<cAnalyzeGenotype, int>
-                              ("dom_num_cpus", "Number of Dominant Organisms",
-                               &cAnalyzeGenotype::GetNumCPUs, &cAnalyzeGenotype::SetNumCPUs));
-  genotype_data_list.PushRear(new tDataEntry<cAnalyzeGenotype, int>
-                              ("dom_depth",    "Tree Depth of Dominant Genotype",
-                               &cAnalyzeGenotype::GetDepth, &cAnalyzeGenotype::SetDepth));
-  genotype_data_list.PushRear(new tDataEntry<cAnalyzeGenotype, int>
-                              ("dom_id",       "Dominant Genotype ID",
-                               &cAnalyzeGenotype::GetID, &cAnalyzeGenotype::SetID));
-  genotype_data_list.PushRear(new tDataEntry<cAnalyzeGenotype, cString>
-                              ("dom_sequence", "Dominant Genotype Sequence",
-                               &cAnalyzeGenotype::GetSequence, &cAnalyzeGenotype::SetSequence, 
-                               &cAnalyzeGenotype::CompareNULL, "(N/A)", ""));
-}
-
-
-// Pass in the arguments for a command and fill out the entries in list
-// format....
-
-void cAnalyze::LoadGenotypeDataList(cStringList arg_list,
-                                    tList< tDataEntryCommand<cAnalyzeGenotype> > & output_list)
-{
-  // For the moment, just put everything into the output list.
-  SetupGenotypeDataList();
-  
-  // If no args were given, load all of the stats.
-  if (arg_list.GetSize() == 0) {
-    tListIterator< tDataEntryBase<cAnalyzeGenotype> >
-    genotype_data_it(genotype_data_list);
-    while (genotype_data_it.Next() != (void *) NULL) {
-      tDataEntryCommand<cAnalyzeGenotype> * entry_command =
-      new tDataEntryCommand<cAnalyzeGenotype>(genotype_data_it.Get());
-      output_list.PushRear(entry_command);
-    }
-  }
-  // Otherwise, load only those listed.
-  else {
-    while (arg_list.GetSize() != 0) {
-      // Setup the next entry
-      cString cur_args = arg_list.Pop();
-      cString cur_entry = cur_args.Pop(':');
-      bool found_entry = false;
-      
-      // Scan the genotype data list for the current entry
-      tListIterator< tDataEntryBase<cAnalyzeGenotype> >
-        genotype_data_it(genotype_data_list);
-      
-      while (genotype_data_it.Next() != (void *) NULL) {
-        if (genotype_data_it.Get()->GetName() == cur_entry) {
-          tDataEntryCommand<cAnalyzeGenotype> * entry_command =
-          new tDataEntryCommand<cAnalyzeGenotype>
-          (genotype_data_it.Get(), cur_args);
-          output_list.PushRear(entry_command);
-          found_entry = true;
-          break;
-        }
-      }
-      
-      // If the entry was not found, give a warning.
-      if (found_entry == false) {
-        int best_match = 1000;
-        cString best_entry;
-        
-        genotype_data_it.Reset();
-        while (genotype_data_it.Next() != (void *) NULL) {
-          const cString & test_str = genotype_data_it.Get()->GetName();
-          const int test_dist = cStringUtil::EditDistance(test_str, cur_entry);
-          if (test_dist < best_match) {
-            best_match = test_dist;
-            best_entry = test_str;
-          }
-        }	
-        
-        cerr << "Warning: Format entry \"" << cur_entry
-          << "\" not found.  Best match is \""
-          << best_entry << "\"." << endl;
-      }
-      
-    }
-  }
-}
-
-
-void cAnalyze::AddLibraryDef(const cString & name,
-                             void (cAnalyze::*_fun)(cString))
-{
-  command_lib.PushRear(new cAnalyzeCommandDef(name, _fun));
-}
-
-void cAnalyze::AddLibraryDef(const cString & name,
-                             void (cAnalyze::*_fun)(cString, tList<cAnalyzeCommand> &))
-{
-  command_lib.PushRear(new cAnalyzeFlowCommandDef(name, _fun));
-}
-
-void cAnalyze::SetupCommandDefLibrary()
-{
-  if (command_lib.GetSize() != 0) return; // Library already setup.
-  
-  AddLibraryDef("LOAD_ORGANISM", &cAnalyze::LoadOrganism);
-  AddLibraryDef("LOAD_BASE_DUMP", &cAnalyze::LoadBasicDump);
-  AddLibraryDef("LOAD_DETAIL_DUMP", &cAnalyze::LoadDetailDump);
-  AddLibraryDef("LOAD_MULTI_DETAIL", &cAnalyze::LoadMultiDetail);
-  AddLibraryDef("LOAD_SEQUENCE", &cAnalyze::LoadSequence);
-  AddLibraryDef("LOAD_DOMINANT", &cAnalyze::LoadDominant);
-  AddLibraryDef("LOAD_RESOURCES", &cAnalyze::LoadResources);
-  AddLibraryDef("LOAD", &cAnalyze::LoadFile);
-  
-  // Reduction commands...
-  AddLibraryDef("FIND_GENOTYPE", &cAnalyze::FindGenotype);
-  AddLibraryDef("FIND_ORGANISM", &cAnalyze::FindOrganism);
-  AddLibraryDef("FIND_LINEAGE", &cAnalyze::FindLineage);
-  AddLibraryDef("FIND_SEX_LINEAGE", &cAnalyze::FindSexLineage);
-  AddLibraryDef("FIND_CLADE", &cAnalyze::FindClade);
-  AddLibraryDef("SAMPLE_ORGANISMS", &cAnalyze::SampleOrganisms);
-  AddLibraryDef("SAMPLE_GENOTYPES", &cAnalyze::SampleGenotypes);
-  AddLibraryDef("KEEP_TOP", &cAnalyze::KeepTopGenotypes);
-  
-  // Direct output commands...
-  AddLibraryDef("PRINT", &cAnalyze::CommandPrint);
-  AddLibraryDef("TRACE", &cAnalyze::CommandTrace);
-  AddLibraryDef("PRINT_TASKS", &cAnalyze::CommandPrintTasks);
-  AddLibraryDef("DETAIL", &cAnalyze::CommandDetail);
-  AddLibraryDef("DETAIL_TIMELINE", &cAnalyze::CommandDetailTimeline);
-  AddLibraryDef("DETAIL_BATCHES", &cAnalyze::CommandDetailBatches);
-  AddLibraryDef("DETAIL_AVERAGE", &cAnalyze::CommandDetailAverage);
-  AddLibraryDef("DETAIL_INDEX", &cAnalyze::CommandDetailIndex);
-  AddLibraryDef("HISTOGRAM", &cAnalyze::CommandHistogram);
-  
-  // Population analysis commands...
-  AddLibraryDef("PRINT_PHENOTYPES", &cAnalyze::CommandPrintPhenotypes);
-  AddLibraryDef("PRINT_DIVERSITY", &cAnalyze::CommandPrintDiversity);
-  AddLibraryDef("COMMUNITY_COMPLEXITY", &cAnalyze::CommunityComplexity);
-
-  // Individual organism analysis...
-  AddLibraryDef("LANDSCAPE", &cAnalyze::CommandLandscape);
-  AddLibraryDef("FITNESS_MATRIX", &cAnalyze::CommandFitnessMatrix);
-  AddLibraryDef("MAP", &cAnalyze::CommandMapTasks);  // Deprecated...
-  AddLibraryDef("MAP_TASKS", &cAnalyze::CommandMapTasks);
-  AddLibraryDef("AVERAGE_MODULARITY", &cAnalyze::CommandAverageModularity);
-  AddLibraryDef("MAP_MUTATIONS", &cAnalyze::CommandMapMutations);
-  AddLibraryDef("ANALYZE_COMPLEXITY", &cAnalyze::AnalyzeComplexity);
-  AddLibraryDef("ANALYZE_POP_COMPLEXITY", &cAnalyze::AnalyzePopComplexity);
-  AddLibraryDef("MAP_DEPTH", &cAnalyze::CommandMapDepth);
-  
-  // Population comparison commands...
-  AddLibraryDef("HAMMING", &cAnalyze::CommandHamming);
-  AddLibraryDef("LEVENSTEIN", &cAnalyze::CommandLevenstein);
-  AddLibraryDef("SPECIES", &cAnalyze::CommandSpecies);
-  AddLibraryDef("RECOMBINE", &cAnalyze::CommandRecombine);
-  
-  // Lineage analysis commands...
-  AddLibraryDef("ALIGN", &cAnalyze::CommandAlign);
-  AddLibraryDef("ANALYZE_NEWINFO", &cAnalyze::AnalyzeNewInfo);
-  
-  // Build input files for avida...
-  AddLibraryDef("WRITE_CLONE", &cAnalyze::WriteClone);
-  AddLibraryDef("WRITE_INJECT_EVENTS", &cAnalyze::WriteInjectEvents);
-  AddLibraryDef("WRITE_COMPETITION", &cAnalyze::WriteCompetition);
-  
-  // Automated analysis
-  AddLibraryDef("ANALYZE_MUTS", &cAnalyze::AnalyzeMuts);
-  AddLibraryDef("ANALYZE_INSTRUCTIONS", &cAnalyze::AnalyzeInstructions);
-  AddLibraryDef("ANALYZE_INST_POP", &cAnalyze::AnalyzeInstPop);
-  AddLibraryDef("ANALYZE_BRANCHING", &cAnalyze::AnalyzeBranching);
-  AddLibraryDef("ANALYZE_MUTATION_TRACEBACK",
-                &cAnalyze::AnalyzeMutationTraceback);
-  AddLibraryDef("ANALYZE_EPISTASIS", &cAnalyze::AnalyzeEpistasis);
-  AddLibraryDef("ANALYZE_MATE_SELECTION", &cAnalyze::AnalyzeMateSelection);
-  
-  // Environment manipulation
-  AddLibraryDef("ENVIRONMENT", &cAnalyze::EnvironmentSetup);
-  
-  // Documantation...
-  AddLibraryDef("HELPFILE", &cAnalyze::CommandHelpfile);
-  
-  // Control commands...
-  AddLibraryDef("SET", &cAnalyze::VarSet);
-  AddLibraryDef("SET_BATCH", &cAnalyze::BatchSet);
-  AddLibraryDef("NAME_BATCH", &cAnalyze::BatchName);
-  AddLibraryDef("TAG_BATCH", &cAnalyze::BatchTag);
-  AddLibraryDef("PURGE_BATCH", &cAnalyze::BatchPurge);
-  AddLibraryDef("DUPLICATE", &cAnalyze::BatchDuplicate);
-  AddLibraryDef("RECALCULATE", &cAnalyze::BatchRecalculate);
-  AddLibraryDef("RENAME", &cAnalyze::BatchRename);
-  AddLibraryDef("STATUS", &cAnalyze::PrintStatus);
-  AddLibraryDef("DEBUG", &cAnalyze::PrintDebug);
-  AddLibraryDef("ECHO", &cAnalyze::PrintDebug);
-  AddLibraryDef("VERBOSE", &cAnalyze::ToggleVerbose);
-  AddLibraryDef("INCLUDE", &cAnalyze::IncludeFile);
-  AddLibraryDef("SYSTEM", &cAnalyze::CommandSystem);
-  AddLibraryDef("INTERACTIVE", &cAnalyze::CommandInteractive);
-  AddLibraryDef("PRINT_TEST_CPU_RESOURCES", &cAnalyze::PrintTestCPUResources);
-  
-  // Functions...
-  AddLibraryDef("FUNCTION", &cAnalyze::FunctionCreate);
-  
-  // Flow commands...
-  AddLibraryDef("FOREACH", &cAnalyze::CommandForeach);
-  AddLibraryDef("FORRANGE", &cAnalyze::CommandForRange);
-}
-
-cAnalyzeCommandDefBase * cAnalyze::FindAnalyzeCommandDef(const cString & name)
-{
-  SetupCommandDefLibrary();
-  
-  tListIterator<cAnalyzeCommandDefBase> lib_it(command_lib);
-  while (lib_it.Next() != (void *) NULL) {
-    if (lib_it.Get()->GetName() == name) break;
-  }
-  
-  return lib_it.Get();
-}
-
-void cAnalyze::RunInteractive()
-{
-  cout << "Entering interactive mode..." << endl;
-  
-  char text_input[2048];
-  while (true) {
-    cout << ">> ";
-    cout.flush();
-    cin.getline(text_input, 2048);
-    cString cur_input(text_input);
-    cString command = cur_input.PopWord();
-    command.ToUpper();
-    
-    cAnalyzeCommand * cur_command;
-    cAnalyzeCommandDefBase * command_def = FindAnalyzeCommandDef(command);
-    if (command == "") {
-      // Don't worry about blank lines...
-      continue;
-    }
-    else if (command == "END" || command == "QUIT" || command == "EXIT") {
-      // We are done with interactive mode...
-      break;
-    }
-    else if (command_def != NULL && command_def->IsFlowCommand() == true) {
-      // This code has a body to it... fill it out!
-      cur_command = new cAnalyzeFlowCommand(command, cur_input);
-      InteractiveLoadCommandList(*(cur_command->GetCommandList()));
-    }
-    else {
-      // This is a normal command...
-      cur_command = new cAnalyzeCommand(command, cur_input);
-    }
-    
-    cString args = cur_command->GetArgs();
-    PreProcessArgs(args);
-    
-    cAnalyzeCommandDefBase * command_fun = FindAnalyzeCommandDef(command);
-    
-    // First check for built-in functions...
-    if (command_fun != NULL) command_fun->Run(this, args, *cur_command);
-    
-    // Then for user defined functions
-    else if (FunctionRun(command, args) == true) { }
-    
-    // Otherwise, give an error.
-    else cerr << "Error: Unknown command '" << command << "'." << endl;
-  }
-}

Deleted: trunk/source/main/analyze.hh
===================================================================
--- trunk/source/main/analyze.hh	2005-09-15 23:16:19 UTC (rev 313)
+++ trunk/source/main/analyze.hh	2005-09-16 02:10:20 UTC (rev 314)
@@ -1,251 +0,0 @@
-//////////////////////////////////////////////////////////////////////////////
-// Copyright (C) 1993 - 2003 California Institute of Technology             //
-//                                                                          //
-// Read the COPYING and README files, or contact 'avida at alife.org',         //
-// before continuing.  SOME RESTRICTIONS MAY APPLY TO USE OF THIS FILE.     //
-//////////////////////////////////////////////////////////////////////////////
-
-#ifndef ANALYZE_HH
-#define ANALYZE_HH
-
-#include <vector>
-
-#ifndef DATA_FILE_MANAGER_HH
-#include "data_file_manager.hh"
-#endif
-#ifndef GENOTYPE_BATCH_HH
-#include "genotype_batch.hh"
-#endif
-#ifndef RANDOM_HH
-#include "random.hh"
-#endif
-#ifndef STRING_HH
-#include "string.hh"
-#endif
-#ifndef STRING_LIST_HH
-#include "string_list.hh"
-#endif
-#ifndef TLIST_HH
-#include "tList.hh"
-#endif
-
-#define MAX_BATCHES 2000
-
-// cAnalyze            : The master analyze object.
-
-class cGenotypeBatch; // array
-template <class T> class tList; // aggregate
-class cAnalyzeCommand;
-class cAnalyzeFunction;
-class cAnalyzeCommandDefBase;
-class cString; // aggregate
-class cDataFileManager; // aggregate
-template <class T> class tDataEntryBase;
-class cInstSet;
-class cRandom; // aggregate
-class cString; // aggregate
-class cAnalyzeGenotype;
-class cInitFile;
-class cStringList; // aggregate
-template <class T> class tDataEntryCommand;
-template <class T> class tListIterator;
-class cEnvironment;
-
-class cAnalyze {
-private:
-  int cur_batch;
-  cGenotypeBatch batch[MAX_BATCHES];
-  tList<cAnalyzeCommand> command_list;
-  tList<cAnalyzeFunction> function_list;
-  tList<cAnalyzeCommandDefBase> command_lib;
-  cString variables[26];
-  cString local_variables[26];
-  cString arg_variables[10];
-  cEnvironment *d_environment;
-
-  // This is the storage for the resource information from resource.dat.  It 
-  // is a pair of the update and a vector of the resource concentrations
-  std::vector<std::pair<int, std::vector<double> > > resources;
-
-  bool verbose;            // Should details be output to command line?
-  int interactive_depth;   // How nested are we if in interactive mode?
-
-  cDataFileManager data_file_manager;
-  tList< tDataEntryBase<cAnalyzeGenotype> > genotype_data_list;
-
-  cInstSet & inst_set;
-  cRandom random;
-
-private:
-  // Pop specific types of arguments from an arg list.
-  cString PopDirectory(cString & in_string, const cString & default_dir);
-  int PopBatch(const cString & in_string);
-  cAnalyzeGenotype * PopGenotype(cString gen_desc, int batch_id=-1);
-  cString & GetVariable(const cString & varname);
-
-  // Other arg-list methods
-  void LoadCommandList(cInitFile & init_file, tList<cAnalyzeCommand> & clist);
-  void InteractiveLoadCommandList(tList<cAnalyzeCommand> & clist);
-  void PreProcessArgs(cString & args);
-  void ProcessCommands(tList<cAnalyzeCommand> & clist);
-
-  void SetupGenotypeDataList();	
-  void LoadGenotypeDataList(cStringList arg_list,
-	    tList< tDataEntryCommand<cAnalyzeGenotype> > & output_list);
-		      
-  void AddLibraryDef(const cString & name, void (cAnalyze::*_fun)(cString));
-  void AddLibraryDef(const cString & name,
-	     void (cAnalyze::*_fun)(cString, tList<cAnalyzeCommand> &));
-  cAnalyzeCommandDefBase * FindAnalyzeCommandDef(const cString & name);
-  void SetupCommandDefLibrary();
-  bool FunctionRun(const cString & fun_name, cString args);
-
-  // Batch management...
-  int BatchUtil_GetMaxLength(int batch_id=-1);
-
-  // Comamnd helpers...
-  void CommandDetail_Header(std::ostream & fp, int format_type,
-            tListIterator< tDataEntryCommand<cAnalyzeGenotype> > & output_it,
-            int time_step=-1);
-  void CommandDetail_Body(std::ostream & fp, int format_type,
-            tListIterator< tDataEntryCommand<cAnalyzeGenotype> > & output_it,
-            int time_step=-1, int max_time=1);
-  void CommandDetailAverage_Body(std::ostream & fp, int num_arguments,
-            tListIterator< tDataEntryCommand<cAnalyzeGenotype> > & output_it);
-  void CommandHistogram_Header(std::ostream & fp, int format_type,
-            tListIterator< tDataEntryCommand<cAnalyzeGenotype> > & output_it);
-  void CommandHistogram_Body(std::ostream & fp, int format_type,
-            tListIterator< tDataEntryCommand<cAnalyzeGenotype> > & output_it);
-
-private:
-  // Loading methods...
-  void LoadOrganism(cString cur_string);
-  void LoadBasicDump(cString cur_string);
-  void LoadDetailDump(cString cur_string);
-  void LoadMultiDetail(cString cur_string);
-  void LoadSequence(cString cur_string);
-  void LoadDominant(cString cur_string);
-  // Clears the current time oriented list of resources and loads in a new one
-  // from a file specified by the user, or resource.dat by default.
-  void LoadResources(cString cur_string);
-  void LoadFile(cString cur_string);
-
-  // Reduction
-  void FindGenotype(cString cur_string);
-  void FindOrganism(cString cur_string);
-  void FindLineage(cString cur_string);
-  void FindSexLineage(cString cur_string);
-  void FindClade(cString cur_string);
-  void SampleOrganisms(cString cur_string);
-  void SampleGenotypes(cString cur_string);
-  void KeepTopGenotypes(cString cur_string);
-
-  // Direct Output Commands...
-  void CommandPrint(cString cur_string);
-  void CommandTrace(cString cur_string);
-  void CommandTraceWithResources(cString cur_string);
-  void CommandPrintTasks(cString cur_string);
-  void CommandDetail(cString cur_string);
-  void CommandDetailTimeline(cString cur_string);
-  void CommandDetailBatches(cString cur_string);
-  void CommandDetailAverage(cString cur_string);
-  void CommandDetailIndex(cString cur_string);
-  void CommandHistogram(cString cur_string);
-
-  // Population Analysis Commands...
-  void CommandPrintPhenotypes(cString cur_string);
-  void CommandPrintDiversity(cString cur_string);
-  void PhyloCommunityComplexity(cString cur_string);
-  void CommunityComplexity(cString cur_string);
-
-  // Individual Organism Analysis...
-  void CommandLandscape(cString cur_string);
-  void CommandFitnessMatrix(cString cur_string);
-  void CommandMapTasks(cString cur_string);
-  void CommandAverageModularity(cString cur_string);
-  void CommandMapMutations(cString cur_string);
-  void CommandMapDepth(cString cur_string);
-
-  // Population Comparison Commands...
-  void CommandHamming(cString cur_string);
-  void CommandLevenstein(cString cur_string);
-  void CommandSpecies(cString cur_string);
-  void CommandRecombine(cString cur_string);
-
-  // Lineage Analysis Commands...
-  void CommandAlign(cString cur_string);
-  void AnalyzeNewInfo(cString cur_string);   
-
-  // Build Input Files for Avida
-  void WriteClone(cString cur_string);
-  void WriteInjectEvents(cString cur_string);
-  void WriteCompetition(cString cur_string);
-
-  // Automated analysis...
-  void AnalyzeMuts(cString cur_string);
-  void AnalyzeInstructions(cString cur_string);
-  void AnalyzeInstPop(cString cur_string);
-  void AnalyzeBranching(cString cur_string);
-  void AnalyzeMutationTraceback(cString cur_string);
-  void AnalyzeComplexity(cString cur_string);
-  void AnalyzePopComplexity(cString cur_string);
-  void AnalyzeEpistasis(cString cur_string);
-  void AnalyzeMateSelection(cString cur_string);
-
-  // Environment Manipulation
-  void EnvironmentSetup(cString cur_string);
-
-  // Documentation...
-  void CommandHelpfile(cString cur_string);
-  void CommandDocfile(cString cur_string);
-
-  // Control...
-  void VarSet(cString cur_string);
-  void BatchSet(cString cur_string);
-  void BatchName(cString cur_string);
-  void BatchTag(cString cur_string);
-  void BatchPurge(cString cur_string);
-  void BatchDuplicate(cString cur_string);
-  void BatchRecalculate(cString cur_string);
-  void BatchRename(cString cur_string);
-  void PrintStatus(cString cur_string);
-  void PrintDebug(cString cur_string);
-  void ToggleVerbose(cString cur_string);
-  void IncludeFile(cString cur_string);
-  void CommandSystem(cString cur_string);
-  void CommandInteractive(cString cur_string);
-  void PrintTestCPUResources(cString cur_string);
-
-  // Functions...
-  void FunctionCreate(cString cur_string, tList<cAnalyzeCommand> & clist);
-  // Looks up the resource concentrations that are the closest to the
-  // given update and then fill in those concentrations into the environment.
-  void FillResources(int update);
-  // Analyze the entropy of genotype under default environment
-  double AnalyzeEntropy(cAnalyzeGenotype * genotype, double mut_rate);
-  // Analyze the entropy of child given parent and default environment
-  double AnalyzeEntropyGivenParent(cAnalyzeGenotype * genotype, 
-				   cAnalyzeGenotype * parent, 
-				   double mut_rate);
-  // Calculate the increased information in genotype1 comparing to genotype2 
-  // line by line. If information in genotype1 is less than that in genotype2 
-  // in a line, increasing is 0. Usually this is used for child-parent comparison.
-  double IncreasedInfo(cAnalyzeGenotype * genotype1, 
-		       cAnalyzeGenotype * genotype2, 
-		       double mut_rate);
-  
-  // Flow Control...
-  void CommandForeach(cString cur_string, tList<cAnalyzeCommand> & clist);
-  void CommandForRange(cString cur_string, tList<cAnalyzeCommand> & clist);
-
-private:
-  // disabled copy constructor.
-  cAnalyze(const cAnalyze &);
-public:
-  cAnalyze(cString filename, cEnvironment* = NULL);
-  ~cAnalyze();
-
-  void RunInteractive();
-};
-
-#endif

Deleted: trunk/source/main/analyze_command.hh
===================================================================
--- trunk/source/main/analyze_command.hh	2005-09-15 23:16:19 UTC (rev 313)
+++ trunk/source/main/analyze_command.hh	2005-09-16 02:10:20 UTC (rev 314)
@@ -1,44 +0,0 @@
-//////////////////////////////////////////////////////////////////////////////
-// Copyright (C) 1993 - 2003 California Institute of Technology             //
-//                                                                          //
-// Read the COPYING and README files, or contact 'avida at alife.org',         //
-// before continuing.  SOME RESTRICTIONS MAY APPLY TO USE OF THIS FILE.     //
-//////////////////////////////////////////////////////////////////////////////
-
-#ifndef ANALYZE_COMMAND_HH
-#define ANALYZE_COMMAND_HH
-
-#ifndef STRING_HH
-#include "string.hh"
-#endif
-
-// cAnalyzeCommand     : A command in a loaded program
-
-class cString; // aggregate
-template <class T> class tList;
-
-class cAnalyzeCommand {
-protected:
-  cString command;
-  cString args;
-private:
-  // disabled copy constructor.
-  cAnalyzeCommand(const cAnalyzeCommand &);
-public:
-  cAnalyzeCommand(const cString & _command, const cString & _args)
-    : command(_command), args(_args) { command.ToUpper(); }
-  virtual ~cAnalyzeCommand() { ; }
-
-  const cString & GetCommand() { return command; }
-  const cString & GetArgs() const { return args; }
-  cString GetArgs() { return args; }
-  virtual tList<cAnalyzeCommand> * GetCommandList() { return NULL; }
-
-  /*
-  added to satisfy Boost.Python; the semantics are fairly useless --
-  equality of two references means that they refer to the same object.
-  */
-  bool operator==(const cAnalyzeCommand &in) const { return &in == this; }
-};
-
-#endif

Deleted: trunk/source/main/analyze_command_def.hh
===================================================================
--- trunk/source/main/analyze_command_def.hh	2005-09-15 23:16:19 UTC (rev 313)
+++ trunk/source/main/analyze_command_def.hh	2005-09-16 02:10:20 UTC (rev 314)
@@ -1,37 +0,0 @@
-//////////////////////////////////////////////////////////////////////////////
-// Copyright (C) 1993 - 2003 California Institute of Technology             //
-//                                                                          //
-// Read the COPYING and README files, or contact 'avida at alife.org',         //
-// before continuing.  SOME RESTRICTIONS MAY APPLY TO USE OF THIS FILE.     //
-//////////////////////////////////////////////////////////////////////////////
-
-#ifndef ANALYZE_COMMAND_DEF_HH
-#define ANALYZE_COMMAND_DEF_HH
-
-#ifndef ANALYZE_COMMAND_DEF_BASE_HH
-#include "analyze_command_def_base.hh"
-#endif
-#ifndef STRING_HH
-#include "string.hh"
-#endif
-
-class cAnalyze;
-class cString; // aggregate
-class cAnalyzeCommand;
-
-class cAnalyzeCommandDef : public cAnalyzeCommandDefBase {
-private:
-  void (cAnalyze::*CommandFunction)(cString);
-public:
-  cAnalyzeCommandDef(const cString & _name, void (cAnalyze::*_cf)(cString))
-    : cAnalyzeCommandDefBase(_name), CommandFunction(_cf) { ; }
-  virtual ~cAnalyzeCommandDef() { ; }
-
-  virtual void Run(cAnalyze * analyze, const cString & args,
-		   cAnalyzeCommand & command) const {
-    (void) command; // used in other types of command defininitions.
-    (analyze->*CommandFunction)(args);
-  }
-};
-
-#endif

Deleted: trunk/source/main/analyze_command_def_base.hh
===================================================================
--- trunk/source/main/analyze_command_def_base.hh	2005-09-15 23:16:19 UTC (rev 313)
+++ trunk/source/main/analyze_command_def_base.hh	2005-09-16 02:10:20 UTC (rev 314)
@@ -1,33 +0,0 @@
-//////////////////////////////////////////////////////////////////////////////
-// Copyright (C) 1993 - 2003 California Institute of Technology             //
-//                                                                          //
-// Read the COPYING and README files, or contact 'avida at alife.org',         //
-// before continuing.  SOME RESTRICTIONS MAY APPLY TO USE OF THIS FILE.     //
-//////////////////////////////////////////////////////////////////////////////
-
-#ifndef ANALYZE_COMMAND_DEF_BASE_HH
-#define ANALYZE_COMMAND_DEF_BASE_HH
-
-#ifndef STRING_HH
-#include "string.hh"
-#endif
-
-class cString; // aggregate
-class cAnalyze;
-class cAnalyzeCommand;
-
-class cAnalyzeCommandDefBase {
-protected:
-  cString name;
-public:
-  cAnalyzeCommandDefBase(const cString & _name) : name(_name) { ; }
-  virtual ~cAnalyzeCommandDefBase() { ; }
-
-  virtual void Run(cAnalyze * analyze, const cString & args,
-		   cAnalyzeCommand & command) const = 0;
-  virtual bool IsFlowCommand() { return false; }
-
-  const cString & GetName() const { return name; }
-};
-
-#endif

Deleted: trunk/source/main/analyze_flow_command.hh
===================================================================
--- trunk/source/main/analyze_flow_command.hh	2005-09-15 23:16:19 UTC (rev 313)
+++ trunk/source/main/analyze_flow_command.hh	2005-09-16 02:10:20 UTC (rev 314)
@@ -1,36 +0,0 @@
-//////////////////////////////////////////////////////////////////////////////
-// Copyright (C) 1993 - 2003 California Institute of Technology             //
-//                                                                          //
-// Read the COPYING and README files, or contact 'avida at alife.org',         //
-// before continuing.  SOME RESTRICTIONS MAY APPLY TO USE OF THIS FILE.     //
-//////////////////////////////////////////////////////////////////////////////
-
-#ifndef ANALYZE_FLOW_COMMAND_HH
-#define ANALYZE_FLOW_COMMAND_HH
-
-#ifndef ANALYZE_COMMAND_HH
-#include "analyze_command.hh"
-#endif
-#ifndef TLIST_HH
-#include "tList.hh"
-#endif
-
-// cAnalyzeFlowCommand : A cAnalyzeCommand containing other commands
-
-template <class T> class tList; // aggregate
-class cString;
-
-class cAnalyzeFlowCommand : public cAnalyzeCommand {
-protected:
-  tList<cAnalyzeCommand> command_list;
-public:
-  cAnalyzeFlowCommand(const cString & _command, const cString & _args)
-    : cAnalyzeCommand(_command, _args) { ; }
-  virtual ~cAnalyzeFlowCommand() {
-    while ( command_list.GetSize() > 0 ) delete command_list.Pop();
-  }
-
-  tList<cAnalyzeCommand> * GetCommandList() { return &command_list; }
-};
-
-#endif

Deleted: trunk/source/main/analyze_flow_command_def.hh
===================================================================
--- trunk/source/main/analyze_flow_command_def.hh	2005-09-15 23:16:19 UTC (rev 313)
+++ trunk/source/main/analyze_flow_command_def.hh	2005-09-16 02:10:20 UTC (rev 314)
@@ -1,46 +0,0 @@
-//////////////////////////////////////////////////////////////////////////////
-// Copyright (C) 1993 - 2003 California Institute of Technology             //
-//                                                                          //
-// Read the COPYING and README files, or contact 'avida at alife.org',         //
-// before continuing.  SOME RESTRICTIONS MAY APPLY TO USE OF THIS FILE.     //
-//////////////////////////////////////////////////////////////////////////////
-
-#ifndef ANALYZE_FLOW_COMMAND_DEF_HH
-#define ANALYZE_FLOW_COMMAND_DEF_HH
-
-#ifndef ANALYZE_COMMAND_HH
-#include "analyze_command.hh"
-#endif
-#ifndef ANALYZE_COMMAND_DEF_BASE_HH
-#include "analyze_command_def_base.hh"
-#endif
-#ifndef STRING_HH
-#include "string.hh"
-#endif
-#ifndef TLIST_HH
-#include "tList.hh"
-#endif
-
-class cAnalyze;
-template <class T> class tList;
-class cAnalyzeCommand; // access
-class cString; // aggregate
-
-class cAnalyzeFlowCommandDef : public cAnalyzeCommandDefBase {
-private:
-  void (cAnalyze::*CommandFunction)(cString, tList<cAnalyzeCommand> &);
-public:
-  cAnalyzeFlowCommandDef(const cString &_name,
-	 void (cAnalyze::*_cf)(cString, tList<cAnalyzeCommand> &))
-    : cAnalyzeCommandDefBase(_name), CommandFunction(_cf) { ; }
-  virtual ~cAnalyzeFlowCommandDef() { ; }
-			 
-  virtual void Run(cAnalyze * analyze, const cString & args,
-		   cAnalyzeCommand & command) const {
-    (analyze->*CommandFunction)(args, *(command.GetCommandList()) );
-  }
-
-  virtual bool IsFlowCommand() { return true; }
-};
-
-#endif

Deleted: trunk/source/main/analyze_function.hh
===================================================================
--- trunk/source/main/analyze_function.hh	2005-09-15 23:16:19 UTC (rev 313)
+++ trunk/source/main/analyze_function.hh	2005-09-16 02:10:20 UTC (rev 314)
@@ -1,44 +0,0 @@
-//////////////////////////////////////////////////////////////////////////////
-// Copyright (C) 1993 - 2003 California Institute of Technology             //
-//                                                                          //
-// Read the COPYING and README files, or contact 'avida at alife.org',         //
-// before continuing.  SOME RESTRICTIONS MAY APPLY TO USE OF THIS FILE.     //
-//////////////////////////////////////////////////////////////////////////////
-
-#ifndef ANALYZE_FUNCTION_HH
-#define ANALYZE_FUNCTION_HH
-
-#ifndef ANALYZE_COMMAND_HH
-#include "analyze_command.hh"
-#endif
-#ifndef STRING_HH
-#include "string.hh"
-#endif
-#ifndef TLIST_HH
-#include "tList.hh"
-#endif
-
-// cAnalyzeFunction    : User-defined function
-
-class cString; // aggregate
-template <class T> class tList; // aggregate
-class cAnalyzeCommand;
-
-class cAnalyzeFunction {
-private:
-  cString name;
-  tList<cAnalyzeCommand> command_list;
-private:
-  // disabled copy constructor.
-  cAnalyzeFunction(const cAnalyzeFunction &);
-public:
-  cAnalyzeFunction(const cString & _name) : name(_name) { ; }
-  ~cAnalyzeFunction() { 
-    while ( command_list.GetSize() > 0 ) delete command_list.Pop();
-  }
-
-  const cString & GetName() { return name; }
-  tList<cAnalyzeCommand> * GetCommandList() { return &command_list; }
-};
-
-#endif

Deleted: trunk/source/main/analyze_genotype.cc
===================================================================
--- trunk/source/main/analyze_genotype.cc	2005-09-15 23:16:19 UTC (rev 313)
+++ trunk/source/main/analyze_genotype.cc	2005-09-16 02:10:20 UTC (rev 314)
@@ -1,331 +0,0 @@
-//////////////////////////////////////////////////////////////////////////////
-// Copyright (C) 1993 - 2003 California Institute of Technology             //
-//                                                                          //
-// Read the COPYING and README files, or contact 'avida at alife.org',         //
-// before continuing.  SOME RESTRICTIONS MAY APPLY TO USE OF THIS FILE.     //
-//////////////////////////////////////////////////////////////////////////////
-
-#include "analyze_genotype.hh"
-
-#include "config.hh"
-#include "cCPUTestInfo.h"
-#include "inst_set.hh"
-#include "landscape.hh"
-#include "organism.hh"
-#include "phenotype.hh"
-#include "cTestCPU.h"
-
-using namespace std;
-
-//////////////////////
-//  cAnalyzeGenotype
-//////////////////////
-
-cAnalyzeGenotype::cAnalyzeGenotype(cString symbol_string,
-				   cInstSet & in_inst_set)
-  : genome(symbol_string)
-  , inst_set(in_inst_set)
-  , name("")
-  , aligned_sequence("")
-  , tag("")
-  , viable(false)
-  , id_num(-1)
-  , parent_id(-1)
-  , parent2_id(-1)
-  , num_cpus(0)
-  , total_cpus(0)
-  , update_born(0)
-  , update_dead(0)
-  , depth(0)
-  , length(0)
-  , copy_length(0)
-  , exe_length(0)
-  , merit(0.0)
-  , gest_time(INT_MAX)
-  , fitness(0.0)
-  , errors(0)
-  , task_counts(0)
-  , fitness_ratio(0.0)
-  , efficiency_ratio(0.0)
-  , comp_merit_ratio(0.0)
-  , parent_dist(0)
-  , ancestor_dist(0)
-  , parent_muts("")
-  , landscape_stats(NULL)
-{
-  // Make sure that the sequences jive with the inst_set
-  for (int i = 0; i < genome.GetSize(); i++) {
-    if (genome[i].GetOp() >= inst_set.GetSize()) {
-      cerr << "Error: Trying to load instruction " << genome[i].GetOp()
-	   << ".  Max in set is" << inst_set.GetSize() - 1
-	   << endl;
-    }
-  }
-}
-
-cAnalyzeGenotype::cAnalyzeGenotype(const cGenome & _genome,
-				   cInstSet & in_inst_set)
-  : genome(_genome)
-  , inst_set(in_inst_set)
-  , name("")
-  , aligned_sequence("")
-  , tag("")
-  , viable(false)
-  , id_num(-1)
-  , parent_id(-1)
-  , parent2_id(-1)
-  , num_cpus(0)
-  , total_cpus(0)
-  , update_born(0)
-  , update_dead(0)
-  , depth(0)
-  , length(0)
-  , copy_length(0)
-  , exe_length(0)
-  , merit(0.0)
-  , gest_time(INT_MAX)
-  , fitness(0.0)
-  , errors(0)
-  , task_counts(0)
-  , fitness_ratio(0.0)
-  , efficiency_ratio(0.0)
-  , comp_merit_ratio(0.0)
-  , parent_dist(0)
-  , ancestor_dist(0)
-  , parent_muts("")
-  , landscape_stats(NULL)
-{
-}
-
-cAnalyzeGenotype::cAnalyzeGenotype(const cAnalyzeGenotype & _gen)
-  : genome(_gen.genome)
-  , inst_set(_gen.inst_set)
-  , name(_gen.name)
-  , aligned_sequence(_gen.aligned_sequence)
-  , tag(_gen.tag)
-  , viable(_gen.viable)
-  , id_num(_gen.id_num)
-  , parent_id(_gen.parent_id)
-  , parent2_id(_gen.parent2_id)
-  , num_cpus(_gen.num_cpus)
-  , total_cpus(_gen.total_cpus)
-  , update_born(_gen.update_born)
-  , update_dead(_gen.update_dead)
-  , depth(_gen.depth)
-  , length(_gen.length)
-  , copy_length(_gen.copy_length)
-  , exe_length(_gen.exe_length)
-  , merit(_gen.merit)
-  , gest_time(_gen.gest_time)
-  , fitness(_gen.fitness)
-  , errors(_gen.errors)
-  , task_counts(_gen.task_counts)
-  , fitness_ratio(_gen.fitness_ratio)
-  , efficiency_ratio(_gen.efficiency_ratio)
-  , comp_merit_ratio(_gen.comp_merit_ratio)
-  , parent_dist(_gen.parent_dist)
-  , ancestor_dist(_gen.ancestor_dist)
-  , parent_muts(_gen.parent_muts)
-  , landscape_stats(NULL)
-{
-  if (_gen.landscape_stats != NULL) {
-    landscape_stats = new cAnalyzeLandscape;
-    *landscape_stats = *(_gen.landscape_stats);
-  }
-}
-
-cAnalyzeGenotype::~cAnalyzeGenotype()
-{
-  if (landscape_stats != NULL) delete landscape_stats;
-}
-
-
-int cAnalyzeGenotype::CalcMaxGestation() const
-{
-  return cConfig::GetTestCPUTimeMod() * genome.GetSize();
-}
-
-void cAnalyzeGenotype::CalcLandscape() const
-{
-  if (landscape_stats != NULL) return;
-
-  landscape_stats = new cAnalyzeLandscape;
-  cLandscape landscape(genome, inst_set);
-  landscape.Process(1);
-  landscape_stats->frac_dead = landscape.GetProbDead();
-  landscape_stats->frac_neg  = landscape.GetProbNeg();
-  landscape_stats->frac_neut = landscape.GetProbNeut();
-  landscape_stats->frac_pos  = landscape.GetProbPos();
-}
-
-void cAnalyzeGenotype::Recalculate(cAnalyzeGenotype * parent_genotype)
-{
-    // Build the test info for printing.
-  cCPUTestInfo test_info;
-  test_info.TestThreads();
-  // test_info.TraceTaskOrder();
-
-  // Use the inst lib for this genotype...
-  cInstSet * inst_set_backup = cTestCPU::GetInstSet();
-  cTestCPU::SetInstSet(&inst_set);
-  cTestCPU::TestGenome(test_info, genome);
-  cTestCPU::SetInstSet(inst_set_backup);
-
-  viable = test_info.IsViable();
-
-  cOrganism * test_organism = test_info.GetTestOrganism();
-  cPhenotype & test_phenotype = test_organism->GetPhenotype();
-
-  length = test_organism->GetGenome().GetSize();
-  copy_length = test_phenotype.GetCopiedSize();
-  exe_length = test_phenotype.GetExecutedSize();
-  merit = test_phenotype.GetMerit().GetDouble();
-  gest_time = test_phenotype.GetGestationTime();
-  fitness = test_phenotype.GetFitness();
-  errors = test_phenotype.GetLastNumErrors();
-  div_type = test_phenotype.GetDivType();
-  mate_id = test_phenotype.MateSelectID();
-  task_counts = test_phenotype.GetLastTaskCount();
-
-  // Setup a new parent stats if we have a parent to work with.
-  if (parent_genotype != NULL) {
-    fitness_ratio = GetFitness() / parent_genotype->GetFitness();
-    efficiency_ratio = GetEfficiency() / parent_genotype->GetEfficiency();
-    comp_merit_ratio = GetCompMerit() / parent_genotype->GetCompMerit();
-    parent_dist = cStringUtil::EditDistance(genome.AsString(),
-		    parent_genotype->GetGenome().AsString(), parent_muts);
-    ancestor_dist = parent_genotype->GetAncestorDist() + parent_dist;
-  }
-}
-
-
-void cAnalyzeGenotype::PrintTasks(ofstream & fp, int min_task, int max_task)
-{
-  if (max_task == -1) max_task = task_counts.GetSize();
-
-  for (int i = min_task; i < max_task; i++) {
-    fp << task_counts[i] << " ";
-  }
-}
-
-void cAnalyzeGenotype::SetSequence(cString _sequence)
-{
-  cGenome new_genome(_sequence);
-  genome = new_genome;
-}
-
-
-double cAnalyzeGenotype::GetFracDead() const
-{
-  CalcLandscape();  // Make sure the landscape is calculated...
-  return landscape_stats->frac_dead;
-}
-
-double cAnalyzeGenotype::GetFracNeg() const
-{
-  CalcLandscape();  // Make sure the landscape is calculated...
-  return landscape_stats->frac_neg;
-}
-
-double cAnalyzeGenotype::GetFracNeut() const
-{
-  CalcLandscape();  // Make sure the landscape is calculated...
-  return landscape_stats->frac_neut;
-}
-
-double cAnalyzeGenotype::GetFracPos() const
-{
-  CalcLandscape();  // Make sure the landscape is calculated...
-  return landscape_stats->frac_pos;
-}
-
-
-cString cAnalyzeGenotype::GetTaskList() const
-{
-  const int num_tasks = task_counts.GetSize();
-  cString out_string(num_tasks);
-  
-  for (int i = 0; i < num_tasks; i++) {
-    const int cur_count = task_counts[i];
-    if (cur_count < 10) {
-      out_string[i] = '0' + cur_count;
-    }
-    else if (cur_count < 30) {
-      out_string[i] = 'X';
-    }
-    else if (cur_count < 80) {
-      out_string[i] = 'L';
-    }
-    else if (cur_count < 300) {
-      out_string[i] = 'C';
-    }
-    else if (cur_count < 800) {
-      out_string[i] = 'D';
-    }
-    else if (cur_count < 3000) {
-      out_string[i] = 'M';
-    }
-    else {
-      out_string[i] = '+';
-    }
-  }
-
-  return out_string;
-}
-
-
-cString cAnalyzeGenotype::GetHTMLSequence() const
-{
-  cString text_genome = genome.AsString();
-  cString html_code("<tt>");
-
-  cString diff_info = parent_muts;
-  char mut_type = 'N';
-  int mut_pos = -1;
-
-  cString cur_mut = diff_info.Pop(',');
-  if (cur_mut != "") {
-    mut_type = cur_mut[0];
-    cur_mut.ClipFront(1); cur_mut.ClipEnd(1);
-    mut_pos = cur_mut.AsInt();
-  }
-
-  int ins_count = 0;
-  for (int i = 0; i < genome.GetSize(); i++) {
-    char symbol = text_genome[i];
-    if (i != mut_pos) html_code += symbol;
-    else {
-      // Figure out the information for the type of mutation we had...
-      cString color;
-      if (mut_type == 'M') {
-	color = "#FF0000";	
-      } else if (mut_type == 'I') {
-	color = "#00FF00";
-	ins_count++;
-      } else { // if (mut_type == 'D') {
-	color = "#0000FF";
-	symbol = '*';
-	i--;  // Rewind - we didn't read the handle character yet!
-      }
-
-      // Move on to the next mutation...
-      cur_mut = diff_info.Pop(',');
-      if (cur_mut != "") {
-	mut_type = cur_mut[0];
-	cur_mut.ClipFront(1); cur_mut.ClipEnd(1);
-	mut_pos = cur_mut.AsInt();
-	if (mut_type == 'D') mut_pos += ins_count;
-      } else mut_pos = -1;
-
-      // Tack on the current symbol...
-      cString symbol_string;
-      symbol_string.Set("<b><font color=\"%s\">%c</font></b>",
-			color(), symbol);
-      html_code += symbol_string;
-    }
-  }
-
-  html_code += "</tt>";
-
-  return html_code;
-}

Deleted: trunk/source/main/analyze_genotype.hh
===================================================================
--- trunk/source/main/analyze_genotype.hh	2005-09-15 23:16:19 UTC (rev 313)
+++ trunk/source/main/analyze_genotype.hh	2005-09-16 02:10:20 UTC (rev 314)
@@ -1,263 +0,0 @@
-//////////////////////////////////////////////////////////////////////////////
-// Copyright (C) 1993 - 2003 California Institute of Technology             //
-//                                                                          //
-// Read the COPYING and README files, or contact 'avida at alife.org',         //
-// before continuing.  SOME RESTRICTIONS MAY APPLY TO USE OF THIS FILE.     //
-//////////////////////////////////////////////////////////////////////////////
-
-#ifndef ANALYZE_GENOTYPE_HH
-#define ANALYZE_GENOTYPE_HH
-
-#include <fstream>
-
-#ifndef FUNCTIONS_HH
-#include "functions.hh"
-#endif
-#ifndef GENOME_HH
-#include "genome.hh"
-#endif
-#ifndef STRING_HH
-#include "string.hh"
-#endif
-#ifndef STRING_LIST_HH
-#include "string_list.hh"
-#endif
-#ifndef STRING_UTIL_HH
-#include "string_util.hh"
-#endif
-#ifndef TARRAY_HH
-#include "tArray.hh"
-#endif
-
-// cAnalyzeGenotype    : Collection of information about loaded genotypes
-
-class cGenome; // aggregate
-class cInstSet;
-class cString; // aggregate
-template <class T> class tArray; // aggregate
-class cStringList; // aggregate
-class cStringUtil; // access
-
-class cAnalyzeGenotype {
-private:
-  cGenome genome;            // Full Genome
-  cInstSet & inst_set;       // Instruction set used in this genome
-  cString name;              // Name, if one was provided in loading
-  cString aligned_sequence;  // Sequence (in ASCII) after alignment
-  cString tag;               // All genotypes in a batch can be tagged
-
-  bool viable;
-
-  // Group 1 : Load-in Stats (Only obtained if available for input file)
-  int id_num;
-  int parent_id;
-  int parent2_id;
-  int num_cpus;
-  int total_cpus;
-  int update_born;
-  int update_dead;
-  int depth;
-
-  // Group 2 : Basic Execution Stats (Obtained from test CPUs)
-  int length;
-  int copy_length;
-  int exe_length;
-  double merit;
-  int gest_time;
-  double fitness;
-  int errors;
-  double div_type;
-  int mate_id;
-
-  tArray<int> task_counts;
-
-  // Group 3 : Stats requiring parental genotype (Also from test CPUs)
-  double fitness_ratio;
-  double efficiency_ratio;
-  double comp_merit_ratio;
-  int parent_dist;
-  int ancestor_dist;
-  int lineage_label;
-  cString parent_muts;
-
-  // Group 4 : Landscape stats (obtained from testing all possible mutations)
-  class cAnalyzeLandscape {
-  public:
-    double frac_dead;
-    double frac_neg;
-    double frac_neut;
-    double frac_pos;
-    cAnalyzeLandscape() : frac_dead(0.0), frac_neg(0.0),
-			  frac_neut(0.0), frac_pos(0.0) { ; }
-  };
-  mutable cAnalyzeLandscape * landscape_stats;
-
-  // Group 5 : More complex stats (obtained indvidually, through tests)
-  cString task_order;
-
-  cStringList special_args; // These are args placed after a ':' in details...
-
-  int NumCompare(double new_val, double old_val) const {
-    if (new_val == old_val) return  0;
-    else if (new_val == 0)       return -2;
-    else if (old_val == 0)       return +2;
-    else if (new_val < old_val)  return -1;
-    // else if (new_val > old_val)
-    return +1;
-  }
-
-  int CalcMaxGestation() const;
-  void CalcLandscape() const;
-public:
-  cAnalyzeGenotype(cString symbol_string, cInstSet & in_inst_set);
-  cAnalyzeGenotype(const cGenome & _genome, cInstSet & in_inst_set);
-  cAnalyzeGenotype(const cAnalyzeGenotype & _gen);
-  ~cAnalyzeGenotype();
-
-  const cStringList & GetSpecialArgs() { return special_args; }
-  void SetSpecialArgs(const cStringList & _args) { special_args = _args; }
-
-  void Recalculate(cAnalyzeGenotype * parent_genotype=NULL);
-  void PrintTasks(std::ofstream & fp, int min_task=0, int max_task=-1);
-
-  // Set...
-  void SetSequence(cString _sequence);
-  
-  void SetName(const cString & _name) { name = _name; }
-  void SetAlignedSequence(const cString & _seq) { aligned_sequence = _seq; }
-  void SetTag(const cString & _tag) { tag = _tag; }
-
-  void SetViable(bool _viable) { viable = _viable; }
-
-  void SetID(int _id) { id_num = _id; }
-  void SetParentID(int _id) { parent_id = _id; }
-  void SetParent2ID(int _id) { parent2_id = _id; }
-  void SetNumCPUs(int _cpus) { num_cpus = _cpus; }
-  void SetTotalCPUs(int _cpus) { total_cpus = _cpus; }
-  void SetUpdateBorn(int _born) { update_born = _born; }
-  void SetUpdateDead(int _dead) { update_dead = _dead; }
-  void SetDepth(int _depth) { depth = _depth; }
-
-  void SetLength(int _length) { length = _length; }
-  void SetCopyLength(int _length) { copy_length = _length; }
-  void SetExeLength(int _length) { exe_length = _length; }
-  void SetMerit(double _merit) { merit = _merit; }
-  void SetGestTime(int _gest) { gest_time = _gest; }
-  void SetFitness(double _fitness) { fitness = _fitness; }
-  void SetDivType(double _div_type) { div_type = _div_type; }
-  void SetMateID(int _mate_id) { mate_id = _mate_id; }
-  void SetParentDist(int _dist) { parent_dist = _dist; }
-  void SetAncestorDist(int _dist) { ancestor_dist = _dist; }
-  void SetLineageLabel(int _label) { lineage_label = _label; }
-
-  void SetParentMuts(const cString & in_muts) { parent_muts = in_muts; }
-  void SetTaskOrder(const cString & in_order) { task_order = in_order; }
-
-//    void SetFracDead(double in_frac);
-//    void SetFracNeg(double in_frac);
-//    void SetFracNeut(double in_frac);
-//    void SetFracPos(double in_frac);
-
-  // Accessors...
-  const cGenome & GetGenome() const { return genome; }
-  const cString & GetName() const { return name; }
-  const cString & GetAlignedSequence() const { return aligned_sequence; }
-  const cString & GetTag() const { return tag; }
-
-  bool GetViable() const { return viable; }
-
-  int GetID() const { return id_num; }
-  int GetParentID() const { return parent_id; }
-  int GetParent2ID() const { return parent2_id; }
-  int GetParentDist() const { return parent_dist; }
-  int GetAncestorDist() const { return ancestor_dist; }
-  int GetLineageLabel() const { return lineage_label; }
-  int GetNumCPUs() const { return num_cpus; }
-  int GetTotalCPUs() const { return total_cpus; }
-  int GetLength() const { return length; }
-  int GetCopyLength() const { return copy_length; }
-  int GetExeLength() const { return exe_length; }
-  int GetMinLength() const { return Min(exe_length, copy_length); }
-  double GetMerit() const { return merit; }
-  double GetCompMerit() const { return merit / (double) GetMinLength(); }
-  int GetGestTime() const { return gest_time; }
-  double GetEfficiency() const
-    { return ((double) GetMinLength()) / (double) gest_time; }
-  double GetFitness() const { return fitness; }
-  double GetDivType() const { return div_type; }
-  int GetMateID() const { return mate_id; }
-  int GetUpdateBorn() const { return update_born; }
-  int GetUpdateDead() const { return update_dead; }
-  int GetDepth() const { return depth; }
-
-  const cString & GetParentMuts() const { return parent_muts; }
-
-  double GetFracDead() const;
-  double GetFracNeg() const;
-  double GetFracNeut() const;
-  double GetFracPos() const;
-
-  double GetFitnessRatio() const { return fitness_ratio; }
-  double GetEfficiencyRatio() const { return efficiency_ratio; }
-  double GetCompMeritRatio() const { return comp_merit_ratio; }
-
-  const cString & GetTaskOrder() const { return task_order; }
-  cString GetTaskList() const;
-
-  cString GetSequence() const { return genome.AsString(); }
-  cString GetHTMLSequence() const;
-
-  cString GetMapLink() const {
-    return cStringUtil::Stringf("<a href=\"tasksites.%s.html\">Phenotype Map</a>", GetName()());
-  }
-
-  int GetNumTasks() const { return task_counts.GetSize(); }
-  int GetTaskCount(int task_id) const {
-    if (task_id >= task_counts.GetSize()) return 0;
-    if (special_args.HasString("binary")) return (task_counts[task_id] > 0);
-    return task_counts[task_id];
-  }
-
-  // Comparisons...  Compares a genotype to the "previous" one, which is
-  // passed in, in one specified phenotype.
-  // Return values are:
-  //   -2 : Toggle; no longer has phenotype it used to...
-  //   -1 : Reduction in strength of phenotype
-  //    0 : Identical in phenotype
-  //   +1 : Improvement in phenotype
-  //   +2 : Toggle; phenotype now present that wasn't.
-  int CompareNULL(cAnalyzeGenotype * prev) const { (void) prev; return 0; }
-  int CompareArgNULL(cAnalyzeGenotype * prev, int i) const
-    { (void) prev; (void) i;  return 0; }
-  int CompareLength(cAnalyzeGenotype * prev) const {
-    if (GetLength() < MIN_CREATURE_SIZE &&
-	prev->GetLength() > MIN_CREATURE_SIZE) return -2;
-    if (GetLength() > MIN_CREATURE_SIZE &&
-	prev->GetLength() < MIN_CREATURE_SIZE) return 2;
-    return 0;
-  }
-  int CompareMerit(cAnalyzeGenotype * prev) const
-    { return NumCompare(GetMerit(), prev->GetMerit()); }
-  int CompareCompMerit(cAnalyzeGenotype * prev) const
-    { return NumCompare(GetCompMerit(), prev->GetCompMerit()); }
-  int CompareGestTime(cAnalyzeGenotype * prev) const {
-    const int max_time = CalcMaxGestation();
-    const int cur_time = max_time - GetGestTime();
-    const int prev_time = max_time - prev->GetGestTime();
-    return NumCompare(cur_time, prev_time);
-  }
-  int CompareEfficiency(cAnalyzeGenotype * prev) const
-    { return NumCompare(GetEfficiency(), prev->GetEfficiency()); }
-  int CompareFitness(cAnalyzeGenotype * prev) const
-    { return NumCompare(GetFitness(), prev->GetFitness()); }
-  int CompareTaskCount(cAnalyzeGenotype * prev, int task_id) const
-    { return NumCompare(GetTaskCount(task_id), prev->GetTaskCount(task_id)); }
-
-  /*
-  added to satisfy Boost.Python; the semantics are fairly useless --
-  equality of two references means that they refer to the same object.
-  */
-  bool operator==(const cAnalyzeGenotype &in) const { return &in == this; }
-};
-
-#endif

Deleted: trunk/source/main/analyze_util.cc
===================================================================
--- trunk/source/main/analyze_util.cc	2005-09-15 23:16:19 UTC (rev 313)
+++ trunk/source/main/analyze_util.cc	2005-09-16 02:10:20 UTC (rev 314)
@@ -1,997 +0,0 @@
-//////////////////////////////////////////////////////////////////////////////
-// Copyright (C) 1993 - 2001 California Institute of Technology             //
-//                                                                          //
-// Read the COPYING and README files, or contact 'avida at alife.org',         //
-// before continuing.  SOME RESTRICTIONS MAY APPLY TO USE OF THIS FILE.     //
-//////////////////////////////////////////////////////////////////////////////
-
-#ifndef ANALYZE_UTIL_HH
-#include "analyze_util.hh"
-#endif
-
-#ifndef CONFIG_HH
-#include "config.hh"
-#endif
-#ifndef DEFS_HH
-#include "defs.hh"
-#endif
-#ifndef ENVIRONMENT_HH
-#include "environment.hh"
-#endif
-#ifndef GENEBANK_HH
-#include "genebank.hh"
-#endif
-#ifndef GENOME_HH
-#include "genome.hh"
-#endif
-#ifndef GENOME_UTIL_HH
-#include "genome_util.hh"
-#endif
-#ifndef GENOTYPE_HH
-#include "genotype.hh"
-#endif
-#ifndef HARDWARE_BASE_HH
-#include "cHardwareBase.h"
-#endif
-#ifndef HISTOGRAM_HH
-#include "histogram.hh"
-#endif
-#ifndef INST_SET_HH
-#include "inst_set.hh"
-#endif
-#ifndef INST_UTIL_HH
-#include "inst_util.hh"
-#endif
-#ifndef LANDSCAPE_HH
-#include "landscape.hh"
-#endif
-#ifndef ORGANISM_HH
-#include "organism.hh"
-#endif
-#ifndef PHENOTYPE_HH
-#include "phenotype.hh"
-#endif
-#ifndef POPULATION_HH
-#include "population.hh"
-#endif
-#ifndef POPULATION_CELL_HH
-#include "population_cell.hh"
-#endif
-#ifndef SPECIES_HH
-#include "species.hh"
-#endif
-#ifndef STATS_HH
-#include "stats.hh"
-#endif
-#ifndef TEST_CPU_HH
-#include "cTestCPU.h"
-#endif
-#ifndef TEST_UTIL_HH
-#include "cTestUtil.h"
-#endif
-#ifndef TOOLS_HH
-#include "tools.hh"
-#endif
-
-#include <vector>
-
-using namespace std;
-
-void cAnalyzeUtil::TestGenome(const cGenome & genome, cInstSet & inst_set,
-			      ofstream & fp, int update)
-{
-  cCPUTestInfo test_info;
-  cTestCPU::TestGenome(test_info, genome);
-
-  cPhenotype &colony_phenotype = test_info.GetColonyOrganism()->GetPhenotype();
-  fp << update << " "                                //  1
-     << colony_phenotype.GetMerit().GetDouble() << " "            //  2
-     << colony_phenotype.GetGestationTime() << " "             //  3
-     << colony_phenotype.GetFitness() << " "                      //  4
-     << 1.0 / (0.1  + colony_phenotype.GetGestationTime()) << " " //  5
-     << genome.GetSize() << " "                                   //  6
-     << colony_phenotype.GetCopiedSize() << " "                   //  7
-     << colony_phenotype.GetExecutedSize() << endl;               //  8
-}
-
-
-
-void cAnalyzeUtil::TestInsSizeChangeRobustness(ofstream & fp,
-		    const cInstSet & inst_set, const cGenome & in_genome,
-		    int num_trials, int update)
-{
-  cCPUTestInfo test_info;
-  const cInstruction inst_none = inst_set.GetInst("instruction_none");
-
-  // Stats
-  int num_viable = 0;
-  int num_new_size = 0;
-  int num_parent_size = 0;
-
-  for (int i = 0; i < num_trials; i++) {
-    cCPUMemory genome(in_genome);
-    // Should check to only insert infront of an instruction (not a Nop)
-    int ins_pos = -1;
-    while (ins_pos < 0) {
-      ins_pos = g_random.GetUInt(genome.GetSize());
-      if( inst_set.IsNop(genome[ins_pos]) )  ins_pos = -1;
-    }
-
-    // Insert some "instruction_none" into the genome
-    const int num_nops = g_random.GetUInt(5) + 5;
-    for (int j = 0; j < num_nops; j++)  genome.Insert(ins_pos, inst_none);
-
-    // Test the genome and output stats
-    if ( cTestCPU::TestGenome(test_info, genome) ){ // Daughter viable...
-      num_viable++;
-      const double child_size =
-	test_info.GetColonyOrganism()->GetGenome().GetSize();
-
-      if (child_size == (double) in_genome.GetSize()) num_parent_size++;
-      else if (child_size == (double) genome.GetSize()) num_new_size++;
-    }
-  } // for num_trials
-
-  fp << update << " "
-     << (double) num_viable / num_trials << " "
-     << (double) num_new_size / num_trials << " "
-     << (double) num_parent_size / num_trials << " "
-     << endl;
-}
-
-
-
-// Returns the genome of maximal fitness.
-cGenome cAnalyzeUtil::CalcLandscape(int dist, const cGenome & genome,
-				    cInstSet & inst_set)
-{
-  cLandscape landscape(genome, inst_set);
-  landscape.Process(dist);
-  double peak_fitness = landscape.GetPeakFitness();
-  cGenome peak_genome = landscape.GetPeakGenome();
-
-  // Print the results.
-
-  static ofstream fp("landscape.dat");
-  static ofstream fp_entropy("land-entropy.dat");
-  static ofstream fp_count("land-sitecount.dat");
-
-  landscape.PrintStats(fp);
-  landscape.PrintEntropy(fp_entropy);
-  landscape.PrintSiteCount(fp_count);
-
-  // Repeat for Insertions...
-  landscape.Reset(genome);
-  landscape.ProcessInsert();
-  static ofstream fp_ins("landscape-ins.dat");
-  static ofstream fp_ins_count("land-ins-sitecount.dat");
-  landscape.PrintStats(fp_ins);
-  landscape.PrintSiteCount(fp_ins_count);
-  if (landscape.GetPeakFitness() > peak_fitness) {
-    peak_fitness = landscape.GetPeakFitness();
-    peak_genome = landscape.GetPeakGenome();
-  }
-
-  // And Deletions...
-  landscape.Reset(genome);
-  landscape.ProcessDelete();
-  static ofstream fp_del("landscape-del.dat");
-  static ofstream fp_del_count("land-del-sitecount.dat");
-  landscape.PrintStats(fp_del);
-  landscape.PrintSiteCount(fp_del_count);
-  if (landscape.GetPeakFitness() > peak_fitness) {
-    peak_fitness = landscape.GetPeakFitness();
-    peak_genome = landscape.GetPeakGenome();
-  }
-
-  return peak_genome;
-}
-
-
-void cAnalyzeUtil::AnalyzeLandscape(const cGenome & genome, cInstSet &inst_set,
-	       int sample_size, int min_found, int max_sample_size, int update)
-{
-  cLandscape landscape(genome, inst_set);
-
-  static ofstream fp("land_analyze.dat");
-
-  int num_found = 0;
-  for (int dist = 1; dist <= 10; dist++) {
-    landscape.Reset(genome);
-    if (dist == 1) {
-      landscape.Process(dist);
-      num_found = genome.GetSize() * (inst_set.GetSize() - 1);
-    } else {
-      num_found =
-	landscape.RandomProcess(sample_size, dist, min_found, max_sample_size);
-    }
-
-    fp << update                       << " "  // 1
-       << dist                         << " "  // 2
-       << landscape.GetProbDead()      << " "  // 3
-       << landscape.GetProbNeg()       << " "  // 4
-       << landscape.GetProbNeut()      << " "  // 5
-       << landscape.GetProbPos()       << " "  // 6
-       << landscape.GetNumTrials()     << " "  // 7
-       << num_found                    << " "  // 8
-       << landscape.GetAveFitness()    << " "  // 9
-       << landscape.GetAveSqrFitness() << " "  // 10
-       << endl;
-
-    if ((dist > 1) && (num_found < min_found)) break;
-  }
-}
-
-
-void cAnalyzeUtil::PairTestLandscape(const cGenome &genome, cInstSet &inst_set,
-				     int sample_size, int update)
-{
-  cLandscape landscape(genome, inst_set);
-
-  cString filename;
-  filename.Set("pairtest.%d.dat", update);
-  ofstream fp(filename());
-
-  if (sample_size != 0) landscape.TestPairs(sample_size, fp);
-  else landscape.TestAllPairs(fp);
-}
-
-
-void cAnalyzeUtil::CalcConsensus(cPopulation * population, int lines_saved)
-{
-  const int num_inst = population->GetEnvironment().GetInstSet().GetSize();
-  const int update = population->GetStats().GetUpdate();
-  cGenebank & genebank = population->GetGenebank();
-
-  // Setup the histogtams...
-  cHistogram * inst_hist = new cHistogram[MAX_CREATURE_SIZE];
-  for (int i = 0; i < MAX_CREATURE_SIZE; i++) inst_hist[i].Resize(num_inst,-1);
-
-  // Loop through all of the genotypes adding them to the histograms.
-  cGenotype * cur_genotype = genebank.GetBestGenotype();
-  for (int i = 0; i < genebank.GetSize(); i++) {
-    const int num_organisms = cur_genotype->GetNumOrganisms();
-    const int length = cur_genotype->GetLength();
-    const cGenome & genome = cur_genotype->GetGenome();
-
-    // Place this genotype into the histograms.
-    for (int j = 0; j < length; j++) {
-      assert(genome[j].GetOp() < num_inst);
-      inst_hist[j].Insert(genome[j].GetOp(), num_organisms);
-    }
-
-    // Mark all instructions beyond the length as -1 in histogram...
-    for (int j = length; j < MAX_CREATURE_SIZE; j++) {
-      inst_hist[j].Insert(-1, num_organisms);
-    }
-
-    // ...and advance to the next genotype...
-    cur_genotype = cur_genotype->GetNext();
-  }
-
-  // Now, lets print something!
-  static ofstream fp("consensus.dat");
-  static ofstream fp_abundance("con-abundance.dat");
-  static ofstream fp_var("con-var.dat");
-  static ofstream fp_entropy("con-entropy.dat");
-
-  // Determine the length of the concensus genome
-  int con_length;
-  for (con_length = 0; con_length < MAX_CREATURE_SIZE; con_length++) {
-    if (inst_hist[con_length].GetMode() == -1) break;
-  }
-
-  // Build the concensus genotype...
-  cGenome con_genome(con_length);
-  double total_entropy = 0.0;
-  for (int i = 0; i < MAX_CREATURE_SIZE; i++) {
-    const int mode = inst_hist[i].GetMode();
-    const int count = inst_hist[i].GetCount(mode);
-    const int total = inst_hist[i].GetCount();
-    const double entropy = inst_hist[i].GetNormEntropy();
-    if (i < con_length) total_entropy += entropy;
-
-    // Break out if ALL creatures have a -1 in this area, and we've
-    // finished printing all of the files.
-    if (mode == -1 && count == total) break;
-
-    if ( i < con_length )
-      con_genome[i].SetOp(mode);
-
-    // Print all needed files.
-    if (i < lines_saved) {
-      fp_abundance << count << " ";
-      fp_var << inst_hist[i].GetCountVariance() << " ";
-      fp_entropy << entropy << " ";
-    }
-  }
-
-  // Put end-of-lines on the files.
-  if (lines_saved > 0) {
-    fp_abundance << endl;
-    fp_var       << endl;
-    fp_entropy   << endl;
-  }
-
-  // --- Study the consensus genome ---
-
-  // Loop through genotypes again, and determine the average genetic distance.
-  cur_genotype = genebank.GetBestGenotype();
-  cDoubleSum distance_sum;
-  for (int i = 0; i < genebank.GetSize(); i++) {
-    const int num_organisms = cur_genotype->GetNumOrganisms();
-    const int cur_dist =
-      cGenomeUtil::FindEditDistance(con_genome, cur_genotype->GetGenome());
-    distance_sum.Add(cur_dist, num_organisms);
-
-    // ...and advance to the next genotype...
-    cur_genotype = cur_genotype->GetNext();
-  }
-
-  // Finally, gather last bits of data and print the results.
-  cGenotype * con_genotype = genebank.FindGenotype(con_genome, -1);
-  const int best_dist = cGenomeUtil::FindEditDistance(con_genome,
-			     genebank.GetBestGenotype()->GetGenome());
-
-  const double ave_dist = distance_sum.Average();
-  const double var_dist = distance_sum.Variance();
-  const double complexity_base = (double) con_genome.GetSize() - total_entropy;
-
-  cString con_name;
-  con_name.Set("genebank/%03d-consensus-u%i.gen", con_genome.GetSize(),update);
-  cTestUtil::PrintGenome( con_genome, con_name() );
-
-
-  if (con_genotype) {
-    fp << update                                 << " " //  1
-       << con_genotype->GetMerit()               << " " //  2
-       << con_genotype->GetGestationTime()       << " " //  3
-       << con_genotype->GetFitness()             << " " //  4
-       << con_genotype->GetReproRate()           << " " //  5
-       << con_genotype->GetLength()              << " " //  6
-       << con_genotype->GetCopiedSize()          << " " //  7
-       << con_genotype->GetExecutedSize()        << " " //  8
-       << con_genotype->GetBirths()              << " " //  9
-       << con_genotype->GetBreedTrue()           << " " // 10
-       << con_genotype->GetBreedIn()             << " " // 11
-       << con_genotype->GetNumOrganisms()        << " " // 12
-       << con_genotype->GetDepth()               << " " // 13
-       << con_genotype->GetID()                  << " " // 14
-       << update - con_genotype->GetUpdateBorn() << " " // 15
-       << best_dist                              << " " // 16
-       << ave_dist                               << " " // 17
-       << var_dist                               << " " // 18
-       << total_entropy                          << " " // 19
-       << complexity_base                        << " " // 20
-       << endl;
-  }
-  else {
-    cCPUTestInfo test_info;
-    cTestCPU::TestGenome(test_info, con_genome);
-    cPhenotype & colony_phenotype =
-      test_info.GetColonyOrganism()->GetPhenotype();
-    fp << update                                             << " "   //  1
-       << colony_phenotype.GetMerit()                        << " "  //  2
-       << colony_phenotype.GetGestationTime()                << " "  //  3
-       << colony_phenotype.GetFitness()                      << " "  //  4
-       << 1.0 / (0.1  + colony_phenotype.GetGestationTime()) << " "  //  5
-       << con_genome.GetSize()                               << " "  //  6
-       << colony_phenotype.GetCopiedSize()                   << " "  //  7
-       << colony_phenotype.GetExecutedSize()                 << " "  //  8
-       << 0                                  << " "  // Births       //  9
-       << 0                                  << " "  // Breed True   // 10
-       << 0                                  << " "  // Breed In     // 11
-       << 0                                  << " "  // Num CPUs     // 12
-       << -1                                 << " "  // Depth        // 13
-       << -1                                 << " "  // ID           // 14
-       << 0                                  << " "  // Age          // 15
-       << best_dist                                          << " "  // 16
-       << ave_dist                                           << " "  // 17
-       << var_dist                                           << " "  // 18
-       << total_entropy                                      << " "  // 19
-       << complexity_base                                    << " "  // 20
-       << endl;
-  }
-
-  // Flush the file...
-  fp.flush();
-  
-  delete [] inst_hist;
-}
-
-
-
-/**
- * This function goes through all creatures in the soup, and saves the
- * basic landscape data (neutrality, fitness, and so on) into a stream.
- *
- * @param fp The stream into which the data should be saved.
- *
- * @param sample_prob The probability with which a particular creature should
- * be analyzed (a value of 1 analyzes all creatures, a value of 0.1 analyzes
- * 10%, and so on).
- *
- * @param landscape A bool that indicates whether the creatures should be
- * landscaped (calc. neutrality and so on) or not.
- *
- * @param save_genotype A bool that indicates whether the creatures should
- * be saved or not.
- **/
-
-void cAnalyzeUtil::AnalyzePopulation(cPopulation * pop, ofstream & fp,
-	    double sample_prob, bool landscape, bool save_genotype)
-{
-  fp << "# (1) cell number (2) genotype name (3) length (4) fitness [test-cpu] (5) fitness (actual) (6) merit (7) no of breed trues occurred (8) lineage label (9) neutral metric (10) -... landscape data" << endl;
-
-  const double skip_prob = 1.0 - sample_prob;
-  for (int i = 0; i < pop->GetSize(); i++) {
-    if (pop->GetCell(i).IsOccupied() == false) continue;  // No organism...
-    if (g_random.P(skip_prob)) continue;               // Not sampled...
-
-    cOrganism * organism = pop->GetCell(i).GetOrganism();
-    cGenotype * genotype = organism->GetGenotype();
-    const cGenome & genome = organism->GetGenome();
-
-    cString creature_name;
-    if ( genotype->GetThreshold() ) creature_name = genotype->GetName();
-    else creature_name.Set("%03d-no_name-u%i-c%i", genotype->GetLength(),
-			   pop->GetStats().GetUpdate(), i );
-
-    fp << i                                     << " "  // 1 cell ID
-       << creature_name()                       << " "  // 2 name
-       << genotype->GetLength()                 << " "  // 3 length
-       << genotype->GetTestFitness()            << " "  // 4 fitness (test-cpu)
-       << organism->GetPhenotype().GetFitness() << " "  // 5 fitness (actual)
-       << organism->GetPhenotype().GetMerit()   << " "  // 6 merit
-       << genotype->GetBreedTrue()              << " "  // 7 breed true?
-       << organism->GetLineageLabel()           << " "  // 8 lineage label
-       << organism->GetPhenotype().GetNeutralMetric() << " "; // 9 neut metric
-
-    // create landscape object for this creature
-    if (landscape &&  genotype->GetTestFitness() > 0) {
-      cLandscape landscape( genome, pop->GetEnvironment().GetInstSet());
-      landscape.Process(1);
-      landscape.PrintStats(fp);
-    }
-    else fp << endl;
-    if ( save_genotype ){
-      char filename[40];
-      sprintf( filename, "genebank/%s", creature_name() );
-      cTestUtil::PrintGenome( genome, filename );
-    }
-  }
-}
-
-
-/**
- * This function prints out fitness data. The main point is that it
- * calculates the average fitness from info from the testCPU + the actual
- * merit of the organisms, and assigns zero fitness to those organisms
- * that will never reproduce.
- *
- * The function also determines the maximum fitness genotype, and can
- * produce fitness histograms.
- *
- * @param datafp A stream into which the fitness data should be written.
- * @param histofp A stream into which the fitness histogram should be
- * written.
- * @param histo_testCPU_fp A stream into which the fitness histogram as
- * determined exclusively from the test-CPU should be written.
- * @param save_max_f_genotype A bool that determines whether the genotype
- * with the maximum fitness should be saved into the genebank.
- * @param print_fitness_histo A bool that determines whether fitness
- * histograms should be written.
- * @param hist_fmax The maximum fitness value to be taken into account
- * for the fitness histograms.
- * @param hist_fstep The width of the individual bins in the fitness
- * histograms.
- **/
-
-void cAnalyzeUtil::PrintDetailedFitnessData(cPopulation *pop, ofstream &datafp,
-   ofstream & hist_fp, ofstream & histo_testCPU_fp, bool save_max_f_genotype,
-   bool print_fitness_histo, double hist_fmax, double hist_fstep)
-{
-  const int update = pop->GetStats().GetUpdate();
-  const double generation = pop->GetStats().SumGeneration().Average();
-
-  // the histogram variables
-  vector<int> histo;
-  vector<int> histo_testCPU;
-  int bins;
-
-  if ( print_fitness_histo ){
-    bins = (int) (hist_fmax / hist_fstep) + 1;
-    histo.resize( bins, 0 ); // resize and clear
-    histo_testCPU.resize( bins, 0 );
-  }
-
-  int n = 0;
-  int nhist_tot = 0;
-  int nhist_tot_testCPU = 0;
-  double fave = 0;
-  double fave_testCPU = 0;
-  double max_fitness = -1; // we set this to -1, so that even 0 is larger...
-  cGenotype * max_f_genotype = NULL;
-
-  for (int i = 0; i < pop->GetSize(); i++) {
-    if (pop->GetCell(i).IsOccupied() == false) continue;  // One use organisms.
-
-    cOrganism * organism = pop->GetCell(i).GetOrganism();
-    cGenotype * genotype = organism->GetGenotype();
-
-    cCPUTestInfo test_info;
-    cTestCPU::TestGenome( test_info, genotype->GetGenome() );
-    // We calculate the fitness based on the current merit,
-    // but with the true gestation time. Also, we set the fitness
-    // to zero if the creature is not viable.
-    const double f = ( test_info.IsViable() ) ? organism->GetPhenotype().GetMerit().CalcFitness(test_info.GetTestOrganism()->GetPhenotype().GetGestationTime()) : 0;
-    const double f_testCPU = test_info.GetColonyFitness();
-
-    // Get the maximum fitness in the population
-    // Here, we want to count only organisms that can truly replicate,
-    // to avoid complications
-    if ( f_testCPU > max_fitness &&
-	 test_info.GetTestOrganism()->GetPhenotype().CopyTrue() ){
-      max_fitness = f_testCPU;
-      max_f_genotype = genotype;
-    }
-
-    fave += f;
-    fave_testCPU += f_testCPU;
-    n += 1;
-
-
-    // histogram
-    if ( print_fitness_histo && f < hist_fmax ){
-      histo[(int) (f / hist_fstep)] += 1;
-      nhist_tot += 1;
-    }
-
-    if ( print_fitness_histo && f_testCPU < hist_fmax ){
-      histo_testCPU[(int) (f_testCPU / hist_fstep)] += 1;
-      nhist_tot_testCPU += 1;
-    }
-  }
-
-  // determine the name of the maximum fitness genotype
-  cString max_f_name;
-  if ( max_f_genotype->GetThreshold() )
-    max_f_name = max_f_genotype->GetName();
-  else // we put the current update into the name, so that it becomes unique.
-     max_f_name.Set("%03d-no_name-u%i", max_f_genotype->GetLength(),
-		    update );
-
-  datafp << update                    << " "  // 1 update
-	 << generation                << " "  // 2 generation
-	 << fave/ (double) n          << " "  // 3 average fitness
-	 << fave_testCPU/ (double) n  << " "  // 4 average test fitness
-	 << n 	                      << " "  // 5 organism total
-	 << max_fitness               << " "  // 6 maximum fitness
-	 << max_f_name()	      << " "  // 7 maxfit genotype name
-	 << endl;
-
-  if (save_max_f_genotype) {
-    char filename[40];
-    sprintf( filename, "genebank/%s", max_f_name() );
-    cTestUtil::PrintGenome( max_f_genotype->GetGenome(), filename );
-  }
-
-  if (print_fitness_histo) {
-    hist_fp << update            << " "  // 1 update
-	    << generation        << " "  // 2 generation
-	    << fave/ (double) n  << " "; // 3 average fitness
-
-    // now output the fitness histo
-    vector<int>::const_iterator it = histo.begin();
-    for ( ; it != histo.end(); it++ )
-      hist_fp << (double) (*it) / (double) nhist_tot << " ";
-    hist_fp << endl;
-
-    histo_testCPU_fp << update                    << " "  // 1 update
-		     << generation                << " "  // 2 generation
-		     << fave_testCPU/ (double) n  << " "; // 3 average fitness
-
-    // now output the fitness histo
-    it = histo_testCPU.begin();
-    for ( ; it != histo_testCPU.end(); it++ )
-      histo_testCPU_fp << (double) (*it) / (double) nhist_tot_testCPU << " ";
-    histo_testCPU_fp << endl;
-  }
-}
-
-
-/**
- * This function goes through all genotypes currently present in the soup,
- * and writes into an output file the average Hamming distance between the
- * creatures in the population and a given reference genome.
- *
- * @param fp The stream into which the data should be saved.
- * @param reference_genome The reference genome.
- * @param save_creatures A bool that indicates whether creatures should be
- * saved into the genebank or not.
- **/
-
-void cAnalyzeUtil::PrintGeneticDistanceData(cPopulation * pop, ofstream & fp,
-					    const char * creature_name)
-{
-  double hamming_m1 = 0;
-  double hamming_m2 = 0;
-  int count = 0;
-  int dom_dist = 0;
-
-  // load the reference genome
-  cGenome reference_genome(cInstUtil::LoadGenome(creature_name,
-					 pop->GetEnvironment().GetInstSet()));
-
-  // get the info for the dominant genotype
-  cGenotype * cur_genotype = pop->GetGenebank().GetBestGenotype();
-  cGenome genome = cur_genotype->GetGenome();
-  dom_dist = cGenomeUtil::FindHammingDistance( reference_genome, genome );
-  hamming_m1 += dom_dist;
-  hamming_m2 += dom_dist*dom_dist;
-  count += cur_genotype->GetNumOrganisms();
-  // now cycle over the remaining genotypes
-  for (int i = 1; i < pop->GetGenebank().GetSize(); i++) {
-    cur_genotype = cur_genotype->GetNext();
-    cGenome genome = cur_genotype->GetGenome();
-
-    int dist = cGenomeUtil::FindHammingDistance( reference_genome, genome );
-    hamming_m1 += dist;
-    hamming_m2 += dist*dist;
-    count += cur_genotype->GetNumOrganisms();
-  }
-
-  hamming_m1 /= (double) count;
-  hamming_m2 /= (double) count;
-
-  fp << pop->GetStats().GetUpdate()          << " "  // 1 update
-     << hamming_m1 			     << " "  // ave. Hamming dist
-     << sqrt( ( hamming_m2 - hamming_m1*hamming_m1 ) / (double) count )
-                                             << " "  // std. error
-     << cGenomeUtil::FindHammingDistance( reference_genome,
-	      pop->GetGenebank().GetBestGenotype()->GetGenome() ) << " "
-     << endl;
-}
-
-
-/**
- * This function goes through all genotypes currently present in the soup,
- * and writes into an output file the names of the genotypes, the fitness
- * as determined in the test cpu, and the genetic distance to a reference
- * genome.
- *
- * @param fp The stream into which the data should be saved.
- * @param reference_genome The reference genome.
- * @param save_creatures A bool that indicates whether creatures should be
- * saved into the genebank or not.
- **/
-
-void cAnalyzeUtil::GeneticDistancePopDump(cPopulation * pop, ofstream & fp,
-			 const char * creature_name, bool save_creatures)
-{
-  double sum_fitness = 0;
-  int sum_num_organisms = 0;
-
-  // load the reference genome
-  cGenome reference_genome( cInstUtil::LoadGenome(creature_name,
-				  pop->GetEnvironment().GetInstSet()) );
-
-  // first, print out some documentation...
-  fp << "# (1) genotype name (2) fitness [test-cpu] (3) abundance (4) Hamming distance to reference (5) Levenstein distance to reference" << endl;
-  fp << "# reference genome is the START_CREATURE" << endl;
-
-  // cycle over all genotypes
-  cGenotype * cur_genotype = pop->GetGenebank().GetBestGenotype();
-  for (int i = 0; i < pop->GetGenebank().GetSize(); i++) {
-    const cGenome & genome = cur_genotype->GetGenome();
-    const int num_orgs = cur_genotype->GetNumOrganisms();
-
-    // now output
-
-    sum_fitness += cur_genotype->GetTestFitness() * num_orgs;
-    sum_num_organisms += num_orgs;
-
-    fp << cur_genotype->GetName()()       << " "  // 1 name
-       << cur_genotype->GetTestFitness()  << " "  // 2 fitness
-       << num_orgs                        << " "  // 3 abundance
-       << cGenomeUtil::FindHammingDistance(reference_genome, genome) << " "
-       << cGenomeUtil::FindEditDistance(reference_genome, genome) << " "  // 5
-       << genome.AsString()()             << " "  // 6 genome
-       << endl;
-
-    // save into genebank
-    if (save_creatures) {
-      char filename[40];
-      sprintf( filename, "genebank/%s", cur_genotype->GetName()() );
-      cTestUtil::PrintGenome( genome, filename );
-    }
-
-    // ...and advance to the next genotype...
-    cur_genotype = cur_genotype->GetNext();
-  }
-  fp << "# ave fitness from Test CPU's: "
-     << sum_fitness/sum_num_organisms << endl;
-}
-
-
-/**
- * This function goes through all creatures in the soup, and writes out
- * how many tasks the different creatures have done up to now. It counts
- * every task only once, i.e., if a creature does 'put' three times, that
- * will increase its count only by one.
- *
- * @param fp The file into which the result should be written.
- **/
-
-void cAnalyzeUtil::TaskSnapshot(cPopulation * pop, ofstream & fp)
-{
-  fp << "# (1) cell number\n# (2) number of rewarded tasks done so far\n# (3) total number of tasks done so far\n# (4) same as 2, but right before divide\n# (5) same as 3, but right before divide\n# (6) same as 2, but for parent\n# (7) same as 3, but for parent\n# (8) genotype fitness\n# (9) genotype name" << endl;
-
-  for (int i = 0; i < pop->GetSize(); i++) {
-    if (pop->GetCell(i).IsOccupied() == false) continue;
-    cOrganism * organism = pop->GetCell(i).GetOrganism();
-
-    // create a test-cpu for the current creature
-    cCPUTestInfo test_info;
-    cTestCPU::TestGenome( test_info, organism->GetGenome() );
-    cPhenotype & test_phenotype = test_info.GetTestOrganism()->GetPhenotype();
-    cPhenotype & phenotype = organism->GetPhenotype();
-
-    int num_tasks = phenotype.GetEnvironment().GetTaskLib().GetSize();
-    int sum_tasks_all = 0;
-    int sum_tasks_rewarded = 0;
-    int divide_sum_tasks_all = 0;
-    int divide_sum_tasks_rewarded = 0;
-    int parent_sum_tasks_all = 0;
-    int parent_sum_tasks_rewarded = 0;
-
-    for (int j = 0; j < num_tasks; j++) {
-      // get the number of bonuses for this task
-      int bonuses = 1; //phenotype.GetTaskLib().GetTaskNumBonus(j);
-      int task_count = ( phenotype.GetCurTaskCount()[j] == 0 ) ? 0 : 1;
-      int divide_tasks_count = (test_phenotype.GetLastTaskCount()[j] == 0)?0:1;
-      int parent_task_count = (phenotype.GetLastTaskCount()[j] == 0) ? 0 : 1;
-
-      // If only one bonus, this task is not rewarded, as last bonus is + 0.
-      if (bonuses > 1) {
-	sum_tasks_rewarded += task_count;
-	divide_sum_tasks_rewarded += divide_tasks_count;
-	parent_sum_tasks_rewarded += parent_task_count;
-      }
-      sum_tasks_all += task_count;
-      divide_sum_tasks_all += divide_tasks_count;
-      parent_sum_tasks_all += parent_task_count;
-    }
-
-    fp << i                          << " " // 1 cell number
-       << sum_tasks_rewarded         << " " // 2 number of tasks rewarded
-       << sum_tasks_all              << " " // 3 total number of tasks done
-       << divide_sum_tasks_rewarded  << " " // 4 num rewarded tasks on divide
-       << divide_sum_tasks_all       << " " // 5 num total tasks on divide
-       << parent_sum_tasks_rewarded  << " " // 6 parent number of tasks rewared
-       << parent_sum_tasks_all       << " " // 7 parent total num tasks done
-       << test_info.GetColonyFitness()         << " " // 8 genotype fitness
-       << organism->GetGenotype()->GetName()() << " " // 9 genotype name
-       << endl;
-  }
-}
-
-void cAnalyzeUtil::TaskGrid(cPopulation * pop, ofstream & fp)
-{ 
-  for (int i = 0; i < pop->GetWorldX(); i++) {
-    for (int j = 0; j < pop->GetWorldY(); j++) {
-      int task_sum = 0;
-      int cell_num = i*pop->GetWorldX()+j;
-      if (pop->GetCell(cell_num).IsOccupied() == true) {
-        cOrganism * organism = pop->GetCell(cell_num).GetOrganism();
-        cCPUTestInfo test_info;
-        cTestCPU::TestGenome( test_info, organism->GetGenome() );
-        cPhenotype & test_phenotype = test_info.GetTestOrganism()->GetPhenotype();
-        int num_tasks = test_phenotype.GetEnvironment().GetTaskLib().GetSize();   
-        for (int k = 0; k < num_tasks; k++) {
-          if (test_phenotype.GetLastTaskCount()[k]>0) {
-	    task_sum = task_sum + (int) pow(2.0,k); 
-          } 
-        }
-      }
-      fp << task_sum << " ";
-    }
-    fp << endl;
-  }
-}
-
-/**
- * This function prints all the tasks that viable creatures have performed
- * so far (compare with the event 'print_task_data', which prints all tasks.
- **/
-
-void cAnalyzeUtil::PrintViableTasksData(cPopulation * pop, ofstream & fp)
-{
-  const int num_tasks = cConfig::GetNumTasks();
-
-  static vector<int> tasks(num_tasks);
-  vector<int>::iterator it;
-
-  // clear task vector
-  for (it = tasks.begin(); it != tasks.end(); it++)  (*it) = 0;
-
-  for (int i = 0; i < pop->GetSize(); i++) {
-    if (pop->GetCell(i).IsOccupied() == false) continue;
-    if (pop->GetCell(i).GetOrganism()->GetGenotype()->GetTestFitness() > 0.0) {
-      cPhenotype & phenotype = pop->GetCell(i).GetOrganism()->GetPhenotype();
-      for (int j = 0; j < num_tasks; j++) {
-	if (phenotype.GetCurTaskCount()[j] > 0)  tasks[j] += 1;
-      }
-    }
-  }
-
-  fp << pop->GetStats().GetUpdate();
-  for (it = tasks.begin(); it != tasks.end(); it++)  fp << " " << (*it);
-  fp<<endl;
-}
-
-
-void cAnalyzeUtil::PrintTreeDepths(cPopulation * pop, ofstream & fp)
-{
-  // cycle over all genotypes
-  cGenotype * genotype = pop->GetGenebank().GetBestGenotype();
-  for (int i = 0; i < pop->GetGenebank().GetSize(); i++) {
-    fp << genotype->GetID() << " "             // 1
-       << genotype->GetTestFitness() << " "    // 2
-       << genotype->GetNumOrganisms() << " "   // 3
-       << genotype->GetDepth() << " "          // 4
-       << endl;
-
-    // ...and advance to the next genotype...
-    genotype = genotype->GetNext();
-  }
-}
-
-
-void cAnalyzeUtil::PrintDepthHistogram(ofstream & fp, cPopulation * pop)
-{
-  // Output format:    update  min  max  histogram_values...
-  int min = INT_MAX;
-  int max = 0;
-  assert(fp.good());
-
-  // Two pass method
-
-  // Loop through all genotypes getting min and max values
-  cGenebank & genebank = pop->GetGenebank();
-  cGenotype * cur_genotype = genebank.GetBestGenotype();
-  for (int i = 0; i < genebank.GetSize(); i++) {
-    if (cur_genotype->GetDepth() < min) min = cur_genotype->GetDepth();
-    if (cur_genotype->GetDepth() > max) max = cur_genotype->GetDepth();
-    cur_genotype = cur_genotype->GetNext();
-  }
-  assert(max >= min);
-
-  // Allocate the array for the bins (& zero)
-  int * n = new int[max - min + 1];
-  for (int i = 0; i < max - min + 1; i++) n[i] = 0;
-
-  // Loop through all genotypes binning the values
-  cur_genotype = genebank.GetBestGenotype();
-  for (int i = 0; i < genebank.GetSize(); i++) {
-    n[cur_genotype->GetDepth() - min] += cur_genotype->GetNumOrganisms();
-    cur_genotype = cur_genotype->GetNext();
-  }
-
-  // Actual output
-  fp << pop->GetStats().GetUpdate() << " "
-     << min << " "
-     << max;
-
-  for (int i = 0; i < max - min + 1; i++)  fp << " " << n[i];
-  fp<<endl;
-}
-
-
-void cAnalyzeUtil::PrintGenotypeAbundanceHistogram(ofstream & fp,
-						   cPopulation * pop)
-{
-  assert(fp.good());
-
-  // Allocate array for the histogram & zero it
-  tArray <int> hist(pop->GetGenebank().GetBestGenotype()->GetNumOrganisms());
-  for (int i = 0; i < hist.GetSize(); i++) hist[i] = 0;
-
-  // Loop through all genotypes binning the values
-  cGenotype * cur_genotype = pop->GetGenebank().GetBestGenotype();
-  for (int i = 0; i < pop->GetGenebank().GetSize(); i++) {
-    assert( cur_genotype->GetNumOrganisms() - 1 >= 0 );
-    assert( cur_genotype->GetNumOrganisms() - 1 < hist.GetSize() );
-    hist[cur_genotype->GetNumOrganisms() - 1]++;
-    cur_genotype = cur_genotype->GetNext();
-  }
-
-  // Actual output
-  fp << pop->GetStats().GetUpdate() << " ";
-  for (int i = 0; i < hist.GetSize(); i++)  fp<<hist[i]<<" ";
-  fp << endl;
-}
-
-
-void cAnalyzeUtil::PrintSpeciesAbundanceHistogram(ofstream & fp,
-						  cPopulation * pop)
-{
-  int max = 0;
-  assert(fp.good());
-
-  // Find max species abundance...
-  cGenebank & genebank = pop->GetGenebank();
-  cSpecies * cur_species = genebank.GetFirstSpecies();
-  for (int i = 0; i < genebank.GetNumSpecies(); i++) {
-    if (max < cur_species->GetNumOrganisms()) {
-      max = cur_species->GetNumOrganisms();
-    }
-    cur_species = cur_species->GetNext();
-  }
-
-  // Allocate array for the histogram & zero it
-  tArray <int> hist(max);
-  for (int i = 0; i < hist.GetSize(); i++)  hist[i] = 0;
-
-  // Loop through all species binning the values
-  cur_species = genebank.GetFirstSpecies();
-  for (int i = 0; i < genebank.GetNumSpecies(); i++) {
-    assert( cur_species->GetNumOrganisms() - 1 >= 0 );
-    assert( cur_species->GetNumOrganisms() - 1 < hist.GetSize() );
-    hist[cur_species->GetNumOrganisms() -1]++;
-    cur_species = cur_species->GetNext();
-  }
-
-  // Actual output
-  fp << pop->GetStats().GetUpdate() << " ";
-  for (int i = 0; i < hist.GetSize(); i++)  fp<<hist[i]<<" ";
-  fp<<endl;
-}
-
-
-// this adds support for evan dorn's InstructionHistogramEvent.  -- kgn
-/**
- * Count the number of each instruction present in the population.  Output
- * this info to a log file
- **/
-void cAnalyzeUtil::PrintInstructionAbundanceHistogram(ofstream & fp,
-                  cPopulation * pop)
-{ int i,x,y;
-  int num_inst=0;
-  int mem_size=0;
-  int * inst_counts;
-  cCPUMemory cpu_mem; // cCPUMemory is a subclass of cGenome
-  assert(fp.good());
-
-  // ----- number of instructions available?
-  num_inst=pop->GetEnvironment().GetInstSet().GetSize();
-  inst_counts= new int[num_inst];
-
-  // ----- create and initialize counting array
-  inst_counts  = new int[num_inst];
-  for (i=0;i<num_inst;i++)
-    { inst_counts[i]=0;
-    }
-  
-  int num_cells = pop->GetSize();
-  //looping through all CPUs counting up instructions
-  for( x=0; x<num_cells; x++ )
-    { cPopulationCell & cell=pop->GetCell(x);
-      if (cell.IsOccupied())
-      {
-      // access this CPU's code block
-        cpu_mem=cell.GetOrganism()->GetHardware().GetMemory();
-        mem_size=cpu_mem.GetSize();
-        for (y=0; y<mem_size ; y++)
-    { inst_counts[(cpu_mem[y]).GetOp()]++;     
-    }  
-      }
-    }
-  
-  // ----- output instruction counts
-  for(i=0; i<num_inst; i++)
-    { fp<<inst_counts[i]<<" ";
-    }
-  fp<<endl;
-}
-

Deleted: trunk/source/main/analyze_util.hh
===================================================================
--- trunk/source/main/analyze_util.hh	2005-09-15 23:16:19 UTC (rev 313)
+++ trunk/source/main/analyze_util.hh	2005-09-16 02:10:20 UTC (rev 314)
@@ -1,71 +0,0 @@
-//////////////////////////////////////////////////////////////////////////////
-// Copyright (C) 1993 - 2001 California Institute of Technology             //
-//                                                                          //
-// Read the COPYING and README files, or contact 'avida at alife.org',         //
-// before continuing.  SOME RESTRICTIONS MAY APPLY TO USE OF THIS FILE.     //
-//////////////////////////////////////////////////////////////////////////////
-
-#ifndef ANALYZE_UTIL_HH
-#define ANALYZE_UTIL_HH
-
-#include <fstream>
-
-class cGenome;
-class cInstSet;
-class cPopulation;
-
-// This is a static class used to do various forms of complex analysis
-// on genomes.
-
-class cAnalyzeUtil {
-private:
-public:
-  // Generic test-CPU analysis
-  static void TestGenome(const cGenome & genome, cInstSet & inst_set,
-			 std::ofstream & fp, int update);
-
-  static void TestInsSizeChangeRobustness(std::ofstream & fp,
-                 const cInstSet & inst_set, const cGenome & in_genome,
-                 int num_trials, int update);
-
-
-  // Landscape-based analysis
-  static cGenome CalcLandscape(int dist, const cGenome & genome,
-			       cInstSet & inst_set);
-  static void AnalyzeLandscape(const cGenome & genome, cInstSet & inst_set,
-			       int sample_size=1000, int min_found=0,
-			       int max_sample_size=0, int update=-1);
-  static void PairTestLandscape(const cGenome & genome, cInstSet & inst_set,
-				int sample_size=0, int update=-1);
-
-
-  // Population-wide analysis
-  static void CalcConsensus(cPopulation * population, int lines_saved);
-
-  static void AnalyzePopulation(cPopulation * pop, std::ofstream & fp,
-				double sample_prob=1, bool landscape=false,
-				bool save_genotype=false);
-
-  static void PrintDetailedFitnessData(cPopulation * pop, std::ofstream & datafp,
-    std::ofstream & histofp, std::ofstream & histo_testCPU_fp, bool save_max_f_genotype,
-    bool print_fitness_histo, double hist_fmax, double hist_fstep);
-
-  static void PrintGeneticDistanceData(cPopulation * pop, std::ofstream & fp,
-				const char *creature_name );
-  static void GeneticDistancePopDump(cPopulation * pop, std::ofstream & fp,
-		    const char * creature_name, bool save_creatures=false);
-
-  static void TaskSnapshot(cPopulation * pop, std::ofstream & fp);
-  static void TaskGrid(cPopulation * pop, std::ofstream & fp);
-  static void PrintViableTasksData(cPopulation *pop, std::ofstream &fp);
-  static void PrintTreeDepths(cPopulation * pop, std::ofstream & fp);
-
-  static void PrintDepthHistogram(std::ofstream &fp, cPopulation * pop);
-  static void PrintGenotypeAbundanceHistogram(std::ofstream &fp, cPopulation * pop);
-  static void PrintSpeciesAbundanceHistogram(std::ofstream &fp, cPopulation * pop);
-
-  // this adds support for evan dorn's InstructionHistogramEvent.  -- kgn
-  static void PrintInstructionAbundanceHistogram(std::ofstream &fp, cPopulation * pop);
-  // -- kgn
-};
-#endif

Modified: trunk/source/main/avida.cc
===================================================================
--- trunk/source/main/avida.cc	2005-09-15 23:16:19 UTC (rev 313)
+++ trunk/source/main/avida.cc	2005-09-16 02:10:20 UTC (rev 314)
@@ -10,19 +10,19 @@
 #endif
 
 #ifndef AVIDA_DRIVER_BASE_HH
-#include "avida_driver_base.hh"
+#include "cAvidaDriver_Base.h"
 #endif
 #ifndef CALLBACK_UTIL_HH
-#include "callback_util.hh"
+#include "cCallbackUtil.h"
 #endif
 #ifndef CONFIG_HH
-#include "config.hh"
+#include "cConfig.h"
 #endif
 #ifndef DEFS_HH
 #include "defs.hh"
 #endif
 #ifndef ENVIRONMENT_HH
-#include "environment.hh"
+#include "cEnvironment.h"
 #endif
 #ifndef HARDWARE_4STACK_HH
 #include "cHardware4Stack.h"
@@ -37,7 +37,7 @@
 #include "cInstLibCPU.h"
 #endif
 #ifndef POPULATION_INTERFACE_HH
-#include "population_interface.hh"
+#include "cPopulationInterface.h"
 #endif
 #ifndef RESOURCE_COUNT_HH
 #include "resource_count.hh"

Deleted: trunk/source/main/avida_driver_analyze.cc
===================================================================
--- trunk/source/main/avida_driver_analyze.cc	2005-09-15 23:16:19 UTC (rev 313)
+++ trunk/source/main/avida_driver_analyze.cc	2005-09-16 02:10:20 UTC (rev 314)
@@ -1,47 +0,0 @@
-//////////////////////////////////////////////////////////////////////////////
-// Copyright (C) 1993 - 2003 California Institute of Technology             //
-//                                                                          //
-// Read the COPYING and README files, or contact 'avida at alife.org',         //
-// before continuing.  SOME RESTRICTIONS MAY APPLY TO USE OF THIS FILE.     //
-//////////////////////////////////////////////////////////////////////////////
-
-#ifndef AVIDA_DRIVER_ANALYZE_HH
-#include "avida_driver_analyze.hh"
-#endif
-
-#ifndef ANALYZE_HH
-#include "analyze.hh"
-#endif
-#ifndef CONFIG_HH
-#include "config.hh"
-#endif
-
-#ifndef ENVIRONMENT_HH
-#include "environment.hh"
-#endif
-
-#include <iostream>
-
-using namespace std;
-
-//////////////////////////
-//  cAvidaDriver_Analyze
-//////////////////////////
-
-cAvidaDriver_Analyze::cAvidaDriver_Analyze(bool _interactive, cEnvironment *e)
-  : interactive(_interactive), d_environment(e)
-{
-}
-
-cAvidaDriver_Analyze::~cAvidaDriver_Analyze()
-{
-}
-
-void cAvidaDriver_Analyze::Run()
-{
-  cout << "In analyze mode!!" << endl;
-  cAnalyze analyze(cConfig::GetAnalyzeFilename(), d_environment);
-  if (interactive == true) {
-    analyze.RunInteractive();
-  }
-}

Deleted: trunk/source/main/avida_driver_analyze.hh
===================================================================
--- trunk/source/main/avida_driver_analyze.hh	2005-09-15 23:16:19 UTC (rev 313)
+++ trunk/source/main/avida_driver_analyze.hh	2005-09-16 02:10:20 UTC (rev 314)
@@ -1,29 +0,0 @@
-//////////////////////////////////////////////////////////////////////////////
-// Copyright (C) 1993 - 2003 California Institute of Technology             //
-//                                                                          //
-// Read the COPYING and README files, or contact 'avida at alife.org',         //
-// before continuing.  SOME RESTRICTIONS MAY APPLY TO USE OF THIS FILE.     //
-//////////////////////////////////////////////////////////////////////////////
-
-#ifndef AVIDA_DRIVER_ANALYZE_HH
-#define AVIDA_DRIVER_ANALYZE_HH
-
-#include <cstdlib>
-
-#ifndef AVIDA_DRIVER_BASE_HH
-#include "avida_driver_base.hh"
-#endif
-
-class cEnvironment;
-
-class cAvidaDriver_Analyze : public cAvidaDriver_Base {
-protected:
-  bool interactive;
-  cEnvironment *d_environment;
-public:
-  cAvidaDriver_Analyze(bool _interactive=false, cEnvironment* = NULL);
-  virtual ~cAvidaDriver_Analyze();
-  virtual void Run();
-};
-
-#endif

Deleted: trunk/source/main/avida_driver_base.cc
===================================================================
--- trunk/source/main/avida_driver_base.cc	2005-09-15 23:16:19 UTC (rev 313)
+++ trunk/source/main/avida_driver_base.cc	2005-09-16 02:10:20 UTC (rev 314)
@@ -1,55 +0,0 @@
-//////////////////////////////////////////////////////////////////////////////
-// Copyright (C) 1993 - 2003 California Institute of Technology             //
-//                                                                          //
-// Read the COPYING and README files, or contact 'avida at alife.org',         //
-// before continuing.  SOME RESTRICTIONS MAY APPLY TO USE OF THIS FILE.     //
-//////////////////////////////////////////////////////////////////////////////
-
-#ifndef AVIDA_DRIVER_BASE_HH
-#include "avida_driver_base.hh"
-#endif
-
-#ifndef STRING_HH
-#include "string.hh"
-#endif
-
-#include <iostream>
-
-using namespace std;
-
-
-// Static variable definitions
-cAvidaDriver_Base * cAvidaDriver_Base::main_driver = NULL;
-
-///////////////////////
-//  cAvidaDriver_Base
-///////////////////////
-
-cAvidaDriver_Base::cAvidaDriver_Base()
-  : done_flag(false)
-{
-}
-
-cAvidaDriver_Base::~cAvidaDriver_Base()
-{
-}
-
-void cAvidaDriver_Base::ExitProgram(int exit_code)
-{
-  exit(exit_code);   // If nothing is setup, nothing needs to be shutdown.
-}
-
-void cAvidaDriver_Base::NotifyComment(const cString & in_string)
-{
-  cout << in_string << endl;  // Just output
-}
-
-void cAvidaDriver_Base::NotifyWarning(const cString & in_string)
-{
-  cerr << in_string << endl;  // Just output
-}
-
-void cAvidaDriver_Base::NotifyError(const cString & in_string)
-{
-  cerr << in_string << endl;  // Just output
-}

Deleted: trunk/source/main/avida_driver_base.hh
===================================================================
--- trunk/source/main/avida_driver_base.hh	2005-09-15 23:16:19 UTC (rev 313)
+++ trunk/source/main/avida_driver_base.hh	2005-09-16 02:10:20 UTC (rev 314)
@@ -1,46 +0,0 @@
-//////////////////////////////////////////////////////////////////////////////
-// Copyright (C) 1993 - 2003 California Institute of Technology             //
-//                                                                          //
-// Read the COPYING and README files, or contact 'avida at alife.org',         //
-// before continuing.  SOME RESTRICTIONS MAY APPLY TO USE OF THIS FILE.     //
-//////////////////////////////////////////////////////////////////////////////
-
-#ifndef AVIDA_DRIVER_BASE_HH
-#define AVIDA_DRIVER_BASE_HH
-
-/**
- *  cAvidaDriver_Base
- *
- *  This class is the base class for driving an avida run (be it in analyze
- *  mode or as a population).  It includes all of the functions that should
- *  be overloaded to make any viewer work.
- **/
-
-class cString;
-class cAvidaDriver_Base {
-protected:
-  bool done_flag;   // This is set to true when run should finish.
-
-public:
-  static cAvidaDriver_Base * main_driver;
-
-  cAvidaDriver_Base();
-  virtual ~cAvidaDriver_Base();
-
-  virtual void Run() = 0;  // Called when Driver should take over execution.
-  virtual void ExitProgram(int exit_code);  // Called on an interupt,
-
-  // There functions are ideally called by avida whenever a message needs to
-  // be sent to the user.
-  virtual void NotifyComment(const cString & in_string);
-  virtual void NotifyWarning(const cString & in_string);
-  virtual void NotifyError(const cString & in_string);
-
-  // Called when the driver should stop what its doing for the moment, to
-  // let the user see what just happened.
-  virtual void SignalBreakpoint() { ; }
-
-  void SetDone() { done_flag = true; }
-};
-
-#endif

Deleted: trunk/source/main/avida_driver_population.cc
===================================================================
--- trunk/source/main/avida_driver_population.cc	2005-09-15 23:16:19 UTC (rev 313)
+++ trunk/source/main/avida_driver_population.cc	2005-09-16 02:10:20 UTC (rev 314)
@@ -1,251 +0,0 @@
-//////////////////////////////////////////////////////////////////////////////
-// Copyright (C) 1993 - 2003 California Institute of Technology             //
-//                                                                          //
-// Read the COPYING and README files, or contact 'avida at alife.org',         //
-// before continuing.  SOME RESTRICTIONS MAY APPLY TO USE OF THIS FILE.     //
-//////////////////////////////////////////////////////////////////////////////
-
-#include "avida_driver_population.hh"
-
-#include "avida_triggers.hh"
-#include "callback_util.hh"
-#include "change_list.hh"
-#include "config.hh"
-#include "cEventFactoryManager.h"
-#include "cEventList.h"
-#include "genebank.hh"
-#include "genotype.hh"
-#include "cHardwareBase.h"
-#include "cHardwareFactory.h"
-#include "init_file.hh"
-#include "organism.hh"
-#include "population.hh"
-#include "population_cell.hh"
-#include "cPopulationEventFactory.h"
-#include "population_interface.hh"
-#include "string.hh"
-#include "tools.hh"
-
-#include <iostream>
-#include <iomanip>
-
-using namespace std;
-
-/////////////////////////////
-//  cAvidaDriver_Population
-/////////////////////////////
-
-cAvidaDriver_Population::cAvidaDriver_Population(cEnvironment & environment, cChangeList * change_list)
-  : population(NULL), event_manager(NULL), event_list(NULL)
-{
-  // Setup Population    
-  cPopulationInterface default_interface;
-  default_interface.SetFun_NewHardware(&cCallbackUtil::CB_NewHardware);
-  default_interface.SetFun_Recycle(&cCallbackUtil::CB_RecycleHardware);
-  default_interface.SetFun_Divide(&cCallbackUtil::CB_Divide);
-  default_interface.SetFun_TestOnDivide(&cCallbackUtil::CB_TestOnDivide);
-  default_interface.SetFun_GetNeighbor(&cCallbackUtil::CB_GetNeighbor);
-  default_interface.SetFun_NumNeighbors(&cCallbackUtil::CB_GetNumNeighbors);
-  default_interface.SetFun_Rotate(&cCallbackUtil::CB_Rotate);
-  default_interface.SetFun_Breakpoint(&cCallbackUtil::CB_Breakpoint);
-  default_interface.SetFun_TestFitness(&cCallbackUtil::CB_TestFitness);
-  default_interface.SetFun_GetInput(&cCallbackUtil::CB_GetInput);
-  default_interface.SetFun_GetInputAt(&cCallbackUtil::CB_GetInputAt);
-  default_interface.SetFun_Debug(&cCallbackUtil::CB_Debug);
-  default_interface.SetFun_GetResources(&cCallbackUtil::CB_GetResources);
-  default_interface.SetFun_UpdateResources(&cCallbackUtil::CB_UpdateResources);
-  default_interface.SetFun_KillCell(&cCallbackUtil::CB_KillCell);
-  default_interface.SetFun_KillSurroundCell(&cCallbackUtil::CB_KillSurroundCell);
-  default_interface.SetFun_SendMessage(&cCallbackUtil::CB_SendMessage);
-  default_interface.SetFun_ReceiveValue(&cCallbackUtil::CB_ReceiveValue);
-  default_interface.SetFun_InjectParasite(&cCallbackUtil::CB_InjectParasite);
-  default_interface.SetFun_UpdateMerit(&cCallbackUtil::CB_UpdateMerit);
-
-  population = new cPopulation(default_interface, environment, change_list);
-
-  //Setup Event List
-  event_manager = new cEventFactoryManager;
-  cStats & stats = population->GetStats();
-  event_list = new cEventList( event_manager, new cAvidaTriggers(stats) );
-  
-  // in principle, one could add more than one event factory here.
-  // however, this is not a good idea, because the automatic documentation
-  // system cannot cope with this at this point. Claus
-  event_manager->AddFactory(new cPopulationEventFactory(population));
-
-  ReadEventListFile(cConfig::GetEventFilename());
-  
-  // Make sure the directory 'genebank' exits!
-  cTools::MkDir("genebank", true);
-}
-
-cAvidaDriver_Population::~cAvidaDriver_Population()
-{
-  if (population != NULL) delete population;
-}
-
-void cAvidaDriver_Population::Run()
-{
-  assert( population != NULL );
-
-  // Process until done...
-  while ( !ProcessUpdate() ) {} 
-}
-
-bool cAvidaDriver_Population::ProcessUpdate()
-{
-  if (cChangeList *change_list = population->GetChangeList()) {
-    change_list->Reset();
-  }
-
-  GetEvents();
-  if (done_flag == true) return true;
-
-  // Increment the Update.
-  cStats & stats = population->GetStats();
-  stats.IncCurrentUpdate();
-
-  // Handle all data collection for previous update.
-  if (stats.GetUpdate() > 0) {
-    // Tell the stats object to do update calculations and printing.
-    stats.ProcessUpdate();
-
-    // Update all the genotypes for the end of this update.
-    cGenebank & genebank = population->GetGenebank();
-    for (cGenotype * cur_genotype = genebank.ResetThread(0);
-	 cur_genotype != NULL && cur_genotype->GetThreshold();
-	 cur_genotype = genebank.NextGenotype(0)) {
-      cur_genotype->UpdateReset();
-    }
-  }
-
-  ProcessOrganisms();
-
-  // Do Point Mutations
-  if (cConfig::GetPointMutProb() > 0 ) {
-    for (int i = 0; i < population->GetSize(); i++) {
-      if (population->GetCell(i).IsOccupied()) {
-	population->GetCell(i).GetOrganism()->
-	  GetHardware().PointMutate(cConfig::GetPointMutProb());
-      }
-    }
-  }
-  
-
-#ifdef DEBUG_CHECK_OK
-  // If we're in a debug mode, make sure the population is OK.
-  if (population->OK() == false) {
-    g_debug.Warning("Population::OK() is failing.");
-  }
-#endif
-
-  // Do any cleanup in the hardware factory...
-  cHardwareFactory::Update();
-  
-  // Exit conditons...
-  if (population->GetNumOrganisms() == 0) done_flag = true;
-  
-  return done_flag;
-}
-
-
-void cAvidaDriver_Population::NotifyUpdate()
-{
-  // Nothing here for now.  This method should be overloaded and only
-  // run if there is no proper viewer.
-}
-
-
-void cAvidaDriver_Population::GetEvents()
-{
-  assert(population != NULL);
-
-  if (population->GetSyncEvents() == true) {
-    SyncEventList();
-    population->SetSyncEvents(false);
-  }
-  event_list->Process();
-}
-
-void cAvidaDriver_Population::ProcessOrganisms()
-{
-  // Process the update.
-  const int UD_size =
-    cConfig::GetAveTimeslice() * population->GetNumOrganisms();
-  const double step_size = 1.0 / (double) UD_size;
-
-  for (int i = 0; i < UD_size; i++) {
-    if (population->GetNumOrganisms() == 0) {
-      done_flag = true;
-      break;
-    }
-    population->ProcessStep(step_size);
-  }
-
-  // end of update stats...
-  population->CalcUpdateStats();
-
-  // No viewer; print out status for this update....
-  cStats & stats = population->GetStats();
-  cout.setf(ios::left);
-  cout.setf(ios::showpoint);
-  cout << "UD: " << setw(6) << stats.GetUpdate() << "  "
-       << "Gen: " << setw(9) << setprecision(7) << stats.SumGeneration().Average() << "  "
-       << "Fit: " << setw(9) << setprecision(7) << stats.GetAveFitness() << "  "
-       << "Size: " << population->GetNumOrganisms()
-       << endl;
-}
-
-
-void cAvidaDriver_Population::
-ReadEventListFile(const cString & filename)
-{
-  cInitFile event_file(filename);
-
-  // Load in the proper event list and set it up.
-  event_file.Load();
-  event_file.Compress();
-
-  // Loop through the line_list and change the lines to events.
-  for (int line_id = 0; line_id < event_file.GetNumLines(); line_id++) {
-    event_list->AddEventFileFormat(event_file.GetLine(line_id));
-  }
-
-  ////////// Adding events from the Genesis file //////////
-  // Max Updates and/or Max Generations
-  if( cConfig::GetEndConditionMode() == 0 ){
-    if( cConfig::GetMaxUpdates() >= 0 ){
-      event_list->AddEvent( cEventTriggers::UPDATE, cConfig::GetMaxUpdates(),
-			    cEventTriggers::TRIGGER_ONCE,
-			    cEventTriggers::TRIGGER_END, "exit", "");
-    }
-    if( cConfig::GetMaxGenerations() >= 0 ){
-      event_list->AddEvent( cEventTriggers::GENERATION,
-			    cConfig::GetMaxGenerations(),
-			    cEventTriggers::TRIGGER_ONCE,
-			    cEventTriggers::TRIGGER_END, "exit", "");
-    }
-  }else{
-    if( cConfig::GetMaxUpdates() >= 0 && cConfig::GetMaxGenerations() >= 0 ){
-      cString max_gen_str;
-      max_gen_str.Set("%d",cConfig::GetMaxGenerations());
-      cString max_update_str;
-      max_update_str.Set("%d",cConfig::GetMaxUpdates());
-      event_list->AddEvent( cEventTriggers::UPDATE, cConfig::GetMaxUpdates(),
-			    1, cEventTriggers::TRIGGER_END,
-			    "exit_if_generation_greater_than", max_gen_str);
-      event_list->AddEvent( cEventTriggers::GENERATION,
-			    cConfig::GetMaxGenerations(),
-			    .01, cEventTriggers::TRIGGER_END,
-			    "exit_if_update_greater_than", max_update_str);
-    }
-  }
-
-}
-
-void cAvidaDriver_Population::SyncEventList()
-{
-  if( event_list != NULL ){
-    event_list->Sync();
-  }
-}

Deleted: trunk/source/main/avida_driver_population.hh
===================================================================
--- trunk/source/main/avida_driver_population.hh	2005-09-15 23:16:19 UTC (rev 313)
+++ trunk/source/main/avida_driver_population.hh	2005-09-16 02:10:20 UTC (rev 314)
@@ -1,52 +0,0 @@
-//////////////////////////////////////////////////////////////////////////////
-// Copyright (C) 1993 - 2003 California Institute of Technology             //
-//                                                                          //
-// Read the COPYING and README files, or contact 'avida at alife.org',         //
-// before continuing.  SOME RESTRICTIONS MAY APPLY TO USE OF THIS FILE.     //
-//////////////////////////////////////////////////////////////////////////////
-
-#ifndef AVIDA_DRIVER_POPULATION_HH
-#define AVIDA_DRIVER_POPULATION_HH
-
-#ifndef AVIDA_DRIVER_BASE_HH
-#include "avida_driver_base.hh"
-#endif
-#ifndef STRING_HH
-#include "string.hh"
-#endif
-
-class cEnvironment;
-class cEventFactoryManager;
-class cEventList;
-class cString;
-class cChangeList;
-class cPopulation;
-
-class cAvidaDriver_Population : public cAvidaDriver_Base {
-protected:
-  cPopulation * population;
-  cEventFactoryManager * event_manager;
-  cEventList * event_list;
-
-public:
-  cPopulation &GetPopulation(){ return *population; }
-
-  void GetEvents();
-  /**
-   * Processes one complete update.
-   *
-   * Returns true when finished.
-   **/
-  virtual bool ProcessUpdate();
-  virtual void ProcessOrganisms();
-  void ReadEventListFile(const cString & filename="event_list");
-  void SyncEventList();
-			
-  cAvidaDriver_Population(cEnvironment & environment, cChangeList * change_list = 0);
-  virtual ~cAvidaDriver_Population();
-
-  virtual void Run();
-  virtual void NotifyUpdate();
-};
-
-#endif

Deleted: trunk/source/main/avida_triggers.hh
===================================================================
--- trunk/source/main/avida_triggers.hh	2005-09-15 23:16:19 UTC (rev 313)
+++ trunk/source/main/avida_triggers.hh	2005-09-16 02:10:20 UTC (rev 314)
@@ -1,34 +0,0 @@
-//////////////////////////////////////////////////////////////////////////////
-// Copyright (C) 1993 - 2003 California Institute of Technology             //
-//                                                                          //
-// Read the COPYING and README files, or contact 'avida at alife.org',         //
-// before continuing.  SOME RESTRICTIONS MAY APPLY TO USE OF THIS FILE.     //
-//////////////////////////////////////////////////////////////////////////////
-
-#ifndef AVIDA_TRIGGERS_HH
-#define AVIDA_TRIGGERS_HH
-
-#ifndef EVENT_TRIGGERS_HH
-#include "cEventTriggers.h"
-#endif
-#ifndef STATS_HH
-#include "stats.hh"
-#endif
-
-/**
- * A small class that determines the correct triggers for the event list.
- * Needed in order to separate the event business from the rest.
- */
-class cAvidaTriggers : public cEventTriggers {
-private:
-  cStats & stats;
-private:
-  // disabled copy constructor.
-  cAvidaTriggers(const cAvidaTriggers &);
-public:
-  cAvidaTriggers(cStats & _stats) : stats(_stats) { ; }
-  double GetUpdate() const { return (double) stats.GetUpdate(); }
-  double GetGeneration() const { return stats.SumGeneration().Average(); }
-};
-
-#endif

Deleted: trunk/source/main/birth_chamber.cc
===================================================================
--- trunk/source/main/birth_chamber.cc	2005-09-15 23:16:19 UTC (rev 313)
+++ trunk/source/main/birth_chamber.cc	2005-09-16 02:10:20 UTC (rev 314)
@@ -1,668 +0,0 @@
-//////////////////////////////////////////////////////////////////////////////
-// Copyright (C) 1993 - 2004 California Institute of Technology             //
-//                                                                          //
-// Read the COPYING and README files, or contact 'avida at alife.org',         //
-// before continuing.  SOME RESTRICTIONS MAY APPLY TO USE OF THIS FILE.     //
-//////////////////////////////////////////////////////////////////////////////
-
-#ifndef BIRTH_CHAMBER_HH
-#include "birth_chamber.hh"
-#endif
-
-#ifndef TARRAY_HH
-#include "tArray.hh"
-#endif
-#ifndef CONFIG_HH
-#include "config.hh"
-#endif
-#ifndef FUNCTIONS_HH
-#include "functions.hh"
-#endif
-#ifndef  GENEBANK_HH
-#include "genebank.hh"
-#endif
-#ifndef GENOME_HH
-#include "genome.hh"
-#endif
-#ifndef GENOME_UTIL_HH
-#include "genome_util.hh"
-#endif
-#ifndef  GENOTYPE_HH
-#include "genotype.hh"
-#endif
-#ifndef ORGANISM_HH
-#include "organism.hh"
-#endif
-#ifndef TOOLS_HH
-#include "tools.hh"
-#endif
-
-cBirthChamber::cBirthChamber()
-  : genebank(NULL)
-{
-  const int num_orgs = cConfig::GetWorldX()*cConfig::GetWorldY();
-  const int num_demes = cConfig::GetNumDemes(); 
-  local_wait_entry.Resize(num_orgs);
-  deme_wait_entry.Resize(num_demes);
-  for (int i = 0; i < num_orgs; i++) {
-    local_wait_entry[i].is_waiting = false;
-  }
-  for (int i = 0; i < num_demes; i++) {
-    deme_wait_entry[i].is_waiting = false;
-  }
-  global_wait_entry.is_waiting = false;
-}
-
-cBirthChamber::~cBirthChamber()
-{
-}
-
-bool cBirthChamber::GetNeighborWaiting(const int & parent_id,
-				       int world_x,
-				       int world_y)
-{
-  for (int i=-1; i<=1; i++) {
-    for (int j=-1; j<=1; j++) { 
-      const int neighbor_id = GridNeighbor(parent_id, world_x, world_y, i, j);
-      if (local_wait_entry[neighbor_id].is_waiting == true) {
-	return true;
-      }
-    }
-  }
-  return false;
-}
-
-
-int cBirthChamber::PickRandRecGenome(const int & parent_id, 
-				     int world_x,
-				     int world_y)
-{
-  bool done = false; 
-  while (done ==false) {
-    int test_neighbor = (int) g_random.GetUInt(9); 
-    int i = test_neighbor / 3 - 1; 
-    int j = test_neighbor % 3 - 1;
-    int test_loc = GridNeighbor(parent_id,world_x, world_y, i, j); 		
-    if (local_wait_entry[test_loc].is_waiting == true) {
-      return test_loc;
-    }
-  }
-
-  return -1;
-}
-
-bool cBirthChamber::RegionSwap(cCPUMemory & genome0, 
-			       cCPUMemory & genome1,
-			       int start0, int end0, 
-			       int start1, int end1)
-{
-   assert( start0 >= 0  &&  start0 < genome0.GetSize() );
-   assert( end0   >= 0  &&  end0   < genome0.GetSize() );
-   assert( start1 >= 0  &&  start1 < genome1.GetSize() );
-   assert( end1   >= 0  &&  end1   < genome1.GetSize() );
-            
-   // Calculate size of sections crossing over...
-   int size0 = end0 - start0;
-   int size1 = end1 - start1;
-            
-   int new_size0 = genome0.GetSize() - size0 + size1;
-   int new_size1 = genome1.GetSize() - size1 + size0;
-      
-   // Don't Crossover if offspring will be illegal!!!
-   if( new_size0 < MIN_CREATURE_SIZE || new_size0 > MAX_CREATURE_SIZE ||
-       new_size1 < MIN_CREATURE_SIZE || new_size1 > MAX_CREATURE_SIZE ){
-     return false;
-   } 
-
-   if (size0 > 0 && size1 > 0) {
-     cGenome cross0 = cGenomeUtil::Crop(genome0, start0, end0);
-     cGenome cross1 = cGenomeUtil::Crop(genome1, start1, end1);
-     genome0.Replace(start0, size0, cross1);
-     genome1.Replace(start1, size1, cross0);
-   }
-   else if (size0 > 0) {
-     cGenome cross0 = cGenomeUtil::Crop(genome0, start0, end0);
-     genome1.Replace(start1, size1, cross0);
-   }
-   else if (size1 > 0) {
-     cGenome cross1 = cGenomeUtil::Crop(genome1, start1, end1);
-     genome0.Replace(start0, size0, cross1);
-   }
-
-   return true;
-}
-
-bool cBirthChamber::GenomeSwap(cCPUMemory & genome0,
-	                       cCPUMemory & genome1,
-                  	       double & merit0,
-                  	       double & merit1)
-{
-  cCPUMemory & genome0_tmp = genome0;
-  genome0 = genome1; 
-  genome1 = genome0_tmp; 
-
-  double & merit0_tmp = merit0; 
-  merit0 = merit1; 
-  merit1 = merit0_tmp;
-
-	// This had no return value, added 9/23/2004 DMB
-  return true;
-}
-
-
-bool cBirthChamber::DoAsexBirth(const cGenome & child_genome,
-				cOrganism & parent,
-				tArray<cOrganism *> & child_array,
-				tArray<cMerit> & merit_array)
-{
-  const cPopulationInterface & pop_interface = parent.PopInterface();
-  const cEnvironment & environment = parent.GetPhenotype().GetEnvironment();
-
-  // This is asexual who doesn't need to wait in the birth chamber
-  // just build the child and return.
-  child_array.Resize(1);
-  child_array[0] = new cOrganism(child_genome, pop_interface, environment);
-  merit_array.Resize(1);
-  merit_array[0] = parent.GetPhenotype().GetMerit();
-
-  // Setup the genotype for the child
-  cGenotype * child_genotype = parent.GetGenotype();
-  
-  if (parent.GetPhenotype().CopyTrue() == false) {
-    // Add this genotype with only one parent since its asexual.
-    child_genotype = genebank->AddGenotype(child_genome,
-					   parent.GetGenotype(), NULL);
-  }
-
-  child_array[0]->SetGenotype(child_genotype);
-  parent.GetGenotype()->SetBreedStats(*child_genotype);
-    
-  child_genotype->IncDeferAdjust();
-
-  return true;
-}
-
-bool cBirthChamber::DoPairAsexBirth(const cBirthEntry & old_entry,
-				    const cGenome & new_genome,
-				    cOrganism & parent,
-				    tArray<cOrganism *> & child_array,
-				    tArray<cMerit> & merit_array)
-{
-  const cPopulationInterface & pop_interface = parent.PopInterface();
-  const cEnvironment & environment = parent.GetPhenotype().GetEnvironment();
-
-  // Build both child organisms...
-  child_array.Resize(2);
-  child_array[0] = new cOrganism(old_entry.genome, pop_interface, environment);
-  child_array[1] = new cOrganism(new_genome, pop_interface, environment);
-
-  // Setup the merits for both children...
-  merit_array.Resize(2);
-  merit_array[0] = old_entry.merit;
-  merit_array[1] = parent.GetPhenotype().GetMerit();
-
-  // Setup the genotypes for both children...
-  SetupGenotypeInfo(child_array[0], old_entry.parent_genotype, NULL);
-  SetupGenotypeInfo(child_array[1], parent.GetGenotype(), NULL);
-
-  // We are now also done with the parent genotype that we were saving in
-  // the birth chamber, so we can un-defer that one.
-
-  old_entry.parent_genotype->DecDeferAdjust();
-  genebank->AdjustGenotype(*old_entry.parent_genotype);
-
-  return true;
-}
-
-cBirthChamber::cBirthEntry *
-  cBirthChamber::FindSexSizeWaiting(const cGenome & child_genome,
-				    cOrganism & parent)
-{
-  const int child_length = child_genome.GetSize();
-
-  // If this is a new largest genome, increase the array size.
-  if (size_wait_entry.GetSize() <= child_length) {
-    int old_wait_size = size_wait_entry.GetSize();
-    size_wait_entry.Resize(child_length + 1);
-    for (int i = old_wait_size; i <= child_length; i++) {
-      size_wait_entry[i].is_waiting = false;
-    }
-  }
-
-  // Determine if we have an offspring of this length waiting already...
-  if (size_wait_entry[child_length].is_waiting == false) {
-    cGenotype * parent_genotype = parent.GetGenotype();
-    parent_genotype->IncDeferAdjust();
-    size_wait_entry[child_length].genome = child_genome;
-    size_wait_entry[child_length].merit = parent.GetPhenotype().GetMerit();
-    size_wait_entry[child_length].parent_genotype = parent_genotype;
-    size_wait_entry[child_length].is_waiting = true;
-    return NULL; 				
-  }
-
-  // There is already a child waiting -- do crossover between the two.
-  return &( size_wait_entry[child_length] ); 
-}
-
-cBirthChamber::cBirthEntry *
-  cBirthChamber::FindSexMateSelectWaiting(const cGenome & child_genome,
-					  cOrganism & parent)
-{
-  const int mate_id = parent.GetPhenotype().MateSelectID();
-
-  // If this is a new largest ID, increase the array size.
-  if (mate_select_wait_entry.GetSize() <= mate_id) {
-    int old_wait_size = mate_select_wait_entry.GetSize();
-    mate_select_wait_entry.Resize(mate_id + 1);
-    for (int i = old_wait_size; i <= mate_id; i++) {
-      mate_select_wait_entry[i].is_waiting = false;
-    }
-  }
-
-  // Determine if we have an offspring of this length waiting already...
-  if (mate_select_wait_entry[mate_id].is_waiting == false) {
-    cGenotype * parent_genotype = parent.GetGenotype();
-    parent_genotype->IncDeferAdjust();
-    mate_select_wait_entry[mate_id].genome = child_genome;
-    mate_select_wait_entry[mate_id].merit = parent.GetPhenotype().GetMerit();
-    mate_select_wait_entry[mate_id].parent_genotype = parent_genotype;
-    mate_select_wait_entry[mate_id].is_waiting = true;
-    return NULL;
-  }
-
-  // There is already a child waiting -- do crossover between the two.
-  return &( mate_select_wait_entry[mate_id] ); 
-}
-
-cBirthChamber::cBirthEntry *
-  cBirthChamber::FindSexLocalWaiting(const cGenome & child_genome,
-				   cOrganism & parent)
-{
-  // Collect some info for building the child.
-  const int world_x = cConfig::GetWorldX();
-  const int world_y = cConfig::GetWorldY();
-  const int parent_id = parent.PopInterface().GetCellID();
-  
-  // If nothing is waiting, store child locally.
-  if (GetNeighborWaiting(parent_id, world_x, world_y) == false) { 
-    cGenotype * parent_genotype = parent.GetGenotype();
-    parent_genotype->IncDeferAdjust();
-    local_wait_entry[parent_id].genome = child_genome;
-    local_wait_entry[parent_id].merit = parent.GetPhenotype().GetMerit();
-    local_wait_entry[parent_id].parent_genotype = parent_genotype;
-    local_wait_entry[parent_id].is_waiting = true;
-    return NULL; 				
-  }
-
-  // There is already a child waiting -- do crossover between the two.
-  int found_location = PickRandRecGenome(parent_id, world_x, world_y);
-  return &( local_wait_entry[found_location] ); 
-}
-
-cBirthChamber::cBirthEntry *
-  cBirthChamber::FindSexDemeWaiting(const cGenome & child_genome,
-				   cOrganism & parent)
-{
-  // Collect some info for building the child.
-  const int world_x = cConfig::GetWorldX();
-  const int world_y = cConfig::GetWorldY();
-  const int num_demes = cConfig::GetNumDemes();
-  const int parent_id = parent.PopInterface().GetCellID();
-  
-  const int parent_deme = (int) parent_id/(world_y*world_x/num_demes);
-
-  // If nothing is waiting, store child locally.
-  if (deme_wait_entry[parent_deme].is_waiting == false) { 
-    cGenotype * parent_genotype = parent.GetGenotype();
-    parent_genotype->IncDeferAdjust();
-    deme_wait_entry[parent_deme].genome = child_genome;
-    deme_wait_entry[parent_deme].merit = parent.GetPhenotype().GetMerit();
-    deme_wait_entry[parent_deme].parent_genotype = parent_genotype;
-    deme_wait_entry[parent_deme].is_waiting = true;
-    return NULL; 				
-  }
-
-  // There is already a child waiting -- do crossover between the two.
-  return &( deme_wait_entry[parent_deme] );
-
-}
-
-cBirthChamber::cBirthEntry * cBirthChamber::FindSexGlobalWaiting(const cGenome & child_genome,
-						  cOrganism & parent)
-{
-  // If no other child is waiting, store this one.
-  if (global_wait_entry.is_waiting == false){
-    cGenotype * parent_genotype = parent.GetGenotype();
-    parent_genotype->IncDeferAdjust();
-    global_wait_entry.genome = child_genome; 
-    global_wait_entry.merit = parent.GetPhenotype().GetMerit();
-    global_wait_entry.parent_genotype = parent_genotype;
-    global_wait_entry.is_waiting = true;
-    return NULL;
-  }
-
-  // There is already a child waiting -- do crossover between the two.
-
-  return &global_wait_entry;
-}
-
-void cBirthChamber::DoBasicRecombination(cCPUMemory & genome0,
-					 cCPUMemory & genome1, 
-					 double & merit0, double & merit1)
-{
-  double start_frac = g_random.GetDouble();
-  double end_frac = g_random.GetDouble();
-  if (start_frac > end_frac) nFunctions::Swap(start_frac, end_frac);
-    
-  // calculate the proportion of the genome  that will be swapped
-  double cut_frac = end_frac - start_frac;
-  double stay_frac = 1.0 - cut_frac;
-
-  int start0 = (int) (start_frac * (double) genome0.GetSize());
-  int end0   = (int) (end_frac * (double) genome0.GetSize());
-  int start1 = (int) (start_frac * (double) genome1.GetSize());
-  int end1   = (int) (end_frac * (double) genome1.GetSize());
-
-  RegionSwap(genome0, genome1, start0, end0, start1, end1);
-
-  // Adjust the merits....
-  double tmp_merit0 = merit0 * stay_frac + merit1 * cut_frac;
-  merit1 = merit1 * stay_frac + merit0 * cut_frac;
-  merit0 = tmp_merit0;
-
-  // Majority of the genome should stay in the offspring
-  if (stay_frac < cut_frac) {
-     GenomeSwap(genome0, genome1, merit0, merit1); 
-  } 
-}
-
-void cBirthChamber::DoModularContRecombination(cCPUMemory & genome0,
-					       cCPUMemory & genome1, 
-					       double & merit0,
-					       double & merit1)
-{
-  const int num_modules = cConfig::GetNumModules();
-
-  int start_module = (int) (g_random.GetDouble() * num_modules);
-  int end_module = (int) (g_random.GetDouble() * num_modules);
-
-  double start_frac = ((double) start_module) / (double) num_modules;
-  double end_frac = ((double) end_module) / (double) num_modules;
-
-  if (start_frac > end_frac) nFunctions::Swap(start_frac, end_frac);
-	    
-  // calculate the proportion of the genome  that will be swapped
-  double cut_frac = end_frac - start_frac;
-  double stay_frac = 1.0 - cut_frac;
-
-  int start0 = (int) (start_frac * (double) genome0.GetSize());
-  int end0   = (int) (end_frac * (double) genome0.GetSize());
-  int start1 = (int) (start_frac * (double) genome1.GetSize());
-  int end1   = (int) (end_frac * (double) genome1.GetSize());
-
-  RegionSwap(genome0, genome1, start0, end0, start1, end1);
-
-  // Adjust the merits....
-  double tmp_merit0 = merit0 * stay_frac + merit1 * cut_frac;
-  merit1 = merit1 * stay_frac + merit0 * cut_frac;
-  merit0 = tmp_merit0;
-
-  // Majority of the genome should stay in the offspring
-  if (stay_frac < cut_frac) {
-     GenomeSwap(genome0, genome1, merit0, merit1); 
-  } 
-}
-
-void cBirthChamber::DoModularNonContRecombination(cCPUMemory & genome0,
-						  cCPUMemory & genome1, 
-						  double & merit0,
-						  double & merit1)
-{
-  const int num_modules = cConfig::GetNumModules();
-
-  int swap_count = 0;
-  for (int i = 0; i < num_modules; i++) {
-    if (g_random.GetDouble() < 0.5) {
-      swap_count++;
-      double start_frac = ((double) i) / (double) num_modules;
-      double end_frac = ((double) i+1) / (double) num_modules;
-      int start0 = (int) (start_frac * (double) genome0.GetSize());
-      int end0   = (int) (end_frac * (double) genome0.GetSize());
-      int start1 = (int) (start_frac * (double) genome1.GetSize());
-      int end1   = (int) (end_frac * (double) genome1.GetSize());
-
-      RegionSwap(genome0, genome1, start0, end0, start1, end1);  
-    }
-  }
-
-  double cut_frac = ((double) swap_count) / (double) num_modules;
-  double stay_frac = 1.0 - cut_frac;
-
-  // Adjust the merits....
-  double tmp_merit0 = merit0 * stay_frac + merit1 * cut_frac;
-  merit1 = merit1 * stay_frac + merit0 * cut_frac;
-  merit0 = tmp_merit0;
-
-  // Majority of the genome should stay in the offspring
-  if (stay_frac < cut_frac) {
-     GenomeSwap(genome0, genome1, merit0, merit1); 
-  } 
-}
-
-void cBirthChamber::DoModularShuffleRecombination(cCPUMemory & genome0,
-						  cCPUMemory & genome1, 
-						  double & merit0,
-						  double & merit1)
-{
-  const int num_modules = cConfig::GetNumModules();
-  tArray<bool> swapped_region(num_modules);
-  swapped_region.SetAll(false);
-
-  int swap_count = 0;
-  for (int mod0 = 0; mod0 < num_modules; mod0++) {
-    if (g_random.GetDouble() < 0.5) {
-      swap_count++;
-
-      // Collect start and end info for current module
-      double start0_frac = ((double) mod0) / (double) num_modules;
-      double end0_frac = ((double) mod0+1) / (double) num_modules;
-      int start0 = (int) (start0_frac * (double) genome0.GetSize());
-      int end0   = (int) (end0_frac * (double) genome0.GetSize());
-
-      // Pick module from other genome...
-      int mod1 = g_random.GetUInt(num_modules);
-      while (swapped_region[mod1] == true) {
-	mod1 = g_random.GetUInt(num_modules);
-      }
-      swapped_region[mod1] = true;
-
-      // Collect start and end info for other module
-      double start1_frac = ((double) mod1) / (double) num_modules;
-      double end1_frac = ((double) mod1+1) / (double) num_modules;
-      int start1 = (int) (start1_frac * (double) genome1.GetSize());
-      int end1   = (int) (end1_frac * (double) genome1.GetSize());
-
-      // Do the swap.
-      RegionSwap(genome0, genome1, start0, end0, start1, end1);  
-    }
-  }
-
-  double cut_frac = ((double) swap_count) / (double) num_modules;
-  double stay_frac = 1.0 - cut_frac;
-
-  // Adjust the merits....
-  double tmp_merit0 = merit0 * stay_frac + merit1 * cut_frac;
-  merit1 = merit1 * stay_frac + merit0 * cut_frac;
-  merit0 = tmp_merit0;
-
-  // Majority of the genome should stay in the offspring
-  if (stay_frac < cut_frac) {
-     GenomeSwap(genome0, genome1, merit0, merit1); 
-  } 
-}
-
-
-void cBirthChamber::SetupGenotypeInfo(cOrganism * organism,
-				      cGenotype * parent0_genotype,
-				      cGenotype * parent1_genotype)
-{
-  // Setup the genotypes for both children...
-  cGenotype * child_genotype =
-    genebank->AddGenotype(organism->GetGenome(),
-			  parent0_genotype, parent1_genotype);
-
-  organism->SetGenotype(child_genotype);
-
-  parent0_genotype->SetBreedStats(*child_genotype);
-  
-  // Defer the child genotype from being adjusted until after the child
-  // has been placed into the population.
-
-  child_genotype->IncDeferAdjust();
-}
-
-bool cBirthChamber::SubmitOffspring(const cGenome & child_genome,
-				    cOrganism & parent,
-				    tArray<cOrganism *> & child_array,
-				    tArray<cMerit> & merit_array)
-{
-  assert(genebank != NULL);
-
-  cPhenotype & parent_phenotype = parent.GetPhenotype();
-
-  if (parent_phenotype.DivideSex() == false) {
-    return DoAsexBirth(child_genome, parent, child_array, merit_array);
-  }
-
-  // If we make it this far, this must be a sexual or a "waiting" asexual
-  // organism (which is the same as sexual with 0 recombination points)
-
-  // Find a waiting entry (locally or globally)
-  cBirthEntry * old_entry = NULL;
-  // First check if the birth method is one of the local ones... 
-  if (cConfig::GetBirthMethod() < NUM_LOCAL_POSITION_CHILD) { 
-    old_entry = FindSexLocalWaiting(child_genome, parent);
-  }
-  // ... then check if population is split into demes
-  else if (cConfig::GetBirthMethod() == POSITION_CHILD_DEME_RANDOM) {
-    old_entry = FindSexDemeWaiting(child_genome, parent);
-  }
-
-  // If none of the previous conditions were met, it must be global.
-  // ...check if recombination must be with organisms of the same length
-  else if (cConfig::GetSameLengthSex() != 0) {
-    old_entry = FindSexSizeWaiting(child_genome, parent);
-  }
-
-  // ...check if we have mate selection
-  else if (parent_phenotype.MateSelectID() >= 0) {
-    old_entry = FindSexMateSelectWaiting(child_genome, parent);
-  }
-
-  // If everything failed until this point, use default global.
-  else {
-    old_entry = FindSexGlobalWaiting(child_genome, parent);
-  }
-
-  // If we couldn't find a waiting entry, this one was saved -- stop here!
-  if (old_entry == NULL) {
-    return false;
-  }
-
-  // We have now found a waiting entry.  Mark it no longer waiting and use it.
-  old_entry->is_waiting = false;
-
-  // If we are NOT recombining, handle that here.
-  if (parent_phenotype.CrossNum() == 0 || 
-      g_random.GetDouble() > cConfig::GetRecombProb()) {
-    return DoPairAsexBirth(*old_entry, child_genome, parent, 
-			   child_array, merit_array);
-  }
-
-  // If we made it this far, RECOMBINATION will happen!
-  cCPUMemory genome0 = old_entry->genome;
-  cCPUMemory genome1 = child_genome;
-  double merit0 = old_entry->merit.GetDouble();
-  double merit1 = parent_phenotype.GetMerit().GetDouble();
-
-
-  // Check the modular recombination settings.  There are three variables:
-  //  1: How many modules?  (0 = non-modular)
-  //  2: Are the recombination regions continuous? (only used if modular)
-  //  3: Can modules be shuffled during recombination? (only if non-continuous)
-
-  const int num_modules = cConfig::GetNumModules();
-  const int continuous_regions = cConfig::GetContRecRegs();
-  const int shuffle_regions = !cConfig::GetCorespondRecRegs();
-
-  // If we are NOT modular...
-  if (num_modules == 0) {
-    DoBasicRecombination(genome0, genome1, merit0, merit1);
-  }
-
-  // If we ARE modular, and continuous...
-  else if (continuous_regions == 1) {
-    DoModularContRecombination(genome0, genome1, merit0, merit1);
-  }
-
-  // If we are NOT continuous, but NO shuffling...
-  else if (shuffle_regions == 0) {
-    DoModularNonContRecombination(genome0, genome1, merit0, merit1);
-  }
-
-  // If there IS shuffling (NON-continuous required)
-  else {
-    DoModularShuffleRecombination(genome0, genome1, merit0, merit1);
-  }
-
-  // Should there be a 2-fold cost to sex?
-
-  const int two_fold_cost = cConfig::GetTwoFoldCostSex();
-  const cPopulationInterface & pop_interface = parent.PopInterface();
-  const cEnvironment & environment = parent_phenotype.GetEnvironment();
-
-  cGenotype * parent0_genotype = old_entry->parent_genotype;
-  cGenotype * parent1_genotype = parent.GetGenotype();
-
-  if (two_fold_cost == 0) {	// Build the two organisms.
-    child_array.Resize(2);
-    child_array[0] = new cOrganism(genome0, pop_interface, environment);
-    child_array[1] = new cOrganism(genome1, pop_interface, environment);
-    
-    merit_array.Resize(2);
-    merit_array[0] = merit0;
-    merit_array[1] = merit1;
-
-    // Setup the genotypes for both children...
-    SetupGenotypeInfo(child_array[0], parent0_genotype, parent1_genotype);
-    SetupGenotypeInfo(child_array[1], parent1_genotype, parent0_genotype);
-
-  }
-  else { 			// Build only one organism	
-    child_array.Resize(1);
-    merit_array.Resize(1);
-
-    if (g_random.GetDouble() < 0.5) {
-      child_array[0] = new cOrganism(genome0, pop_interface, environment);
-      merit_array[0] = merit0;
-
-      // Setup the genotype for the child...
-      SetupGenotypeInfo(child_array[0], parent0_genotype, parent1_genotype);
-    } 
-    else {
-      child_array[0] = new cOrganism(genome1, pop_interface, environment);
-      merit_array[0] = merit1;
-
-      // Setup the genotype for the child...
-      SetupGenotypeInfo(child_array[0], parent1_genotype, parent0_genotype);
-    }
-  } 
-
-  // We are now also done with the parent genotype that we were saving in
-  // the birth chamber, so we can un-defer that one.
-  parent0_genotype->DecDeferAdjust();
-  genebank->AdjustGenotype(*parent0_genotype);
-
-  return true;
-}
-

Deleted: trunk/source/main/birth_chamber.hh
===================================================================
--- trunk/source/main/birth_chamber.hh	2005-09-15 23:16:19 UTC (rev 313)
+++ trunk/source/main/birth_chamber.hh	2005-09-16 02:10:20 UTC (rev 314)
@@ -1,118 +0,0 @@
-//////////////////////////////////////////////////////////////////////////////
-// Copyright (C) 1993 - 2003 California Institute of Technology             //
-//                                                                          //
-// Read the COPYING and README files, or contact 'avida at alife.org',         //
-// before continuing.  SOME RESTRICTIONS MAY APPLY TO USE OF THIS FILE.     //
-//////////////////////////////////////////////////////////////////////////////
-
-#ifndef BIRTH_CHAMBER_HH
-#define BIRTH_CHAMBER_HH
-
-#ifndef CPU_MEMORY_HH
-#include "cCPUMemory.h"
-#endif
-#ifndef MERIT_HH
-#include "merit.hh"
-#endif
-
-/**
- * All genome-based organisms must go through the birth chamber, which will
- * handle any special modifications during the birth process, such as divide
- * mutations reversions, sterilization, and crossover for sex.  If sex is
- * turned on, this class will hold organisms that are waiting to be crossed
- * over before they are born.
- **/
-
-class cCPUMemory; // aggregate
-class cMerit; // aggregate
-class cGenebank;
-class cGenome;
-class cGenotype;
-class cOrganism;
-template <class T> class tArray;
-
-class cBirthChamber {
-private:
-
-  class cBirthEntry {
-  public:
-    cCPUMemory genome;
-    cMerit merit;
-    cGenotype * parent_genotype;
-    bool is_waiting;
-  };
-
-  cGenebank * genebank;
-
-  cBirthEntry global_wait_entry;
-  tArray<cBirthEntry> local_wait_entry;
-  tArray<cBirthEntry> deme_wait_entry;
-  tArray<cBirthEntry> size_wait_entry;
-  tArray<cBirthEntry> mate_select_wait_entry;
-
-  // mark whether that instruction has already been swapped 
-  // between two genomes; used in modular recombination
-  tArray<int> swapped0;
-  tArray<int> swapped1;
-
-  // Private methods...
-  bool RegionSwap(cCPUMemory & genome0,
-		  cCPUMemory & genome1,
-		  int start0, int end0,
-		  int start1, int end1);
-
-  bool GenomeSwap(cCPUMemory & genome0, 
-		  cCPUMemory & genome1,
-		  double & merit0, 
-		  double & merit1);
-
-  bool DoAsexBirth(const cGenome & child_genome, cOrganism & parent,
-	   tArray<cOrganism *> & child_array, tArray<cMerit> & merit_array);
-  bool DoPairAsexBirth(const cBirthEntry & old_entry,
-		       const cGenome & new_genome,
-		       cOrganism & parent,
-		       tArray<cOrganism *> & child_array,
-		       tArray<cMerit> & merit_array);
-  cBirthEntry * FindSexLocalWaiting(const cGenome & child_genome,
-				    cOrganism & parent);
-  cBirthEntry * FindSexDemeWaiting(const cGenome & child_genome,
-				   cOrganism & parent);
-  cBirthEntry * FindSexSizeWaiting(const cGenome & child_genome,
-				   cOrganism & parent);
-  cBirthEntry * FindSexMateSelectWaiting(const cGenome & child_genome,
-					 cOrganism & parent);
-  cBirthEntry * FindSexGlobalWaiting(const cGenome & child_genome,
-				     cOrganism & parent);
-
-  void DoBasicRecombination(cCPUMemory & genome0, cCPUMemory & genome1, 
-			    double & merit0, double & merit1);
-  void DoModularContRecombination(cCPUMemory & genome0, cCPUMemory & genome1, 
-				  double & merit0, double & merit1);
-  void DoModularNonContRecombination(cCPUMemory &genome0, cCPUMemory &genome1, 
-				     double & merit0, double & merit1);
-  void DoModularShuffleRecombination(cCPUMemory &genome0, cCPUMemory &genome1, 
-				     double & merit0, double & merit1);
-
-  void SetupGenotypeInfo(cOrganism * organism, cGenotype * parent0_genotype,
-			 cGenotype * parent1_genotype);
-public:
-  cBirthChamber();
-  ~cBirthChamber();
-
-  void SetGenebank(cGenebank * in_genebank) { genebank = in_genebank; }
-
-  // Handle manipulations & tests of genome.  Return false if divide process
-  // should halt.  Place offspring in child_array.
-  bool SubmitOffspring(const cGenome & child_genome, cOrganism & parent,
-		       tArray<cOrganism *> & child_array,
-		       tArray<cMerit> & merit_array);
-
-  // Check the neighborhood for waiting genomes
-  bool GetNeighborWaiting(const int & parent_id, int world_x, int world_y);
-
-  // Pick a random waiting genome from the nehighborhood for recombination
-  int PickRandRecGenome(const int & parent_id, int world_x, int world_y);
-
-};
-
-#endif

Copied: trunk/source/main/cAnalyze.cc (from rev 313, trunk/source/main/analyze.cc)
===================================================================
--- trunk/source/main/analyze.cc	2005-09-15 23:16:19 UTC (rev 313)
+++ trunk/source/main/cAnalyze.cc	2005-09-16 02:10:20 UTC (rev 314)
@@ -0,0 +1,7073 @@
+//////////////////////////////////////////////////////////////////////////////
+// Copyright (C) 1993 - 2003 California Institute of Technology             //
+//                                                                          //
+// Read the COPYING and README files, or contact 'avida at alife.org',         //
+// before continuing.  SOME RESTRICTIONS MAY APPLY TO USE OF THIS FILE.     //
+//////////////////////////////////////////////////////////////////////////////
+
+#include <fstream>
+#include <sstream>
+#include <string>
+#include <queue>
+#include <stack>
+
+#include "cAnalyze.h"
+
+#include "cAnalyzeCommand.h"
+#include "cAnalyzeCommandDef.h"
+#include "cAnalyzeCommandDefBase.h"
+#include "cAnalyzeFlowCommand.h"
+#include "cAnalyzeFlowCommandDef.h"
+#include "cAnalyzeFunction.h"
+#include "cAnalyzeGenotype.h"
+#include "cConfig.h"
+#include "data_file.hh"
+#include "cEnvironment.h"
+#include "fitness_matrix.hh"
+#include "genome_util.hh"
+#include "cHardwareBase.h"
+#include "cHardwareStatusPrinter.h"
+#include "cHardwareUtil.h"
+#include "help_manager.hh"
+#include "init_file.hh"
+#include "inst_set.hh"
+#include "inst_util.hh"
+#include "landscape.hh"
+#include "phenotype.hh"
+#include "species.hh"
+#include "tArgDataEntry.hh"
+#include "task_entry.hh"
+#include "tDataEntry.hh"
+#include "tDataEntryCommand.hh"
+#include "tMatrix.hh"
+#include "cTestCPU.h"
+#include "cCPUTestInfo.h"
+#include "cTestUtil.h"
+#include "resource.hh"
+#include "tHashTable.hh"
+#ifdef WIN32
+#  include "win32_mkdir_hack.hh"
+#endif
+
+extern "C" {
+#include <errno.h>
+#include <sys/stat.h>
+}
+
+using namespace std;
+
+//////////////
+//  cAnalyze
+//////////////
+
+cAnalyze::cAnalyze(cString filename, cEnvironment *environment)
+: cur_batch(0)
+, d_environment(environment)
+, verbose(false)
+, interactive_depth(0)
+, inst_set(cHardwareUtil::DefaultInstSet(cConfig::GetInstFilename()))
+{
+  random.ResetSeed(cConfig::GetRandSeed());
+  
+  for (int i = 0; i < MAX_BATCHES; i++) {
+    batch[i].Name().Set("Batch%d", i);
+  }
+  
+  // Initialize the time oriented resource list to be just the initial
+  // concentrations of the resources in the environment.  This will only
+  // be changed if LOAD_RESOURCES analyze command is called.  If there is
+  // no resources in the environment or there is no environment, the list
+  // is empty and will cause an assert to be thrown in FindResource function.
+  const cResourceLib &resource_lib = environment->GetResourceLib();
+  if(environment != NULL && resource_lib.GetSize() > 0) {
+    vector<double> r;
+    for(int i=0; i<resource_lib.GetSize(); i++) {
+      cResource *resource = resource_lib.GetResource(i);
+      assert(resource);
+      r.push_back(resource->GetInitial());
+    }
+    resources.push_back(make_pair(0, r));
+  }
+  FillResources(0);
+  
+  cInitFile analyze_file(filename);
+  analyze_file.Load();
+  analyze_file.Compress();
+  analyze_file.Close();
+  
+  LoadCommandList(analyze_file, command_list);
+  ProcessCommands(command_list);
+  
+  return;
+}
+
+cAnalyze::~cAnalyze()
+{
+  data_file_manager.FlushAll();
+  while (genotype_data_list.GetSize()) delete genotype_data_list.Pop();
+  while (command_list.GetSize()) delete command_list.Pop();
+  while (function_list.GetSize()) delete function_list.Pop();
+}
+
+
+//////////////// Loading methods...
+
+void cAnalyze::LoadOrganism(cString cur_string)
+{
+  // LOAD_ORGANISM command...
+  
+  cString filename = cur_string.PopWord();
+  
+  cout << "Loading: " << filename << endl;
+  
+  // Setup the genome...
+  cGenome genome( cInstUtil::LoadGenome(filename, inst_set) );
+  
+  // Construct the new genotype..
+  cAnalyzeGenotype * genotype = new cAnalyzeGenotype(genome, inst_set);
+  
+  // Determine the organism's original name -- strip off directory...
+  while (filename.Find('/') != -1) filename.Pop('/');
+  while (filename.Find('\\') != -1) filename.Pop('\\');
+  filename.Replace(".gen", "");  // Remove the .gen from the filename.
+  genotype->SetName(filename);
+  
+  // And save it in the current batch.
+  batch[cur_batch].List().PushRear(genotype);
+  
+  // Adjust the flags on this batch
+  batch[cur_batch].SetLineage(false);
+  batch[cur_batch].SetAligned(false);
+}
+
+void cAnalyze::LoadBasicDump(cString cur_string)
+{
+  // LOAD_BASE_DUMP
+  
+  cString filename = cur_string.PopWord();
+  
+  cout << "Loading: " << filename << endl;
+  
+  cInitFile input_file(filename);
+  if (!input_file.IsOpen()) {
+    cerr << "Error: Cannot load file: \"" << filename << "\"." << endl;
+    exit(1);
+  }
+  input_file.Load();
+  input_file.Compress();
+  input_file.Close();
+  
+  // Setup the genome...
+  
+  for (int line_id = 0; line_id < input_file.GetNumLines(); line_id++) {
+    cString cur_line = input_file.GetLine(line_id);
+    
+    // Setup the genotype for this line...
+    cAnalyzeGenotype * genotype =
+      new cAnalyzeGenotype(cur_line.PopWord(), inst_set);
+    int num_cpus = cur_line.PopWord().AsInt();
+    int id_num = cur_line.PopWord().AsInt();
+    cString name = cStringUtil::Stringf("org-%d", id_num);
+    
+    genotype->SetNumCPUs(num_cpus);
+    genotype->SetID(id_num);
+    genotype->SetName(name);
+    
+    // Add this genotype to the proper batch.
+    batch[cur_batch].List().PushRear(genotype);
+  }
+  
+  // Adjust the flags on this batch
+  batch[cur_batch].SetLineage(false);
+  batch[cur_batch].SetAligned(false);
+}
+
+void cAnalyze::LoadDetailDump(cString cur_string)
+{
+  cout << "Warning: Use of LoadDetailDump() is deprecated.  Use \"LOAD\" instead." << endl;  
+  // LOAD_DETAIL_DUMP
+  
+  cString filename = cur_string.PopWord();
+  
+  cout << "Loading: " << filename << endl;
+  
+  cInitFile input_file(filename);
+  if (!input_file.IsOpen()) {
+    cerr << "Error: Cannot load file: \"" << filename << "\"." << endl;
+    exit(1);
+  }
+  input_file.Load();
+  input_file.Compress();
+  input_file.Close();
+  
+  // Setup the genome...
+  
+  for (int line_id = 0; line_id < input_file.GetNumLines(); line_id++) {
+    cString cur_line = input_file.GetLine(line_id);
+    
+    // Setup the genotype for this line...
+    
+    int id_num      = cur_line.PopWord().AsInt();
+    int parent_id   = cur_line.PopWord().AsInt();
+    int parent_dist = cur_line.PopWord().AsInt();
+    int num_cpus    = cur_line.PopWord().AsInt();
+    int total_cpus  = cur_line.PopWord().AsInt();
+    int length      = cur_line.PopWord().AsInt();
+    double merit    = cur_line.PopWord().AsDouble();
+    int gest_time   = cur_line.PopWord().AsInt();
+    double fitness  = cur_line.PopWord().AsDouble();
+    int update_born = cur_line.PopWord().AsInt();
+    int update_dead = cur_line.PopWord().AsInt();
+    int depth       = cur_line.PopWord().AsInt();
+    cString name = cStringUtil::Stringf("org-%d", id_num);
+    
+    cAnalyzeGenotype * genotype =
+      new cAnalyzeGenotype(cur_line.PopWord(), inst_set);
+    
+    genotype->SetID(id_num);
+    genotype->SetParentID(parent_id);
+    genotype->SetParentDist(parent_dist);
+    genotype->SetNumCPUs(num_cpus);
+    genotype->SetTotalCPUs(total_cpus);
+    genotype->SetLength(length);
+    genotype->SetMerit(merit);
+    genotype->SetGestTime(gest_time);
+    genotype->SetFitness(fitness);
+    genotype->SetUpdateBorn(update_born);
+    genotype->SetUpdateDead(update_dead);
+    genotype->SetDepth(depth);
+    genotype->SetName(name);
+    
+    // Add this genotype to the proper batch.
+    batch[cur_batch].List().PushRear(genotype);
+  }
+  
+  // Adjust the flags on this batch
+  batch[cur_batch].SetLineage(false);
+  batch[cur_batch].SetAligned(false);
+}
+
+void cAnalyze::LoadMultiDetail(cString cur_string)
+{
+  // LOAD_MULTI_DETAIL
+  
+  int start_UD = cur_string.PopWord().AsInt();
+  int step_UD = cur_string.PopWord().AsInt();
+  int stop_UD = cur_string.PopWord().AsInt();
+  cString data_directory = PopDirectory(cur_string, "./");
+  cur_batch = cur_string.PopWord().AsInt();
+  
+  if (step_UD == 0) {
+    cerr << "Error: LOAD_MULTI_DETAIL must have a non-zero value for step."
+    << endl;
+    return;
+  }
+  
+  int num_steps = (stop_UD - start_UD) / step_UD + 1;
+  if (num_steps > 1000) {
+    cerr << "Warning: Loading over 1000 files in LOAD_MULTI_DETAIL!"
+    << endl;
+  }
+  
+  if (verbose == true) {
+    cout << "Loading in " << num_steps
+    << " detail files from update " << start_UD
+    << " to update " << stop_UD
+    << endl;
+  } else {
+    cout << "Running LOAD_MULTI_DETAIL" << endl;
+  }
+  
+  for (int cur_UD = start_UD; cur_UD <= stop_UD; cur_UD += step_UD) {
+    cString filename = cStringUtil::Stringf("detail_pop.%d", cur_UD);
+    
+    cout << "Loading '" << filename
+      << "' into batch " << cur_batch
+      << endl;
+    
+    cInitFile input_file(filename);
+    if (!input_file.IsOpen()) {
+      cerr << "Error: Cannot load file: \"" << filename << "\"." << endl;
+      exit(1);
+    }
+    input_file.Load();
+    input_file.Compress();
+    input_file.Close();
+    
+    // Setup the genome...
+    
+    for (int line_id = 0; line_id < input_file.GetNumLines(); line_id++) {
+      cString cur_line = input_file.GetLine(line_id);
+      
+      // Setup the genotype for this line...
+      
+      int id_num      = cur_line.PopWord().AsInt();
+      int parent_id   = cur_line.PopWord().AsInt();
+      int parent_dist = cur_line.PopWord().AsInt();
+      int num_cpus    = cur_line.PopWord().AsInt();
+      int total_cpus  = cur_line.PopWord().AsInt();
+      int length      = cur_line.PopWord().AsInt();
+      double merit    = cur_line.PopWord().AsDouble();
+      int gest_time   = cur_line.PopWord().AsInt();
+      double fitness  = cur_line.PopWord().AsDouble();
+      int update_born = cur_line.PopWord().AsInt();
+      int update_dead = cur_line.PopWord().AsInt();
+      int depth       = cur_line.PopWord().AsInt();
+      cString name = cStringUtil::Stringf("org-%d", id_num);
+      
+      cAnalyzeGenotype * genotype =
+        new cAnalyzeGenotype(cur_line.PopWord(), inst_set);
+      
+      genotype->SetID(id_num);
+      genotype->SetParentID(parent_id);
+      genotype->SetParentDist(parent_dist);
+      genotype->SetNumCPUs(num_cpus);
+      genotype->SetTotalCPUs(total_cpus);
+      genotype->SetLength(length);
+      genotype->SetMerit(merit);
+      genotype->SetGestTime(gest_time);
+      genotype->SetFitness(fitness);
+      genotype->SetUpdateBorn(update_born);
+      genotype->SetUpdateDead(update_dead);
+      genotype->SetDepth(depth);
+      genotype->SetName(name);
+      
+      // Add this genotype to the proper batch.
+      batch[cur_batch].List().PushRear(genotype);
+    }
+    
+    // Adjust the flags on this batch
+    batch[cur_batch].SetLineage(false);
+    batch[cur_batch].SetAligned(false);
+    
+    cur_batch++;
+  }
+}
+
+void cAnalyze::LoadSequence(cString cur_string)
+{
+  // LOAD_SEQUENCE
+  
+  static int sequence_count = 1;
+  cString sequence = cur_string.PopWord();
+  cString seq_name = cur_string.PopWord();
+  
+  cout << "Loading: " << sequence << endl;
+  
+  // Setup the genotype...
+  cAnalyzeGenotype * genotype = new cAnalyzeGenotype(sequence, inst_set);
+  
+  genotype->SetNumCPUs(1);      // Initialize to a single organism.
+  if (seq_name == "") {
+    seq_name = cStringUtil::Stringf("org-Seq%d", sequence_count);
+  }
+  genotype->SetName(seq_name);
+  sequence_count++;
+  
+  // Add this genotype to the proper batch.
+  batch[cur_batch].List().PushRear(genotype);
+  
+  // Adjust the flags on this batch
+  batch[cur_batch].SetLineage(false);
+  batch[cur_batch].SetAligned(false);
+}
+
+void cAnalyze::LoadDominant(cString cur_string)
+{
+  (void) cur_string;
+  cerr << "Warning: \"LOAD_DOMINANT\" not implmented yet!"<<endl;
+}
+
+// Clears the current time oriented list of resources and loads in a new one
+// from a file specified by the user, or resource.dat by default.
+void cAnalyze::LoadResources(cString cur_string)
+{
+  resources.clear();
+  
+  int words = cur_string.CountNumWords();
+  
+  cString filename = "resource.dat";
+  if(words >= 1) {
+    filename = cur_string.PopWord();
+  }
+  
+  cout << "Loading Resources from: " << filename << endl;
+  
+  // Process the resource.dat, currently assuming this is the only possible
+  // input file
+  ifstream resourceFile(filename, ios::in);
+  assert(resourceFile);
+  
+  // Read in each line of the resource file and process it
+  char line[2048];
+  while(!resourceFile.eof()) {
+    resourceFile.getline(line, 2047);
+    if(line[0] == '\0') { continue; }
+    
+    // Get rid of the whitespace at the beginning of the stream, then 
+    // see if the line begins with a #, if so move on to the next line.
+    stringstream ss;
+    ss << line; ss >> ws; if(ss.peek() == '#') { continue; }
+    
+    // Read the update number from the stream
+    int update;
+    ss >> update; assert(ss.good());
+    
+    // Read in the concentration values for the current update and put them
+    // into a temporary vector.
+    double x;
+    vector<double> tempValues;
+    // Loop until the stream is no longer valid, which means either all the
+    // data has been processed or a non-numeric was encountered.  Currently
+    // assuming a non-numeric is a comment denoting the rest of the line as
+    // not informational.
+    while(true) {
+      ss >> ws; ss >> x;
+      tempValues.push_back(x);
+      if(!ss.good()) { ss.clear(); break; }
+    }
+    // Can't have no resources, so assert
+    if(tempValues.empty()) { assert(0); }
+    // add the update to the list of updates.  Also assuming the values
+    // in the file are already sorted.  If this turns out not to be the
+    // case you will need to sort on resources[i].first
+    resources.push_back(make_pair(update, tempValues));
+  }
+  resourceFile.close();
+  
+  return;
+}
+
+
+// Looks up the resource concentrations that are the closest to the
+// given update and then fill in those concentrations into the environment.
+void cAnalyze::FillResources(int update)
+{
+  // There must be some resources for at least one update
+  //assert(!resources.empty());
+  if(resources.empty()) { return; }
+  
+  int which = -1;
+  // Assuming resource vector is sorted by update, front to back
+  if(update <= resources[0].first) {
+    which = 0;
+  } else if(update >= resources.back().first) {
+    which = resources.size() - 1;
+  } else {
+    // Find the update that is closest to the born update
+    for(unsigned int i=0; i<resources.size()-1; i++) {
+      if(update > resources[i+1].first) { continue; }
+      if(update - resources[i].first <=
+         resources[i+1].first - update) {
+        which = i;
+      } else {
+        which = i + 1;
+      }
+      break;
+    }
+  }
+  if(which < 0) { assert(0); }
+  
+  //cResourceLib &resLib = environment.GetResourceLib();
+  // The resources from the file and the original resources from
+  // environment.cfg must be the same size.
+  //assert((unsigned int)resLib.GetSize() == resources[which].second.size());
+  // Set the resource concentrations to the values for the appropriate
+  // update
+  //for(unsigned int i=0; i<resources[which].second.size(); i++) {
+  //  cResource *res = resLib.GetResource(i);
+  //  assert(res);
+  //  res->SetInitial(resources[which].second[i]);
+  //}
+  
+tArray<double> temp(resources[which].second.size());
+for(unsigned int i=0; i<resources[which].second.size(); i++) {
+  temp[i] = resources[which].second[i];
+}
+cTestCPU::SetupResourceArray(temp);
+
+return;
+}
+
+double cAnalyze::AnalyzeEntropy(cAnalyzeGenotype * genotype, double mu) 
+{
+  double entropy = 0.0;
+
+  // If the fitness is 0, the entropy is the length of genotype ...
+  genotype->Recalculate();
+  if (genotype->GetFitness() == 0) {
+    return genotype->GetLength();
+  }
+
+  // Calculate the stats for the genotype we're working with ...
+  const int num_insts = inst_set.GetSize();
+  const int num_lines = genotype->GetLength();
+  const cGenome & base_genome = genotype->GetGenome();
+  cGenome mod_genome(base_genome);
+  double base_fitness = genotype->GetFitness();
+  
+  // Loop through all the lines of code, testing all mutations...
+  tArray<double> test_fitness(num_insts);
+  tArray<double> prob(num_insts);
+  for (int line_no = 0; line_no < num_lines; line_no ++) {
+    int cur_inst = base_genome[line_no].GetOp();
+    
+    // Test fitness of each mutant.
+    for (int mod_inst = 0; mod_inst < num_insts; mod_inst++) {
+      mod_genome[line_no].SetOp(mod_inst);
+      cAnalyzeGenotype test_genotype(mod_genome, inst_set);
+      test_genotype.Recalculate();
+      // Ajust fitness ...
+      if (test_genotype.GetFitness() <= base_fitness) {
+	test_fitness[mod_inst] = test_genotype.GetFitness();
+      } else {
+	test_fitness[mod_inst] = base_fitness;
+      }
+    }
+    
+    // Calculate probabilities at mut-sel balance
+    double w_bar = 1;
+    
+    // Normalize fitness values
+    double maxFitness = 0.0;
+    for(int i=0; i<num_insts; i++) {
+      if(test_fitness[i] > maxFitness) {
+	maxFitness = test_fitness[i];
+      }
+    }
+    
+   
+    for(int i=0; i<num_insts; i++) {
+      test_fitness[i] /= maxFitness;
+    }
+       
+    while(1) {
+      double sum = 0.0;
+      for (int mod_inst = 0; mod_inst < num_insts; mod_inst ++) {
+	prob[mod_inst] = (mu * w_bar) / 
+	  ((double)num_insts * 
+	   (w_bar + test_fitness[mod_inst] * mu - test_fitness[mod_inst]));
+	sum = sum + prob[mod_inst];
+      }
+      if ((sum-1.0)*(sum-1.0) <= 0.0001) 
+	break;
+      else
+	w_bar = w_bar - 0.000001;
+    }
+    
+    // Calculate entropy ...
+    double this_entropy = 0.0;
+    for (int i = 0; i < num_insts; i ++) {
+      this_entropy += prob[i] * log((double) 1.0/prob[i]) / log ((double) num_insts);
+    }
+    entropy += this_entropy;
+    
+    // Reset the mod_genome back to the original sequence.
+    mod_genome[line_no].SetOp(cur_inst);
+  }
+  return entropy;
+}
+
+double cAnalyze::AnalyzeEntropyGivenParent(cAnalyzeGenotype * genotype,
+					   cAnalyzeGenotype * parent, double mut_rate)
+{
+  double entropy = 0.0;
+
+  // Calculate the stats for the genotype we're working with ...
+  genotype->Recalculate();
+  const int num_insts = inst_set.GetSize();
+  const int num_lines = genotype->GetLength();
+  const cGenome & base_genome = genotype->GetGenome();
+  const cGenome & parent_genome = parent->GetGenome();
+  cGenome mod_genome(base_genome);
+
+  // Loop through all the lines of code, testing all mutations ...
+  tArray<double> test_fitness(num_insts);
+  tArray<double> prob(num_insts);
+  for (int line_no = 0; line_no < num_lines; line_no ++) {
+    int cur_inst = base_genome[line_no].GetOp();
+    int parent_inst = parent_genome[line_no].GetOp();
+
+    // Test fitness of each mutant.
+    for (int mod_inst = 0; mod_inst < num_insts; mod_inst++) {
+      mod_genome[line_no].SetOp(mod_inst);
+      cAnalyzeGenotype test_genotype(mod_genome, inst_set);
+      test_genotype.Recalculate();
+      test_fitness[mod_inst] = test_genotype.GetFitness();
+    }
+
+
+    // Calculate probabilities at mut-sel balance
+    double w_bar = 1;
+    
+    // Normalize fitness values, assert if they are all zero
+    double maxFitness = 0.0;
+    for(int i=0; i<num_insts; i++) {
+      if ( i == parent_inst) { continue; }
+      if (test_fitness[i] > maxFitness) {
+	maxFitness = test_fitness[i];
+      }
+    }
+    
+    if(maxFitness > 0) {
+      for(int i = 0; i < num_insts; i ++) {
+	if (i == parent_inst) { continue; }
+	test_fitness[i] /= maxFitness;
+      }
+    } else {
+      // every other inst is equally likely to be mutated to
+      for (int i = 0; i < num_insts; i ++) {
+	if (i == parent_inst) { continue; }
+	test_fitness[i] = 1;
+      }
+    }
+    
+    double double_num_insts = num_insts * 1.0;
+    while(1) {
+      double sum = 0.0;
+      for (int mod_inst = 0; mod_inst < num_insts; mod_inst ++) {
+	if (mod_inst == parent_inst) { continue; }
+	prob[mod_inst] = (mut_rate * w_bar) / 
+	  (double_num_insts-2) / 
+	   (w_bar + test_fitness[mod_inst] * mut_rate * (double_num_insts-1) / (double_num_insts - 2) 
+	    - test_fitness[mod_inst]);
+	sum = sum + prob[mod_inst];
+      }
+      if ((sum-1.0)*(sum-1.0) <= 0.0001) 
+	break;
+      else
+	w_bar = w_bar - 0.000001;
+    }
+    
+    // Calculate entropy ...
+    double this_entropy = 0.0;
+    this_entropy -= (1.0 - mut_rate) * log(1.0 - mut_rate) / log(static_cast<double>(num_insts));
+    for (int i = 0; i < num_insts; i ++) {
+      if (i == parent_inst) { continue; }
+      prob[i] = prob[i] * mut_rate;
+      this_entropy += prob[i] * log(static_cast<double>(1.0/prob[i])) / log (static_cast<double>(num_insts));
+    }
+    entropy += this_entropy;
+
+    // Reset the mod_genome back to the base_genome.
+    mod_genome[line_no].SetOp(cur_inst);
+  }
+  return entropy;
+}
+
+double cAnalyze::IncreasedInfo(cAnalyzeGenotype * genotype1,
+			       cAnalyzeGenotype * genotype2,
+			       double mu) 
+{
+  double increased_info = 0.0;
+
+  // Calculate the stats for the genotypes we're working with ...
+  if ( genotype1->GetLength() != genotype2->GetLength() ) {
+    cerr << "Error: Two genotypes don't have same length.(cAnalyze::IncreasedInfo)" << endl;
+    exit(1);
+  }
+
+  genotype1->Recalculate();
+  if (genotype1->GetFitness() == 0) {
+    return 0.0;
+  }
+
+  const int num_insts = inst_set.GetSize();
+  const int num_lines = genotype1->GetLength();
+  const cGenome & genotype1_base_genome = genotype1->GetGenome();
+  cGenome genotype1_mod_genome(genotype1_base_genome);
+  double genotype1_base_fitness = genotype1->GetFitness();
+  vector<double> genotype1_info(num_lines, 0.0);
+  
+  // Loop through all the lines of code, calculate genotype1 information
+  tArray<double> test_fitness(num_insts);
+  tArray<double> prob(num_insts);
+  for (int line_no = 0; line_no < num_lines; line_no ++) {
+    int cur_inst = genotype1_base_genome[line_no].GetOp();
+    
+    // Test fitness of each mutant.
+    for (int mod_inst = 0; mod_inst < num_insts; mod_inst++) {
+      genotype1_mod_genome[line_no].SetOp(mod_inst);
+      cAnalyzeGenotype test_genotype(genotype1_mod_genome, inst_set);
+      test_genotype.Recalculate();
+      // Ajust fitness ...
+      if (test_genotype.GetFitness() <= genotype1_base_fitness) {
+	test_fitness[mod_inst] = test_genotype.GetFitness();
+      } else {
+	test_fitness[mod_inst] = genotype1_base_fitness;
+      }
+    }
+    
+    // Calculate probabilities at mut-sel balance
+    double w_bar = 1;
+    
+    // Normalize fitness values
+    double maxFitness = 0.0;
+    for(int i=0; i<num_insts; i++) {
+      if(test_fitness[i] > maxFitness) {
+	maxFitness = test_fitness[i];
+      }
+    }
+    
+    for(int i=0; i<num_insts; i++) {
+      test_fitness[i] /= maxFitness;
+    }
+    
+    while(1) {
+      double sum = 0.0;
+      for (int mod_inst = 0; mod_inst < num_insts; mod_inst ++) {
+	prob[mod_inst] = (mu * w_bar) / 
+	  ((double)num_insts * 
+	   (w_bar + test_fitness[mod_inst] * mu - test_fitness[mod_inst]));
+	sum = sum + prob[mod_inst];
+      }
+      if ((sum-1.0)*(sum-1.0) <= 0.0001) 
+	break;
+      else
+	w_bar = w_bar - 0.000001;
+    }
+    
+    // Calculate entropy ...
+    double this_entropy = 0.0;
+    for (int i = 0; i < num_insts; i ++) {
+      this_entropy += prob[i] * log((double) 1.0/prob[i]) / log ((double) num_insts);
+    }
+    genotype1_info[line_no] = 1 - this_entropy;
+    
+    // Reset the mod_genome back to the original sequence.
+    genotype1_mod_genome[line_no].SetOp(cur_inst);
+  }
+
+  genotype2->Recalculate();
+  if (genotype2->GetFitness() == 0) {
+    for (int line_no = 0; line_no < num_lines; ++ line_no) {
+      increased_info += genotype1_info[line_no];
+    }
+    return increased_info;
+  }
+    
+  const cGenome & genotype2_base_genome = genotype2->GetGenome();
+  cGenome genotype2_mod_genome(genotype2_base_genome);
+  double genotype2_base_fitness = genotype2->GetFitness();
+
+  // Loop through all the lines of code, calculate increased information
+  for (int line_no = 0; line_no < num_lines; line_no ++) {
+    int cur_inst = genotype2_base_genome[line_no].GetOp();
+    
+    // Test fitness of each mutant.
+    for (int mod_inst = 0; mod_inst < num_insts; mod_inst++) {
+      genotype2_mod_genome[line_no].SetOp(mod_inst);
+      cAnalyzeGenotype test_genotype(genotype2_mod_genome, inst_set);
+      test_genotype.Recalculate();
+      // Ajust fitness ...
+      if (test_genotype.GetFitness() <= genotype2_base_fitness) {
+	test_fitness[mod_inst] = test_genotype.GetFitness();
+      } else {
+	test_fitness[mod_inst] = genotype2_base_fitness;
+      }
+    }
+    
+    // Calculate probabilities at mut-sel balance
+    double w_bar = 1;
+    
+    // Normalize fitness values, assert if they are all zero
+    double maxFitness = 0.0;
+    for(int i=0; i<num_insts; i++) {
+      if(test_fitness[i] > maxFitness) {
+	maxFitness = test_fitness[i];
+      }
+    }
+    
+    for(int i=0; i<num_insts; i++) {
+      test_fitness[i] /= maxFitness;
+    }
+    
+    while(1) {
+      double sum = 0.0;
+      for (int mod_inst = 0; mod_inst < num_insts; mod_inst ++) {
+	prob[mod_inst] = (mu * w_bar) / 
+	  ((double)num_insts * 
+	   (w_bar + test_fitness[mod_inst] * mu - test_fitness[mod_inst]));
+	sum = sum + prob[mod_inst];
+      }
+      if ((sum-1.0)*(sum-1.0) <= 0.0001) 
+	break;
+      else
+	w_bar = w_bar - 0.000001;
+    }
+    
+    // Calculate entropy ...
+    double this_entropy = 0.0;
+    for (int i = 0; i < num_insts; i ++) {
+      this_entropy += prob[i] * log((double) 1.0/prob[i]) / log ((double) num_insts);
+    }
+    
+    // Compare information 
+    if (genotype1_info[line_no] > 1 - this_entropy) {
+      increased_info += genotype1_info[line_no] - (1 - this_entropy);
+    } // else increasing is 0, do nothing
+    
+    // Reset the mod_genome back to the original sequence.
+    genotype2_mod_genome[line_no].SetOp(cur_inst);
+  }
+
+
+  return increased_info;
+}
+
+void cAnalyze::LoadFile(cString cur_string)
+{
+  // LOAD
+  
+  cString filename = cur_string.PopWord();
+  
+  cout << "Loading: " << filename << endl;
+  
+  cInitFile input_file(filename);
+  if (!input_file.IsOpen()) {
+    cerr << "Error: Cannot load file: \"" << filename << "\"." << endl;
+    exit(1);
+  }
+  input_file.Load();
+  input_file.ReadHeader();
+  input_file.Compress();
+  input_file.Close();
+  
+  const cString filetype = input_file.GetFiletype();
+  if (filetype != "population_data" &&  // Depricated
+      filetype != "genotype_data") {
+    cerr << "Error: Cannot load files of type \"" << filetype << "\"." << endl;
+    exit(1);
+  }
+  
+  if (verbose == true) {
+    cout << "Loading file of type: " << filetype << endl;
+  }
+  
+  
+  // Construct a linked list of data types that can be loaded...
+  tList< tDataEntryCommand<cAnalyzeGenotype> > output_list;
+  tListIterator< tDataEntryCommand<cAnalyzeGenotype> > output_it(output_list);
+  LoadGenotypeDataList(input_file.GetFormat(), output_list);
+  bool id_inc = input_file.GetFormat().HasString("id");
+  
+  // Setup the genome...
+  cGenome default_genome(1);
+  int load_count = 0;
+  
+  for (int line_id = 0; line_id < input_file.GetNumLines(); line_id++) {
+    cString cur_line = input_file.GetLine(line_id);
+    
+    cAnalyzeGenotype * genotype =
+      new cAnalyzeGenotype(default_genome, inst_set);
+    
+    output_it.Reset();
+    tDataEntryCommand<cAnalyzeGenotype> * data_command = NULL;
+    while ((data_command = output_it.Next()) != NULL) {
+      data_command->SetTarget(genotype);
+      //        genotype->SetSpecialArgs(data_command->GetArgs());
+      data_command->SetValue(cur_line.PopWord());
+    }
+    
+    // Give this genotype a name.  Base it on the ID if possible.
+    if (id_inc == false) {
+      cString name = cStringUtil::Stringf("org-%d", load_count++);
+      genotype->SetName(name);
+    }
+    else {
+      cString name = cStringUtil::Stringf("org-%d", genotype->GetID());
+      genotype->SetName(name);
+    }
+    
+    // Add this genotype to the proper batch.
+    batch[cur_batch].List().PushRear(genotype);
+  }
+  
+  // Adjust the flags on this batch
+  batch[cur_batch].SetLineage(false);
+  batch[cur_batch].SetAligned(false);
+}
+
+
+//////////////// Reduction....
+
+void cAnalyze::FindGenotype(cString cur_string)
+{
+  // If no arguments are passed in, just find max num_cpus.
+  if (cur_string.GetSize() == 0) cur_string = "num_cpus";
+  
+  if (verbose == true) {
+    cout << "Reducing batch " << cur_batch << " to genotypes: ";
+  }
+  
+  tListPlus<cAnalyzeGenotype> & gen_list = batch[cur_batch].List();
+  tListPlus<cAnalyzeGenotype> found_list;
+  while (cur_string.CountNumWords() > 0) {
+    cString gen_desc(cur_string.PopWord());
+    if (verbose) cout << gen_desc << " ";
+    
+    // Determine by lin_type which genotype were are tracking...
+    cAnalyzeGenotype * found_gen = PopGenotype(gen_desc, cur_batch);
+    
+    if (found_gen == NULL) {
+      cerr << "  Warning: genotype not found!" << endl;
+      continue;
+    }
+    
+    // Save this genotype...
+    found_list.Push(found_gen);
+  }
+  cout << endl;
+  
+  // Delete all genotypes other than the ones found!
+  while (gen_list.GetSize() > 0) delete gen_list.Pop();
+  
+  // And fill it back in with the good stuff.
+  while (found_list.GetSize() > 0) gen_list.Push(found_list.Pop());
+  
+  // Adjust the flags on this batch
+  batch[cur_batch].SetLineage(false);
+  batch[cur_batch].SetAligned(false);
+}
+
+void cAnalyze::FindOrganism(cString cur_string)
+{
+  // At least one argument is rquired.
+  if (cur_string.GetSize() == 0) {
+    cerr << "Error: At least one argument is required in FIND_ORGANISM." << endl;
+    return;
+  }
+  
+  if (verbose == true) {
+    cout << "Reducing batch " << cur_batch << " to organisms: " << endl;
+  }
+  
+  tListPlus<cAnalyzeGenotype> & gen_list = batch[cur_batch].List();
+  tListPlus<cAnalyzeGenotype> found_list;
+  
+  tArray<int> new_counts(gen_list.GetSize());
+  new_counts.SetAll(0);
+  
+  while (cur_string.CountNumWords() > 0) {
+    cString org_desc(cur_string.PopWord());
+    if (verbose) cout << org_desc << " ";
+    
+    // Determine by org_desc which genotype were are tracking...
+    if (org_desc == "random") {
+      bool found = false; 
+      int num_orgs = gen_list.Count(&cAnalyzeGenotype::GetNumCPUs);
+      while (found != true) {
+      	int org_chosen = random.GetUInt(num_orgs);
+      	cAnalyzeGenotype * found_genotype = 
+          gen_list.FindSummedValue(org_chosen, &cAnalyzeGenotype::GetNumCPUs);
+        if ( found_genotype->GetNumCPUs() != 0 && found_genotype->GetViable()) {
+          found_genotype->SetNumCPUs(found_genotype->GetNumCPUs()-1);
+          new_counts[gen_list.FindPosPtr(found_genotype)] +=1;
+          cout << "Found genotype " << gen_list.FindPosPtr(found_genotype) << endl;
+          found = true;
+        }
+      }
+    }
+    
+    // pick a random organisms, with replacement!
+    if (org_desc == "randomWR") {
+      bool found = false;
+      int num_orgs = gen_list.Count(&cAnalyzeGenotype::GetNumCPUs);
+      while (found != true) {
+        int org_chosen = random.GetUInt(num_orgs);
+        cAnalyzeGenotype * found_genotype =
+          gen_list.FindSummedValue(org_chosen, &cAnalyzeGenotype::GetNumCPUs);
+        if ( found_genotype->GetNumCPUs() != 0 && found_genotype->GetViable()) {
+          new_counts[gen_list.FindPosPtr(found_genotype)] +=1;
+          cout << "Found genotype " << gen_list.FindPosPtr(found_genotype) << endl;
+          found = true;
+        }
+      }
+    }
+  }
+  
+  int pos_count = 0;
+  cAnalyzeGenotype * genotype = NULL;
+  tListIterator<cAnalyzeGenotype> batch_it(batch[cur_batch].List());
+  
+  while ((genotype = batch_it.Next()) != NULL) {
+    genotype->SetNumCPUs(new_counts[pos_count]);
+    if (genotype->GetNumCPUs() == 0) batch_it.Remove();
+    else cout << "Genotype " << pos_count << " has " << new_counts[pos_count] << " organisms." << endl;
+    pos_count++;
+  }
+  
+  // Adjust the flags on this batch
+  batch[cur_batch].SetLineage(false);
+  batch[cur_batch].SetAligned(false);
+}
+
+void cAnalyze::FindLineage(cString cur_string)
+{
+  cString lin_type = "num_cpus";
+  if (cur_string.CountNumWords() > 0) lin_type = cur_string.PopWord();
+  
+  if (verbose == true) {
+    cout << "Reducing batch " << cur_batch
+    << " to " << lin_type << " lineage " << endl;
+  } else cout << "Performing lineage scan..." << endl;
+  
+  
+  // Determine by lin_type which genotype we are tracking...
+  cAnalyzeGenotype * found_gen = PopGenotype(lin_type, cur_batch);
+  
+  if (found_gen == NULL) {
+    cerr << "  Warning: Genotype " << lin_type
+    << " not found.  Lineage scan aborted." << endl;
+    return;
+  }
+  
+  // Otherwise, trace back through the id numbers to mark all of those
+  // in the ancestral lineage...
+  
+  // Construct a list of genotypes found...
+  
+  tListPlus<cAnalyzeGenotype> found_list;
+  found_list.Push(found_gen);
+  int next_id = found_gen->GetParentID();
+  bool found = true;
+  while (found == true) {
+    found = false;
+    
+    tListIterator<cAnalyzeGenotype> batch_it(batch[cur_batch].List());
+    while ((found_gen = batch_it.Next()) != NULL) {
+      if (found_gen->GetID() == next_id) {
+        batch_it.Remove();
+        found_list.Push(found_gen);
+        next_id = found_gen->GetParentID();
+        found = true;
+        break;
+      }
+    }
+  }
+  
+  // We now have all of the genotypes in this lineage, delete everything
+  // else.
+  
+  const int total_removed = batch[cur_batch].List().GetSize();
+  while (batch[cur_batch].List().GetSize() > 0) {
+    delete batch[cur_batch].List().Pop();
+  }
+  
+  // And fill it back in with the good stuff.
+  int total_kept = found_list.GetSize();
+  while (found_list.GetSize() > 0) {
+    batch[cur_batch].List().PushRear(found_list.Pop());
+  }
+  
+  if (verbose == true) {
+    cout << "  Lineage has " << total_kept << " genotypes; "
+    << total_removed << " were removed." << endl;
+  }
+  
+  // Adjust the flags on this batch
+  batch[cur_batch].SetLineage(true);
+  batch[cur_batch].SetAligned(false);
+}
+
+void cAnalyze::FindSexLineage(cString cur_string)
+{
+  
+  // detemine the method for construicting a lineage 
+  // by defauly, find the lineage of the final dominant
+  cString lin_type = "num_cpus";
+  if (cur_string.CountNumWords() > 0) lin_type = cur_string.PopWord();
+  
+  // parent_method determins which of the two parental lineages to use
+  // "rec_region_size" : 
+  //		"mother" (dominant parent) is the parent contributing
+  // 		more to the offspring genome (default)
+  // "genome_size" : 
+  //		"mother" (dominant parent) is the longer parent 
+  cString parent_method = "rec_region_size";
+  if (cur_string.CountNumWords() > 0) parent_method = cur_string.PopWord();
+  
+  if (verbose == true) {
+    cout << "Reducing batch " << cur_batch
+    << " to " << lin_type << " sexual lineage " 
+    << " using " << parent_method << " criteria." << endl;
+  } else cout << "Performing sexual lineage scan..." << endl;
+  
+  
+  // Determine by lin_type which genotype we are tracking...
+  cAnalyzeGenotype * found_gen = PopGenotype(lin_type, cur_batch);
+  
+  cAnalyzeGenotype * found_dad;
+  cAnalyzeGenotype * found_mom;
+  cAnalyzeGenotype * found_temp;
+  
+  if (found_gen == NULL) {
+    cerr << "  Warning: Genotype " << lin_type
+    << " not found.  Sexual lineage scan aborted." << endl;
+    return;
+  }
+  
+  // Otherwise, trace back through the id numbers to mark all of those
+  // in the ancestral lineage...
+  
+  // Construct a list of genotypes found...
+  
+  tListPlus<cAnalyzeGenotype> found_list;
+  found_list.Push(found_gen);
+  int next_id1 = found_gen->GetParentID();
+  int next_id2 = found_gen->GetParent2ID();
+  
+  bool found_m = true;
+  bool found_d = true;
+  
+  while (found_m == true & found_d == true) {
+    
+    //cout << "Searching for mom=" << next_id1
+    //	 << " and dad=" << next_id2 << endl;
+    found_m = false;
+    found_d = false;
+    
+    // Look for the father first....
+    tListIterator<cAnalyzeGenotype> batch_it(batch[cur_batch].List());
+    batch_it.Reset();
+    while ((found_dad = batch_it.Next()) != NULL) {
+      // Check if the father is found...
+      if (found_dad->GetID() == next_id2) {
+        //cout << "Found dad!" << endl;
+        batch_it.Remove();
+        found_list.Push(found_dad);
+        found_d = true; 
+        break;
+      }
+    }
+    
+    // dad may have already been found, check the find list!
+    if (found_d == false) {
+      tListIterator<cAnalyzeGenotype> found_it(found_list);
+      while ((found_dad = found_it.Next()) != NULL) {
+        if (found_dad->GetID() == next_id2) {
+          //cout << "Found dad in found list!" << endl;
+          found_d = true;
+          break;
+        }
+      }
+    } 
+    
+    // Next, look for the mother...
+    batch_it.Reset();
+    while ((found_mom = batch_it.Next()) != NULL) {
+      if (found_mom->GetID() == next_id1) {
+        //cout << "Found mom!" << endl;
+        batch_it.Remove();
+        found_list.Push(found_mom);
+        // if finding lineages by parental length, may have to swap 
+        if (parent_method == "genome_size" & 
+            found_mom->GetLength() < found_dad->GetLength()) { 
+          //cout << "Swapping parents!" << endl;
+          found_temp = found_mom; 
+          found_mom = found_dad; 
+          found_dad = found_temp; 
+        } 	
+        next_id1 = found_mom->GetParentID();
+        next_id2 = found_mom->GetParent2ID();
+        found_m = true;
+        break;
+      }
+    }
+    
+    // If the mother was not found, it may already have been placed in the
+    // found list as a father... 
+    if (found_m == false) {
+      tListIterator<cAnalyzeGenotype> found_it(found_list);
+      while ((found_mom = found_it.Next()) != NULL) {
+        if (found_mom->GetID() == next_id1) {
+          //cout << "Found mom as dad!" << endl;
+          // Don't move to found list, since its already there, but update
+          // to the next ids.
+          // if finding lineages by parental length, may have to swap 
+          if (parent_method == "genome_size" & 
+              found_mom->GetLength() < found_dad->GetLength()) {
+            //cout << "Swapping parents!" << endl;
+            found_temp = found_mom; 
+            found_mom = found_dad;  
+            found_dad = found_temp;
+          }
+          next_id1 = found_mom->GetParentID();
+          next_id2 = found_mom->GetParent2ID();
+          found_m = true;
+          break;
+        }
+      }
+    }    
+  }
+  
+  // We now have all of the genotypes in this lineage, delete everything
+  // else.
+  
+  const int total_removed = batch[cur_batch].List().GetSize();
+  while (batch[cur_batch].List().GetSize() > 0) {
+    delete batch[cur_batch].List().Pop();
+  }
+  
+  // And fill it back in with the good stuff.
+  int total_kept = found_list.GetSize();
+  while (found_list.GetSize() > 0) {
+    batch[cur_batch].List().PushRear(found_list.Pop());
+  }
+  
+  if (verbose == true) {
+    cout << "  Sexual lineage has " << total_kept << " genotypes; "
+    << total_removed << " were removed." << endl;
+  }
+  
+  // Adjust the flags on this batch
+  batch[cur_batch].SetLineage(false);
+  batch[cur_batch].SetAligned(false);
+}
+
+void cAnalyze::FindClade(cString cur_string)
+{
+  if (cur_string.GetSize() == 0) {
+    cerr << "  Warning: No clade specified for FIND_CLADE.  Aborting." << endl;
+    return;
+  }
+  
+  cString clade_type( cur_string.PopWord() );
+  
+  if (verbose == true) {
+    cout << "Reducing batch " << cur_batch
+    << " to clade " << clade_type << "." << endl;
+  } else cout << "Performing clade scan..." << endl;
+  
+  
+  // Determine by clade_type which genotype we are tracking...
+  cAnalyzeGenotype * found_gen = PopGenotype(clade_type, cur_batch);
+  
+  if (found_gen == NULL) {
+    cerr << "  Warning: Ancestral genotype " << clade_type
+    << " not found.  Clade scan aborted." << endl;
+    return;
+  }
+  
+  // Do this the brute force way... scan for one step at a time.
+  
+  // Construct a list of genotypes found...
+  
+  tListPlus<cAnalyzeGenotype> found_list; // Found and finished.
+  tListPlus<cAnalyzeGenotype> scan_list;  // Found, but need to scan for children.
+  scan_list.Push(found_gen);
+  
+  // Keep going as long as there is something in the scan list...
+  while (scan_list.GetSize() > 0) {
+    // Move the next genotype from the scan list to the found_list.
+    found_gen = scan_list.Pop();
+    int parent_id = found_gen->GetID();
+    found_list.Push(found_gen);
+    
+    // Seach for all of the children of this genotype...
+    tListIterator<cAnalyzeGenotype> batch_it(batch[cur_batch].List());
+    while ((found_gen = batch_it.Next()) != NULL) {
+      // If we found a child, place it into the scan list.
+      if (found_gen->GetParentID() == parent_id) {
+        batch_it.Remove();
+        scan_list.Push(found_gen);
+      }
+    }
+  }
+  
+  // We now have all of the genotypes in this clade, delete everything else.
+  
+  const int total_removed = batch[cur_batch].List().GetSize();
+  while (batch[cur_batch].List().GetSize() > 0) {
+    delete batch[cur_batch].List().Pop();
+  }
+  
+  // And fill it back in with the good stuff.
+  int total_kept = found_list.GetSize();
+  while (found_list.GetSize() > 0) {
+    batch[cur_batch].List().PushRear(found_list.Pop());
+  }
+  
+  if (verbose == true) {
+    cout << "  Clade has " << total_kept << " genotypes; "
+    << total_removed << " were removed." << endl;
+  }
+  
+  // Adjust the flags on this batch
+  batch[cur_batch].SetLineage(false);
+  batch[cur_batch].SetAligned(false);
+}
+
+void cAnalyze::SampleOrganisms(cString cur_string)
+{
+  double fraction = cur_string.PopWord().AsDouble();
+  int init_genotypes = batch[cur_batch].List().GetSize();
+  
+  double test_viable = 0; 
+  if (cur_string.GetSize() > 0) {
+    test_viable = cur_string.PopWord().AsDouble();
+  }
+  
+  if (verbose == true) {
+    cout << "Sampling " << fraction << " organisms from batch "
+    << cur_batch << "." << endl;
+  }
+  else cout << "Sampling Organisms..." << endl;
+  
+  int old_total = 0;
+  int new_total = 0;
+  
+  cAnalyzeGenotype * genotype = NULL;
+  tListIterator<cAnalyzeGenotype> batch_it(batch[cur_batch].List());
+  
+  // of only interested in viables, remove them first. 
+  if (test_viable==1) {
+    while ((genotype = batch_it.Next()) != NULL) {
+      if ((genotype->GetViable())==0) { 
+        batch_it.Remove();
+        delete genotype;
+      } 
+    } 
+  } 
+  
+  batch_it.Reset();
+  
+  while ((genotype = batch_it.Next()) != NULL) {
+    const int old_count = genotype->GetNumCPUs();
+    const int new_count = random.GetRandBinomial(old_count, fraction);
+    old_total += old_count;
+    new_total += new_count;
+    
+    if (new_count == 0) {
+      batch_it.Remove();
+      delete genotype;
+    } else {
+      genotype->SetNumCPUs(new_count);
+    }
+  }
+  
+  int num_genotypes = batch[cur_batch].List().GetSize();
+  if (verbose) {
+    cout << "  Removed " << old_total - new_total
+    << " organisms (" << init_genotypes - num_genotypes
+    << " genotypes); " << new_total
+    << " orgs (" << num_genotypes << " gens) remaining."
+    << endl;
+  }
+  
+  // Adjust the flags on this batch
+  batch[cur_batch].SetLineage(false);
+  batch[cur_batch].SetAligned(false);
+}
+
+
+void cAnalyze::SampleGenotypes(cString cur_string)
+{
+  double fraction = cur_string.PopWord().AsDouble();
+  int init_genotypes = batch[cur_batch].List().GetSize();
+  
+  double test_viable = 0;
+  if (cur_string.GetSize() > 0) {
+    test_viable = cur_string.PopWord().AsDouble();
+  }
+  
+  if (verbose == true) {
+    cout << "Sampling " << fraction << " genotypes from batch "
+    << cur_batch << "." << endl;
+  }
+  else cout << "Sampling Genotypes..." << endl;
+  
+  double frac_remove = 1.0 - fraction;
+  
+  cAnalyzeGenotype * genotype = NULL;
+  
+  tListIterator<cAnalyzeGenotype> batch_it(batch[cur_batch].List());
+  while ((genotype = batch_it.Next()) != NULL) {
+    if (random.P(frac_remove) || ((genotype->GetViable())==0 && test_viable==1) ) {
+      batch_it.Remove();
+      delete genotype;
+    }
+  }
+  
+  int num_genotypes = batch[cur_batch].List().GetSize();
+  if (verbose == true) {
+    cout << "  Removed " << init_genotypes - num_genotypes
+    << " genotypes; " << num_genotypes << " remaining."
+    << endl;
+  }
+  
+  // Adjust the flags on this batch
+  batch[cur_batch].SetLineage(false);
+  batch[cur_batch].SetAligned(false);
+}
+
+void cAnalyze::KeepTopGenotypes(cString cur_string)
+{
+  const int num_kept = cur_string.PopWord().AsInt();
+  const int num_genotypes = batch[cur_batch].List().GetSize();
+  const int num_removed = num_genotypes - num_kept;
+  
+  for (int i = 0; i < num_removed; i++) {
+    delete batch[cur_batch].List().PopRear();
+  }
+  
+  // Adjust the flags on this batch
+  // batch[cur_batch].SetLineage(false); // Should not destroy a lineage...
+  batch[cur_batch].SetAligned(false);
+}
+
+
+
+//////////////// Output Commands...
+
+void cAnalyze::CommandPrint(cString cur_string)
+{
+  if (verbose == true) cout << "Printing batch " << cur_batch << endl;
+  else cout << "Printing organisms..." << endl;
+  
+  cString directory = PopDirectory(cur_string, "genebank/");
+  
+  tListIterator<cAnalyzeGenotype> batch_it(batch[cur_batch].List());
+  cAnalyzeGenotype * genotype = NULL;
+  while ((genotype = batch_it.Next()) != NULL) {
+    cString filename(directory);
+    
+    if (cur_string.GetSize() > 0) {
+      filename += cur_string.PopWord();
+    }
+    else { 
+      filename += genotype->GetName();
+      filename += ".gen";
+    }
+    
+    cTestUtil::PrintGenome(genotype->GetGenome(), filename);
+    if (verbose) cout << "Printing: " << filename << endl;
+  }
+}
+
+void cAnalyze::CommandTrace(cString cur_string)
+{
+  if (verbose == true) cout << "Tracing batch " << cur_batch << endl;
+  else cout << "Tracing organisms..." << endl;
+  
+  int words = cur_string.CountNumWords();
+  
+  cString dir = cur_string.PopWord();
+  cString defaultDirectory = "genebank/";
+  cString directory = PopDirectory(dir, defaultDirectory);
+  
+  int useResources = 0;
+  if(words >= 2) {
+    useResources = cur_string.PopWord().AsInt();
+    // All non-zero values are considered false
+    if(useResources != 0 && useResources != 1) {
+      useResources = 0;
+    }
+  }
+  
+  bool backupUsage;
+  tArray<double> backupResources;
+  
+  if(useResources) {
+    // Backup test cpu data
+    backupUsage = cTestCPU::UseResources();
+    backupResources = cTestCPU::GetResources();
+    
+    cTestCPU::UseResources() = true;
+  }
+  
+  tListIterator<cAnalyzeGenotype> batch_it(batch[cur_batch].List());
+  cAnalyzeGenotype * genotype = NULL;
+  while ((genotype = batch_it.Next()) != NULL) {
+    cString filename(directory);
+    filename += genotype->GetName();
+    filename += ".trace";
+    
+    if (genotype->GetGenome().GetSize() == 0) {
+      break;
+    }
+    
+    // Build the hardware status printer for tracing.
+    ofstream trace_fp;
+    trace_fp.open(filename);
+    assert (trace_fp.good() == true); // Unable to open trace file.
+    cHardwareStatusPrinter trace_printer(trace_fp);
+
+    // Build the test info for printing.
+    cCPUTestInfo test_info;
+    test_info.TestThreads();
+    test_info.SetTraceExecution(&trace_printer);
+    
+    cTestCPU::TestGenome(test_info, genotype->GetGenome());
+    
+    if (verbose) cout << "  Tracing: " << filename << endl;
+    trace_fp.close();
+  }
+  
+  if(useResources) {
+    // Set the test cpu back to the state it was in before we messed with it
+    cTestCPU::UseResources() = backupUsage;
+    cTestCPU::SetupResourceArray(backupResources);
+  }
+  
+  return;
+}
+
+void cAnalyze::CommandPrintTasks(cString cur_string)
+{
+  if (verbose == true) cout << "Printing tasks in batch " << cur_batch << endl;
+  else cout << "Printing tasks..." << endl;
+  
+  // Load in the variables...
+  cString filename("tasks.dat");
+  if (cur_string.GetSize() != 0) filename = cur_string.PopWord();
+  
+  ofstream & fp = data_file_manager.GetOFStream(filename);
+  
+  // Loop through all of the genotypes in this batch...
+  tListIterator<cAnalyzeGenotype> batch_it(batch[cur_batch].List());
+  cAnalyzeGenotype * genotype = NULL;
+  while ((genotype = batch_it.Next()) != NULL) {
+    fp << genotype->GetID() << " ";
+    genotype->PrintTasks(fp);
+    fp << endl;
+  }
+}
+
+void cAnalyze::CommandDetail(cString cur_string)
+{
+  if (verbose == true) cout << "Detailing batch " << cur_batch << endl;
+  else cout << "Detailing..." << endl;
+  
+  // Load in the variables...
+  cString filename("detail.dat");
+  if (cur_string.GetSize() != 0) filename = cur_string.PopWord();
+  
+  // Construct a linked list of details needed...
+  tList< tDataEntryCommand<cAnalyzeGenotype> > output_list;
+  tListIterator< tDataEntryCommand<cAnalyzeGenotype> > output_it(output_list);
+  LoadGenotypeDataList(cur_string, output_list);
+  
+  // Determine the file type...
+  int file_type = FILE_TYPE_TEXT;
+  cString file_extension(filename);
+  while (file_extension.Find('.') != -1) file_extension.Pop('.');
+  if (file_extension == "html") file_type = FILE_TYPE_HTML;
+  
+  // Setup the file...
+  if (filename == "cout") {
+    CommandDetail_Header(cout, file_type, output_it);
+    CommandDetail_Body(cout, file_type, output_it);
+  } else {
+    ofstream & fp = data_file_manager.GetOFStream(filename);
+    CommandDetail_Header(fp, file_type, output_it);
+    CommandDetail_Body(fp, file_type, output_it);
+  }
+  
+  // And clean up...
+  while (output_list.GetSize() != 0) delete output_list.Pop();
+}
+
+
+void cAnalyze::CommandDetailTimeline(cString cur_string)
+{
+  if (verbose == true) cout << "Detailing batch "
+    << cur_batch << " based on time" << endl;
+  else cout << "Detailing..." << endl;
+  
+  // Load in the variables...
+  cString filename("detail_timeline.dat");
+  int time_step = 100;
+  int max_time = 100000;
+  if (cur_string.GetSize() != 0) filename = cur_string.PopWord();
+  if (cur_string.GetSize() != 0) time_step = cur_string.PopWord().AsInt();
+  if (cur_string.GetSize() != 0) max_time = cur_string.PopWord().AsInt();
+  
+  if (verbose == true) {
+    cout << "  Time step = " << time_step << endl
+    << "  Max time = " << max_time << endl;
+  }
+  
+  // Construct a linked list of details needed...
+  tList< tDataEntryCommand<cAnalyzeGenotype> > output_list;
+  tListIterator< tDataEntryCommand<cAnalyzeGenotype> > output_it(output_list);
+  LoadGenotypeDataList(cur_string, output_list);
+  
+  // Determine the file type...
+  int file_type = FILE_TYPE_TEXT;
+  cString file_extension(filename);
+  while (file_extension.Find('.') != -1) file_extension.Pop('.');
+  if (file_extension == "html") file_type = FILE_TYPE_HTML;
+  
+  // Setup the file...
+  if (filename == "cout") {
+    CommandDetail_Header(cout, file_type, output_it, time_step);
+    CommandDetail_Body(cout, file_type, output_it, time_step, max_time);
+  } else {
+    ofstream & fp = data_file_manager.GetOFStream(filename);
+    CommandDetail_Header(fp, file_type, output_it, time_step);
+    CommandDetail_Body(fp, file_type, output_it, time_step, max_time);
+  }
+  
+  // And clean up...
+  while (output_list.GetSize() != 0) delete output_list.Pop();
+}
+
+
+void cAnalyze::CommandDetail_Header(ostream & fp, int format_type,
+                                    tListIterator< tDataEntryCommand<cAnalyzeGenotype> > & output_it,
+                                    int time_step)
+{
+  // Write out the header on the file
+  if (format_type == FILE_TYPE_TEXT) {
+    fp << "#filetype genotype_data" << endl;
+    fp << "#format ";
+    if (time_step > 0) fp << "update ";
+    while (output_it.Next() != NULL) {
+      const cString & entry_name = output_it.Get()->GetName();
+      fp << entry_name << " ";
+    }
+    fp << endl << endl;
+    
+    // Give the more human-readable legend.
+    fp << "# Legend:" << endl;
+    int count = 0;
+    if (time_step > 0) fp << "# " << ++count << ": Update" << endl;
+    while (output_it.Next() != NULL) {
+      const cString & entry_desc = output_it.Get()->GetDesc();
+      fp << "# " << ++count << ": " << entry_desc << endl;
+    }
+    fp << endl;
+  } else { // if (format_type == FILE_TYPE_HTML) {
+    fp << "<html>" << endl
+    << "<body bgcolor=\"#FFFFFF\"" << endl
+    << " text=\"#000000\"" << endl
+    << " link=\"#0000AA\"" << endl
+    << " alink=\"#0000FF\"" << endl
+    << " vlink=\"#000044\">" << endl
+    << endl
+    << "<h1 align=center>Run " << batch[cur_batch].Name() << endl
+    << endl
+    << "<center>" << endl
+    << "<table border=1 cellpadding=2><tr>" << endl;
+    
+    if (time_step > 0) fp << "<th bgcolor=\"#AAAAFF\">Update ";
+    while (output_it.Next() != NULL) {
+      const cString & entry_desc = output_it.Get()->GetDesc();
+      fp << "<th bgcolor=\"#AAAAFF\">" << entry_desc << " ";
+    }
+    fp << "</tr>" << endl;
+    
+  }
+  
+  }
+
+
+void cAnalyze::CommandDetail_Body(ostream & fp, int format_type,
+                                  tListIterator< tDataEntryCommand<cAnalyzeGenotype> > & output_it,
+                                  int time_step, int max_time)
+{
+  // Loop through all of the genotypes in this batch...
+  tListIterator<cAnalyzeGenotype> batch_it(batch[cur_batch].List());
+  cAnalyzeGenotype * cur_genotype = batch_it.Next();
+  cAnalyzeGenotype * next_genotype = batch_it.Next();
+  cAnalyzeGenotype * prev_genotype = NULL;
+  
+  int cur_time = 0;
+  while (cur_genotype != NULL && cur_time <= max_time) {
+    output_it.Reset();
+    tDataEntryCommand<cAnalyzeGenotype> * data_command = NULL;
+    if (format_type == FILE_TYPE_HTML) {
+      fp << "<tr>";
+      if (time_step > 0) fp << "<td>" << cur_time << " ";
+    }
+    else if (time_step > 0) {  // TEXT file, printing times...
+      fp << cur_time << " ";
+    }
+    
+    while ((data_command = output_it.Next()) != NULL) {
+      data_command->SetTarget(cur_genotype);
+      cur_genotype->SetSpecialArgs(data_command->GetArgs());
+      if (format_type == FILE_TYPE_HTML) {
+        int compare = 0;
+        if (prev_genotype) {
+          prev_genotype->SetSpecialArgs(data_command->GetArgs());
+          compare = data_command->Compare(prev_genotype);
+        }
+        data_command->HTMLPrint(fp, compare);
+      }
+      else {  // if (format_type == FILE_TYPE_TEXT) {
+        fp << data_command->GetEntry() << " ";
+      }
+      }
+    if (format_type == FILE_TYPE_HTML) fp << "</tr>";
+    fp << endl;
+    
+    cur_time += time_step;
+    if (time_step > 0) {
+      while (next_genotype && next_genotype->GetUpdateBorn() < cur_time) {
+        prev_genotype = cur_genotype;
+        cur_genotype = next_genotype;
+        next_genotype = batch_it.Next();
+      }
+    }
+    else {
+      // Always moveon if we're not basing this on time, or if we've run out
+      // of genotypes.
+      prev_genotype = cur_genotype;
+      cur_genotype = next_genotype;
+      next_genotype = batch_it.Next();
+    }
+    
+    }
+  
+  // If in HTML mode, we need to end the file...
+  if (format_type == FILE_TYPE_HTML) {
+    fp << "</table>" << endl
+    << "</center>" << endl;
+  }
+}
+
+void cAnalyze::CommandDetailAverage_Body(ostream & fp, int num_outputs,
+                                         tListIterator< tDataEntryCommand<cAnalyzeGenotype> > & output_it)
+{
+  // Loop through all of the genotypes in this batch...
+  tListIterator<cAnalyzeGenotype> batch_it(batch[cur_batch].List());
+  cAnalyzeGenotype * cur_genotype = batch_it.Next();
+  cAnalyzeGenotype * next_genotype = batch_it.Next();
+  cAnalyzeGenotype * prev_genotype = NULL;
+  
+  tArray<cDoubleSum> output_counts(num_outputs);
+  for (int i = 0; i < num_outputs; i++) { output_counts[i].Clear();} 
+  int count; 
+  while (cur_genotype != NULL) { 
+    count = 0; 
+    output_it.Reset();
+    tDataEntryCommand<cAnalyzeGenotype> * data_command = NULL;
+    while ((data_command = output_it.Next()) != NULL) {
+      data_command->SetTarget(cur_genotype);
+      cur_genotype->SetSpecialArgs(data_command->GetArgs());
+      for (int j = 0; j < cur_genotype->GetNumCPUs(); j++) { 
+        output_counts[count].Add((double) data_command->GetEntry().AsString().AsDouble()); 
+      } 	
+      count++;
+    }
+    
+    prev_genotype = cur_genotype;
+    cur_genotype = next_genotype;
+    next_genotype = batch_it.Next();
+  }
+  fp << batch[cur_batch].Name() << " "; 
+  for (int i = 0; i < num_outputs; i++) {  
+    fp << output_counts[i].Average() << " ";
+  } 
+  fp << endl;   
+}
+
+void cAnalyze::CommandDetailAverage(cString cur_string) 
+{ 
+  if (verbose == true) cout << "Average detailing batch " << cur_batch << endl;
+  else cout << "Detailing..." << endl;
+  
+  // Load in the variables...
+  cString filename("detail.dat");
+  if (cur_string.GetSize() != 0) filename = cur_string.PopWord();
+  
+  // Construct a linked list of details needed...
+  tList< tDataEntryCommand<cAnalyzeGenotype> > output_list;
+  tListIterator< tDataEntryCommand<cAnalyzeGenotype> > output_it(output_list);
+  LoadGenotypeDataList(cur_string, output_list);
+  
+  // check if file is already in use.
+  bool file_active = data_file_manager.IsOpen(filename);
+  
+  ofstream & fp = data_file_manager.GetOFStream(filename);
+  
+  // if it's a new file print out the header
+  if (file_active == false) {
+    CommandDetail_Header(fp, FILE_TYPE_TEXT, output_it);
+  } 
+  CommandDetailAverage_Body(fp, cur_string.CountNumWords(), output_it);
+  
+  while (output_list.GetSize() != 0) delete output_list.Pop();
+  
+} 
+
+void cAnalyze::CommandDetailBatches(cString cur_string)
+{
+  // Load in the variables...
+  cString keyword("num_cpus");
+  cString filename("detail_batch.dat");
+  if (cur_string.GetSize() != 0) keyword = cur_string.PopWord();
+  if (cur_string.GetSize() != 0) filename = cur_string.PopWord();
+  
+  if (verbose == true) cout << "Detailing batches for " << keyword << endl;
+  else cout << "Detailing Batches..." << endl;
+  
+  // Scan the functions list for the keyword we need...
+  SetupGenotypeDataList();
+  tListIterator< tDataEntryBase<cAnalyzeGenotype> >
+    output_it(genotype_data_list);
+  
+  // Divide up the keyword into its acrual entry and its arguments...
+  cString cur_args = keyword;
+  cString cur_entry = cur_args.Pop(':');
+  
+  // Find its associated command...
+  tDataEntryCommand<cAnalyzeGenotype> * cur_command = NULL;
+  bool found = false;
+  while (output_it.Next() != NULL) {
+    if (output_it.Get()->GetName() == cur_entry) {
+      cur_command = new tDataEntryCommand<cAnalyzeGenotype>
+      (output_it.Get(), cur_args);
+      found = true;
+      break;
+    }
+  }
+  if (found == false) {
+    cout << "Error: Unknown data type: " << cur_entry << endl;
+    return;
+  }
+  
+  
+  // Determine the file type...
+  int file_type = FILE_TYPE_TEXT;
+  cString file_extension(filename);
+  while (file_extension.Find('.') != -1) file_extension.Pop('.');
+  if (file_extension == "html") file_type = FILE_TYPE_HTML;
+  
+  ofstream & fp = data_file_manager.GetOFStream(filename);
+  
+  // Write out the header on the file
+  if (file_type == FILE_TYPE_TEXT) {
+    fp << "#filetype batch_data" << endl
+    << "#format batch_id " << keyword << endl
+    << endl;
+    
+    // Give the more human-readable legend.
+    fp << "# Legend:" << endl
+      << "#  Column 1 = Batch ID" << endl
+      << "#  Remaining entries: " << cur_command->GetDesc() << endl
+      << endl;
+    
+  } else { // if (file_type == FILE_TYPE_HTML) {
+    fp << "<html>" << endl
+    << "<body bgcolor=\"#FFFFFF\"" << endl
+    << " text=\"#000000\"" << endl
+    << " link=\"#0000AA\"" << endl
+    << " alink=\"#0000FF\"" << endl
+    << " vlink=\"#000044\">" << endl
+    << endl
+    << "<h1 align=center> Distribution of " << cur_command->GetDesc()
+    << endl << endl
+    << "<center>" << endl
+    << "<table border=1 cellpadding=2>" << endl
+    << "<tr><th bgcolor=\"#AAAAFF\">" << cur_command->GetDesc() << "</tr>"
+    << endl;
+  }
+  
+  
+  // Loop through all of the batches...
+  for (int i = 0; i < MAX_BATCHES; i++) {
+    if (batch[i].List().GetSize() == 0) continue;
+    
+    if (file_type == FILE_TYPE_HTML) fp << "<tr><td>";
+    fp << i << " ";
+    
+    tListIterator<cAnalyzeGenotype> batch_it(batch[i].List());
+    cAnalyzeGenotype * genotype = NULL;
+    while ((genotype = batch_it.Next()) != NULL) {
+      output_it.Reset();
+      if (file_type == FILE_TYPE_HTML) fp << "<td>";
+      
+      cur_command->SetTarget(genotype);
+      genotype->SetSpecialArgs(cur_command->GetArgs());
+      if (file_type == FILE_TYPE_HTML) {
+        cur_command->HTMLPrint(fp, 0);
+      }
+      else {  // if (file_type == FILE_TYPE_TEXT) {
+        fp << cur_command->GetEntry() << " ";
+      }
+      }
+    if (file_type == FILE_TYPE_HTML) fp << "</tr>";
+    fp << endl;
+    }
+  
+  // If in HTML mode, we need to end the file...
+  if (file_type == FILE_TYPE_HTML) {
+    fp << "</table>" << endl
+    << "</center>" << endl;
+  }
+  
+  delete cur_command;
+  }
+
+
+
+void cAnalyze::CommandDetailIndex(cString cur_string)
+{
+  cout << "Creating a Detail Index..." << endl;
+  
+  // A filename and min and max batches must be included.
+  if (cur_string.CountNumWords() < 3) {
+    cerr << "Error: must include filename, and min and max batch numbers."
+    << endl;
+    exit(1);
+  }
+  
+  // Load in the variables...
+  cString filename(cur_string.PopWord());
+  int min_batch = cur_string.PopWord().AsInt();
+  int max_batch = cur_string.PopWord().AsInt();
+  
+  if (max_batch < min_batch) {
+    cerr << "Error: min_batch=" << min_batch
+    << ", max_batch=" << max_batch << "  (incorrect order?)" << endl;
+    exit(1);
+  }
+  
+  // Construct a linked list of details needed...
+  tList< tDataEntryBase<cAnalyzeGenotype> > output_list;
+  tListIterator< tDataEntryBase<cAnalyzeGenotype> > output_it(output_list);
+  
+  // For the moment, just put everything into the output list.
+  SetupGenotypeDataList();
+  
+  // If no args were given, load all of the stats.
+  if (cur_string.CountNumWords() == 0) {
+    tListIterator< tDataEntryBase<cAnalyzeGenotype> >
+    genotype_data_it(genotype_data_list);
+    while (genotype_data_it.Next() != NULL) {
+      output_list.PushRear(genotype_data_it.Get());
+    }
+  }
+  // Otherwise, load only those listed.
+  else {
+    while (cur_string.GetSize() != 0) {
+      // Setup the next entry
+      cString cur_entry = cur_string.PopWord();
+      bool found_entry = false;
+      
+      // Scan the genotype data list for the current entry
+      tListIterator< tDataEntryBase<cAnalyzeGenotype> >
+        genotype_data_it(genotype_data_list);
+      
+      while (genotype_data_it.Next() != NULL) {
+        if (genotype_data_it.Get()->GetName() == cur_entry) {
+          output_list.PushRear(genotype_data_it.Get());
+          found_entry = true;
+          break;
+        }
+      }
+      
+      // If the entry was not found, give a warning.
+      if (found_entry == false) {
+        int best_match = 1000;
+        cString best_entry;
+        
+        genotype_data_it.Reset();
+        while (genotype_data_it.Next() != NULL) {
+          const cString & test_str = genotype_data_it.Get()->GetName();
+          const int test_dist = cStringUtil::EditDistance(test_str, cur_entry);
+          if (test_dist < best_match) {
+            best_match = test_dist;
+            best_entry = test_str;
+          }
+        }	
+        
+        cerr << "Warning: Format entry \"" << cur_entry
+          << "\" not found.  Best match is \""
+          << best_entry << "\"." << endl;
+      }
+      
+    }
+  }
+  
+  // Setup the file...
+  ofstream fp;
+  fp.open(filename);
+  
+  // Determine the file type...
+  int file_type = FILE_TYPE_TEXT;
+  while (filename.Find('.') != -1) filename.Pop('.'); // Grab only extension
+  if (filename == "html") file_type = FILE_TYPE_HTML;
+  
+  // Write out the header on the file
+  if (file_type == FILE_TYPE_TEXT) {
+    fp << "#filetype genotype_data" << endl;
+    fp << "#format ";
+    while (output_it.Next() != NULL) {
+      const cString & entry_name = output_it.Get()->GetName();
+      fp << entry_name << " ";
+    }
+    fp << endl << endl;
+    
+    // Give the more human-readable legend.
+    fp << "# Legend:" << endl;
+    fp << "# 1: Batch Name" << endl;
+    int count = 1;
+    while (output_it.Next() != NULL) {
+      const cString & entry_desc = output_it.Get()->GetDesc();
+      fp << "# " << ++count << ": " << entry_desc << endl;
+    }
+    fp << endl;
+  } else { // if (file_type == FILE_TYPE_HTML) {
+    fp << "<html>" << endl
+    << "<body bgcolor=\"#FFFFFF\"" << endl
+    << " text=\"#000000\"" << endl
+    << " link=\"#0000AA\"" << endl
+    << " alink=\"#0000FF\"" << endl
+    << " vlink=\"#000044\">" << endl
+    << endl
+    << "<h1 align=center>Batch Index" << endl
+    << endl
+    << "<center>" << endl
+    << "<table border=1 cellpadding=2><tr>" << endl;
+    
+    fp << "<th bgcolor=\"#AAAAFF\">Batch ";
+    while (output_it.Next() != NULL) {
+      const cString & entry_desc = output_it.Get()->GetDesc();
+      fp << "<th bgcolor=\"#AAAAFF\">" << entry_desc << " ";
+    }
+    fp << "</tr>" << endl;
+    
+  }
+  
+  // Loop through all of the batchs...
+  for (int batch_id = min_batch; batch_id <= max_batch; batch_id++) {
+    cAnalyzeGenotype * genotype = batch[batch_id].List().GetFirst();
+    if (genotype == NULL) continue;
+    output_it.Reset();
+    tDataEntryBase<cAnalyzeGenotype> * data_entry = NULL;
+    const cString & batch_name = batch[batch_id].Name();
+    if (file_type == FILE_TYPE_HTML) {
+      fp << "<tr><th><a href=lineage." << batch_name << ".html>"
+      << batch_name << "</a> ";
+    }
+    else {
+      fp << batch_name << " ";
+    }
+    
+    while ((data_entry = output_it.Next()) != NULL) {
+      data_entry->SetTarget(genotype);
+      if (file_type == FILE_TYPE_HTML) {
+        fp << "<td align=center><a href=\""
+        << data_entry->GetName() << "." << batch_name << ".png\">"
+        << *data_entry << "</a> ";
+      }
+      else {  // if (file_type == FILE_TYPE_TEXT) {
+        fp << *data_entry << " ";
+      }
+      }
+    if (file_type == FILE_TYPE_HTML) fp << "</tr>";
+    fp << endl;
+    }
+  
+  // If in HTML mode, we need to end the file...
+  if (file_type == FILE_TYPE_HTML) {
+    fp << "</table>" << endl
+    << "</center>" << endl;
+  }
+}
+
+void cAnalyze::CommandHistogram(cString cur_string)
+{
+  if (verbose == true) cout << "Histogram batch " << cur_batch << endl;
+  else cout << "Histograming..." << endl;
+  
+  // Load in the variables...
+  cString filename("histogram.dat");
+  if (cur_string.GetSize() != 0) filename = cur_string.PopWord();
+  
+  // Construct a linked list of details needed...
+  tList< tDataEntryCommand<cAnalyzeGenotype> > output_list;
+  tListIterator< tDataEntryCommand<cAnalyzeGenotype> > output_it(output_list);
+  LoadGenotypeDataList(cur_string, output_list);
+  
+  // Determine the file type...
+  int file_type = FILE_TYPE_TEXT;
+  cString file_extension(filename);
+  while (file_extension.Find('.') != -1) file_extension.Pop('.');
+  if (file_extension == "html") file_type = FILE_TYPE_HTML;
+  
+  // Setup the file...
+  if (filename == "cout") {
+    CommandHistogram_Header(cout, file_type, output_it);
+    CommandHistogram_Body(cout, file_type, output_it);
+  } else {
+    ofstream & fp = data_file_manager.GetOFStream(filename);
+    CommandHistogram_Header(fp, file_type, output_it);
+    CommandHistogram_Body(fp, file_type, output_it);
+  }
+  
+  // And clean up...
+  while (output_list.GetSize() != 0) delete output_list.Pop();
+}
+
+void cAnalyze::CommandHistogram_Header(ostream & fp, int format_type,
+       tListIterator< tDataEntryCommand<cAnalyzeGenotype> > & output_it)
+{
+  // Write out the header on the file
+  if (format_type == FILE_TYPE_TEXT) {
+    fp << "#filetype histogram_data" << endl;
+    fp << "#format ";
+    while (output_it.Next() != NULL) {
+      const cString & entry_name = output_it.Get()->GetName();
+      fp << entry_name << " ";
+    }
+    fp << endl << endl;
+    
+    // Give the more human-readable legend.
+    fp << "# Histograms:" << endl;
+    int count = 0;
+    while (output_it.Next() != NULL) {
+      const cString & entry_desc = output_it.Get()->GetDesc();
+      fp << "# " << ++count << ": " << entry_desc << endl;
+    }
+    fp << endl;
+  } else { // if (format_type == FILE_TYPE_HTML) {
+    fp << "<html>" << endl
+       << "<body bgcolor=\"#FFFFFF\"" << endl
+       << " text=\"#000000\"" << endl
+       << " link=\"#0000AA\"" << endl
+       << " alink=\"#0000FF\"" << endl
+       << " vlink=\"#000044\">" << endl
+       << endl
+       << "<h1 align=center>Histograms for " << batch[cur_batch].Name()
+       << "</h1>" << endl
+       << endl
+       << "<center>" << endl
+       << "<table border=1 cellpadding=2><tr>" << endl;
+    
+    while (output_it.Next() != NULL) {
+      const cString & entry_desc = output_it.Get()->GetDesc();
+      const cString & entry_name = output_it.Get()->GetName();
+      fp << "<tr><th bgcolor=\"#AAAAFF\"><a href=\"#"
+	 << entry_name << "\">"
+	 << entry_desc << "</a></tr>";
+    }
+    fp << "</tr></table>" << endl;    
+  }
+}
+
+
+void cAnalyze::CommandHistogram_Body(ostream & fp, int format_type,
+	     tListIterator< tDataEntryCommand<cAnalyzeGenotype> > & output_it)
+{
+  output_it.Reset();
+  tDataEntryCommand<cAnalyzeGenotype> * data_command = NULL;
+    
+  while ((data_command = output_it.Next()) != NULL) {
+    if (format_type == FILE_TYPE_TEXT) {
+      fp << "# --- " << data_command->GetDesc() << " ---" << endl;
+    } else {
+      fp << "<table cellpadding=3>" << endl
+	 << "<tr><th colspan=3><a name=\"" << data_command->GetName() << "\">"
+	 << data_command->GetDesc() << "</th></tr>" << endl;
+    }
+
+    tDictionary<int> count_dict;
+
+    // Loop through all genotypes in this batch to collect the info we need.
+    tListIterator<cAnalyzeGenotype> batch_it(batch[cur_batch].List());
+    cAnalyzeGenotype * cur_genotype;
+    while ((cur_genotype = batch_it.Next()) != NULL) {
+      data_command->SetTarget(cur_genotype);
+      const cString cur_name(data_command->GetEntry().AsString());
+      int count = 0;
+      count_dict.Find(cur_name, count);
+      count += cur_genotype->GetNumCPUs();
+      count_dict.SetValue(cur_name, count);
+    }
+
+    tList<cString> name_list;
+    tList<int> count_list;
+    count_dict.AsLists(name_list, count_list);
+
+    // Figure out the maximum count and the maximum widths...
+    int max_count = 0;
+    int max_name_width = 0;
+    int max_count_width = 0;
+    tListIterator<int> count_it(count_list);
+    tListIterator<cString> name_it(name_list);
+    while (count_it.Next() != NULL) {
+      const cString cur_name( *(name_it.Next()) );
+      const int cur_count = *(count_it.Get());
+      const int name_width = cur_name.GetSize();
+      const int count_width = cStringUtil::Stringf("%d", cur_count).GetSize();
+      if (cur_count > max_count) max_count = cur_count;
+      if (name_width > max_name_width) max_name_width = name_width;
+      if (count_width > max_count_width) max_count_width = count_width;
+    }
+
+    // Do some final calculations now that we know the maximums...
+    const int max_stars = 75 - max_name_width - max_count_width;
+
+    // Now print everything out...
+    count_it.Reset();
+    name_it.Reset();
+    while (count_it.Next() != NULL) {
+      const cString cur_name( *(name_it.Next()) );
+      const int cur_count = *(count_it.Get());
+      if (cur_count == 0) continue;
+      int num_stars = (cur_count * max_stars) / max_count;
+
+      if (format_type == FILE_TYPE_TEXT) {
+	fp << setw(max_name_width) << cur_name << "  " 
+	   << setw(max_count_width) << cur_count << "  ";
+	for (int i = 0; i < num_stars; i++) { fp << '#'; }
+	fp << endl;
+      } else { // FILE_TYPE_HTML
+	fp << "<tr><td>" << cur_name
+	   << "<td>" << cur_count
+	   << "<td>";
+	for (int i = 0; i < num_stars; i++) { fp << '#'; }
+	fp << "</tr>" << endl;
+      }
+    }
+
+    if (format_type == FILE_TYPE_TEXT) {
+      // Skip a line between histograms...
+      fp << endl;
+    } else {
+      fp << "</table><br><br>" << endl << endl;;
+    }
+  }
+  
+  // If in HTML mode, we need to end the file...
+  if (format_type == FILE_TYPE_HTML) {
+    fp << "</table>" << endl
+    << "</center>" << endl;
+  }
+}
+
+
+///// Population Analysis Commands ////
+
+void cAnalyze::CommandPrintPhenotypes(cString cur_string)
+{
+  if (verbose == true) cout << "Printing phenotypes in batch "
+    << cur_batch << endl;
+  else cout << "Printing phenotypes..." << endl;
+  
+  // Load in the variables...
+  cString filename("phenotype.dat");
+  if (cur_string.GetSize() != 0) filename = cur_string.PopWord();
+  
+  // Make sure we have at least one genotype...
+  if (batch[cur_batch].List().GetSize() == 0) return;
+  
+  // Setup the phenotype categories...
+  const int num_tasks = batch[cur_batch].List().GetFirst()->GetNumTasks();
+  const int num_phenotypes = 1 << (num_tasks + 1);
+  tArray<int> phenotype_counts(num_phenotypes);
+  tArray<int> genotype_counts(num_phenotypes);
+  tArray<double> total_length(num_phenotypes);
+  tArray<double> total_gest(num_phenotypes);
+  
+  phenotype_counts.SetAll(0);
+  genotype_counts.SetAll(0);
+  total_length.SetAll(0.0);
+  total_gest.SetAll(0.0);
+  
+  // Loop through all of the genotypes in this batch...
+  tListIterator<cAnalyzeGenotype> batch_it(batch[cur_batch].List());
+  cAnalyzeGenotype * genotype = NULL;
+  while ((genotype = batch_it.Next()) != NULL) {
+    int phen_id = 0;
+    if (genotype->GetViable() == true) phen_id++;
+    for (int i = 0; i < num_tasks; i++) {
+      if (genotype->GetTaskCount(i) > 0)  phen_id += 1 << (i+1);
+    }
+    phenotype_counts[phen_id] += genotype->GetNumCPUs();
+    genotype_counts[phen_id]++;
+    total_length[phen_id] += genotype->GetNumCPUs() * genotype->GetLength();
+    total_gest[phen_id] += genotype->GetNumCPUs() * genotype->GetGestTime();
+  }
+  
+  // Print out the results...
+  
+  ofstream & fp = data_file_manager.GetOFStream(filename);
+  
+  fp << "# 1: Number of organisms of this phenotype" << endl
+    << "# 2: Number of genotypes of this phenotye" << endl
+    << "# 3: Average Genome Length" << endl
+    << "# 4: Average Gestation Time" << endl
+    << "# 5: Viability of Phenotype" << endl
+    << "# 6+: Tasks performed in this phenotype" << endl
+    << endl;
+  
+  // @CAO Lets do this inefficiently for the moment, but print out the
+  // phenotypes in order.
+  
+  while (true) {
+    // Find the next phenotype to print...
+    int max_count = phenotype_counts[0];
+    int max_position = 0;
+    for (int i = 0; i < num_phenotypes; i++) {
+      if (phenotype_counts[i] > max_count) {
+        max_count = phenotype_counts[i];
+        max_position = i;
+      }
+    }
+    
+    if (max_count == 0) break; // we're done!
+    
+    fp << phenotype_counts[max_position] << " "
+      << genotype_counts[max_position] << " "
+      << total_length[max_position] / phenotype_counts[max_position] << " "
+      << total_gest[max_position] / phenotype_counts[max_position] << " "
+      << (max_position & 1) << "  ";
+    for (int i = 1; i <= num_tasks; i++) {
+      if ((max_position >> i) & 1 > 0) fp << "1 ";
+      else fp << "0 ";
+    }
+    fp << endl;
+    phenotype_counts[max_position] = 0;
+  }
+  
+  fp.close();
+}
+
+
+// Print various diversity metrics from the current batch of genotypes...
+void cAnalyze::CommandPrintDiversity(cString cur_string)
+{
+  if (verbose == true) cout << "Printing diversity data for batch "
+    << cur_batch << endl;
+  else cout << "Printing diversity data..." << endl;
+  
+  // Load in the variables...
+  cString filename("diversity.dat");
+  if (cur_string.GetSize() != 0) filename = cur_string.PopWord();
+  
+  // Make sure we have at least one genotype...
+  if (batch[cur_batch].List().GetSize() == 0) return;
+  
+  // Setup the task categories...
+  const int num_tasks = batch[cur_batch].List().GetFirst()->GetNumTasks();
+  tArray<int> task_count(num_tasks);
+  tArray<int> task_gen_count(num_tasks);
+  tArray<double> task_gen_dist(num_tasks);
+  tArray<double> task_site_entropy(num_tasks);
+  task_count.SetAll(0);
+  task_gen_count.SetAll(0);
+  
+  // We must determine the average hamming distance between genotypes in
+  // this batch that perform each task.  Levenstein distance would be ideal,
+  // but takes a while, so we'll do it this way first.  For the calculations,
+  // we need to know home many times each instruction appears at each
+  // position for each genotype collection that performs a particular task.
+  const int num_insts = inst_set.GetSize();
+  const int max_length = BatchUtil_GetMaxLength();
+  tMatrix<int> inst_freq(max_length, num_insts+1);
+  
+  for (int task_id = 0; task_id < num_tasks; task_id++) {
+    inst_freq.SetAll(0);
+    
+    // Loop through all genotypes, singling out those that do current task...
+    tListIterator<cAnalyzeGenotype> batch_it(batch[cur_batch].List());
+    cAnalyzeGenotype * genotype = NULL;
+    while ((genotype = batch_it.Next()) != NULL) {
+      if (genotype->GetTaskCount(task_id) == 0) continue;
+      
+      const cGenome & genome = genotype->GetGenome();
+      const int num_cpus = genotype->GetNumCPUs();
+      task_count[task_id] += num_cpus;
+      task_gen_count[task_id]++;
+      for (int i = 0; i < genotype->GetLength(); i++) {
+        inst_freq( i, genome[i].GetOp() ) += num_cpus;
+      }
+      for (int i = genotype->GetLength(); i < max_length; i++) {
+        inst_freq(i, num_insts) += num_cpus; // Entry for "past genome end"
+      }
+    }
+    
+    // Analyze the data for this entry...
+    const int cur_count = task_count[task_id];
+    const int total_pairs = cur_count * (cur_count - 1) / 2;
+    int total_dist = 0;
+    double total_ent = 0;
+    for (int pos = 0; pos < max_length; pos++) {
+      // Calculate distance component...
+      for (int inst1 = 0; inst1 < num_insts; inst1++) {
+        if (inst_freq(pos, inst1) == 0) continue;
+        for (int inst2 = inst1+1; inst2 <= num_insts; inst2++) {
+          total_dist += inst_freq(pos, inst1) * inst_freq(pos, inst2);
+        }
+      }
+      
+      // Calculate entropy component...
+      for (int i = 0; i <= num_insts; i++) {
+        const int cur_freq = inst_freq(pos, i);
+        if (cur_freq == 0) continue;
+        const double p = ((double) cur_freq) / (double) cur_count;
+        total_ent -= p * log(p);
+      }
+    }
+    
+    task_gen_dist[task_id] = ((double) total_dist) / (double) total_pairs;
+    task_site_entropy[task_id] = total_ent;
+  }
+  
+  // Print out the results...
+  cDataFile & df = data_file_manager.Get(filename);
+  
+  for (int i = 0; i < num_tasks; i++) {
+    df.Write(i,                    "# 1: Task ID");
+    df.Write(task_count[i],        "# 2: Number of organisms performing task");
+    df.Write(task_gen_count[i],    "# 3: Number of genotypes performing task");
+    df.Write(task_gen_dist[i],     "# 4: Average distance between genotypes performing task");
+    df.Write(task_site_entropy[i], "# 5: Total per-site entropy of genotypes performing task");
+    df.Endl();
+  }
+}
+
+
+void cAnalyze::PhyloCommunityComplexity(cString cur_string)
+{
+
+  /////////////////////////////////////////////////////////////////////////
+  // Calculate the mutual information between all genotypes and environment
+  /////////////////////////////////////////////////////////////////////////
+
+  cout << "Analyze biocomplexity of current population about environment ...\n";
+
+  // Get the number of genotypes that are gonna be analyzed.
+  int max_genotypes = cur_string.PopWord().AsInt();
+
+  // Get update
+  int update = cur_string.PopWord().AsInt();
+
+  // Get the directory  
+  cString dir = cur_string.PopWord();
+  cString defaultDir = "community_cpx/";
+  cString directory = PopDirectory(dir, defaultDir);
+
+  // Get the file name that saves the result 
+  cString filename = cur_string.PopWord();
+  if (filename.IsEmpty()) {
+    filename = "community.complexity.dat";
+  }
+
+  filename.Set("%s%s", directory(), filename.GetData());
+  ofstream cpx_fp(filename());
+
+  cpx_fp << "# Legend:" << endl;
+  cpx_fp << "# 1: Genotype ID" << endl;
+  cpx_fp << "# 2: Entropy given Known Genotypes" << endl;
+  cpx_fp << "# 3: Entropy given Both Known Genotypes and Env" << endl;
+  cpx_fp << "# 4: New Information about Environment" << endl;
+  cpx_fp << "# 5: Total Complexity" << endl;
+  cpx_fp << endl;
+
+  /////////////////////////////////////////////////////////////////////////////////
+  // Loop through all of the genotypes in all batches and build id vs. genotype map
+
+  map<int, cAnalyzeGenotype *> genotype_database;
+  for (int i = 0; i < MAX_BATCHES; ++ i) {
+    tListIterator<cAnalyzeGenotype> batch_it(batch[i].List());
+    cAnalyzeGenotype * genotype = NULL;
+    while ((genotype = batch_it.Next()) != NULL) {
+      genotype_database.insert(make_pair(genotype->GetID(), genotype));
+    }
+  }
+
+  ////////////////////////////////////////////////
+  // Check if all the genotypes having same length
+
+  int length_genome;
+  if (genotype_database.size() > 0) {
+    length_genome = genotype_database.begin()->second->GetLength();
+  }
+  map<int, cAnalyzeGenotype *>::iterator gen_iterator = genotype_database.begin();
+  for (; gen_iterator != genotype_database.end(); ++ gen_iterator) {
+    if (gen_iterator->second->GetLength() != length_genome) {
+      cerr << "Genotype " << gen_iterator->first << " has different genome length." << endl;
+      exit(1);
+    }
+  }
+
+  ///////////////////////
+  // Backup test CPU data
+  bool backupUsage = cTestCPU::UseResources();
+  tArray<double> backupResources(cTestCPU::GetResources());
+  cTestCPU::UseResources() = true;
+  FillResources(update);
+
+  ///////////////////////////////////////////////////////////////////////
+  // Choose the first n most abundant genotypes and put them in community
+
+  vector<cAnalyzeGenotype *> community;
+  cAnalyzeGenotype * genotype = NULL;
+  tListIterator<cAnalyzeGenotype> batch_it(batch[cur_batch].List());
+
+  while (((genotype = batch_it.Next()) != NULL) && (community.size() < max_genotypes)) {
+    community.push_back(genotype);
+  }
+    
+  ///////////////////////////
+  // Measure hamming distance
+
+  int size_community = community.size();
+  if (size_community == 0) {
+    cerr << "There is no genotype in this community." << endl;
+    cpx_fp.close();
+    exit(1);
+  }
+  typedef pair<int,int> gen_pair;
+  map<gen_pair, int> hamming_dist;
+  
+  for (int i = 0; i< size_community; ++ i) {
+    for (int j = i+1; j < size_community; ++ j) {
+      int dist = cGenomeUtil::FindHammingDistance(community[i]->GetGenome(),
+						  community[j]->GetGenome());
+      int id1 = community[i]->GetID();
+      int id2 = community[j]->GetID();
+
+      hamming_dist.insert(make_pair(gen_pair(id1, id2), dist));
+      hamming_dist.insert(make_pair(gen_pair(id2, id1), dist));
+    }
+  }
+
+  //////////////////////////////////
+  // Get Most Recent Common Ancestor
+
+  map<gen_pair, cAnalyzeGenotype *> mrca;
+  map<gen_pair, int> raw_dist;
+  for (int i = 0; i< size_community; ++ i) {
+    for (int j = i+1; j < size_community; ++ j) {
+				    
+      cAnalyzeGenotype * lineage1_genotype = community[i];
+      cAnalyzeGenotype * lineage2_genotype = community[j];
+      int total_dist = 0;
+
+      while (lineage1_genotype->GetID() != lineage2_genotype->GetID()) {
+	if (lineage1_genotype->GetID() > lineage2_genotype->GetID()) {
+	  int parent_id = lineage1_genotype->GetParentID();
+	  cAnalyzeGenotype * parent = genotype_database.find(parent_id)->second;
+
+	  total_dist += cGenomeUtil::FindHammingDistance(lineage1_genotype->GetGenome(),
+							 parent->GetGenome());
+	  lineage1_genotype = parent;
+	} else {
+	  int parent_id = lineage2_genotype->GetParentID();
+	  cAnalyzeGenotype * parent = genotype_database.find(parent_id)->second;
+	  total_dist += cGenomeUtil::FindHammingDistance(lineage2_genotype->GetGenome(),
+							 parent->GetGenome());
+      
+	  lineage2_genotype = parent;
+	}
+      }
+
+      int id1 = community[i]->GetID();
+      int id2 = community[j]->GetID();
+      mrca.insert(make_pair(gen_pair(id1, id2), lineage1_genotype));
+      mrca.insert(make_pair(gen_pair(id2, id1), lineage1_genotype));
+      raw_dist.insert(make_pair(gen_pair(id1, id2), total_dist));
+      raw_dist.insert(make_pair(gen_pair(id2, id1), total_dist));
+    }
+  }
+
+  /*
+  ////////////////////////////////////////////////////////////////////////////////////////////
+  // Sort the genotype that is next genotype is the most closest one to all previous genotypes
+
+  vector<cAnalyzeGenotype *> sorted_community;
+  vector<cAnalyzeGenotype *> left_genotypes = community;
+
+  // Put the first genotype in left to sorted.
+  sorted_community.push_back(*left_genotypes.begin());
+  left_genotypes.erase(left_genotypes.begin());
+
+  while (left_genotypes.size() > 0) {
+    int min_total_hamming = size_community * length_genome;
+    int index_next;
+
+    for (int next = 0; next < left_genotypes.size(); ++ next) {
+      int total_hamming = 0;
+      int id1 = left_genotypes[next]->GetID();
+      
+      for (int given = 0; given < sorted_community.size(); ++ given) {
+	int id2 = sorted_community[given]->GetID();
+	total_hamming += hamming_dist.find(gen_pair(id1, id2))->second;
+      }
+
+      if (total_hamming < min_total_hamming) {
+	min_total_hamming = total_hamming;
+	index_next = next;
+      }
+    }
+
+    sorted_community.push_back(left_genotypes[index_next]);
+    left_genotypes.erase(left_genotypes.begin() + index_next);
+  }
+
+  */
+
+  vector<cAnalyzeGenotype *> sorted_community = community;
+  /////////////////////////////////////////////
+  // Loop through genotypes in sorted community
+
+  double complexity = 0.0;
+  vector<cAnalyzeGenotype *> given_genotypes;
+  int num_insts = inst_set.GetSize();
+
+  for (int i = 0; i < size_community; ++ i) {
+    genotype = sorted_community[i];
+
+    // Skip the dead organisms
+    genotype->Recalculate();
+    if (genotype->GetFitness() == 0) {
+      continue;
+    }
+
+    vector<double> one_line_prob(num_insts, 0.0);
+    vector< vector<double> > prob(length_genome, one_line_prob);
+
+    cout << endl << genotype->GetID() << endl;
+
+    /*if (given_genotypes.size() >= 2) {
+
+      ///////////////////////////////////////////////////////////////////
+      // Look for two given genotypes that has minimun depth dist with it
+
+      cAnalyzeGenotype * min_depth_gen = given_genotypes[0];
+      cAnalyzeGenotype * tmrca = mrca.find(gen_pair(genotype->GetID(), 
+						    given_genotypes[0]->GetID()))->second;
+      int min_depth_dist = genotype->GetDepth() + given_genotypes[0]->GetDepth() - 2 * tmrca->GetDepth();
+      
+      cAnalyzeGenotype * second_min_gen = given_genotypes[1];
+      tmrca = mrca.find(gen_pair(genotype->GetID(), given_genotypes[1]->GetID()))->second;
+      int second_min_depth = genotype->GetDepth() + given_genotypes[1]->GetDepth() - 2 * tmrca->GetDepth();
+
+      for (int i = 2; i < given_genotypes.size(); ++ i) {
+	cAnalyzeGenotype * given_genotype = given_genotypes[i];
+	cAnalyzeGenotype * tmrca = mrca.find(gen_pair(genotype->GetID(),
+						      given_genotype->GetID()))->second;
+	int dist = genotype->GetDepth() + given_genotype->GetDepth() - 2 * tmrca->GetDepth();
+
+	if (dist < min_depth_dist) {
+	  second_min_depth = min_depth_dist;
+	  second_min_gen = min_depth_gen;
+	  min_depth_dist = dist;
+	  min_depth_gen = given_genotype;
+	} else if (dist >= min_depth_dist && dist < second_min_depth) {
+	  second_min_depth = dist;
+	  second_min_gen = given_genotype;
+	}
+      }
+
+      const cGenome & given_genome1 = min_depth_gen->GetGenome();
+      const cGenome & given_genome2 = second_min_gen->GetGenome();
+      for (int line = 0; line < length_genome; ++ line) {
+	int given_inst = given_genome1[line].GetOp();
+	prob[line][given_inst] += pow(1 - 1.0/length_genome, min_depth_dist);
+	given_inst = given_genome2[line].GetOp();
+	prob[line][given_inst] += pow(1 - 1.0/length_genome, min_depth_dist);
+      }
+
+      cpx_fp << genotype->GetID() << " " << min_depth_dist << " " << second_min_depth 
+	     << " " << raw_dist.find(gen_pair(genotype->GetID(), min_depth_gen->GetID()))->second
+	     << " " << raw_dist.find(gen_pair(genotype->GetID(), second_min_gen->GetID()))->second
+	     << " ";
+      
+	
+    } else  if (given_genotypes.size() == 1) {
+      //////////////////////////////////////////////////////
+      // Calculate the probability of each inst at each line
+      cAnalyzeGenotype * tmrca = mrca.find(gen_pair(genotype->GetID(), 
+						    given_genotypes[0]->GetID()))->second;
+      int dist = genotype->GetDepth() + given_genotypes[0]->GetDepth() - 2 * tmrca->GetDepth();
+      const cGenome & given_genome = given_genotypes[0]->GetGenome();
+
+      for (int line = 0; line < length_genome; ++ line) {
+	int given_inst = given_genome[line].GetOp();
+	prob[line][given_inst] += pow(1 - 1.0/length_genome, dist);
+      }
+      
+      cpx_fp << genotype->GetID() << " " << dist << " " 
+	     << raw_dist.find(gen_pair(genotype->GetID(), given_genotypes[0]->GetID()))->second << " ";
+    } else {
+      cpx_fp << genotype->GetID() << " ";
+      }*/
+
+    if (given_genotypes.size() >= 1) {
+      //////////////////////////////////////////////////
+      // Look for a genotype that is closest to this one
+      
+      cAnalyzeGenotype * min_depth_gen = given_genotypes[0];
+      cAnalyzeGenotype * tmrca = mrca.find(gen_pair(genotype->GetID(), 
+						    given_genotypes[0]->GetID()))->second;
+      int min_depth_dist = genotype->GetDepth() + given_genotypes[0]->GetDepth() - 2 * tmrca->GetDepth();
+
+      for (int i = 1; i < given_genotypes.size() ; ++ i) {
+	cAnalyzeGenotype * given_genotype = given_genotypes[i];
+	cAnalyzeGenotype * tmrca = mrca.find(gen_pair(genotype->GetID(),
+						      given_genotype->GetID()))->second;
+	int dist = genotype->GetDepth() + given_genotype->GetDepth() - 2 * tmrca->GetDepth();
+	
+	if (dist < min_depth_dist) {
+	  min_depth_dist = dist;
+	  min_depth_gen = given_genotype;
+	}
+      }
+
+      const cGenome & given_genome = min_depth_gen->GetGenome();
+      const cGenome & base_genome = genotype->GetGenome();
+      cGenome mod_genome(base_genome);
+      for (int line = 0; line < length_genome; ++ line) {
+	int given_inst = given_genome[line].GetOp();
+	mod_genome = base_genome;
+	mod_genome[line].SetOp(given_inst);
+	cAnalyzeGenotype test_genotype(mod_genome, inst_set);
+	test_genotype.Recalculate();
+
+	// Only when given inst make the genotype alive
+	if (test_genotype.GetFitness() > 0) {
+	  prob[line][given_inst] += pow(1 - 1.0/length_genome, min_depth_dist);
+	}
+      }
+      
+      cpx_fp << genotype->GetID() << " " << min_depth_dist << " " 
+	     << raw_dist.find(gen_pair(genotype->GetID(), min_depth_gen->GetID()))->second << " "
+	     << hamming_dist.find(gen_pair(genotype->GetID(), min_depth_gen->GetID()))->second << "   ";
+    } else {
+      cpx_fp << genotype->GetID() << " ";
+    }
+
+    ///////////////////////////////////////////////////////////////////
+    // Point mutation at all lines of code to look for neutral mutation
+    // and the mutations that can make organism alive
+    cout << "Test point mutation." << endl;
+    vector<bool> one_line_neutral(num_insts, false);
+    vector< vector<bool> > neutral_mut(length_genome, one_line_neutral);
+    vector< vector<bool> > alive_mut(length_genome, one_line_neutral);
+//     if (verbose == true) {
+//       PrintTestCPUResources("");
+//     }
+
+    genotype->Recalculate();
+    double base_fitness = genotype->GetFitness();
+    cout << base_fitness << endl;
+    const cGenome & base_genome = genotype->GetGenome();
+    cGenome mod_genome(base_genome);
+      
+    for (int line = 0; line < length_genome; ++ line) {
+      int cur_inst = base_genome[line].GetOp();
+      
+      for (int mod_inst = 0; mod_inst < num_insts; ++ mod_inst) {
+	mod_genome[line].SetOp(mod_inst);
+	cAnalyzeGenotype test_genotype(mod_genome, inst_set);
+	test_genotype.Recalculate();
+	if (test_genotype.GetFitness() >= base_fitness) {
+	  neutral_mut[line][mod_inst] = true;
+	} 
+	if (test_genotype.GetFitness() > 0) {
+	  alive_mut[line][mod_inst] = true;
+	}
+      }
+      
+      mod_genome[line].SetOp(cur_inst);
+    }
+
+    /////////////////////////////////////////
+    // Normalize the probability at each line
+    vector< vector<double> > prob_before_env(length_genome, one_line_prob);
+
+    for (int line = 0; line < length_genome; ++ line) {
+      double cur_total_prob = 0.0;
+      int num_alive = 0;
+      for (int inst = 0; inst < num_insts; ++ inst) {
+	if (alive_mut[line][inst] == true) {
+	  cur_total_prob += prob[line][inst];
+	  num_alive ++;
+	}
+      }
+      if (cur_total_prob > 1) {
+	cout << "Total probability at " << line << " is greater than 0." << endl;
+	exit(1);
+      }
+      double left_prob = 1 - cur_total_prob;
+
+      for (int inst = 0; inst < num_insts; ++ inst) {
+	if (alive_mut[line][inst] == true) {
+	  prob_before_env[line][inst] = prob[line][inst] + left_prob / num_alive;
+	} else {
+	  prob_before_env[line][inst] = 0;
+	}	
+      }
+      
+    }
+
+    /////////////////////////////////
+    // Calculate entropy of each line  
+    vector<double> entropy(length_genome, 0.0);
+    for (int line = 0; line < length_genome; ++ line) {
+      double sum = 0;
+      for (int inst = 0; inst < num_insts; ++ inst) {
+	sum += prob_before_env[line][inst];
+	if (prob_before_env[line][inst] > 0) {
+	  entropy[line] -= prob_before_env[line][inst] * log(prob_before_env[line][inst]) / log(num_insts*1.0);
+	}
+      }
+      if (sum > 1.001 || sum < 0.999) {
+	cout << "Sum of probability is not 1 at line " << line << endl;
+	exit(1);
+      }
+    }
+
+
+    /////////////////////////////////////////////////////
+    // Redistribute the probability of insts at each line
+    vector< vector<double> > prob_given_env(length_genome, one_line_prob);
+    
+    for (int line = 0; line < length_genome; ++ line) {
+      double total_prob = 0.0;
+      int num_neutral = 0;
+      for (int inst = 0; inst < num_insts; ++ inst) {
+	if (neutral_mut[line][inst] == true) {
+	  num_neutral ++;
+	  total_prob += prob[line][inst];
+	}
+      }
+
+      double left = 1 - total_prob;
+
+      for (int inst = 0; inst < num_insts; ++ inst) {
+	if (neutral_mut[line][inst] == true) {
+	  prob_given_env[line][inst] = prob[line][inst] + left / num_neutral;
+	} else {
+	  prob_given_env[line][inst] = 0.0;
+	}
+      }
+      
+    }
+
+    ////////////////////////////////////////////////
+    // Calculate the entropy given environment
+
+    vector<double> entropy_given_env(length_genome, 0.0);
+    for (int line = 0; line < length_genome; ++ line) {
+      double sum = 0;
+      for (int inst = 0; inst < num_insts; ++ inst) {
+	sum += prob_given_env[line][inst];
+	if (prob_given_env[line][inst] > 0) {
+	  entropy_given_env[line] -= prob_given_env[line][inst] * log(prob_given_env[line][inst]) / 
+	                             log(num_insts*1.0);
+	}
+      }
+      if (sum > 1.001 || sum < 0.999) {
+	cout << "Sum of probability is not 1 at line " << line << " " << sum << endl;
+	exit(1);
+      }
+    }
+
+
+    ///////////////////////////////////////////////////////////////////////////
+    // Calculate the information between genotype and env given other genotypes
+    double information = 0.0;
+    double entropy_before = 0.0;
+    double entropy_after = 0.0;
+    for (int line = 0; line < length_genome; ++ line) {
+      entropy_before += entropy[line];
+      entropy_after += entropy_given_env[line];
+
+      if (entropy[line] >= entropy_given_env[line]) {
+	information += entropy[line] - entropy_given_env[line];	
+      } else {    // Negative information is because given condition is not related with this genotype  ...
+	
+	// Count the number of insts that can make genotype alive
+	int num_inst_alive = 0;
+	for (int inst = 0; inst < num_insts; ++ inst) {
+	  if (alive_mut[line][inst] == true) {
+	    num_inst_alive ++;
+	  }
+	}
+	
+	double entropy_before = - log(1.0/num_inst_alive) / log(num_insts*1.0);
+	information += entropy_before - entropy_given_env[line];
+	if (information < 0) {
+	  cout << "Negative information at site " << line << endl;
+	  exit(1);
+	}
+      }
+      
+    }
+    complexity += information;
+
+    cpx_fp << entropy_before << " " << entropy_after << " "
+	   << information << " " << complexity << "   ";
+
+    genotype->PrintTasks(cpx_fp, 0, -1);
+    cpx_fp << endl; 
+
+    /////////////////////////////////////////////////////////////
+    // This genotype becomes the given condition of next genotype
+
+    given_genotypes.push_back(genotype);
+    
+  }
+
+  // Set the test CPU back to the state it was 
+  cTestCPU::UseResources() = backupUsage;
+  cTestCPU::SetupResourceArray(backupResources);
+    
+  cpx_fp.close();
+  return;
+	 
+}
+
+void cAnalyze::CommunityComplexity(cString cur_string)
+{
+  /////////////////////////////////////////////////////////////////////
+  // Calculate the mutual information between community and environment
+  /////////////////////////////////////////////////////////////////////
+
+  cout << "Analyze community complexity of current population about environment with Charles method ...\n";
+
+  // Get the number of genotypes that are gonna be analyzed.
+  int max_genotypes = cur_string.PopWord().AsInt();
+
+  // Get update
+  int update = cur_string.PopWord().AsInt();
+
+  // Get the directory  
+  cString dir = cur_string.PopWord();
+  cString defaultDir = "community_cpx/";
+  cString directory = PopDirectory(dir, defaultDir);
+
+  // Get the file name that saves the result 
+  cString filename = cur_string.PopWord();
+  if (filename.IsEmpty()) {
+    filename = "community.complexity.dat";
+  }
+
+  filename.Set("%s%s", directory(), filename.GetData());
+  ofstream cpx_fp(filename());
+
+  cpx_fp << "# Legend:" << endl;
+  cpx_fp << "# 1: Genotype ID" << endl;
+  cpx_fp << "# 2: Entropy given Known Genotypes" << endl;
+  cpx_fp << "# 3: Entropy given Both Known Genotypes and Env" << endl;
+  cpx_fp << "# 4: New Information about Environment" << endl;
+  cpx_fp << "# 5: Total Complexity" << endl;
+  cpx_fp << "# 6: Hamming Distance to Closest Given Genotype" << endl;
+  cpx_fp << "# 7 - : Tasks Implemented" << endl;
+  cpx_fp << endl;
+
+  ///////////////////////
+  // Backup test CPU data
+  bool backupUsage = cTestCPU::UseResources();
+  tArray<double> backupResources(cTestCPU::GetResources());
+  cTestCPU::UseResources() = true;
+  FillResources(update);
+
+  ///////////////////////////////////////////////////////////////////////
+  // Choose the first n most abundant genotypes and put them in community
+
+  vector<cAnalyzeGenotype *> community;
+  cAnalyzeGenotype * genotype = NULL;
+  tListIterator<cAnalyzeGenotype> batch_it(batch[cur_batch].List());
+
+  while (((genotype = batch_it.Next()) != NULL) && (community.size() < max_genotypes)) {
+    community.push_back(genotype);
+  }
+
+  //////////////////////////////////////////////////////
+  // Test point mutation of each genotype in environment
+
+  int num_insts = inst_set.GetSize();
+  map<int, tMatrix<double> > point_mut; 
+  int size_community = community.size();
+  int length_genome;
+  if (size_community > 1) {
+    length_genome = community[0]->GetLength();
+  }
+
+  for (int i = 0; i < size_community; ++ i) {
+    genotype = community[i];
+    
+    ///////////////////////////////////////////////////////////////////
+    // Point mutation at all lines of code to look for neutral mutation
+    cout << "Test point mutation for genotype " << genotype->GetID() << endl;
+    tMatrix<double> prob(length_genome, num_insts);
+//     if (verbose == true) {
+//       PrintTestCPUResources("");
+//     }
+
+    genotype->Recalculate();
+    double base_fitness = genotype->GetFitness();
+    const cGenome & base_genome = genotype->GetGenome();
+    cGenome mod_genome(base_genome);
+      
+    for (int line = 0; line < length_genome; ++ line) {
+      int cur_inst = base_genome[line].GetOp();
+      int num_neutral = 0;
+
+      for (int mod_inst = 0; mod_inst < num_insts; ++ mod_inst) {
+	mod_genome[line].SetOp(mod_inst);
+	cAnalyzeGenotype test_genotype(mod_genome, inst_set);
+	test_genotype.Recalculate();
+	if (test_genotype.GetFitness() >= base_fitness) {
+	  prob[line][mod_inst] = 1.0;
+	  num_neutral ++;
+	} else {
+	  prob[line][mod_inst] = 0.0;
+	}
+      }
+
+      for (int mod_inst = 0; mod_inst < num_insts; ++ mod_inst) {
+	prob[line][mod_inst] /= num_neutral;
+      }
+   
+      
+      mod_genome[line].SetOp(cur_inst);
+    }
+
+    point_mut.insert(make_pair(genotype->GetID(), prob));
+  }
+
+  //////////////////////////////////////
+  // Loop through genotypes in community
+
+  double complexity = 0.0;
+  double complexity2 = 0.0;
+  vector<cAnalyzeGenotype *> given_genotypes;
+
+  // Calculate the complexity of the first gentoype
+  genotype = community[0];
+  double oo_initial_entropy = length_genome;
+  double oo_conditional_entropy = 0.0;
+  tMatrix<double> this_prob = point_mut.find(genotype->GetID())->second;
+
+  for (int line = 0; line < length_genome; ++ line) {
+    double oneline_entropy = 0.0;
+    for (int inst = 0; inst < num_insts; ++ inst) {
+      if (this_prob[line][inst] > 0) {
+	oneline_entropy -= this_prob[line][inst] * (log(this_prob[line][inst]) /
+						    log(1.0*num_insts));
+      }
+    }
+    oo_conditional_entropy += oneline_entropy;
+  }
+  double new_info = oo_initial_entropy - oo_conditional_entropy;
+  complexity += new_info;
+  complexity2 += new_info;
+  given_genotypes.push_back(genotype);
+  cpx_fp << genotype->GetID() << " " 
+	 << oo_initial_entropy << " " 
+	 << oo_conditional_entropy << " "
+	 << new_info << " " 
+	 << complexity << "   "
+	 << 0 << "   ";
+  genotype->Recalculate();
+  genotype->PrintTasks(cpx_fp, 0, -1);
+  cpx_fp << endl;
+
+  // New information in other genotypes in community ...
+  for (int i = 1; i < size_community; ++ i) {
+    genotype = community[i];
+    if (genotype->GetLength() != length_genome) {
+      cerr << "Genotypes in the community do not same genome length.\n";
+      cpx_fp.close();
+      exit(1);
+    }
+
+    // Skip the dead organisms
+    genotype->Recalculate();
+    cout << genotype->GetID() << " " << genotype->GetFitness() << endl;
+    if (genotype->GetFitness() == 0) {
+      continue;
+    }
+
+    double min_new_info = length_genome; 
+    double oo_initial_entropy, oo_conditional_entropy;
+    cAnalyzeGenotype * used_genotype;
+    tMatrix<double> this_prob = point_mut.find(genotype->GetID())->second;
+
+    // For any given genotype, calculate the new information in genotype
+    for (int j = 0; j < given_genotypes.size(); ++ j) {
+
+      tMatrix<double> given_prob = point_mut.find(given_genotypes[j]->GetID())->second;
+      double new_info = 0.0;
+      double total_initial_entropy = 0.0;
+      double total_conditional_entropy = 0.0;
+
+      for (int line = 0; line < length_genome; ++ line) {
+
+	// H(genotype|known_genotype)    
+	double prob_overlap = 0;
+	for (int inst = 0; inst < num_insts; ++ inst) {
+	  if (this_prob[line][inst] < given_prob[line][inst]) {
+	    prob_overlap += this_prob[line][inst];
+	  } else {
+	    prob_overlap += given_prob[line][inst];
+	  }
+	}
+
+	double given_site_entropy = 0.0;
+	for (int inst = 0; inst < num_insts; ++ inst) {
+	  if (given_prob[line][inst] > 0) {
+	    given_site_entropy -= given_prob[line][inst] * (log(given_prob[line][inst]) /
+							 log(1.0*num_insts));
+	  }
+	}
+	
+
+	double entropy_overlap = 0.0;
+	if (prob_overlap > 0 &&  (1 - prob_overlap > 0)) {
+	  entropy_overlap = (- prob_overlap * log(prob_overlap) 
+			     - (1-prob_overlap) * log(1 - prob_overlap)) / log(1.0*num_insts);
+	} else {
+	  entropy_overlap = 0; 
+	}
+
+	double initial_entropy = prob_overlap * given_site_entropy 
+                             + (1 - prob_overlap) * 1 + entropy_overlap;
+	total_initial_entropy += initial_entropy;
+
+	// H(genotype|E, known_genotype) = H(genotype|Env)
+	double conditional_entropy = 0.0;
+	for (int inst = 0; inst < num_insts; ++ inst) {
+	  if (this_prob[line][inst] > 0) {
+	    conditional_entropy -= this_prob[line][inst] * (log(this_prob[line][inst]) / 
+							    log(1.0*num_insts));
+	  }
+	}
+	total_conditional_entropy += conditional_entropy;
+
+	if (conditional_entropy > initial_entropy + 0.00001) {
+	  cerr << "Negative Information.\n";
+	  cout << line << endl;
+	  for (int inst = 0; inst < num_insts; ++ inst) {
+	    cout << this_prob[line][inst] << " ";
+	  }
+	  cout << endl;
+	  for (int inst = 0; inst < num_insts; ++ inst) {
+	    cout << given_prob[line][inst] << " ";
+	  }
+	  cout << endl;
+
+	  exit(1);
+	}
+
+	new_info += initial_entropy - conditional_entropy;
+      }
+     
+      if (new_info < min_new_info) {
+	min_new_info = new_info;
+	oo_initial_entropy = total_initial_entropy;
+	oo_conditional_entropy = total_conditional_entropy;
+	used_genotype = given_genotypes[j];
+      }
+
+    }
+    complexity += min_new_info;
+    cpx_fp << genotype->GetID() << " " 
+	   << oo_initial_entropy << " "
+	   << oo_conditional_entropy << " "
+	   << min_new_info << " " << complexity << "   ";
+
+    cpx_fp << cGenomeUtil::FindHammingDistance(genotype->GetGenome(),
+					       used_genotype->GetGenome()) << "   ";
+    
+    
+    genotype->PrintTasks(cpx_fp, 0, -1);
+    cpx_fp << endl;
+    given_genotypes.push_back(genotype);
+  }
+  
+  
+  // Set the test CPU back to the state it was 
+  cTestCPU::UseResources() = backupUsage;
+  cTestCPU::SetupResourceArray(backupResources);
+    
+  cpx_fp.close();
+  return;
+
+    
+  
+}
+
+void cAnalyze::CommandLandscape(cString cur_string)
+{
+  if (verbose == true) cout << "Landscaping batch " << cur_batch << endl;
+  else cout << "Landscapping..." << endl;
+  
+  // Load in the variables...
+  cString filename;
+  if (cur_string.GetSize() != 0) filename = cur_string.PopWord();
+  int dist = 1;
+  if (cur_string.GetSize() != 0) dist = cur_string.PopWord().AsInt();
+  int num_test = 0;
+  if (cur_string.GetSize() != 0) num_test=cur_string.PopWord().AsInt();
+  
+  // If we're given a file, write to it.
+  ofstream & fp = data_file_manager.GetOFStream(filename);
+  
+  // Loop through all of the genotypes in this batch...
+  tListIterator<cAnalyzeGenotype> batch_it(batch[cur_batch].List());
+  cAnalyzeGenotype * genotype = NULL;
+  while ((genotype = batch_it.Next()) != NULL) {
+    cLandscape landscape(genotype->GetGenome(), inst_set);
+    if (num_test == 0) landscape.Process(dist);
+    else landscape.RandomProcess(num_test,dist,num_test,num_test*2);
+    landscape.PrintStats(fp);
+  }
+}
+
+void cAnalyze::AnalyzeEpistasis(cString cur_string)
+{
+  if (verbose == true) cout << "Epistasis on " << cur_batch << endl;
+  else cout << "Calculating epistasis values..." << endl;
+  
+  // Load in the variables...
+  cString filename;
+  if (cur_string.GetSize() != 0) filename = cur_string.PopWord();
+  int test_num = 1;
+  if (cur_string.GetSize() != 0) test_num = cur_string.PopWord().AsInt();
+  
+  // If we're given a file, write to it.
+  ofstream & fp = data_file_manager.GetOFStream(filename);
+  
+  // Loop through all of the genotypes in this batch...
+  tListIterator<cAnalyzeGenotype> batch_it(batch[cur_batch].List());
+  cAnalyzeGenotype * genotype = NULL;
+  while ((genotype = batch_it.Next()) != NULL) {
+    cLandscape landscape(genotype->GetGenome(), inst_set);
+    if (test_num == 1)  landscape.TestAllPairs(fp);
+    else 		landscape.TestPairs(test_num,fp); 
+    landscape.PrintStats(fp);
+  }
+}
+
+
+// This command will take the current batch and analyze how well organisms
+// cross-over with each other, both across the population and between mates.
+
+void cAnalyze::AnalyzeMateSelection(cString cur_string)
+{
+  int sample_size = 10000;
+  if (cur_string.GetSize() != 0) sample_size = cur_string.PopWord().AsInt();
+  cString filename("none");
+  if (cur_string.GetSize() != 0) filename = cur_string.PopWord();
+  double min_swap_frac = 0.0;
+  if (cur_string.GetSize() != 0) min_swap_frac=cur_string.PopWord().AsDouble();
+  double max_swap_frac = 1.0 - min_swap_frac;
+
+  cout << "Analyzing Mate Selection... " << endl;
+
+  // Do some quick tests before moving on...
+  if (min_swap_frac < 0.0 || min_swap_frac >= 0.5) {
+    cerr << "ERROR: Minimum swap fraction out of range [0.0, 0.5)." << endl;
+  }
+  
+  // Next, we create an array that contains pointers to all of the organisms
+  // in this batch.  Note that we want to select genotypes based on their
+  // abundance, so they will have one entry in the array per organism.  Note
+  // that we only consider viable genotypes.
+
+  // Start by counting the total number of organisms (and do other such
+  // data collection...
+  tHashTable<int, int> mate_id_counts;
+
+  int org_count = 0;
+  int gen_count = 0;
+  cAnalyzeGenotype * genotype = NULL;
+  tListIterator<cAnalyzeGenotype> list_it(batch[cur_batch].List());
+  while ((genotype = list_it.Next()) != NULL) {
+    if (genotype->GetViable() == false || genotype->GetNumCPUs() == 0) {
+      continue;
+    }
+    gen_count++;
+    org_count += genotype->GetNumCPUs();
+
+    // Keep track of how many organisms have each mate id...
+    int mate_id = genotype->GetMateID();
+    int count = 0;
+    mate_id_counts.Find(mate_id, count);
+    count += genotype->GetNumCPUs();
+    mate_id_counts.SetValue(mate_id, count);
+  }
+
+  // Create an array of the correct size.
+  tArray<cAnalyzeGenotype *> genotype_array(org_count);
+
+  // And insert all of the organisms into the array.
+  int cur_pos = 0;
+  while ((genotype = list_it.Next()) != NULL) {
+    if (genotype->GetViable() == false) continue;
+    int cur_count = genotype->GetNumCPUs();
+    for (int i = 0; i < cur_count; i++) {
+      genotype_array[cur_pos++] = genotype;
+    }
+  }
+  
+
+  // Setup some variables to collect statistics.
+  int total_matches_tested = 0;
+  int fail_count = 0;
+  int match_fail_count = 0;
+
+  // Loop through all of the tests, picking random organisms each time and
+  // performing a random cross test.
+  cAnalyzeGenotype * genotype2 = NULL;
+  for (int test_id = 0; test_id < sample_size; test_id++) {
+    genotype = genotype_array[ g_random.GetUInt(org_count) ];
+    genotype2 = genotype_array[ g_random.GetUInt(org_count) ];
+
+    // Stop immediately if we're comparing a genotype to itself.
+    if (genotype == genotype2) {
+      total_matches_tested++;
+      continue;
+    }
+
+    // Setup the random parameters for this test.
+    cCPUMemory test_genome0 = genotype->GetGenome(); 
+    cCPUMemory test_genome1 = genotype2->GetGenome(); 
+
+    double start_frac = -1.0;
+    double end_frac = -1.0;
+    double swap_frac = -1.0;
+    while (swap_frac < min_swap_frac || swap_frac > max_swap_frac) {
+      start_frac = g_random.GetDouble();
+      end_frac = g_random.GetDouble();
+      if (start_frac > end_frac) nFunctions::Swap(start_frac, end_frac);
+      swap_frac = end_frac - start_frac;
+    }
+          
+    int start0 = (int) (start_frac * (double) test_genome0.GetSize());
+    int end0   = (int) (end_frac * (double) test_genome0.GetSize());
+    int size0 = end0 - start0;
+
+    int start1 = (int) (start_frac * (double) test_genome1.GetSize());
+    int end1   = (int) (end_frac * (double) test_genome1.GetSize());
+    int size1 = end1 - start1;
+
+    int new_size0 = test_genome0.GetSize() - size0 + size1;   
+    int new_size1 = test_genome1.GetSize() - size1 + size0;
+
+    // Setup some statistics for this particular test.
+    bool cross_viable = true;
+    bool same_mate_id = ( genotype->GetMateID() == genotype2->GetMateID() );
+    if (same_mate_id == true) total_matches_tested++;
+
+    // Don't Crossover if offspring will be illegal!!!
+    if (new_size0 < MIN_CREATURE_SIZE || new_size0 > MAX_CREATURE_SIZE || 
+	new_size1 < MIN_CREATURE_SIZE || new_size1 > MAX_CREATURE_SIZE) { 
+      fail_count++; 
+      if (same_mate_id == true) match_fail_count++;
+      continue; 
+    } 
+
+    // Do the replacement...  We're only going to test genome0, so we only
+    // need to modify that one.
+    cGenome cross1 = cGenomeUtil::Crop(test_genome1, start1, end1);
+    test_genome0.Replace(start0, size0, cross1);
+
+    // Do the test.
+    cCPUTestInfo test_info;
+          
+    // Run each side, and determine viability...
+    cTestCPU::TestGenome(test_info, test_genome0);
+    if( test_info.IsViable() == false ) {
+      fail_count++;
+      if (same_mate_id == true) match_fail_count++;
+    }
+  }
+
+  // Do some calculations on the sizes of the mate groups...
+  const int num_mate_groups = mate_id_counts.GetSize();
+
+  // Collect lists on all of the mate groups for the calculations...
+  tList<int> key_list;
+  tList<int> count_list;
+  mate_id_counts.AsLists(key_list, count_list);
+  tListIterator<int> count_it(count_list);
+
+  int max_group_size = 0;
+  double mate_id_entropy = 0.0;
+  while (count_it.Next() != NULL) {
+    int cur_count = *(count_it.Get());
+    double cur_frac = ((double) cur_count) / ((double) org_count);
+    if (cur_count > max_group_size) max_group_size = cur_count;
+    mate_id_entropy -= cur_frac * log(cur_frac);
+  }
+  
+  // Calculate the final answer
+  double fail_frac = (double) fail_count / (double) sample_size;
+  double match_fail_frac =
+    (double) match_fail_count / (double) total_matches_tested;
+  cout << "  ave fraction failed = " << fail_frac << endl
+       << "  ave matches failed = " << match_fail_frac << endl
+       << "  total mate matches = " <<  total_matches_tested
+       << " / " << sample_size<< endl;
+
+  if (filename == "none") return;
+  
+  cDataFile & df = data_file_manager.Get(filename);
+  df.WriteComment( "Mate selection information" );
+  df.WriteTimeStamp();  
+  
+  df.Write(fail_frac,       "Average fraction failed");
+  df.Write(match_fail_frac, "Average fraction of mate matches failed");
+  df.Write(sample_size, "Total number of crossovers tested");
+  df.Write(total_matches_tested, "Number of crossovers with matching mate IDs");
+  df.Write(gen_count, "Number of genotypes in test batch");
+  df.Write(org_count, "Number of organisms in test batch");
+  df.Write(num_mate_groups, "Number of distinct mate IDs");
+  df.Write(max_group_size, "Size of the largest distinct mate ID group");
+  df.Write(mate_id_entropy, "Diversity of mate IDs (entropy)");
+  df.Endl();
+}
+
+  
+void cAnalyze::CommandFitnessMatrix(cString cur_string)
+{
+  if (verbose == true) cout << "Calculating fitness matrix for batch " << cur_batch << endl;
+  else cout << "Calculating fitness matrix..." << endl;
+  
+  cout << "Warning: considering only first genotype of the batch!" << endl;
+  
+  // Load in the variables...
+  int depth_limit = 4;
+  if (cur_string.GetSize() != 0) depth_limit = cur_string.PopWord().AsInt();
+  
+  double fitness_threshold_ratio = .9;
+  if (cur_string.GetSize() != 0) fitness_threshold_ratio = cur_string.PopWord().AsDouble();
+  
+  int ham_thresh  = 1;
+  if (cur_string.GetSize() != 0) ham_thresh = cur_string.PopWord().AsInt();
+  
+  double error_rate_min = 0.005;
+  if (cur_string.GetSize() != 0) error_rate_min = cur_string.PopWord().AsDouble();
+  
+  double error_rate_max = 0.05;
+  if (cur_string.GetSize() != 0) error_rate_max = cur_string.PopWord().AsDouble();
+  
+  double error_rate_step = 0.005;
+  if (cur_string.GetSize() != 0) error_rate_step = cur_string.PopWord().AsDouble();
+  
+  double vect_fmax = 1.1;
+  if (cur_string.GetSize() != 0) vect_fmax = cur_string.PopWord().AsDouble();
+  
+  double vect_fstep = .1;
+  if (cur_string.GetSize() != 0) vect_fstep = cur_string.PopWord().AsDouble();
+  
+  int diag_iters = 200;
+  if (cur_string.GetSize() != 0) diag_iters = cur_string.PopWord().AsInt();
+  
+  int write_ham_vector = 0;
+  if (cur_string.GetSize() != 0) write_ham_vector = cur_string.PopWord().AsInt();
+  
+  int write_full_vector = 0;
+  if (cur_string.GetSize() != 0) write_full_vector = cur_string.PopWord().AsInt();
+  
+  // Consider only the first genotypes in this batch...
+  tListIterator<cAnalyzeGenotype> batch_it(batch[cur_batch].List());
+  cAnalyzeGenotype * genotype = batch_it.Next();
+  
+  cFitnessMatrix matrix( genotype->GetGenome(), &inst_set);
+  
+  matrix.CalcFitnessMatrix( depth_limit, fitness_threshold_ratio, ham_thresh, error_rate_min, error_rate_max, error_rate_step, vect_fmax, vect_fstep, diag_iters, write_ham_vector, write_full_vector );
+}
+
+
+void cAnalyze::CommandMapTasks(cString cur_string)
+{
+  cout << "Constructing genotype-phenotype maps..." << endl;
+  
+  // Load in the variables...
+  cString directory = PopDirectory(cur_string, "phenotype/");
+  int print_mode = 0;   // 0=Normal, 1=Boolean results
+  int file_type = FILE_TYPE_TEXT;
+  
+  // HTML special flags...
+  bool link_maps = false;  // Should muliple maps be linked together?
+  bool link_insts = false; // Should links be made to instruction descs?
+  
+  // Collect any other format information needed...
+  tList< tDataEntryCommand<cAnalyzeGenotype> > output_list;
+  tListIterator< tDataEntryCommand<cAnalyzeGenotype> > output_it(output_list);
+  
+  cStringList arg_list(cur_string);
+  
+  cout << "Found " << arg_list.GetSize() << " args." << endl;
+  
+  // Check for some command specific variables.
+  if (arg_list.PopString("0") != "") print_mode = 0;
+  if (arg_list.PopString("1") != "") print_mode = 1;
+  if (arg_list.PopString("text") != "") file_type = FILE_TYPE_TEXT;
+  if (arg_list.PopString("html") != "") file_type = FILE_TYPE_HTML;
+  if (arg_list.PopString("link_maps") != "") link_maps = true;
+  if (arg_list.PopString("link_insts") != "") link_insts = true;
+  
+  cout << "There are " << arg_list.GetSize() << " column args." << endl;
+  
+  LoadGenotypeDataList(arg_list, output_list);
+  
+  cout << "Args are loaded." << endl;
+  
+  const int num_cols = output_list.GetSize();
+  
+  // Give some information in verbose mode.
+  if (verbose == true) {
+    cout << "  outputing as ";
+    if (print_mode == 1) cout << "boolean ";
+    if (file_type == FILE_TYPE_TEXT) {
+      cout << "text files." << endl;
+    } else { // if (file_type == FILE_TYPE_HTML) {
+      cout << "HTML files";
+      if (link_maps == true) cout << "; linking files together";
+      if (link_maps == true) cout << "; linking inst names to descs";
+      cout << "." << endl;
+    }
+    cout << "  Format: ";
+    
+    output_it.Reset();
+    while (output_it.Next() != NULL) {
+      cout << output_it.Get()->GetName() << " ";
+    }
+    cout << endl;
+  }
+  
+  
+  ///////////////////////////////////////////////////////
+  // Loop through all of the genotypes in this batch...
+  
+  tListIterator<cAnalyzeGenotype> batch_it(batch[cur_batch].List());
+  cAnalyzeGenotype * genotype = NULL;
+  while ((genotype = batch_it.Next()) != NULL) {
+    if (verbose == true) cout << "  Mapping " << genotype->GetName() << endl;
+    
+    // Construct this filename...
+    cString filename;
+    if (file_type == FILE_TYPE_TEXT) {
+      filename.Set("%stasksites.%s.dat", directory(), genotype->GetName()());
+    } else {   //  if (file_type == FILE_TYPE_HTML) {
+      filename.Set("%stasksites.%s.html", directory(), genotype->GetName()());
+    }
+    ofstream fp(filename());
+    
+    // Construct linked filenames...
+    cString next_file("");
+    cString prev_file("");
+    if (link_maps == true) {
+      // Check the next genotype on the list...
+      if (batch_it.Next() != NULL) {
+        next_file.Set("tasksites.%s.html", batch_it.Get()->GetName()());
+      }
+      batch_it.Prev();  // Put the list back where it was...
+      
+      // Check the previous genotype on the list...
+      if (batch_it.Prev() != NULL) {
+        prev_file.Set("tasksites.%s.html", batch_it.Get()->GetName()());
+      }
+      batch_it.Next();  // Put the list back where it was...
+    }
+    
+    // Calculate the stats for the genotype we're working with...
+    genotype->Recalculate();
+    
+    // Headers...
+    if (file_type == FILE_TYPE_TEXT) {
+      fp << "-1 "  << batch[cur_batch].Name() << " "
+      << genotype->GetID() << " ";
+      
+      tDataEntryCommand<cAnalyzeGenotype> * data_command = NULL;
+      while ((data_command = output_it.Next()) != NULL) {
+        data_command->SetTarget(genotype);
+        fp << data_command->GetEntry() << " ";
+      }
+      fp << endl;
+      
+    } else { // if (file_type == FILE_TYPE_HTML) {
+             // Mark file as html
+      fp << "<html>" << endl;
+      
+      // Setup any javascript macros needed...
+      fp << "<head>" << endl;
+      if (link_insts == true) {
+        fp << "<script language=\"javascript\">" << endl
+        << "function Inst(inst_name)" << endl
+        << "{" << endl
+        << "var filename = \"help.\" + inst_name + \".html\";" << endl
+        << "newwin = window.open(filename, 'Instruction', "
+        << "'toolbar=0,status=0,location=0,directories=0,menubar=0,"
+        << "scrollbars=1,height=150,width=300');" << endl
+        << "newwin.focus();" << endl
+        << "}" << endl
+        << "</script>" << endl;
+      }
+      fp << "</head>" << endl;
+      
+      // Setup the body...
+      fp << "<body bgcolor=\"#FFFFFF\"" << endl
+        << " text=\"#000000\"" << endl
+        << " link=\"#0000AA\"" << endl
+        << " alink=\"#0000FF\"" << endl
+        << " vlink=\"#000044\">" << endl
+        << endl
+        << "<h1 align=center>Run " << batch[cur_batch].Name()
+        << ", ID " << genotype->GetID() << "</h1>" << endl
+        << "<center>" << endl
+        << endl;
+      
+      // Links?
+      fp << "<table width=90%><tr><td align=left>";
+      if (prev_file != "") fp << "<a href=\"" << prev_file << "\">Prev</a>";
+      else fp << "&nbsp;";
+      fp << "<td align=right>";
+      if (next_file != "") fp << "<a href=\"" << next_file << "\">Next</a>";
+      else fp << "&nbsp;";
+      fp << "</tr></table>" << endl;
+      
+      // The table
+      fp << "<table border=1 cellpadding=2>" << endl;
+      
+      // The headings...///
+      fp << "<tr><td colspan=3> ";
+      output_it.Reset();
+      while (output_it.Next() != NULL) {
+        fp << "<th>" << output_it.Get()->GetDesc() << " ";
+      }
+      fp << "</tr>" << endl;
+      
+      // The base creature...
+      fp << "<tr><th colspan=3>Base Creature";
+      tDataEntryCommand<cAnalyzeGenotype> * data_command = NULL;
+      cAnalyzeGenotype null_genotype("a", inst_set);
+      while ((data_command = output_it.Next()) != NULL) {
+        data_command->SetTarget(genotype);
+        genotype->SetSpecialArgs(data_command->GetArgs());
+        if (data_command->Compare(&null_genotype) > 0) {
+          fp << "<th bgcolor=\"#00FF00\">";
+        }
+        else  fp << "<th bgcolor=\"#FF0000\">";
+        
+        if (data_command->HasArg("blank") == true) fp << "&nbsp;" << " ";
+        else fp << data_command->GetEntry() << " ";
+      }
+      fp << "</tr>" << endl;
+    }
+    
+    
+    const int max_line = genotype->GetLength();
+    const cGenome & base_genome = genotype->GetGenome();
+    cGenome mod_genome(base_genome);
+    
+    // Keep track of the number of failues/successes for attributes...
+    int * col_pass_count = new int[num_cols];
+    int * col_fail_count = new int[num_cols];
+    for (int i = 0; i < num_cols; i++) {
+      col_pass_count[i] = 0;
+      col_fail_count[i] = 0;
+    }
+    
+    cInstSet map_inst_set(inst_set);
+    // Locate instruction corresponding to "NULL" in the instruction library.
+    {
+      const cInstruction inst_lib_null_inst = map_inst_set.GetInstLib()->GetInst("NULL");
+      if(inst_lib_null_inst == map_inst_set.GetInstLib()->GetInstError()){
+        cout << "<cAnalyze::CommandMapTasks> got error:" << endl;
+        cout << " --- instruction \"NULL\" isn't in the instruction library;" << endl;
+        cout << " --- get somebody to map a function to \"NULL\" in the library." << endl;
+        cout << " --- (probably to class method \"cHardware-of-some-type::initInstLib\"" << endl;
+        cout << " --- in file named \"cpu/hardware-of-some-type.cc\".)" << endl;
+        cout << " --- bailing-out." << endl;
+        exit(1);
+      }
+      // Add mapping to located instruction. 
+      map_inst_set.Add2(inst_lib_null_inst.GetOp());
+    }
+    const cInstruction null_inst = map_inst_set.GetInst("NULL");
+    
+    // Loop through all the lines of code, testing the removal of each.
+    for (int line_num = 0; line_num < max_line; line_num++) {
+      int cur_inst = base_genome[line_num].GetOp();
+      char cur_symbol = base_genome[line_num].GetSymbol();
+      
+      mod_genome[line_num] = null_inst;
+      cAnalyzeGenotype test_genotype(mod_genome, map_inst_set);
+      test_genotype.Recalculate();
+      
+      if (file_type == FILE_TYPE_HTML) fp << "<tr><td align=right>";
+      fp << (line_num + 1) << " ";
+      if (file_type == FILE_TYPE_HTML) fp << "<td align=center>";
+      fp << cur_symbol << " ";
+      if (file_type == FILE_TYPE_HTML) fp << "<td align=center>";
+      if (link_insts == true) {
+        fp << "<a href=\"javascript:Inst('"
+        << map_inst_set.GetName(cur_inst)
+        << "')\">";
+      }
+      fp << map_inst_set.GetName(cur_inst) << " ";
+      if (link_insts == true) fp << "</a>";
+      
+      
+      // Print the individual columns...
+      output_it.Reset();
+      tDataEntryCommand<cAnalyzeGenotype> * data_command = NULL;
+      int cur_col = 0;
+      while ((data_command = output_it.Next()) != NULL) {
+        data_command->SetTarget(&test_genotype);
+        test_genotype.SetSpecialArgs(data_command->GetArgs());
+        int compare = data_command->Compare(genotype);
+        if (file_type == FILE_TYPE_HTML) {
+          data_command->HTMLPrint(fp, compare,
+                                  !(data_command->HasArg("blank")));
+        } 
+        else fp << data_command->GetEntry() << " ";
+        
+        if (compare == -2) col_fail_count[cur_col]++;
+        else if (compare == 2) col_pass_count[cur_col]++;
+        cur_col++;
+      }
+      if (file_type == FILE_TYPE_HTML) fp << "</tr>";
+      fp << endl;
+      
+      // Reset the mod_genome back to the original sequence.
+      mod_genome[line_num].SetOp(cur_inst);
+    }
+    
+    
+    // Construct the final line of the table with all totals...
+    if (file_type == FILE_TYPE_HTML) {
+      fp << "<tr><th colspan=3>Totals";
+      
+      for (int i = 0; i < num_cols; i++) {
+        if (col_pass_count[i] > 0) {
+          fp << "<th bgcolor=\"#00FF00\">" << col_pass_count[i];
+        }
+        else if (col_fail_count[i] > 0) {
+          fp << "<th bgcolor=\"#FF0000\">" << col_fail_count[i];
+        }
+        else fp << "<th>0";
+      }
+      fp << "</tr>" << endl;
+      
+      // And close everything up...
+      fp << "</table>" << endl
+        << "</center>" << endl;
+    }
+    
+    delete [] col_pass_count;
+    delete [] col_fail_count;
+    
+    }
+}
+
+void cAnalyze::CommandAverageModularity(cString cur_string)
+{
+  cout << "Average Modularity calculations" << endl;
+  
+  // Load in the variables...
+  cString filename = cur_string.PopWord();
+  //    cString filename = "average.dat";
+  
+  int print_mode = 0;   // 0=Normal, 1=Boolean results
+  
+  // Collect any other format information needed...
+  tList< tDataEntryCommand<cAnalyzeGenotype> > output_list;
+  tListIterator< tDataEntryCommand<cAnalyzeGenotype> > output_it(output_list);
+  
+  cStringList arg_list(cur_string);
+  
+  cout << "Found " << arg_list.GetSize() << " args." << endl;
+  
+  // Check for some command specific variables.
+  if (arg_list.PopString("0") != "") print_mode = 0;
+  if (arg_list.PopString("1") != "") print_mode = 1;
+  
+  cout << "There are " << arg_list.GetSize() << " column args." << endl;
+  
+  LoadGenotypeDataList(arg_list, output_list);
+  
+  cout << "Args are loaded." << endl;
+  
+  const int num_cols = output_list.GetSize();
+  
+  // Give some information in verbose mode.
+  if (verbose == true) {
+    cout << "  outputing as ";
+    if (print_mode == 1) cout << "boolean ";
+    cout << "text files." << endl;
+    cout << "  Format: ";
+    
+    output_it.Reset();
+    while (output_it.Next() != NULL) {
+      cout << output_it.Get()->GetName() << " ";
+    }
+    cout << endl;
+  }
+  
+  ofstream & fp = data_file_manager.GetOFStream(filename);
+  
+  // printing the headers
+  // not done by default since many dumps may be analyzed at the same time
+  // and results would be put in the same file
+  if (arg_list.GetSize()==0) {
+    // Headers
+    fp << "# Avida analyze modularity data" << endl;
+    fp << "# 1: organism length" << endl;
+    fp << "# 2: number of tasks done" << endl;
+    fp << "# 3: number of sites used in tasks" << endl;
+    fp << "# 4: proportion of sites used in tasks" << endl;
+    fp << "# 5: average number of tasks done per site" << endl;
+    fp << "# 6: average number sites per task done" << endl;
+    fp << "# 7: average number tasks per site per task" << endl;
+    fp << "# 8: average proportion of the non-overlaping region of a task" << endl;
+    fp << "# 9-17: average StDev in positions used for task 1-9" << endl;
+    fp << "# 18-26: average number of sites necessary for each of the tasks" << endl;
+    fp << "# 27-36: number of sites involved in 0-9 tasks" << endl;
+    fp << "# 37-45: average task length (distance from first to last inst used)" << endl;
+    fp << endl;
+    return;
+  }        
+  
+  // initialize various variables used in calculations
+  
+  int num_orgs = 0;		// number of organisms in the dump
+  
+  double  av_length = 0; 	// average organism length
+  double  av_task = 0; 	// average # of tasks done
+  double  av_inst = 0; 	// average # instructions used in tasks
+  double  av_inst_len = 0; 	// proportion of sites used for tasks
+  double  av_site_task = 0; 	// average number of sites per task
+  double  av_task_site = 0;   // average number of tasks per site
+  double  av_t_s_norm = 0;	// average number of tasks per site per task
+  double  av_task_overlap = 0; // average overlap between tasks
+  
+  // average StDev in positions used for a task
+  tArray<double> std_task_position(num_cols);
+  std_task_position.SetAll(0.0);
+  
+  // # of organisms actually doing a task
+  tArray<double> org_task(num_cols);
+  org_task.SetAll(0.0);
+  
+  // av. # of sites necessary for each of the tasks
+  tArray<double> av_num_inst(num_cols);
+  av_num_inst.SetAll(0.0);
+  
+  // number of sites involved in 0-9 tasks 
+  tArray<double> av_inst_task(num_cols+1);
+  av_inst_task.SetAll(0.0);
+  
+  // av. # task length (distance from first to last site used)
+  tArray<double> av_task_length(num_cols);
+  av_task_length.SetAll(0.0);
+  
+  
+  ///////////////////////////////////////////////////////
+  // Loop through all of the genotypes in this batch...
+  ///////////////////////////////////////////////////////
+  
+  tListIterator<cAnalyzeGenotype> batch_it(batch[cur_batch].List());
+  cAnalyzeGenotype * genotype = NULL;
+  
+  // would like to test oly the viable ones, but they can be non-viable
+  // and still reproduce and do tasks
+  // while ((genotype = batch_it.Next()) != NULL && genotype->GetViable()) {
+  while ((genotype = batch_it.Next()) != NULL) {
+    
+    int num_cpus = genotype->GetNumCPUs();
+    
+    if (verbose == true) cout << "  Mapping " << genotype->GetName() << endl;
+    
+    // Calculate the stats for the genotype we're working with...
+    genotype->Recalculate();
+    
+    // Check if the organism does any tasks. 
+    int does_tasks = 0;
+    for (int i = 0; i < num_cols; i++) {
+      if (genotype->GetTaskCount(i) > 0)  does_tasks = 1;
+    }
+    
+    // Don't calculate the modularity if the organism doesn't reproduce
+    // i.e. if the fitness is 0 
+    if (genotype->GetFitness() != 0 && does_tasks != 0) {
+      num_orgs = num_orgs + num_cpus;
+      
+      const int max_line = genotype->GetLength();
+      const cGenome & base_genome = genotype->GetGenome();
+      cGenome mod_genome(base_genome);
+      
+      // Create and initialize the modularity matrix
+      tMatrix<int> mod_matrix(num_cols, max_line);
+      mod_matrix.SetAll(0);
+      
+      // Create and initialize the task overalp matrix
+      tMatrix<int> task_overlap(num_cols, num_cols);
+      task_overlap.SetAll(0);
+      
+      // Create an initialize the counters for modularity
+      tArray<int> num_task(max_line); // number of tasks instruction is used in
+      tArray<int> num_inst(num_cols); // number of instructions involved in a task
+      tArray<int> sum(num_cols); 	    // helps with StDev calculations
+      tArray<int> sumsq(num_cols);    // helps with StDev calculations
+      tArray<int> inst_task(num_cols+1); // # of inst's involved in 0,1,2,3... tasks
+      tArray<int> task_length(num_cols);    // ditance between first and last inst involved in a task
+      
+      num_task.SetAll(0);
+      num_inst.SetAll(0);
+      sum.SetAll(0);
+      sumsq.SetAll(0);
+      inst_task.SetAll(0);
+      task_length.SetAll(0);
+      
+      int total_task = 0;        // total number of tasks done
+      int total_inst = 0;        // total number of instructions involved in tasks
+      int total_all = 0;         // sum of mod_matrix
+      double sum_task_overlap = 0;// task overlap for for this geneome
+        
+        cInstSet map_inst_set(inst_set);
+        
+        // Locate instruction corresponding to "NULL" in the instruction library.
+        {
+          const cInstruction inst_lib_null_inst = map_inst_set.GetInstLib()->GetInst("NULL");
+          if(inst_lib_null_inst == map_inst_set.GetInstLib()->GetInstError()){
+            cout << "<cAnalyze::CommandMapTasks> got error:" << endl;
+            cout << " --- instruction \"NULL\" isn't in the instruction library;" << endl;
+            cout << " --- get somebody to map a function to \"NULL\" in the library." << endl;
+            cout << " --- (probably to class method \"cHardware-of-some-type::initInstLib\"" << endl;
+            cout << " --- in file named \"cpu/hardware-of-some-type.cc\".)" << endl;
+            cout << " --- bailing-out." << endl;
+            exit(1);
+          }
+          // Add mapping to located instruction. 
+          map_inst_set.Add2(inst_lib_null_inst.GetOp());
+        }
+        const cInstruction null_inst = map_inst_set.GetInst("NULL");
+        
+        // Loop through all the lines of code, testing the removal of each.
+        for (int line_num = 0; line_num < max_line; line_num++) {
+          int cur_inst = base_genome[line_num].GetOp();
+          
+          mod_genome[line_num] = null_inst;
+          cAnalyzeGenotype test_genotype(mod_genome, map_inst_set);
+          cAnalyzeGenotype old_genotype(base_genome, map_inst_set);
+          test_genotype.Recalculate();
+          
+          // Print the individual columns...
+          output_it.Reset();
+          tDataEntryCommand<cAnalyzeGenotype> * data_command = NULL;
+          int cur_col = 0;
+          while ((data_command = output_it.Next()) != NULL) {
+            data_command->SetTarget(&test_genotype);
+            test_genotype.SetSpecialArgs(data_command->GetArgs());
+            // This is done so that under 'binary' option it marks
+            // the task as being influenced by the mutation iff
+            // it is completely knocked out, not just decreased
+            genotype->SetSpecialArgs(data_command->GetArgs());
+            
+            int compare = data_command->Compare(genotype);
+            
+            // If knocking out an instruction stops the expression of a
+            // particular task, mark that in the modularity matrix
+            // and add it to two counts
+            // Only do the checking if the test_genotype replicate, i.e.
+            // if it's fitness is not zeros
+            
+            if (compare < 0  && test_genotype.GetFitness() != 0) {
+              mod_matrix(cur_col,line_num) = 1;
+              num_inst[cur_col]++;
+              num_task[line_num]++;
+            }
+            cur_col++;
+          }
+          
+          // Reset the mod_genome back to the original sequence.
+          mod_genome[line_num].SetOp(cur_inst);
+        } // end of genotype-phenotype mapping for a single organism
+        
+        for (int i = 0; i < num_cols; i++) {if (num_inst[i] != 0) total_task++;}
+        for (int i = 0; i < max_line; i++) {if (num_task[i] != 0) total_inst++;}
+        for (int i = 0; i < num_cols; i++) {total_all = total_all + num_inst[i];}
+        
+        // Add the values to the av_ variables, used for calculating the average
+        // in order to weigh them by abundance, multiply everything by num_cpus
+        
+        av_length = av_length + max_line*num_cpus;
+        av_task = av_task + total_task*num_cpus;
+        av_inst = av_inst + total_inst*num_cpus;
+        av_inst_len = av_inst_len + (double) total_inst*num_cpus/max_line;
+        
+        if (total_task !=0)  av_site_task = av_site_task + num_cpus * (double) total_all/total_task; 
+        if (total_inst !=0)  av_task_site = av_task_site + num_cpus * (double) total_all/total_inst; 
+        if (total_inst !=0 && total_task !=0) {
+          av_t_s_norm = av_t_s_norm + num_cpus * (double) total_all/(total_inst*total_task); 
+        }
+        
+        for (int i = 0; i < num_cols; i++) { 
+          if (num_inst[i] > 0) {
+            av_num_inst[i] = av_num_inst[i] + num_inst[i] * num_cpus;
+            org_task[i] = org_task[i] + num_cpus;   // count how many are actually doing the task
+          }
+        }	
+        
+        // calculate average task overlap
+        // first construct num_task x num_task matrix with number of sites overlapping
+        for (int i = 0; i < max_line; i++) {
+          for (int j = 0; j < num_cols; j++) {
+            for (int k = j; k < num_cols; k++) {
+              if (mod_matrix(j,i)>0 && mod_matrix(k,i)>0) {
+                task_overlap(j,k)++;
+                if (j!=k) task_overlap(k,j)++;
+              }               
+            }
+          }
+        }
+        
+        // go though the task_overlap matrix, add and average everything up. 
+        if (total_task > 1) {
+          for (int i = 0; i < num_cols; i++) {
+            double overlap_per_task = 0;                 
+            for (int j = 0; j < num_cols; j++) {
+              if (i!=j) {overlap_per_task = overlap_per_task + task_overlap(i,j);}
+            }
+            if (task_overlap(i,i) !=0){
+              sum_task_overlap = sum_task_overlap + overlap_per_task / (task_overlap(i,i) * (total_task-1));   
+            }
+          }
+        }
+        
+        // now, divide that by number of tasks done and add to the grand sum, weigthed by num_cpus 
+        if (total_task!=0) {
+          av_task_overlap = av_task_overlap + num_cpus * (double) sum_task_overlap/total_task ;
+        }
+        // calculate the first/last postion of a task, the task "spread"
+        // starting from the top look for the fist command that matters for a task
+        
+        for (int i = 0; i < num_cols; i++) { 
+          int j = 0; 
+          while (j < max_line) {
+            if (mod_matrix(i,j) > 0 && task_length[i] == 0 ) {
+              task_length[i] = j;
+              break;
+            }
+            j++;
+          }
+        }
+        
+        // starting frm the bottom look for the last command that matters for a task
+        // and substract it from the first to get the task length
+        // add one in order to account for both the beginning and the end instruction
+        for (int i = 0; i < num_cols; i++) { 
+          int j = max_line - 1; 
+          while (j > -1) {
+            if (mod_matrix(i,j) > 0) {
+              task_length[i] = j - task_length[i] + 1;
+              break;
+            }
+            j--;
+          }
+        }
+        // add the task lengths to the average for the batch
+        // weigthed by the number of cpus for that genotype 
+        for (int i = 0; i < num_cols; i++) { 
+          av_task_length[i] = av_task_length[i] +  num_cpus * task_length[i];
+        }
+        
+        // calculate the Standard Deviation in the mean position of the task
+        for (int i = 0; i < num_cols; i++) { 
+          for (int j = 0; j < max_line; j++) { 
+            if (mod_matrix(i,j)>0) sum[i] = sum[i] + j;
+          }		
+        }
+        
+        double temp = 0;
+        for (int i = 0; i < num_cols; i++) {
+          if (num_inst[i]>1) { 
+            double av_sum = sum[i]/num_inst[i];
+            for (int j = 0; j < max_line; j++) {
+              if (mod_matrix(i,j)>0) temp = (av_sum - j)*(av_sum - j);
+            }
+            std_task_position[i] = std_task_position[i] + sqrt(temp/(num_inst[i]-1))*num_cpus;
+          } 
+        } 
+        
+        for (int i = 0; i < max_line; i++) { inst_task[num_task[i]]++ ;}
+        for (int i = 0; i < num_cols+1; i++) { av_inst_task[i] = av_inst_task[i] + inst_task[i] * num_cpus;}
+        
+    }
+  }  // this is the end of the loop going though all the organisms
+  
+  // make sure there are some organisms doing task in this batch
+  // if not, return all zeros
+  
+  if (num_orgs != 0) { 
+    fp << (double) av_length/num_orgs  << " ";  	// 1: average length
+    fp << (double) av_task/num_orgs << " ";		// 2: av. number of tasks done
+    fp << (double) av_inst/num_orgs << " ";		// 3: av. number of sites used for tasks
+    fp << (double) av_inst_len/num_orgs << " ";		// 4: proportion of sites used for tasks
+    fp << (double) av_task_site/num_orgs << " ";	// 5: av. number of tasks per site
+    fp << (double) av_site_task/num_orgs << " ";	// 6: av. number of sites per task
+    fp << (double) av_t_s_norm/num_orgs << " ";		// 7: av. number of tasks per site per task
+    fp << (double) 1 - av_task_overlap/num_orgs << " ";        // 8: av. proportion of a task that DOESN'T overlap
+    for (int i = 0; i < num_cols; i++) {
+      if (org_task[i] > 0) fp << std_task_position[i]/org_task[i]  << " ";
+      else fp << 0 << " ";
+    }
+    for (int i = 0; i < num_cols; i++) {
+      if (org_task[i] > 0) fp << (double) av_num_inst[i]/org_task[i]  << " ";
+      else fp << 0 << " ";
+    }
+    for (int i = 0; i < num_cols+1; i++) { fp << (double) av_inst_task[i]/num_orgs  << " ";}
+    for (int i = 0; i < num_cols; i++) { fp << (double) av_task_length[i]/num_orgs  << " ";}
+    fp << endl;
+  }
+  
+  else {
+    for (int i = 0; i < 8+4*num_cols+1; i++) {fp << "0 ";}
+    fp << endl;
+  }
+  }
+
+
+void cAnalyze::CommandMapMutations(cString cur_string)
+{
+  cout << "Constructing genome mutations maps..." << endl;
+  
+  // Load in the variables...
+  cString directory = PopDirectory(cur_string, "mutations/");
+  int file_type = FILE_TYPE_TEXT;
+  
+  cStringList arg_list(cur_string);
+  
+  // Check for some command specific variables.
+  if (arg_list.PopString("text") != "") file_type = FILE_TYPE_TEXT;
+  if (arg_list.PopString("html") != "") file_type = FILE_TYPE_HTML;
+  
+  // Give some information in verbose mode.
+  if (verbose == true) {
+    cout << "  outputing as ";
+    if (file_type == FILE_TYPE_TEXT) cout << "text files." << endl;
+    else cout << "HTML files." << endl;
+  }
+  
+  
+  ///////////////////////////////////////////////////////
+  // Loop through all of the genotypes in this batch...
+  
+  tListIterator<cAnalyzeGenotype> batch_it(batch[cur_batch].List());
+  cAnalyzeGenotype * genotype = NULL;
+  while ((genotype = batch_it.Next()) != NULL) {
+    if (verbose == true) {
+      cout << "  Creating mutation map for " << genotype->GetName() << endl;
+    }
+    
+    // Construct this filename...
+    cString filename;
+    if (file_type == FILE_TYPE_TEXT) {
+      filename.Set("%smut_map.%s.dat", directory(), genotype->GetName()());
+    } else {   //  if (file_type == FILE_TYPE_HTML) {
+      filename.Set("%smut_map.%s.html", directory(), genotype->GetName()());
+    }
+    ofstream fp(filename());
+    
+    // Calculate the stats for the genotype we're working with...
+    genotype->Recalculate();
+    const double base_fitness = genotype->GetFitness();
+    const int num_insts = inst_set.GetSize();
+    
+    // Headers...
+    if (file_type == FILE_TYPE_TEXT) {
+      fp << "# 1: Genome instruction ID (pre-mutation)" << endl;
+      for (int i = 0; i < num_insts; i++) {
+        fp << "# " << i+1 <<": Fit if mutated to '"
+        << inst_set.GetName(i) << "'" << endl;
+      }
+      fp << "# " << num_insts + 2 << ": Knockout" << endl;
+      fp << "# " << num_insts + 3 << ": Fraction Lethal" << endl;
+      fp << "# " << num_insts + 4 << ": Fraction Detremental" << endl;
+      fp << "# " << num_insts + 5 << ": Fraction Neutral" << endl;
+      fp << "# " << num_insts + 6 << ": Fraction Beneficial" << endl;
+      fp << "# " << num_insts + 7 << ": Average Fitness" << endl;
+      fp << "# " << num_insts + 8 << ": Expected Entropy" << endl;
+      fp << "# " << num_insts + 9 << ": Original Instruction Name" << endl;
+      fp << endl;
+      
+    } else { // if (file_type == FILE_TYPE_HTML) {
+             // Mark file as html
+      fp << "<html>" << endl;
+      
+      // Setup the body...
+      fp << "<body bgcolor=\"#FFFFFF\"" << endl
+        << " text=\"#000000\"" << endl
+        << " link=\"#0000AA\"" << endl
+        << " alink=\"#0000FF\"" << endl
+        << " vlink=\"#000044\">" << endl
+        << endl
+        << "<h1 align=center>Mutation Map for Run " << batch[cur_batch].Name()
+        << ", ID " << genotype->GetID() << "</h1>" << endl
+        << "<center>" << endl
+        << endl;
+      
+      // The main chart...
+      fp << "<table border=1 cellpadding=2>" << endl;
+      
+      // The headings...///
+      fp << "<tr><th>Genome ";
+      for (int i = 0; i < num_insts; i++) {
+        fp << "<th>" << inst_set.GetName(i) << " ";
+      }
+      fp << "<th>Knockout ";
+      fp << "<th>Frac. Lethal ";
+      fp << "<th>Frac. Detremental ";
+      fp << "<th>Frac. Neutral ";
+      fp << "<th>Frac. Beneficial ";
+      fp << "<th>Ave. Fitness ";
+      fp << "<th>Expected Entropy ";
+      fp << "</tr>" << endl << endl;
+    }
+    
+    const int max_line = genotype->GetLength();
+    const cGenome & base_genome = genotype->GetGenome();
+    cGenome mod_genome(base_genome);
+    
+    // Keep track of the number of mutations in each category...
+    int total_dead = 0, total_neg = 0, total_neut = 0, total_pos = 0;
+    double total_fitness = 0.0;
+    tArray<double> col_fitness(num_insts + 1);
+    col_fitness.SetAll(0.0);
+    
+    // Build an empty instruction into the an instruction library.
+    cInstSet map_inst_set(inst_set);
+    // Locate instruction corresponding to "NULL" in the instruction library.
+    {
+      const cInstruction inst_lib_null_inst = map_inst_set.GetInstLib()->GetInst("NULL");
+      if (inst_lib_null_inst == map_inst_set.GetInstLib()->GetInstError()){
+        cout << "<cAnalyze::CommandMapMutations> got error:" << endl;
+        cout << " --- instruction \"NULL\" isn't in the instruction library;" << endl;
+        cout << " --- get somebody to map a function to \"NULL\" in the library." << endl;
+        cout << " --- (probably to class method \"cHardware-of-some-type::initInstLib\"" << endl;
+        cout << " --- in file named \"cpu/hardware-of-some-type.cc\".)" << endl;
+        cout << " --- bailing-out." << endl;
+        exit(1);
+      }
+      // Add mapping to located instruction. 
+      map_inst_set.Add2(inst_lib_null_inst.GetOp());
+    }
+    const cInstruction null_inst = map_inst_set.GetInst("NULL");
+    
+    cString color_string;  // For coloring cells...
+    
+    // Loop through all the lines of code, testing all mutations...
+    for (int line_num = 0; line_num < max_line; line_num++) {
+      int cur_inst = base_genome[line_num].GetOp();
+      char cur_symbol = base_genome[line_num].GetSymbol();
+      int row_dead = 0, row_neg = 0, row_neut = 0, row_pos = 0;
+      double row_fitness = 0.0;
+      
+      // Column 1... the original instruction in the geneome.
+      if (file_type == FILE_TYPE_HTML) {
+        fp << "<tr><td align=right>" << inst_set.GetName(cur_inst)
+        << " (" << cur_symbol << ") ";
+      } else {
+        fp << cur_inst << " ";
+      }
+      
+      // Columns 2 to D+1 (the possible mutations)
+      for (int mod_inst = 0; mod_inst < num_insts; mod_inst++) 
+      {
+        if (mod_inst == cur_inst) {
+          if (file_type == FILE_TYPE_HTML) {
+            color_string = "#FFFFFF";
+            fp << "<th bgcolor=\"" << color_string << "\">";
+          }
+        }
+        else {
+          mod_genome[line_num].SetOp(mod_inst);
+          cAnalyzeGenotype test_genotype(mod_genome, inst_set);
+          test_genotype.Recalculate();
+          const double test_fitness = test_genotype.GetFitness() / base_fitness;
+          row_fitness += test_fitness;
+          total_fitness += test_fitness;
+          col_fitness[mod_inst] += test_fitness;
+
+          // Categorize this mutation...
+          if (test_fitness == 1.0) {           // Neutral Mutation...
+            row_neut++;
+            total_neut++;
+            if (file_type == FILE_TYPE_HTML) color_string = "#FFFFFF";
+          } else if (test_fitness == 0.0) {    // Lethal Mutation...
+            row_dead++;
+            total_dead++;
+            if (file_type == FILE_TYPE_HTML) color_string = "#FF0000";
+          } else if (test_fitness < 1.0) {     // Detrimental Mutation...
+            row_neg++;
+            total_neg++;
+            if (file_type == FILE_TYPE_HTML) color_string = "#FFFF00";
+          } else {                             // Beneficial Mutation...
+            row_pos++;
+            total_pos++;
+            if (file_type == FILE_TYPE_HTML) color_string = "#00FF00";
+          }
+          
+          // Write out this cell...
+          if (file_type == FILE_TYPE_HTML) {
+            fp << "<th bgcolor=\"" << color_string << "\">";
+          }
+          fp << test_fitness << " ";
+        }
+      }
+      
+      // Column: Knockout
+      mod_genome[line_num] = null_inst;
+      cAnalyzeGenotype test_genotype(mod_genome, map_inst_set);
+      test_genotype.Recalculate();
+      const double test_fitness = test_genotype.GetFitness() / base_fitness;
+      col_fitness[num_insts] += test_fitness;
+      
+      // Categorize this mutation if its in HTML mode (color only)...
+      if (file_type == FILE_TYPE_HTML) {
+        if (test_fitness == 1.0) color_string = "#FFFFFF";
+        else if (test_fitness == 0.0) color_string = "#FF0000";
+        else if (test_fitness < 1.0) color_string = "#FFFF00";
+        else color_string = "#00FF00";
+        
+        fp << "<th bgcolor=\"" << color_string << "\">";
+      }
+      
+      fp << test_fitness << " ";
+      
+      // Fraction Columns...
+      if (file_type == FILE_TYPE_HTML) fp << "<th bgcolor=\"#FF0000\">";
+      fp << (double) row_dead / (double) (num_insts-1) << " ";
+      
+      if (file_type == FILE_TYPE_HTML) fp << "<th bgcolor=\"#FFFF00\">";
+      fp << (double) row_neg / (double) (num_insts-1) << " ";
+      
+      if (file_type == FILE_TYPE_HTML) fp << "<th bgcolor=\"#FFFFFF\">";
+      fp << (double) row_neut / (double) (num_insts-1) << " ";
+      
+      if (file_type == FILE_TYPE_HTML) fp << "<th bgcolor=\"#00FF00\">";
+      fp << (double) row_pos / (double) (num_insts-1) << " ";
+      
+      
+      // Column: Average Fitness
+      if (file_type == FILE_TYPE_HTML) fp << "<th>";
+      fp << row_fitness / (double) (num_insts-1) << " ";
+      
+      // Column: Expected Entropy  @CAO Implement!
+      if (file_type == FILE_TYPE_HTML) fp << "<th>";
+      fp << 0.0 << " ";
+      
+      // End this row...
+      if (file_type == FILE_TYPE_HTML) fp << "</tr>";
+      fp << endl;
+      
+      // Reset the mod_genome back to the original sequence.
+      mod_genome[line_num].SetOp(cur_inst);
+    }
+    
+    
+    // Construct the final line of the table with all totals...
+    if (file_type == FILE_TYPE_HTML) {
+      fp << "<tr><th>Totals";
+      
+      // Instructions + Knockout
+      for (int i = 0; i <= num_insts; i++) {
+        fp << "<th>" << col_fitness[i] / max_line << " ";
+      }
+      
+      int total_tests = max_line * (num_insts-1);
+      fp << "<th>" << (double) total_dead / (double) total_tests << " ";
+      fp << "<th>" << (double) total_neg / (double) total_tests << " ";
+      fp << "<th>" << (double) total_neut / (double) total_tests << " ";
+      fp << "<th>" << (double) total_pos / (double) total_tests << " ";
+      fp << "<th>" << total_fitness / (double) total_tests << " ";
+      fp << "<th>" << 0.0 << " ";
+      
+      
+      // And close everything up...
+      fp << "</table>" << endl
+        << "</center>" << endl;
+    }
+    
+    }
+    }
+
+
+void cAnalyze::CommandMapDepth(cString cur_string)
+{
+  cout << "Constructing depth map..." << endl;
+  
+  cString filename("depth_map.dat");
+  if (cur_string.GetSize() != 0) filename = cur_string.PopWord();  
+  
+  int min_batch = 0;
+  int max_batch = cur_batch - 1;
+  
+  if (cur_string.GetSize() != 0) min_batch = cur_string.PopWord().AsInt();
+  if (cur_string.GetSize() != 0) max_batch = cur_string.PopWord().AsInt();
+  
+  // First, scan all of the batches to find the maximum depth.
+  int max_depth = -1;
+  cAnalyzeGenotype * genotype;
+  for (int i = min_batch; i <= max_batch; i++) {
+    tListIterator<cAnalyzeGenotype> list_it(batch[i].List());
+    while ((genotype = list_it.Next()) != NULL) {
+      if (genotype->GetDepth() > max_depth) max_depth = genotype->GetDepth();
+    }
+  }
+  
+  cout << "max_depth = " << max_depth << endl;
+  
+  ofstream & fp = data_file_manager.GetOFStream(filename);
+  
+  cout << "Output to " << filename << endl;
+  tArray<int> depth_array(max_depth+1);
+  for (cur_batch = min_batch; cur_batch <= max_batch; cur_batch++) {
+    depth_array.SetAll(0);
+    tListIterator<cAnalyzeGenotype> list_it(batch[cur_batch].List());
+    while ((genotype = list_it.Next()) != NULL) {
+      const int cur_depth = genotype->GetDepth();
+      const int cur_count = genotype->GetNumCPUs();
+      depth_array[cur_depth] += cur_count;
+    }
+    
+    for (int i = 0; i <= max_depth; i++) {
+      fp << depth_array[i] << " ";
+    }
+    fp << endl;
+  }
+}
+
+void cAnalyze::CommandHamming(cString cur_string)
+{
+  cString filename("hamming.dat");
+  if (cur_string.GetSize() != 0) filename = cur_string.PopWord();
+  
+  int batch1 = PopBatch(cur_string.PopWord());
+  int batch2 = PopBatch(cur_string.PopWord());
+  
+  // We want batch2 to be the larger one for efficiency...
+  if (batch[batch1].List().GetSize() > batch[batch2].List().GetSize()) {
+    int tmp = batch1;  batch1 = batch2;  batch2 = tmp;
+  }
+  
+  if (verbose == false) {
+    cout << "Calculating Hamming Distance... ";
+    cout.flush();
+  } else {
+    cout << "Calculating Hamming Distance between batches "
+    << batch1 << " and " << batch2 << endl;
+    cout.flush();
+  }
+  
+  // Setup some variables;
+  cAnalyzeGenotype * genotype1 = NULL;
+  cAnalyzeGenotype * genotype2 = NULL;
+  int total_dist = 0;
+  int total_count = 0;
+  
+  tListIterator<cAnalyzeGenotype> list1_it(batch[batch1].List());
+  tListIterator<cAnalyzeGenotype> list2_it(batch[batch2].List());
+  
+  while ((genotype1 = list1_it.Next()) != NULL) {
+    list2_it.Reset();
+    while ((genotype2 = list2_it.Next()) != NULL) {
+      // Determine the counts...
+      const int count1 = genotype1->GetNumCPUs();
+      const int count2 = genotype2->GetNumCPUs();
+      const int num_pairs = (genotype1 == genotype2) ?
+        ((count1 - 1) * (count2 - 1)) : (count1 * count2);
+      if (num_pairs == 0) continue;
+      
+      // And do the tests...
+      const int dist =
+        cGenomeUtil::FindHammingDistance(genotype1->GetGenome(),
+                                         genotype2->GetGenome());
+      total_dist += dist * num_pairs;
+      total_count += num_pairs;
+    }
+  }
+  
+  
+  // Calculate the final answer
+  double ave_dist = (double) total_dist / (double) total_count;
+  cout << " ave distance = " << ave_dist << endl;
+  
+  cDataFile & df = data_file_manager.Get(filename);
+  
+  df.WriteComment( "Hamming distance information" );
+  df.WriteTimeStamp();  
+  
+  df.Write(batch[batch1].Name(), "Name of First Batch");
+  df.Write(batch[batch2].Name(), "Name of Second Batch");
+  df.Write(ave_dist,             "Average Hamming Distance");
+  df.Write(total_count,          "Total Pairs Test");
+  df.Endl();
+}
+
+void cAnalyze::CommandLevenstein(cString cur_string)
+{
+  cString filename("lev.dat");
+  if (cur_string.GetSize() != 0) filename = cur_string.PopWord();
+  
+  int batch1 = PopBatch(cur_string.PopWord());
+  int batch2 = PopBatch(cur_string.PopWord());
+  
+  // We want batch2 to be the larger one for efficiency...
+  if (batch[batch1].List().GetSize() > batch[batch2].List().GetSize()) {
+    int tmp = batch1;  batch1 = batch2;  batch2 = tmp;
+  }
+  
+  if (verbose == false) {
+    cout << "Calculating Levenstein Distance... ";
+    cout.flush();
+  } else {
+    cout << "Calculating Levenstein Distance between batch "
+    << batch1 << " and " << batch2 << endl;
+    cout.flush();
+  }
+  
+  // Setup some variables;
+  cAnalyzeGenotype * genotype1 = NULL;
+  cAnalyzeGenotype * genotype2 = NULL;
+  int total_dist = 0;
+  int total_count = 0;
+  
+  tListIterator<cAnalyzeGenotype> list1_it(batch[batch1].List());
+  tListIterator<cAnalyzeGenotype> list2_it(batch[batch2].List());
+  
+  // Loop through all of the genotypes in each batch...
+  while ((genotype1 = list1_it.Next()) != NULL) {
+    list2_it.Reset();
+    while ((genotype2 = list2_it.Next()) != NULL) {
+      // Determine the counts...
+      const int count1 = genotype1->GetNumCPUs();
+      const int count2 = genotype2->GetNumCPUs();
+      const int num_pairs = (genotype1 == genotype2) ?
+        ((count1 - 1) * (count2 - 1)) : (count1 * count2);
+      if (num_pairs == 0) continue;
+      
+      // And do the tests...
+      const int dist = cGenomeUtil::FindEditDistance(genotype1->GetGenome(),
+                                                     genotype2->GetGenome());
+      total_dist += dist * num_pairs;
+      total_count += num_pairs;
+    }
+  }
+  
+  // Calculate the final answer
+  double ave_dist = (double) total_dist / (double) total_count;
+  cout << " ave distance = " << ave_dist << endl;
+  
+  cDataFile & df = data_file_manager.Get(filename);
+  
+  df.WriteComment( "Levenstein distance information" );
+  df.WriteTimeStamp();  
+  
+  df.Write(batch[batch1].Name(), "Name of First Batch");
+  df.Write(batch[batch2].Name(), "Name of Second Batch");
+  df.Write(ave_dist,             "Average Levenstein Distance");
+  df.Write(total_count,          "Total Pairs Test");
+  df.Endl();
+}
+
+void cAnalyze::CommandSpecies(cString cur_string)
+{
+  cString filename("species.dat");
+  if (cur_string.GetSize() != 0) filename = cur_string.PopWord();
+  
+  int batch1 = PopBatch(cur_string.PopWord());
+  int batch2 = PopBatch(cur_string.PopWord());
+  int num_compare = PopBatch(cur_string.PopWord());
+  
+  // We want batch2 to be the larger one for efficiency...
+  if (batch[batch1].List().GetSize() > batch[batch2].List().GetSize()) {
+    int tmp = batch1;  batch1 = batch2;  batch2 = tmp;
+  }
+  
+  if (verbose == false) cout << "Calculating Species Distance... " << endl;
+  else cout << "Calculating Species Distance between batch "
+    << batch1 << " and " << batch2 << endl;
+  
+  // Setup some variables;
+  cAnalyzeGenotype * genotype1 = NULL;
+  cAnalyzeGenotype * genotype2 = NULL;
+  int total_fail = 0;
+  int total_count = 0;
+  
+  tListIterator<cAnalyzeGenotype> list1_it(batch[batch1].List());
+  tListIterator<cAnalyzeGenotype> list2_it(batch[batch2].List());
+  
+  // Loop through all of the genotypes in each batch...
+  while ((genotype1 = list1_it.Next()) != NULL) {
+    list2_it.Reset();
+    while ((genotype2 = list2_it.Next()) != NULL) {
+      // Determine the counts...
+      const int count1 = genotype1->GetNumCPUs();
+      const int count2 = genotype2->GetNumCPUs();
+      int num_pairs = count1 * count2; 
+      int fail_count = 0;
+      bool cross1_viable = true;
+      bool cross2_viable = true;
+      
+      
+      if (genotype1 == genotype2) {
+        total_count += num_pairs * 2 * num_compare;
+      }
+      else {	
+        assert(num_compare!=0);
+        // And do the tests...
+        for (int iter=1; iter < num_compare; iter++) {
+          cCPUMemory test_genome0 = genotype1->GetGenome(); 
+          cCPUMemory test_genome1 = genotype2->GetGenome(); 
+          
+          double start_frac = g_random.GetDouble();
+          double end_frac = g_random.GetDouble();
+          if (start_frac > end_frac) nFunctions::Swap(start_frac, end_frac);
+          
+          int start0 = (int) (start_frac * (double) test_genome0.GetSize());
+          int end0   = (int) (end_frac * (double) test_genome0.GetSize());
+          int start1 = (int) (start_frac * (double) test_genome1.GetSize());
+          int end1   = (int) (end_frac * (double) test_genome1.GetSize());
+          assert( start0 >= 0  &&  start0 < test_genome0.GetSize() );
+          assert( end0   >= 0  &&  end0   < test_genome0.GetSize() );
+          assert( start1 >= 0  &&  start1 < test_genome1.GetSize() );
+          assert( end1   >= 0  &&  end1   < test_genome1.GetSize() );
+          
+          // Calculate size of sections crossing over...    
+          int size0 = end0 - start0;
+          int size1 = end1 - start1;
+          
+          int new_size0 = test_genome0.GetSize() - size0 + size1;   
+          int new_size1 = test_genome1.GetSize() - size1 + size0;
+          
+          // Don't Crossover if offspring will be illegal!!!
+          if (new_size0 < MIN_CREATURE_SIZE || new_size0 > MAX_CREATURE_SIZE || 
+              new_size1 < MIN_CREATURE_SIZE || new_size1 > MAX_CREATURE_SIZE) { 
+            fail_count +=2; 
+            break; 
+          } 
+          
+	  // Swap the components
+	  cGenome cross0 = cGenomeUtil::Crop(test_genome0, start0, end0);
+	  cGenome cross1 = cGenomeUtil::Crop(test_genome1, start1, end1);
+	  test_genome0.Replace(start0, size0, cross1);
+	  test_genome1.Replace(start1, size1, cross0);
+          
+	  // Run each side, and determine viability...
+          cCPUTestInfo test_info;
+          cTestCPU::TestGenome(test_info, test_genome0);
+          cross1_viable = test_info.IsViable();
+          
+          cTestCPU::TestGenome(test_info, test_genome1);
+          cross2_viable = test_info.IsViable();
+          
+          if (cross1_viable == false) fail_count++;   
+          if (cross2_viable == false) fail_count++;
+        }
+        
+        total_fail += fail_count * num_pairs;
+        total_count += num_pairs * 2 * num_compare;
+      }
+    }
+  }
+  // Calculate the final answer
+  double ave_dist = (double) total_fail / (double) total_count;
+  cout << "  ave distance = " << ave_dist
+    << " in " << total_count
+    << " tests." << endl; 
+  
+  cDataFile & df = data_file_manager.Get(filename);
+  
+  df.WriteComment( "Species information" );
+  df.WriteTimeStamp();  
+  
+  df.Write(batch[batch1].Name(), "Name of First Batch");
+  df.Write(batch[batch2].Name(), "Name of Second Batch");
+  df.Write(ave_dist,             "Average Species Distance");
+  df.Write(total_count,          "Total Recombinants tested");
+  df.Endl();
+}
+
+void cAnalyze::CommandRecombine(cString cur_string)
+{
+  int batch1 = PopBatch(cur_string.PopWord());
+  int batch2 = PopBatch(cur_string.PopWord());
+  int batch3 = PopBatch(cur_string.PopWord());
+  int num_compare = PopBatch(cur_string.PopWord());
+  
+  // We want batch2 to be the larger one for efficiency...
+  if (batch[batch1].List().GetSize() > batch[batch2].List().GetSize()) {
+    int tmp = batch1;  batch1 = batch2;  batch2 = tmp;
+  }
+  
+  if (verbose == false) cout << "Creating recombinants...  " << endl;
+  else cout << "Creating recombinants between batch "
+    << batch1 << " and " << batch2 << endl;
+  
+  // Setup some variables;
+  cAnalyzeGenotype * genotype1 = NULL;
+  cAnalyzeGenotype * genotype2 = NULL;
+  
+  tListIterator<cAnalyzeGenotype> list1_it(batch[batch1].List());
+  tListIterator<cAnalyzeGenotype> list2_it(batch[batch2].List());
+  
+  // Loop through all of the genotypes in each batch...
+  while ((genotype1 = list1_it.Next()) != NULL) {
+    list2_it.Reset();
+    while ((genotype2 = list2_it.Next()) != NULL) {
+      // Determine the counts...
+      int fail_count = 0;
+      
+      
+      assert(num_compare!=0);
+      // And do the tests...
+      for (int iter=1; iter < num_compare; iter++) {
+        cCPUMemory test_genome0 = genotype1->GetGenome(); 
+        cCPUMemory test_genome1 = genotype2->GetGenome(); 
+        
+        double start_frac = g_random.GetDouble();
+        double end_frac = g_random.GetDouble();
+        if (start_frac > end_frac) nFunctions::Swap(start_frac, end_frac);
+        
+        int start0 = (int) (start_frac * (double) test_genome0.GetSize());
+        int end0   = (int) (end_frac * (double) test_genome0.GetSize());
+        int start1 = (int) (start_frac * (double) test_genome1.GetSize());
+        int end1   = (int) (end_frac * (double) test_genome1.GetSize());
+        assert( start0 >= 0  &&  start0 < test_genome0.GetSize() );
+        assert( end0   >= 0  &&  end0   < test_genome0.GetSize() );
+        assert( start1 >= 0  &&  start1 < test_genome1.GetSize() );
+        assert( end1   >= 0  &&  end1   < test_genome1.GetSize() );
+        
+        // Calculate size of sections crossing over...    
+        int size0 = end0 - start0;
+        int size1 = end1 - start1;
+        
+        int new_size0 = test_genome0.GetSize() - size0 + size1;   
+        int new_size1 = test_genome1.GetSize() - size1 + size0;
+        
+        // Don't Crossover if offspring will be illegal!!!
+        if (new_size0 < MIN_CREATURE_SIZE || new_size0 > MAX_CREATURE_SIZE || 
+            new_size1 < MIN_CREATURE_SIZE || new_size1 > MAX_CREATURE_SIZE) { 
+          fail_count +=2; 
+          break; 
+        } 
+        
+        if (size0 > 0 && size1 > 0) {
+          cGenome cross0 = cGenomeUtil::Crop(test_genome0, start0, end0);
+          cGenome cross1 = cGenomeUtil::Crop(test_genome1, start1, end1);
+          test_genome0.Replace(start0, size0, cross1);
+          test_genome1.Replace(start1, size1, cross0);
+        }
+        else if (size0 > 0) {
+          cGenome cross0 = cGenomeUtil::Crop(test_genome0, start0, end0);
+          test_genome1.Replace(start1, size1, cross0);
+        }
+        else if (size1 > 0) {
+          cGenome cross1 = cGenomeUtil::Crop(test_genome1, start1, end1);
+          test_genome0.Replace(start0, size0, cross1);
+        }
+        
+        cAnalyzeGenotype * new_genotype0 = new cAnalyzeGenotype(test_genome0, inst_set); 
+        cAnalyzeGenotype * new_genotype1 = new cAnalyzeGenotype(test_genome1, inst_set); 
+        new_genotype0->SetNumCPUs(1); 
+        new_genotype1->SetNumCPUs(1); 
+        new_genotype0->SetID(0);
+        new_genotype1->SetID(0);
+        new_genotype0->SetName("noname");
+        new_genotype1->SetName("noname");
+        
+        batch[batch3].List().PushRear(new_genotype0);
+        batch[batch3].List().PushRear(new_genotype1); 
+        
+        //batch[batch3].List().PushRear(new cAnalyzeGenotype(test_genome0, inst_set));
+        //batch[batch3].List().PushRear(new cAnalyzeGenotype(test_genome1, inst_set));
+        
+      }
+    }
+  }
+}
+
+void cAnalyze::CommandAlign(cString cur_string)
+{
+  // Align does not need any args yet.
+  (void) cur_string;
+  
+  cout << "Aligning sequences..." << endl;
+  
+  if (batch[cur_batch].IsLineage() == false && verbose == true) {
+    cerr << "  Warning: sequences may not be a consecutive lineage."
+    << endl;
+  }
+  
+  // Create an array of all the sequences we need to align.
+  tListPlus<cAnalyzeGenotype> & glist = batch[cur_batch].List();
+  tListIterator<cAnalyzeGenotype> batch_it(glist);
+  const int num_sequences = glist.GetSize();
+  cString * sequences = new cString[num_sequences];
+  
+  // Move through each sequence an update it.
+  batch_it.Reset();
+  cString diff_info;
+  for (int i = 0; i < num_sequences; i++) {
+    sequences[i] = batch_it.Next()->GetGenome().AsString();
+    if (i == 0) continue;
+    // Track of the number of insertions and deletions to shift properly.
+    int num_ins = 0;
+    int num_del = 0;
+    
+    // Compare each string to the previous.
+    cStringUtil::EditDistance(sequences[i], sequences[i-1], diff_info, '_');
+    while (diff_info.GetSize() != 0) {
+      cString cur_mut = diff_info.Pop(',');
+      const char mut_type = cur_mut[0];
+      cur_mut.ClipFront(1); cur_mut.ClipEnd(1);
+      int position = cur_mut.AsInt();
+      
+      // Nothing to do with Mutations
+      if (mut_type == 'M') continue;
+      
+      // Handle insertions...
+      if (mut_type == 'I') {
+        // Loop back and insert an '_' into all previous sequences.
+        for (int j = 0; j < i; j++) {
+          sequences[j].Insert('_', position + num_del);
+        }
+        num_ins++;
+      }
+      
+      // Handle Deletions...
+      else if (mut_type == 'D') {
+        // Insert '_' into the current sequence at the point of deletions.
+        sequences[i].Insert("_", position + num_ins);
+        num_del++;
+      }
+      
+    }
+  }
+  
+  batch_it.Reset();
+  for (int i = 0; i < num_sequences; i++) {
+    batch_it.Next()->SetAlignedSequence(sequences[i]);
+  }
+  
+  // Cleanup
+  delete [] sequences;
+  
+  // Adjust the flags on this batch
+  // batch[cur_batch].SetLineage(false);
+  batch[cur_batch].SetAligned(true);
+}
+
+// Now this command do not consider changing environment 
+// and only work for lineage and fixed-length runs.
+void cAnalyze::AnalyzeNewInfo(cString cur_string)
+{
+  cout << "Analyze new information in child about environment ..." << endl;
+  
+  // Load in the variables
+  int words = cur_string.CountNumWords();
+  if (words < 1) {
+    cout << "This command requires mutation rate, skipping." << endl;
+    return;
+  }
+  
+  // Get the mutation rate ...
+  double mu = cur_string.PopWord().AsDouble();
+  
+  // Create the directory using the string given as the second argument
+  cString dir = cur_string.PopWord();
+  cString defaultDir = "newinfo/";
+  cString directory = PopDirectory(dir, defaultDir);
+  
+  ///////////////////////////////////////////////////////
+  // Loop through all of the genotypes in this batch...
+  
+  cString newinfo_fn;
+  ofstream newinfo_fp;
+  if (batch[cur_batch].IsLineage() == true) {
+    newinfo_fn.Set("%s%s.newinfo.dat", directory(), "lineage");
+    newinfo_fp.open(newinfo_fn);
+  } else {
+    cout << "This command requires the lineage in the batch, skipping.\n";
+    return;
+  }
+  newinfo_fp << "# Legend:" << endl;
+  newinfo_fp << "# 1:Child Genotype ID" << endl;
+  newinfo_fp << "# 2:Parent Genotype ID" << endl;
+  newinfo_fp << "# 3:Information of Child about Environment I(C:E)" << endl;
+  newinfo_fp << "# 4:Information of Parent about Environment I(P:E)" << endl;
+  newinfo_fp << "# 5:I(C:E)-I(P:E)" << endl;
+  newinfo_fp << "# 6:Information Gained in Child" << endl;
+  newinfo_fp << "# 7:Information Decreased in Child" << endl;
+  newinfo_fp << "# 8:Net Increasing of Information in Child" << endl;
+  newinfo_fp << endl; 
+  
+  tListIterator<cAnalyzeGenotype> batch_it(batch[cur_batch].List());
+  cAnalyzeGenotype * parent_genotype = batch_it.Next();
+  if (parent_genotype == NULL) {
+    newinfo_fp.close();
+    return;
+  }
+  cAnalyzeGenotype * child_genotype = NULL;
+  double I_P_E; // Information of parent about environment
+  double H_P_E = AnalyzeEntropy(parent_genotype, mu);
+  I_P_E = parent_genotype->GetLength() - H_P_E;
+
+  while ((child_genotype = batch_it.Next()) != NULL) {
+    
+    if (verbose == true) {
+      cout << "Analyze new information for " << child_genotype->GetName() << endl;
+    }
+    
+    // Information of parent about its environment should not be zero.
+    if (I_P_E == 0) {
+      cerr << "Error: Information between parent and its enviroment is zero."
+	   << "(cAnalyze::AnalyzeNewInfo)" << endl;
+      exit(1);
+    }
+
+    double H_C_E = AnalyzeEntropy(child_genotype, mu);
+    double I_C_E = child_genotype->GetLength() - H_C_E;
+    double net_gain = I_C_E - I_P_E;
+    
+    // Increased information in child compared to parent
+    double child_increased_info = IncreasedInfo(child_genotype, parent_genotype, mu);
+    
+    // Lost information in child compared to parent
+    double child_lost_info = IncreasedInfo(parent_genotype, child_genotype, mu);
+
+    // Write information to file ...
+    newinfo_fp << child_genotype->GetID() << " ";
+    newinfo_fp << parent_genotype->GetID() << " ";
+    newinfo_fp << I_C_E << " ";
+    newinfo_fp << I_P_E << " ";
+    newinfo_fp << net_gain << " ";
+    newinfo_fp << child_increased_info << " ";
+    newinfo_fp << child_lost_info << " ";
+    newinfo_fp << child_increased_info - child_lost_info << endl;
+    
+    parent_genotype = child_genotype;
+    I_P_E = I_C_E;
+  }
+  
+  newinfo_fp.close();
+  return;
+}
+
+
+
+void cAnalyze::WriteClone(cString cur_string)
+{
+  // Load in the variables...
+  cString filename("clone.dat");
+  int num_cells = -1;
+  if (cur_string.GetSize() != 0) filename = cur_string.PopWord();
+  if (cur_string.GetSize() != 0) num_cells = cur_string.PopWord().AsInt();
+  
+  
+  ofstream & fp = data_file_manager.GetOFStream(filename);
+  
+  // Start up again at update zero...
+  fp << "0 ";
+  
+  // Setup the genebank sizes of lists to all be zero.
+  fp << MAX_CREATURE_SIZE << " ";
+  for (int i = 0; i < MAX_CREATURE_SIZE; i++) {
+    fp << "0 ";
+  }
+  
+  // Save the individual genotypes
+  fp << batch[cur_batch].List().GetSize() << " ";
+  
+  int org_count = 0;
+  tListIterator<cAnalyzeGenotype> batch_it(batch[cur_batch].List());
+  cAnalyzeGenotype * genotype = NULL;
+  while ((genotype = batch_it.Next()) != NULL) {
+    org_count += genotype->GetNumCPUs();
+    const int length = genotype->GetLength();
+    const cGenome & genome = genotype->GetGenome();
+    
+    fp << genotype->GetID() << " "
+      << length << " ";
+    
+    for (int i = 0; i < length; i++) {
+      fp << genome[i].GetOp() << " ";
+    }
+  }
+  
+  // Write out the current state of the grid.
+  
+  if (num_cells == 0) num_cells = org_count;
+  fp << num_cells << " ";
+  
+  batch_it.Reset();
+  while ((genotype = batch_it.Next()) != NULL) {
+    for (int i = 0; i < genotype->GetNumCPUs(); i++) {
+      fp << genotype->GetID() << " ";
+    }
+  }
+  
+  // Fill out the remainder of the grid with -1
+  for (int i = org_count; i < num_cells; i++) {
+    fp << "-1 ";
+  }
+}
+
+
+void cAnalyze::WriteInjectEvents(cString cur_string)
+{
+  // Load in the variables...
+  cString filename("events_inj.cfg");
+  int start_cell = 0;
+  int lineage = 0;
+  if (cur_string.GetSize() != 0) filename = cur_string.PopWord();
+  if (cur_string.GetSize() != 0) start_cell = cur_string.PopWord().AsInt();
+  if (cur_string.GetSize() != 0) lineage = cur_string.PopWord().AsInt();
+  
+  ofstream & fp = data_file_manager.GetOFStream(filename);
+  
+  int org_count = 0;
+  tListIterator<cAnalyzeGenotype> batch_it(batch[cur_batch].List());
+  cAnalyzeGenotype * genotype = NULL;
+  while ((genotype = batch_it.Next()) != NULL) {
+    const int cur_count = genotype->GetNumCPUs();
+    org_count += cur_count;
+    const cGenome & genome = genotype->GetGenome();
+    
+    fp << "u 0 inject_sequence "
+      << genome.AsString() << " "
+      << start_cell << " "
+      << start_cell + cur_count << " "
+      << genotype->GetMerit() << " "
+      << lineage << " "
+      << endl;
+    start_cell += cur_count;
+  }
+}
+
+
+void cAnalyze::WriteCompetition(cString cur_string)
+{
+  cout << "Writing Competition events..." << endl;
+  
+  // Load in the variables...
+  int join_UD = 0;
+  double start_merit = 50000;
+  cString filename("events_comp.cfg");
+  int batch_A = cur_batch - 1;
+  int batch_B = cur_batch;
+  int grid_side = -1;
+  int lineage = 0;
+  
+  // Make sure we have reasonable default batches.
+  if (cur_batch == 0) { batch_A = 0; batch_B = 1; }
+  
+  if (cur_string.GetSize() != 0) join_UD = cur_string.PopWord().AsInt();
+  if (cur_string.GetSize() != 0) start_merit = cur_string.PopWord().AsDouble();
+  if (cur_string.GetSize() != 0) filename = cur_string.PopWord();
+  if (cur_string.GetSize() != 0) batch_A = cur_string.PopWord().AsInt();
+  if (cur_string.GetSize() != 0) batch_B = cur_string.PopWord().AsInt();
+  if (cur_string.GetSize() != 0) grid_side = cur_string.PopWord().AsInt();
+  if (cur_string.GetSize() != 0) lineage = cur_string.PopWord().AsInt();
+  
+  // Check inputs...
+  if (join_UD < 0) join_UD = 0;
+  if (batch_A < 0 || batch_B < 0) {
+    cerr << "Error: Batch IDs must be positive!" << endl;
+    return;
+  }
+  
+  ofstream & fp = data_file_manager.GetOFStream(filename);
+  
+  // Count the number of organisms in each batch...
+  cAnalyzeGenotype * genotype = NULL;
+  
+  int org_count_A = 0;
+  tListIterator<cAnalyzeGenotype> batchA_it(batch[batch_A].List());
+  while ((genotype = batchA_it.Next()) != NULL) {
+    org_count_A += genotype->GetNumCPUs();
+  }
+  
+  int org_count_B = 0;
+  tListIterator<cAnalyzeGenotype> batchB_it(batch[batch_B].List());
+  while ((genotype = batchB_it.Next()) != NULL) {
+    org_count_B += genotype->GetNumCPUs();
+  }
+  
+  int max_count = Max(org_count_A, org_count_B);
+  if (max_count > 10000) {
+    cout << "Warning: more than 10,000 organisms in sub-population!" << endl;
+  }
+  
+  if (grid_side <= 0) {
+    for (grid_side = 5; grid_side < 100; grid_side += 5) {
+      if (grid_side * grid_side >= max_count) break;
+    }
+    if (verbose == true) {
+      cout << "...assuming population size "
+      << grid_side << "x" << grid_side << "." << endl;
+    }
+  }
+  
+  
+  int pop_size = grid_side * grid_side;
+  
+  int inject_pos = 0;
+  while ((genotype = batchA_it.Next()) != NULL) {
+    const int cur_count = genotype->GetNumCPUs();
+    const cGenome & genome = genotype->GetGenome();
+    double cur_merit = start_merit;
+    if (cur_merit < 0) cur_merit = genotype->GetMerit();
+    fp << "u 0 inject_sequence "
+      << genome.AsString() << " "
+      << inject_pos << " "
+      << inject_pos + cur_count << " "
+      << cur_merit << " "
+      << lineage << " "
+      << endl;
+    inject_pos += cur_count;
+  }
+  
+  inject_pos = pop_size;
+  while ((genotype = batchB_it.Next()) != NULL) {
+    const int cur_count = genotype->GetNumCPUs();
+    const cGenome & genome = genotype->GetGenome();
+    double cur_merit = start_merit;
+    if (cur_merit < 0) cur_merit = genotype->GetMerit();
+    fp << "u 0 inject_sequence "
+      << genome.AsString() << " "
+      << inject_pos << " "
+      << inject_pos + cur_count << " "
+      << cur_merit << " "
+      << lineage+1 << " "
+      << endl;
+    inject_pos += cur_count;
+  }
+  
+  fp << "u 0 sever_grid_row" << grid_side << endl;
+  fp << "u " << join_UD << " join_grid_row " << grid_side << endl;
+}
+
+
+void cAnalyze::AnalyzeMuts(cString cur_string)
+{
+  cout << "Analyzing Mutations" << endl;
+  
+  // Make sure we have everything we need.
+  if (batch[cur_batch].IsAligned() == false) {
+    cout << "  Error: sequences not aligned." << endl;
+    return;
+  }
+  
+  // Setup variables...
+  cString filename("analyze_muts.dat");
+  bool all_combos = false;
+  if (cur_string.GetSize() != 0) filename = cur_string.PopWord();
+  if (cur_string.GetSize() != 0) all_combos = cur_string.PopWord().AsInt();
+  
+  tListPlus<cAnalyzeGenotype> & gen_list = batch[cur_batch].List();
+  tListIterator<cAnalyzeGenotype> batch_it(batch[cur_batch].List());
+  
+  const int num_sequences = gen_list.GetSize();
+  const int sequence_length =
+    gen_list.GetFirst()->GetAlignedSequence().GetSize();
+  cString * sequences = new cString[num_sequences];
+  int * mut_count = new int[sequence_length];
+  for (int i = 0; i < sequence_length; i++) mut_count[i] = 0;
+  
+  // Load in the sequences
+  batch_it.Reset();
+  int count = 0;
+  while (batch_it.Next() != NULL) {
+    sequences[count] = batch_it.Get()->GetAlignedSequence();
+    count++;
+  }
+  
+  // Count the number of changes at each site...
+  for (int i = 1; i < num_sequences; i++) {       // For each pair...
+    cString & seq1 = sequences[i-1];
+    cString & seq2 = sequences[i];
+    for (int j = 0; j < sequence_length; j++) {   // For each site...
+      if (seq1[j] != seq2[j]) mut_count[j]++;
+    }
+  }
+  
+  // Grab the two strings we're actively going to be working with.
+  cString & first_seq = sequences[0];
+  cString & last_seq = sequences[num_sequences - 1];
+  
+  // Print out the header...
+  ofstream & fp = data_file_manager.GetOFStream(filename);
+  fp << "# " << sequences[0] << endl;
+  fp << "# " << sequences[num_sequences - 1] << endl;
+  fp << "# ";
+  for (int i = 0; i < sequence_length; i++) {
+    if (mut_count[i] == 0) fp << " ";
+    else if (mut_count[i] > 9) fp << "+";
+    else fp << mut_count[i];
+  }
+  fp << endl;
+  fp << "# ";
+  for (int i = 0; i < sequence_length; i++) {
+    if (first_seq[i] == last_seq[i]) fp << " ";
+    else fp << "^";
+  }
+  fp << endl << endl;
+  
+  // Count the number of diffs between the two strings we're interested in.
+  const int total_diffs = cStringUtil::Distance(first_seq, last_seq);
+  if (verbose) cout << "  " << total_diffs << " mutations being tested."
+    << endl;
+  
+  // Locate each difference.
+  int * mut_positions = new int[total_diffs];
+  int cur_mut = 0;
+  for (int i = 0; i < first_seq.GetSize(); i++) {
+    if (first_seq[i] != last_seq[i]) {
+      mut_positions[cur_mut] = i;
+      cur_mut++;
+    }
+  }
+  
+  // The number of mutations we need to deal with will tell us how much
+  // we can attempt to do. (@CAO should be able to overide defaults)
+  bool scan_combos = true;  // Scan all possible combos of mutations?
+  bool detail_muts = true;  // Collect detailed info on all mutations?
+  bool print_all = true;    // Print everything we collect without digestion?
+  if (total_diffs > 30) scan_combos = false;
+  if (total_diffs > 20) detail_muts = false;
+  if (total_diffs > 10) print_all = false;
+  
+  // Start moving through the difference combinations...
+  if (scan_combos) {
+    const int total_combos = 1 << total_diffs;
+    cout << "  Scanning through " << total_combos << " combos." << endl;
+    
+    double * total_fitness = new double[total_diffs + 1];
+    double * total_sqr_fitness = new double[total_diffs + 1];
+    double * max_fitness = new double[total_diffs + 1];
+    cString * max_sequence = new cString[total_diffs + 1];
+    int * test_count = new int[total_diffs + 1];
+    for (int i = 0; i <= total_diffs; i++) {
+      total_fitness[i] = 0.0;
+      total_sqr_fitness[i] = 0.0;
+      max_fitness[i] = 0.0;
+      test_count[i] = 0;
+    }
+    
+    // Loop through all of the combos...
+    const int combo_step = total_combos / 79;
+    for (int combo_id = 0; combo_id < total_combos; combo_id++) {
+      if (combo_id % combo_step == 0) {
+        cout << '.';
+        cout.flush();
+      }
+      // Start at the first sequence and add needed changes...
+      cString test_sequence = first_seq;
+      int diff_count = 0;
+      for (int mut_id = 0; mut_id < total_diffs; mut_id++) {
+        if ((combo_id >> mut_id) & 1) {
+          const int cur_pos = mut_positions[mut_id];
+          test_sequence[cur_pos] = last_seq.GetData()[cur_pos];
+          diff_count++;
+        }
+      }
+      
+      // Determine the fitness of the current sequence...
+      cGenome test_genome(test_sequence);
+      cCPUTestInfo test_info;
+      test_info.TestThreads();
+      cTestCPU::TestGenome(test_info, test_genome);
+      const double fitness = test_info.GetGenotypeFitness();
+      
+      //cAnalyzeGenotype test_genotype(test_sequence);
+      //test_genotype.Recalculate();
+      //const double fitness = test_genotype.GetFitness();
+      
+      total_fitness[diff_count] += fitness;
+      total_sqr_fitness[diff_count] += fitness * fitness;
+      if (fitness > max_fitness[diff_count]) {
+        max_fitness[diff_count] = fitness;
+        max_sequence[diff_count] = test_sequence;
+        //  	cout << endl
+        //  	     << max_sequence[diff_count] << " "
+        //  	     << test_info.GetGenotypeMerit() << " "
+        //  	     << fitness << " "
+        //  	     << combo_id << endl;
+      }
+      test_count[diff_count]++;
+    }
+    
+    // Output the results...
+    
+    for (int i = 0; i <= total_diffs; i++) {
+      cAnalyzeGenotype max_genotype(max_sequence[i], inst_set);
+      max_genotype.Recalculate();
+      fp << i                                         << " "  //  1
+        << test_count[i]                             << " "  //  2
+        << total_fitness[i] / (double) test_count[i] << " "  //  3
+        << max_fitness[i]                            << " "  //  4
+        << max_genotype.GetMerit()                   << " "  //  5
+        << max_genotype.GetGestTime()                << " "  //  6
+        << max_genotype.GetLength()                  << " "  //  7
+        << max_genotype.GetCopyLength()              << " "  //  8
+        << max_genotype.GetExeLength()               << " "; //  9
+      max_genotype.PrintTasks(fp, 3,12);
+      fp << max_sequence[i] << endl;
+    }
+    
+    // Cleanup
+    delete [] total_fitness;
+    delete [] total_sqr_fitness;
+    delete [] max_fitness;
+    delete [] max_sequence;
+    delete [] test_count;
+  }
+  // If we can't scan through all combos, give wanring.
+  else {
+    cerr << "  Warning: too many mutations (" << total_diffs
+    << ") to scan through combos." << endl;
+  }
+  
+  
+  // Cleanup...
+  delete [] sequences;
+  delete [] mut_count;
+  delete [] mut_positions;
+}
+
+void cAnalyze::AnalyzeInstructions(cString cur_string)
+{
+  if (verbose == true) {
+    cout << "Analyzing Instructions in batch " << cur_batch << endl;
+  }
+  else cout << "Analyzeing Instructions..." << endl;
+  
+  // Load in the variables...
+  cString filename("inst_analyze.dat");
+  if (cur_string.GetSize() != 0) filename = cur_string.PopWord();
+  const int num_insts = inst_set.GetSize();
+  
+  // Setup the file...
+  ofstream fp(filename);
+  
+  // Determine the file type...
+  int file_type = FILE_TYPE_TEXT;
+  while (filename.Find('.') != -1) filename.Pop('.');
+  if (filename == "html") file_type = FILE_TYPE_HTML;
+  
+  // If we're in HTML mode, setup the header...
+  if (file_type == FILE_TYPE_HTML) {
+    // Document header...
+    fp << "<html>" << endl
+    << "<body bgcolor=\"#FFFFFF\"" << endl
+    << " text=\"#000000\"" << endl
+    << " link=\"#0000AA\"" << endl
+    << " alink=\"#0000FF\"" << endl
+    << " vlink=\"#000044\">" << endl
+    << endl
+    << "<h1 align=center>Instruction Chart: "
+    << batch[cur_batch].Name() << endl
+    << "<br><br>" << endl
+    << endl;
+    
+    // Instruction key...
+    const int num_cols = 6;
+    const int num_rows = ((num_insts - 1) / num_cols) + 1;
+    fp << "<table border=2 cellpadding=3>" << endl
+      << "<tr bgcolor=\"#AAAAFF\"><th colspan=6>Instruction Set Legend</tr>"
+      << endl;
+    for (int i = 0; i < num_rows; i++) {
+      fp << "<tr>";
+      for (int j = 0; j < num_cols; j++) {
+        const int inst_id = i + j * num_rows;
+        if (inst_id < num_insts) {
+          cInstruction cur_inst(inst_id);
+          fp << "<td><b>" << cur_inst.GetSymbol() << "</b> : "
+            << inst_set.GetName(inst_id) << " ";
+        }
+        else {
+          fp << "<td>&nbsp; ";
+        }
+      }
+      fp << "</tr>" << endl;
+    }
+    fp << "</table>" << endl
+      << "<br><br><br>" << endl;
+    
+    // Main table header...
+    fp << "<center>" << endl
+      << "<table border=1 cellpadding=2>" << endl
+      << "<tr><th bgcolor=\"#AAAAFF\">Run # <th bgcolor=\"#AAAAFF\">Length"
+      << endl;
+    for (int i = 0; i < num_insts; i++) {
+      cInstruction cur_inst(i);
+      fp << "<th bgcolor=\"#AAAAFF\">" << cur_inst.GetSymbol() << " ";
+    }
+    fp << "</tr>" << endl;
+  }
+  else { // if (file_type == FILE_TYPE_TEXT) {
+    fp << "#RUN_NAME  LENGTH  ";
+    for (int i = 0; i < num_insts; i++) {
+      cInstruction cur_inst(i);
+      fp << cur_inst.GetSymbol() << ":" << inst_set.GetName(i) << " ";
+    }
+    fp << endl;
+  }
+  
+  // Figure out how often we expect each instruction to appear...
+  const double exp_freq = 1.0 / (double) num_insts;
+  const double min_freq = exp_freq * 0.5;
+  const double max_freq = exp_freq * 2.0;
+  
+  double total_length = 0.0;
+  tArray<double> total_freq(num_insts);
+  for (int i = 0; i < num_insts; i++) total_freq[i] = 0.0;
+  
+  // Loop through all of the genotypes in this batch...
+  tListIterator<cAnalyzeGenotype> batch_it(batch[cur_batch].List());
+  cAnalyzeGenotype * genotype = NULL;
+  while ((genotype = batch_it.Next()) != NULL) {
+    // Setup for counting...
+    tArray<int> inst_bin(num_insts);
+    for (int i = 0; i < num_insts; i++) inst_bin[i] = 0;
+    
+    // Count it up!
+    const int genome_size = genotype->GetLength();
+    for (int i = 0; i < genome_size; i++) {
+      const int inst_id = genotype->GetGenome()[i].GetOp();
+      inst_bin[inst_id]++;
+    }
+    
+    // Print it out...
+    if (file_type == FILE_TYPE_HTML) fp << "<tr><th>";
+    fp << genotype->GetName() << " ";
+    if (file_type == FILE_TYPE_HTML) fp << "<td align=center>";
+    total_length += genome_size;
+    fp << genome_size << " ";
+    for (int i = 0; i < num_insts; i++) {
+      const double inst_freq = ((double) inst_bin[i]) / (double) genome_size;
+      total_freq[i] += inst_freq;
+      if (file_type == FILE_TYPE_HTML) {
+        if (inst_freq == 0.0) fp << "<td bgcolor=\"FFAAAA\">";
+        else if (inst_freq < min_freq) fp << "<td bgcolor=\"FFFFAA\">";
+        else if (inst_freq < max_freq) fp << "<td bgcolor=\"AAAAFF\">";
+        else fp << "<td bgcolor=\"AAFFAA\">";
+      }
+      fp << cStringUtil::Stringf("%04.3f", inst_freq) << " ";
+    }
+    if (file_type == FILE_TYPE_HTML) fp << "</tr>";
+    fp << endl;
+  }
+  
+  if (file_type == FILE_TYPE_HTML) {
+    int num_genomes = batch[cur_batch].List().GetSize();
+    fp << "<tr><th>Average <th>" << total_length / num_genomes << " ";
+    for (int i = 0; i < num_insts; i++) {
+      double inst_freq = total_freq[i] / num_genomes;
+      if (inst_freq == 0.0) fp << "<td bgcolor=\"FF0000\">";
+      else if (inst_freq < min_freq) fp << "<td bgcolor=\"FFFF00\">";
+      else if (inst_freq < max_freq) fp << "<td bgcolor=\"0000FF\">";
+      else fp << "<td bgcolor=\"00FF00\">";
+      fp << cStringUtil::Stringf("%04.3f", inst_freq) << " ";
+    }
+    fp << "</tr>" << endl
+      << "</table></center>" << endl;
+  }
+  }
+
+void cAnalyze::AnalyzeInstPop(cString cur_string)
+{
+  if (verbose == true) {
+    cout << "Analyzing Instructions in batch " << cur_batch << endl;
+  }
+  else cout << "Analyzeing Instructions..." << endl;
+  
+  // Load in the variables...
+  cString filename("inst_analyze.dat");
+  if (cur_string.GetSize() != 0) filename = cur_string.PopWord();
+  const int num_insts = inst_set.GetSize();
+  
+  // Setup the file...
+  ofstream fp(filename);
+  
+  for (int i = 0; i < num_insts; i++) {
+    cInstruction cur_inst(i);
+    fp << cur_inst.GetSymbol() << ":" << inst_set.GetName(i) << " ";
+  }
+  fp << endl;
+  
+  double total_length = 0.0;
+  tArray<double> total_freq(num_insts);
+  for (int i = 0; i < num_insts; i++) total_freq[i] = 0.0;
+  int num_orgs = 0; 
+  
+  // Loop through all of the genotypes in this batch...
+  tListIterator<cAnalyzeGenotype> batch_it(batch[cur_batch].List());
+  cAnalyzeGenotype * genotype = NULL;
+  while ((genotype = batch_it.Next()) != NULL) {
+    
+    num_orgs++; 
+    
+    // Setup for counting...
+    tArray<int> inst_bin(num_insts);
+    for (int i = 0; i < num_insts; i++) inst_bin[i] = 0;
+    
+    // Count it up!
+    const int genome_size = genotype->GetLength();
+    for (int i = 0; i < genome_size; i++) {
+      const int inst_id = genotype->GetGenome()[i].GetOp();
+      inst_bin[inst_id]++;
+    }
+    total_length += genome_size;
+    for (int i = 0; i < num_insts; i++) {
+      const double inst_freq = ((double) inst_bin[i]) / (double) genome_size;
+      total_freq[i] += inst_freq;
+    }
+  }
+  // Print it out...
+  //    fp << total_length/num_orgs  << " ";
+  for (int i = 0; i < num_insts; i++) {
+    fp << cStringUtil::Stringf("%04.3f", total_freq[i]/num_orgs) << " ";
+  }
+  fp << endl;
+  
+}
+
+void cAnalyze::AnalyzeBranching(cString cur_string)
+{
+  if (verbose == true) {
+    cout << "Analyzing branching patterns in batch " << cur_batch << endl;
+  }
+  else cout << "Analyzeing Branches..." << endl;
+  
+  // Load in the variables...
+  cString filename("branch_analyze.dat");
+  if (cur_string.GetSize() != 0) filename = cur_string.PopWord();
+  
+  // Setup the file...
+  ofstream fp(filename);
+  
+  // UNFINISHED!
+  // const int num_insts = inst_set.GetSize();
+}
+
+void cAnalyze::AnalyzeMutationTraceback(cString cur_string)
+{
+  if (verbose == true) {
+    cout << "Analyzing mutation traceback in batch " << cur_batch << endl;
+  }
+  else cout << "Analyzing mutation traceback..." << endl;
+  
+  // This works best on lineages, so warn if we don't have one.
+  if (batch[cur_batch].IsLineage() == false && verbose == true) {
+    cerr << "  Warning: trying to traceback mutations outside of lineage."
+    << endl;
+  }
+  
+  if (batch[cur_batch].List().GetSize() == 0) {
+    cerr << "Error: Trying to traceback mutations with no genotypes in batch."
+    << endl;
+    return;
+  }
+  
+  // Make sure all genotypes are the same length.
+  int size = -1;
+  tListIterator<cAnalyzeGenotype> batch_it(batch[cur_batch].List());
+  cAnalyzeGenotype * genotype = NULL;
+  while ((genotype = batch_it.Next()) != NULL) {
+    if (size == -1) size = genotype->GetLength();
+    if (size != genotype->GetLength()) {
+      cerr << "  Error: Trying to traceback mutations in genotypes of differing lengths." << endl;
+      cerr << "  Aborting." << endl;
+      return;
+    }
+  }
+  
+  // Setup variables...
+  cString filename("analyze_traceback.dat");
+  if (cur_string.GetSize() != 0) filename = cur_string.PopWord();
+  
+  // Setup a genome to store the previous values before mutations.
+  tArray<int> prev_inst(size);
+  prev_inst.SetAll(-1);  // -1 indicates never changed.
+  
+  // Open the output file...
+  ofstream fp(filename);
+  
+  // Loop through all of the genotypes again, testing mutation reversions.
+  cAnalyzeGenotype * prev_genotype = batch_it.Next();
+  while ((genotype = batch_it.Next()) != NULL) {
+    continue;
+    // Check to see if any sites have changed...
+    for (int i = 0; i < size; i++) {
+      if (genotype->GetGenome()[i] != prev_genotype->GetGenome()[i]) {
+        prev_inst[i] = prev_genotype->GetGenome()[i].GetOp();
+      }
+    }
+    
+    // Next, determine the fraction of mutations that are currently adaptive.
+    int num_beneficial = 0;
+    int num_neutral = 0;
+    int num_detrimental = 0;
+    int num_static = 0;      // Sites that were never mutated.
+    
+    cGenome test_genome = genotype->GetGenome();
+    cCPUTestInfo test_info;
+    cTestCPU::TestGenome(test_info, test_genome);
+    const double base_fitness = test_info.GetGenotypeFitness();
+    
+    for (int i = 0; i < size; i++) {
+      if (prev_inst[i] == -1) num_static++;
+      else {
+        test_genome[i].SetOp(prev_inst[i]);
+        cTestCPU::TestGenome(test_info, test_genome);
+        const double cur_fitness = test_info.GetGenotypeFitness();
+        if (cur_fitness > base_fitness) num_detrimental++;
+        else if (cur_fitness < base_fitness) num_beneficial++;
+        else num_neutral++;
+        test_genome[i] = genotype->GetGenome()[i];
+      }      
+    }
+    
+    fp << genotype->GetDepth() << " "
+      << num_beneficial << " "
+      << num_neutral << " "
+      << num_detrimental << " "
+      << num_static << " "
+      << endl;
+    
+    prev_genotype = genotype;
+  }
+}
+
+void cAnalyze::AnalyzeComplexity(cString cur_string)
+{
+  cout << "Analyzing genome complexity..." << endl;
+  
+  // Load in the variables...
+  // This command requires at least on arguement
+  int words = cur_string.CountNumWords();
+  if(words < 1) {
+    cout << "AnalyzeComplexity has no parameters, skipping." << endl;
+    return;
+  }
+  
+  // Get the mutation rate arguement
+  double mut_rate = cur_string.PopWord().AsDouble();
+  
+  // Create the directory using the string given as the second arguement
+  cString dir = cur_string.PopWord();
+  cString defaultDirectory = "complexity/";
+  cString directory = PopDirectory(dir, defaultDirectory);
+  
+  // Default for usage of resources is false
+  int useResources = 0;
+  // resource usage flag is an optional arguement, but is always the 3rd arg
+  if(words >= 3) {
+    useResources = cur_string.PopWord().AsInt();
+    // All non-zero values are considered false
+    if(useResources != 0 && useResources != 1) {
+      useResources = 0;
+    }
+  }
+  
+  // Batch frequency begins with the first organism, but then skips that 
+  // amount ahead in the batch.  It defaults to 1, so that default analyzes
+  // all the organisms in the batch.  It is always the 4th arg.
+  int batchFrequency = 1;
+  if(words == 4) {
+    batchFrequency = cur_string.PopWord().AsInt();
+    if(batchFrequency <= 0) {
+      batchFrequency = 1;
+    }
+  }
+  
+  // These are used to backup the state of the environment and resource_count
+  // for the test cpu, and will be reset to their original values at the end
+  bool backupUsage;
+  tArray<double> backupResources;
+  
+  if(useResources) {
+    // Backup test cpu data
+    backupUsage = cTestCPU::UseResources();
+    backupResources = cTestCPU::GetResources();
+    
+    cTestCPU::UseResources() = true;
+  }
+  
+  ///////////////////////////////////////////////////////
+  // Loop through all of the genotypes in this batch...
+  
+  tListIterator<cAnalyzeGenotype> batch_it(batch[cur_batch].List());
+  cAnalyzeGenotype * genotype = NULL;
+  
+  
+  bool islineage = false;
+  cString lineage_filename;
+  ofstream lineage_fp;
+  ofstream non_lineage_fp;
+  if (batch[cur_batch].IsLineage() == true) {
+    lineage_filename.Set("%s%s.complexity.dat", directory(), "lineage");
+    lineage_fp.open(lineage_filename);
+    islineage = true;
+  } else {
+    cString non_lineage_file;
+    non_lineage_file.Set("%s%s.complexity.dat", directory(), "nonlineage");
+    non_lineage_fp.open(non_lineage_file);
+    islineage = false;
+  }
+  
+  while ((genotype = batch_it.Next()) != NULL) {
+    if (verbose == true) {
+      cout << "  Analyzing complexity for " << genotype->GetName() << endl;
+    }
+    
+    // Construct this filename...
+    cString filename;
+    filename.Set("%s%s.complexity.dat", directory(), genotype->GetName()());
+    ofstream fp(filename());
+    if (islineage) {
+      lineage_fp << genotype->GetID() << " ";
+    } else {
+      non_lineage_fp << genotype->GetID() << " ";
+    }
+    
+    int updateBorn = -1;
+    if(useResources) {
+      updateBorn = genotype->GetUpdateBorn();
+      FillResources(updateBorn);
+    }
+    
+    // Calculate the stats for the genotype we're working with ...
+    genotype->Recalculate();
+    cout << genotype->GetFitness() << endl;
+    const int num_insts = inst_set.GetSize();
+    const int max_line = genotype->GetLength();
+    const cGenome & base_genome = genotype->GetGenome();
+    cGenome mod_genome(base_genome);
+    
+    // Loop through all the lines of code, testing all mutations...
+    tArray<double> test_fitness(num_insts);
+    tArray<double> prob(num_insts);
+    for (int line_num = 0; line_num < max_line; line_num++) {
+      int cur_inst = base_genome[line_num].GetOp();
+      //char cur_symbol = base_genome[line_num].GetSymbol();
+      
+      // Column 1 ... the original instruction in the genome.
+      fp << cur_inst << " ";
+      
+      // Test fitness of each mutant.
+      for (int mod_inst = 0; mod_inst < num_insts; mod_inst++) {
+        mod_genome[line_num].SetOp(mod_inst);
+        cAnalyzeGenotype test_genotype(mod_genome, inst_set);
+        test_genotype.Recalculate();
+        test_fitness[mod_inst] = test_genotype.GetFitness();
+      }
+      
+      // Ajust fitness
+      double cur_inst_fitness = test_fitness[cur_inst];
+      for (int mod_inst = 0; mod_inst < num_insts; mod_inst++) {
+        if (test_fitness[mod_inst] > cur_inst_fitness)
+          test_fitness[mod_inst] = cur_inst_fitness;
+        test_fitness[mod_inst] = test_fitness[mod_inst] / cur_inst_fitness;
+      }
+      
+      // Calculate probabilities at mut-sel balance
+      double w_bar = 1;
+      
+      // Normalize fitness values, assert if they are all zero
+      double maxFitness = 0.0;
+      for(int i=0; i<num_insts; i++) {
+        if(test_fitness[i] > maxFitness) {
+          maxFitness = test_fitness[i];
+        }
+      }
+      
+      if(maxFitness > 0) {
+        for(int i=0; i<num_insts; i++) {
+          test_fitness[i] /= maxFitness;
+        }
+      } else {
+        fp << "All zero fitness, ERROR." << endl;
+        continue;
+      }
+      
+      while(1) {
+        double sum = 0.0;
+        for (int mod_inst = 0; mod_inst < num_insts; mod_inst ++) {
+          prob[mod_inst] = (mut_rate * w_bar) /
+          ((double)num_insts * (w_bar + test_fitness[mod_inst] * mut_rate - test_fitness[mod_inst]));
+          sum = sum + prob[mod_inst];
+        }
+        if ((sum-1.0)*(sum-1.0) <= 0.0001) 
+          break;
+        else
+          w_bar = w_bar - 0.000001;
+      }
+      // Write probability
+      for (int mod_inst = 0; mod_inst < num_insts; mod_inst ++) {
+        fp << prob[mod_inst] << " ";
+      }
+      
+      // Calculate complexity
+      double entropy = 0;
+      for (int i = 0; i < num_insts; i ++) {
+        entropy += prob[i] * log((double) 1.0/prob[i]) / log ((double) num_insts);
+      }
+      double complexity = 1 - entropy;
+      fp << complexity << endl;
+      
+      if (islineage) {
+        lineage_fp << complexity << " ";
+      } else {
+        non_lineage_fp << complexity << " ";
+      }
+      
+      // Reset the mod_genome back to the original sequence.
+      mod_genome[line_num].SetOp(cur_inst);
+    }
+    fp.close();
+    if (islineage) {
+      lineage_fp << endl;
+    } else {
+      non_lineage_fp << endl;
+    }
+    
+    // Always grabs the first one
+    // Skip i-1 times, so that the beginning of the loop will grab the ith one
+    // where i is the batchFrequency
+    for(int count=0; genotype != NULL && count < batchFrequency - 1; count++) {
+      genotype = batch_it.Next();
+      if(genotype != NULL && verbose == true) {
+        cout << "Skipping: " << genotype->GetName() << endl;
+      }
+    }
+    if(genotype == NULL) { break; }
+  }
+  if (islineage) {
+    lineage_fp.close();
+  } else {
+    non_lineage_fp.close();
+  }
+  
+  if(useResources) {
+    // Set the test cpu back to the state it was in before we messed with it
+    cTestCPU::UseResources() = backupUsage;
+    cTestCPU::SetupResourceArray(backupResources);
+  }
+  
+  return;
+}
+
+void cAnalyze::AnalyzePopComplexity(cString cur_string)
+{
+  cout << "Analyzing population complexity ..." << endl;
+  
+  // Load in the variables...
+  //int batch_size = cur_string.PopWord().AsInt();
+  //int sample_size = cur_string.PopWord().AsInt();
+  cString directory = PopDirectory(cur_string, "pop_complexity/");
+  cString file = cur_string;
+  
+  // Get sample index...
+  /*if (sample_size > batch_size) {
+    cout << " Sample size is greater than batch size." << endl;
+  return;
+  }
+int *index_array;
+int *flag_array;
+index_array = (int*) malloc (batch_size*sizeof(int));
+flag_array = (int*) malloc (batch_size*sizeof(int));
+for (int i=0; i<batch_size; i++) {
+  index_array[i] = i;
+  flag_array[i] = 0;
+}
+int max_num = batch_size;
+cRandom random;
+for (int i=0; i<sample_size; i++) {
+  int index = random.GetUInt(max_num);
+  flag_array[index_array[index]] = 1;
+  index_array[index] = index_array[max_num-1];
+  max_num--;
+}*/
+  
+  // Construct filename...
+  cString filename;
+  filename.Set("%spop%s.complexity.dat", directory(), file());
+  ofstream fp(filename());
+  
+  //////////////////////////////////////////////////////////
+  // Loop through all of the genotypes in this batch ...
+  
+  tListIterator<cAnalyzeGenotype> batch_it(batch[cur_batch].List());
+  cAnalyzeGenotype * genotype = NULL;
+  
+  
+  genotype = batch_it.Next();
+  
+  
+  if (genotype == NULL) return;
+  int seq_length = genotype->GetLength();
+  const int num_insts = inst_set.GetSize();
+  tMatrix<int> inst_stat(seq_length, num_insts);
+  
+  // Initializing inst_stat ...
+  for (int line_num = 0; line_num < seq_length; line_num ++) 
+    for (int inst_num = 0; inst_num < num_insts; inst_num ++) 
+      inst_stat(line_num, inst_num) = 0;
+
+  int num_cpus = 0;
+  int actural_samples = 0;
+  while (genotype != NULL) {
+    num_cpus = genotype->GetNumCPUs();
+    const cGenome & base_genome = genotype->GetGenome();
+    for (int i=0; i<num_cpus; i++) {   // Stat on every organism with same genotype.
+                                       //if (flag_array[organism_index] == 0) {
+                                       //organism_index++;
+                                       //continue;
+                                       //}
+      for (int line_num = 0; line_num < seq_length; line_num ++) {
+        int cur_inst = base_genome[line_num].GetOp();
+        inst_stat(line_num, cur_inst) ++;
+      }
+      //organism_index++;
+      actural_samples++;
+    }
+    genotype = batch_it.Next();
+  }
+
+
+
+// Calculate complexity
+for (int line_num = 0; line_num < seq_length; line_num ++) {
+  double entropy = 0.0;
+  for (int inst_num = 0; inst_num < num_insts; inst_num ++) {
+    if (inst_stat(line_num, inst_num) == 0) continue;
+    float prob = (float) (inst_stat(line_num, inst_num)) / (float) (actural_samples);
+    entropy += prob * log((double) 1.0/prob) / log((double) num_insts);
+  }
+  double complexity = 1 - entropy;
+  fp << complexity << " ";
+};
+fp << endl;
+fp.close();
+//free(index_array);
+//free(flag_array);
+return;
+}
+
+
+void cAnalyze::EnvironmentSetup(cString cur_string)
+{
+  cout << "Running environment command: " << endl
+  << "  " << cur_string << endl;
+  
+  cTestCPU::GetEnvironment()->LoadLine(cur_string);
+}
+
+
+void cAnalyze::CommandHelpfile(cString cur_string)
+{
+  cout << "Printing helpfiles in: " << cur_string << endl;
+  
+  cHelpManager help_control;
+  if (verbose == true) help_control.SetVerbose();
+  while (cur_string.GetSize() > 0) {
+    help_control.LoadFile(cur_string.PopWord());
+  }
+  
+  help_control.PrintHTML();
+}
+
+void cAnalyze::CommandDocfile(cString cur_string)
+{
+  cout << "Printing documentation files in: " << cur_string << endl;
+  
+  cHelpManager help_control;
+  if (verbose == true) help_control.SetVerbose();
+  while (cur_string.GetSize() > 0) {
+    help_control.LoadFile(cur_string.PopWord());
+  }
+  
+  help_control.PrintHTML();
+}
+
+
+
+//////////////// Control...
+
+void cAnalyze::VarSet(cString cur_string)
+{
+  cString var = cur_string.PopWord();
+  
+  if (cur_string.GetSize() == 0) {
+    cerr << "Error: No variable provided in SET command" << endl;
+    return;
+  }
+  
+  cString & cur_variable = GetVariable(var);
+  cur_variable = cur_string.PopWord();
+  
+  if (verbose == true) {
+    cout << "Setting " << var << " to " << cur_variable << endl;
+  }
+}
+
+void cAnalyze::BatchSet(cString cur_string)
+{
+  int next_batch = 0;
+  if (cur_string.CountNumWords() > 0) {
+    next_batch = cur_string.PopWord().AsInt();
+  }
+  if (verbose) cout << "Setting current batch to " << next_batch << endl;
+  if (next_batch >= MAX_BATCHES) {
+    cerr << "  Error: max batches is " << MAX_BATCHES << endl;
+    exit(1);
+  } else {
+    cur_batch = next_batch;
+  }
+}
+
+void cAnalyze::BatchName(cString cur_string)
+{
+  if (cur_string.CountNumWords() == 0) {
+    if (verbose) cout << "  Warning: No name given in NAME_BATCH!" << endl;
+    return;
+  }
+  
+  batch[cur_batch].Name() = cur_string.PopWord();
+}
+
+void cAnalyze::BatchTag(cString cur_string)
+{
+  if (cur_string.CountNumWords() == 0) {
+    if (verbose) cout << "  Warning: No tag given in TAG_BATCH!" << endl;
+    return;
+  }
+  
+  if (verbose == true) {
+    cout << "Tagging batch " << cur_batch
+    << " with tag '" << cur_string << "'" << endl;
+  }
+  
+  tListIterator<cAnalyzeGenotype> batch_it(batch[cur_batch].List());
+  cAnalyzeGenotype * genotype = NULL;
+  while ((genotype = batch_it.Next()) != NULL) {
+    genotype->SetTag(cur_string);
+  }
+  
+}
+
+void cAnalyze::BatchPurge(cString cur_string)
+{
+  int batch_id = cur_batch;
+  if (cur_string.CountNumWords() > 0) batch_id = cur_string.PopWord().AsInt();
+  
+  if (verbose) cout << "Purging batch " << batch_id << endl;
+  
+  while (batch[batch_id].List().GetSize() > 0) {
+    delete batch[batch_id].List().Pop();
+  }
+  
+  batch[batch_id].SetLineage(false);
+  batch[batch_id].SetAligned(false);
+}
+
+void cAnalyze::BatchDuplicate(cString cur_string)
+{
+  if (cur_string.GetSize() == 0) {
+    cerr << "Duplicate Error: Must include from ID!" << endl;
+    exit(1);
+  }
+  int batch_from = cur_string.PopWord().AsInt();
+  
+  int batch_to = cur_batch;
+  if (cur_string.GetSize() > 0) batch_to = cur_string.PopWord().AsInt();
+  
+  if (verbose == true) {
+    cout << "Duplicating from batch " << batch_from
+    << " to batch " << batch_to << "." << endl;
+  }
+  
+  tListIterator<cAnalyzeGenotype> batch_from_it(batch[batch_from].List());
+  cAnalyzeGenotype * genotype = NULL;
+  while ((genotype = batch_from_it.Next()) != NULL) {
+    cAnalyzeGenotype * new_genotype = new cAnalyzeGenotype(*genotype);
+    batch[batch_to].List().PushRear(new_genotype);
+  }
+  
+  batch[batch_to].SetLineage(false);
+  batch[batch_to].SetAligned(false);
+}
+
+void cAnalyze::BatchRecalculate(cString cur_string)
+{
+  int words = cur_string.CountNumWords();
+  int useResources = 0;
+  int update = -1;
+  if(words >= 1) {
+    useResources = cur_string.PopWord().AsInt();
+    // All non-zero values are considered false
+    if(useResources != 0 && useResources != 1) {
+      useResources = 0;
+    }
+  }
+  if (words >= 2) {
+    update = cur_string.PopWord().AsInt();
+  }
+  
+  bool backupUsage;
+  tArray<double> backupResources;
+  
+  if(useResources) {
+    // Backup test cpu data
+    backupUsage = cTestCPU::UseResources();
+    backupResources = cTestCPU::GetResources();
+    
+    cTestCPU::UseResources() = true;
+  }
+  
+  if (verbose == true) {
+    cout << "Running batch " << cur_batch << " through test CPUs..." << endl;
+  } else cout << "Running through test CPUs..." << endl;
+  
+  if (verbose == true && batch[cur_batch].IsLineage() == false) {
+    cerr << "  Warning: batch may not be a linege; "
+    << "parent and ancestor distances may not be correct" << endl;
+  }
+  
+  if (useResources && update > -1) {
+    FillResources(update);
+  }
+
+  tListIterator<cAnalyzeGenotype> batch_it(batch[cur_batch].List());
+  cAnalyzeGenotype * genotype = NULL;
+  cAnalyzeGenotype * last_genotype = NULL;
+  while ((genotype = batch_it.Next()) != NULL) {
+    
+    // If use resources, load proper resource according to update_born
+    if(useResources && update == -1) {
+      int updateBorn = -1;
+      updateBorn = genotype->GetUpdateBorn();
+      FillResources(updateBorn);
+    }
+    
+    // If the previous genotype was the parent of this one, pass in a pointer
+    // to it for improved recalculate (such as distance to parent, etc.)
+//     if (verbose == true) {
+//       PrintTestCPUResources("");
+//     }
+    if (last_genotype != NULL &&
+        genotype->GetParentID() == last_genotype->GetID()) {
+      genotype->Recalculate(last_genotype);
+    }
+    else genotype->Recalculate();
+    last_genotype = genotype;
+  }
+  
+  if(useResources) {
+    // Set the test cpu back to the state it was in before we messed with it
+    cTestCPU::UseResources() = backupUsage;
+    cTestCPU::SetupResourceArray(backupResources);
+  }
+  
+  return;
+}
+
+void cAnalyze::BatchRename(cString cur_string)
+{
+  if (verbose == false) cout << "Renaming organisms..." << endl;
+  else cout << "Renaming organisms in batch " << cur_batch << endl;
+  
+  // If a number is given with rename, start at that number...
+  
+  int id_num = cur_string.PopWord().AsInt();
+  tListIterator<cAnalyzeGenotype> batch_it(batch[cur_batch].List());
+  cAnalyzeGenotype * genotype = NULL;
+  while ((genotype = batch_it.Next()) != NULL) {
+    cString name = cStringUtil::Stringf("org-%d", id_num);
+    genotype->SetID(id_num);
+    genotype->SetName(name);
+    id_num++;
+  }
+}
+
+void cAnalyze::PrintStatus(cString cur_string)
+{
+  // No Args needed...
+  (void) cur_string;
+  
+  cout << "Status Report:" << endl;
+  for (int i = 0; i < MAX_BATCHES; i++) {
+    if (i == cur_batch || batch[i].List().GetSize() > 0) {
+      cout << "  Batch " << i << " -- "
+      << batch[i].List().GetSize() << " genotypes.";
+      if (i == cur_batch) cout << "  <current>";
+      if (batch[i].IsLineage() == true) cout << "  <lineage>";
+      if (batch[i].IsAligned() == true) cout << "  <aligned>";
+      
+      cout << endl;
+    }
+  }
+}
+
+void cAnalyze::PrintDebug(cString cur_string)
+{
+  cerr << "Debug Args: " << cur_string << endl;
+}
+
+void cAnalyze::ToggleVerbose(cString cur_string)
+{
+  // No Args needed...
+  (void) cur_string;
+  
+  if (verbose == false) {
+    cout << "Using verbose log messages..." << endl;
+    verbose = true;
+  } else {
+    cout << "Using non-verbose log messages..." << endl;
+    verbose = false;
+  }
+}
+
+void cAnalyze::IncludeFile(cString cur_string)
+{
+  while (cur_string.GetSize() > 0) {
+    cString filename = cur_string.PopWord();
+    
+    cInitFile include_file(filename);
+    include_file.Load();
+    include_file.Compress();
+    include_file.Close();
+    
+    tList<cAnalyzeCommand> include_list;
+    LoadCommandList(include_file, include_list);
+    ProcessCommands(include_list);
+  }
+}
+
+void cAnalyze::CommandSystem(cString cur_string)
+{
+  cout << "Running System Command: " << cur_string << endl;
+  
+  system(cur_string());
+}
+
+void cAnalyze::CommandInteractive(cString cur_string)
+{
+  // No Args needed...
+  (void) cur_string;
+  
+  RunInteractive();
+}
+
+void cAnalyze::PrintTestCPUResources(cString cur_string)
+{
+  cout << "TestCPU is using resources: ";
+  cout << cTestCPU::UseResources() << endl;
+  cout << "Resources currently in TestCPU: ";
+  const tArray<double> &quantity = cTestCPU::GetResources();
+  for(int i=0; i<quantity.GetSize(); i++) {
+    cout << quantity.ElementAt(i) << " ";
+  }
+  cout << endl;
+  
+  return;
+}
+
+void cAnalyze::FunctionCreate(cString cur_string,
+                              tList<cAnalyzeCommand> & clist)
+{
+  int num_args = cur_string.CountNumWords();
+  if (num_args < 1) {
+    cerr << "Error: Must provide function name when creating function.";
+    exit(1);
+  }
+  
+  cString fun_name = cur_string.PopWord();
+  fun_name.ToUpper();
+  
+  if (FindAnalyzeCommandDef(fun_name) != NULL) {
+    cerr << "Error: Cannot create function '" << fun_name
+    << "'; already exists." << endl;
+    exit(1);
+  }
+  
+  if (verbose) cout << "Creating function: " << fun_name << endl;
+  
+  // Create the new function...
+  cAnalyzeFunction * new_function = new cAnalyzeFunction(fun_name);
+  while (clist.GetSize() > 0) {
+    new_function->GetCommandList()->PushRear(clist.Pop());
+  }
+  
+  // Save the function on the new list...
+  function_list.PushRear(new_function);
+}
+
+bool cAnalyze::FunctionRun(const cString & fun_name, cString args)
+{
+  if (verbose) {
+    cout << "Running function: " << fun_name << endl;
+    // << " with args: " << args << endl;
+  }
+  
+  // Find the function we're about to run...
+  cAnalyzeFunction * found_function = NULL;
+  tListIterator<cAnalyzeFunction> function_it(function_list);
+  while (function_it.Next() != NULL) {
+    if (function_it.Get()->GetName() == fun_name) {
+      found_function = function_it.Get();
+      break;
+    }
+  }
+  
+  // If we were unable to find the command we're looking for, return false.
+  if (found_function == NULL) return false;
+  
+  // Back up the local variables
+  cString backup_arg_vars[10];
+  cString backup_local_vars[26];
+  for (int i = 0; i < 10; i++) backup_arg_vars[i] = arg_variables[i];
+  for (int i = 0; i < 26; i++) backup_local_vars[i] = local_variables[i];
+  
+  // Set the arg variables to the passed-in args...
+  arg_variables[0] = fun_name;
+  for (int i = 1; i < 10; i++) arg_variables[i] = args.PopWord();
+  for (int i = 0; i < 26; i++) local_variables[i] = "";
+  
+  ProcessCommands(*(found_function->GetCommandList()));
+  
+  // Restore the local variables
+  for (int i = 0; i < 10; i++) arg_variables[i] = backup_arg_vars[i];
+  for (int i = 0; i < 26; i++) local_variables[i] = backup_local_vars[i];
+  
+  return true;
+}
+
+
+int cAnalyze::BatchUtil_GetMaxLength(int batch_id)
+{
+  if (batch_id < 0) batch_id = cur_batch;
+  
+  int max_length = 0;
+  
+  tListIterator<cAnalyzeGenotype> batch_it(batch[batch_id].List());
+  cAnalyzeGenotype * genotype = NULL;
+  while ((genotype = batch_it.Next()) != NULL) {
+    if (genotype->GetLength() > max_length) max_length = genotype->GetLength();
+  }
+  
+  return max_length;
+}
+
+
+void cAnalyze::CommandForeach(cString cur_string,
+                              tList<cAnalyzeCommand> & clist)
+{
+  if (verbose) cout << "Initiating Foreach loop..." << endl;
+  
+  cString var = cur_string.PopWord();
+  int num_args = cur_string.CountNumWords();
+  
+  cString & cur_variable = GetVariable(var);
+  
+  for (int i = 0; i < num_args; i++) {
+    cur_variable = cur_string.PopWord();
+    
+    if (verbose == true) {
+      cout << "Foreach: setting " << var << " to " << cur_variable << endl;
+    }
+    ProcessCommands(clist);
+  }
+  
+  if (verbose == true) {
+    cout << "Ending Foreach on " << var << endl;
+  }
+}
+
+
+void cAnalyze::CommandForRange(cString cur_string,
+                               tList<cAnalyzeCommand> & clist)
+{
+  if (verbose) cout << "Initiating FORRANGE loop..." << endl;
+  
+  int num_args = cur_string.CountNumWords();
+  if (num_args < 3) {
+    cerr << "  Error: Must give variable, min and max with FORRANGE!"
+    << endl;
+    exit(1);
+  }
+  
+  cString var = cur_string.PopWord();
+  double min_val = cur_string.PopWord().AsDouble();
+  double max_val = cur_string.PopWord().AsDouble();
+  double step_val = 1.0;
+  if (num_args >=4 ) step_val = cur_string.PopWord().AsDouble();
+  
+  cString & cur_variable = GetVariable(var);
+  
+  // Seperate out all ints from not all ints...
+  if (min_val == (double) ((int) min_val) &&
+      max_val == (double) ((int) max_val) &&
+      step_val == (double) ((int) step_val)) {
+    for (int i = (int) min_val; i <= (int) max_val; i += (int) step_val) {
+      cur_variable.Set("%d", i);
+      
+      if (verbose == true) {
+        cout << "FORRANGE: setting " << var << " to " << cur_variable << endl;
+      }
+      ProcessCommands(clist);
+    }
+  } else {
+    for (double i = min_val; i <= max_val; i += step_val) {
+      cur_variable.Set("%f", i);
+      
+      if (verbose == true) {
+        cout << "FORRANGE: setting " << var << " to " << cur_variable << endl;
+      }
+      ProcessCommands(clist);
+    }
+  }
+  
+  if (verbose == true) {
+    cout << "Ending FORRANGE on " << var << endl;
+  }
+}
+
+
+///////////////////  Private Methods ///////////////////////////
+
+cString cAnalyze::PopDirectory(cString & in_string,
+                               const cString & default_dir)
+{
+  // Determing the directory name
+  cString directory(default_dir);
+  if (in_string.GetSize() != 0) directory = in_string.PopWord();
+  
+  // Make sure the directory ends in a slash.  If not, add one.
+  int last_pos = directory.GetSize() - 1;
+  if (directory[last_pos] != '/' && directory[last_pos] != '\\') {
+    directory += '/';
+  }
+  
+  // Make sure the directory exists.
+  FILE *fp = fopen ( directory(), "r" );
+  if ( fp == 0 ){
+    if ( errno == ENOENT ){
+      cerr << "Directory '" << directory
+      << "' does not exist.  Creating..." << endl;
+      if ( mkdir( directory(), (S_IRWXU|S_IRWXG|S_IRWXO) ) )
+        cerr << " Error creating '" << directory << "'" << endl;
+    }
+    else cerr << " Error opening '" << directory << "'" << endl;
+  }
+  
+  return directory;
+}
+
+int cAnalyze::PopBatch(const cString & in_string)
+{
+  int batch = cur_batch;
+  if (in_string.GetSize() != 0 && in_string != "current") {
+    batch = in_string.AsInt();
+  }
+  
+  return batch;
+}
+
+cAnalyzeGenotype * cAnalyze::PopGenotype(cString gen_desc, int batch_id)
+{
+  if (batch_id == -1) batch_id = cur_batch;
+  tListPlus<cAnalyzeGenotype> & gen_list = batch[batch_id].List();
+  gen_desc.ToLower();
+  
+  cAnalyzeGenotype * found_gen = NULL;
+  if (gen_desc == "num_cpus")
+    found_gen = gen_list.PopIntMax(&cAnalyzeGenotype::GetNumCPUs);
+  else if (gen_desc == "total_cpus")
+    found_gen = gen_list.PopIntMax(&cAnalyzeGenotype::GetTotalCPUs);
+  else if (gen_desc == "merit")
+    found_gen = gen_list.PopDoubleMax(&cAnalyzeGenotype::GetMerit);
+  else if (gen_desc == "fitness")
+    found_gen = gen_list.PopDoubleMax(&cAnalyzeGenotype::GetFitness);
+  else if (gen_desc.IsNumeric(0))
+    found_gen = gen_list.PopIntValue(&cAnalyzeGenotype::GetID,
+                                     gen_desc.AsInt());
+  else if (gen_desc == "random") {
+    int gen_pos = random.GetUInt(gen_list.GetSize());
+    found_gen = gen_list.PopPos(gen_pos);
+  }
+  else {
+    cout << "  Error: unknown type " << gen_desc << endl;
+    exit(1);
+  }
+  
+  return found_gen;
+}
+
+
+cString & cAnalyze::GetVariable(const cString & var)
+{
+  if (var.GetSize() != 1 ||
+      (var.IsLetter(0) == false && var.IsNumeric(0) == false)) {
+    cerr << "Error: Illegal variable " << var << " being used." << endl;
+    exit(1);
+  }
+  
+  if (var.IsLowerLetter(0) == true) {
+    int var_id = (int) (var[0] - 'a');
+    return variables[var_id];
+  }
+  else if (var.IsUpperLetter(0) == true) {
+    int var_id = (int) (var[0] - 'A');
+    return local_variables[var_id];
+  }
+  // Otherwise it must be a number...
+  int var_id = (int) (var[0] - '0');
+  return arg_variables[var_id];
+}
+
+
+void cAnalyze::LoadCommandList(cInitFile & init_file,
+                               tList<cAnalyzeCommand> & clist)
+{
+  while (init_file.GetLineNum() < init_file.GetNumLines()) {
+    cString cur_string = init_file.GetNextLine();
+    cString command = cur_string.PopWord();
+    command.ToUpper();
+    
+    cAnalyzeCommand * cur_command;
+    cAnalyzeCommandDefBase * command_def = FindAnalyzeCommandDef(command);
+    if (command == "END") {
+      // We are done with this section of code; break out...
+      break;
+    }
+    else if (command_def != NULL && command_def->IsFlowCommand() == true) {
+      // This code has a body to it... fill it out!
+      cur_command = new cAnalyzeFlowCommand(command, cur_string);
+      LoadCommandList( init_file, *(cur_command->GetCommandList()) );
+    }
+    else {
+      // This is a normal command...
+      cur_command = new cAnalyzeCommand(command, cur_string);
+    }
+    
+    clist.PushRear(cur_command);
+  }
+}
+
+void cAnalyze::InteractiveLoadCommandList(tList<cAnalyzeCommand> & clist)
+{
+  interactive_depth++;
+  char text_input[2048];
+  while (true) {
+    for (int i = 0; i <= interactive_depth; i++) {
+      cout << ">>";
+    }
+    cout << " ";
+    cout.flush();
+    cin.getline(text_input, 2048);
+    cString cur_input(text_input);
+    cString command = cur_input.PopWord();
+    command.ToUpper();
+    
+    cAnalyzeCommand * cur_command;
+    cAnalyzeCommandDefBase * command_def = FindAnalyzeCommandDef(command);
+    if (command == "END") {
+      // We are done with this section of code; break out...
+      break;
+    }
+    else if (command_def != NULL && command_def->IsFlowCommand() == true) {
+      // This code has a body to it... fill it out!
+      cur_command = new cAnalyzeFlowCommand(command, cur_input);
+      InteractiveLoadCommandList(*(cur_command->GetCommandList()));
+    }
+    else {
+      // This is a normal command...
+      cur_command = new cAnalyzeCommand(command, cur_input);
+    }
+    
+    clist.PushRear(cur_command);
+  }
+  interactive_depth--;
+}
+
+void cAnalyze::PreProcessArgs(cString & args)
+{
+  int pos = 0;
+  int search_start = 0;
+  while ((pos = args.Find('$', search_start)) != -1) {
+    // Setup the variable name that was found...
+    char varlet = args[pos+1];
+    cString varname("$");
+    varname += varlet;
+    
+    // Determine the variable and act on it.
+    int varsize = 0;
+    if (varlet == '$') {
+      args.Clip(pos+1, 1);
+      varsize = 1;
+    }
+    else if (varlet >= 'a' && varlet <= 'z') {
+      int var_id = (int) (varlet - 'a');
+      args.Replace(varname, variables[var_id], pos);
+      varsize = variables[var_id].GetSize();
+    }
+    else if (varlet >= 'A' && varlet <= 'Z') {
+      int var_id = (int) (varlet - 'A');
+      args.Replace(varname, local_variables[var_id], pos);
+      varsize = local_variables[var_id].GetSize();
+    }
+    else if (varlet >= '0' && varlet <= '9') {
+      int var_id = (int) (varlet - '0');
+      args.Replace(varname, arg_variables[var_id], pos);
+      varsize = arg_variables[var_id].GetSize();
+    }
+    search_start = pos + varsize;
+  }
+}
+
+void cAnalyze::ProcessCommands(tList<cAnalyzeCommand> & clist)
+{
+  // Process the command list...
+  tListIterator<cAnalyzeCommand> command_it(clist);
+  command_it.Reset();
+  cAnalyzeCommand * cur_command = NULL;
+  while ((cur_command = command_it.Next()) != NULL) {
+    cString command = cur_command->GetCommand();
+    cString args = cur_command->GetArgs();
+    PreProcessArgs(args);
+    
+    cAnalyzeCommandDefBase * command_fun = FindAnalyzeCommandDef(command);
+    
+    if (command_fun != NULL) command_fun->Run(this, args, *cur_command);
+    else if (FunctionRun(command, args) == true) {
+      // Found a defined function by this name.
+    }
+    else {
+      cerr << "Error: Unknown analysis keyword '" << command << "'." << endl;
+      exit(1);
+    }
+    
+  }
+}
+
+void cAnalyze::SetupGenotypeDataList()
+{
+  if (genotype_data_list.GetSize() != 0) return; // List already setup.
+  
+  genotype_data_list.PushRear(new tDataEntry<cAnalyzeGenotype, bool>
+                              ("viable",      "Is Viable (0/1)", &cAnalyzeGenotype::GetViable,
+                               &cAnalyzeGenotype::SetViable));
+  genotype_data_list.PushRear(new tDataEntry<cAnalyzeGenotype, int>
+                              ("id",          "Genome ID",       &cAnalyzeGenotype::GetID,
+                               &cAnalyzeGenotype::SetID));
+  genotype_data_list.PushRear(new tDataEntry<cAnalyzeGenotype, const cString &>
+                              ("tag",         "Genotype Tag",    &cAnalyzeGenotype::GetTag,
+                               &cAnalyzeGenotype::SetTag,
+                               &cAnalyzeGenotype::CompareNULL, "(none)", ""));
+  genotype_data_list.PushRear(new tDataEntry<cAnalyzeGenotype, int>
+                              ("parent_id",   "Parent ID",       &cAnalyzeGenotype::GetParentID,
+                               &cAnalyzeGenotype::SetParentID));
+  genotype_data_list.PushRear(new tDataEntry<cAnalyzeGenotype, int>
+                              ("parent2_id",  "Second Parent ID (for sexual genotypes)",
+                               &cAnalyzeGenotype::GetParent2ID, &cAnalyzeGenotype::SetParent2ID));
+  genotype_data_list.PushRear(new tDataEntry<cAnalyzeGenotype, int>
+                              ("parent_dist", "Parent Distance", &cAnalyzeGenotype::GetParentDist,
+                               &cAnalyzeGenotype::SetParentDist));
+  genotype_data_list.PushRear(new tDataEntry<cAnalyzeGenotype, int>
+                              ("ancestor_dist","Ancestor Distance",&cAnalyzeGenotype::GetAncestorDist,
+                               &cAnalyzeGenotype::SetAncestorDist));
+  genotype_data_list.PushRear(new tDataEntry<cAnalyzeGenotype, int>
+                              ("lineage", "Unique Lineage Label",&cAnalyzeGenotype::GetLineageLabel,
+                               &cAnalyzeGenotype::SetLineageLabel));
+  genotype_data_list.PushRear(new tDataEntry<cAnalyzeGenotype, int>
+                              ("num_cpus",    "Number of CPUs",  &cAnalyzeGenotype::GetNumCPUs,
+                               &cAnalyzeGenotype::SetNumCPUs));
+  genotype_data_list.PushRear(new tDataEntry<cAnalyzeGenotype, int>
+                              ("total_cpus",  "Total CPUs Ever", &cAnalyzeGenotype::GetTotalCPUs,
+                               &cAnalyzeGenotype::SetTotalCPUs));
+  genotype_data_list.PushRear(new tDataEntry<cAnalyzeGenotype, int>
+                              ("length",      "Genome Length",   &cAnalyzeGenotype::GetLength,
+                               &cAnalyzeGenotype::SetLength, &cAnalyzeGenotype::CompareLength));
+  genotype_data_list.PushRear(new tDataEntry<cAnalyzeGenotype, int>
+                              ("copy_length", "Copied Length",   &cAnalyzeGenotype::GetCopyLength,
+                               &cAnalyzeGenotype::SetCopyLength));
+  genotype_data_list.PushRear(new tDataEntry<cAnalyzeGenotype, int>
+                              ("exe_length",  "Executed Length", &cAnalyzeGenotype::GetExeLength,
+                               &cAnalyzeGenotype::SetExeLength));
+  genotype_data_list.PushRear(new tDataEntry<cAnalyzeGenotype, double>
+                              ("merit",       "Merit",           &cAnalyzeGenotype::GetMerit,
+                               &cAnalyzeGenotype::SetMerit, &cAnalyzeGenotype::CompareMerit));
+  genotype_data_list.PushRear(new tDataEntry<cAnalyzeGenotype, double>
+                              ("comp_merit",  "Computational Merit", &cAnalyzeGenotype::GetCompMerit,
+                               (void (cAnalyzeGenotype::*)(double)) NULL, &cAnalyzeGenotype::CompareCompMerit));
+  genotype_data_list.PushRear(new tDataEntry<cAnalyzeGenotype, double>
+                              ("comp_merit_ratio", "Computational Merit Ratio",
+                               &cAnalyzeGenotype::GetCompMeritRatio,
+                               (void (cAnalyzeGenotype::*)(double)) NULL,
+                               &cAnalyzeGenotype::CompareCompMerit));
+  genotype_data_list.PushRear(new tDataEntry<cAnalyzeGenotype, int>
+                              ("gest_time",   "Gestation Time",  &cAnalyzeGenotype::GetGestTime,
+                               &cAnalyzeGenotype::SetGestTime,
+                               &cAnalyzeGenotype::CompareGestTime, "Inf."));
+  genotype_data_list.PushRear(new tDataEntry<cAnalyzeGenotype, double>
+                              ("efficiency",  "Rep. Efficiency", &cAnalyzeGenotype::GetEfficiency,
+                               (void (cAnalyzeGenotype::*)(double)) NULL,
+                               &cAnalyzeGenotype::CompareEfficiency));
+  genotype_data_list.PushRear(new tDataEntry<cAnalyzeGenotype, double>
+                              ("efficiency_ratio", "Rep. Efficiency Ratio",
+                               &cAnalyzeGenotype::GetEfficiencyRatio,
+                               (void (cAnalyzeGenotype::*)(double)) NULL,
+                               &cAnalyzeGenotype::CompareEfficiency));
+  genotype_data_list.PushRear(new tDataEntry<cAnalyzeGenotype, double>
+                              ("fitness",     "Fitness",         &cAnalyzeGenotype::GetFitness,
+                               &cAnalyzeGenotype::SetFitness, &cAnalyzeGenotype::CompareFitness));
+  genotype_data_list.PushRear(new tDataEntry<cAnalyzeGenotype, double>
+                              ("div_type",     "Divide Type",    &cAnalyzeGenotype::GetDivType,
+                               &cAnalyzeGenotype::SetDivType));
+  genotype_data_list.PushRear(new tDataEntry<cAnalyzeGenotype, int>
+                              ("mate_id",     "Mate Selection ID Number",  &cAnalyzeGenotype::GetMateID,
+                               &cAnalyzeGenotype::SetMateID));
+  genotype_data_list.PushRear(new tDataEntry<cAnalyzeGenotype, double>
+                              ("fitness_ratio", "Fitness Ratio", &cAnalyzeGenotype::GetFitnessRatio,
+                               (void (cAnalyzeGenotype::*)(double)) NULL,
+                               &cAnalyzeGenotype::CompareFitness));
+  genotype_data_list.PushRear(new tDataEntry<cAnalyzeGenotype, int>
+                              ("update_born", "Update Born",     &cAnalyzeGenotype::GetUpdateBorn,
+                               &cAnalyzeGenotype::SetUpdateBorn));
+  genotype_data_list.PushRear(new tDataEntry<cAnalyzeGenotype, int>
+                              ("update_dead", "Update Dead",     &cAnalyzeGenotype::GetUpdateDead,
+                               &cAnalyzeGenotype::SetUpdateDead));
+  genotype_data_list.PushRear(new tDataEntry<cAnalyzeGenotype, int>
+                              ("depth",       "Tree Depth",      &cAnalyzeGenotype::GetDepth,
+                               &cAnalyzeGenotype::SetDepth));
+  genotype_data_list.PushRear(new tDataEntry<cAnalyzeGenotype, double>
+                              ("frac_dead",   "Fraction Mutations Lethal",
+                               &cAnalyzeGenotype::GetFracDead,
+                               (void (cAnalyzeGenotype::*)(double)) NULL));
+  genotype_data_list.PushRear(new tDataEntry<cAnalyzeGenotype, double>
+                              ("frac_neg",   "Fraction Mutations Detrimental",
+                               &cAnalyzeGenotype::GetFracNeg,
+                               (void (cAnalyzeGenotype::*)(double)) NULL));
+  genotype_data_list.PushRear(new tDataEntry<cAnalyzeGenotype, double>
+                              ("frac_neut",   "Fraction Mutations Neutral",
+                               &cAnalyzeGenotype::GetFracNeut,
+                               (void (cAnalyzeGenotype::*)(double)) NULL));
+  genotype_data_list.PushRear(new tDataEntry<cAnalyzeGenotype, double>
+                              ("frac_pos",   "Fraction Mutations Beneficial",
+                               &cAnalyzeGenotype::GetFracPos,
+                               (void (cAnalyzeGenotype::*)(double)) NULL));
+  genotype_data_list.PushRear(new tDataEntry<cAnalyzeGenotype, const cString &>
+                              ("parent_muts", "Mutations from Parent",
+                               &cAnalyzeGenotype::GetParentMuts, &cAnalyzeGenotype::SetParentMuts,
+                               &cAnalyzeGenotype::CompareNULL, "(none)", ""));
+  genotype_data_list.PushRear(new tDataEntry<cAnalyzeGenotype, const cString &>
+                              ("task_order", "Task Performance Order",
+                               &cAnalyzeGenotype::GetTaskOrder, &cAnalyzeGenotype::SetTaskOrder,
+                               &cAnalyzeGenotype::CompareNULL, "(none)", ""));
+  genotype_data_list.PushRear(new tDataEntry<cAnalyzeGenotype, cString>
+                              ("sequence",    "Genome Sequence",
+                               &cAnalyzeGenotype::GetSequence, &cAnalyzeGenotype::SetSequence, 
+                               &cAnalyzeGenotype::CompareNULL, "(N/A)", ""));
+  genotype_data_list.PushRear(new tDataEntry<cAnalyzeGenotype, const cString &>
+                              ("alignment",   "Aligned Sequence",
+                               &cAnalyzeGenotype::GetAlignedSequence,
+                               &cAnalyzeGenotype::SetAlignedSequence,
+                               &cAnalyzeGenotype::CompareNULL, "(N/A)", ""));
+  
+  genotype_data_list.PushRear(new tDataEntry<cAnalyzeGenotype, cString>
+                              ("task_list",    "List of all tasks performed",
+                               &cAnalyzeGenotype::GetTaskList,
+                               (void (cAnalyzeGenotype::*)(cString)) NULL,
+                               &cAnalyzeGenotype::CompareNULL, "(N/A)", ""));
+  
+  genotype_data_list.PushRear(new tDataEntry<cAnalyzeGenotype, cString>
+                              ("link.tasksites", "Phenotype Map", &cAnalyzeGenotype::GetMapLink,
+                               (void (cAnalyzeGenotype::*)(cString)) NULL));
+  genotype_data_list.PushRear(new tDataEntry<cAnalyzeGenotype, cString>
+                              ("html.sequence",  "Genome Sequence",
+                               &cAnalyzeGenotype::GetHTMLSequence,
+                               (void (cAnalyzeGenotype::*)(cString)) NULL,
+                               &cAnalyzeGenotype::CompareNULL, "(N/A)", ""));
+  
+  const cTaskLib & task_lib = cTestCPU::GetEnvironment()->GetTaskLib();
+  for (int i = 0; i < task_lib.GetSize(); i++) {
+    cString t_name, t_desc;
+    t_name.Set("task.%d", i);
+    t_desc = task_lib.GetTask(i).GetDesc();
+    genotype_data_list.PushRear(new tArgDataEntry<cAnalyzeGenotype, int, int>
+                                (t_name, t_desc, &cAnalyzeGenotype::GetTaskCount, i,
+                                 &cAnalyzeGenotype::CompareTaskCount));
+  }
+  
+  // The remaining values should actually go in a seperate list called
+  // "population_data_list", but for the moment we're going to put them
+  // here so that we only need to worry about a single system to load and
+  // save genotype information.
+  genotype_data_list.PushRear(new tDataEntry<cAnalyzeGenotype, int>
+                              ("update",       "Update Output",
+                               &cAnalyzeGenotype::GetUpdateDead, &cAnalyzeGenotype::SetUpdateDead));
+  genotype_data_list.PushRear(new tDataEntry<cAnalyzeGenotype, int>
+                              ("dom_num_cpus", "Number of Dominant Organisms",
+                               &cAnalyzeGenotype::GetNumCPUs, &cAnalyzeGenotype::SetNumCPUs));
+  genotype_data_list.PushRear(new tDataEntry<cAnalyzeGenotype, int>
+                              ("dom_depth",    "Tree Depth of Dominant Genotype",
+                               &cAnalyzeGenotype::GetDepth, &cAnalyzeGenotype::SetDepth));
+  genotype_data_list.PushRear(new tDataEntry<cAnalyzeGenotype, int>
+                              ("dom_id",       "Dominant Genotype ID",
+                               &cAnalyzeGenotype::GetID, &cAnalyzeGenotype::SetID));
+  genotype_data_list.PushRear(new tDataEntry<cAnalyzeGenotype, cString>
+                              ("dom_sequence", "Dominant Genotype Sequence",
+                               &cAnalyzeGenotype::GetSequence, &cAnalyzeGenotype::SetSequence, 
+                               &cAnalyzeGenotype::CompareNULL, "(N/A)", ""));
+}
+
+
+// Pass in the arguments for a command and fill out the entries in list
+// format....
+
+void cAnalyze::LoadGenotypeDataList(cStringList arg_list,
+                                    tList< tDataEntryCommand<cAnalyzeGenotype> > & output_list)
+{
+  // For the moment, just put everything into the output list.
+  SetupGenotypeDataList();
+  
+  // If no args were given, load all of the stats.
+  if (arg_list.GetSize() == 0) {
+    tListIterator< tDataEntryBase<cAnalyzeGenotype> >
+    genotype_data_it(genotype_data_list);
+    while (genotype_data_it.Next() != (void *) NULL) {
+      tDataEntryCommand<cAnalyzeGenotype> * entry_command =
+      new tDataEntryCommand<cAnalyzeGenotype>(genotype_data_it.Get());
+      output_list.PushRear(entry_command);
+    }
+  }
+  // Otherwise, load only those listed.
+  else {
+    while (arg_list.GetSize() != 0) {
+      // Setup the next entry
+      cString cur_args = arg_list.Pop();
+      cString cur_entry = cur_args.Pop(':');
+      bool found_entry = false;
+      
+      // Scan the genotype data list for the current entry
+      tListIterator< tDataEntryBase<cAnalyzeGenotype> >
+        genotype_data_it(genotype_data_list);
+      
+      while (genotype_data_it.Next() != (void *) NULL) {
+        if (genotype_data_it.Get()->GetName() == cur_entry) {
+          tDataEntryCommand<cAnalyzeGenotype> * entry_command =
+          new tDataEntryCommand<cAnalyzeGenotype>
+          (genotype_data_it.Get(), cur_args);
+          output_list.PushRear(entry_command);
+          found_entry = true;
+          break;
+        }
+      }
+      
+      // If the entry was not found, give a warning.
+      if (found_entry == false) {
+        int best_match = 1000;
+        cString best_entry;
+        
+        genotype_data_it.Reset();
+        while (genotype_data_it.Next() != (void *) NULL) {
+          const cString & test_str = genotype_data_it.Get()->GetName();
+          const int test_dist = cStringUtil::EditDistance(test_str, cur_entry);
+          if (test_dist < best_match) {
+            best_match = test_dist;
+            best_entry = test_str;
+          }
+        }	
+        
+        cerr << "Warning: Format entry \"" << cur_entry
+          << "\" not found.  Best match is \""
+          << best_entry << "\"." << endl;
+      }
+      
+    }
+  }
+}
+
+
+void cAnalyze::AddLibraryDef(const cString & name,
+                             void (cAnalyze::*_fun)(cString))
+{
+  command_lib.PushRear(new cAnalyzeCommandDef(name, _fun));
+}
+
+void cAnalyze::AddLibraryDef(const cString & name,
+                             void (cAnalyze::*_fun)(cString, tList<cAnalyzeCommand> &))
+{
+  command_lib.PushRear(new cAnalyzeFlowCommandDef(name, _fun));
+}
+
+void cAnalyze::SetupCommandDefLibrary()
+{
+  if (command_lib.GetSize() != 0) return; // Library already setup.
+  
+  AddLibraryDef("LOAD_ORGANISM", &cAnalyze::LoadOrganism);
+  AddLibraryDef("LOAD_BASE_DUMP", &cAnalyze::LoadBasicDump);
+  AddLibraryDef("LOAD_DETAIL_DUMP", &cAnalyze::LoadDetailDump);
+  AddLibraryDef("LOAD_MULTI_DETAIL", &cAnalyze::LoadMultiDetail);
+  AddLibraryDef("LOAD_SEQUENCE", &cAnalyze::LoadSequence);
+  AddLibraryDef("LOAD_DOMINANT", &cAnalyze::LoadDominant);
+  AddLibraryDef("LOAD_RESOURCES", &cAnalyze::LoadResources);
+  AddLibraryDef("LOAD", &cAnalyze::LoadFile);
+  
+  // Reduction commands...
+  AddLibraryDef("FIND_GENOTYPE", &cAnalyze::FindGenotype);
+  AddLibraryDef("FIND_ORGANISM", &cAnalyze::FindOrganism);
+  AddLibraryDef("FIND_LINEAGE", &cAnalyze::FindLineage);
+  AddLibraryDef("FIND_SEX_LINEAGE", &cAnalyze::FindSexLineage);
+  AddLibraryDef("FIND_CLADE", &cAnalyze::FindClade);
+  AddLibraryDef("SAMPLE_ORGANISMS", &cAnalyze::SampleOrganisms);
+  AddLibraryDef("SAMPLE_GENOTYPES", &cAnalyze::SampleGenotypes);
+  AddLibraryDef("KEEP_TOP", &cAnalyze::KeepTopGenotypes);
+  
+  // Direct output commands...
+  AddLibraryDef("PRINT", &cAnalyze::CommandPrint);
+  AddLibraryDef("TRACE", &cAnalyze::CommandTrace);
+  AddLibraryDef("PRINT_TASKS", &cAnalyze::CommandPrintTasks);
+  AddLibraryDef("DETAIL", &cAnalyze::CommandDetail);
+  AddLibraryDef("DETAIL_TIMELINE", &cAnalyze::CommandDetailTimeline);
+  AddLibraryDef("DETAIL_BATCHES", &cAnalyze::CommandDetailBatches);
+  AddLibraryDef("DETAIL_AVERAGE", &cAnalyze::CommandDetailAverage);
+  AddLibraryDef("DETAIL_INDEX", &cAnalyze::CommandDetailIndex);
+  AddLibraryDef("HISTOGRAM", &cAnalyze::CommandHistogram);
+  
+  // Population analysis commands...
+  AddLibraryDef("PRINT_PHENOTYPES", &cAnalyze::CommandPrintPhenotypes);
+  AddLibraryDef("PRINT_DIVERSITY", &cAnalyze::CommandPrintDiversity);
+  AddLibraryDef("COMMUNITY_COMPLEXITY", &cAnalyze::CommunityComplexity);
+
+  // Individual organism analysis...
+  AddLibraryDef("LANDSCAPE", &cAnalyze::CommandLandscape);
+  AddLibraryDef("FITNESS_MATRIX", &cAnalyze::CommandFitnessMatrix);
+  AddLibraryDef("MAP", &cAnalyze::CommandMapTasks);  // Deprecated...
+  AddLibraryDef("MAP_TASKS", &cAnalyze::CommandMapTasks);
+  AddLibraryDef("AVERAGE_MODULARITY", &cAnalyze::CommandAverageModularity);
+  AddLibraryDef("MAP_MUTATIONS", &cAnalyze::CommandMapMutations);
+  AddLibraryDef("ANALYZE_COMPLEXITY", &cAnalyze::AnalyzeComplexity);
+  AddLibraryDef("ANALYZE_POP_COMPLEXITY", &cAnalyze::AnalyzePopComplexity);
+  AddLibraryDef("MAP_DEPTH", &cAnalyze::CommandMapDepth);
+  
+  // Population comparison commands...
+  AddLibraryDef("HAMMING", &cAnalyze::CommandHamming);
+  AddLibraryDef("LEVENSTEIN", &cAnalyze::CommandLevenstein);
+  AddLibraryDef("SPECIES", &cAnalyze::CommandSpecies);
+  AddLibraryDef("RECOMBINE", &cAnalyze::CommandRecombine);
+  
+  // Lineage analysis commands...
+  AddLibraryDef("ALIGN", &cAnalyze::CommandAlign);
+  AddLibraryDef("ANALYZE_NEWINFO", &cAnalyze::AnalyzeNewInfo);
+  
+  // Build input files for avida...
+  AddLibraryDef("WRITE_CLONE", &cAnalyze::WriteClone);
+  AddLibraryDef("WRITE_INJECT_EVENTS", &cAnalyze::WriteInjectEvents);
+  AddLibraryDef("WRITE_COMPETITION", &cAnalyze::WriteCompetition);
+  
+  // Automated analysis
+  AddLibraryDef("ANALYZE_MUTS", &cAnalyze::AnalyzeMuts);
+  AddLibraryDef("ANALYZE_INSTRUCTIONS", &cAnalyze::AnalyzeInstructions);
+  AddLibraryDef("ANALYZE_INST_POP", &cAnalyze::AnalyzeInstPop);
+  AddLibraryDef("ANALYZE_BRANCHING", &cAnalyze::AnalyzeBranching);
+  AddLibraryDef("ANALYZE_MUTATION_TRACEBACK",
+                &cAnalyze::AnalyzeMutationTraceback);
+  AddLibraryDef("ANALYZE_EPISTASIS", &cAnalyze::AnalyzeEpistasis);
+  AddLibraryDef("ANALYZE_MATE_SELECTION", &cAnalyze::AnalyzeMateSelection);
+  
+  // Environment manipulation
+  AddLibraryDef("ENVIRONMENT", &cAnalyze::EnvironmentSetup);
+  
+  // Documantation...
+  AddLibraryDef("HELPFILE", &cAnalyze::CommandHelpfile);
+  
+  // Control commands...
+  AddLibraryDef("SET", &cAnalyze::VarSet);
+  AddLibraryDef("SET_BATCH", &cAnalyze::BatchSet);
+  AddLibraryDef("NAME_BATCH", &cAnalyze::BatchName);
+  AddLibraryDef("TAG_BATCH", &cAnalyze::BatchTag);
+  AddLibraryDef("PURGE_BATCH", &cAnalyze::BatchPurge);
+  AddLibraryDef("DUPLICATE", &cAnalyze::BatchDuplicate);
+  AddLibraryDef("RECALCULATE", &cAnalyze::BatchRecalculate);
+  AddLibraryDef("RENAME", &cAnalyze::BatchRename);
+  AddLibraryDef("STATUS", &cAnalyze::PrintStatus);
+  AddLibraryDef("DEBUG", &cAnalyze::PrintDebug);
+  AddLibraryDef("ECHO", &cAnalyze::PrintDebug);
+  AddLibraryDef("VERBOSE", &cAnalyze::ToggleVerbose);
+  AddLibraryDef("INCLUDE", &cAnalyze::IncludeFile);
+  AddLibraryDef("SYSTEM", &cAnalyze::CommandSystem);
+  AddLibraryDef("INTERACTIVE", &cAnalyze::CommandInteractive);
+  AddLibraryDef("PRINT_TEST_CPU_RESOURCES", &cAnalyze::PrintTestCPUResources);
+  
+  // Functions...
+  AddLibraryDef("FUNCTION", &cAnalyze::FunctionCreate);
+  
+  // Flow commands...
+  AddLibraryDef("FOREACH", &cAnalyze::CommandForeach);
+  AddLibraryDef("FORRANGE", &cAnalyze::CommandForRange);
+}
+
+cAnalyzeCommandDefBase * cAnalyze::FindAnalyzeCommandDef(const cString & name)
+{
+  SetupCommandDefLibrary();
+  
+  tListIterator<cAnalyzeCommandDefBase> lib_it(command_lib);
+  while (lib_it.Next() != (void *) NULL) {
+    if (lib_it.Get()->GetName() == name) break;
+  }
+  
+  return lib_it.Get();
+}
+
+void cAnalyze::RunInteractive()
+{
+  cout << "Entering interactive mode..." << endl;
+  
+  char text_input[2048];
+  while (true) {
+    cout << ">> ";
+    cout.flush();
+    cin.getline(text_input, 2048);
+    cString cur_input(text_input);
+    cString command = cur_input.PopWord();
+    command.ToUpper();
+    
+    cAnalyzeCommand * cur_command;
+    cAnalyzeCommandDefBase * command_def = FindAnalyzeCommandDef(command);
+    if (command == "") {
+      // Don't worry about blank lines...
+      continue;
+    }
+    else if (command == "END" || command == "QUIT" || command == "EXIT") {
+      // We are done with interactive mode...
+      break;
+    }
+    else if (command_def != NULL && command_def->IsFlowCommand() == true) {
+      // This code has a body to it... fill it out!
+      cur_command = new cAnalyzeFlowCommand(command, cur_input);
+      InteractiveLoadCommandList(*(cur_command->GetCommandList()));
+    }
+    else {
+      // This is a normal command...
+      cur_command = new cAnalyzeCommand(command, cur_input);
+    }
+    
+    cString args = cur_command->GetArgs();
+    PreProcessArgs(args);
+    
+    cAnalyzeCommandDefBase * command_fun = FindAnalyzeCommandDef(command);
+    
+    // First check for built-in functions...
+    if (command_fun != NULL) command_fun->Run(this, args, *cur_command);
+    
+    // Then for user defined functions
+    else if (FunctionRun(command, args) == true) { }
+    
+    // Otherwise, give an error.
+    else cerr << "Error: Unknown command '" << command << "'." << endl;
+  }
+}

Copied: trunk/source/main/cAnalyze.h (from rev 313, trunk/source/main/analyze.hh)

Copied: trunk/source/main/cAnalyzeCommand.h (from rev 313, trunk/source/main/analyze_command.hh)

Copied: trunk/source/main/cAnalyzeCommandDef.h (from rev 313, trunk/source/main/analyze_command_def.hh)
===================================================================
--- trunk/source/main/analyze_command_def.hh	2005-09-15 23:16:19 UTC (rev 313)
+++ trunk/source/main/cAnalyzeCommandDef.h	2005-09-16 02:10:20 UTC (rev 314)
@@ -0,0 +1,37 @@
+//////////////////////////////////////////////////////////////////////////////
+// Copyright (C) 1993 - 2003 California Institute of Technology             //
+//                                                                          //
+// Read the COPYING and README files, or contact 'avida at alife.org',         //
+// before continuing.  SOME RESTRICTIONS MAY APPLY TO USE OF THIS FILE.     //
+//////////////////////////////////////////////////////////////////////////////
+
+#ifndef ANALYZE_COMMAND_DEF_HH
+#define ANALYZE_COMMAND_DEF_HH
+
+#ifndef ANALYZE_COMMAND_DEF_BASE_HH
+#include "cAnalyzeCommandDefBase.h"
+#endif
+#ifndef STRING_HH
+#include "string.hh"
+#endif
+
+class cAnalyze;
+class cString; // aggregate
+class cAnalyzeCommand;
+
+class cAnalyzeCommandDef : public cAnalyzeCommandDefBase {
+private:
+  void (cAnalyze::*CommandFunction)(cString);
+public:
+  cAnalyzeCommandDef(const cString & _name, void (cAnalyze::*_cf)(cString))
+    : cAnalyzeCommandDefBase(_name), CommandFunction(_cf) { ; }
+  virtual ~cAnalyzeCommandDef() { ; }
+
+  virtual void Run(cAnalyze * analyze, const cString & args,
+		   cAnalyzeCommand & command) const {
+    (void) command; // used in other types of command defininitions.
+    (analyze->*CommandFunction)(args);
+  }
+};
+
+#endif

Copied: trunk/source/main/cAnalyzeCommandDefBase.h (from rev 313, trunk/source/main/analyze_command_def_base.hh)

Copied: trunk/source/main/cAnalyzeFlowCommand.h (from rev 313, trunk/source/main/analyze_flow_command.hh)
===================================================================
--- trunk/source/main/analyze_flow_command.hh	2005-09-15 23:16:19 UTC (rev 313)
+++ trunk/source/main/cAnalyzeFlowCommand.h	2005-09-16 02:10:20 UTC (rev 314)
@@ -0,0 +1,36 @@
+//////////////////////////////////////////////////////////////////////////////
+// Copyright (C) 1993 - 2003 California Institute of Technology             //
+//                                                                          //
+// Read the COPYING and README files, or contact 'avida at alife.org',         //
+// before continuing.  SOME RESTRICTIONS MAY APPLY TO USE OF THIS FILE.     //
+//////////////////////////////////////////////////////////////////////////////
+
+#ifndef ANALYZE_FLOW_COMMAND_HH
+#define ANALYZE_FLOW_COMMAND_HH
+
+#ifndef ANALYZE_COMMAND_HH
+#include "cAnalyzeCommand.h"
+#endif
+#ifndef TLIST_HH
+#include "tList.hh"
+#endif
+
+// cAnalyzeFlowCommand : A cAnalyzeCommand containing other commands
+
+template <class T> class tList; // aggregate
+class cString;
+
+class cAnalyzeFlowCommand : public cAnalyzeCommand {
+protected:
+  tList<cAnalyzeCommand> command_list;
+public:
+  cAnalyzeFlowCommand(const cString & _command, const cString & _args)
+    : cAnalyzeCommand(_command, _args) { ; }
+  virtual ~cAnalyzeFlowCommand() {
+    while ( command_list.GetSize() > 0 ) delete command_list.Pop();
+  }
+
+  tList<cAnalyzeCommand> * GetCommandList() { return &command_list; }
+};
+
+#endif

Copied: trunk/source/main/cAnalyzeFlowCommandDef.h (from rev 313, trunk/source/main/analyze_flow_command_def.hh)
===================================================================
--- trunk/source/main/analyze_flow_command_def.hh	2005-09-15 23:16:19 UTC (rev 313)
+++ trunk/source/main/cAnalyzeFlowCommandDef.h	2005-09-16 02:10:20 UTC (rev 314)
@@ -0,0 +1,46 @@
+//////////////////////////////////////////////////////////////////////////////
+// Copyright (C) 1993 - 2003 California Institute of Technology             //
+//                                                                          //
+// Read the COPYING and README files, or contact 'avida at alife.org',         //
+// before continuing.  SOME RESTRICTIONS MAY APPLY TO USE OF THIS FILE.     //
+//////////////////////////////////////////////////////////////////////////////
+
+#ifndef ANALYZE_FLOW_COMMAND_DEF_HH
+#define ANALYZE_FLOW_COMMAND_DEF_HH
+
+#ifndef ANALYZE_COMMAND_HH
+#include "cAnalyzeCommand.h"
+#endif
+#ifndef ANALYZE_COMMAND_DEF_BASE_HH
+#include "cAnalyzeCommandDefBase.h"
+#endif
+#ifndef STRING_HH
+#include "string.hh"
+#endif
+#ifndef TLIST_HH
+#include "tList.hh"
+#endif
+
+class cAnalyze;
+template <class T> class tList;
+class cAnalyzeCommand; // access
+class cString; // aggregate
+
+class cAnalyzeFlowCommandDef : public cAnalyzeCommandDefBase {
+private:
+  void (cAnalyze::*CommandFunction)(cString, tList<cAnalyzeCommand> &);
+public:
+  cAnalyzeFlowCommandDef(const cString &_name,
+	 void (cAnalyze::*_cf)(cString, tList<cAnalyzeCommand> &))
+    : cAnalyzeCommandDefBase(_name), CommandFunction(_cf) { ; }
+  virtual ~cAnalyzeFlowCommandDef() { ; }
+			 
+  virtual void Run(cAnalyze * analyze, const cString & args,
+		   cAnalyzeCommand & command) const {
+    (analyze->*CommandFunction)(args, *(command.GetCommandList()) );
+  }
+
+  virtual bool IsFlowCommand() { return true; }
+};
+
+#endif

Copied: trunk/source/main/cAnalyzeFunction.h (from rev 313, trunk/source/main/analyze_function.hh)
===================================================================
--- trunk/source/main/analyze_function.hh	2005-09-15 23:16:19 UTC (rev 313)
+++ trunk/source/main/cAnalyzeFunction.h	2005-09-16 02:10:20 UTC (rev 314)
@@ -0,0 +1,44 @@
+//////////////////////////////////////////////////////////////////////////////
+// Copyright (C) 1993 - 2003 California Institute of Technology             //
+//                                                                          //
+// Read the COPYING and README files, or contact 'avida at alife.org',         //
+// before continuing.  SOME RESTRICTIONS MAY APPLY TO USE OF THIS FILE.     //
+//////////////////////////////////////////////////////////////////////////////
+
+#ifndef ANALYZE_FUNCTION_HH
+#define ANALYZE_FUNCTION_HH
+
+#ifndef ANALYZE_COMMAND_HH
+#include "cAnalyzeCommand.h"
+#endif
+#ifndef STRING_HH
+#include "string.hh"
+#endif
+#ifndef TLIST_HH
+#include "tList.hh"
+#endif
+
+// cAnalyzeFunction    : User-defined function
+
+class cString; // aggregate
+template <class T> class tList; // aggregate
+class cAnalyzeCommand;
+
+class cAnalyzeFunction {
+private:
+  cString name;
+  tList<cAnalyzeCommand> command_list;
+private:
+  // disabled copy constructor.
+  cAnalyzeFunction(const cAnalyzeFunction &);
+public:
+  cAnalyzeFunction(const cString & _name) : name(_name) { ; }
+  ~cAnalyzeFunction() { 
+    while ( command_list.GetSize() > 0 ) delete command_list.Pop();
+  }
+
+  const cString & GetName() { return name; }
+  tList<cAnalyzeCommand> * GetCommandList() { return &command_list; }
+};
+
+#endif

Copied: trunk/source/main/cAnalyzeGenotype.cc (from rev 313, trunk/source/main/analyze_genotype.cc)
===================================================================
--- trunk/source/main/analyze_genotype.cc	2005-09-15 23:16:19 UTC (rev 313)
+++ trunk/source/main/cAnalyzeGenotype.cc	2005-09-16 02:10:20 UTC (rev 314)
@@ -0,0 +1,331 @@
+//////////////////////////////////////////////////////////////////////////////
+// Copyright (C) 1993 - 2003 California Institute of Technology             //
+//                                                                          //
+// Read the COPYING and README files, or contact 'avida at alife.org',         //
+// before continuing.  SOME RESTRICTIONS MAY APPLY TO USE OF THIS FILE.     //
+//////////////////////////////////////////////////////////////////////////////
+
+#include "cAnalyzeGenotype.h"
+
+#include "cConfig.h"
+#include "cCPUTestInfo.h"
+#include "inst_set.hh"
+#include "landscape.hh"
+#include "organism.hh"
+#include "phenotype.hh"
+#include "cTestCPU.h"
+
+using namespace std;
+
+//////////////////////
+//  cAnalyzeGenotype
+//////////////////////
+
+cAnalyzeGenotype::cAnalyzeGenotype(cString symbol_string,
+				   cInstSet & in_inst_set)
+  : genome(symbol_string)
+  , inst_set(in_inst_set)
+  , name("")
+  , aligned_sequence("")
+  , tag("")
+  , viable(false)
+  , id_num(-1)
+  , parent_id(-1)
+  , parent2_id(-1)
+  , num_cpus(0)
+  , total_cpus(0)
+  , update_born(0)
+  , update_dead(0)
+  , depth(0)
+  , length(0)
+  , copy_length(0)
+  , exe_length(0)
+  , merit(0.0)
+  , gest_time(INT_MAX)
+  , fitness(0.0)
+  , errors(0)
+  , task_counts(0)
+  , fitness_ratio(0.0)
+  , efficiency_ratio(0.0)
+  , comp_merit_ratio(0.0)
+  , parent_dist(0)
+  , ancestor_dist(0)
+  , parent_muts("")
+  , landscape_stats(NULL)
+{
+  // Make sure that the sequences jive with the inst_set
+  for (int i = 0; i < genome.GetSize(); i++) {
+    if (genome[i].GetOp() >= inst_set.GetSize()) {
+      cerr << "Error: Trying to load instruction " << genome[i].GetOp()
+	   << ".  Max in set is" << inst_set.GetSize() - 1
+	   << endl;
+    }
+  }
+}
+
+cAnalyzeGenotype::cAnalyzeGenotype(const cGenome & _genome,
+				   cInstSet & in_inst_set)
+  : genome(_genome)
+  , inst_set(in_inst_set)
+  , name("")
+  , aligned_sequence("")
+  , tag("")
+  , viable(false)
+  , id_num(-1)
+  , parent_id(-1)
+  , parent2_id(-1)
+  , num_cpus(0)
+  , total_cpus(0)
+  , update_born(0)
+  , update_dead(0)
+  , depth(0)
+  , length(0)
+  , copy_length(0)
+  , exe_length(0)
+  , merit(0.0)
+  , gest_time(INT_MAX)
+  , fitness(0.0)
+  , errors(0)
+  , task_counts(0)
+  , fitness_ratio(0.0)
+  , efficiency_ratio(0.0)
+  , comp_merit_ratio(0.0)
+  , parent_dist(0)
+  , ancestor_dist(0)
+  , parent_muts("")
+  , landscape_stats(NULL)
+{
+}
+
+cAnalyzeGenotype::cAnalyzeGenotype(const cAnalyzeGenotype & _gen)
+  : genome(_gen.genome)
+  , inst_set(_gen.inst_set)
+  , name(_gen.name)
+  , aligned_sequence(_gen.aligned_sequence)
+  , tag(_gen.tag)
+  , viable(_gen.viable)
+  , id_num(_gen.id_num)
+  , parent_id(_gen.parent_id)
+  , parent2_id(_gen.parent2_id)
+  , num_cpus(_gen.num_cpus)
+  , total_cpus(_gen.total_cpus)
+  , update_born(_gen.update_born)
+  , update_dead(_gen.update_dead)
+  , depth(_gen.depth)
+  , length(_gen.length)
+  , copy_length(_gen.copy_length)
+  , exe_length(_gen.exe_length)
+  , merit(_gen.merit)
+  , gest_time(_gen.gest_time)
+  , fitness(_gen.fitness)
+  , errors(_gen.errors)
+  , task_counts(_gen.task_counts)
+  , fitness_ratio(_gen.fitness_ratio)
+  , efficiency_ratio(_gen.efficiency_ratio)
+  , comp_merit_ratio(_gen.comp_merit_ratio)
+  , parent_dist(_gen.parent_dist)
+  , ancestor_dist(_gen.ancestor_dist)
+  , parent_muts(_gen.parent_muts)
+  , landscape_stats(NULL)
+{
+  if (_gen.landscape_stats != NULL) {
+    landscape_stats = new cAnalyzeLandscape;
+    *landscape_stats = *(_gen.landscape_stats);
+  }
+}
+
+cAnalyzeGenotype::~cAnalyzeGenotype()
+{
+  if (landscape_stats != NULL) delete landscape_stats;
+}
+
+
+int cAnalyzeGenotype::CalcMaxGestation() const
+{
+  return cConfig::GetTestCPUTimeMod() * genome.GetSize();
+}
+
+void cAnalyzeGenotype::CalcLandscape() const
+{
+  if (landscape_stats != NULL) return;
+
+  landscape_stats = new cAnalyzeLandscape;
+  cLandscape landscape(genome, inst_set);
+  landscape.Process(1);
+  landscape_stats->frac_dead = landscape.GetProbDead();
+  landscape_stats->frac_neg  = landscape.GetProbNeg();
+  landscape_stats->frac_neut = landscape.GetProbNeut();
+  landscape_stats->frac_pos  = landscape.GetProbPos();
+}
+
+void cAnalyzeGenotype::Recalculate(cAnalyzeGenotype * parent_genotype)
+{
+    // Build the test info for printing.
+  cCPUTestInfo test_info;
+  test_info.TestThreads();
+  // test_info.TraceTaskOrder();
+
+  // Use the inst lib for this genotype...
+  cInstSet * inst_set_backup = cTestCPU::GetInstSet();
+  cTestCPU::SetInstSet(&inst_set);
+  cTestCPU::TestGenome(test_info, genome);
+  cTestCPU::SetInstSet(inst_set_backup);
+
+  viable = test_info.IsViable();
+
+  cOrganism * test_organism = test_info.GetTestOrganism();
+  cPhenotype & test_phenotype = test_organism->GetPhenotype();
+
+  length = test_organism->GetGenome().GetSize();
+  copy_length = test_phenotype.GetCopiedSize();
+  exe_length = test_phenotype.GetExecutedSize();
+  merit = test_phenotype.GetMerit().GetDouble();
+  gest_time = test_phenotype.GetGestationTime();
+  fitness = test_phenotype.GetFitness();
+  errors = test_phenotype.GetLastNumErrors();
+  div_type = test_phenotype.GetDivType();
+  mate_id = test_phenotype.MateSelectID();
+  task_counts = test_phenotype.GetLastTaskCount();
+
+  // Setup a new parent stats if we have a parent to work with.
+  if (parent_genotype != NULL) {
+    fitness_ratio = GetFitness() / parent_genotype->GetFitness();
+    efficiency_ratio = GetEfficiency() / parent_genotype->GetEfficiency();
+    comp_merit_ratio = GetCompMerit() / parent_genotype->GetCompMerit();
+    parent_dist = cStringUtil::EditDistance(genome.AsString(),
+		    parent_genotype->GetGenome().AsString(), parent_muts);
+    ancestor_dist = parent_genotype->GetAncestorDist() + parent_dist;
+  }
+}
+
+
+void cAnalyzeGenotype::PrintTasks(ofstream & fp, int min_task, int max_task)
+{
+  if (max_task == -1) max_task = task_counts.GetSize();
+
+  for (int i = min_task; i < max_task; i++) {
+    fp << task_counts[i] << " ";
+  }
+}
+
+void cAnalyzeGenotype::SetSequence(cString _sequence)
+{
+  cGenome new_genome(_sequence);
+  genome = new_genome;
+}
+
+
+double cAnalyzeGenotype::GetFracDead() const
+{
+  CalcLandscape();  // Make sure the landscape is calculated...
+  return landscape_stats->frac_dead;
+}
+
+double cAnalyzeGenotype::GetFracNeg() const
+{
+  CalcLandscape();  // Make sure the landscape is calculated...
+  return landscape_stats->frac_neg;
+}
+
+double cAnalyzeGenotype::GetFracNeut() const
+{
+  CalcLandscape();  // Make sure the landscape is calculated...
+  return landscape_stats->frac_neut;
+}
+
+double cAnalyzeGenotype::GetFracPos() const
+{
+  CalcLandscape();  // Make sure the landscape is calculated...
+  return landscape_stats->frac_pos;
+}
+
+
+cString cAnalyzeGenotype::GetTaskList() const
+{
+  const int num_tasks = task_counts.GetSize();
+  cString out_string(num_tasks);
+  
+  for (int i = 0; i < num_tasks; i++) {
+    const int cur_count = task_counts[i];
+    if (cur_count < 10) {
+      out_string[i] = '0' + cur_count;
+    }
+    else if (cur_count < 30) {
+      out_string[i] = 'X';
+    }
+    else if (cur_count < 80) {
+      out_string[i] = 'L';
+    }
+    else if (cur_count < 300) {
+      out_string[i] = 'C';
+    }
+    else if (cur_count < 800) {
+      out_string[i] = 'D';
+    }
+    else if (cur_count < 3000) {
+      out_string[i] = 'M';
+    }
+    else {
+      out_string[i] = '+';
+    }
+  }
+
+  return out_string;
+}
+
+
+cString cAnalyzeGenotype::GetHTMLSequence() const
+{
+  cString text_genome = genome.AsString();
+  cString html_code("<tt>");
+
+  cString diff_info = parent_muts;
+  char mut_type = 'N';
+  int mut_pos = -1;
+
+  cString cur_mut = diff_info.Pop(',');
+  if (cur_mut != "") {
+    mut_type = cur_mut[0];
+    cur_mut.ClipFront(1); cur_mut.ClipEnd(1);
+    mut_pos = cur_mut.AsInt();
+  }
+
+  int ins_count = 0;
+  for (int i = 0; i < genome.GetSize(); i++) {
+    char symbol = text_genome[i];
+    if (i != mut_pos) html_code += symbol;
+    else {
+      // Figure out the information for the type of mutation we had...
+      cString color;
+      if (mut_type == 'M') {
+	color = "#FF0000";	
+      } else if (mut_type == 'I') {
+	color = "#00FF00";
+	ins_count++;
+      } else { // if (mut_type == 'D') {
+	color = "#0000FF";
+	symbol = '*';
+	i--;  // Rewind - we didn't read the handle character yet!
+      }
+
+      // Move on to the next mutation...
+      cur_mut = diff_info.Pop(',');
+      if (cur_mut != "") {
+	mut_type = cur_mut[0];
+	cur_mut.ClipFront(1); cur_mut.ClipEnd(1);
+	mut_pos = cur_mut.AsInt();
+	if (mut_type == 'D') mut_pos += ins_count;
+      } else mut_pos = -1;
+
+      // Tack on the current symbol...
+      cString symbol_string;
+      symbol_string.Set("<b><font color=\"%s\">%c</font></b>",
+			color(), symbol);
+      html_code += symbol_string;
+    }
+  }
+
+  html_code += "</tt>";
+
+  return html_code;
+}

Copied: trunk/source/main/cAnalyzeGenotype.h (from rev 313, trunk/source/main/analyze_genotype.hh)

Copied: trunk/source/main/cAnalyzeUtil.cc (from rev 313, trunk/source/main/analyze_util.cc)
===================================================================
--- trunk/source/main/analyze_util.cc	2005-09-15 23:16:19 UTC (rev 313)
+++ trunk/source/main/cAnalyzeUtil.cc	2005-09-16 02:10:20 UTC (rev 314)
@@ -0,0 +1,997 @@
+//////////////////////////////////////////////////////////////////////////////
+// Copyright (C) 1993 - 2001 California Institute of Technology             //
+//                                                                          //
+// Read the COPYING and README files, or contact 'avida at alife.org',         //
+// before continuing.  SOME RESTRICTIONS MAY APPLY TO USE OF THIS FILE.     //
+//////////////////////////////////////////////////////////////////////////////
+
+#ifndef ANALYZE_UTIL_HH
+#include "cAnalyzeUtil.h"
+#endif
+
+#ifndef CONFIG_HH
+#include "cConfig.h"
+#endif
+#ifndef DEFS_HH
+#include "defs.hh"
+#endif
+#ifndef ENVIRONMENT_HH
+#include "cEnvironment.h"
+#endif
+#ifndef GENEBANK_HH
+#include "genebank.hh"
+#endif
+#ifndef GENOME_HH
+#include "genome.hh"
+#endif
+#ifndef GENOME_UTIL_HH
+#include "genome_util.hh"
+#endif
+#ifndef GENOTYPE_HH
+#include "genotype.hh"
+#endif
+#ifndef HARDWARE_BASE_HH
+#include "cHardwareBase.h"
+#endif
+#ifndef HISTOGRAM_HH
+#include "histogram.hh"
+#endif
+#ifndef INST_SET_HH
+#include "inst_set.hh"
+#endif
+#ifndef INST_UTIL_HH
+#include "inst_util.hh"
+#endif
+#ifndef LANDSCAPE_HH
+#include "landscape.hh"
+#endif
+#ifndef ORGANISM_HH
+#include "organism.hh"
+#endif
+#ifndef PHENOTYPE_HH
+#include "phenotype.hh"
+#endif
+#ifndef POPULATION_HH
+#include "population.hh"
+#endif
+#ifndef POPULATION_CELL_HH
+#include "population_cell.hh"
+#endif
+#ifndef SPECIES_HH
+#include "species.hh"
+#endif
+#ifndef STATS_HH
+#include "stats.hh"
+#endif
+#ifndef TEST_CPU_HH
+#include "cTestCPU.h"
+#endif
+#ifndef TEST_UTIL_HH
+#include "cTestUtil.h"
+#endif
+#ifndef TOOLS_HH
+#include "tools.hh"
+#endif
+
+#include <vector>
+
+using namespace std;
+
+void cAnalyzeUtil::TestGenome(const cGenome & genome, cInstSet & inst_set,
+			      ofstream & fp, int update)
+{
+  cCPUTestInfo test_info;
+  cTestCPU::TestGenome(test_info, genome);
+
+  cPhenotype &colony_phenotype = test_info.GetColonyOrganism()->GetPhenotype();
+  fp << update << " "                                //  1
+     << colony_phenotype.GetMerit().GetDouble() << " "            //  2
+     << colony_phenotype.GetGestationTime() << " "             //  3
+     << colony_phenotype.GetFitness() << " "                      //  4
+     << 1.0 / (0.1  + colony_phenotype.GetGestationTime()) << " " //  5
+     << genome.GetSize() << " "                                   //  6
+     << colony_phenotype.GetCopiedSize() << " "                   //  7
+     << colony_phenotype.GetExecutedSize() << endl;               //  8
+}
+
+
+
+void cAnalyzeUtil::TestInsSizeChangeRobustness(ofstream & fp,
+		    const cInstSet & inst_set, const cGenome & in_genome,
+		    int num_trials, int update)
+{
+  cCPUTestInfo test_info;
+  const cInstruction inst_none = inst_set.GetInst("instruction_none");
+
+  // Stats
+  int num_viable = 0;
+  int num_new_size = 0;
+  int num_parent_size = 0;
+
+  for (int i = 0; i < num_trials; i++) {
+    cCPUMemory genome(in_genome);
+    // Should check to only insert infront of an instruction (not a Nop)
+    int ins_pos = -1;
+    while (ins_pos < 0) {
+      ins_pos = g_random.GetUInt(genome.GetSize());
+      if( inst_set.IsNop(genome[ins_pos]) )  ins_pos = -1;
+    }
+
+    // Insert some "instruction_none" into the genome
+    const int num_nops = g_random.GetUInt(5) + 5;
+    for (int j = 0; j < num_nops; j++)  genome.Insert(ins_pos, inst_none);
+
+    // Test the genome and output stats
+    if ( cTestCPU::TestGenome(test_info, genome) ){ // Daughter viable...
+      num_viable++;
+      const double child_size =
+	test_info.GetColonyOrganism()->GetGenome().GetSize();
+
+      if (child_size == (double) in_genome.GetSize()) num_parent_size++;
+      else if (child_size == (double) genome.GetSize()) num_new_size++;
+    }
+  } // for num_trials
+
+  fp << update << " "
+     << (double) num_viable / num_trials << " "
+     << (double) num_new_size / num_trials << " "
+     << (double) num_parent_size / num_trials << " "
+     << endl;
+}
+
+
+
+// Returns the genome of maximal fitness.
+cGenome cAnalyzeUtil::CalcLandscape(int dist, const cGenome & genome,
+				    cInstSet & inst_set)
+{
+  cLandscape landscape(genome, inst_set);
+  landscape.Process(dist);
+  double peak_fitness = landscape.GetPeakFitness();
+  cGenome peak_genome = landscape.GetPeakGenome();
+
+  // Print the results.
+
+  static ofstream fp("landscape.dat");
+  static ofstream fp_entropy("land-entropy.dat");
+  static ofstream fp_count("land-sitecount.dat");
+
+  landscape.PrintStats(fp);
+  landscape.PrintEntropy(fp_entropy);
+  landscape.PrintSiteCount(fp_count);
+
+  // Repeat for Insertions...
+  landscape.Reset(genome);
+  landscape.ProcessInsert();
+  static ofstream fp_ins("landscape-ins.dat");
+  static ofstream fp_ins_count("land-ins-sitecount.dat");
+  landscape.PrintStats(fp_ins);
+  landscape.PrintSiteCount(fp_ins_count);
+  if (landscape.GetPeakFitness() > peak_fitness) {
+    peak_fitness = landscape.GetPeakFitness();
+    peak_genome = landscape.GetPeakGenome();
+  }
+
+  // And Deletions...
+  landscape.Reset(genome);
+  landscape.ProcessDelete();
+  static ofstream fp_del("landscape-del.dat");
+  static ofstream fp_del_count("land-del-sitecount.dat");
+  landscape.PrintStats(fp_del);
+  landscape.PrintSiteCount(fp_del_count);
+  if (landscape.GetPeakFitness() > peak_fitness) {
+    peak_fitness = landscape.GetPeakFitness();
+    peak_genome = landscape.GetPeakGenome();
+  }
+
+  return peak_genome;
+}
+
+
+void cAnalyzeUtil::AnalyzeLandscape(const cGenome & genome, cInstSet &inst_set,
+	       int sample_size, int min_found, int max_sample_size, int update)
+{
+  cLandscape landscape(genome, inst_set);
+
+  static ofstream fp("land_analyze.dat");
+
+  int num_found = 0;
+  for (int dist = 1; dist <= 10; dist++) {
+    landscape.Reset(genome);
+    if (dist == 1) {
+      landscape.Process(dist);
+      num_found = genome.GetSize() * (inst_set.GetSize() - 1);
+    } else {
+      num_found =
+	landscape.RandomProcess(sample_size, dist, min_found, max_sample_size);
+    }
+
+    fp << update                       << " "  // 1
+       << dist                         << " "  // 2
+       << landscape.GetProbDead()      << " "  // 3
+       << landscape.GetProbNeg()       << " "  // 4
+       << landscape.GetProbNeut()      << " "  // 5
+       << landscape.GetProbPos()       << " "  // 6
+       << landscape.GetNumTrials()     << " "  // 7
+       << num_found                    << " "  // 8
+       << landscape.GetAveFitness()    << " "  // 9
+       << landscape.GetAveSqrFitness() << " "  // 10
+       << endl;
+
+    if ((dist > 1) && (num_found < min_found)) break;
+  }
+}
+
+
+void cAnalyzeUtil::PairTestLandscape(const cGenome &genome, cInstSet &inst_set,
+				     int sample_size, int update)
+{
+  cLandscape landscape(genome, inst_set);
+
+  cString filename;
+  filename.Set("pairtest.%d.dat", update);
+  ofstream fp(filename());
+
+  if (sample_size != 0) landscape.TestPairs(sample_size, fp);
+  else landscape.TestAllPairs(fp);
+}
+
+
+void cAnalyzeUtil::CalcConsensus(cPopulation * population, int lines_saved)
+{
+  const int num_inst = population->GetEnvironment().GetInstSet().GetSize();
+  const int update = population->GetStats().GetUpdate();
+  cGenebank & genebank = population->GetGenebank();
+
+  // Setup the histogtams...
+  cHistogram * inst_hist = new cHistogram[MAX_CREATURE_SIZE];
+  for (int i = 0; i < MAX_CREATURE_SIZE; i++) inst_hist[i].Resize(num_inst,-1);
+
+  // Loop through all of the genotypes adding them to the histograms.
+  cGenotype * cur_genotype = genebank.GetBestGenotype();
+  for (int i = 0; i < genebank.GetSize(); i++) {
+    const int num_organisms = cur_genotype->GetNumOrganisms();
+    const int length = cur_genotype->GetLength();
+    const cGenome & genome = cur_genotype->GetGenome();
+
+    // Place this genotype into the histograms.
+    for (int j = 0; j < length; j++) {
+      assert(genome[j].GetOp() < num_inst);
+      inst_hist[j].Insert(genome[j].GetOp(), num_organisms);
+    }
+
+    // Mark all instructions beyond the length as -1 in histogram...
+    for (int j = length; j < MAX_CREATURE_SIZE; j++) {
+      inst_hist[j].Insert(-1, num_organisms);
+    }
+
+    // ...and advance to the next genotype...
+    cur_genotype = cur_genotype->GetNext();
+  }
+
+  // Now, lets print something!
+  static ofstream fp("consensus.dat");
+  static ofstream fp_abundance("con-abundance.dat");
+  static ofstream fp_var("con-var.dat");
+  static ofstream fp_entropy("con-entropy.dat");
+
+  // Determine the length of the concensus genome
+  int con_length;
+  for (con_length = 0; con_length < MAX_CREATURE_SIZE; con_length++) {
+    if (inst_hist[con_length].GetMode() == -1) break;
+  }
+
+  // Build the concensus genotype...
+  cGenome con_genome(con_length);
+  double total_entropy = 0.0;
+  for (int i = 0; i < MAX_CREATURE_SIZE; i++) {
+    const int mode = inst_hist[i].GetMode();
+    const int count = inst_hist[i].GetCount(mode);
+    const int total = inst_hist[i].GetCount();
+    const double entropy = inst_hist[i].GetNormEntropy();
+    if (i < con_length) total_entropy += entropy;
+
+    // Break out if ALL creatures have a -1 in this area, and we've
+    // finished printing all of the files.
+    if (mode == -1 && count == total) break;
+
+    if ( i < con_length )
+      con_genome[i].SetOp(mode);
+
+    // Print all needed files.
+    if (i < lines_saved) {
+      fp_abundance << count << " ";
+      fp_var << inst_hist[i].GetCountVariance() << " ";
+      fp_entropy << entropy << " ";
+    }
+  }
+
+  // Put end-of-lines on the files.
+  if (lines_saved > 0) {
+    fp_abundance << endl;
+    fp_var       << endl;
+    fp_entropy   << endl;
+  }
+
+  // --- Study the consensus genome ---
+
+  // Loop through genotypes again, and determine the average genetic distance.
+  cur_genotype = genebank.GetBestGenotype();
+  cDoubleSum distance_sum;
+  for (int i = 0; i < genebank.GetSize(); i++) {
+    const int num_organisms = cur_genotype->GetNumOrganisms();
+    const int cur_dist =
+      cGenomeUtil::FindEditDistance(con_genome, cur_genotype->GetGenome());
+    distance_sum.Add(cur_dist, num_organisms);
+
+    // ...and advance to the next genotype...
+    cur_genotype = cur_genotype->GetNext();
+  }
+
+  // Finally, gather last bits of data and print the results.
+  cGenotype * con_genotype = genebank.FindGenotype(con_genome, -1);
+  const int best_dist = cGenomeUtil::FindEditDistance(con_genome,
+			     genebank.GetBestGenotype()->GetGenome());
+
+  const double ave_dist = distance_sum.Average();
+  const double var_dist = distance_sum.Variance();
+  const double complexity_base = (double) con_genome.GetSize() - total_entropy;
+
+  cString con_name;
+  con_name.Set("genebank/%03d-consensus-u%i.gen", con_genome.GetSize(),update);
+  cTestUtil::PrintGenome( con_genome, con_name() );
+
+
+  if (con_genotype) {
+    fp << update                                 << " " //  1
+       << con_genotype->GetMerit()               << " " //  2
+       << con_genotype->GetGestationTime()       << " " //  3
+       << con_genotype->GetFitness()             << " " //  4
+       << con_genotype->GetReproRate()           << " " //  5
+       << con_genotype->GetLength()              << " " //  6
+       << con_genotype->GetCopiedSize()          << " " //  7
+       << con_genotype->GetExecutedSize()        << " " //  8
+       << con_genotype->GetBirths()              << " " //  9
+       << con_genotype->GetBreedTrue()           << " " // 10
+       << con_genotype->GetBreedIn()             << " " // 11
+       << con_genotype->GetNumOrganisms()        << " " // 12
+       << con_genotype->GetDepth()               << " " // 13
+       << con_genotype->GetID()                  << " " // 14
+       << update - con_genotype->GetUpdateBorn() << " " // 15
+       << best_dist                              << " " // 16
+       << ave_dist                               << " " // 17
+       << var_dist                               << " " // 18
+       << total_entropy                          << " " // 19
+       << complexity_base                        << " " // 20
+       << endl;
+  }
+  else {
+    cCPUTestInfo test_info;
+    cTestCPU::TestGenome(test_info, con_genome);
+    cPhenotype & colony_phenotype =
+      test_info.GetColonyOrganism()->GetPhenotype();
+    fp << update                                             << " "   //  1
+       << colony_phenotype.GetMerit()                        << " "  //  2
+       << colony_phenotype.GetGestationTime()                << " "  //  3
+       << colony_phenotype.GetFitness()                      << " "  //  4
+       << 1.0 / (0.1  + colony_phenotype.GetGestationTime()) << " "  //  5
+       << con_genome.GetSize()                               << " "  //  6
+       << colony_phenotype.GetCopiedSize()                   << " "  //  7
+       << colony_phenotype.GetExecutedSize()                 << " "  //  8
+       << 0                                  << " "  // Births       //  9
+       << 0                                  << " "  // Breed True   // 10
+       << 0                                  << " "  // Breed In     // 11
+       << 0                                  << " "  // Num CPUs     // 12
+       << -1                                 << " "  // Depth        // 13
+       << -1                                 << " "  // ID           // 14
+       << 0                                  << " "  // Age          // 15
+       << best_dist                                          << " "  // 16
+       << ave_dist                                           << " "  // 17
+       << var_dist                                           << " "  // 18
+       << total_entropy                                      << " "  // 19
+       << complexity_base                                    << " "  // 20
+       << endl;
+  }
+
+  // Flush the file...
+  fp.flush();
+  
+  delete [] inst_hist;
+}
+
+
+
+/**
+ * This function goes through all creatures in the soup, and saves the
+ * basic landscape data (neutrality, fitness, and so on) into a stream.
+ *
+ * @param fp The stream into which the data should be saved.
+ *
+ * @param sample_prob The probability with which a particular creature should
+ * be analyzed (a value of 1 analyzes all creatures, a value of 0.1 analyzes
+ * 10%, and so on).
+ *
+ * @param landscape A bool that indicates whether the creatures should be
+ * landscaped (calc. neutrality and so on) or not.
+ *
+ * @param save_genotype A bool that indicates whether the creatures should
+ * be saved or not.
+ **/
+
+void cAnalyzeUtil::AnalyzePopulation(cPopulation * pop, ofstream & fp,
+	    double sample_prob, bool landscape, bool save_genotype)
+{
+  fp << "# (1) cell number (2) genotype name (3) length (4) fitness [test-cpu] (5) fitness (actual) (6) merit (7) no of breed trues occurred (8) lineage label (9) neutral metric (10) -... landscape data" << endl;
+
+  const double skip_prob = 1.0 - sample_prob;
+  for (int i = 0; i < pop->GetSize(); i++) {
+    if (pop->GetCell(i).IsOccupied() == false) continue;  // No organism...
+    if (g_random.P(skip_prob)) continue;               // Not sampled...
+
+    cOrganism * organism = pop->GetCell(i).GetOrganism();
+    cGenotype * genotype = organism->GetGenotype();
+    const cGenome & genome = organism->GetGenome();
+
+    cString creature_name;
+    if ( genotype->GetThreshold() ) creature_name = genotype->GetName();
+    else creature_name.Set("%03d-no_name-u%i-c%i", genotype->GetLength(),
+			   pop->GetStats().GetUpdate(), i );
+
+    fp << i                                     << " "  // 1 cell ID
+       << creature_name()                       << " "  // 2 name
+       << genotype->GetLength()                 << " "  // 3 length
+       << genotype->GetTestFitness()            << " "  // 4 fitness (test-cpu)
+       << organism->GetPhenotype().GetFitness() << " "  // 5 fitness (actual)
+       << organism->GetPhenotype().GetMerit()   << " "  // 6 merit
+       << genotype->GetBreedTrue()              << " "  // 7 breed true?
+       << organism->GetLineageLabel()           << " "  // 8 lineage label
+       << organism->GetPhenotype().GetNeutralMetric() << " "; // 9 neut metric
+
+    // create landscape object for this creature
+    if (landscape &&  genotype->GetTestFitness() > 0) {
+      cLandscape landscape( genome, pop->GetEnvironment().GetInstSet());
+      landscape.Process(1);
+      landscape.PrintStats(fp);
+    }
+    else fp << endl;
+    if ( save_genotype ){
+      char filename[40];
+      sprintf( filename, "genebank/%s", creature_name() );
+      cTestUtil::PrintGenome( genome, filename );
+    }
+  }
+}
+
+
+/**
+ * This function prints out fitness data. The main point is that it
+ * calculates the average fitness from info from the testCPU + the actual
+ * merit of the organisms, and assigns zero fitness to those organisms
+ * that will never reproduce.
+ *
+ * The function also determines the maximum fitness genotype, and can
+ * produce fitness histograms.
+ *
+ * @param datafp A stream into which the fitness data should be written.
+ * @param histofp A stream into which the fitness histogram should be
+ * written.
+ * @param histo_testCPU_fp A stream into which the fitness histogram as
+ * determined exclusively from the test-CPU should be written.
+ * @param save_max_f_genotype A bool that determines whether the genotype
+ * with the maximum fitness should be saved into the genebank.
+ * @param print_fitness_histo A bool that determines whether fitness
+ * histograms should be written.
+ * @param hist_fmax The maximum fitness value to be taken into account
+ * for the fitness histograms.
+ * @param hist_fstep The width of the individual bins in the fitness
+ * histograms.
+ **/
+
+void cAnalyzeUtil::PrintDetailedFitnessData(cPopulation *pop, ofstream &datafp,
+   ofstream & hist_fp, ofstream & histo_testCPU_fp, bool save_max_f_genotype,
+   bool print_fitness_histo, double hist_fmax, double hist_fstep)
+{
+  const int update = pop->GetStats().GetUpdate();
+  const double generation = pop->GetStats().SumGeneration().Average();
+
+  // the histogram variables
+  vector<int> histo;
+  vector<int> histo_testCPU;
+  int bins;
+
+  if ( print_fitness_histo ){
+    bins = (int) (hist_fmax / hist_fstep) + 1;
+    histo.resize( bins, 0 ); // resize and clear
+    histo_testCPU.resize( bins, 0 );
+  }
+
+  int n = 0;
+  int nhist_tot = 0;
+  int nhist_tot_testCPU = 0;
+  double fave = 0;
+  double fave_testCPU = 0;
+  double max_fitness = -1; // we set this to -1, so that even 0 is larger...
+  cGenotype * max_f_genotype = NULL;
+
+  for (int i = 0; i < pop->GetSize(); i++) {
+    if (pop->GetCell(i).IsOccupied() == false) continue;  // One use organisms.
+
+    cOrganism * organism = pop->GetCell(i).GetOrganism();
+    cGenotype * genotype = organism->GetGenotype();
+
+    cCPUTestInfo test_info;
+    cTestCPU::TestGenome( test_info, genotype->GetGenome() );
+    // We calculate the fitness based on the current merit,
+    // but with the true gestation time. Also, we set the fitness
+    // to zero if the creature is not viable.
+    const double f = ( test_info.IsViable() ) ? organism->GetPhenotype().GetMerit().CalcFitness(test_info.GetTestOrganism()->GetPhenotype().GetGestationTime()) : 0;
+    const double f_testCPU = test_info.GetColonyFitness();
+
+    // Get the maximum fitness in the population
+    // Here, we want to count only organisms that can truly replicate,
+    // to avoid complications
+    if ( f_testCPU > max_fitness &&
+	 test_info.GetTestOrganism()->GetPhenotype().CopyTrue() ){
+      max_fitness = f_testCPU;
+      max_f_genotype = genotype;
+    }
+
+    fave += f;
+    fave_testCPU += f_testCPU;
+    n += 1;
+
+
+    // histogram
+    if ( print_fitness_histo && f < hist_fmax ){
+      histo[(int) (f / hist_fstep)] += 1;
+      nhist_tot += 1;
+    }
+
+    if ( print_fitness_histo && f_testCPU < hist_fmax ){
+      histo_testCPU[(int) (f_testCPU / hist_fstep)] += 1;
+      nhist_tot_testCPU += 1;
+    }
+  }
+
+  // determine the name of the maximum fitness genotype
+  cString max_f_name;
+  if ( max_f_genotype->GetThreshold() )
+    max_f_name = max_f_genotype->GetName();
+  else // we put the current update into the name, so that it becomes unique.
+     max_f_name.Set("%03d-no_name-u%i", max_f_genotype->GetLength(),
+		    update );
+
+  datafp << update                    << " "  // 1 update
+	 << generation                << " "  // 2 generation
+	 << fave/ (double) n          << " "  // 3 average fitness
+	 << fave_testCPU/ (double) n  << " "  // 4 average test fitness
+	 << n 	                      << " "  // 5 organism total
+	 << max_fitness               << " "  // 6 maximum fitness
+	 << max_f_name()	      << " "  // 7 maxfit genotype name
+	 << endl;
+
+  if (save_max_f_genotype) {
+    char filename[40];
+    sprintf( filename, "genebank/%s", max_f_name() );
+    cTestUtil::PrintGenome( max_f_genotype->GetGenome(), filename );
+  }
+
+  if (print_fitness_histo) {
+    hist_fp << update            << " "  // 1 update
+	    << generation        << " "  // 2 generation
+	    << fave/ (double) n  << " "; // 3 average fitness
+
+    // now output the fitness histo
+    vector<int>::const_iterator it = histo.begin();
+    for ( ; it != histo.end(); it++ )
+      hist_fp << (double) (*it) / (double) nhist_tot << " ";
+    hist_fp << endl;
+
+    histo_testCPU_fp << update                    << " "  // 1 update
+		     << generation                << " "  // 2 generation
+		     << fave_testCPU/ (double) n  << " "; // 3 average fitness
+
+    // now output the fitness histo
+    it = histo_testCPU.begin();
+    for ( ; it != histo_testCPU.end(); it++ )
+      histo_testCPU_fp << (double) (*it) / (double) nhist_tot_testCPU << " ";
+    histo_testCPU_fp << endl;
+  }
+}
+
+
+/**
+ * This function goes through all genotypes currently present in the soup,
+ * and writes into an output file the average Hamming distance between the
+ * creatures in the population and a given reference genome.
+ *
+ * @param fp The stream into which the data should be saved.
+ * @param reference_genome The reference genome.
+ * @param save_creatures A bool that indicates whether creatures should be
+ * saved into the genebank or not.
+ **/
+
+void cAnalyzeUtil::PrintGeneticDistanceData(cPopulation * pop, ofstream & fp,
+					    const char * creature_name)
+{
+  double hamming_m1 = 0;
+  double hamming_m2 = 0;
+  int count = 0;
+  int dom_dist = 0;
+
+  // load the reference genome
+  cGenome reference_genome(cInstUtil::LoadGenome(creature_name,
+					 pop->GetEnvironment().GetInstSet()));
+
+  // get the info for the dominant genotype
+  cGenotype * cur_genotype = pop->GetGenebank().GetBestGenotype();
+  cGenome genome = cur_genotype->GetGenome();
+  dom_dist = cGenomeUtil::FindHammingDistance( reference_genome, genome );
+  hamming_m1 += dom_dist;
+  hamming_m2 += dom_dist*dom_dist;
+  count += cur_genotype->GetNumOrganisms();
+  // now cycle over the remaining genotypes
+  for (int i = 1; i < pop->GetGenebank().GetSize(); i++) {
+    cur_genotype = cur_genotype->GetNext();
+    cGenome genome = cur_genotype->GetGenome();
+
+    int dist = cGenomeUtil::FindHammingDistance( reference_genome, genome );
+    hamming_m1 += dist;
+    hamming_m2 += dist*dist;
+    count += cur_genotype->GetNumOrganisms();
+  }
+
+  hamming_m1 /= (double) count;
+  hamming_m2 /= (double) count;
+
+  fp << pop->GetStats().GetUpdate()          << " "  // 1 update
+     << hamming_m1 			     << " "  // ave. Hamming dist
+     << sqrt( ( hamming_m2 - hamming_m1*hamming_m1 ) / (double) count )
+                                             << " "  // std. error
+     << cGenomeUtil::FindHammingDistance( reference_genome,
+	      pop->GetGenebank().GetBestGenotype()->GetGenome() ) << " "
+     << endl;
+}
+
+
+/**
+ * This function goes through all genotypes currently present in the soup,
+ * and writes into an output file the names of the genotypes, the fitness
+ * as determined in the test cpu, and the genetic distance to a reference
+ * genome.
+ *
+ * @param fp The stream into which the data should be saved.
+ * @param reference_genome The reference genome.
+ * @param save_creatures A bool that indicates whether creatures should be
+ * saved into the genebank or not.
+ **/
+
+void cAnalyzeUtil::GeneticDistancePopDump(cPopulation * pop, ofstream & fp,
+			 const char * creature_name, bool save_creatures)
+{
+  double sum_fitness = 0;
+  int sum_num_organisms = 0;
+
+  // load the reference genome
+  cGenome reference_genome( cInstUtil::LoadGenome(creature_name,
+				  pop->GetEnvironment().GetInstSet()) );
+
+  // first, print out some documentation...
+  fp << "# (1) genotype name (2) fitness [test-cpu] (3) abundance (4) Hamming distance to reference (5) Levenstein distance to reference" << endl;
+  fp << "# reference genome is the START_CREATURE" << endl;
+
+  // cycle over all genotypes
+  cGenotype * cur_genotype = pop->GetGenebank().GetBestGenotype();
+  for (int i = 0; i < pop->GetGenebank().GetSize(); i++) {
+    const cGenome & genome = cur_genotype->GetGenome();
+    const int num_orgs = cur_genotype->GetNumOrganisms();
+
+    // now output
+
+    sum_fitness += cur_genotype->GetTestFitness() * num_orgs;
+    sum_num_organisms += num_orgs;
+
+    fp << cur_genotype->GetName()()       << " "  // 1 name
+       << cur_genotype->GetTestFitness()  << " "  // 2 fitness
+       << num_orgs                        << " "  // 3 abundance
+       << cGenomeUtil::FindHammingDistance(reference_genome, genome) << " "
+       << cGenomeUtil::FindEditDistance(reference_genome, genome) << " "  // 5
+       << genome.AsString()()             << " "  // 6 genome
+       << endl;
+
+    // save into genebank
+    if (save_creatures) {
+      char filename[40];
+      sprintf( filename, "genebank/%s", cur_genotype->GetName()() );
+      cTestUtil::PrintGenome( genome, filename );
+    }
+
+    // ...and advance to the next genotype...
+    cur_genotype = cur_genotype->GetNext();
+  }
+  fp << "# ave fitness from Test CPU's: "
+     << sum_fitness/sum_num_organisms << endl;
+}
+
+
+/**
+ * This function goes through all creatures in the soup, and writes out
+ * how many tasks the different creatures have done up to now. It counts
+ * every task only once, i.e., if a creature does 'put' three times, that
+ * will increase its count only by one.
+ *
+ * @param fp The file into which the result should be written.
+ **/
+
+void cAnalyzeUtil::TaskSnapshot(cPopulation * pop, ofstream & fp)
+{
+  fp << "# (1) cell number\n# (2) number of rewarded tasks done so far\n# (3) total number of tasks done so far\n# (4) same as 2, but right before divide\n# (5) same as 3, but right before divide\n# (6) same as 2, but for parent\n# (7) same as 3, but for parent\n# (8) genotype fitness\n# (9) genotype name" << endl;
+
+  for (int i = 0; i < pop->GetSize(); i++) {
+    if (pop->GetCell(i).IsOccupied() == false) continue;
+    cOrganism * organism = pop->GetCell(i).GetOrganism();
+
+    // create a test-cpu for the current creature
+    cCPUTestInfo test_info;
+    cTestCPU::TestGenome( test_info, organism->GetGenome() );
+    cPhenotype & test_phenotype = test_info.GetTestOrganism()->GetPhenotype();
+    cPhenotype & phenotype = organism->GetPhenotype();
+
+    int num_tasks = phenotype.GetEnvironment().GetTaskLib().GetSize();
+    int sum_tasks_all = 0;
+    int sum_tasks_rewarded = 0;
+    int divide_sum_tasks_all = 0;
+    int divide_sum_tasks_rewarded = 0;
+    int parent_sum_tasks_all = 0;
+    int parent_sum_tasks_rewarded = 0;
+
+    for (int j = 0; j < num_tasks; j++) {
+      // get the number of bonuses for this task
+      int bonuses = 1; //phenotype.GetTaskLib().GetTaskNumBonus(j);
+      int task_count = ( phenotype.GetCurTaskCount()[j] == 0 ) ? 0 : 1;
+      int divide_tasks_count = (test_phenotype.GetLastTaskCount()[j] == 0)?0:1;
+      int parent_task_count = (phenotype.GetLastTaskCount()[j] == 0) ? 0 : 1;
+
+      // If only one bonus, this task is not rewarded, as last bonus is + 0.
+      if (bonuses > 1) {
+	sum_tasks_rewarded += task_count;
+	divide_sum_tasks_rewarded += divide_tasks_count;
+	parent_sum_tasks_rewarded += parent_task_count;
+      }
+      sum_tasks_all += task_count;
+      divide_sum_tasks_all += divide_tasks_count;
+      parent_sum_tasks_all += parent_task_count;
+    }
+
+    fp << i                          << " " // 1 cell number
+       << sum_tasks_rewarded         << " " // 2 number of tasks rewarded
+       << sum_tasks_all              << " " // 3 total number of tasks done
+       << divide_sum_tasks_rewarded  << " " // 4 num rewarded tasks on divide
+       << divide_sum_tasks_all       << " " // 5 num total tasks on divide
+       << parent_sum_tasks_rewarded  << " " // 6 parent number of tasks rewared
+       << parent_sum_tasks_all       << " " // 7 parent total num tasks done
+       << test_info.GetColonyFitness()         << " " // 8 genotype fitness
+       << organism->GetGenotype()->GetName()() << " " // 9 genotype name
+       << endl;
+  }
+}
+
+void cAnalyzeUtil::TaskGrid(cPopulation * pop, ofstream & fp)
+{ 
+  for (int i = 0; i < pop->GetWorldX(); i++) {
+    for (int j = 0; j < pop->GetWorldY(); j++) {
+      int task_sum = 0;
+      int cell_num = i*pop->GetWorldX()+j;
+      if (pop->GetCell(cell_num).IsOccupied() == true) {
+        cOrganism * organism = pop->GetCell(cell_num).GetOrganism();
+        cCPUTestInfo test_info;
+        cTestCPU::TestGenome( test_info, organism->GetGenome() );
+        cPhenotype & test_phenotype = test_info.GetTestOrganism()->GetPhenotype();
+        int num_tasks = test_phenotype.GetEnvironment().GetTaskLib().GetSize();   
+        for (int k = 0; k < num_tasks; k++) {
+          if (test_phenotype.GetLastTaskCount()[k]>0) {
+	    task_sum = task_sum + (int) pow(2.0,k); 
+          } 
+        }
+      }
+      fp << task_sum << " ";
+    }
+    fp << endl;
+  }
+}
+
+/**
+ * This function prints all the tasks that viable creatures have performed
+ * so far (compare with the event 'print_task_data', which prints all tasks.
+ **/
+
+void cAnalyzeUtil::PrintViableTasksData(cPopulation * pop, ofstream & fp)
+{
+  const int num_tasks = cConfig::GetNumTasks();
+
+  static vector<int> tasks(num_tasks);
+  vector<int>::iterator it;
+
+  // clear task vector
+  for (it = tasks.begin(); it != tasks.end(); it++)  (*it) = 0;
+
+  for (int i = 0; i < pop->GetSize(); i++) {
+    if (pop->GetCell(i).IsOccupied() == false) continue;
+    if (pop->GetCell(i).GetOrganism()->GetGenotype()->GetTestFitness() > 0.0) {
+      cPhenotype & phenotype = pop->GetCell(i).GetOrganism()->GetPhenotype();
+      for (int j = 0; j < num_tasks; j++) {
+	if (phenotype.GetCurTaskCount()[j] > 0)  tasks[j] += 1;
+      }
+    }
+  }
+
+  fp << pop->GetStats().GetUpdate();
+  for (it = tasks.begin(); it != tasks.end(); it++)  fp << " " << (*it);
+  fp<<endl;
+}
+
+
+void cAnalyzeUtil::PrintTreeDepths(cPopulation * pop, ofstream & fp)
+{
+  // cycle over all genotypes
+  cGenotype * genotype = pop->GetGenebank().GetBestGenotype();
+  for (int i = 0; i < pop->GetGenebank().GetSize(); i++) {
+    fp << genotype->GetID() << " "             // 1
+       << genotype->GetTestFitness() << " "    // 2
+       << genotype->GetNumOrganisms() << " "   // 3
+       << genotype->GetDepth() << " "          // 4
+       << endl;
+
+    // ...and advance to the next genotype...
+    genotype = genotype->GetNext();
+  }
+}
+
+
+void cAnalyzeUtil::PrintDepthHistogram(ofstream & fp, cPopulation * pop)
+{
+  // Output format:    update  min  max  histogram_values...
+  int min = INT_MAX;
+  int max = 0;
+  assert(fp.good());
+
+  // Two pass method
+
+  // Loop through all genotypes getting min and max values
+  cGenebank & genebank = pop->GetGenebank();
+  cGenotype * cur_genotype = genebank.GetBestGenotype();
+  for (int i = 0; i < genebank.GetSize(); i++) {
+    if (cur_genotype->GetDepth() < min) min = cur_genotype->GetDepth();
+    if (cur_genotype->GetDepth() > max) max = cur_genotype->GetDepth();
+    cur_genotype = cur_genotype->GetNext();
+  }
+  assert(max >= min);
+
+  // Allocate the array for the bins (& zero)
+  int * n = new int[max - min + 1];
+  for (int i = 0; i < max - min + 1; i++) n[i] = 0;
+
+  // Loop through all genotypes binning the values
+  cur_genotype = genebank.GetBestGenotype();
+  for (int i = 0; i < genebank.GetSize(); i++) {
+    n[cur_genotype->GetDepth() - min] += cur_genotype->GetNumOrganisms();
+    cur_genotype = cur_genotype->GetNext();
+  }
+
+  // Actual output
+  fp << pop->GetStats().GetUpdate() << " "
+     << min << " "
+     << max;
+
+  for (int i = 0; i < max - min + 1; i++)  fp << " " << n[i];
+  fp<<endl;
+}
+
+
+void cAnalyzeUtil::PrintGenotypeAbundanceHistogram(ofstream & fp,
+						   cPopulation * pop)
+{
+  assert(fp.good());
+
+  // Allocate array for the histogram & zero it
+  tArray <int> hist(pop->GetGenebank().GetBestGenotype()->GetNumOrganisms());
+  for (int i = 0; i < hist.GetSize(); i++) hist[i] = 0;
+
+  // Loop through all genotypes binning the values
+  cGenotype * cur_genotype = pop->GetGenebank().GetBestGenotype();
+  for (int i = 0; i < pop->GetGenebank().GetSize(); i++) {
+    assert( cur_genotype->GetNumOrganisms() - 1 >= 0 );
+    assert( cur_genotype->GetNumOrganisms() - 1 < hist.GetSize() );
+    hist[cur_genotype->GetNumOrganisms() - 1]++;
+    cur_genotype = cur_genotype->GetNext();
+  }
+
+  // Actual output
+  fp << pop->GetStats().GetUpdate() << " ";
+  for (int i = 0; i < hist.GetSize(); i++)  fp<<hist[i]<<" ";
+  fp << endl;
+}
+
+
+void cAnalyzeUtil::PrintSpeciesAbundanceHistogram(ofstream & fp,
+						  cPopulation * pop)
+{
+  int max = 0;
+  assert(fp.good());
+
+  // Find max species abundance...
+  cGenebank & genebank = pop->GetGenebank();
+  cSpecies * cur_species = genebank.GetFirstSpecies();
+  for (int i = 0; i < genebank.GetNumSpecies(); i++) {
+    if (max < cur_species->GetNumOrganisms()) {
+      max = cur_species->GetNumOrganisms();
+    }
+    cur_species = cur_species->GetNext();
+  }
+
+  // Allocate array for the histogram & zero it
+  tArray <int> hist(max);
+  for (int i = 0; i < hist.GetSize(); i++)  hist[i] = 0;
+
+  // Loop through all species binning the values
+  cur_species = genebank.GetFirstSpecies();
+  for (int i = 0; i < genebank.GetNumSpecies(); i++) {
+    assert( cur_species->GetNumOrganisms() - 1 >= 0 );
+    assert( cur_species->GetNumOrganisms() - 1 < hist.GetSize() );
+    hist[cur_species->GetNumOrganisms() -1]++;
+    cur_species = cur_species->GetNext();
+  }
+
+  // Actual output
+  fp << pop->GetStats().GetUpdate() << " ";
+  for (int i = 0; i < hist.GetSize(); i++)  fp<<hist[i]<<" ";
+  fp<<endl;
+}
+
+
+// this adds support for evan dorn's InstructionHistogramEvent.  -- kgn
+/**
+ * Count the number of each instruction present in the population.  Output
+ * this info to a log file
+ **/
+void cAnalyzeUtil::PrintInstructionAbundanceHistogram(ofstream & fp,
+                  cPopulation * pop)
+{ int i,x,y;
+  int num_inst=0;
+  int mem_size=0;
+  int * inst_counts;
+  cCPUMemory cpu_mem; // cCPUMemory is a subclass of cGenome
+  assert(fp.good());
+
+  // ----- number of instructions available?
+  num_inst=pop->GetEnvironment().GetInstSet().GetSize();
+  inst_counts= new int[num_inst];
+
+  // ----- create and initialize counting array
+  inst_counts  = new int[num_inst];
+  for (i=0;i<num_inst;i++)
+    { inst_counts[i]=0;
+    }
+  
+  int num_cells = pop->GetSize();
+  //looping through all CPUs counting up instructions
+  for( x=0; x<num_cells; x++ )
+    { cPopulationCell & cell=pop->GetCell(x);
+      if (cell.IsOccupied())
+      {
+      // access this CPU's code block
+        cpu_mem=cell.GetOrganism()->GetHardware().GetMemory();
+        mem_size=cpu_mem.GetSize();
+        for (y=0; y<mem_size ; y++)
+    { inst_counts[(cpu_mem[y]).GetOp()]++;     
+    }  
+      }
+    }
+  
+  // ----- output instruction counts
+  for(i=0; i<num_inst; i++)
+    { fp<<inst_counts[i]<<" ";
+    }
+  fp<<endl;
+}
+

Copied: trunk/source/main/cAnalyzeUtil.h (from rev 313, trunk/source/main/analyze_util.hh)

Copied: trunk/source/main/cAvidaDriver_Analyze.cc (from rev 313, trunk/source/main/avida_driver_analyze.cc)
===================================================================
--- trunk/source/main/avida_driver_analyze.cc	2005-09-15 23:16:19 UTC (rev 313)
+++ trunk/source/main/cAvidaDriver_Analyze.cc	2005-09-16 02:10:20 UTC (rev 314)
@@ -0,0 +1,47 @@
+//////////////////////////////////////////////////////////////////////////////
+// Copyright (C) 1993 - 2003 California Institute of Technology             //
+//                                                                          //
+// Read the COPYING and README files, or contact 'avida at alife.org',         //
+// before continuing.  SOME RESTRICTIONS MAY APPLY TO USE OF THIS FILE.     //
+//////////////////////////////////////////////////////////////////////////////
+
+#ifndef AVIDA_DRIVER_ANALYZE_HH
+#include "cAvidaDriver_Analyze.h"
+#endif
+
+#ifndef ANALYZE_HH
+#include "cAnalyze.h"
+#endif
+#ifndef CONFIG_HH
+#include "cConfig.h"
+#endif
+
+#ifndef ENVIRONMENT_HH
+#include "cEnvironment.h"
+#endif
+
+#include <iostream>
+
+using namespace std;
+
+//////////////////////////
+//  cAvidaDriver_Analyze
+//////////////////////////
+
+cAvidaDriver_Analyze::cAvidaDriver_Analyze(bool _interactive, cEnvironment *e)
+  : interactive(_interactive), d_environment(e)
+{
+}
+
+cAvidaDriver_Analyze::~cAvidaDriver_Analyze()
+{
+}
+
+void cAvidaDriver_Analyze::Run()
+{
+  cout << "In analyze mode!!" << endl;
+  cAnalyze analyze(cConfig::GetAnalyzeFilename(), d_environment);
+  if (interactive == true) {
+    analyze.RunInteractive();
+  }
+}

Copied: trunk/source/main/cAvidaDriver_Analyze.h (from rev 313, trunk/source/main/avida_driver_analyze.hh)
===================================================================
--- trunk/source/main/avida_driver_analyze.hh	2005-09-15 23:16:19 UTC (rev 313)
+++ trunk/source/main/cAvidaDriver_Analyze.h	2005-09-16 02:10:20 UTC (rev 314)
@@ -0,0 +1,29 @@
+//////////////////////////////////////////////////////////////////////////////
+// Copyright (C) 1993 - 2003 California Institute of Technology             //
+//                                                                          //
+// Read the COPYING and README files, or contact 'avida at alife.org',         //
+// before continuing.  SOME RESTRICTIONS MAY APPLY TO USE OF THIS FILE.     //
+//////////////////////////////////////////////////////////////////////////////
+
+#ifndef AVIDA_DRIVER_ANALYZE_HH
+#define AVIDA_DRIVER_ANALYZE_HH
+
+#include <cstdlib>
+
+#ifndef AVIDA_DRIVER_BASE_HH
+#include "cAvidaDriver_Base.h"
+#endif
+
+class cEnvironment;
+
+class cAvidaDriver_Analyze : public cAvidaDriver_Base {
+protected:
+  bool interactive;
+  cEnvironment *d_environment;
+public:
+  cAvidaDriver_Analyze(bool _interactive=false, cEnvironment* = NULL);
+  virtual ~cAvidaDriver_Analyze();
+  virtual void Run();
+};
+
+#endif

Copied: trunk/source/main/cAvidaDriver_Base.cc (from rev 313, trunk/source/main/avida_driver_base.cc)
===================================================================
--- trunk/source/main/avida_driver_base.cc	2005-09-15 23:16:19 UTC (rev 313)
+++ trunk/source/main/cAvidaDriver_Base.cc	2005-09-16 02:10:20 UTC (rev 314)
@@ -0,0 +1,55 @@
+//////////////////////////////////////////////////////////////////////////////
+// Copyright (C) 1993 - 2003 California Institute of Technology             //
+//                                                                          //
+// Read the COPYING and README files, or contact 'avida at alife.org',         //
+// before continuing.  SOME RESTRICTIONS MAY APPLY TO USE OF THIS FILE.     //
+//////////////////////////////////////////////////////////////////////////////
+
+#ifndef AVIDA_DRIVER_BASE_HH
+#include "cAvidaDriver_Base.h"
+#endif
+
+#ifndef STRING_HH
+#include "string.hh"
+#endif
+
+#include <iostream>
+
+using namespace std;
+
+
+// Static variable definitions
+cAvidaDriver_Base * cAvidaDriver_Base::main_driver = NULL;
+
+///////////////////////
+//  cAvidaDriver_Base
+///////////////////////
+
+cAvidaDriver_Base::cAvidaDriver_Base()
+  : done_flag(false)
+{
+}
+
+cAvidaDriver_Base::~cAvidaDriver_Base()
+{
+}
+
+void cAvidaDriver_Base::ExitProgram(int exit_code)
+{
+  exit(exit_code);   // If nothing is setup, nothing needs to be shutdown.
+}
+
+void cAvidaDriver_Base::NotifyComment(const cString & in_string)
+{
+  cout << in_string << endl;  // Just output
+}
+
+void cAvidaDriver_Base::NotifyWarning(const cString & in_string)
+{
+  cerr << in_string << endl;  // Just output
+}
+
+void cAvidaDriver_Base::NotifyError(const cString & in_string)
+{
+  cerr << in_string << endl;  // Just output
+}

Copied: trunk/source/main/cAvidaDriver_Base.h (from rev 313, trunk/source/main/avida_driver_base.hh)

Copied: trunk/source/main/cAvidaDriver_Population.cc (from rev 313, trunk/source/main/avida_driver_population.cc)
===================================================================
--- trunk/source/main/avida_driver_population.cc	2005-09-15 23:16:19 UTC (rev 313)
+++ trunk/source/main/cAvidaDriver_Population.cc	2005-09-16 02:10:20 UTC (rev 314)
@@ -0,0 +1,251 @@
+//////////////////////////////////////////////////////////////////////////////
+// Copyright (C) 1993 - 2003 California Institute of Technology             //
+//                                                                          //
+// Read the COPYING and README files, or contact 'avida at alife.org',         //
+// before continuing.  SOME RESTRICTIONS MAY APPLY TO USE OF THIS FILE.     //
+//////////////////////////////////////////////////////////////////////////////
+
+#include "cAvidaDriver_Population.h"
+
+#include "cAvidaTriggers.h"
+#include "cCallbackUtil.h"
+#include "change_list.hh"
+#include "cConfig.h"
+#include "cEventFactoryManager.h"
+#include "cEventList.h"
+#include "genebank.hh"
+#include "genotype.hh"
+#include "cHardwareBase.h"
+#include "cHardwareFactory.h"
+#include "init_file.hh"
+#include "organism.hh"
+#include "population.hh"
+#include "population_cell.hh"
+#include "cPopulationEventFactory.h"
+#include "cPopulationInterface.h"
+#include "string.hh"
+#include "tools.hh"
+
+#include <iostream>
+#include <iomanip>
+
+using namespace std;
+
+/////////////////////////////
+//  cAvidaDriver_Population
+/////////////////////////////
+
+cAvidaDriver_Population::cAvidaDriver_Population(cEnvironment & environment, cChangeList * change_list)
+  : population(NULL), event_manager(NULL), event_list(NULL)
+{
+  // Setup Population    
+  cPopulationInterface default_interface;
+  default_interface.SetFun_NewHardware(&cCallbackUtil::CB_NewHardware);
+  default_interface.SetFun_Recycle(&cCallbackUtil::CB_RecycleHardware);
+  default_interface.SetFun_Divide(&cCallbackUtil::CB_Divide);
+  default_interface.SetFun_TestOnDivide(&cCallbackUtil::CB_TestOnDivide);
+  default_interface.SetFun_GetNeighbor(&cCallbackUtil::CB_GetNeighbor);
+  default_interface.SetFun_NumNeighbors(&cCallbackUtil::CB_GetNumNeighbors);
+  default_interface.SetFun_Rotate(&cCallbackUtil::CB_Rotate);
+  default_interface.SetFun_Breakpoint(&cCallbackUtil::CB_Breakpoint);
+  default_interface.SetFun_TestFitness(&cCallbackUtil::CB_TestFitness);
+  default_interface.SetFun_GetInput(&cCallbackUtil::CB_GetInput);
+  default_interface.SetFun_GetInputAt(&cCallbackUtil::CB_GetInputAt);
+  default_interface.SetFun_Debug(&cCallbackUtil::CB_Debug);
+  default_interface.SetFun_GetResources(&cCallbackUtil::CB_GetResources);
+  default_interface.SetFun_UpdateResources(&cCallbackUtil::CB_UpdateResources);
+  default_interface.SetFun_KillCell(&cCallbackUtil::CB_KillCell);
+  default_interface.SetFun_KillSurroundCell(&cCallbackUtil::CB_KillSurroundCell);
+  default_interface.SetFun_SendMessage(&cCallbackUtil::CB_SendMessage);
+  default_interface.SetFun_ReceiveValue(&cCallbackUtil::CB_ReceiveValue);
+  default_interface.SetFun_InjectParasite(&cCallbackUtil::CB_InjectParasite);
+  default_interface.SetFun_UpdateMerit(&cCallbackUtil::CB_UpdateMerit);
+
+  population = new cPopulation(default_interface, environment, change_list);
+
+  //Setup Event List
+  event_manager = new cEventFactoryManager;
+  cStats & stats = population->GetStats();
+  event_list = new cEventList( event_manager, new cAvidaTriggers(stats) );
+  
+  // in principle, one could add more than one event factory here.
+  // however, this is not a good idea, because the automatic documentation
+  // system cannot cope with this at this point. Claus
+  event_manager->AddFactory(new cPopulationEventFactory(population));
+
+  ReadEventListFile(cConfig::GetEventFilename());
+  
+  // Make sure the directory 'genebank' exits!
+  cTools::MkDir("genebank", true);
+}
+
+cAvidaDriver_Population::~cAvidaDriver_Population()
+{
+  if (population != NULL) delete population;
+}
+
+void cAvidaDriver_Population::Run()
+{
+  assert( population != NULL );
+
+  // Process until done...
+  while ( !ProcessUpdate() ) {} 
+}
+
+bool cAvidaDriver_Population::ProcessUpdate()
+{
+  if (cChangeList *change_list = population->GetChangeList()) {
+    change_list->Reset();
+  }
+
+  GetEvents();
+  if (done_flag == true) return true;
+
+  // Increment the Update.
+  cStats & stats = population->GetStats();
+  stats.IncCurrentUpdate();
+
+  // Handle all data collection for previous update.
+  if (stats.GetUpdate() > 0) {
+    // Tell the stats object to do update calculations and printing.
+    stats.ProcessUpdate();
+
+    // Update all the genotypes for the end of this update.
+    cGenebank & genebank = population->GetGenebank();
+    for (cGenotype * cur_genotype = genebank.ResetThread(0);
+	 cur_genotype != NULL && cur_genotype->GetThreshold();
+	 cur_genotype = genebank.NextGenotype(0)) {
+      cur_genotype->UpdateReset();
+    }
+  }
+
+  ProcessOrganisms();
+
+  // Do Point Mutations
+  if (cConfig::GetPointMutProb() > 0 ) {
+    for (int i = 0; i < population->GetSize(); i++) {
+      if (population->GetCell(i).IsOccupied()) {
+	population->GetCell(i).GetOrganism()->
+	  GetHardware().PointMutate(cConfig::GetPointMutProb());
+      }
+    }
+  }
+  
+
+#ifdef DEBUG_CHECK_OK
+  // If we're in a debug mode, make sure the population is OK.
+  if (population->OK() == false) {
+    g_debug.Warning("Population::OK() is failing.");
+  }
+#endif
+
+  // Do any cleanup in the hardware factory...
+  cHardwareFactory::Update();
+  
+  // Exit conditons...
+  if (population->GetNumOrganisms() == 0) done_flag = true;
+  
+  return done_flag;
+}
+
+
+void cAvidaDriver_Population::NotifyUpdate()
+{
+  // Nothing here for now.  This method should be overloaded and only
+  // run if there is no proper viewer.
+}
+
+
+void cAvidaDriver_Population::GetEvents()
+{
+  assert(population != NULL);
+
+  if (population->GetSyncEvents() == true) {
+    SyncEventList();
+    population->SetSyncEvents(false);
+  }
+  event_list->Process();
+}
+
+void cAvidaDriver_Population::ProcessOrganisms()
+{
+  // Process the update.
+  const int UD_size =
+    cConfig::GetAveTimeslice() * population->GetNumOrganisms();
+  const double step_size = 1.0 / (double) UD_size;
+
+  for (int i = 0; i < UD_size; i++) {
+    if (population->GetNumOrganisms() == 0) {
+      done_flag = true;
+      break;
+    }
+    population->ProcessStep(step_size);
+  }
+
+  // end of update stats...
+  population->CalcUpdateStats();
+
+  // No viewer; print out status for this update....
+  cStats & stats = population->GetStats();
+  cout.setf(ios::left);
+  cout.setf(ios::showpoint);
+  cout << "UD: " << setw(6) << stats.GetUpdate() << "  "
+       << "Gen: " << setw(9) << setprecision(7) << stats.SumGeneration().Average() << "  "
+       << "Fit: " << setw(9) << setprecision(7) << stats.GetAveFitness() << "  "
+       << "Size: " << population->GetNumOrganisms()
+       << endl;
+}
+
+
+void cAvidaDriver_Population::
+ReadEventListFile(const cString & filename)
+{
+  cInitFile event_file(filename);
+
+  // Load in the proper event list and set it up.
+  event_file.Load();
+  event_file.Compress();
+
+  // Loop through the line_list and change the lines to events.
+  for (int line_id = 0; line_id < event_file.GetNumLines(); line_id++) {
+    event_list->AddEventFileFormat(event_file.GetLine(line_id));
+  }
+
+  ////////// Adding events from the Genesis file //////////
+  // Max Updates and/or Max Generations
+  if( cConfig::GetEndConditionMode() == 0 ){
+    if( cConfig::GetMaxUpdates() >= 0 ){
+      event_list->AddEvent( cEventTriggers::UPDATE, cConfig::GetMaxUpdates(),
+			    cEventTriggers::TRIGGER_ONCE,
+			    cEventTriggers::TRIGGER_END, "exit", "");
+    }
+    if( cConfig::GetMaxGenerations() >= 0 ){
+      event_list->AddEvent( cEventTriggers::GENERATION,
+			    cConfig::GetMaxGenerations(),
+			    cEventTriggers::TRIGGER_ONCE,
+			    cEventTriggers::TRIGGER_END, "exit", "");
+    }
+  }else{
+    if( cConfig::GetMaxUpdates() >= 0 && cConfig::GetMaxGenerations() >= 0 ){
+      cString max_gen_str;
+      max_gen_str.Set("%d",cConfig::GetMaxGenerations());
+      cString max_update_str;
+      max_update_str.Set("%d",cConfig::GetMaxUpdates());
+      event_list->AddEvent( cEventTriggers::UPDATE, cConfig::GetMaxUpdates(),
+			    1, cEventTriggers::TRIGGER_END,
+			    "exit_if_generation_greater_than", max_gen_str);
+      event_list->AddEvent( cEventTriggers::GENERATION,
+			    cConfig::GetMaxGenerations(),
+			    .01, cEventTriggers::TRIGGER_END,
+			    "exit_if_update_greater_than", max_update_str);
+    }
+  }
+
+}
+
+void cAvidaDriver_Population::SyncEventList()
+{
+  if( event_list != NULL ){
+    event_list->Sync();
+  }
+}

Copied: trunk/source/main/cAvidaDriver_Population.h (from rev 313, trunk/source/main/avida_driver_population.hh)
===================================================================
--- trunk/source/main/avida_driver_population.hh	2005-09-15 23:16:19 UTC (rev 313)
+++ trunk/source/main/cAvidaDriver_Population.h	2005-09-16 02:10:20 UTC (rev 314)
@@ -0,0 +1,52 @@
+//////////////////////////////////////////////////////////////////////////////
+// Copyright (C) 1993 - 2003 California Institute of Technology             //
+//                                                                          //
+// Read the COPYING and README files, or contact 'avida at alife.org',         //
+// before continuing.  SOME RESTRICTIONS MAY APPLY TO USE OF THIS FILE.     //
+//////////////////////////////////////////////////////////////////////////////
+
+#ifndef AVIDA_DRIVER_POPULATION_HH
+#define AVIDA_DRIVER_POPULATION_HH
+
+#ifndef AVIDA_DRIVER_BASE_HH
+#include "cAvidaDriver_Base.h"
+#endif
+#ifndef STRING_HH
+#include "string.hh"
+#endif
+
+class cEnvironment;
+class cEventFactoryManager;
+class cEventList;
+class cString;
+class cChangeList;
+class cPopulation;
+
+class cAvidaDriver_Population : public cAvidaDriver_Base {
+protected:
+  cPopulation * population;
+  cEventFactoryManager * event_manager;
+  cEventList * event_list;
+
+public:
+  cPopulation &GetPopulation(){ return *population; }
+
+  void GetEvents();
+  /**
+   * Processes one complete update.
+   *
+   * Returns true when finished.
+   **/
+  virtual bool ProcessUpdate();
+  virtual void ProcessOrganisms();
+  void ReadEventListFile(const cString & filename="event_list");
+  void SyncEventList();
+			
+  cAvidaDriver_Population(cEnvironment & environment, cChangeList * change_list = 0);
+  virtual ~cAvidaDriver_Population();
+
+  virtual void Run();
+  virtual void NotifyUpdate();
+};
+
+#endif

Copied: trunk/source/main/cAvidaTriggers.h (from rev 313, trunk/source/main/avida_triggers.hh)

Copied: trunk/source/main/cBirthChamber.cc (from rev 313, trunk/source/main/birth_chamber.cc)
===================================================================
--- trunk/source/main/birth_chamber.cc	2005-09-15 23:16:19 UTC (rev 313)
+++ trunk/source/main/cBirthChamber.cc	2005-09-16 02:10:20 UTC (rev 314)
@@ -0,0 +1,668 @@
+//////////////////////////////////////////////////////////////////////////////
+// Copyright (C) 1993 - 2004 California Institute of Technology             //
+//                                                                          //
+// Read the COPYING and README files, or contact 'avida at alife.org',         //
+// before continuing.  SOME RESTRICTIONS MAY APPLY TO USE OF THIS FILE.     //
+//////////////////////////////////////////////////////////////////////////////
+
+#ifndef BIRTH_CHAMBER_HH
+#include "cBirthChamber.h"
+#endif
+
+#ifndef TARRAY_HH
+#include "tArray.hh"
+#endif
+#ifndef CONFIG_HH
+#include "cConfig.h"
+#endif
+#ifndef FUNCTIONS_HH
+#include "functions.hh"
+#endif
+#ifndef  GENEBANK_HH
+#include "genebank.hh"
+#endif
+#ifndef GENOME_HH
+#include "genome.hh"
+#endif
+#ifndef GENOME_UTIL_HH
+#include "genome_util.hh"
+#endif
+#ifndef  GENOTYPE_HH
+#include "genotype.hh"
+#endif
+#ifndef ORGANISM_HH
+#include "organism.hh"
+#endif
+#ifndef TOOLS_HH
+#include "tools.hh"
+#endif
+
+cBirthChamber::cBirthChamber()
+  : genebank(NULL)
+{
+  const int num_orgs = cConfig::GetWorldX()*cConfig::GetWorldY();
+  const int num_demes = cConfig::GetNumDemes(); 
+  local_wait_entry.Resize(num_orgs);
+  deme_wait_entry.Resize(num_demes);
+  for (int i = 0; i < num_orgs; i++) {
+    local_wait_entry[i].is_waiting = false;
+  }
+  for (int i = 0; i < num_demes; i++) {
+    deme_wait_entry[i].is_waiting = false;
+  }
+  global_wait_entry.is_waiting = false;
+}
+
+cBirthChamber::~cBirthChamber()
+{
+}
+
+bool cBirthChamber::GetNeighborWaiting(const int & parent_id,
+				       int world_x,
+				       int world_y)
+{
+  for (int i=-1; i<=1; i++) {
+    for (int j=-1; j<=1; j++) { 
+      const int neighbor_id = GridNeighbor(parent_id, world_x, world_y, i, j);
+      if (local_wait_entry[neighbor_id].is_waiting == true) {
+	return true;
+      }
+    }
+  }
+  return false;
+}
+
+
+int cBirthChamber::PickRandRecGenome(const int & parent_id, 
+				     int world_x,
+				     int world_y)
+{
+  bool done = false; 
+  while (done ==false) {
+    int test_neighbor = (int) g_random.GetUInt(9); 
+    int i = test_neighbor / 3 - 1; 
+    int j = test_neighbor % 3 - 1;
+    int test_loc = GridNeighbor(parent_id,world_x, world_y, i, j); 		
+    if (local_wait_entry[test_loc].is_waiting == true) {
+      return test_loc;
+    }
+  }
+
+  return -1;
+}
+
+bool cBirthChamber::RegionSwap(cCPUMemory & genome0, 
+			       cCPUMemory & genome1,
+			       int start0, int end0, 
+			       int start1, int end1)
+{
+   assert( start0 >= 0  &&  start0 < genome0.GetSize() );
+   assert( end0   >= 0  &&  end0   < genome0.GetSize() );
+   assert( start1 >= 0  &&  start1 < genome1.GetSize() );
+   assert( end1   >= 0  &&  end1   < genome1.GetSize() );
+            
+   // Calculate size of sections crossing over...
+   int size0 = end0 - start0;
+   int size1 = end1 - start1;
+            
+   int new_size0 = genome0.GetSize() - size0 + size1;
+   int new_size1 = genome1.GetSize() - size1 + size0;
+      
+   // Don't Crossover if offspring will be illegal!!!
+   if( new_size0 < MIN_CREATURE_SIZE || new_size0 > MAX_CREATURE_SIZE ||
+       new_size1 < MIN_CREATURE_SIZE || new_size1 > MAX_CREATURE_SIZE ){
+     return false;
+   } 
+
+   if (size0 > 0 && size1 > 0) {
+     cGenome cross0 = cGenomeUtil::Crop(genome0, start0, end0);
+     cGenome cross1 = cGenomeUtil::Crop(genome1, start1, end1);
+     genome0.Replace(start0, size0, cross1);
+     genome1.Replace(start1, size1, cross0);
+   }
+   else if (size0 > 0) {
+     cGenome cross0 = cGenomeUtil::Crop(genome0, start0, end0);
+     genome1.Replace(start1, size1, cross0);
+   }
+   else if (size1 > 0) {
+     cGenome cross1 = cGenomeUtil::Crop(genome1, start1, end1);
+     genome0.Replace(start0, size0, cross1);
+   }
+
+   return true;
+}
+
+bool cBirthChamber::GenomeSwap(cCPUMemory & genome0,
+	                       cCPUMemory & genome1,
+                  	       double & merit0,
+                  	       double & merit1)
+{
+  cCPUMemory & genome0_tmp = genome0;
+  genome0 = genome1; 
+  genome1 = genome0_tmp; 
+
+  double & merit0_tmp = merit0; 
+  merit0 = merit1; 
+  merit1 = merit0_tmp;
+
+	// This had no return value, added 9/23/2004 DMB
+  return true;
+}
+
+
+bool cBirthChamber::DoAsexBirth(const cGenome & child_genome,
+				cOrganism & parent,
+				tArray<cOrganism *> & child_array,
+				tArray<cMerit> & merit_array)
+{
+  const cPopulationInterface & pop_interface = parent.PopInterface();
+  const cEnvironment & environment = parent.GetPhenotype().GetEnvironment();
+
+  // This is asexual who doesn't need to wait in the birth chamber
+  // just build the child and return.
+  child_array.Resize(1);
+  child_array[0] = new cOrganism(child_genome, pop_interface, environment);
+  merit_array.Resize(1);
+  merit_array[0] = parent.GetPhenotype().GetMerit();
+
+  // Setup the genotype for the child
+  cGenotype * child_genotype = parent.GetGenotype();
+  
+  if (parent.GetPhenotype().CopyTrue() == false) {
+    // Add this genotype with only one parent since its asexual.
+    child_genotype = genebank->AddGenotype(child_genome,
+					   parent.GetGenotype(), NULL);
+  }
+
+  child_array[0]->SetGenotype(child_genotype);
+  parent.GetGenotype()->SetBreedStats(*child_genotype);
+    
+  child_genotype->IncDeferAdjust();
+
+  return true;
+}
+
+bool cBirthChamber::DoPairAsexBirth(const cBirthEntry & old_entry,
+				    const cGenome & new_genome,
+				    cOrganism & parent,
+				    tArray<cOrganism *> & child_array,
+				    tArray<cMerit> & merit_array)
+{
+  const cPopulationInterface & pop_interface = parent.PopInterface();
+  const cEnvironment & environment = parent.GetPhenotype().GetEnvironment();
+
+  // Build both child organisms...
+  child_array.Resize(2);
+  child_array[0] = new cOrganism(old_entry.genome, pop_interface, environment);
+  child_array[1] = new cOrganism(new_genome, pop_interface, environment);
+
+  // Setup the merits for both children...
+  merit_array.Resize(2);
+  merit_array[0] = old_entry.merit;
+  merit_array[1] = parent.GetPhenotype().GetMerit();
+
+  // Setup the genotypes for both children...
+  SetupGenotypeInfo(child_array[0], old_entry.parent_genotype, NULL);
+  SetupGenotypeInfo(child_array[1], parent.GetGenotype(), NULL);
+
+  // We are now also done with the parent genotype that we were saving in
+  // the birth chamber, so we can un-defer that one.
+
+  old_entry.parent_genotype->DecDeferAdjust();
+  genebank->AdjustGenotype(*old_entry.parent_genotype);
+
+  return true;
+}
+
+cBirthChamber::cBirthEntry *
+  cBirthChamber::FindSexSizeWaiting(const cGenome & child_genome,
+				    cOrganism & parent)
+{
+  const int child_length = child_genome.GetSize();
+
+  // If this is a new largest genome, increase the array size.
+  if (size_wait_entry.GetSize() <= child_length) {
+    int old_wait_size = size_wait_entry.GetSize();
+    size_wait_entry.Resize(child_length + 1);
+    for (int i = old_wait_size; i <= child_length; i++) {
+      size_wait_entry[i].is_waiting = false;
+    }
+  }
+
+  // Determine if we have an offspring of this length waiting already...
+  if (size_wait_entry[child_length].is_waiting == false) {
+    cGenotype * parent_genotype = parent.GetGenotype();
+    parent_genotype->IncDeferAdjust();
+    size_wait_entry[child_length].genome = child_genome;
+    size_wait_entry[child_length].merit = parent.GetPhenotype().GetMerit();
+    size_wait_entry[child_length].parent_genotype = parent_genotype;
+    size_wait_entry[child_length].is_waiting = true;
+    return NULL; 				
+  }
+
+  // There is already a child waiting -- do crossover between the two.
+  return &( size_wait_entry[child_length] ); 
+}
+
+cBirthChamber::cBirthEntry *
+  cBirthChamber::FindSexMateSelectWaiting(const cGenome & child_genome,
+					  cOrganism & parent)
+{
+  const int mate_id = parent.GetPhenotype().MateSelectID();
+
+  // If this is a new largest ID, increase the array size.
+  if (mate_select_wait_entry.GetSize() <= mate_id) {
+    int old_wait_size = mate_select_wait_entry.GetSize();
+    mate_select_wait_entry.Resize(mate_id + 1);
+    for (int i = old_wait_size; i <= mate_id; i++) {
+      mate_select_wait_entry[i].is_waiting = false;
+    }
+  }
+
+  // Determine if we have an offspring of this length waiting already...
+  if (mate_select_wait_entry[mate_id].is_waiting == false) {
+    cGenotype * parent_genotype = parent.GetGenotype();
+    parent_genotype->IncDeferAdjust();
+    mate_select_wait_entry[mate_id].genome = child_genome;
+    mate_select_wait_entry[mate_id].merit = parent.GetPhenotype().GetMerit();
+    mate_select_wait_entry[mate_id].parent_genotype = parent_genotype;
+    mate_select_wait_entry[mate_id].is_waiting = true;
+    return NULL;
+  }
+
+  // There is already a child waiting -- do crossover between the two.
+  return &( mate_select_wait_entry[mate_id] ); 
+}
+
+cBirthChamber::cBirthEntry *
+  cBirthChamber::FindSexLocalWaiting(const cGenome & child_genome,
+				   cOrganism & parent)
+{
+  // Collect some info for building the child.
+  const int world_x = cConfig::GetWorldX();
+  const int world_y = cConfig::GetWorldY();
+  const int parent_id = parent.PopInterface().GetCellID();
+  
+  // If nothing is waiting, store child locally.
+  if (GetNeighborWaiting(parent_id, world_x, world_y) == false) { 
+    cGenotype * parent_genotype = parent.GetGenotype();
+    parent_genotype->IncDeferAdjust();
+    local_wait_entry[parent_id].genome = child_genome;
+    local_wait_entry[parent_id].merit = parent.GetPhenotype().GetMerit();
+    local_wait_entry[parent_id].parent_genotype = parent_genotype;
+    local_wait_entry[parent_id].is_waiting = true;
+    return NULL; 				
+  }
+
+  // There is already a child waiting -- do crossover between the two.
+  int found_location = PickRandRecGenome(parent_id, world_x, world_y);
+  return &( local_wait_entry[found_location] ); 
+}
+
+cBirthChamber::cBirthEntry *
+  cBirthChamber::FindSexDemeWaiting(const cGenome & child_genome,
+				   cOrganism & parent)
+{
+  // Collect some info for building the child.
+  const int world_x = cConfig::GetWorldX();
+  const int world_y = cConfig::GetWorldY();
+  const int num_demes = cConfig::GetNumDemes();
+  const int parent_id = parent.PopInterface().GetCellID();
+  
+  const int parent_deme = (int) parent_id/(world_y*world_x/num_demes);
+
+  // If nothing is waiting, store child locally.
+  if (deme_wait_entry[parent_deme].is_waiting == false) { 
+    cGenotype * parent_genotype = parent.GetGenotype();
+    parent_genotype->IncDeferAdjust();
+    deme_wait_entry[parent_deme].genome = child_genome;
+    deme_wait_entry[parent_deme].merit = parent.GetPhenotype().GetMerit();
+    deme_wait_entry[parent_deme].parent_genotype = parent_genotype;
+    deme_wait_entry[parent_deme].is_waiting = true;
+    return NULL; 				
+  }
+
+  // There is already a child waiting -- do crossover between the two.
+  return &( deme_wait_entry[parent_deme] );
+
+}
+
+cBirthChamber::cBirthEntry * cBirthChamber::FindSexGlobalWaiting(const cGenome & child_genome,
+						  cOrganism & parent)
+{
+  // If no other child is waiting, store this one.
+  if (global_wait_entry.is_waiting == false){
+    cGenotype * parent_genotype = parent.GetGenotype();
+    parent_genotype->IncDeferAdjust();
+    global_wait_entry.genome = child_genome; 
+    global_wait_entry.merit = parent.GetPhenotype().GetMerit();
+    global_wait_entry.parent_genotype = parent_genotype;
+    global_wait_entry.is_waiting = true;
+    return NULL;
+  }
+
+  // There is already a child waiting -- do crossover between the two.
+
+  return &global_wait_entry;
+}
+
+void cBirthChamber::DoBasicRecombination(cCPUMemory & genome0,
+					 cCPUMemory & genome1, 
+					 double & merit0, double & merit1)
+{
+  double start_frac = g_random.GetDouble();
+  double end_frac = g_random.GetDouble();
+  if (start_frac > end_frac) nFunctions::Swap(start_frac, end_frac);
+    
+  // calculate the proportion of the genome  that will be swapped
+  double cut_frac = end_frac - start_frac;
+  double stay_frac = 1.0 - cut_frac;
+
+  int start0 = (int) (start_frac * (double) genome0.GetSize());
+  int end0   = (int) (end_frac * (double) genome0.GetSize());
+  int start1 = (int) (start_frac * (double) genome1.GetSize());
+  int end1   = (int) (end_frac * (double) genome1.GetSize());
+
+  RegionSwap(genome0, genome1, start0, end0, start1, end1);
+
+  // Adjust the merits....
+  double tmp_merit0 = merit0 * stay_frac + merit1 * cut_frac;
+  merit1 = merit1 * stay_frac + merit0 * cut_frac;
+  merit0 = tmp_merit0;
+
+  // Majority of the genome should stay in the offspring
+  if (stay_frac < cut_frac) {
+     GenomeSwap(genome0, genome1, merit0, merit1); 
+  } 
+}
+
+void cBirthChamber::DoModularContRecombination(cCPUMemory & genome0,
+					       cCPUMemory & genome1, 
+					       double & merit0,
+					       double & merit1)
+{
+  const int num_modules = cConfig::GetNumModules();
+
+  int start_module = (int) (g_random.GetDouble() * num_modules);
+  int end_module = (int) (g_random.GetDouble() * num_modules);
+
+  double start_frac = ((double) start_module) / (double) num_modules;
+  double end_frac = ((double) end_module) / (double) num_modules;
+
+  if (start_frac > end_frac) nFunctions::Swap(start_frac, end_frac);
+	    
+  // calculate the proportion of the genome  that will be swapped
+  double cut_frac = end_frac - start_frac;
+  double stay_frac = 1.0 - cut_frac;
+
+  int start0 = (int) (start_frac * (double) genome0.GetSize());
+  int end0   = (int) (end_frac * (double) genome0.GetSize());
+  int start1 = (int) (start_frac * (double) genome1.GetSize());
+  int end1   = (int) (end_frac * (double) genome1.GetSize());
+
+  RegionSwap(genome0, genome1, start0, end0, start1, end1);
+
+  // Adjust the merits....
+  double tmp_merit0 = merit0 * stay_frac + merit1 * cut_frac;
+  merit1 = merit1 * stay_frac + merit0 * cut_frac;
+  merit0 = tmp_merit0;
+
+  // Majority of the genome should stay in the offspring
+  if (stay_frac < cut_frac) {
+     GenomeSwap(genome0, genome1, merit0, merit1); 
+  } 
+}
+
+void cBirthChamber::DoModularNonContRecombination(cCPUMemory & genome0,
+						  cCPUMemory & genome1, 
+						  double & merit0,
+						  double & merit1)
+{
+  const int num_modules = cConfig::GetNumModules();
+
+  int swap_count = 0;
+  for (int i = 0; i < num_modules; i++) {
+    if (g_random.GetDouble() < 0.5) {
+      swap_count++;
+      double start_frac = ((double) i) / (double) num_modules;
+      double end_frac = ((double) i+1) / (double) num_modules;
+      int start0 = (int) (start_frac * (double) genome0.GetSize());
+      int end0   = (int) (end_frac * (double) genome0.GetSize());
+      int start1 = (int) (start_frac * (double) genome1.GetSize());
+      int end1   = (int) (end_frac * (double) genome1.GetSize());
+
+      RegionSwap(genome0, genome1, start0, end0, start1, end1);  
+    }
+  }
+
+  double cut_frac = ((double) swap_count) / (double) num_modules;
+  double stay_frac = 1.0 - cut_frac;
+
+  // Adjust the merits....
+  double tmp_merit0 = merit0 * stay_frac + merit1 * cut_frac;
+  merit1 = merit1 * stay_frac + merit0 * cut_frac;
+  merit0 = tmp_merit0;
+
+  // Majority of the genome should stay in the offspring
+  if (stay_frac < cut_frac) {
+     GenomeSwap(genome0, genome1, merit0, merit1); 
+  } 
+}
+
+void cBirthChamber::DoModularShuffleRecombination(cCPUMemory & genome0,
+						  cCPUMemory & genome1, 
+						  double & merit0,
+						  double & merit1)
+{
+  const int num_modules = cConfig::GetNumModules();
+  tArray<bool> swapped_region(num_modules);
+  swapped_region.SetAll(false);
+
+  int swap_count = 0;
+  for (int mod0 = 0; mod0 < num_modules; mod0++) {
+    if (g_random.GetDouble() < 0.5) {
+      swap_count++;
+
+      // Collect start and end info for current module
+      double start0_frac = ((double) mod0) / (double) num_modules;
+      double end0_frac = ((double) mod0+1) / (double) num_modules;
+      int start0 = (int) (start0_frac * (double) genome0.GetSize());
+      int end0   = (int) (end0_frac * (double) genome0.GetSize());
+
+      // Pick module from other genome...
+      int mod1 = g_random.GetUInt(num_modules);
+      while (swapped_region[mod1] == true) {
+	mod1 = g_random.GetUInt(num_modules);
+      }
+      swapped_region[mod1] = true;
+
+      // Collect start and end info for other module
+      double start1_frac = ((double) mod1) / (double) num_modules;
+      double end1_frac = ((double) mod1+1) / (double) num_modules;
+      int start1 = (int) (start1_frac * (double) genome1.GetSize());
+      int end1   = (int) (end1_frac * (double) genome1.GetSize());
+
+      // Do the swap.
+      RegionSwap(genome0, genome1, start0, end0, start1, end1);  
+    }
+  }
+
+  double cut_frac = ((double) swap_count) / (double) num_modules;
+  double stay_frac = 1.0 - cut_frac;
+
+  // Adjust the merits....
+  double tmp_merit0 = merit0 * stay_frac + merit1 * cut_frac;
+  merit1 = merit1 * stay_frac + merit0 * cut_frac;
+  merit0 = tmp_merit0;
+
+  // Majority of the genome should stay in the offspring
+  if (stay_frac < cut_frac) {
+     GenomeSwap(genome0, genome1, merit0, merit1); 
+  } 
+}
+
+
+void cBirthChamber::SetupGenotypeInfo(cOrganism * organism,
+				      cGenotype * parent0_genotype,
+				      cGenotype * parent1_genotype)
+{
+  // Setup the genotypes for both children...
+  cGenotype * child_genotype =
+    genebank->AddGenotype(organism->GetGenome(),
+			  parent0_genotype, parent1_genotype);
+
+  organism->SetGenotype(child_genotype);
+
+  parent0_genotype->SetBreedStats(*child_genotype);
+  
+  // Defer the child genotype from being adjusted until after the child
+  // has been placed into the population.
+
+  child_genotype->IncDeferAdjust();
+}
+
+bool cBirthChamber::SubmitOffspring(const cGenome & child_genome,
+				    cOrganism & parent,
+				    tArray<cOrganism *> & child_array,
+				    tArray<cMerit> & merit_array)
+{
+  assert(genebank != NULL);
+
+  cPhenotype & parent_phenotype = parent.GetPhenotype();
+
+  if (parent_phenotype.DivideSex() == false) {
+    return DoAsexBirth(child_genome, parent, child_array, merit_array);
+  }
+
+  // If we make it this far, this must be a sexual or a "waiting" asexual
+  // organism (which is the same as sexual with 0 recombination points)
+
+  // Find a waiting entry (locally or globally)
+  cBirthEntry * old_entry = NULL;
+  // First check if the birth method is one of the local ones... 
+  if (cConfig::GetBirthMethod() < NUM_LOCAL_POSITION_CHILD) { 
+    old_entry = FindSexLocalWaiting(child_genome, parent);
+  }
+  // ... then check if population is split into demes
+  else if (cConfig::GetBirthMethod() == POSITION_CHILD_DEME_RANDOM) {
+    old_entry = FindSexDemeWaiting(child_genome, parent);
+  }
+
+  // If none of the previous conditions were met, it must be global.
+  // ...check if recombination must be with organisms of the same length
+  else if (cConfig::GetSameLengthSex() != 0) {
+    old_entry = FindSexSizeWaiting(child_genome, parent);
+  }
+
+  // ...check if we have mate selection
+  else if (parent_phenotype.MateSelectID() >= 0) {
+    old_entry = FindSexMateSelectWaiting(child_genome, parent);
+  }
+
+  // If everything failed until this point, use default global.
+  else {
+    old_entry = FindSexGlobalWaiting(child_genome, parent);
+  }
+
+  // If we couldn't find a waiting entry, this one was saved -- stop here!
+  if (old_entry == NULL) {
+    return false;
+  }
+
+  // We have now found a waiting entry.  Mark it no longer waiting and use it.
+  old_entry->is_waiting = false;
+
+  // If we are NOT recombining, handle that here.
+  if (parent_phenotype.CrossNum() == 0 || 
+      g_random.GetDouble() > cConfig::GetRecombProb()) {
+    return DoPairAsexBirth(*old_entry, child_genome, parent, 
+			   child_array, merit_array);
+  }
+
+  // If we made it this far, RECOMBINATION will happen!
+  cCPUMemory genome0 = old_entry->genome;
+  cCPUMemory genome1 = child_genome;
+  double merit0 = old_entry->merit.GetDouble();
+  double merit1 = parent_phenotype.GetMerit().GetDouble();
+
+
+  // Check the modular recombination settings.  There are three variables:
+  //  1: How many modules?  (0 = non-modular)
+  //  2: Are the recombination regions continuous? (only used if modular)
+  //  3: Can modules be shuffled during recombination? (only if non-continuous)
+
+  const int num_modules = cConfig::GetNumModules();
+  const int continuous_regions = cConfig::GetContRecRegs();
+  const int shuffle_regions = !cConfig::GetCorespondRecRegs();
+
+  // If we are NOT modular...
+  if (num_modules == 0) {
+    DoBasicRecombination(genome0, genome1, merit0, merit1);
+  }
+
+  // If we ARE modular, and continuous...
+  else if (continuous_regions == 1) {
+    DoModularContRecombination(genome0, genome1, merit0, merit1);
+  }
+
+  // If we are NOT continuous, but NO shuffling...
+  else if (shuffle_regions == 0) {
+    DoModularNonContRecombination(genome0, genome1, merit0, merit1);
+  }
+
+  // If there IS shuffling (NON-continuous required)
+  else {
+    DoModularShuffleRecombination(genome0, genome1, merit0, merit1);
+  }
+
+  // Should there be a 2-fold cost to sex?
+
+  const int two_fold_cost = cConfig::GetTwoFoldCostSex();
+  const cPopulationInterface & pop_interface = parent.PopInterface();
+  const cEnvironment & environment = parent_phenotype.GetEnvironment();
+
+  cGenotype * parent0_genotype = old_entry->parent_genotype;
+  cGenotype * parent1_genotype = parent.GetGenotype();
+
+  if (two_fold_cost == 0) {	// Build the two organisms.
+    child_array.Resize(2);
+    child_array[0] = new cOrganism(genome0, pop_interface, environment);
+    child_array[1] = new cOrganism(genome1, pop_interface, environment);
+    
+    merit_array.Resize(2);
+    merit_array[0] = merit0;
+    merit_array[1] = merit1;
+
+    // Setup the genotypes for both children...
+    SetupGenotypeInfo(child_array[0], parent0_genotype, parent1_genotype);
+    SetupGenotypeInfo(child_array[1], parent1_genotype, parent0_genotype);
+
+  }
+  else { 			// Build only one organism	
+    child_array.Resize(1);
+    merit_array.Resize(1);
+
+    if (g_random.GetDouble() < 0.5) {
+      child_array[0] = new cOrganism(genome0, pop_interface, environment);
+      merit_array[0] = merit0;
+
+      // Setup the genotype for the child...
+      SetupGenotypeInfo(child_array[0], parent0_genotype, parent1_genotype);
+    } 
+    else {
+      child_array[0] = new cOrganism(genome1, pop_interface, environment);
+      merit_array[0] = merit1;
+
+      // Setup the genotype for the child...
+      SetupGenotypeInfo(child_array[0], parent1_genotype, parent0_genotype);
+    }
+  } 
+
+  // We are now also done with the parent genotype that we were saving in
+  // the birth chamber, so we can un-defer that one.
+  parent0_genotype->DecDeferAdjust();
+  genebank->AdjustGenotype(*parent0_genotype);
+
+  return true;
+}
+

Copied: trunk/source/main/cBirthChamber.h (from rev 313, trunk/source/main/birth_chamber.hh)

Copied: trunk/source/main/cCallbackUtil.cc (from rev 313, trunk/source/main/callback_util.cc)
===================================================================
--- trunk/source/main/callback_util.cc	2005-09-15 23:16:19 UTC (rev 313)
+++ trunk/source/main/cCallbackUtil.cc	2005-09-16 02:10:20 UTC (rev 314)
@@ -0,0 +1,276 @@
+//////////////////////////////////////////////////////////////////////////////
+// Copyright (C) 1993 - 2003 California Institute of Technology             //
+//                                                                          //
+// Read the COPYING and README files, or contact 'avida at alife.org',         //
+// before continuing.  SOME RESTRICTIONS MAY APPLY TO USE OF THIS FILE.     //
+//////////////////////////////////////////////////////////////////////////////
+
+#ifndef CALLBACK_UTIL_HH
+#include "cCallbackUtil.h"
+#endif
+
+#ifndef AVIDA_HH
+#include "avida.hh"
+#endif
+#ifndef AVIDA_DRIVER_BASE_HH
+#include "cAvidaDriver_Base.h"
+#endif
+#ifndef BIRTH_CHAMBER_HH
+#include "cBirthChamber.h"
+#endif
+#ifndef CONFIG_HH
+#include "cConfig.h"
+#endif
+#ifndef ENVIRONMENT_HH
+#include "cEnvironment.h"
+#endif
+#ifndef GENOTYPE_HH
+#include "genotype.hh"
+#endif
+#ifndef HARDWARE_BASE_HH
+#include "cHardwareBase.h"
+#endif
+#ifndef HARDWARE_FACTORY_HH
+#include "cHardwareFactory.h"
+#endif
+#ifndef ORG_MESSAGE_HH
+#include "org_message.hh"
+#endif
+#ifndef ORGANISM_HH
+#include "organism.hh"
+#endif
+#ifndef POPULATION_HH
+#include "population.hh"
+#endif
+#ifndef POPULATION_CELL_HH
+#include "population_cell.hh"
+#endif
+#ifndef POPULATION_INTERFACE_HH
+#include "cPopulationInterface.h"
+#endif
+#ifndef TEST_CPU_HH
+#include "cTestCPU.h"
+#endif
+
+
+using namespace std;
+
+
+cHardwareBase * cCallbackUtil::CB_NewHardware(cPopulation * pop,
+					      cOrganism * owner)
+{
+  cInstSet * inst_set;
+
+  // Determine which inst_set we should be using...
+  // If we're in a population, setup the inst_set properly.
+  if (pop != NULL) inst_set = &(pop->GetEnvironment().GetInstSet());
+
+  // Otherwise, use the test inst lib...
+  else inst_set = cTestCPU::GetInstSet();
+
+  // For the moment, we only have one hardware type...
+  assert(inst_set != NULL && inst_set->OK());
+  cHardwareBase * new_hardware =
+    cHardwareFactory::Create(owner, inst_set, cConfig::GetHardwareType());
+
+  return new_hardware;
+}
+
+
+void cCallbackUtil::CB_RecycleHardware(cHardwareBase * out_hardware)
+{
+  cHardwareFactory::Recycle(out_hardware);
+}
+
+
+// Callback for a divide inside of a population.  Return parent alive.
+bool cCallbackUtil::CB_Divide(cPopulation * pop, int cell_id,
+			      cOrganism * parent, cGenome & child_genome)
+{
+  assert(pop != NULL);
+  assert(parent != NULL);
+  assert(pop->GetCell(cell_id).GetOrganism() == parent);
+
+  return pop->ActivateOffspring(child_genome, *parent);
+}
+
+
+// Callback for a divide outside of a population
+bool cCallbackUtil::CB_TestDivide(cPopulation * pop, int cell_id,
+				  cOrganism * parent, cGenome & child_genome)
+{
+  assert(pop == NULL);  // Must not be in a population...
+
+  // Reset the parent from the divide
+  parent->GetPhenotype().TestDivideReset(parent->GetGenome().GetSize());
+
+  // @CAO in the future, we probably want to pass this child the test_cpu!
+
+  return true;
+}
+
+// Callback to find out if we need to run a test CPU on all divides...
+bool cCallbackUtil::CB_TestOnDivide(cPopulation * pop, int cell_id)
+{
+  assert(pop != NULL); // Must be in a population...
+  return cConfig::GetTestOnDivide();
+}
+
+cOrganism * cCallbackUtil::CB_GetNeighbor(cPopulation * pop, int cell_id)
+{
+  assert(pop != NULL);
+  cPopulationCell & cell = pop->GetCell(cell_id);
+  assert(cell.IsOccupied());
+
+  return cell.ConnectionList().GetFirst()->GetOrganism();
+}
+
+
+int cCallbackUtil::CB_GetNumNeighbors(cPopulation * pop, int cell_id)
+{
+  assert(pop != NULL);
+  cPopulationCell & cell = pop->GetCell(cell_id);
+  assert(cell.IsOccupied());
+
+  return cell.ConnectionList().GetSize();
+}
+
+
+void cCallbackUtil::CB_Rotate(cPopulation * pop, int cell_id,
+				    int direction)
+{
+  assert(pop != NULL);
+  cPopulationCell & cell = pop->GetCell(cell_id);
+  assert(cell.IsOccupied());
+
+  if (direction >= 0) cell.ConnectionList().CircNext();
+  else cell.ConnectionList().CircPrev();
+}
+
+
+void cCallbackUtil::CB_Breakpoint()
+{
+  cAvidaDriver_Base::main_driver->SignalBreakpoint();
+}
+
+
+double cCallbackUtil::CB_TestFitness(cPopulation * pop, int cell_id)
+{
+  assert(pop != NULL);
+  cPopulationCell & cell = pop->GetCell(cell_id);
+  assert(cell.IsOccupied());
+
+  return cell.GetOrganism()->GetGenotype()->GetTestFitness();
+}
+
+
+int cCallbackUtil::CB_GetInput(cPopulation * pop, int cell_id)
+{
+  if (pop == NULL) return cTestCPU::GetInput();
+  cPopulationCell & cell = pop->GetCell(cell_id);
+  assert(cell.IsOccupied());
+  return cell.GetInput();
+}
+
+int cCallbackUtil::CB_GetInputAt(cPopulation * pop, int cell_id, int & input_pointer)
+{
+  if (pop == NULL) return cTestCPU::GetInputAt(input_pointer);
+  cPopulationCell & cell = pop->GetCell(cell_id);
+  assert(cell.IsOccupied());
+  return cell.GetInputAt(input_pointer);
+}
+
+int cCallbackUtil::CB_Debug(cPopulation * pop, int cell_id)
+{
+  if (pop == NULL) return -1;
+  cPopulationCell & cell = pop->GetCell(cell_id);
+  assert(cell.IsOccupied());
+  return cell.GetOrganism()->GetGenotype()->GetID();
+}
+
+
+const tArray<double> &
+cCallbackUtil::CB_GetResources(cPopulation * pop, int cell_id)
+{
+  if (pop == NULL) return cTestCPU::GetResources();
+
+  // @CAO for the moment, ignore the possibility of local resources...
+  return pop->GetCellResources(cell_id);
+}
+
+
+void cCallbackUtil::CB_UpdateResources(cPopulation * pop, int cell_id,
+				       const tArray<double> & res_change)
+{
+  if (pop == NULL) return cTestCPU::UpdateResources(res_change);
+
+  // @CAO for the moment, ignore the possibility of local resources...
+  return pop->UpdateCellResources(res_change, cell_id);
+}
+
+
+void cCallbackUtil::CB_KillCell(cPopulation * pop, int death_id)
+{
+  assert(pop != NULL);
+  cPopulationCell & death_cell = pop->GetCell(death_id);
+  pop->KillOrganism(death_cell);
+}
+
+void cCallbackUtil::CB_KillSurroundCell(cPopulation * pop, int commie_id)
+{
+	assert (pop != NULL);
+	cPopulationCell & death_cell = pop->GetCell(commie_id);
+	pop->Kaboom(death_cell);
+}
+
+bool cCallbackUtil::CB_SendMessage(cPopulation * pop, int cell_id, cOrgMessage & mess)
+{
+  mess.SetSenderID(cell_id);
+  mess.SetTime(pop->GetUpdate());
+  cPopulationCell & cell = pop->GetCell(cell_id);
+  if(cell.ConnectionList().GetFirst() == NULL)
+    return false;
+  mess.SetRecipientID(cell.ConnectionList().GetFirst()->GetID());
+  return cell.ConnectionList().GetFirst()->GetOrganism()->ReceiveMessage(mess);
+}
+
+int cCallbackUtil::CB_ReceiveValue(cPopulation * pop, int cell_id)
+{
+  if (pop == NULL) return cTestCPU::GetReceiveValue();
+
+  cPopulationCell & cell = pop->GetCell(cell_id);
+  assert(cell.IsOccupied());
+
+  const int num_neighbors = cell.ConnectionList().GetSize();
+  for (int i = 0; i < num_neighbors; i++) {
+	cPopulationCell & cell = pop->GetCell(cell_id);
+	cell.ConnectionList().CircNext();
+
+    cOrganism * cur_neighbor = cell.ConnectionList().GetFirst()->GetOrganism();
+    if (cur_neighbor == NULL || cur_neighbor->GetSentActive() == false) {
+      continue;
+    }
+
+    return cur_neighbor->RetrieveSentValue();
+  }
+
+  return 0;
+
+}
+
+bool cCallbackUtil::CB_InjectParasite(cPopulation * pop, int cell_id, cOrganism * parent,
+				      const cGenome & injected_code)
+{
+  assert(pop != NULL);
+  assert(parent != NULL);
+  assert(pop->GetCell(cell_id).GetOrganism() == parent);
+
+  return pop->ActivateInject(*parent, injected_code);
+}
+
+bool cCallbackUtil::CB_UpdateMerit(cPopulation * pop, int cell_id,
+				   double new_merit)
+{
+  assert(pop != NULL);
+  return pop->UpdateMerit(cell_id, new_merit);
+}

Copied: trunk/source/main/cCallbackUtil.h (from rev 313, trunk/source/main/callback_util.hh)

Copied: trunk/source/main/cConfig.cc (from rev 313, trunk/source/main/config.cc)
===================================================================
--- trunk/source/main/config.cc	2005-09-15 23:16:19 UTC (rev 313)
+++ trunk/source/main/cConfig.cc	2005-09-16 02:10:20 UTC (rev 314)
@@ -0,0 +1,683 @@
+//////////////////////////////////////////////////////////////////////////////
+// Copyright (C) 1993 - 2003 California Institute of Technology             //
+//                                                                          //
+// Read the COPYING and README files, or contact 'avida at alife.org',         //
+// before continuing.  SOME RESTRICTIONS MAY APPLY TO USE OF THIS FILE.     //
+//////////////////////////////////////////////////////////////////////////////
+
+#include "cConfig.h"
+
+#include "defs.hh"
+#include "cEventFactoryManager.h"
+#include "genesis.hh"
+#include "cPopulationEventFactory.h"
+#include "tools.hh"
+
+using namespace std;
+
+tList<cConfig::cConfigGroup> cConfig::group_list;
+bool cConfig::analyze_mode;
+bool cConfig::primitive_mode;
+bool cConfig::interactive_analyze;
+cString cConfig::default_dir;
+cString cConfig::genesis_filename;
+cString cConfig::inst_filename;
+cString cConfig::event_filename;
+cString cConfig::analyze_filename;
+cString cConfig::env_filename;
+cString cConfig::start_creature;
+cString cConfig::clone_filename;
+cString cConfig::load_pop_filename;
+int cConfig::max_updates;
+int cConfig::max_generations;
+int cConfig::end_condition_mode;
+int cConfig::world_x;
+int cConfig::world_y;
+int cConfig::world_geometry;
+int cConfig::num_demes;
+int cConfig::rand_seed;
+double cConfig::point_mut_prob;
+double cConfig::copy_mut_prob;
+double cConfig::ins_mut_prob;
+double cConfig::del_mut_prob;
+double cConfig::div_mut_prob;
+double cConfig::divide_mut_prob;
+double cConfig::divide_ins_prob;
+double cConfig::divide_del_prob;
+double cConfig::parent_mut_prob;
+int cConfig::special_mut_line;
+double cConfig::recomb_prob;
+int cConfig::num_modules;
+int cConfig::cont_rec_regs;
+int cConfig::corespond_rec_regs;
+int cConfig::two_fold_cost_sex;
+int cConfig::same_length_sex;
+int cConfig::num_instructions;
+int cConfig::hardware_type;
+int cConfig::max_cpu_threads;
+double cConfig::thread_slicing_method;
+int cConfig::size_merit_method;
+int cConfig::base_size_merit;
+double cConfig::default_bonus;
+int cConfig::task_merit_method;
+int cConfig::max_label_exe_size;
+int cConfig::merit_time;
+double cConfig::merit_given;
+double cConfig::merit_received;
+int cConfig::max_donate_kin_distance;
+int cConfig::max_donate_edit_distance;
+int cConfig::max_donates;
+int cConfig::num_tasks;
+int cConfig::num_reactions;
+int cConfig::num_resources;
+int cConfig::slicing_method;
+int cConfig::birth_method;
+int cConfig::prefer_empty;
+int cConfig::death_method;
+int cConfig::alloc_method;
+int cConfig::divide_method;
+int cConfig::required_task;
+int cConfig::immunity_task;
+int cConfig::required_reaction;
+int cConfig::lineage_creation_method;
+int cConfig::generation_inc_method;
+int cConfig::age_limit;
+double cConfig::age_deviation;
+double cConfig::child_size_range;
+double cConfig::min_copied_lines;
+double cConfig::min_exe_lines;
+int cConfig::require_allocate;
+bool cConfig::test_on_divide;
+bool cConfig::test_sterilize;
+double cConfig::revert_fatal;
+double cConfig::revert_neg;
+double cConfig::revert_neut;
+double cConfig::revert_pos;
+double cConfig::sterilize_fatal;
+double cConfig::sterilize_neg;
+double cConfig::sterilize_neut;
+double cConfig::sterilize_pos;
+int cConfig::fail_implicit;
+int cConfig::ave_time_slice;
+int cConfig::species_threshold;
+int cConfig::threshold;
+int cConfig::genotype_print;
+int cConfig::species_print;
+int cConfig::species_recording;
+int cConfig::genotype_print_dom;
+int cConfig::test_cpu_time_mod;
+int cConfig::track_main_lineage;
+bool cConfig::log_threshold_only;
+bool cConfig::log_creatures;
+int cConfig::log_genotypes;
+bool cConfig::log_threshold;
+bool cConfig::log_species;
+bool cConfig::log_landscape;
+bool cConfig::log_lineages;
+int cConfig::debug_level;
+int cConfig::view_mode;
+double cConfig::die_prob;
+
+void cConfig::InitGroupList(){
+  // Start with the Architecture variables...
+  cConfigGroup * arch_group = new cConfigGroup("Architecture Variables");
+  group_list.PushRear(arch_group);
+  
+  arch_group->Add(max_updates, "-1", "MAX_UPDATES",
+                  "Maximum updates to run experiment (-1 = no limit)");
+  arch_group->Add(max_generations, "-1", "MAX_GENERATIONS",
+                  "Maximum generations to run experiment (-1 = no limit)");
+  arch_group->Add(end_condition_mode, "0", "END_CONDITION_MODE",
+                  "End run when ...\n0 = MAX_UPDATES _OR_ MAX_GENERATIONS is reached\n1 = MAX_UPDATES _AND_ MAX_GENERATIONS is reached");
+  arch_group->Add(world_x, "100", "WORLD-X",
+                  "Width of the Avida world");
+  arch_group->Add(world_y, "100", "WORLD-Y",
+                  "Height of the Avida world");
+  arch_group->Add(world_geometry, "2", "WORLD_GEOMETRY",
+                  "1 = Bounded Grid\n2 = Torus");
+  arch_group->Add(num_demes, "0", "NUM_DEMES",
+                  "Number of independed groups in the population; 0=off");
+  arch_group->Add(rand_seed, "0", "RANDOM_SEED",
+                  "Random number seed (0 for based on time)");
+  arch_group->Add(hardware_type, "0", "HARDWARE_TYPE",
+                  "0 = Original CPUs\n1 = New, Stack-based CPUs");
+  
+  // Configuration file group.
+  cConfigGroup * file_group = new cConfigGroup("Configuration Files");
+  group_list.PushRear(file_group);
+  
+  file_group->Add(default_dir, DEFAULT_DIR, "DEFAULT_DIR",
+                  "Directory in which config files are found");
+  file_group->Add(inst_filename, "inst_set.default", "INST_SET",
+                  "File containing instruction set");
+  file_group->Add(event_filename, "events.cfg", "EVENT_FILE",
+                  "File containing list of events during run");
+  file_group->Add(analyze_filename, "analyze.cfg", "ANALYZE_FILE",
+                  "File used for analysis mode");
+  file_group->Add(env_filename, "environment.cfg", "ENVIRONMENT_FILE",
+                  "File that describes the environment");
+  file_group->Add(start_creature, "organism.default", "START_CREATURE",
+                  "Organism to seed the soup");
+  
+  // Reproduction group.
+  cConfigGroup * repro_group = new cConfigGroup("Birth and Death");
+  group_list.PushRear(repro_group);
+  
+  repro_group->Add(birth_method, "4", "BIRTH_METHOD",
+                   "0 = Replace random organism in neighborhood\n1 = Replace oldest organism in neighborhood\n2 = Replace largest Age/Merit in neighborhood\n3 = Place only in empty cells in neighborhood\n4 = Replace random from population (Mass Action)\n5 = Replace oldest in entire population (like Tierra)\n6 = Replace random within deme");
+  repro_group->Add(prefer_empty, "1", "PREFER_EMPTY",
+                   "Are empty cells given preference in offsping placement?");
+  repro_group->Add(death_method, "1", "DEATH_METHOD",
+                   "0 = Never die of old age.\n1 = Die when inst executed = AGE_LIMIT (+deviation)\n2 = Die when inst executed = length*AGE_LIMIT (+dev)");
+  repro_group->Add(age_limit, "20", "AGE_LIMIT",
+                   "Modifies DEATH_METHOD");
+  repro_group->Add(age_deviation, "0", "AGE_DEVIATION",
+                   "Creates a distribution around AGE_LIMIT");
+  repro_group->Add(alloc_method, "0", "ALLOC_METHOD",
+                   "0 = Allocated space is set to default instruction.\n1 = Set to section of dead genome (Necrophilia)\n2 = Allocated space is set to random instruction.");
+  repro_group->Add(divide_method, "1", "DIVIDE_METHOD",
+                   "0 = Divide leaves state of mother untouched.\n1 = Divide resets state of mother (after the divide, we have 2 children)\n2 = Divide resets state of current thread only(does not touch possible parasite threads)");
+  repro_group->Add(generation_inc_method, "1", "GENERATION_INC_METHOD",
+                   "0 = Only the generation of the child is\n    increased on divide.\n1 = Both the generation of the mother and child are\n    increased on divide (good with DIVIDE_METHOD 1).");
+  repro_group->Add(recomb_prob, "1", "RECOMBINATION_PROB",
+                   "probability that recombination will happen when div-sex is used");
+  repro_group->Add(num_modules, "0", "MODULE_NUM",
+                   "number of modules in the genome");
+  repro_group->Add(cont_rec_regs, "1", "CONT_REC_REGS",
+                   "are (modular) recombination regions continuous");
+  repro_group->Add(corespond_rec_regs, "1", "CORESPOND_REC_REGS",
+                   "are (modular) recombination regions swapped at random or with corresponding ones, by location");
+  repro_group->Add(two_fold_cost_sex, "0", "TWO_FOLD_COST_SEX",
+                   "1 = only one recombined offspring is born.\n2 = both offspring are born");
+  repro_group->Add(same_length_sex, "0", "SAME_LENGTH_SEX",
+                   "0 = recombine with any genome\n1 = only recombine w/ same length");
+  
+  
+  // Divide Restrictions Group.
+  cConfigGroup * div_group = new cConfigGroup("Divide Restrictions");
+  group_list.PushRear(div_group);
+  
+  div_group->Add(child_size_range, "2.0", "CHILD_SIZE_RANGE",
+                 "Maximal differential between child and parent sizes.");
+  div_group->Add(min_copied_lines, "0.5", "MIN_COPIED_LINES",
+                 "Code fraction which must be copied before divide.");
+  div_group->Add(min_exe_lines, "0.5", "MIN_EXE_LINES",
+                 "Code fraction which must be executed before divide.");
+  div_group->Add(require_allocate, "1", "REQUIRE_ALLOCATE",
+                 "Is a an allocate required before a divide? (0/1)");
+  div_group->Add(required_task, "-1", "REQUIRED_TASK",
+                 "Task ID required for successful divide.");
+  div_group->Add(immunity_task, "-1", "IMMUNITY_TASK",
+                 "Task providing immunity from the required task.");
+  div_group->Add(immunity_task, "-1", "IMMUNITY_TASK",
+		 "Task providing immunity from the required task.");
+  div_group->Add(required_reaction, "-1", "REQUIRED_REACTION",
+                 "Reaction ID required for successful divide.");
+  div_group->Add(die_prob, "0", "DIE_PROB",
+                 "probability of death when 'die' instruction is executed"); 
+  
+  
+  
+  // Mutations Group
+  cConfigGroup * muts_group = new cConfigGroup("Mutations");
+  group_list.PushRear(muts_group);
+  
+  muts_group->Add(point_mut_prob, "0.0", "POINT_MUT_PROB",
+                  "Mutation rate (per-location per update)");
+  muts_group->Add(copy_mut_prob, "0.0075", "COPY_MUT_PROB",
+                  "Mutation rate (per copy)");
+  muts_group->Add(ins_mut_prob, "0.0", "INS_MUT_PROB",
+                  "Insertion rate (per site, applied on divide)");
+  muts_group->Add(del_mut_prob, "0.0", "DEL_MUT_PROB",
+                  "Deletion rate (per site, applied on divide)");
+  muts_group->Add(div_mut_prob, "0.0", "DIV_MUT_PROB",
+                  "Mutation rate (per site, applied on divide)");
+  muts_group->Add(divide_mut_prob, "0.0", "DIVIDE_MUT_PROB",
+                  "Mutation rate (per divide)");
+  muts_group->Add(divide_ins_prob, "0.05", "DIVIDE_INS_PROB",
+                  "Insertion rate (per divide)");
+  muts_group->Add(divide_del_prob, "0.05", "DIVIDE_DEL_PROB",
+                  "Deletion rate (per divide)");
+  muts_group->Add(parent_mut_prob, "0.0", "PARENT_MUT_PROB",
+                  "Per-site, in parent, on divide");
+  muts_group->Add(special_mut_line, "-1", "SPECIAL_MUT_LINE",
+                  "If this is >= 0, ONLY this line is mutated");
+  
+  
+  // Mutation reversions group
+  cConfigGroup * rev_group = new cConfigGroup("Mutation Reversion");
+  rev_group->SetComment("These slow down avida a lot, and should be set to 0.0 normally.");
+  group_list.PushRear(rev_group);
+  
+  rev_group->Add(revert_fatal, "0.0", "REVERT_FATAL",
+                 "Should any mutations be reverted on birth?");
+  rev_group->Add(revert_neg, "0.0", "REVERT_DETRIMENTAL",
+                 "  0.0 to 1.0; Probability of reversion.");
+  rev_group->Add(revert_neut, "0.0", "REVERT_NEUTRAL",
+                 "");
+  rev_group->Add(revert_pos, "0.0", "REVERT_BENEFICIAL",
+                 "");
+  rev_group->Add(sterilize_fatal, "0.0", "STERILIZE_FATAL",
+                 "Should any mutations clear (kill) the organism?");
+  rev_group->Add(sterilize_neg, "0.0", "STERILIZE_DETRIMENTAL",
+                 "  0.0 to 1.0; Probability of reset.");
+  rev_group->Add(sterilize_neut, "0.0", "STERILIZE_NEUTRAL",
+                 "");
+  rev_group->Add(sterilize_pos, "0.0", "STERILIZE_BENEFICIAL",
+                 "");
+  rev_group->Add(fail_implicit, "0", "FAIL_IMPLICIT",
+                 "Should copies that failed *not* due to mutations\nbe eliminated?");
+  
+  // Time slicing group
+  cConfigGroup * time_group = new cConfigGroup("Time Slicing");
+  group_list.PushRear(time_group);
+  
+  time_group->Add(ave_time_slice, "30", "AVE_TIME_SLICE",
+                  "Ave number of insts per org per update");
+  time_group->Add(slicing_method, "2", "SLICING_METHOD",
+                  "0 = CONSTANT: all organisms get default...\n1 = PROBABILISTIC: Run _prob_ proportional to merit.\n2 = INTEGRATED: Perfectly integrated deterministic.");
+  time_group->Add(size_merit_method, "0", "SIZE_MERIT_METHOD",
+                  "0 = off (merit is independent of size)\n1 = Merit proportional to copied size\n2 = Merit prop. to executed size\n3 = Merit prop. to full size\n4 = Merit prop. to min of executed or copied size\n5 = Merit prop. to sqrt of the minimum size");
+  time_group->Add(task_merit_method, "1", "TASK_MERIT_METHOD",
+                  "0 = No task bonuses\n1 = Bonus just equals the task bonus");
+  time_group->Add(max_cpu_threads, "1", "MAX_CPU_THREADS",
+                  "Number of Threads a CPU can spawn");
+  time_group->Add(thread_slicing_method, "0", "THREAD_SLICING_METHOD",
+                  "Formula for and organism's thread slicing -> 1 + (num_organism_threads-1) * THREAD_SLICING_METHOD.\n0 = One thread executed per time slice.\n1 = All threads executed each time slice.\n");
+  time_group->Add(max_label_exe_size, "1", "MAX_LABEL_EXE_SIZE",
+                  "Max nops marked as executed when labels are used");
+  time_group->Add(base_size_merit, "100", "BASE_SIZE_MERIT",
+                  "Base merit when size is *not* used");
+  time_group->Add(default_bonus, "1", "DEFAULT_BONUS",
+                  "The bonus an organism gets before it has completed any tasks");
+  time_group->Add(merit_time, "0", "MERIT_TIME",
+                  "0 = Merit Calculated when task completed\n1 = Merit Calculated on Divide");
+  time_group->Add(merit_given, "0.0", "MERIT_GIVEN",
+                  "Fraction of merit donated with 'donate' command");
+  time_group->Add(merit_received, "0.0", "MERIT_RECEIVED",
+                  "Multiplier of merit given with 'donate' command");
+  time_group->Add(max_donate_kin_distance, "-1", "MAX_DONATE_KIN_DIST",
+                  "Limit on distance of relation for donate; -1=no max");
+  time_group->Add(max_donate_edit_distance, "-1", "MAX_DONATE_EDIT_DIST",
+                  "Limit on genetic (edit) distance for donate; -1=no max");
+  time_group->Add(max_donates, "1000000", "MAX_DONATES",
+                  "Limit on number of donates organisms are allowed.");
+  
+  
+  // Geneology group
+  cConfigGroup * gen_group = new cConfigGroup("Geneology");
+  group_list.PushRear(gen_group);
+  
+  gen_group->Add(track_main_lineage, "1", "TRACK_MAIN_LINEAGE",
+                 "Keep all ancestors of the active population?\n0=no, 1=yes, 2=yes,w/sexual population");
+  gen_group->Add(threshold, "3", "THRESHOLD",
+                 "Number of organisms in a genotype needed for it\n  to be considered viable.");
+  gen_group->Add(genotype_print, "0", "GENOTYPE_PRINT",
+                 "0/1 (off/on) Print out all threshold genotypes?");
+  gen_group->Add(genotype_print_dom, "0", "GENOTYPE_PRINT_DOM",
+                 "Print out a genotype if it stays dominant for\n  this many updates. (0 = off)");
+  gen_group->Add(species_threshold, "2", "SPECIES_THRESHOLD",
+                 "max failure count for organisms to be same species");
+  gen_group->Add(species_recording, "0", "SPECIES_RECORDING",
+                 "1 = full, 2 = limited search (parent only)");
+  gen_group->Add(species_print, "0", "SPECIES_PRINT",
+                 "0/1 (off/on) Print out all species?");
+  gen_group->Add(test_cpu_time_mod, "20", "TEST_CPU_TIME_MOD",
+                 "Time allocated in test CPUs (multiple of length)");
+  
+  
+  // Log Files group
+  cConfigGroup * log_group = new cConfigGroup("Log Files");
+  group_list.PushRear(log_group);
+  
+  log_group->Add(log_creatures, "0", "LOG_CREATURES",
+                 "0/1 (off/on) toggle to print file.");
+  log_group->Add(log_genotypes, "0", "LOG_GENOTYPES",
+                 "0 = off, 1 = print ALL, 2 = print threshold ONLY.");
+  log_group->Add(log_threshold, "0", "LOG_THRESHOLD",
+                 "0/1 (off/on) toggle to print file.");
+  log_group->Add(log_species, "0", "LOG_SPECIES",
+                 "0/1 (off/on) toggle to print file.");
+  log_group->Add(log_landscape, "0", "LOG_LANDSCAPE",
+                 "0/1 (off/on) toggle to print file.");
+  
+  
+  // Viewer group
+  cConfigGroup * view_group = new cConfigGroup("Viewer Settings");
+  group_list.PushRear(view_group);
+  
+  view_group->Add(view_mode, "0", "VIEW_MODE",
+                  "Initial viewer screen");
+  
+  // Lineages group
+  cConfigGroup * lin_group = new cConfigGroup("Lineage");
+  lin_group->SetComment("NOTE: This should probably be called \"Clade\"\nThis one can slow down avida a lot. It is used to get an idea of how\noften an advantageous mutation arises, and where it goes afterwards.\nLineage creation options are.  Works only when LOG_LINEAGES is set to 1.\n  0 = manual creation (on inject, use successive integers as lineage labels).\n  1 = when a child's (potential) fitness is higher than that of its parent.\n  2 = when a child's (potential) fitness is higher than max in population.\n  3 = when a child's (potential) fitness is higher than max in dom. lineage\n*and* the child is in the dominant lineage, or (2)\n  4 = when a child's (potential) fitness is higher than max in dom. lineage\n(and that of its own lineage)\n  5 = same as child's (potential) fitness is higher than that of the\n      currently dominant organism, and also than that of any organism\n      currently in the same lineage.\n  6 = when a child's (potential) fitness is higher th!
 an any organism\n      currently in the same lineage.\n  7 = when a child's (potential) fitness is higher than that of any\n      organism in its line of descent");
+  
+  group_list.PushRear(lin_group);
+  
+  lin_group->Add(log_lineages, "0", "LOG_LINEAGES",
+                 "");
+  lin_group->Add(lineage_creation_method, "0", "LINEAGE_CREATION_METHOD",
+                 "");
+  
+}
+
+void cConfig::Setup(cGenesis & genesis)
+{
+  rand_seed = genesis.ReadInt("RANDOM_SEED");
+  cout << "Random Seed: " << rand_seed;
+  g_random.ResetSeed(rand_seed);
+  if( rand_seed != g_random.GetSeed() ) cout << " -> " << g_random.GetSeed();
+  cout << endl;
+  
+  tListIterator<cConfigGroup> group_it(group_list);
+  cConfigGroup * cur_group;
+  while ((cur_group = group_it.Next()) != NULL) {
+    cur_group->LoadValues(genesis);
+  }
+  
+  /***
+    * Handle any special modifications to any of the variables now that
+    * they've been loaded.
+    ***/
+  
+  // The default directory should end in a '/'.
+  char dir_tail = default_dir[default_dir.GetSize() - 1];
+  if (dir_tail != '\\' && dir_tail != '/') default_dir += "/";
+  
+  // Determine if any variables were set that require test CPUs to be run
+  // at every divide.
+  test_on_divide = false;
+  if ((revert_fatal > 0.0) || (revert_neg > 0.0) || (revert_neut > 0.0) ||
+      (revert_pos > 0.0) || (fail_implicit > 0)) {
+    test_on_divide = true;
+  }
+  
+  test_sterilize = false;
+  if ((sterilize_fatal > 0.0) || (sterilize_neg > 0.0) ||
+      (sterilize_neut > 0.0) || (sterilize_pos > 0.0)) {
+    test_sterilize = true;
+  }
+  
+  // Determine if we are only logging threshold genotypes...
+  log_threshold_only = false;
+  if (log_genotypes > 1) log_threshold_only = true;
+  
+  // Warn if there are settings in the genesis file that have not been read.
+  genesis.WarnUnused();
+  
+  // Test printing... @CAO
+  //  PrintGenesis("genesis.test");
+}
+
+void cConfig::Setup(int argc, char * argv[])
+{
+  /***
+  * Load all of the variables from genesis.
+  ***/
+  
+  default_dir = DEFAULT_DIR;
+  
+  cGenesis genesis;
+  genesis.SetVerbose();
+  ProcessConfiguration(argc, argv, genesis);
+  
+  Setup(genesis);
+}
+
+void cConfig::SetupMS()
+{
+#ifdef PLATFORM_WINDOWS
+  OSVERSIONINFO	osVersion;
+  
+  SetFileApisToOEM();             // use console character set for files
+  memset (&osVersion, 0, sizeof (osVersion));
+  osVersion.dwOSVersionInfoSize = sizeof (osVersion);
+  GetVersionEx (&osVersion);
+  if (osVersion.dwPlatformId == VER_PLATFORM_WIN32_NT) {
+    // Only need to set Code Pages for NT. Default console on Win95 is OEM.
+    // In fact, these APIs fail on Win95 w/ rc = 120 (API only works in NT
+    //  mode).
+    if (!SetConsoleCP (GetOEMCP()))        // and for Console input
+      cerr << "Warning: Unable to set input character set, rc="
+        << GetLastError() << endl;
+    if (!SetConsoleOutputCP (GetOEMCP()))  // and for Console output
+      cerr << "Warning: Unable to set output character set, rc="
+        << GetLastError() << endl;
+  }
+#endif
+}
+
+void cConfig::PrintGenesis(const cString & filename)
+{
+  ofstream fp(filename);
+  
+  // Print out the generic header, including the version ID.
+  fp << "#############################################################################" << endl
+    << "# This file includes all the basic run-time defines for avida." << endl
+    << "# For more information, see doc/genesis.html" << endl
+    << "#############################################################################" << endl
+    << endl
+    << "VERSION_ID " << VERSION << "   # Do not change this value."
+    << endl;
+  
+  // Loop through the groups, and print out all of the variables.
+  
+  tListIterator<cConfigGroup> group_it(group_list);
+  cConfigGroup * cur_group;
+  while ((cur_group = group_it.Next()) != NULL) {
+    // Print out the group name...
+    fp << endl;
+    fp << "### " << cur_group->GetName() << " ###" << endl;
+    
+    // If we have a comment about the current group, include it.
+    for (int i = 0; i < cur_group->GetComment().GetSize(); i++) {
+      fp << "# " << cur_group->GetComment().GetLine(i) << endl;
+    }
+    
+    // Print out everything for this group...
+    tListIterator<cConfigEntryBase> entry_it(cur_group->GetEntries());
+    cConfigEntryBase * cur_entry;
+    
+    // First, figure out the widest entry so we know where to put comments.
+    int max_width = 0;
+    while ((cur_entry = entry_it.Next()) != NULL) {
+      int cur_width = cur_entry->GetTag().GetSize() +
+      cur_entry->GetDefault().GetSize() + 1;
+      if (cur_width > max_width) max_width = cur_width;
+    }
+    
+    // Now, make a second pass printing everything.
+    entry_it.Reset();
+    while ((cur_entry = entry_it.Next()) != NULL) {
+      int cur_width = cur_entry->GetTag().GetSize() +
+      cur_entry->GetDefault().GetSize() + 1;
+      // Print the variable and its setting...
+      fp << cur_entry->GetTag() << " " << cur_entry->GetDefault();
+      
+      // Print some spaces before the description.
+      for (int i = cur_width; i < max_width; i++) fp << " ";
+      
+      // Print the first line of the description.
+      if (cur_entry->GetDesc().GetSize() == 0) {
+        fp << "  # " << endl;
+      } else {
+        fp << "  # " << cur_entry->GetDesc().GetLine(0) << endl;
+      }
+      
+      // Print the remaining lines of a description.
+      for (int i = 1; i < cur_entry->GetDesc().GetSize(); i++) {
+        for (int j = 0; j < max_width; j++) fp << " ";
+        fp << "  # " << cur_entry->GetDesc().GetLine(i) << endl;
+      }
+    }
+  }
+}
+
+//  void cConfig::PerturbTaskSet(double max_factor)
+//  {
+//    default_task_lib->Perturb(max_factor);
+//  }
+
+//  void cConfig::ChangeTaskSet(double prob_change, double min_bonus,
+//  			    double max_bonus)
+//  {
+//    default_task_lib->Change(prob_change, min_bonus, max_bonus);
+//  }
+
+
+// This function takes in the genesis file and the input arguments, and puts
+// out a pointer to a built-up cGenesis object.
+
+// @COW This function depends on the inclusion of the file
+// 'vent/cPopulation_descr.ci' for the automatic event documentation.
+// If you move the function away from here, move this include as well.
+
+
+void cConfig::ProcessConfiguration(int argc, char * argv[], cGenesis & genesis)
+{
+  const cString default_filename = "genesis";
+  genesis_filename = default_filename;
+  
+  int arg_num = 1;              // Argument number being looked at.
+  analyze_mode = false;         // Initialize analyze_mode tp be off.
+  primitive_mode = false;       // Initialize primitive_mode tp be off.
+  interactive_analyze = false;  // Don't start analyze interactively either.
+  
+  // Load all of the args into string objects for ease of access.
+  cString * args = new cString[argc];
+  for (int i = 0; i < argc; i++) args[i] = argv[i];
+  
+  
+  // -genesis option
+  
+  if (argc > 1 && (args[1] == "-g" || args[1] == "-genesis")) {
+    if (argc < 3) {
+      cerr << "Need filename for genesis file used." << endl;
+      exit(0);
+    }
+    genesis_filename = args[2];
+    arg_num += 2;
+  }
+  
+  
+  // Open and verify the genesis file.
+  
+  genesis.Open(genesis_filename);
+  
+  // If we failed to open the genesis file, and we are using the default,
+  // try creating it.
+  if (genesis.IsOpen() == false && genesis_filename == default_filename) {
+    cerr << "Warning: Unable to find file '" << genesis_filename
+    << "'.  Creating." << endl;
+    PrintGenesis(genesis_filename);
+    genesis.Open(genesis_filename);
+  }
+  
+  cString version_id = genesis.ReadString("VERSION_ID", "Unknown");
+  if (genesis.IsOpen() == true && version_id != VERSION) {
+    cerr << "/  WARNING   WARNING   WARNING   WARNING   WARNING  \\" << endl
+    << "|   Using incorrect genesis file.                   |" << endl
+    << "|   Version needed = \"" << VERSION
+    << "\".  Version used = \"" << version_id() << "\"   |" << endl
+    << "\\  WARNING   WARNING   WARNING   WARNING   WARNING  /" << endl
+    << endl;
+  }
+  
+  // Then scan through and process the rest of the args.
+  
+  while (arg_num < argc || genesis.IsOpen() == false) {
+    cString cur_arg = genesis.IsOpen() ? static_cast<cString>( args[arg_num] ) : static_cast<cString>( "--help" );
+    
+    // Test against the possible inputs.
+    if (cur_arg == "-events" || cur_arg == "-e") {
+      cout << "Known events:" << endl;
+      // @DMB - A cleaner way of constructing the cEventFactoryManager should be created
+      cEventFactoryManager event_manager;
+      event_manager.AddFactory(new cPopulationEventFactory(NULL));
+      event_manager.PrintAllEventDescriptions();
+      exit(0);
+    }
+    else if (cur_arg == "--help" || cur_arg == "-help" ||
+             cur_arg == "-h"     || genesis.IsOpen() == false) {
+      cout << "Options:"<<endl
+      << "  -g[enesis] <filename> Set genesis file to be <filename>"<<endl
+      << "  -h[elp]               Help on options (this listing)"<<endl
+      << "  -e[vents]             Print a list of all known events"<< endl
+      << "  -s[eed] <value>       Set random seed to <value>"<<endl
+      << "  -viewer <value>       Sets Viewer to <value>"<<endl
+      << "  -v[ersion]            Prints the version number"<<endl
+      << "  -set <name> <value>   Overide the genesis file"<<endl
+      << "  -l[oad] <filename>    Load a clone file"<<endl
+      << "  -loadpop <filename>   Load a saved population file (precedence over load)"<<endl
+      << "  -a[nalyze]            Process analyze.cfg instead of normal run."<<endl
+      << "  -i[nteractive]        Run analyze mode interactively."
+      // << "  -p[rimitive]          Overide viewer to be primitive."<<endl
+      << endl;
+      
+      exit(0);
+    }
+    else if (cur_arg == "-seed" || cur_arg == "-s") {
+      int in_seed = 0;
+      if (arg_num + 1 == argc || args[arg_num + 1][0] == '-') {
+        cerr<<"Must include a number as the random seed!"<<endl;
+        exit(0);
+      } else {
+        arg_num++;  if (arg_num < argc) cur_arg = args[arg_num];
+        in_seed = cur_arg.AsInt();
+      }
+      genesis.AddInput("RANDOM_SEED", in_seed);
+    } else if (cur_arg == "-analyze" || cur_arg == "-a") {
+      analyze_mode = true;
+    } else if (cur_arg == "-interactive" || cur_arg == "-i") {
+      analyze_mode = true;
+      interactive_analyze = true;
+    } else if (cur_arg == "-primitive" || cur_arg == "-p") {
+      primitive_mode = true;
+    } else if (cur_arg == "-load" || cur_arg == "-l") {
+      if (arg_num + 1 == argc || args[arg_num + 1][0] == '-') {
+        cerr<<"Must include a filename to load from"<<endl;
+        exit(0);
+      } else {
+        arg_num++;  if (arg_num < argc) cur_arg = args[arg_num];
+        clone_filename = cur_arg;
+      }
+    } else if (cur_arg == "-loadpop" || cur_arg == "-lp") {
+      if (arg_num + 1 == argc || args[arg_num + 1][0] == '-') {
+        cerr<<"Must include a filename to load from"<<endl;
+        exit(0);
+      } else {
+        arg_num++;  if (arg_num < argc) cur_arg = args[arg_num];
+        load_pop_filename = cur_arg;
+      }
+    } else if (cur_arg == "-version" || cur_arg == "-v") {
+      cout << " by Charles Ofria" << endl;
+      cout << " designed by Charles Ofria, Chris Adami, Travis Collier, C. Titus Brown, and Claus Wilke" << endl;
+      cout << " For more information, see: http://devolab.cse.msu.edu/software/avida/" << endl;
+      exit(0);
+    } else if (cur_arg == "-set") {
+      if (arg_num + 1 == argc || arg_num + 2 == argc) {
+        cerr << "'-set' option must be followed by name and value" << endl;
+        exit(0);
+      }
+      arg_num++;  if (arg_num < argc) cur_arg = args[arg_num];
+      cString name(cur_arg);
+      arg_num++;  if (arg_num < argc) cur_arg = args[arg_num];
+      cString value(cur_arg);
+      cout << "SET " << name() << " = " << value() << endl;
+      genesis.AddInput(name(), value());
+      
+    } else if (cur_arg == "-g" || cur_arg == "-genesis") {
+      cerr << "Error: -g[enesis] option must be listed first." << endl;
+      exit(0);
+    } else {
+      cerr << "Unknown Option: " << argv[arg_num] << endl
+      << "Type: \"" << argv[0] << " -h\" for a full option list." << endl;
+      exit(0);
+    }
+    
+    arg_num++;  if (arg_num < argc) cur_arg = args[arg_num];
+  }
+  
+  delete [] args;
+}

Copied: trunk/source/main/cConfig.h (from rev 313, trunk/source/main/config.hh)

Copied: trunk/source/main/cEnvironment.cc (from rev 313, trunk/source/main/environment.cc)
===================================================================
--- trunk/source/main/environment.cc	2005-09-15 23:16:19 UTC (rev 313)
+++ trunk/source/main/cEnvironment.cc	2005-09-16 02:10:20 UTC (rev 314)
@@ -0,0 +1,946 @@
+//////////////////////////////////////////////////////////////////////////////
+// Copyright (C) 1993 - 2003 California Institute of Technology             //
+//                                                                          //
+// Read the COPYING and README files, or contact 'avida at alife.org',         //
+// before continuing.  SOME RESTRICTIONS MAY APPLY TO USE OF THIS FILE.     //
+//////////////////////////////////////////////////////////////////////////////
+
+#ifndef ENVIRONMENT_HH
+#include "cEnvironment.h"
+#endif
+
+#ifndef INIT_FILE_HH
+#include "init_file.hh"
+#endif
+#ifndef MUTATION_MACROS_HH
+#include "mutation_macros.hh"
+#endif
+#ifndef RANDOM_HH
+#include "random.hh"
+#endif
+#ifndef REACTION_HH
+#include "reaction.hh"
+#endif
+#ifndef REACTION_MACROS_HH
+#include "reaction_macros.hh"
+#endif
+#ifndef REACTION_PROCESS_HH
+#include "reaction_process.hh"
+#endif
+#ifndef REACTION_REQUISITE_HH
+#include "reaction_requisite.hh"
+#endif
+#ifndef REACTION_RESULT_HH
+#include "reaction_result.hh"
+#endif
+#ifndef RESOURCE_HH
+#include "resource.hh"
+#endif
+#ifndef STRING_UTIL_HH
+#include "string_util.hh"
+#endif
+#ifndef TASK_ENTRY_HH
+#include "task_entry.hh"
+#endif
+#ifndef TOOLS_HH
+#include "tools.hh"
+#endif
+
+using namespace std;
+
+cEnvironment::cEnvironment()
+{
+}
+
+// cEnvironment::cEnvironment(const cString & filename)
+// {
+//   if (Load(filename) == false) {
+//     cerr << "Unable to load environment... aborting!" << endl;
+//     abort();
+//   }
+// }
+
+bool cEnvironment::ParseSetting(cString entry, cString & var_name,
+				cString & var_value, const cString & var_type)
+{
+  // Make sure we have an actual entry to parse.
+  if (entry.GetSize() == 0) {
+    cerr << "Error: Empty setting to parse in " << var_type << endl;
+    return false;
+  }
+
+  // Collect the values...
+  var_name = entry.Pop('=');
+  var_value = entry;
+
+  // Make sure we have both a name and a value...
+  if (var_name.GetSize() == 0) {
+    cerr << "Error: No variable povided to set to '" << var_value
+	 << "' in " << var_type << endl;
+    return false;
+  }
+
+  if (var_value.GetSize() == 0) {
+    cerr << "Error: No value given for '" << var_name
+	 << "' in " << var_type << endl;
+    return false;
+  }
+
+  // Make the names case insensitive.
+  var_name.ToLower();
+
+  return true;
+}
+
+bool cEnvironment::AssertInputInt(const cString & input,
+				  const cString & name,
+				  const cString & type)
+{
+  if (input.IsNumeric() == false) {
+    cerr << "Error: In " << type << "," << name << " set to non-integer."
+	 << endl;
+    return false;
+  }
+  return true;
+}
+
+bool cEnvironment::AssertInputDouble(const cString & input,
+				     const cString & name,
+				     const cString & type)
+{
+  if (input.IsNumber() == false) {
+    cerr << "Error: In " << type << "," << name << " set to non-number."
+	 << endl;
+    return false;
+  }
+  return true;
+}
+
+bool cEnvironment::AssertInputBool(const cString & input,
+				  const cString & name,
+				  const cString & type)
+{
+  if (input.IsNumber() == false) {
+    cerr << "Error: In " << type << "," << name << " set to non-number."
+	 << endl;
+    return false;
+  }
+  int value = input.AsInt();
+  if ((value != 1) && (value != 0))  {
+    cerr << "Error: In " << type << "," << name << " set to non-bool."
+	 << endl;
+    return false;
+  }
+  return true;
+}
+
+bool cEnvironment::AssertInputValid(void * input,
+				    const cString & name,
+				    const cString & type,
+				    const cString & value)
+{
+  if (input == NULL) {
+    cerr << "Error: In " << type << ", '" << name << "' setting of '"
+	 << value << "' not found." << endl;
+    return false;
+  }
+  return true;
+}
+
+
+
+bool cEnvironment::LoadReactionProcess(cReaction * reaction, cString desc)
+{
+  cReactionProcess * new_process = reaction->AddProcess();
+
+  // Loop through all entries in description.
+  while (desc.GetSize() > 0) {
+    // Entries are divided by colons.
+    cString var_entry = desc.Pop(':');
+    cString var_name;
+    cString var_value;
+    const cString var_type =
+      cStringUtil::Stringf("reaction '%s' process", reaction->GetName()());
+
+    // Parse this entry.
+    if (!ParseSetting(var_entry, var_name, var_value, var_type)) return false;
+
+    // Now that we know we have a variable name and its value, set it!
+    if (var_name == "resource") {
+      cResource * test_resource = resource_lib.GetResource(var_value);
+      if (!AssertInputValid(test_resource, "resource", var_type, var_value)) {
+	return false;
+      }
+      new_process->SetResource(test_resource);
+    }
+    else if (var_name == "value") {
+      if (!AssertInputDouble(var_value, "value", var_type)) return false;
+      new_process->SetValue(var_value.AsDouble());
+    }
+    else if (var_name == "type") {
+      if (var_value=="add") new_process->SetType(REACTION_PROCTYPE_ADD);
+      else if (var_value=="mult") new_process->SetType(REACTION_PROCTYPE_MULT);
+      else if (var_value=="pow") new_process->SetType(REACTION_PROCTYPE_POW);
+      else {
+	cerr << "Unknown reaction process type '" << var_value
+	     << "' found in '" << reaction->GetName() << "'." << endl;
+	return false;
+      }
+    }
+    else if (var_name == "max") {
+      if (!AssertInputDouble(var_value, "max", var_type)) return false;
+      new_process->SetMaxNumber(var_value.AsDouble());
+    }
+    else if (var_name == "min") {
+      if (!AssertInputDouble(var_value, "min", var_type)) return false;
+      new_process->SetMinNumber(var_value.AsDouble());
+    }
+    else if (var_name == "frac") {
+      if (!AssertInputDouble(var_value, "frac", var_type)) return false;
+      double in_frac = var_value.AsDouble();
+      if (in_frac > 1.0) in_frac = 1.0;
+      new_process->SetMaxFraction(in_frac);
+    }
+    else if (var_name == "product") {
+      cResource * test_resource = resource_lib.GetResource(var_value);
+      if (!AssertInputValid(test_resource, "product", var_type, var_value)) {
+	return false;
+      }
+      new_process->SetProduct(test_resource);
+    }
+    else if (var_name == "conversion") {
+      if (!AssertInputDouble(var_value, "conversion", var_type)) return false;
+      new_process->SetConversion(var_value.AsDouble());
+    }
+    else if (var_name == "inst") {
+      new_process->SetInstID( inst_set.GetInst(var_value).GetOp() );
+    }
+    else if (var_name == "lethal") {
+      if (!AssertInputBool(var_value, "lethal", var_type)) 
+	return false;
+      new_process->SetLethal(var_value.AsInt());
+    }
+    else if (var_name == "detect") {
+      cResource * test_resource = resource_lib.GetResource(var_value);
+      if (!AssertInputValid(test_resource, "product", var_type, var_value)) {
+	return false;
+      }
+      new_process->SetDetect(test_resource);
+    }
+    else if (var_name == "threshold") {
+      if (!AssertInputDouble(var_value, "threshold", var_type))
+	return false;
+      new_process->SetDetectionThreshold(var_value.AsDouble());
+    }
+    else if (var_name == "detectionerror") {
+      if (!AssertInputDouble(var_value, "detectionerror", var_type)) 
+	return false;
+      new_process->SetDetectionError(var_value.AsDouble());
+    }
+    else {
+      cerr << "Error: Unknown process variable '" << var_name
+	   << "' in reaction '" << reaction->GetName() << "'" << endl;
+      return false;
+    }
+  }
+
+  return true;
+}
+
+bool cEnvironment::LoadReactionRequisite(cReaction * reaction, cString desc)
+{
+  cReactionRequisite * new_requisite = reaction->AddRequisite();
+
+  // Loop through all entries in description.
+  while (desc.GetSize() > 0) {
+    // Entries are divided by colons.
+    cString var_entry = desc.Pop(':');
+    cString var_name;
+    cString var_value;
+    const cString var_type =
+      cStringUtil::Stringf("reaction '%s' requisite", reaction->GetName()());
+
+    // Parse this entry.
+    if (!ParseSetting(var_entry, var_name, var_value, var_type)) return false;
+
+    // Now that we know we have a variable name and its value, set it!
+    if (var_name == "reaction") {
+      cReaction * test_reaction = reaction_lib.GetReaction(var_value);
+      if (!AssertInputValid(test_reaction, "reaction", var_type, var_value)) {
+	return false;
+      }
+      new_requisite->AddReaction(test_reaction);
+    }
+    else if (var_name == "noreaction") {
+      cReaction * test_reaction = reaction_lib.GetReaction(var_value);
+      if (!AssertInputValid(test_reaction,"noreaction",var_type, var_value)) {
+	return false;
+      }
+      new_requisite->AddNoReaction(test_reaction);
+    }
+    else if (var_name == "min_count") {
+      if (!AssertInputInt(var_value, "min_count", var_type)) return false;
+      new_requisite->SetMinTaskCount(var_value.AsInt());
+    }
+    else if (var_name == "max_count") {
+      if (!AssertInputInt(var_value, "max_count", var_type)) return false;
+      new_requisite->SetMaxTaskCount(var_value.AsInt());
+    }
+    else {
+      cerr << "Error: Unknown requisite variable '" << var_name
+	   << "' in reaction '" << reaction->GetName() << "'" << endl;
+      return false;
+    }
+  }
+
+  return true;
+}
+
+
+bool cEnvironment::LoadResource(cString desc)
+{
+  if (desc.GetSize() == 0) {
+    cerr << "Warning: Resource line with no resources listed." << endl;
+    return false;
+  }
+
+  while (desc.GetSize() > 0) {
+    cString cur_resource = desc.PopWord();
+    const cString name = cur_resource.Pop(':');
+    cResource * new_resource = resource_lib.AddResource(name);
+
+    while (cur_resource.GetSize() != 0) {
+      cString var_entry = cur_resource.Pop(':');
+      cString var_name;
+      cString var_value;
+      const cString var_type = cStringUtil::Stringf("resource '%s'", name());
+
+      // Parse this entry.
+      if (!ParseSetting(var_entry, var_name, var_value, var_type)) {
+	return false;
+      }
+
+      if (var_name == "inflow") {
+	if (!AssertInputDouble(var_value, "inflow", var_type)) return false;
+	new_resource->SetInflow( var_value.AsDouble() );
+      }
+      else if (var_name == "outflow") {
+	if (!AssertInputDouble(var_value, "outflow", var_type)) return false;
+	new_resource->SetOutflow( var_value.AsDouble() );
+      }
+      else if (var_name == "initial") {
+	if (!AssertInputDouble(var_value, "initial", var_type)) return false;
+	new_resource->SetInitial( var_value.AsDouble() );
+      }
+      else if (var_name == "geometry") {
+	if (!new_resource->SetGeometry( var_value )) {
+          cerr << "Error: In " << var_type << "," << var_value << 
+	          " unknown geometry" << endl;
+          return false;
+        }
+      }
+      else if (var_name == "inflowx1" || var_name == "inflowx") {
+	if (!AssertInputInt(var_value, "inflowX1", var_type)) return false;
+	new_resource->SetInflowX1( var_value.AsInt() );
+      }
+      else if (var_name == "inflowx2") {
+	if (!AssertInputInt(var_value, "inflowX2", var_type)) return false;
+	new_resource->SetInflowX2( var_value.AsInt() );
+      }
+      else if (var_name == "inflowy1" || var_name == "inflowy") {
+	if (!AssertInputInt(var_value, "inflowY1", var_type)) return false;
+	new_resource->SetInflowY1( var_value.AsInt() );
+      }
+      else if (var_name == "inflowy2") {
+	if (!AssertInputInt(var_value, "inflowY2", var_type)) return false;
+	new_resource->SetInflowY2( var_value.AsInt() );
+      }
+      else if (var_name == "outflowx1" || var_name == "outflowx") {
+	if (!AssertInputInt(var_value, "outflowX1", var_type)) return false;
+	new_resource->SetOutflowX1( var_value.AsInt() );
+      }
+      else if (var_name == "outflowx2") {
+	if (!AssertInputInt(var_value, "outflowX2", var_type)) return false;
+	new_resource->SetOutflowX2( var_value.AsInt() );
+      }
+      else if (var_name == "outflowy1" || var_name == "outflowy") {
+	if (!AssertInputInt(var_value, "outflowY1", var_type)) return false;
+	new_resource->SetOutflowY1( var_value.AsInt() );
+      }
+      else if (var_name == "outflowy2") {
+	if (!AssertInputInt(var_value, "outflowY2", var_type)) return false;
+	new_resource->SetOutflowY2( var_value.AsInt() );
+      }
+      else if (var_name == "xdiffuse") {
+	if (!AssertInputDouble(var_value, "xdiffuse", var_type)) return false;
+	new_resource->SetXDiffuse( var_value.AsDouble() );
+      }
+      else if (var_name == "xgravity") {
+	if (!AssertInputDouble(var_value, "xgravity", var_type)) return false;
+	new_resource->SetXGravity( var_value.AsDouble() );
+      }
+      else if (var_name == "ydiffuse") {
+	if (!AssertInputDouble(var_value, "ydiffuse", var_type)) return false;
+	new_resource->SetYDiffuse( var_value.AsDouble() );
+      }
+      else if (var_name == "ygravity") {
+	if (!AssertInputDouble(var_value, "ygravity", var_type)) return false;
+	new_resource->SetYGravity( var_value.AsDouble() );
+      }
+      else {
+	cerr << "Error: Unknown variable '" << var_name
+	     << "' in resource '" << name << "'" << endl;
+	return false;
+      }
+    }
+
+    // If there are valid values for X/Y1's but not for X/Y2's assume that 
+    // the user is interested only in one point and set the X/Y2's to the
+    // same value as 
+
+    if (new_resource->GetInflowX1()>-99 && new_resource->GetInflowX2()==-99){
+         new_resource->SetInflowX2(new_resource->GetInflowX1());
+    }
+    if (new_resource->GetInflowY1()>-99 && new_resource->GetInflowY2()==-99){
+         new_resource->SetInflowY2(new_resource->GetInflowY1());
+    }
+    if (new_resource->GetOutflowX1()>-99 && new_resource->GetOutflowX2()==-99) {
+         new_resource->SetOutflowX2(new_resource->GetOutflowX1());
+    }
+    if (new_resource->GetOutflowY1()>-99 && new_resource->GetOutflowY2()==-99) {
+         new_resource->SetOutflowY2(new_resource->GetOutflowY1());
+    }
+  }
+
+  return true;
+}
+
+bool cEnvironment::LoadReaction(cString desc)
+{
+  // Make sure this reaction has a description...
+  if (desc.GetSize() == 0) {
+    cerr << "Error: Each reaction must include a name and trigger." << endl;
+    return false;
+  }
+
+  // Load in the reaction name
+  const cString name = desc.PopWord();
+  cReaction * new_reaction = reaction_lib.AddReaction(name);
+
+  // If only a name was present, assume this reaction is a pre-declaration.
+  if (desc.GetSize() == 0) {
+    return true;
+  }
+
+  // Make sure this reaction hasn't already been loaded with a different
+  // definition.
+  if (new_reaction->GetTask() != NULL) {
+    cerr << "Error: Re-defining reaction '" << name << "'." << endl;
+    return false;
+  }
+
+  // Finish loading in this reaction.
+  const cString trigger = desc.PopWord();
+
+  // Load the task trigger
+  cTaskEntry * cur_task = task_lib.AddTask(trigger);
+  if (cur_task == NULL) {
+    cerr << "...failed to find task in cTaskLib..." << endl;
+    return false;
+  }
+  new_reaction->SetTask(cur_task);      // Attack task to reaction.
+
+  while (desc.GetSize()) {
+    cString desc_entry = desc.PopWord();      // Get the next argument
+    cString entry_type = desc_entry.Pop(':'); // Determine argument type
+    entry_type.ToLower();                     // Make case insensitive.
+
+    // Determine the type of each argument and process it.
+    if (entry_type == "process") {
+      if (LoadReactionProcess(new_reaction, desc_entry) == false) {
+	cerr << "...failed in loading reaction-process..." << endl;
+	return false;
+      }
+    }
+    else if (entry_type == "requisite") {
+      if (LoadReactionRequisite(new_reaction, desc_entry) == false) {
+	cerr << "...failed in loading reaction-requisite..." << endl;
+	return false;
+      }
+    }
+    else {
+      cerr << "Unknown entry type '" << entry_type
+  	   << "' in reaction '" << name << "'"
+  	   << endl;
+      return false;
+    }
+  }
+
+  return true;
+}
+
+bool cEnvironment::LoadMutation(cString desc)
+{
+  // Make sure this mutation has a description...
+  if (desc.CountNumWords() < 5) {
+    cerr << "Error: Each mutation must include a name, trigger, scope, type, and rate." << endl;
+    return false;
+  }
+
+  // Load in the mutation info
+  const cString name = desc.PopWord().ToLower();
+  const cString trigger = desc.PopWord().ToLower();
+  const cString scope = desc.PopWord().ToLower();
+  const cString type = desc.PopWord().ToLower();
+  const double rate = desc.PopWord().AsDouble();
+
+  int trig_id = -1;
+  int scope_id = -1;
+  int type_id = -1;
+
+  if (trigger == "none") trig_id = MUTATION_TRIGGER_NONE;
+  else if (trigger == "update") trig_id = MUTATION_TRIGGER_UPDATE;
+  else if (trigger == "divide") trig_id = MUTATION_TRIGGER_DIVIDE;
+  else if (trigger == "parent") trig_id = MUTATION_TRIGGER_PARENT;
+  else if (trigger == "write") trig_id = MUTATION_TRIGGER_WRITE;
+  else if (trigger == "read") trig_id = MUTATION_TRIGGER_READ;
+  else if (trigger == "exec") trig_id = MUTATION_TRIGGER_EXEC;
+  else {
+    cerr << "Error: Unknown mutation trigger '" << trigger << "'." << endl;
+    return false;
+  }
+
+  if (scope == "genome") scope_id = MUTATION_SCOPE_GENOME;
+  else if (scope == "local") scope_id = MUTATION_SCOPE_LOCAL;
+  else if (scope == "prop") scope_id = MUTATION_SCOPE_PROP;
+  else if (scope == "global") scope_id = MUTATION_SCOPE_GLOBAL;
+  else if (scope == "spread") scope_id = MUTATION_SCOPE_SPREAD;
+  else {
+    cerr << "Error: Unknown mutation scope '" << scope << "'." << endl;
+    return false;
+  }
+
+  if (type == "point") type_id = MUTATION_TYPE_POINT;
+  else if (type == "insert") type_id = MUTATION_TYPE_INSERT;
+  else if (type == "delete") type_id = MUTATION_TYPE_DELETE;
+  else if (type == "head_inc") type_id = MUTATION_TYPE_HEAD_INC;
+  else if (type == "head_dec") type_id = MUTATION_TYPE_HEAD_DEC;
+  else if (type == "temp") type_id = MUTATION_TYPE_TEMP;
+  else if (type == "kill") type_id = MUTATION_TYPE_KILL;
+  else {
+    cerr << "Error: Unknown mutation type '" << type << "'." << endl;
+    return false;
+  }
+
+  // Lets do a few checks for legal combinations...
+  if (trig_id == MUTATION_TRIGGER_NONE) {
+    cerr << "Warning: Mutations with trigger 'none' will never occur." << endl;
+  }
+
+  if (scope_id == MUTATION_SCOPE_LOCAL || scope_id == MUTATION_SCOPE_PROP) {
+    if (trig_id == MUTATION_TRIGGER_DIVIDE) {
+      cerr << "Error: Offspring after divide have no " << scope
+	   << " for mutations." << endl;
+      return false;
+    }
+    if (trig_id == MUTATION_TRIGGER_UPDATE ||
+	trig_id == MUTATION_TRIGGER_PARENT) {
+      cerr << "Warning: Mutation trigger " << trigger
+	   << "has no natural positions; IP used." << endl;
+    }
+  }
+  else {  // Genome-wide scope
+    if (type_id == MUTATION_TYPE_HEAD_INC ||
+	type_id == MUTATION_TYPE_HEAD_DEC ||
+	type_id == MUTATION_TYPE_TEMP) {
+      cerr << "Error: " << scope << " scope not compatible with type "
+	   << type << "." << endl;
+      return false;
+    }
+  }
+
+  if (type_id == MUTATION_TYPE_TEMP) {
+    if (trig_id == MUTATION_TRIGGER_UPDATE ||
+	trig_id == MUTATION_TRIGGER_DIVIDE ||
+	trig_id == MUTATION_TRIGGER_PARENT ||
+	trig_id == MUTATION_TRIGGER_WRITE) {
+      cerr << "Error: " << trigger << " trigger not meaningful with type "
+	   << type << "." << endl;
+      return false;
+    }
+  }
+
+  // If we made it this far, it should be safe to build the mutation.
+  mutation_lib.AddMutation(name, trig_id, scope_id, type_id, rate);
+
+  return true;
+}
+
+bool cEnvironment::LoadSetActive(cString desc)
+{
+  cString item_type = desc.PopWord(); 
+  item_type.ToUpper();
+
+  cString item_name = desc.PopWord();
+
+  cString item_active = desc.PopWord();
+  item_active.ToUpper();
+
+  bool new_active = true;
+  if (item_active == "0" || item_active == "FALSE") new_active = false;
+
+  if (item_type == "REACTION") {
+    cReaction * cur_reaction = reaction_lib.GetReaction(item_name);
+    if (cur_reaction == NULL) {
+      cerr << "Unknown REACTION: '" << item_name << "'" << endl;
+      return false;
+    }
+    cur_reaction->SetActive(new_active);
+  } else if (item_type == "") {
+    cerr << "Format: SET_ACTIVE <type> <name> <new_status=true>" << endl;
+  } else {
+    cerr << "Error: Cannot deactivate items of type "
+	 << item_type << endl;
+    return false;
+  }
+
+  return true;
+}
+
+bool cEnvironment::LoadLine(cString line) 
+{
+  cString type = line.PopWord();      // Determine type of this entry.
+  type.ToUpper();                     // Make type case insensitive.
+
+  bool load_ok = true;
+  if (type == "RESOURCE") load_ok = LoadResource(line);
+  else if (type == "REACTION") load_ok = LoadReaction(line);
+  else if (type == "MUTATION") load_ok = LoadMutation(line);
+  else if (type == "SET_ACTIVE") load_ok = LoadSetActive(line);
+  else {
+    cerr << "Error: Unknown environment keyword '" << type << "." << endl;
+    return false;
+  }
+  
+  if (load_ok == false) {
+    cerr << "...failed in loading '" << type << "'..." << endl;
+    return false;
+  }
+
+  return true;
+}
+
+bool cEnvironment::Load(const cString & filename)
+{
+  cInitFile infile(filename);
+  if (infile.Good() == false) {
+    cerr << "Error: Failed to load environment '" << filename << "'." << endl;
+    return false;
+  }
+
+  infile.Load();
+  infile.Close();
+  infile.Compress();
+
+  for (int line_id = 0; line_id < infile.GetNumLines(); line_id++) {
+    // Load the next line from the file.
+    bool load_ok = LoadLine(infile.GetLine(line_id));
+    if (load_ok == false) return false;
+  }
+
+  // Make sure that all pre-declared reactions have been loaded correctly.
+  for (int i = 0; i < reaction_lib.GetSize(); i++) {
+    if (reaction_lib.GetReaction(i)->GetTask() == NULL) {
+      cerr << "Error: Pre-declared reaction '"
+	   << reaction_lib.GetReaction(i)->GetName()
+	   << "' never defined." << endl;
+      return false;
+    }
+  }
+
+  cerr << "--- FINISHED ENVIRONMENT SETUP---" << endl;
+
+  return true;
+}
+
+
+void cEnvironment::SetupInputs( tArray<int> & input_array ) const
+{
+  input_array.Resize(3);
+
+  // Set the top 8 bits of the input buffer...
+  input_array[0] = 15 << 24;  // 00001111
+  input_array[1] = 51 << 24;  // 00110011
+  input_array[2] = 85 << 24;  // 01010101
+
+  // And randomize the rest...
+  for (int i = 0; i < 3; i++) {
+    input_array[i] += g_random.GetUInt(1 << 24);
+  }
+}
+
+
+bool cEnvironment::TestInput( cReactionResult & result,
+			      const tBuffer<int> & inputs,
+			      const tBuffer<int> & outputs,
+			      const tArray<double> & resource_count ) const
+{
+  // @CAO nothing for the moment...
+  return false;
+}
+
+
+bool cEnvironment::TestOutput( cReactionResult & result,
+			       const tBuffer<int> & input_buf,
+			       const tBuffer<int> & output_buf,
+			       const tBuffer<int> & send_buf,
+			       const tBuffer<int> & receive_buf,
+			       const tArray<int> & task_count,
+			       const tArray<int> & reaction_count,
+			       const tArray<double> & resource_count,
+			       const tList< tBuffer<int> > & input_buffers,
+			       const tList< tBuffer<int> > & output_buffers) const
+{
+  // Do setup for reaction tests...
+  task_lib.SetupTests(input_buf, output_buf, input_buffers, output_buffers);
+
+  // Loop through all reactions to see if any have been triggered...
+  const int num_reactions = reaction_lib.GetSize();
+  for (int i = 0; i < num_reactions; i++) {
+    cReaction * cur_reaction = reaction_lib.GetReaction(i);
+    assert(cur_reaction != NULL);
+
+    // Only use active reactions...
+    if (cur_reaction->GetActive() == false) continue;
+
+    // Examine the task trigger associated with this reaction
+    cTaskEntry * cur_task = cur_reaction->GetTask();
+    assert(cur_task != NULL);
+    const double task_quality = task_lib.TestOutput(*cur_task);
+    const int task_id = cur_task->GetID();
+
+    // If this task wasn't performed, move on to the next one.
+    if (task_quality == 0.0) continue;
+
+    // Mark this task as performed...
+    result.MarkTask(task_id);
+
+    // Examine requisites on this reaction
+    if (TestRequisites(cur_reaction->GetRequisites(), task_count[task_id],
+		       reaction_count) == false) {
+      continue;
+    }
+
+    // And lets process it!
+    DoProcesses(cur_reaction->GetProcesses(), resource_count,
+		task_quality, result);
+
+    // Mark this reaction as occuring...
+    result.MarkReaction(cur_reaction->GetID());
+  }
+
+  // Loop again to check receive tasks...
+  // if (receive_buf.GetSize() != 0)
+  {
+    // Do setup for reaction tests...
+    task_lib.
+      SetupTests(receive_buf, output_buf, input_buffers, output_buffers);
+
+    for (int i = 0; i < num_reactions; i++) {
+      cReaction * cur_reaction = reaction_lib.GetReaction(i);
+      assert(cur_reaction != NULL);
+      
+      // Only use active reactions...
+      if (cur_reaction->GetActive() == false) continue;
+      
+      // Examine the task trigger associated with this reaction
+      cTaskEntry * cur_task = cur_reaction->GetTask();
+      assert(cur_task != NULL);
+      const double task_quality = task_lib.TestOutput(*cur_task);
+      const int task_id = cur_task->GetID();
+      
+      // If this task wasn't performed, move on to the next one.
+      if (task_quality == 0.0) continue;
+      
+      // Mark this task as performed...
+      result.MarkReceiveTask(task_id);
+    }
+  }
+
+  return result.GetActive();
+}
+
+
+bool cEnvironment::TestRequisites(const tList<cReactionRequisite> & req_list,
+		  int task_count, const tArray<int> & reaction_count) const
+{
+  const int num_reqs = req_list.GetSize();
+
+  // If there are no requisites, there is nothing to meet!
+  if (num_reqs == 0) return true;
+
+  tConstListIterator<cReactionRequisite> req_it(req_list);
+  for (int i = 0; i < num_reqs; i++) {
+    // See if this requisite batch can be satisfied.
+    const cReactionRequisite * cur_req = req_it.Next();
+    bool satisfied = true;
+
+    // Have all reactions been met?
+    tConstListIterator<cReaction> reaction_it(cur_req->GetReactions());
+    while (reaction_it.Next() != NULL) {
+      int react_id = reaction_it.Get()->GetID();
+      if (reaction_count[react_id] == 0) {
+	satisfied = false;
+	break;
+      }
+    }
+    if (satisfied == false) continue;
+
+    // Have all no-reactions been met?
+    tConstListIterator<cReaction> noreaction_it(cur_req->GetNoReactions());
+    while (noreaction_it.Next() != NULL) {
+      int react_id = noreaction_it.Get()->GetID();
+      if (reaction_count[react_id] != 0) {
+	satisfied = false;
+	break;
+      }
+    }
+    if (satisfied == false) continue;
+
+    // Have all task counts been met?
+    if (task_count < cur_req->GetMinTaskCount()) continue;
+
+    // Have all reactions been met?
+    if (task_count >= cur_req->GetMaxTaskCount()) continue;
+
+    return true;
+  }
+
+  return false;
+}
+
+
+void cEnvironment::DoProcesses(const tList<cReactionProcess> & process_list,
+			       const tArray<double> & resource_count,
+			       const double task_quality,
+			       cReactionResult & result) const
+{
+  const int num_process = process_list.GetSize();
+
+  tConstListIterator<cReactionProcess> process_it(process_list);
+  for (int i = 0; i < num_process; i++) {
+    // See if this requisite batch can be satisfied.
+    const cReactionProcess * cur_process = process_it.Next();
+    const double max_consumed = cur_process->GetMaxNumber();
+    const double min_consumed = cur_process->GetMinNumber();
+
+    // Determine resource consumption
+    double consumed = 0.0;
+    cResource * in_resource = cur_process->GetResource();
+
+    // Test if infinite resource
+    if (in_resource == NULL) {
+      consumed = max_consumed;
+    }
+
+    // Otherwise we're using a finite resource
+    else {
+      const int res_id = in_resource->GetID();
+
+      consumed = resource_count[res_id] - result.GetConsumed(res_id);
+      consumed *= cur_process->GetMaxFraction();
+
+      // Make sure we're not above the maximum consumption.
+      if (consumed > max_consumed) consumed = max_consumed;
+
+      // Test if we are below the minimum consumption.
+      if (consumed < min_consumed) consumed = 0.0;
+
+      // If we don't actually have any resource to consume stop here.
+      if (consumed == 0.0) continue;
+
+      // Mark in the results the resource consumed.
+      result.Consume(res_id, consumed);
+    }
+
+    // Calculate the bonus
+    double bonus = consumed * cur_process->GetValue() * task_quality;
+
+    switch (cur_process->GetType()) {
+    case REACTION_PROCTYPE_ADD:
+      result.AddBonus(bonus);
+      break;
+    case REACTION_PROCTYPE_MULT:
+      result.MultBonus(bonus);
+      break;
+    case REACTION_PROCTYPE_POW:
+      result.MultBonus( pow(2.0, bonus) );
+      break;
+    default:
+      assert(false);  // Should not get here!
+      break;
+    };
+
+    // Determine detection events
+    cResource * detected = cur_process->GetDetect();
+    if (detected != NULL) {
+      const int detected_id = detected->GetID();
+      const double real_amount = resource_count[detected_id];
+      double estimated_amount =
+	   g_random.GetRandNormal(real_amount, cur_process->GetDetectionError()*real_amount);
+      if (estimated_amount < cur_process->GetDetectionThreshold()) {
+	result.Detect(detected_id, 0.0);		
+      } else {
+        result.Detect(detected_id, estimated_amount);
+      }
+    }
+
+    // Determine byproducts
+    cResource * product = cur_process->GetProduct();
+    if (product != NULL) {
+      int product_id = product->GetID();
+      double product_size = consumed * cur_process->GetConversion();
+      result.Produce(product_id, product_size);
+    }
+
+    // Determine what instructions should be run...
+    const int inst_id = cur_process->GetInstID();
+    if (inst_id >= 0) {
+      result.AddInst(inst_id);
+    }
+
+    result.Lethal(cur_process->GetLethal());
+  }
+}
+
+double cEnvironment::GetReactionValue(int & reaction_id)
+{
+  cReaction * found_reaction = reaction_lib.GetReaction(reaction_id);
+  if (found_reaction == NULL) return false;
+  return found_reaction->GetValue();
+}
+
+bool cEnvironment::SetReactionValue(const cString & name, double value)
+{
+  cReaction * found_reaction = reaction_lib.GetReaction(name);
+  if (found_reaction == NULL) return false;
+  found_reaction->ModifyValue(value);
+  return true;
+}
+
+bool cEnvironment::SetReactionValueMult(const cString & name, double value_mult)
+{
+  cReaction * found_reaction = reaction_lib.GetReaction(name);
+  if (found_reaction == NULL) return false;
+  found_reaction->MultiplyValue(value_mult);
+  return true;
+}
+
+bool cEnvironment::SetReactionInst(const cString & name, cString inst_name)
+{
+  cReaction * found_reaction = reaction_lib.GetReaction(name);
+  if (found_reaction == NULL) return false;
+  found_reaction->ModifyInst( inst_set.GetInst(inst_name).GetOp() );
+  return true;
+}
+

Copied: trunk/source/main/cEnvironment.h (from rev 313, trunk/source/main/environment.hh)

Copied: trunk/source/main/cPopulationInterface.cc (from rev 313, trunk/source/main/population_interface.cc)
===================================================================
--- trunk/source/main/population_interface.cc	2005-09-15 23:16:19 UTC (rev 313)
+++ trunk/source/main/cPopulationInterface.cc	2005-09-16 02:10:20 UTC (rev 314)
@@ -0,0 +1,209 @@
+//////////////////////////////////////////////////////////////////////////////
+// Copyright (C) 1993 - 2003 California Institute of Technology             //
+//                                                                          //
+// Read the COPYING and README files, or contact 'avida at alife.org',         //
+// before continuing.  SOME RESTRICTIONS MAY APPLY TO USE OF THIS FILE.     //
+//////////////////////////////////////////////////////////////////////////////
+
+#ifndef POPULATION_INTERFACE_HH
+#include "cPopulationInterface.h"
+#endif
+
+#include <assert.h>
+
+#ifndef NULL
+#define NULL 0
+#endif
+
+cPopulationInterface::cPopulationInterface()
+  : population(NULL)
+  , cell_id(-1)
+  , fun_new_hardware(NULL)
+  , fun_recycle(NULL)
+  , fun_divide(NULL)
+  , fun_test_on_divide(NULL)
+  , fun_get_neighbor(NULL)
+  , fun_birth_chamber(NULL)
+  , fun_num_neighbors(NULL)
+  , fun_rotate(NULL)
+  , fun_breakpoint(NULL)
+  , fun_test_fitness(NULL)
+  , fun_get_input(NULL)
+  , fun_get_input_at(NULL)
+  , fun_debug(NULL)
+  , fun_get_resources(NULL)
+  , fun_update_resources(NULL)
+  , fun_kill_cell(NULL)
+  , fun_kill_surround_cell(NULL)
+  , fun_send_message(NULL)
+  , fun_receive_value(NULL)
+  , fun_inject_parasite(NULL)
+  , fun_update_merit(NULL)
+{
+}
+
+
+cPopulationInterface::~cPopulationInterface()
+{
+}
+
+void cPopulationInterface::CopyCallbacks(cPopulationInterface & in_interface)
+{
+  fun_new_hardware     = in_interface.fun_new_hardware;
+  fun_recycle          = in_interface.fun_recycle;
+  fun_divide           = in_interface.fun_divide;
+  fun_test_on_divide   = in_interface.fun_test_on_divide;
+  fun_get_neighbor     = in_interface.fun_get_neighbor;
+  fun_birth_chamber    = in_interface.fun_birth_chamber;
+  fun_num_neighbors    = in_interface.fun_num_neighbors;
+  fun_rotate           = in_interface.fun_rotate;
+  fun_breakpoint       = in_interface.fun_breakpoint;
+  fun_test_fitness     = in_interface.fun_test_fitness;
+  fun_get_input        = in_interface.fun_get_input;
+  fun_debug            = in_interface.fun_debug;
+  fun_get_resources    = in_interface.fun_get_resources;
+  fun_update_resources = in_interface.fun_update_resources;
+  fun_kill_cell        = in_interface.fun_kill_cell;
+  fun_kill_surround_cell = in_interface.fun_kill_surround_cell;
+  fun_send_message     = in_interface.fun_send_message;
+  fun_receive_value    = in_interface.fun_receive_value;
+  fun_inject_parasite  = in_interface.fun_inject_parasite;
+  fun_update_merit     = in_interface.fun_update_merit;
+}
+
+cHardwareBase * cPopulationInterface::NewHardware(cOrganism * owner)
+{
+  assert(fun_new_hardware != NULL);  // All interfaces must have a NewHardware!
+  return (*fun_new_hardware)(population, owner);
+}
+
+
+void cPopulationInterface::RecycleHardware(cHardwareBase * out_hardware)
+{
+  assert(fun_recycle != NULL);  // All interfaces must have a RecycleHArdware!
+  (*fun_recycle)(out_hardware);
+}
+
+
+bool cPopulationInterface::Divide(cOrganism * parent, cGenome & child_genome)
+{
+  assert (fun_divide != NULL);       // All interfaces must have a Divide!
+  return (*fun_divide)(population, cell_id, parent, child_genome);  
+}
+
+bool cPopulationInterface::TestOnDivide() const
+{
+  if (population == NULL) return false;
+  assert(fun_test_on_divide != NULL);
+  return (*fun_test_on_divide)(population, cell_id);
+}
+
+cOrganism * cPopulationInterface::GetNeighbor()
+{
+  if (fun_get_neighbor == NULL) return NULL;
+
+  assert(cell_id >= 0);
+  return (*fun_get_neighbor)(population, cell_id);
+}
+
+cBirthChamber & cPopulationInterface::GetBirthChamber()
+{
+  assert(fun_birth_chamber != NULL);
+  
+  return (*fun_birth_chamber)(population, cell_id);
+}
+
+int cPopulationInterface::GetNumNeighbors()
+{
+  if (fun_num_neighbors == NULL) return 0;
+
+  assert(cell_id >= 0);
+  return (*fun_num_neighbors)(population, cell_id);
+}
+
+void cPopulationInterface::Rotate(int direction)
+{
+  if (fun_rotate == NULL) return;
+
+  assert(cell_id >= 0);
+  (*fun_rotate)(population, cell_id, direction);
+}
+
+void cPopulationInterface::Breakpoint()
+{
+  if (fun_breakpoint == NULL) return;
+  (*fun_breakpoint)();
+}
+
+double cPopulationInterface::TestFitness()
+{
+  if (fun_test_fitness == NULL) return -1.0;
+  return (*fun_test_fitness)(population, cell_id);
+}
+
+int cPopulationInterface::GetInput()
+{
+  assert(fun_get_input != NULL);
+  return (*fun_get_input)(population, cell_id);
+}
+
+int cPopulationInterface::GetInputAt(int & input_pointer)
+{
+  assert(fun_get_input_at != NULL);
+  return (*fun_get_input_at)(population, cell_id, input_pointer);
+}
+
+int cPopulationInterface::Debug()
+{
+  assert(fun_debug != NULL);
+  return (*fun_debug)(population, cell_id);
+}
+
+const tArray<double> & cPopulationInterface::GetResources()
+{
+  assert(fun_get_resources != NULL);
+  return (*fun_get_resources)(population, cell_id);
+}
+
+void cPopulationInterface::UpdateResources(const tArray<double> & res_change)
+{
+  assert(fun_update_resources != NULL);
+  (*fun_update_resources)(population, cell_id, res_change);
+}
+
+void cPopulationInterface::Die()
+{
+  if (fun_kill_cell == NULL) return;
+  (*fun_kill_cell)(population, cell_id);
+}
+
+void cPopulationInterface::Kaboom()
+{
+	if (fun_kill_surround_cell == NULL) return;
+	(*fun_kill_surround_cell)(population, cell_id);
+}
+
+bool cPopulationInterface::SendMessage(cOrgMessage & mess)
+{
+  if (fun_send_message == NULL) return false;
+  return (*fun_send_message)(population, cell_id, mess);
+}
+
+int cPopulationInterface::ReceiveValue()
+{
+  assert(fun_receive_value != NULL);
+  return (*fun_receive_value)(population, cell_id);
+}
+
+bool cPopulationInterface::InjectParasite(cOrganism * parent, 
+					  const cGenome & injected_code)
+{
+  if (fun_inject_parasite == NULL) return false;
+  return (*fun_inject_parasite)(population, cell_id, parent, injected_code);
+}
+
+bool cPopulationInterface::UpdateMerit(double new_merit)
+{
+  if (fun_update_merit == NULL) return false;
+  return (*fun_update_merit)(population, cell_id, new_merit);
+}

Copied: trunk/source/main/cPopulationInterface.h (from rev 313, trunk/source/main/population_interface.hh)

Deleted: trunk/source/main/callback_util.cc
===================================================================
--- trunk/source/main/callback_util.cc	2005-09-15 23:16:19 UTC (rev 313)
+++ trunk/source/main/callback_util.cc	2005-09-16 02:10:20 UTC (rev 314)
@@ -1,276 +0,0 @@
-//////////////////////////////////////////////////////////////////////////////
-// Copyright (C) 1993 - 2003 California Institute of Technology             //
-//                                                                          //
-// Read the COPYING and README files, or contact 'avida at alife.org',         //
-// before continuing.  SOME RESTRICTIONS MAY APPLY TO USE OF THIS FILE.     //
-//////////////////////////////////////////////////////////////////////////////
-
-#ifndef CALLBACK_UTIL_HH
-#include "callback_util.hh"
-#endif
-
-#ifndef AVIDA_HH
-#include "avida.hh"
-#endif
-#ifndef AVIDA_DRIVER_BASE_HH
-#include "avida_driver_base.hh"
-#endif
-#ifndef BIRTH_CHAMBER_HH
-#include "birth_chamber.hh"
-#endif
-#ifndef CONFIG_HH
-#include "config.hh"
-#endif
-#ifndef ENVIRONMENT_HH
-#include "environment.hh"
-#endif
-#ifndef GENOTYPE_HH
-#include "genotype.hh"
-#endif
-#ifndef HARDWARE_BASE_HH
-#include "cHardwareBase.h"
-#endif
-#ifndef HARDWARE_FACTORY_HH
-#include "cHardwareFactory.h"
-#endif
-#ifndef ORG_MESSAGE_HH
-#include "org_message.hh"
-#endif
-#ifndef ORGANISM_HH
-#include "organism.hh"
-#endif
-#ifndef POPULATION_HH
-#include "population.hh"
-#endif
-#ifndef POPULATION_CELL_HH
-#include "population_cell.hh"
-#endif
-#ifndef POPULATION_INTERFACE_HH
-#include "population_interface.hh"
-#endif
-#ifndef TEST_CPU_HH
-#include "cTestCPU.h"
-#endif
-
-
-using namespace std;
-
-
-cHardwareBase * cCallbackUtil::CB_NewHardware(cPopulation * pop,
-					      cOrganism * owner)
-{
-  cInstSet * inst_set;
-
-  // Determine which inst_set we should be using...
-  // If we're in a population, setup the inst_set properly.
-  if (pop != NULL) inst_set = &(pop->GetEnvironment().GetInstSet());
-
-  // Otherwise, use the test inst lib...
-  else inst_set = cTestCPU::GetInstSet();
-
-  // For the moment, we only have one hardware type...
-  assert(inst_set != NULL && inst_set->OK());
-  cHardwareBase * new_hardware =
-    cHardwareFactory::Create(owner, inst_set, cConfig::GetHardwareType());
-
-  return new_hardware;
-}
-
-
-void cCallbackUtil::CB_RecycleHardware(cHardwareBase * out_hardware)
-{
-  cHardwareFactory::Recycle(out_hardware);
-}
-
-
-// Callback for a divide inside of a population.  Return parent alive.
-bool cCallbackUtil::CB_Divide(cPopulation * pop, int cell_id,
-			      cOrganism * parent, cGenome & child_genome)
-{
-  assert(pop != NULL);
-  assert(parent != NULL);
-  assert(pop->GetCell(cell_id).GetOrganism() == parent);
-
-  return pop->ActivateOffspring(child_genome, *parent);
-}
-
-
-// Callback for a divide outside of a population
-bool cCallbackUtil::CB_TestDivide(cPopulation * pop, int cell_id,
-				  cOrganism * parent, cGenome & child_genome)
-{
-  assert(pop == NULL);  // Must not be in a population...
-
-  // Reset the parent from the divide
-  parent->GetPhenotype().TestDivideReset(parent->GetGenome().GetSize());
-
-  // @CAO in the future, we probably want to pass this child the test_cpu!
-
-  return true;
-}
-
-// Callback to find out if we need to run a test CPU on all divides...
-bool cCallbackUtil::CB_TestOnDivide(cPopulation * pop, int cell_id)
-{
-  assert(pop != NULL); // Must be in a population...
-  return cConfig::GetTestOnDivide();
-}
-
-cOrganism * cCallbackUtil::CB_GetNeighbor(cPopulation * pop, int cell_id)
-{
-  assert(pop != NULL);
-  cPopulationCell & cell = pop->GetCell(cell_id);
-  assert(cell.IsOccupied());
-
-  return cell.ConnectionList().GetFirst()->GetOrganism();
-}
-
-
-int cCallbackUtil::CB_GetNumNeighbors(cPopulation * pop, int cell_id)
-{
-  assert(pop != NULL);
-  cPopulationCell & cell = pop->GetCell(cell_id);
-  assert(cell.IsOccupied());
-
-  return cell.ConnectionList().GetSize();
-}
-
-
-void cCallbackUtil::CB_Rotate(cPopulation * pop, int cell_id,
-				    int direction)
-{
-  assert(pop != NULL);
-  cPopulationCell & cell = pop->GetCell(cell_id);
-  assert(cell.IsOccupied());
-
-  if (direction >= 0) cell.ConnectionList().CircNext();
-  else cell.ConnectionList().CircPrev();
-}
-
-
-void cCallbackUtil::CB_Breakpoint()
-{
-  cAvidaDriver_Base::main_driver->SignalBreakpoint();
-}
-
-
-double cCallbackUtil::CB_TestFitness(cPopulation * pop, int cell_id)
-{
-  assert(pop != NULL);
-  cPopulationCell & cell = pop->GetCell(cell_id);
-  assert(cell.IsOccupied());
-
-  return cell.GetOrganism()->GetGenotype()->GetTestFitness();
-}
-
-
-int cCallbackUtil::CB_GetInput(cPopulation * pop, int cell_id)
-{
-  if (pop == NULL) return cTestCPU::GetInput();
-  cPopulationCell & cell = pop->GetCell(cell_id);
-  assert(cell.IsOccupied());
-  return cell.GetInput();
-}
-
-int cCallbackUtil::CB_GetInputAt(cPopulation * pop, int cell_id, int & input_pointer)
-{
-  if (pop == NULL) return cTestCPU::GetInputAt(input_pointer);
-  cPopulationCell & cell = pop->GetCell(cell_id);
-  assert(cell.IsOccupied());
-  return cell.GetInputAt(input_pointer);
-}
-
-int cCallbackUtil::CB_Debug(cPopulation * pop, int cell_id)
-{
-  if (pop == NULL) return -1;
-  cPopulationCell & cell = pop->GetCell(cell_id);
-  assert(cell.IsOccupied());
-  return cell.GetOrganism()->GetGenotype()->GetID();
-}
-
-
-const tArray<double> &
-cCallbackUtil::CB_GetResources(cPopulation * pop, int cell_id)
-{
-  if (pop == NULL) return cTestCPU::GetResources();
-
-  // @CAO for the moment, ignore the possibility of local resources...
-  return pop->GetCellResources(cell_id);
-}
-
-
-void cCallbackUtil::CB_UpdateResources(cPopulation * pop, int cell_id,
-				       const tArray<double> & res_change)
-{
-  if (pop == NULL) return cTestCPU::UpdateResources(res_change);
-
-  // @CAO for the moment, ignore the possibility of local resources...
-  return pop->UpdateCellResources(res_change, cell_id);
-}
-
-
-void cCallbackUtil::CB_KillCell(cPopulation * pop, int death_id)
-{
-  assert(pop != NULL);
-  cPopulationCell & death_cell = pop->GetCell(death_id);
-  pop->KillOrganism(death_cell);
-}
-
-void cCallbackUtil::CB_KillSurroundCell(cPopulation * pop, int commie_id)
-{
-	assert (pop != NULL);
-	cPopulationCell & death_cell = pop->GetCell(commie_id);
-	pop->Kaboom(death_cell);
-}
-
-bool cCallbackUtil::CB_SendMessage(cPopulation * pop, int cell_id, cOrgMessage & mess)
-{
-  mess.SetSenderID(cell_id);
-  mess.SetTime(pop->GetUpdate());
-  cPopulationCell & cell = pop->GetCell(cell_id);
-  if(cell.ConnectionList().GetFirst() == NULL)
-    return false;
-  mess.SetRecipientID(cell.ConnectionList().GetFirst()->GetID());
-  return cell.ConnectionList().GetFirst()->GetOrganism()->ReceiveMessage(mess);
-}
-
-int cCallbackUtil::CB_ReceiveValue(cPopulation * pop, int cell_id)
-{
-  if (pop == NULL) return cTestCPU::GetReceiveValue();
-
-  cPopulationCell & cell = pop->GetCell(cell_id);
-  assert(cell.IsOccupied());
-
-  const int num_neighbors = cell.ConnectionList().GetSize();
-  for (int i = 0; i < num_neighbors; i++) {
-	cPopulationCell & cell = pop->GetCell(cell_id);
-	cell.ConnectionList().CircNext();
-
-    cOrganism * cur_neighbor = cell.ConnectionList().GetFirst()->GetOrganism();
-    if (cur_neighbor == NULL || cur_neighbor->GetSentActive() == false) {
-      continue;
-    }
-
-    return cur_neighbor->RetrieveSentValue();
-  }
-
-  return 0;
-
-}
-
-bool cCallbackUtil::CB_InjectParasite(cPopulation * pop, int cell_id, cOrganism * parent,
-				      const cGenome & injected_code)
-{
-  assert(pop != NULL);
-  assert(parent != NULL);
-  assert(pop->GetCell(cell_id).GetOrganism() == parent);
-
-  return pop->ActivateInject(*parent, injected_code);
-}
-
-bool cCallbackUtil::CB_UpdateMerit(cPopulation * pop, int cell_id,
-				   double new_merit)
-{
-  assert(pop != NULL);
-  return pop->UpdateMerit(cell_id, new_merit);
-}

Deleted: trunk/source/main/callback_util.hh
===================================================================
--- trunk/source/main/callback_util.hh	2005-09-15 23:16:19 UTC (rev 313)
+++ trunk/source/main/callback_util.hh	2005-09-16 02:10:20 UTC (rev 314)
@@ -1,51 +0,0 @@
-//////////////////////////////////////////////////////////////////////////////
-// Copyright (C) 1993 - 2003 California Institute of Technology             //
-//                                                                          //
-// Read the COPYING and README files, or contact 'avida at alife.org',         //
-// before continuing.  SOME RESTRICTIONS MAY APPLY TO USE OF THIS FILE.     //
-//////////////////////////////////////////////////////////////////////////////
-
-#ifndef CALLBACK_UTIL_HH
-#define CALLBACK_UTIL_HH
-
-class cGenome;
-class cHardwareBase;
-class cOrganism;
-class cPopulation;
-class cPopulationInterface;
-class cOrgMessage;
-class cCodeLabel;
-template <class T> class tArray;
-
-class cCallbackUtil {
-public:
-  // Callbacks from organism...
-  static cHardwareBase * CB_NewHardware(cPopulation * pop, cOrganism * owner);
-  static void CB_RecycleHardware(cHardwareBase * out_hardware);
-  static bool CB_Divide(cPopulation * pop, int cell_id,
-			cOrganism * parent, cGenome & child_genome);
-  static bool CB_TestDivide(cPopulation * pop, int cell_id,
-			    cOrganism * parent, cGenome & child_genome);
-  static bool CB_TestOnDivide(cPopulation * pop, int cell_id);
-  static cOrganism * CB_GetNeighbor(cPopulation * pop, int cell_id);
-  static int CB_GetNumNeighbors(cPopulation * pop, int cell_id);
-  static void CB_Rotate(cPopulation * pop, int cell_id, int direction);
-  static void CB_Breakpoint();
-  static double CB_TestFitness(cPopulation * pop, int cell_id);
-  static int CB_GetInput(cPopulation * pop, int cell_id);
-  static int CB_GetInputAt(cPopulation * pop, int cell_id, int & input_pointer);
-  static int CB_Debug(cPopulation * pop, int cell_id);
-  static const tArray<double>& CB_GetResources(cPopulation * pop, int cell_id);
-  static void CB_UpdateResources(cPopulation  * pop, int cell_id,
-				 const tArray<double> & res_change);
-  static void CB_KillCell(cPopulation * pop, int death_id);
-  static void CB_KillSurroundCell(cPopulation * pop, int commie_id);
-  static bool CB_SendMessage(cPopulation * pop, int cell_id, cOrgMessage & mess);
-  static int CB_ReceiveValue(cPopulation * pop, int cell_id);
-  static bool CB_InjectParasite(cPopulation * pop, int cell_id, cOrganism * parent,
-				const cGenome & injected_code);
-
-  static bool CB_UpdateMerit(cPopulation * pop, int cell_id, double new_merit);
-};
-
-#endif

Deleted: trunk/source/main/config.cc
===================================================================
--- trunk/source/main/config.cc	2005-09-15 23:16:19 UTC (rev 313)
+++ trunk/source/main/config.cc	2005-09-16 02:10:20 UTC (rev 314)
@@ -1,683 +0,0 @@
-//////////////////////////////////////////////////////////////////////////////
-// Copyright (C) 1993 - 2003 California Institute of Technology             //
-//                                                                          //
-// Read the COPYING and README files, or contact 'avida at alife.org',         //
-// before continuing.  SOME RESTRICTIONS MAY APPLY TO USE OF THIS FILE.     //
-//////////////////////////////////////////////////////////////////////////////
-
-#include "config.hh"
-
-#include "defs.hh"
-#include "cEventFactoryManager.h"
-#include "genesis.hh"
-#include "cPopulationEventFactory.h"
-#include "tools.hh"
-
-using namespace std;
-
-tList<cConfig::cConfigGroup> cConfig::group_list;
-bool cConfig::analyze_mode;
-bool cConfig::primitive_mode;
-bool cConfig::interactive_analyze;
-cString cConfig::default_dir;
-cString cConfig::genesis_filename;
-cString cConfig::inst_filename;
-cString cConfig::event_filename;
-cString cConfig::analyze_filename;
-cString cConfig::env_filename;
-cString cConfig::start_creature;
-cString cConfig::clone_filename;
-cString cConfig::load_pop_filename;
-int cConfig::max_updates;
-int cConfig::max_generations;
-int cConfig::end_condition_mode;
-int cConfig::world_x;
-int cConfig::world_y;
-int cConfig::world_geometry;
-int cConfig::num_demes;
-int cConfig::rand_seed;
-double cConfig::point_mut_prob;
-double cConfig::copy_mut_prob;
-double cConfig::ins_mut_prob;
-double cConfig::del_mut_prob;
-double cConfig::div_mut_prob;
-double cConfig::divide_mut_prob;
-double cConfig::divide_ins_prob;
-double cConfig::divide_del_prob;
-double cConfig::parent_mut_prob;
-int cConfig::special_mut_line;
-double cConfig::recomb_prob;
-int cConfig::num_modules;
-int cConfig::cont_rec_regs;
-int cConfig::corespond_rec_regs;
-int cConfig::two_fold_cost_sex;
-int cConfig::same_length_sex;
-int cConfig::num_instructions;
-int cConfig::hardware_type;
-int cConfig::max_cpu_threads;
-double cConfig::thread_slicing_method;
-int cConfig::size_merit_method;
-int cConfig::base_size_merit;
-double cConfig::default_bonus;
-int cConfig::task_merit_method;
-int cConfig::max_label_exe_size;
-int cConfig::merit_time;
-double cConfig::merit_given;
-double cConfig::merit_received;
-int cConfig::max_donate_kin_distance;
-int cConfig::max_donate_edit_distance;
-int cConfig::max_donates;
-int cConfig::num_tasks;
-int cConfig::num_reactions;
-int cConfig::num_resources;
-int cConfig::slicing_method;
-int cConfig::birth_method;
-int cConfig::prefer_empty;
-int cConfig::death_method;
-int cConfig::alloc_method;
-int cConfig::divide_method;
-int cConfig::required_task;
-int cConfig::immunity_task;
-int cConfig::required_reaction;
-int cConfig::lineage_creation_method;
-int cConfig::generation_inc_method;
-int cConfig::age_limit;
-double cConfig::age_deviation;
-double cConfig::child_size_range;
-double cConfig::min_copied_lines;
-double cConfig::min_exe_lines;
-int cConfig::require_allocate;
-bool cConfig::test_on_divide;
-bool cConfig::test_sterilize;
-double cConfig::revert_fatal;
-double cConfig::revert_neg;
-double cConfig::revert_neut;
-double cConfig::revert_pos;
-double cConfig::sterilize_fatal;
-double cConfig::sterilize_neg;
-double cConfig::sterilize_neut;
-double cConfig::sterilize_pos;
-int cConfig::fail_implicit;
-int cConfig::ave_time_slice;
-int cConfig::species_threshold;
-int cConfig::threshold;
-int cConfig::genotype_print;
-int cConfig::species_print;
-int cConfig::species_recording;
-int cConfig::genotype_print_dom;
-int cConfig::test_cpu_time_mod;
-int cConfig::track_main_lineage;
-bool cConfig::log_threshold_only;
-bool cConfig::log_creatures;
-int cConfig::log_genotypes;
-bool cConfig::log_threshold;
-bool cConfig::log_species;
-bool cConfig::log_landscape;
-bool cConfig::log_lineages;
-int cConfig::debug_level;
-int cConfig::view_mode;
-double cConfig::die_prob;
-
-void cConfig::InitGroupList(){
-  // Start with the Architecture variables...
-  cConfigGroup * arch_group = new cConfigGroup("Architecture Variables");
-  group_list.PushRear(arch_group);
-  
-  arch_group->Add(max_updates, "-1", "MAX_UPDATES",
-                  "Maximum updates to run experiment (-1 = no limit)");
-  arch_group->Add(max_generations, "-1", "MAX_GENERATIONS",
-                  "Maximum generations to run experiment (-1 = no limit)");
-  arch_group->Add(end_condition_mode, "0", "END_CONDITION_MODE",
-                  "End run when ...\n0 = MAX_UPDATES _OR_ MAX_GENERATIONS is reached\n1 = MAX_UPDATES _AND_ MAX_GENERATIONS is reached");
-  arch_group->Add(world_x, "100", "WORLD-X",
-                  "Width of the Avida world");
-  arch_group->Add(world_y, "100", "WORLD-Y",
-                  "Height of the Avida world");
-  arch_group->Add(world_geometry, "2", "WORLD_GEOMETRY",
-                  "1 = Bounded Grid\n2 = Torus");
-  arch_group->Add(num_demes, "0", "NUM_DEMES",
-                  "Number of independed groups in the population; 0=off");
-  arch_group->Add(rand_seed, "0", "RANDOM_SEED",
-                  "Random number seed (0 for based on time)");
-  arch_group->Add(hardware_type, "0", "HARDWARE_TYPE",
-                  "0 = Original CPUs\n1 = New, Stack-based CPUs");
-  
-  // Configuration file group.
-  cConfigGroup * file_group = new cConfigGroup("Configuration Files");
-  group_list.PushRear(file_group);
-  
-  file_group->Add(default_dir, DEFAULT_DIR, "DEFAULT_DIR",
-                  "Directory in which config files are found");
-  file_group->Add(inst_filename, "inst_set.default", "INST_SET",
-                  "File containing instruction set");
-  file_group->Add(event_filename, "events.cfg", "EVENT_FILE",
-                  "File containing list of events during run");
-  file_group->Add(analyze_filename, "analyze.cfg", "ANALYZE_FILE",
-                  "File used for analysis mode");
-  file_group->Add(env_filename, "environment.cfg", "ENVIRONMENT_FILE",
-                  "File that describes the environment");
-  file_group->Add(start_creature, "organism.default", "START_CREATURE",
-                  "Organism to seed the soup");
-  
-  // Reproduction group.
-  cConfigGroup * repro_group = new cConfigGroup("Birth and Death");
-  group_list.PushRear(repro_group);
-  
-  repro_group->Add(birth_method, "4", "BIRTH_METHOD",
-                   "0 = Replace random organism in neighborhood\n1 = Replace oldest organism in neighborhood\n2 = Replace largest Age/Merit in neighborhood\n3 = Place only in empty cells in neighborhood\n4 = Replace random from population (Mass Action)\n5 = Replace oldest in entire population (like Tierra)\n6 = Replace random within deme");
-  repro_group->Add(prefer_empty, "1", "PREFER_EMPTY",
-                   "Are empty cells given preference in offsping placement?");
-  repro_group->Add(death_method, "1", "DEATH_METHOD",
-                   "0 = Never die of old age.\n1 = Die when inst executed = AGE_LIMIT (+deviation)\n2 = Die when inst executed = length*AGE_LIMIT (+dev)");
-  repro_group->Add(age_limit, "20", "AGE_LIMIT",
-                   "Modifies DEATH_METHOD");
-  repro_group->Add(age_deviation, "0", "AGE_DEVIATION",
-                   "Creates a distribution around AGE_LIMIT");
-  repro_group->Add(alloc_method, "0", "ALLOC_METHOD",
-                   "0 = Allocated space is set to default instruction.\n1 = Set to section of dead genome (Necrophilia)\n2 = Allocated space is set to random instruction.");
-  repro_group->Add(divide_method, "1", "DIVIDE_METHOD",
-                   "0 = Divide leaves state of mother untouched.\n1 = Divide resets state of mother (after the divide, we have 2 children)\n2 = Divide resets state of current thread only(does not touch possible parasite threads)");
-  repro_group->Add(generation_inc_method, "1", "GENERATION_INC_METHOD",
-                   "0 = Only the generation of the child is\n    increased on divide.\n1 = Both the generation of the mother and child are\n    increased on divide (good with DIVIDE_METHOD 1).");
-  repro_group->Add(recomb_prob, "1", "RECOMBINATION_PROB",
-                   "probability that recombination will happen when div-sex is used");
-  repro_group->Add(num_modules, "0", "MODULE_NUM",
-                   "number of modules in the genome");
-  repro_group->Add(cont_rec_regs, "1", "CONT_REC_REGS",
-                   "are (modular) recombination regions continuous");
-  repro_group->Add(corespond_rec_regs, "1", "CORESPOND_REC_REGS",
-                   "are (modular) recombination regions swapped at random or with corresponding ones, by location");
-  repro_group->Add(two_fold_cost_sex, "0", "TWO_FOLD_COST_SEX",
-                   "1 = only one recombined offspring is born.\n2 = both offspring are born");
-  repro_group->Add(same_length_sex, "0", "SAME_LENGTH_SEX",
-                   "0 = recombine with any genome\n1 = only recombine w/ same length");
-  
-  
-  // Divide Restrictions Group.
-  cConfigGroup * div_group = new cConfigGroup("Divide Restrictions");
-  group_list.PushRear(div_group);
-  
-  div_group->Add(child_size_range, "2.0", "CHILD_SIZE_RANGE",
-                 "Maximal differential between child and parent sizes.");
-  div_group->Add(min_copied_lines, "0.5", "MIN_COPIED_LINES",
-                 "Code fraction which must be copied before divide.");
-  div_group->Add(min_exe_lines, "0.5", "MIN_EXE_LINES",
-                 "Code fraction which must be executed before divide.");
-  div_group->Add(require_allocate, "1", "REQUIRE_ALLOCATE",
-                 "Is a an allocate required before a divide? (0/1)");
-  div_group->Add(required_task, "-1", "REQUIRED_TASK",
-                 "Task ID required for successful divide.");
-  div_group->Add(immunity_task, "-1", "IMMUNITY_TASK",
-                 "Task providing immunity from the required task.");
-  div_group->Add(immunity_task, "-1", "IMMUNITY_TASK",
-		 "Task providing immunity from the required task.");
-  div_group->Add(required_reaction, "-1", "REQUIRED_REACTION",
-                 "Reaction ID required for successful divide.");
-  div_group->Add(die_prob, "0", "DIE_PROB",
-                 "probability of death when 'die' instruction is executed"); 
-  
-  
-  
-  // Mutations Group
-  cConfigGroup * muts_group = new cConfigGroup("Mutations");
-  group_list.PushRear(muts_group);
-  
-  muts_group->Add(point_mut_prob, "0.0", "POINT_MUT_PROB",
-                  "Mutation rate (per-location per update)");
-  muts_group->Add(copy_mut_prob, "0.0075", "COPY_MUT_PROB",
-                  "Mutation rate (per copy)");
-  muts_group->Add(ins_mut_prob, "0.0", "INS_MUT_PROB",
-                  "Insertion rate (per site, applied on divide)");
-  muts_group->Add(del_mut_prob, "0.0", "DEL_MUT_PROB",
-                  "Deletion rate (per site, applied on divide)");
-  muts_group->Add(div_mut_prob, "0.0", "DIV_MUT_PROB",
-                  "Mutation rate (per site, applied on divide)");
-  muts_group->Add(divide_mut_prob, "0.0", "DIVIDE_MUT_PROB",
-                  "Mutation rate (per divide)");
-  muts_group->Add(divide_ins_prob, "0.05", "DIVIDE_INS_PROB",
-                  "Insertion rate (per divide)");
-  muts_group->Add(divide_del_prob, "0.05", "DIVIDE_DEL_PROB",
-                  "Deletion rate (per divide)");
-  muts_group->Add(parent_mut_prob, "0.0", "PARENT_MUT_PROB",
-                  "Per-site, in parent, on divide");
-  muts_group->Add(special_mut_line, "-1", "SPECIAL_MUT_LINE",
-                  "If this is >= 0, ONLY this line is mutated");
-  
-  
-  // Mutation reversions group
-  cConfigGroup * rev_group = new cConfigGroup("Mutation Reversion");
-  rev_group->SetComment("These slow down avida a lot, and should be set to 0.0 normally.");
-  group_list.PushRear(rev_group);
-  
-  rev_group->Add(revert_fatal, "0.0", "REVERT_FATAL",
-                 "Should any mutations be reverted on birth?");
-  rev_group->Add(revert_neg, "0.0", "REVERT_DETRIMENTAL",
-                 "  0.0 to 1.0; Probability of reversion.");
-  rev_group->Add(revert_neut, "0.0", "REVERT_NEUTRAL",
-                 "");
-  rev_group->Add(revert_pos, "0.0", "REVERT_BENEFICIAL",
-                 "");
-  rev_group->Add(sterilize_fatal, "0.0", "STERILIZE_FATAL",
-                 "Should any mutations clear (kill) the organism?");
-  rev_group->Add(sterilize_neg, "0.0", "STERILIZE_DETRIMENTAL",
-                 "  0.0 to 1.0; Probability of reset.");
-  rev_group->Add(sterilize_neut, "0.0", "STERILIZE_NEUTRAL",
-                 "");
-  rev_group->Add(sterilize_pos, "0.0", "STERILIZE_BENEFICIAL",
-                 "");
-  rev_group->Add(fail_implicit, "0", "FAIL_IMPLICIT",
-                 "Should copies that failed *not* due to mutations\nbe eliminated?");
-  
-  // Time slicing group
-  cConfigGroup * time_group = new cConfigGroup("Time Slicing");
-  group_list.PushRear(time_group);
-  
-  time_group->Add(ave_time_slice, "30", "AVE_TIME_SLICE",
-                  "Ave number of insts per org per update");
-  time_group->Add(slicing_method, "2", "SLICING_METHOD",
-                  "0 = CONSTANT: all organisms get default...\n1 = PROBABILISTIC: Run _prob_ proportional to merit.\n2 = INTEGRATED: Perfectly integrated deterministic.");
-  time_group->Add(size_merit_method, "0", "SIZE_MERIT_METHOD",
-                  "0 = off (merit is independent of size)\n1 = Merit proportional to copied size\n2 = Merit prop. to executed size\n3 = Merit prop. to full size\n4 = Merit prop. to min of executed or copied size\n5 = Merit prop. to sqrt of the minimum size");
-  time_group->Add(task_merit_method, "1", "TASK_MERIT_METHOD",
-                  "0 = No task bonuses\n1 = Bonus just equals the task bonus");
-  time_group->Add(max_cpu_threads, "1", "MAX_CPU_THREADS",
-                  "Number of Threads a CPU can spawn");
-  time_group->Add(thread_slicing_method, "0", "THREAD_SLICING_METHOD",
-                  "Formula for and organism's thread slicing -> 1 + (num_organism_threads-1) * THREAD_SLICING_METHOD.\n0 = One thread executed per time slice.\n1 = All threads executed each time slice.\n");
-  time_group->Add(max_label_exe_size, "1", "MAX_LABEL_EXE_SIZE",
-                  "Max nops marked as executed when labels are used");
-  time_group->Add(base_size_merit, "100", "BASE_SIZE_MERIT",
-                  "Base merit when size is *not* used");
-  time_group->Add(default_bonus, "1", "DEFAULT_BONUS",
-                  "The bonus an organism gets before it has completed any tasks");
-  time_group->Add(merit_time, "0", "MERIT_TIME",
-                  "0 = Merit Calculated when task completed\n1 = Merit Calculated on Divide");
-  time_group->Add(merit_given, "0.0", "MERIT_GIVEN",
-                  "Fraction of merit donated with 'donate' command");
-  time_group->Add(merit_received, "0.0", "MERIT_RECEIVED",
-                  "Multiplier of merit given with 'donate' command");
-  time_group->Add(max_donate_kin_distance, "-1", "MAX_DONATE_KIN_DIST",
-                  "Limit on distance of relation for donate; -1=no max");
-  time_group->Add(max_donate_edit_distance, "-1", "MAX_DONATE_EDIT_DIST",
-                  "Limit on genetic (edit) distance for donate; -1=no max");
-  time_group->Add(max_donates, "1000000", "MAX_DONATES",
-                  "Limit on number of donates organisms are allowed.");
-  
-  
-  // Geneology group
-  cConfigGroup * gen_group = new cConfigGroup("Geneology");
-  group_list.PushRear(gen_group);
-  
-  gen_group->Add(track_main_lineage, "1", "TRACK_MAIN_LINEAGE",
-                 "Keep all ancestors of the active population?\n0=no, 1=yes, 2=yes,w/sexual population");
-  gen_group->Add(threshold, "3", "THRESHOLD",
-                 "Number of organisms in a genotype needed for it\n  to be considered viable.");
-  gen_group->Add(genotype_print, "0", "GENOTYPE_PRINT",
-                 "0/1 (off/on) Print out all threshold genotypes?");
-  gen_group->Add(genotype_print_dom, "0", "GENOTYPE_PRINT_DOM",
-                 "Print out a genotype if it stays dominant for\n  this many updates. (0 = off)");
-  gen_group->Add(species_threshold, "2", "SPECIES_THRESHOLD",
-                 "max failure count for organisms to be same species");
-  gen_group->Add(species_recording, "0", "SPECIES_RECORDING",
-                 "1 = full, 2 = limited search (parent only)");
-  gen_group->Add(species_print, "0", "SPECIES_PRINT",
-                 "0/1 (off/on) Print out all species?");
-  gen_group->Add(test_cpu_time_mod, "20", "TEST_CPU_TIME_MOD",
-                 "Time allocated in test CPUs (multiple of length)");
-  
-  
-  // Log Files group
-  cConfigGroup * log_group = new cConfigGroup("Log Files");
-  group_list.PushRear(log_group);
-  
-  log_group->Add(log_creatures, "0", "LOG_CREATURES",
-                 "0/1 (off/on) toggle to print file.");
-  log_group->Add(log_genotypes, "0", "LOG_GENOTYPES",
-                 "0 = off, 1 = print ALL, 2 = print threshold ONLY.");
-  log_group->Add(log_threshold, "0", "LOG_THRESHOLD",
-                 "0/1 (off/on) toggle to print file.");
-  log_group->Add(log_species, "0", "LOG_SPECIES",
-                 "0/1 (off/on) toggle to print file.");
-  log_group->Add(log_landscape, "0", "LOG_LANDSCAPE",
-                 "0/1 (off/on) toggle to print file.");
-  
-  
-  // Viewer group
-  cConfigGroup * view_group = new cConfigGroup("Viewer Settings");
-  group_list.PushRear(view_group);
-  
-  view_group->Add(view_mode, "0", "VIEW_MODE",
-                  "Initial viewer screen");
-  
-  // Lineages group
-  cConfigGroup * lin_group = new cConfigGroup("Lineage");
-  lin_group->SetComment("NOTE: This should probably be called \"Clade\"\nThis one can slow down avida a lot. It is used to get an idea of how\noften an advantageous mutation arises, and where it goes afterwards.\nLineage creation options are.  Works only when LOG_LINEAGES is set to 1.\n  0 = manual creation (on inject, use successive integers as lineage labels).\n  1 = when a child's (potential) fitness is higher than that of its parent.\n  2 = when a child's (potential) fitness is higher than max in population.\n  3 = when a child's (potential) fitness is higher than max in dom. lineage\n*and* the child is in the dominant lineage, or (2)\n  4 = when a child's (potential) fitness is higher than max in dom. lineage\n(and that of its own lineage)\n  5 = same as child's (potential) fitness is higher than that of the\n      currently dominant organism, and also than that of any organism\n      currently in the same lineage.\n  6 = when a child's (potential) fitness is higher th!
 an any organism\n      currently in the same lineage.\n  7 = when a child's (potential) fitness is higher than that of any\n      organism in its line of descent");
-  
-  group_list.PushRear(lin_group);
-  
-  lin_group->Add(log_lineages, "0", "LOG_LINEAGES",
-                 "");
-  lin_group->Add(lineage_creation_method, "0", "LINEAGE_CREATION_METHOD",
-                 "");
-  
-}
-
-void cConfig::Setup(cGenesis & genesis)
-{
-  rand_seed = genesis.ReadInt("RANDOM_SEED");
-  cout << "Random Seed: " << rand_seed;
-  g_random.ResetSeed(rand_seed);
-  if( rand_seed != g_random.GetSeed() ) cout << " -> " << g_random.GetSeed();
-  cout << endl;
-  
-  tListIterator<cConfigGroup> group_it(group_list);
-  cConfigGroup * cur_group;
-  while ((cur_group = group_it.Next()) != NULL) {
-    cur_group->LoadValues(genesis);
-  }
-  
-  /***
-    * Handle any special modifications to any of the variables now that
-    * they've been loaded.
-    ***/
-  
-  // The default directory should end in a '/'.
-  char dir_tail = default_dir[default_dir.GetSize() - 1];
-  if (dir_tail != '\\' && dir_tail != '/') default_dir += "/";
-  
-  // Determine if any variables were set that require test CPUs to be run
-  // at every divide.
-  test_on_divide = false;
-  if ((revert_fatal > 0.0) || (revert_neg > 0.0) || (revert_neut > 0.0) ||
-      (revert_pos > 0.0) || (fail_implicit > 0)) {
-    test_on_divide = true;
-  }
-  
-  test_sterilize = false;
-  if ((sterilize_fatal > 0.0) || (sterilize_neg > 0.0) ||
-      (sterilize_neut > 0.0) || (sterilize_pos > 0.0)) {
-    test_sterilize = true;
-  }
-  
-  // Determine if we are only logging threshold genotypes...
-  log_threshold_only = false;
-  if (log_genotypes > 1) log_threshold_only = true;
-  
-  // Warn if there are settings in the genesis file that have not been read.
-  genesis.WarnUnused();
-  
-  // Test printing... @CAO
-  //  PrintGenesis("genesis.test");
-}
-
-void cConfig::Setup(int argc, char * argv[])
-{
-  /***
-  * Load all of the variables from genesis.
-  ***/
-  
-  default_dir = DEFAULT_DIR;
-  
-  cGenesis genesis;
-  genesis.SetVerbose();
-  ProcessConfiguration(argc, argv, genesis);
-  
-  Setup(genesis);
-}
-
-void cConfig::SetupMS()
-{
-#ifdef PLATFORM_WINDOWS
-  OSVERSIONINFO	osVersion;
-  
-  SetFileApisToOEM();             // use console character set for files
-  memset (&osVersion, 0, sizeof (osVersion));
-  osVersion.dwOSVersionInfoSize = sizeof (osVersion);
-  GetVersionEx (&osVersion);
-  if (osVersion.dwPlatformId == VER_PLATFORM_WIN32_NT) {
-    // Only need to set Code Pages for NT. Default console on Win95 is OEM.
-    // In fact, these APIs fail on Win95 w/ rc = 120 (API only works in NT
-    //  mode).
-    if (!SetConsoleCP (GetOEMCP()))        // and for Console input
-      cerr << "Warning: Unable to set input character set, rc="
-        << GetLastError() << endl;
-    if (!SetConsoleOutputCP (GetOEMCP()))  // and for Console output
-      cerr << "Warning: Unable to set output character set, rc="
-        << GetLastError() << endl;
-  }
-#endif
-}
-
-void cConfig::PrintGenesis(const cString & filename)
-{
-  ofstream fp(filename);
-  
-  // Print out the generic header, including the version ID.
-  fp << "#############################################################################" << endl
-    << "# This file includes all the basic run-time defines for avida." << endl
-    << "# For more information, see doc/genesis.html" << endl
-    << "#############################################################################" << endl
-    << endl
-    << "VERSION_ID " << VERSION << "   # Do not change this value."
-    << endl;
-  
-  // Loop through the groups, and print out all of the variables.
-  
-  tListIterator<cConfigGroup> group_it(group_list);
-  cConfigGroup * cur_group;
-  while ((cur_group = group_it.Next()) != NULL) {
-    // Print out the group name...
-    fp << endl;
-    fp << "### " << cur_group->GetName() << " ###" << endl;
-    
-    // If we have a comment about the current group, include it.
-    for (int i = 0; i < cur_group->GetComment().GetSize(); i++) {
-      fp << "# " << cur_group->GetComment().GetLine(i) << endl;
-    }
-    
-    // Print out everything for this group...
-    tListIterator<cConfigEntryBase> entry_it(cur_group->GetEntries());
-    cConfigEntryBase * cur_entry;
-    
-    // First, figure out the widest entry so we know where to put comments.
-    int max_width = 0;
-    while ((cur_entry = entry_it.Next()) != NULL) {
-      int cur_width = cur_entry->GetTag().GetSize() +
-      cur_entry->GetDefault().GetSize() + 1;
-      if (cur_width > max_width) max_width = cur_width;
-    }
-    
-    // Now, make a second pass printing everything.
-    entry_it.Reset();
-    while ((cur_entry = entry_it.Next()) != NULL) {
-      int cur_width = cur_entry->GetTag().GetSize() +
-      cur_entry->GetDefault().GetSize() + 1;
-      // Print the variable and its setting...
-      fp << cur_entry->GetTag() << " " << cur_entry->GetDefault();
-      
-      // Print some spaces before the description.
-      for (int i = cur_width; i < max_width; i++) fp << " ";
-      
-      // Print the first line of the description.
-      if (cur_entry->GetDesc().GetSize() == 0) {
-        fp << "  # " << endl;
-      } else {
-        fp << "  # " << cur_entry->GetDesc().GetLine(0) << endl;
-      }
-      
-      // Print the remaining lines of a description.
-      for (int i = 1; i < cur_entry->GetDesc().GetSize(); i++) {
-        for (int j = 0; j < max_width; j++) fp << " ";
-        fp << "  # " << cur_entry->GetDesc().GetLine(i) << endl;
-      }
-    }
-  }
-}
-
-//  void cConfig::PerturbTaskSet(double max_factor)
-//  {
-//    default_task_lib->Perturb(max_factor);
-//  }
-
-//  void cConfig::ChangeTaskSet(double prob_change, double min_bonus,
-//  			    double max_bonus)
-//  {
-//    default_task_lib->Change(prob_change, min_bonus, max_bonus);
-//  }
-
-
-// This function takes in the genesis file and the input arguments, and puts
-// out a pointer to a built-up cGenesis object.
-
-// @COW This function depends on the inclusion of the file
-// 'vent/cPopulation_descr.ci' for the automatic event documentation.
-// If you move the function away from here, move this include as well.
-
-
-void cConfig::ProcessConfiguration(int argc, char * argv[], cGenesis & genesis)
-{
-  const cString default_filename = "genesis";
-  genesis_filename = default_filename;
-  
-  int arg_num = 1;              // Argument number being looked at.
-  analyze_mode = false;         // Initialize analyze_mode tp be off.
-  primitive_mode = false;       // Initialize primitive_mode tp be off.
-  interactive_analyze = false;  // Don't start analyze interactively either.
-  
-  // Load all of the args into string objects for ease of access.
-  cString * args = new cString[argc];
-  for (int i = 0; i < argc; i++) args[i] = argv[i];
-  
-  
-  // -genesis option
-  
-  if (argc > 1 && (args[1] == "-g" || args[1] == "-genesis")) {
-    if (argc < 3) {
-      cerr << "Need filename for genesis file used." << endl;
-      exit(0);
-    }
-    genesis_filename = args[2];
-    arg_num += 2;
-  }
-  
-  
-  // Open and verify the genesis file.
-  
-  genesis.Open(genesis_filename);
-  
-  // If we failed to open the genesis file, and we are using the default,
-  // try creating it.
-  if (genesis.IsOpen() == false && genesis_filename == default_filename) {
-    cerr << "Warning: Unable to find file '" << genesis_filename
-    << "'.  Creating." << endl;
-    PrintGenesis(genesis_filename);
-    genesis.Open(genesis_filename);
-  }
-  
-  cString version_id = genesis.ReadString("VERSION_ID", "Unknown");
-  if (genesis.IsOpen() == true && version_id != VERSION) {
-    cerr << "/  WARNING   WARNING   WARNING   WARNING   WARNING  \\" << endl
-    << "|   Using incorrect genesis file.                   |" << endl
-    << "|   Version needed = \"" << VERSION
-    << "\".  Version used = \"" << version_id() << "\"   |" << endl
-    << "\\  WARNING   WARNING   WARNING   WARNING   WARNING  /" << endl
-    << endl;
-  }
-  
-  // Then scan through and process the rest of the args.
-  
-  while (arg_num < argc || genesis.IsOpen() == false) {
-    cString cur_arg = genesis.IsOpen() ? static_cast<cString>( args[arg_num] ) : static_cast<cString>( "--help" );
-    
-    // Test against the possible inputs.
-    if (cur_arg == "-events" || cur_arg == "-e") {
-      cout << "Known events:" << endl;
-      // @DMB - A cleaner way of constructing the cEventFactoryManager should be created
-      cEventFactoryManager event_manager;
-      event_manager.AddFactory(new cPopulationEventFactory(NULL));
-      event_manager.PrintAllEventDescriptions();
-      exit(0);
-    }
-    else if (cur_arg == "--help" || cur_arg == "-help" ||
-             cur_arg == "-h"     || genesis.IsOpen() == false) {
-      cout << "Options:"<<endl
-      << "  -g[enesis] <filename> Set genesis file to be <filename>"<<endl
-      << "  -h[elp]               Help on options (this listing)"<<endl
-      << "  -e[vents]             Print a list of all known events"<< endl
-      << "  -s[eed] <value>       Set random seed to <value>"<<endl
-      << "  -viewer <value>       Sets Viewer to <value>"<<endl
-      << "  -v[ersion]            Prints the version number"<<endl
-      << "  -set <name> <value>   Overide the genesis file"<<endl
-      << "  -l[oad] <filename>    Load a clone file"<<endl
-      << "  -loadpop <filename>   Load a saved population file (precedence over load)"<<endl
-      << "  -a[nalyze]            Process analyze.cfg instead of normal run."<<endl
-      << "  -i[nteractive]        Run analyze mode interactively."
-      // << "  -p[rimitive]          Overide viewer to be primitive."<<endl
-      << endl;
-      
-      exit(0);
-    }
-    else if (cur_arg == "-seed" || cur_arg == "-s") {
-      int in_seed = 0;
-      if (arg_num + 1 == argc || args[arg_num + 1][0] == '-') {
-        cerr<<"Must include a number as the random seed!"<<endl;
-        exit(0);
-      } else {
-        arg_num++;  if (arg_num < argc) cur_arg = args[arg_num];
-        in_seed = cur_arg.AsInt();
-      }
-      genesis.AddInput("RANDOM_SEED", in_seed);
-    } else if (cur_arg == "-analyze" || cur_arg == "-a") {
-      analyze_mode = true;
-    } else if (cur_arg == "-interactive" || cur_arg == "-i") {
-      analyze_mode = true;
-      interactive_analyze = true;
-    } else if (cur_arg == "-primitive" || cur_arg == "-p") {
-      primitive_mode = true;
-    } else if (cur_arg == "-load" || cur_arg == "-l") {
-      if (arg_num + 1 == argc || args[arg_num + 1][0] == '-') {
-        cerr<<"Must include a filename to load from"<<endl;
-        exit(0);
-      } else {
-        arg_num++;  if (arg_num < argc) cur_arg = args[arg_num];
-        clone_filename = cur_arg;
-      }
-    } else if (cur_arg == "-loadpop" || cur_arg == "-lp") {
-      if (arg_num + 1 == argc || args[arg_num + 1][0] == '-') {
-        cerr<<"Must include a filename to load from"<<endl;
-        exit(0);
-      } else {
-        arg_num++;  if (arg_num < argc) cur_arg = args[arg_num];
-        load_pop_filename = cur_arg;
-      }
-    } else if (cur_arg == "-version" || cur_arg == "-v") {
-      cout << " by Charles Ofria" << endl;
-      cout << " designed by Charles Ofria, Chris Adami, Travis Collier, C. Titus Brown, and Claus Wilke" << endl;
-      cout << " For more information, see: http://devolab.cse.msu.edu/software/avida/" << endl;
-      exit(0);
-    } else if (cur_arg == "-set") {
-      if (arg_num + 1 == argc || arg_num + 2 == argc) {
-        cerr << "'-set' option must be followed by name and value" << endl;
-        exit(0);
-      }
-      arg_num++;  if (arg_num < argc) cur_arg = args[arg_num];
-      cString name(cur_arg);
-      arg_num++;  if (arg_num < argc) cur_arg = args[arg_num];
-      cString value(cur_arg);
-      cout << "SET " << name() << " = " << value() << endl;
-      genesis.AddInput(name(), value());
-      
-    } else if (cur_arg == "-g" || cur_arg == "-genesis") {
-      cerr << "Error: -g[enesis] option must be listed first." << endl;
-      exit(0);
-    } else {
-      cerr << "Unknown Option: " << argv[arg_num] << endl
-      << "Type: \"" << argv[0] << " -h\" for a full option list." << endl;
-      exit(0);
-    }
-    
-    arg_num++;  if (arg_num < argc) cur_arg = args[arg_num];
-  }
-  
-  delete [] args;
-}

Deleted: trunk/source/main/config.hh
===================================================================
--- trunk/source/main/config.hh	2005-09-15 23:16:19 UTC (rev 313)
+++ trunk/source/main/config.hh	2005-09-16 02:10:20 UTC (rev 314)
@@ -1,506 +0,0 @@
-//////////////////////////////////////////////////////////////////////////////
-// Copyright (C) 1993 - 2003 California Institute of Technology             //
-//                                                                          //
-// Read the COPYING and README files, or contact 'avida at alife.org',         //
-// before continuing.  SOME RESTRICTIONS MAY APPLY TO USE OF THIS FILE.     //
-//////////////////////////////////////////////////////////////////////////////
-
-#ifndef CONFIG_HH
-#define CONFIG_HH
-
-#ifndef GENESIS_HH
-#include "genesis.hh"
-#endif
-#ifndef STRING_LIST_HH
-#include "string_list.hh"
-#endif
-#ifndef TLIST_HH
-#include "tList.hh"
-#endif
-
-#define SLICE_CONSTANT         0
-#define SLICE_PROB_MERIT       1
-#define SLICE_INTEGRATED_MERIT 2
-
-#define POSITION_CHILD_RANDOM           0
-#define POSITION_CHILD_AGE              1
-#define POSITION_CHILD_MERIT            2
-#define POSITION_CHILD_EMPTY            3
-#define NUM_LOCAL_POSITION_CHILD        4
-
-#define POSITION_CHILD_FULL_SOUP_RANDOM 4
-#define POSITION_CHILD_FULL_SOUP_ELDEST 5
-#define POSITION_CHILD_DEME_RANDOM      6
-
-#define DEATH_METHOD_OFF       0
-#define DEATH_METHOD_CONST     1
-#define DEATH_METHOD_MULTIPLE  2
-
-#define ALLOC_METHOD_DEFAULT   0
-#define ALLOC_METHOD_NECRO     1
-#define ALLOC_METHOD_RANDOM    2
-
-#define DIVIDE_METHOD_OFFSPRING 0
-#define DIVIDE_METHOD_SPLIT     1
-#define DIVIDE_METHOD_BIRTH     2
-
-#define GENERATION_INC_OFFSPRING 0
-#define GENERATION_INC_BOTH      1
-
-#define TASK_MERIT_OFF         0
-#define TASK_MERIT_EXPONENTIAL 1
-#define TASK_MERIT_LINEAR      2
-
-#define SIZE_MERIT_OFF         0
-#define SIZE_MERIT_COPIED      1
-#define SIZE_MERIT_EXECUTED    2
-#define SIZE_MERIT_FULL        3
-#define SIZE_MERIT_LEAST       4
-#define SIZE_MERIT_SQRT_LEAST  5
-
-#define GEOMETRY_GLOBAL 0
-#define GEOMETRY_GRID   1
-#define GEOMETRY_TORUS  2
-
-class cString; // aggregate
-class cStringList; // aggregate
-class cGenesis;
-template <class T> class tList; // aggregate
-template <class T> class tListIterator; // aggregate
-
-class cConfig {
-protected:
-  class cConfigEntryBase {
-  protected:
-    const cString genesis_tag;
-    const cString default_value;
-    const cStringList description;
-  public:
-    cConfigEntryBase(const cString & _tag, const cString & _def,
-		     const cString & _desc)
-      : genesis_tag(_tag), default_value(_def), description(_desc, '\n') { ; }
-    virtual ~cConfigEntryBase(){}
-
-    //    virtual ~cConfigEntryBase();
-    const cString & GetTag() { return genesis_tag; }
-    const cString & GetDefault() { return default_value; }
-    const cStringList & GetDesc() { return description; }
-
-    virtual bool LoadValue(cGenesis & genesis) = 0;
-  };
-
-  template <class T> class tConfigEntry : public cConfigEntryBase {
-  private:
-    T & variable;
-  public:
-    tConfigEntry(T & _var, const cString & _def, const cString & _tag,
-		 const cString _desc)
-      : cConfigEntryBase(_tag, _def, _desc), variable(_var)
-    { ; }
-
-    bool LoadValue(cGenesis & genesis) {
-      genesis.Read(variable, genesis_tag, default_value);
-      return true;
-    }
-  };
-
-  class cConfigGroup {
-  private:
-    const cString group_name;
-    cStringList comment;
-    tList<cConfigEntryBase> group_entries;
-  public:
-    cConfigGroup(const cString & _name) : group_name(_name) { ; }
-    ~cConfigGroup() {
-      while (group_entries.GetSize() > 0) delete group_entries.Pop();
-    }
-
-    void SetComment(const cString & _comment) { comment.Load(_comment, '\n'); }
-
-    const cString & GetName() { return group_name; }
-    const cStringList & GetComment() { return comment; }
-    tList<cConfigEntryBase> & GetEntries() { return group_entries; }
-
-    void LoadValues(cGenesis & genesis) {
-      tListIterator<cConfigEntryBase> group_it(group_entries);
-      cConfigEntryBase * cur_entry;
-      while ((cur_entry = group_it.Next()) != NULL) {
-	cur_entry->LoadValue(genesis);
-      }
-    };
-
-    void Add(int & _var, const cString &  _def, const cString & _tag,
-	     const cString & _desc)
-    {
-      group_entries.
-	PushRear(new cConfig::tConfigEntry<int>(_var,_def,_tag,_desc));
-    }
-
-    void Add(double & _var, const cString & _def, const cString & _tag,
-	     const cString & _desc)
-    {
-      group_entries.
-	PushRear(new cConfig::tConfigEntry<double>(_var,_def,_tag,_desc));
-    }
-
-    void Add(cString & _var, const cString & _def, const cString & _tag,
-	     const cString & _desc)
-    {
-      group_entries.
-	PushRear(new cConfig::tConfigEntry<cString>(_var,_def,_tag,_desc));
-    }
-
-    void Add(bool & _var, const cString & _def, const cString & _tag,
-	     const cString & _desc)
-    {
-      group_entries.
-	PushRear(new cConfig::tConfigEntry<bool>(_var,_def,_tag,_desc));
-    }
-  };
-
-  // Collection of genesis groups...
-  static tList<cConfigGroup> group_list;
-
-  // Major Configurations
-  static bool analyze_mode;     // Should avida do only analysis work?
-  static bool primitive_mode;   // Should avida run in primitive mode?
-  static bool interactive_analyze; // Should analyze mode be interactive?
-
-  // Config Filenames
-  static cString default_dir;
-  static cString genesis_filename;
-  static cString inst_filename;
-  static cString event_filename;
-  static cString analyze_filename;
-  static cString env_filename;
-
-  static cString start_creature;
-  static cString clone_filename;
-  static cString load_pop_filename;
-
-  // Archetecture
-  static int max_updates;
-  static int max_generations;
-  static int end_condition_mode;
-  static int world_x;
-  static int world_y;
-  static int world_geometry;
-  static int num_demes;
-  static int rand_seed;
-
-  // Mutations
-  static double point_mut_prob;
-  static double copy_mut_prob;
-  static double ins_mut_prob;
-  static double del_mut_prob;
-  static double div_mut_prob;
-  static double divide_mut_prob;
-  static double divide_ins_prob;
-  static double divide_del_prob;
-  static double parent_mut_prob;
-  static int special_mut_line;
-
-  // CPU Configutation
-  static int num_instructions;
-  static int hardware_type;
-  static int max_cpu_threads;
-  static double thread_slicing_method;
-
-  // Merit info
-  static int size_merit_method;
-  static int base_size_merit;
-  static double default_bonus;
-  static int ave_time_slice;
-
-  // Task info
-  static int num_tasks;
-  static int num_reactions;
-  static int num_resources;
-
-  // Task Merit Method
-  static int task_merit_method;
-  static int merit_time;
-
-  // Transfering merits...
-  static double merit_given;
-  static double merit_received;
-  static int max_donate_kin_distance;
-  static int max_donate_edit_distance;
-  static int max_donates;
-
-  // Methodology
-  static int slicing_method;
-  static int birth_method;
-  static int prefer_empty;
-  static int death_method;
-  static int alloc_method;
-  static int divide_method;
-  static double recomb_prob;
-  static int num_modules;
-  static int cont_rec_regs;
-  static int corespond_rec_regs;
-  static int two_fold_cost_sex;
-  static int same_length_sex;
-  static int required_task;
-  static int immunity_task;
-  static int required_reaction;
-  static int lineage_creation_method;
-  static int generation_inc_method;
-  static int age_limit;
-  static double age_deviation;
-  static double child_size_range;
-  static double min_copied_lines;
-  static double min_exe_lines;
-  static int require_allocate;
-  static int max_label_exe_size;
-
-  // For specialized experiments -- mutation reversion.
-  static bool test_on_divide;
-  static bool test_sterilize;
-  static double revert_fatal;
-  static double revert_neg;
-  static double revert_neut;
-  static double revert_pos;
-  static double sterilize_fatal;
-  static double sterilize_neg;
-  static double sterilize_neut;
-  static double sterilize_pos;
-  static int fail_implicit;
-
-  // Genealogy & Recording
-  static int species_threshold;
-  static int threshold;
-  static int genotype_print;
-  static int species_print;
-  static int species_recording;
-  static int genotype_print_dom;
-  static int test_cpu_time_mod;
-  static int track_main_lineage;
-
-  // Log files...
-  static bool log_threshold_only;
-
-  static bool log_creatures;
-  static int log_genotypes;
-  static bool log_threshold;
-  static bool log_species;
-  static bool log_landscape;
-  static bool log_mutations;
-  static bool log_lineages;
-
-  // Debugging
-  static int debug_level;
-
-  // Viewer
-  static int view_mode;
-
-  // Death
-  static double die_prob; 
-
-  // Other functions...
-  static void ProcessConfiguration(int argc, char* argv[], cGenesis & genesis);
-public:
-  static void InitGroupList();
-  static void Setup(cGenesis & genesis);
-  static void Setup(int argc, char * argv[]);
-  static void SetupMS();
-  static void PrintGenesis(const cString & filename);
-
-  // ``Get''
-  static bool GetAnalyzeMode() { return analyze_mode; }
-  static bool GetPrimitiveMode() { return primitive_mode; }
-  static bool GetInteractiveAnalyze() { return interactive_analyze; }
-
-  /*
-  addition to permit access to cConfig::default_dir for use in locating
-  preset_organisms subdirectory (accessed in godbox widget).
-  -- kaben.
-  */
-  static cString & GetDefaultDir() { return default_dir; }
-  /* -- kaben. */
-
-  static cString & GetGenesisFilename() { return genesis_filename; }
-  static cString & GetInstFilename()  { return inst_filename; }
-  static cString & GetEventFilename() { return event_filename; }
-  static cString & GetAnalyzeFilename() { return analyze_filename; }
-  static cString & GetEnvironmentFilename() { return env_filename; }
-
-  static cString & GetStartCreature() { return start_creature; }
-  static cString & GetCloneFilename() { return clone_filename; }
-  static cString & GetLoadPopFilename() { return load_pop_filename; }
-
-  static int GetMaxUpdates()     { return max_updates; }
-  static int GetMaxGenerations() { return max_generations; }
-  static int GetEndConditionMode() { return end_condition_mode; }
-  static int GetWorldX()         { return world_x; }
-  static int GetWorldY()         { return world_y; }
-  static int GetWorldGeometry()  { return world_geometry; }
-  static int GetNumDemes()       { return num_demes; }
-  static int GetRandSeed()       { return rand_seed; }
-
-  static double GetPointMutProb()  { return point_mut_prob; }
-  static double GetCopyMutProb()   { return copy_mut_prob; }
-  static double GetInsMutProb()    { return ins_mut_prob; }
-  static double GetDelMutProb()    { return del_mut_prob; }
-  static double GetDivMutProb()    { return div_mut_prob; }
-  static double GetDivideMutProb() { return divide_mut_prob; }
-  static double GetDivideInsProb() { return divide_ins_prob; }
-  static double GetDivideDelProb() { return divide_del_prob; }
-  static double GetParentMutProb() { return parent_mut_prob; }
-  static int GetSpecialMutLine() { return special_mut_line; }
-
-  static int GetNumInstructions() { return num_instructions; }
-  static int GetHardwareType() { return hardware_type; }
-  static int GetMaxCPUThreads() { return max_cpu_threads; }
-  static double GetThreadSlicingMethod() { return thread_slicing_method; }
-
-  static int GetSizeMeritMethod() { return size_merit_method; }
-  static int GetBaseSizeMerit()  { return base_size_merit; }
-  static double GetDefaultBonus() { return default_bonus; }
-  static int GetTaskMeritMethod() { return task_merit_method; }
-  static int GetMaxLabelExeSize() { return max_label_exe_size; }
-
-  static int GetMeritTime() { return merit_time; }
-
-  static double GetMeritGiven() { return merit_given; }
-  static double GetMeritReceived() { return merit_received; }
-  static int GetMaxDonateKinDistance() { return max_donate_kin_distance; }
-  static int GetMaxDonateEditDistance() { return max_donate_edit_distance; }
-  static int GetMaxDonates() { return max_donates; }
-
-  static int GetNumTasks() { return num_tasks; }
-  static int GetNumReactions() { return num_reactions; }
-  static int GetNumResources() { return num_resources; }
-
-  static int GetSlicingMethod() { return slicing_method; }
-  static int GetBirthMethod() { return birth_method; }
-  static int GetPreferEmpty() { return prefer_empty; }
-  static int GetDeathMethod() { return death_method; }
-  static int GetAllocMethod() { return alloc_method; }
-  static int GetDivideMethod() { return divide_method; }
-  static double GetRecombProb() { return recomb_prob; }
-  static int GetNumModules() { return num_modules; }
-  static int GetContRecRegs() { return cont_rec_regs; }
-  static int GetCorespondRecRegs() { return corespond_rec_regs; }
-  static int GetTwoFoldCostSex() { return two_fold_cost_sex; }
-  static int GetSameLengthSex() { return same_length_sex; }
-  static int GetRequiredTask() { return required_task; }
-  static int GetImmunityTask() { return immunity_task; }
-  static int GetRequiredReaction() { return required_reaction; }
-  static int GetLineageCreationMethod() { return lineage_creation_method; }
-  static int GetGenerationIncMethod() { return generation_inc_method; }
-  static int GetAgeLimit() { return age_limit; }
-  static double GetAgeDeviation() { return age_deviation; }
-  static double GetChildSizeRange() { return child_size_range; }
-  static double GetMinCopiedLines() { return min_copied_lines; }
-  static double GetMinExeLines() { return min_exe_lines; }
-  static int GetRequireAllocate() { return require_allocate; }
-
-  static bool GetTestOnDivide() { return test_on_divide; }
-  static bool GetTestSterilize() { return test_sterilize; }
-  static double GetRevertFatal() { return revert_fatal; }
-  static double GetRevertNeg() { return revert_neg; }
-  static double GetRevertNeut() { return revert_neut; }
-  static double GetRevertPos() { return revert_pos; }
-  static double GetSterilizeFatal() { return sterilize_fatal; }
-  static double GetSterilizeNeg() { return sterilize_neg; }
-  static double GetSterilizeNeut() { return sterilize_neut; }
-  static double GetSterilizePos() { return sterilize_pos; }
-  static int GetFailImplicit() { return fail_implicit; }
-
-
-  static int GetAveTimeslice() { return ave_time_slice; }
-  static int GetSpeciesThreshold() { return species_threshold; }
-  static int GetThreshold() { return threshold; }
-  static int GetGenotypePrint() { return genotype_print; }
-  static int GetSpeciesPrint() { return species_print; }
-  static int GetSpeciesRecording() { return species_recording; }
-  static int GetGenotypePrintDom() { return genotype_print_dom; }
-  static int GetTestCPUTimeMod() { return test_cpu_time_mod; }
-  static int GetTrackMainLineage() { return track_main_lineage; }
-
-
-  static bool GetLogThresholdOnly()  { return log_threshold_only; }
-
-  static bool GetLogCreatures() { return log_creatures; }
-  static int GetLogGenotypes() { return log_genotypes; }
-  static bool GetLogThreshold() { return log_threshold; }
-  static bool GetLogSpecies()   { return log_species; }
-  static bool GetLogLandscape() { return log_landscape; }
-  static bool GetLogLineages()  { return log_lineages; }
-
-  static int GetDebugLevel() { return debug_level; }
-
-  static int GetViewMode() { return view_mode; }
-
-  static double GetDieProb() { return die_prob; }
-
-
-  // ``Set''
-  static void SetInstFilename(const cString & in_name)
-    { inst_filename = in_name; }
-  static void SetEventFilename(const cString & in_name)
-    { event_filename = in_name; }
-  static void SetAnalyzeFilename(const cString & in_name)
-    { analyze_filename = in_name; }
-  static void SetEnvironmentFilename(const cString & in_name)
-    { env_filename = in_name; }
-
-  static void SetMaxUpdates(int in_max_updates)
-    { max_updates = in_max_updates; }
-  static void SetMaxGenerations(int _in)
-    { max_generations = _in; }
-  static void SetEndConditionMode(int _in)
-    { end_condition_mode = _in; }
-
-  static void SetCopyMutProb(double _in)  { copy_mut_prob = _in; }
-  static void SetDivMutProb(double _in)  { div_mut_prob = _in; }
-  static void SetPointMutProb(double _in) { point_mut_prob = _in; }
-
-  /*
-  addition to permit tweaking of ins_mut_prob, del_mut_prob from godbox
-  widget.
-  -- kaben.
-  */
-  static void SetInsMutProb(double _in)  { ins_mut_prob = _in; }
-  static void SetDelMutProb(double _in) { del_mut_prob = _in; }
-  /* -- kaben. */
-
-  static void SetNumInstructions(int in_num_instructions)
-    { num_instructions = in_num_instructions; }
-  static void SetHardwareType(int in_htype) { hardware_type = in_htype; }
-  static void SetMaxCPUThreads(int in_threads)
-    { max_cpu_threads = in_threads; }
-
-  static void SetSizeMeritMethod(int in_merit_method)
-    { size_merit_method = in_merit_method; }
-  static void SetBaseSizeMerit(int in_base_size_merit)
-    { base_size_merit = in_base_size_merit; }
-  static void SetDefaultBonus(int in_default_bonus)
-    { default_bonus = in_default_bonus; }
-
-  static void SetBirthMethod(int in_birth_method)
-    { birth_method = in_birth_method; }
-  static void SetPreferEmpty(int in_prefer_empty)
-    { prefer_empty = in_prefer_empty; }
-  static void SetDeathMethod(int in_death_method)
-    { death_method = in_death_method; }
-  static void SetAllocMethod(int in_alloc_method)
-    { alloc_method = in_alloc_method; }
-  static void SetDivideMethod(int in_divide_method)
-    { divide_method = in_divide_method; }
-  static void SetLineageCreationMethod( int in_lineage_creation_method )
-    { lineage_creation_method = in_lineage_creation_method; }
-  static void SetGenerationIncMethod(int in_generation_inc_method)
-    { generation_inc_method = in_generation_inc_method; }
-  static void SetAgeLimit(int in_age_limit) { age_limit = in_age_limit; }
-  static void SetAgeDeviation(double in_dev) { age_deviation = in_dev; }
-
-  static void SetAveTimeslice(int in_slice) { ave_time_slice = in_slice; }
-
-  static void SetNumTasks(int in_num) { num_tasks = in_num; }
-  static void SetNumReactions(int in_num) { num_reactions = in_num; }
-  static void SetNumResources(int in_num) { num_resources = in_num; }
-};
-
-#endif

Deleted: trunk/source/main/environment.cc
===================================================================
--- trunk/source/main/environment.cc	2005-09-15 23:16:19 UTC (rev 313)
+++ trunk/source/main/environment.cc	2005-09-16 02:10:20 UTC (rev 314)
@@ -1,946 +0,0 @@
-//////////////////////////////////////////////////////////////////////////////
-// Copyright (C) 1993 - 2003 California Institute of Technology             //
-//                                                                          //
-// Read the COPYING and README files, or contact 'avida at alife.org',         //
-// before continuing.  SOME RESTRICTIONS MAY APPLY TO USE OF THIS FILE.     //
-//////////////////////////////////////////////////////////////////////////////
-
-#ifndef ENVIRONMENT_HH
-#include "environment.hh"
-#endif
-
-#ifndef INIT_FILE_HH
-#include "init_file.hh"
-#endif
-#ifndef MUTATION_MACROS_HH
-#include "mutation_macros.hh"
-#endif
-#ifndef RANDOM_HH
-#include "random.hh"
-#endif
-#ifndef REACTION_HH
-#include "reaction.hh"
-#endif
-#ifndef REACTION_MACROS_HH
-#include "reaction_macros.hh"
-#endif
-#ifndef REACTION_PROCESS_HH
-#include "reaction_process.hh"
-#endif
-#ifndef REACTION_REQUISITE_HH
-#include "reaction_requisite.hh"
-#endif
-#ifndef REACTION_RESULT_HH
-#include "reaction_result.hh"
-#endif
-#ifndef RESOURCE_HH
-#include "resource.hh"
-#endif
-#ifndef STRING_UTIL_HH
-#include "string_util.hh"
-#endif
-#ifndef TASK_ENTRY_HH
-#include "task_entry.hh"
-#endif
-#ifndef TOOLS_HH
-#include "tools.hh"
-#endif
-
-using namespace std;
-
-cEnvironment::cEnvironment()
-{
-}
-
-// cEnvironment::cEnvironment(const cString & filename)
-// {
-//   if (Load(filename) == false) {
-//     cerr << "Unable to load environment... aborting!" << endl;
-//     abort();
-//   }
-// }
-
-bool cEnvironment::ParseSetting(cString entry, cString & var_name,
-				cString & var_value, const cString & var_type)
-{
-  // Make sure we have an actual entry to parse.
-  if (entry.GetSize() == 0) {
-    cerr << "Error: Empty setting to parse in " << var_type << endl;
-    return false;
-  }
-
-  // Collect the values...
-  var_name = entry.Pop('=');
-  var_value = entry;
-
-  // Make sure we have both a name and a value...
-  if (var_name.GetSize() == 0) {
-    cerr << "Error: No variable povided to set to '" << var_value
-	 << "' in " << var_type << endl;
-    return false;
-  }
-
-  if (var_value.GetSize() == 0) {
-    cerr << "Error: No value given for '" << var_name
-	 << "' in " << var_type << endl;
-    return false;
-  }
-
-  // Make the names case insensitive.
-  var_name.ToLower();
-
-  return true;
-}
-
-bool cEnvironment::AssertInputInt(const cString & input,
-				  const cString & name,
-				  const cString & type)
-{
-  if (input.IsNumeric() == false) {
-    cerr << "Error: In " << type << "," << name << " set to non-integer."
-	 << endl;
-    return false;
-  }
-  return true;
-}
-
-bool cEnvironment::AssertInputDouble(const cString & input,
-				     const cString & name,
-				     const cString & type)
-{
-  if (input.IsNumber() == false) {
-    cerr << "Error: In " << type << "," << name << " set to non-number."
-	 << endl;
-    return false;
-  }
-  return true;
-}
-
-bool cEnvironment::AssertInputBool(const cString & input,
-				  const cString & name,
-				  const cString & type)
-{
-  if (input.IsNumber() == false) {
-    cerr << "Error: In " << type << "," << name << " set to non-number."
-	 << endl;
-    return false;
-  }
-  int value = input.AsInt();
-  if ((value != 1) && (value != 0))  {
-    cerr << "Error: In " << type << "," << name << " set to non-bool."
-	 << endl;
-    return false;
-  }
-  return true;
-}
-
-bool cEnvironment::AssertInputValid(void * input,
-				    const cString & name,
-				    const cString & type,
-				    const cString & value)
-{
-  if (input == NULL) {
-    cerr << "Error: In " << type << ", '" << name << "' setting of '"
-	 << value << "' not found." << endl;
-    return false;
-  }
-  return true;
-}
-
-
-
-bool cEnvironment::LoadReactionProcess(cReaction * reaction, cString desc)
-{
-  cReactionProcess * new_process = reaction->AddProcess();
-
-  // Loop through all entries in description.
-  while (desc.GetSize() > 0) {
-    // Entries are divided by colons.
-    cString var_entry = desc.Pop(':');
-    cString var_name;
-    cString var_value;
-    const cString var_type =
-      cStringUtil::Stringf("reaction '%s' process", reaction->GetName()());
-
-    // Parse this entry.
-    if (!ParseSetting(var_entry, var_name, var_value, var_type)) return false;
-
-    // Now that we know we have a variable name and its value, set it!
-    if (var_name == "resource") {
-      cResource * test_resource = resource_lib.GetResource(var_value);
-      if (!AssertInputValid(test_resource, "resource", var_type, var_value)) {
-	return false;
-      }
-      new_process->SetResource(test_resource);
-    }
-    else if (var_name == "value") {
-      if (!AssertInputDouble(var_value, "value", var_type)) return false;
-      new_process->SetValue(var_value.AsDouble());
-    }
-    else if (var_name == "type") {
-      if (var_value=="add") new_process->SetType(REACTION_PROCTYPE_ADD);
-      else if (var_value=="mult") new_process->SetType(REACTION_PROCTYPE_MULT);
-      else if (var_value=="pow") new_process->SetType(REACTION_PROCTYPE_POW);
-      else {
-	cerr << "Unknown reaction process type '" << var_value
-	     << "' found in '" << reaction->GetName() << "'." << endl;
-	return false;
-      }
-    }
-    else if (var_name == "max") {
-      if (!AssertInputDouble(var_value, "max", var_type)) return false;
-      new_process->SetMaxNumber(var_value.AsDouble());
-    }
-    else if (var_name == "min") {
-      if (!AssertInputDouble(var_value, "min", var_type)) return false;
-      new_process->SetMinNumber(var_value.AsDouble());
-    }
-    else if (var_name == "frac") {
-      if (!AssertInputDouble(var_value, "frac", var_type)) return false;
-      double in_frac = var_value.AsDouble();
-      if (in_frac > 1.0) in_frac = 1.0;
-      new_process->SetMaxFraction(in_frac);
-    }
-    else if (var_name == "product") {
-      cResource * test_resource = resource_lib.GetResource(var_value);
-      if (!AssertInputValid(test_resource, "product", var_type, var_value)) {
-	return false;
-      }
-      new_process->SetProduct(test_resource);
-    }
-    else if (var_name == "conversion") {
-      if (!AssertInputDouble(var_value, "conversion", var_type)) return false;
-      new_process->SetConversion(var_value.AsDouble());
-    }
-    else if (var_name == "inst") {
-      new_process->SetInstID( inst_set.GetInst(var_value).GetOp() );
-    }
-    else if (var_name == "lethal") {
-      if (!AssertInputBool(var_value, "lethal", var_type)) 
-	return false;
-      new_process->SetLethal(var_value.AsInt());
-    }
-    else if (var_name == "detect") {
-      cResource * test_resource = resource_lib.GetResource(var_value);
-      if (!AssertInputValid(test_resource, "product", var_type, var_value)) {
-	return false;
-      }
-      new_process->SetDetect(test_resource);
-    }
-    else if (var_name == "threshold") {
-      if (!AssertInputDouble(var_value, "threshold", var_type))
-	return false;
-      new_process->SetDetectionThreshold(var_value.AsDouble());
-    }
-    else if (var_name == "detectionerror") {
-      if (!AssertInputDouble(var_value, "detectionerror", var_type)) 
-	return false;
-      new_process->SetDetectionError(var_value.AsDouble());
-    }
-    else {
-      cerr << "Error: Unknown process variable '" << var_name
-	   << "' in reaction '" << reaction->GetName() << "'" << endl;
-      return false;
-    }
-  }
-
-  return true;
-}
-
-bool cEnvironment::LoadReactionRequisite(cReaction * reaction, cString desc)
-{
-  cReactionRequisite * new_requisite = reaction->AddRequisite();
-
-  // Loop through all entries in description.
-  while (desc.GetSize() > 0) {
-    // Entries are divided by colons.
-    cString var_entry = desc.Pop(':');
-    cString var_name;
-    cString var_value;
-    const cString var_type =
-      cStringUtil::Stringf("reaction '%s' requisite", reaction->GetName()());
-
-    // Parse this entry.
-    if (!ParseSetting(var_entry, var_name, var_value, var_type)) return false;
-
-    // Now that we know we have a variable name and its value, set it!
-    if (var_name == "reaction") {
-      cReaction * test_reaction = reaction_lib.GetReaction(var_value);
-      if (!AssertInputValid(test_reaction, "reaction", var_type, var_value)) {
-	return false;
-      }
-      new_requisite->AddReaction(test_reaction);
-    }
-    else if (var_name == "noreaction") {
-      cReaction * test_reaction = reaction_lib.GetReaction(var_value);
-      if (!AssertInputValid(test_reaction,"noreaction",var_type, var_value)) {
-	return false;
-      }
-      new_requisite->AddNoReaction(test_reaction);
-    }
-    else if (var_name == "min_count") {
-      if (!AssertInputInt(var_value, "min_count", var_type)) return false;
-      new_requisite->SetMinTaskCount(var_value.AsInt());
-    }
-    else if (var_name == "max_count") {
-      if (!AssertInputInt(var_value, "max_count", var_type)) return false;
-      new_requisite->SetMaxTaskCount(var_value.AsInt());
-    }
-    else {
-      cerr << "Error: Unknown requisite variable '" << var_name
-	   << "' in reaction '" << reaction->GetName() << "'" << endl;
-      return false;
-    }
-  }
-
-  return true;
-}
-
-
-bool cEnvironment::LoadResource(cString desc)
-{
-  if (desc.GetSize() == 0) {
-    cerr << "Warning: Resource line with no resources listed." << endl;
-    return false;
-  }
-
-  while (desc.GetSize() > 0) {
-    cString cur_resource = desc.PopWord();
-    const cString name = cur_resource.Pop(':');
-    cResource * new_resource = resource_lib.AddResource(name);
-
-    while (cur_resource.GetSize() != 0) {
-      cString var_entry = cur_resource.Pop(':');
-      cString var_name;
-      cString var_value;
-      const cString var_type = cStringUtil::Stringf("resource '%s'", name());
-
-      // Parse this entry.
-      if (!ParseSetting(var_entry, var_name, var_value, var_type)) {
-	return false;
-      }
-
-      if (var_name == "inflow") {
-	if (!AssertInputDouble(var_value, "inflow", var_type)) return false;
-	new_resource->SetInflow( var_value.AsDouble() );
-      }
-      else if (var_name == "outflow") {
-	if (!AssertInputDouble(var_value, "outflow", var_type)) return false;
-	new_resource->SetOutflow( var_value.AsDouble() );
-      }
-      else if (var_name == "initial") {
-	if (!AssertInputDouble(var_value, "initial", var_type)) return false;
-	new_resource->SetInitial( var_value.AsDouble() );
-      }
-      else if (var_name == "geometry") {
-	if (!new_resource->SetGeometry( var_value )) {
-          cerr << "Error: In " << var_type << "," << var_value << 
-	          " unknown geometry" << endl;
-          return false;
-        }
-      }
-      else if (var_name == "inflowx1" || var_name == "inflowx") {
-	if (!AssertInputInt(var_value, "inflowX1", var_type)) return false;
-	new_resource->SetInflowX1( var_value.AsInt() );
-      }
-      else if (var_name == "inflowx2") {
-	if (!AssertInputInt(var_value, "inflowX2", var_type)) return false;
-	new_resource->SetInflowX2( var_value.AsInt() );
-      }
-      else if (var_name == "inflowy1" || var_name == "inflowy") {
-	if (!AssertInputInt(var_value, "inflowY1", var_type)) return false;
-	new_resource->SetInflowY1( var_value.AsInt() );
-      }
-      else if (var_name == "inflowy2") {
-	if (!AssertInputInt(var_value, "inflowY2", var_type)) return false;
-	new_resource->SetInflowY2( var_value.AsInt() );
-      }
-      else if (var_name == "outflowx1" || var_name == "outflowx") {
-	if (!AssertInputInt(var_value, "outflowX1", var_type)) return false;
-	new_resource->SetOutflowX1( var_value.AsInt() );
-      }
-      else if (var_name == "outflowx2") {
-	if (!AssertInputInt(var_value, "outflowX2", var_type)) return false;
-	new_resource->SetOutflowX2( var_value.AsInt() );
-      }
-      else if (var_name == "outflowy1" || var_name == "outflowy") {
-	if (!AssertInputInt(var_value, "outflowY1", var_type)) return false;
-	new_resource->SetOutflowY1( var_value.AsInt() );
-      }
-      else if (var_name == "outflowy2") {
-	if (!AssertInputInt(var_value, "outflowY2", var_type)) return false;
-	new_resource->SetOutflowY2( var_value.AsInt() );
-      }
-      else if (var_name == "xdiffuse") {
-	if (!AssertInputDouble(var_value, "xdiffuse", var_type)) return false;
-	new_resource->SetXDiffuse( var_value.AsDouble() );
-      }
-      else if (var_name == "xgravity") {
-	if (!AssertInputDouble(var_value, "xgravity", var_type)) return false;
-	new_resource->SetXGravity( var_value.AsDouble() );
-      }
-      else if (var_name == "ydiffuse") {
-	if (!AssertInputDouble(var_value, "ydiffuse", var_type)) return false;
-	new_resource->SetYDiffuse( var_value.AsDouble() );
-      }
-      else if (var_name == "ygravity") {
-	if (!AssertInputDouble(var_value, "ygravity", var_type)) return false;
-	new_resource->SetYGravity( var_value.AsDouble() );
-      }
-      else {
-	cerr << "Error: Unknown variable '" << var_name
-	     << "' in resource '" << name << "'" << endl;
-	return false;
-      }
-    }
-
-    // If there are valid values for X/Y1's but not for X/Y2's assume that 
-    // the user is interested only in one point and set the X/Y2's to the
-    // same value as 
-
-    if (new_resource->GetInflowX1()>-99 && new_resource->GetInflowX2()==-99){
-         new_resource->SetInflowX2(new_resource->GetInflowX1());
-    }
-    if (new_resource->GetInflowY1()>-99 && new_resource->GetInflowY2()==-99){
-         new_resource->SetInflowY2(new_resource->GetInflowY1());
-    }
-    if (new_resource->GetOutflowX1()>-99 && new_resource->GetOutflowX2()==-99) {
-         new_resource->SetOutflowX2(new_resource->GetOutflowX1());
-    }
-    if (new_resource->GetOutflowY1()>-99 && new_resource->GetOutflowY2()==-99) {
-         new_resource->SetOutflowY2(new_resource->GetOutflowY1());
-    }
-  }
-
-  return true;
-}
-
-bool cEnvironment::LoadReaction(cString desc)
-{
-  // Make sure this reaction has a description...
-  if (desc.GetSize() == 0) {
-    cerr << "Error: Each reaction must include a name and trigger." << endl;
-    return false;
-  }
-
-  // Load in the reaction name
-  const cString name = desc.PopWord();
-  cReaction * new_reaction = reaction_lib.AddReaction(name);
-
-  // If only a name was present, assume this reaction is a pre-declaration.
-  if (desc.GetSize() == 0) {
-    return true;
-  }
-
-  // Make sure this reaction hasn't already been loaded with a different
-  // definition.
-  if (new_reaction->GetTask() != NULL) {
-    cerr << "Error: Re-defining reaction '" << name << "'." << endl;
-    return false;
-  }
-
-  // Finish loading in this reaction.
-  const cString trigger = desc.PopWord();
-
-  // Load the task trigger
-  cTaskEntry * cur_task = task_lib.AddTask(trigger);
-  if (cur_task == NULL) {
-    cerr << "...failed to find task in cTaskLib..." << endl;
-    return false;
-  }
-  new_reaction->SetTask(cur_task);      // Attack task to reaction.
-
-  while (desc.GetSize()) {
-    cString desc_entry = desc.PopWord();      // Get the next argument
-    cString entry_type = desc_entry.Pop(':'); // Determine argument type
-    entry_type.ToLower();                     // Make case insensitive.
-
-    // Determine the type of each argument and process it.
-    if (entry_type == "process") {
-      if (LoadReactionProcess(new_reaction, desc_entry) == false) {
-	cerr << "...failed in loading reaction-process..." << endl;
-	return false;
-      }
-    }
-    else if (entry_type == "requisite") {
-      if (LoadReactionRequisite(new_reaction, desc_entry) == false) {
-	cerr << "...failed in loading reaction-requisite..." << endl;
-	return false;
-      }
-    }
-    else {
-      cerr << "Unknown entry type '" << entry_type
-  	   << "' in reaction '" << name << "'"
-  	   << endl;
-      return false;
-    }
-  }
-
-  return true;
-}
-
-bool cEnvironment::LoadMutation(cString desc)
-{
-  // Make sure this mutation has a description...
-  if (desc.CountNumWords() < 5) {
-    cerr << "Error: Each mutation must include a name, trigger, scope, type, and rate." << endl;
-    return false;
-  }
-
-  // Load in the mutation info
-  const cString name = desc.PopWord().ToLower();
-  const cString trigger = desc.PopWord().ToLower();
-  const cString scope = desc.PopWord().ToLower();
-  const cString type = desc.PopWord().ToLower();
-  const double rate = desc.PopWord().AsDouble();
-
-  int trig_id = -1;
-  int scope_id = -1;
-  int type_id = -1;
-
-  if (trigger == "none") trig_id = MUTATION_TRIGGER_NONE;
-  else if (trigger == "update") trig_id = MUTATION_TRIGGER_UPDATE;
-  else if (trigger == "divide") trig_id = MUTATION_TRIGGER_DIVIDE;
-  else if (trigger == "parent") trig_id = MUTATION_TRIGGER_PARENT;
-  else if (trigger == "write") trig_id = MUTATION_TRIGGER_WRITE;
-  else if (trigger == "read") trig_id = MUTATION_TRIGGER_READ;
-  else if (trigger == "exec") trig_id = MUTATION_TRIGGER_EXEC;
-  else {
-    cerr << "Error: Unknown mutation trigger '" << trigger << "'." << endl;
-    return false;
-  }
-
-  if (scope == "genome") scope_id = MUTATION_SCOPE_GENOME;
-  else if (scope == "local") scope_id = MUTATION_SCOPE_LOCAL;
-  else if (scope == "prop") scope_id = MUTATION_SCOPE_PROP;
-  else if (scope == "global") scope_id = MUTATION_SCOPE_GLOBAL;
-  else if (scope == "spread") scope_id = MUTATION_SCOPE_SPREAD;
-  else {
-    cerr << "Error: Unknown mutation scope '" << scope << "'." << endl;
-    return false;
-  }
-
-  if (type == "point") type_id = MUTATION_TYPE_POINT;
-  else if (type == "insert") type_id = MUTATION_TYPE_INSERT;
-  else if (type == "delete") type_id = MUTATION_TYPE_DELETE;
-  else if (type == "head_inc") type_id = MUTATION_TYPE_HEAD_INC;
-  else if (type == "head_dec") type_id = MUTATION_TYPE_HEAD_DEC;
-  else if (type == "temp") type_id = MUTATION_TYPE_TEMP;
-  else if (type == "kill") type_id = MUTATION_TYPE_KILL;
-  else {
-    cerr << "Error: Unknown mutation type '" << type << "'." << endl;
-    return false;
-  }
-
-  // Lets do a few checks for legal combinations...
-  if (trig_id == MUTATION_TRIGGER_NONE) {
-    cerr << "Warning: Mutations with trigger 'none' will never occur." << endl;
-  }
-
-  if (scope_id == MUTATION_SCOPE_LOCAL || scope_id == MUTATION_SCOPE_PROP) {
-    if (trig_id == MUTATION_TRIGGER_DIVIDE) {
-      cerr << "Error: Offspring after divide have no " << scope
-	   << " for mutations." << endl;
-      return false;
-    }
-    if (trig_id == MUTATION_TRIGGER_UPDATE ||
-	trig_id == MUTATION_TRIGGER_PARENT) {
-      cerr << "Warning: Mutation trigger " << trigger
-	   << "has no natural positions; IP used." << endl;
-    }
-  }
-  else {  // Genome-wide scope
-    if (type_id == MUTATION_TYPE_HEAD_INC ||
-	type_id == MUTATION_TYPE_HEAD_DEC ||
-	type_id == MUTATION_TYPE_TEMP) {
-      cerr << "Error: " << scope << " scope not compatible with type "
-	   << type << "." << endl;
-      return false;
-    }
-  }
-
-  if (type_id == MUTATION_TYPE_TEMP) {
-    if (trig_id == MUTATION_TRIGGER_UPDATE ||
-	trig_id == MUTATION_TRIGGER_DIVIDE ||
-	trig_id == MUTATION_TRIGGER_PARENT ||
-	trig_id == MUTATION_TRIGGER_WRITE) {
-      cerr << "Error: " << trigger << " trigger not meaningful with type "
-	   << type << "." << endl;
-      return false;
-    }
-  }
-
-  // If we made it this far, it should be safe to build the mutation.
-  mutation_lib.AddMutation(name, trig_id, scope_id, type_id, rate);
-
-  return true;
-}
-
-bool cEnvironment::LoadSetActive(cString desc)
-{
-  cString item_type = desc.PopWord(); 
-  item_type.ToUpper();
-
-  cString item_name = desc.PopWord();
-
-  cString item_active = desc.PopWord();
-  item_active.ToUpper();
-
-  bool new_active = true;
-  if (item_active == "0" || item_active == "FALSE") new_active = false;
-
-  if (item_type == "REACTION") {
-    cReaction * cur_reaction = reaction_lib.GetReaction(item_name);
-    if (cur_reaction == NULL) {
-      cerr << "Unknown REACTION: '" << item_name << "'" << endl;
-      return false;
-    }
-    cur_reaction->SetActive(new_active);
-  } else if (item_type == "") {
-    cerr << "Format: SET_ACTIVE <type> <name> <new_status=true>" << endl;
-  } else {
-    cerr << "Error: Cannot deactivate items of type "
-	 << item_type << endl;
-    return false;
-  }
-
-  return true;
-}
-
-bool cEnvironment::LoadLine(cString line) 
-{
-  cString type = line.PopWord();      // Determine type of this entry.
-  type.ToUpper();                     // Make type case insensitive.
-
-  bool load_ok = true;
-  if (type == "RESOURCE") load_ok = LoadResource(line);
-  else if (type == "REACTION") load_ok = LoadReaction(line);
-  else if (type == "MUTATION") load_ok = LoadMutation(line);
-  else if (type == "SET_ACTIVE") load_ok = LoadSetActive(line);
-  else {
-    cerr << "Error: Unknown environment keyword '" << type << "." << endl;
-    return false;
-  }
-  
-  if (load_ok == false) {
-    cerr << "...failed in loading '" << type << "'..." << endl;
-    return false;
-  }
-
-  return true;
-}
-
-bool cEnvironment::Load(const cString & filename)
-{
-  cInitFile infile(filename);
-  if (infile.Good() == false) {
-    cerr << "Error: Failed to load environment '" << filename << "'." << endl;
-    return false;
-  }
-
-  infile.Load();
-  infile.Close();
-  infile.Compress();
-
-  for (int line_id = 0; line_id < infile.GetNumLines(); line_id++) {
-    // Load the next line from the file.
-    bool load_ok = LoadLine(infile.GetLine(line_id));
-    if (load_ok == false) return false;
-  }
-
-  // Make sure that all pre-declared reactions have been loaded correctly.
-  for (int i = 0; i < reaction_lib.GetSize(); i++) {
-    if (reaction_lib.GetReaction(i)->GetTask() == NULL) {
-      cerr << "Error: Pre-declared reaction '"
-	   << reaction_lib.GetReaction(i)->GetName()
-	   << "' never defined." << endl;
-      return false;
-    }
-  }
-
-  cerr << "--- FINISHED ENVIRONMENT SETUP---" << endl;
-
-  return true;
-}
-
-
-void cEnvironment::SetupInputs( tArray<int> & input_array ) const
-{
-  input_array.Resize(3);
-
-  // Set the top 8 bits of the input buffer...
-  input_array[0] = 15 << 24;  // 00001111
-  input_array[1] = 51 << 24;  // 00110011
-  input_array[2] = 85 << 24;  // 01010101
-
-  // And randomize the rest...
-  for (int i = 0; i < 3; i++) {
-    input_array[i] += g_random.GetUInt(1 << 24);
-  }
-}
-
-
-bool cEnvironment::TestInput( cReactionResult & result,
-			      const tBuffer<int> & inputs,
-			      const tBuffer<int> & outputs,
-			      const tArray<double> & resource_count ) const
-{
-  // @CAO nothing for the moment...
-  return false;
-}
-
-
-bool cEnvironment::TestOutput( cReactionResult & result,
-			       const tBuffer<int> & input_buf,
-			       const tBuffer<int> & output_buf,
-			       const tBuffer<int> & send_buf,
-			       const tBuffer<int> & receive_buf,
-			       const tArray<int> & task_count,
-			       const tArray<int> & reaction_count,
-			       const tArray<double> & resource_count,
-			       const tList< tBuffer<int> > & input_buffers,
-			       const tList< tBuffer<int> > & output_buffers) const
-{
-  // Do setup for reaction tests...
-  task_lib.SetupTests(input_buf, output_buf, input_buffers, output_buffers);
-
-  // Loop through all reactions to see if any have been triggered...
-  const int num_reactions = reaction_lib.GetSize();
-  for (int i = 0; i < num_reactions; i++) {
-    cReaction * cur_reaction = reaction_lib.GetReaction(i);
-    assert(cur_reaction != NULL);
-
-    // Only use active reactions...
-    if (cur_reaction->GetActive() == false) continue;
-
-    // Examine the task trigger associated with this reaction
-    cTaskEntry * cur_task = cur_reaction->GetTask();
-    assert(cur_task != NULL);
-    const double task_quality = task_lib.TestOutput(*cur_task);
-    const int task_id = cur_task->GetID();
-
-    // If this task wasn't performed, move on to the next one.
-    if (task_quality == 0.0) continue;
-
-    // Mark this task as performed...
-    result.MarkTask(task_id);
-
-    // Examine requisites on this reaction
-    if (TestRequisites(cur_reaction->GetRequisites(), task_count[task_id],
-		       reaction_count) == false) {
-      continue;
-    }
-
-    // And lets process it!
-    DoProcesses(cur_reaction->GetProcesses(), resource_count,
-		task_quality, result);
-
-    // Mark this reaction as occuring...
-    result.MarkReaction(cur_reaction->GetID());
-  }
-
-  // Loop again to check receive tasks...
-  // if (receive_buf.GetSize() != 0)
-  {
-    // Do setup for reaction tests...
-    task_lib.
-      SetupTests(receive_buf, output_buf, input_buffers, output_buffers);
-
-    for (int i = 0; i < num_reactions; i++) {
-      cReaction * cur_reaction = reaction_lib.GetReaction(i);
-      assert(cur_reaction != NULL);
-      
-      // Only use active reactions...
-      if (cur_reaction->GetActive() == false) continue;
-      
-      // Examine the task trigger associated with this reaction
-      cTaskEntry * cur_task = cur_reaction->GetTask();
-      assert(cur_task != NULL);
-      const double task_quality = task_lib.TestOutput(*cur_task);
-      const int task_id = cur_task->GetID();
-      
-      // If this task wasn't performed, move on to the next one.
-      if (task_quality == 0.0) continue;
-      
-      // Mark this task as performed...
-      result.MarkReceiveTask(task_id);
-    }
-  }
-
-  return result.GetActive();
-}
-
-
-bool cEnvironment::TestRequisites(const tList<cReactionRequisite> & req_list,
-		  int task_count, const tArray<int> & reaction_count) const
-{
-  const int num_reqs = req_list.GetSize();
-
-  // If there are no requisites, there is nothing to meet!
-  if (num_reqs == 0) return true;
-
-  tConstListIterator<cReactionRequisite> req_it(req_list);
-  for (int i = 0; i < num_reqs; i++) {
-    // See if this requisite batch can be satisfied.
-    const cReactionRequisite * cur_req = req_it.Next();
-    bool satisfied = true;
-
-    // Have all reactions been met?
-    tConstListIterator<cReaction> reaction_it(cur_req->GetReactions());
-    while (reaction_it.Next() != NULL) {
-      int react_id = reaction_it.Get()->GetID();
-      if (reaction_count[react_id] == 0) {
-	satisfied = false;
-	break;
-      }
-    }
-    if (satisfied == false) continue;
-
-    // Have all no-reactions been met?
-    tConstListIterator<cReaction> noreaction_it(cur_req->GetNoReactions());
-    while (noreaction_it.Next() != NULL) {
-      int react_id = noreaction_it.Get()->GetID();
-      if (reaction_count[react_id] != 0) {
-	satisfied = false;
-	break;
-      }
-    }
-    if (satisfied == false) continue;
-
-    // Have all task counts been met?
-    if (task_count < cur_req->GetMinTaskCount()) continue;
-
-    // Have all reactions been met?
-    if (task_count >= cur_req->GetMaxTaskCount()) continue;
-
-    return true;
-  }
-
-  return false;
-}
-
-
-void cEnvironment::DoProcesses(const tList<cReactionProcess> & process_list,
-			       const tArray<double> & resource_count,
-			       const double task_quality,
-			       cReactionResult & result) const
-{
-  const int num_process = process_list.GetSize();
-
-  tConstListIterator<cReactionProcess> process_it(process_list);
-  for (int i = 0; i < num_process; i++) {
-    // See if this requisite batch can be satisfied.
-    const cReactionProcess * cur_process = process_it.Next();
-    const double max_consumed = cur_process->GetMaxNumber();
-    const double min_consumed = cur_process->GetMinNumber();
-
-    // Determine resource consumption
-    double consumed = 0.0;
-    cResource * in_resource = cur_process->GetResource();
-
-    // Test if infinite resource
-    if (in_resource == NULL) {
-      consumed = max_consumed;
-    }
-
-    // Otherwise we're using a finite resource
-    else {
-      const int res_id = in_resource->GetID();
-
-      consumed = resource_count[res_id] - result.GetConsumed(res_id);
-      consumed *= cur_process->GetMaxFraction();
-
-      // Make sure we're not above the maximum consumption.
-      if (consumed > max_consumed) consumed = max_consumed;
-
-      // Test if we are below the minimum consumption.
-      if (consumed < min_consumed) consumed = 0.0;
-
-      // If we don't actually have any resource to consume stop here.
-      if (consumed == 0.0) continue;
-
-      // Mark in the results the resource consumed.
-      result.Consume(res_id, consumed);
-    }
-
-    // Calculate the bonus
-    double bonus = consumed * cur_process->GetValue() * task_quality;
-
-    switch (cur_process->GetType()) {
-    case REACTION_PROCTYPE_ADD:
-      result.AddBonus(bonus);
-      break;
-    case REACTION_PROCTYPE_MULT:
-      result.MultBonus(bonus);
-      break;
-    case REACTION_PROCTYPE_POW:
-      result.MultBonus( pow(2.0, bonus) );
-      break;
-    default:
-      assert(false);  // Should not get here!
-      break;
-    };
-
-    // Determine detection events
-    cResource * detected = cur_process->GetDetect();
-    if (detected != NULL) {
-      const int detected_id = detected->GetID();
-      const double real_amount = resource_count[detected_id];
-      double estimated_amount =
-	   g_random.GetRandNormal(real_amount, cur_process->GetDetectionError()*real_amount);
-      if (estimated_amount < cur_process->GetDetectionThreshold()) {
-	result.Detect(detected_id, 0.0);		
-      } else {
-        result.Detect(detected_id, estimated_amount);
-      }
-    }
-
-    // Determine byproducts
-    cResource * product = cur_process->GetProduct();
-    if (product != NULL) {
-      int product_id = product->GetID();
-      double product_size = consumed * cur_process->GetConversion();
-      result.Produce(product_id, product_size);
-    }
-
-    // Determine what instructions should be run...
-    const int inst_id = cur_process->GetInstID();
-    if (inst_id >= 0) {
-      result.AddInst(inst_id);
-    }
-
-    result.Lethal(cur_process->GetLethal());
-  }
-}
-
-double cEnvironment::GetReactionValue(int & reaction_id)
-{
-  cReaction * found_reaction = reaction_lib.GetReaction(reaction_id);
-  if (found_reaction == NULL) return false;
-  return found_reaction->GetValue();
-}
-
-bool cEnvironment::SetReactionValue(const cString & name, double value)
-{
-  cReaction * found_reaction = reaction_lib.GetReaction(name);
-  if (found_reaction == NULL) return false;
-  found_reaction->ModifyValue(value);
-  return true;
-}
-
-bool cEnvironment::SetReactionValueMult(const cString & name, double value_mult)
-{
-  cReaction * found_reaction = reaction_lib.GetReaction(name);
-  if (found_reaction == NULL) return false;
-  found_reaction->MultiplyValue(value_mult);
-  return true;
-}
-
-bool cEnvironment::SetReactionInst(const cString & name, cString inst_name)
-{
-  cReaction * found_reaction = reaction_lib.GetReaction(name);
-  if (found_reaction == NULL) return false;
-  found_reaction->ModifyInst( inst_set.GetInst(inst_name).GetOp() );
-  return true;
-}
-

Deleted: trunk/source/main/environment.hh
===================================================================
--- trunk/source/main/environment.hh	2005-09-15 23:16:19 UTC (rev 313)
+++ trunk/source/main/environment.hh	2005-09-16 02:10:20 UTC (rev 314)
@@ -1,143 +0,0 @@
-//////////////////////////////////////////////////////////////////////////////
-// Copyright (C) 1993 - 2003 California Institute of Technology             //
-//                                                                          //
-// Read the COPYING and README files, or contact 'avida at alife.org',         //
-// before continuing.  SOME RESTRICTIONS MAY APPLY TO USE OF THIS FILE.     //
-//////////////////////////////////////////////////////////////////////////////
-
-#ifndef ENVIRONMENT_HH
-#define ENVIRONMENT_HH
-
-#ifndef INST_SET_HH
-#include "inst_set.hh"
-#endif
-#ifndef MUTATION_LIB_HH
-#include "mutation_lib.hh"
-#endif
-#ifndef MUTATION_RATES_HH
-#include "mutation_rates.hh"
-#endif
-#ifndef REACTION_LIB_HH
-#include "reaction_lib.hh"
-#endif
-#ifndef RESOURCE_LIB_HH
-#include "resource_lib.hh"
-#endif
-#ifndef STRING_HH
-#include "string.hh"
-#endif
-#ifndef TASK_LIB_HH
-#include "task_lib.hh"
-#endif
-#ifndef TLIST_HH
-#include "tList.hh"
-#endif
-
-class cResourceLib; // aggregate
-class cReactionLib; // aggregate
-class cMutationLib; // aggregate
-class cTaskLib; // aggregate
-class cInstSet; // aggregate
-class cMutationRates; // aggregate
-class cString; // aggregate
-class cReaction;
-template <class T> class tList;
-class cReactionRequisite;
-template <class T> class tArray;
-class cReactionProcess;
-class cReactionResult;
-template <class T> class tBuffer;
-
-class cEnvironment {
-private:
-  // Keep libraries of resources, reactions, and tasks.
-  cResourceLib resource_lib;
-  cReactionLib reaction_lib;
-  cMutationLib mutation_lib;
-  cTaskLib task_lib;
-  cInstSet inst_set;
-  cMutationRates mut_rates;
-
-  static bool ParseSetting(cString entry, cString & var_name,
-			   cString & var_value, const cString & var_type);
-  static bool AssertInputInt(const cString & input, const cString & name,
-			     const cString & type);
-  static bool AssertInputDouble(const cString & input, const cString & name,
-				const cString & type);
-  static bool AssertInputBool(const cString & input, const cString & name,
-				const cString & type);
-  static bool AssertInputValid(void * input, const cString & name,
-			       const cString & type, const cString & value);
-
-  bool LoadReactionProcess(cReaction * reaction, cString desc);
-  bool LoadReactionRequisite(cReaction * reaction, cString desc);
-  bool LoadResource(cString desc);
-  bool LoadReaction(cString desc);
-  bool LoadMutation(cString desc);
-
-  bool LoadSetActive(cString desc);
-
-  bool TestRequisites(const tList<cReactionRequisite> & req_list,
-		      int task_count,
-		      const tArray<int> & reaction_count) const;
-  void DoProcesses(const tList<cReactionProcess> & process_list,
-		   const tArray<double> & resource_count,
-		   const double task_quality,
-		   cReactionResult & result) const;
-private:
-  // disabled copy constructor.
-  cEnvironment(const cEnvironment &);
-public:
-  cEnvironment();
-  // cEnvironment(const cString & filename);
-  ~cEnvironment() { ; }
-
-  /**
-   * Reads the environment from disk.
-   **/
-  bool Load(const cString & filename);
-
-  /**
-   * Reads in a single environment configuration line
-   **/
-  bool LoadLine(cString line);
-
-  // Interaction with the organisms
-  void SetupInputs( tArray<int> & input_array ) const;
-
-  bool TestInput(  cReactionResult & result,
-		   const tBuffer<int> & inputs,
-		   const tBuffer<int> & outputs,
-		   const tArray<double> & resource_count ) const;
-
-  bool TestOutput(  cReactionResult & result,
-		    const tBuffer<int> & input_buf,
-		    const tBuffer<int> & output_buf,
-		    const tBuffer<int> & send_buf,
-		    const tBuffer<int> & receive_buf,
-		    const tArray<int> & task_count,
-		    const tArray<int> & reaction_count,
-		    const tArray<double> & resource_count,
-		    const tList<tBuffer<int> > & other_inputs,
-		    const tList<tBuffer<int> > & other_outputs) const;
-
-  // Accessors
-  const cResourceLib & GetResourceLib() const { return resource_lib; }
-  const cReactionLib & GetReactionLib() const { return reaction_lib; }
-  const cMutationLib & GetMutationLib() const { return mutation_lib; }
-  const cTaskLib & GetTaskLib() const { return task_lib; }
-  const cInstSet & GetInstSet() const { return inst_set; }
-  const cMutationRates & GetMutRates() const { return mut_rates; }
-
-  cResourceLib & GetResourceLib() { return resource_lib; }
-  cReactionLib & GetReactionLib() { return reaction_lib; }
-  cInstSet & GetInstSet() { return inst_set; }
-  cMutationRates & GetMutRates() { return mut_rates; }
-
-  double GetReactionValue(int & reaction_id);
-  bool SetReactionValue(const cString & name, double value);
-  bool SetReactionValueMult(const cString & name, double value_mult);
-  bool SetReactionInst(const cString & name, cString inst_name);
-};
-
-#endif

Modified: trunk/source/main/genebank.cc
===================================================================
--- trunk/source/main/genebank.cc	2005-09-15 23:16:19 UTC (rev 313)
+++ trunk/source/main/genebank.cc	2005-09-16 02:10:20 UTC (rev 314)
@@ -10,7 +10,7 @@
 #endif
 
 #ifndef CONFIG_HH
-#include "config.hh"
+#include "cConfig.h"
 #endif
 #ifndef GENOTYPE_HH
 #include "genotype.hh"

Modified: trunk/source/main/genotype.cc
===================================================================
--- trunk/source/main/genotype.cc	2005-09-15 23:16:19 UTC (rev 313)
+++ trunk/source/main/genotype.cc	2005-09-16 02:10:20 UTC (rev 314)
@@ -7,7 +7,7 @@
 
 #include "genotype.hh"
 
-#include "config.hh"
+#include "cConfig.h"
 #include "cCPUTestInfo.h"
 #include "genome_util.hh"
 #include "merit.hh"

Modified: trunk/source/main/inject_genebank.cc
===================================================================
--- trunk/source/main/inject_genebank.cc	2005-09-15 23:16:19 UTC (rev 313)
+++ trunk/source/main/inject_genebank.cc	2005-09-16 02:10:20 UTC (rev 314)
@@ -10,7 +10,7 @@
 #endif
 
 #ifndef CONFIG_HH
-#include "config.hh"
+#include "cConfig.h"
 #endif
 #ifndef DATA_FILE_HH
 #include "data_file.hh"

Modified: trunk/source/main/inject_genotype.cc
===================================================================
--- trunk/source/main/inject_genotype.cc	2005-09-15 23:16:19 UTC (rev 313)
+++ trunk/source/main/inject_genotype.cc	2005-09-16 02:10:20 UTC (rev 314)
@@ -10,7 +10,7 @@
 #endif
 
 #ifndef CONFIG_HH
-#include "config.hh"
+#include "cConfig.h"
 #endif
 #ifndef TOOLS_HH
 #include "tools.hh"

Modified: trunk/source/main/landscape.cc
===================================================================
--- trunk/source/main/landscape.cc	2005-09-15 23:16:19 UTC (rev 313)
+++ trunk/source/main/landscape.cc	2005-09-16 02:10:20 UTC (rev 314)
@@ -8,7 +8,7 @@
 #include "landscape.hh"
 
 #include "cCPUMemory.h"
-#include "environment.hh"
+#include "cEnvironment.h"
 #include "inst_set.hh"
 #include "organism.hh"
 #include "phenotype.hh"

Modified: trunk/source/main/lineage_control.cc
===================================================================
--- trunk/source/main/lineage_control.cc	2005-09-15 23:16:19 UTC (rev 313)
+++ trunk/source/main/lineage_control.cc	2005-09-16 02:10:20 UTC (rev 314)
@@ -11,7 +11,7 @@
 
 #include "lineage.hh"
 #include "stats.hh"
-#include "config.hh"
+#include "cConfig.h"
 #include "genebank.hh"
 #include "genotype.hh"
 #include "organism.hh"

Modified: trunk/source/main/main_sub.pri
===================================================================
--- trunk/source/main/main_sub.pri	2005-09-15 23:16:19 UTC (rev 313)
+++ trunk/source/main/main_sub.pri	2005-09-16 02:10:20 UTC (rev 314)
@@ -1,13 +1,13 @@
 
 main {
   HEADERS += \
-             $$MAIN_HH/analyze.hh \
-             $$MAIN_HH/analyze_util.hh \
+             $$MAIN_HH/cAnalyze.h \
+             $$MAIN_HH/cAnalyzeUtil.h \
              $$MAIN_HH/avida.hh \
-             $$MAIN_HH/birth_chamber.hh \
-             $$MAIN_HH/callback_util.hh \
-             $$MAIN_HH/config.hh \
-             $$MAIN_HH/environment.hh \
+             $$MAIN_HH/cBirthChamber.h \
+             $$MAIN_HH/cCallbackUtil.h \
+             $$MAIN_HH/cConfig.h \
+             $$MAIN_HH/cEnvironment.h \
              $$MAIN_HH/fitness_matrix.hh \
              $$MAIN_HH/genebank.hh \
              $$MAIN_HH/genome.hh \
@@ -24,7 +24,7 @@
              $$MAIN_HH/lineage_control.hh \
              $$MAIN_HH/organism.hh \
              $$MAIN_HH/phenotype.hh \
-             $$MAIN_HH/population_interface.hh \
+             $$MAIN_HH/cPopulationInterface.h \
              $$MAIN_HH/population.hh \
              $$MAIN_HH/population_cell.hh \
              $$MAIN_HH/reaction.hh \
@@ -36,17 +36,17 @@
              $$MAIN_HH/stats.hh
 
   SOURCES += \
-             $$MAIN_CC/analyze.cc \
-             $$MAIN_CC/analyze_util.cc \
-             $$MAIN_CC/analyze_genotype.cc \
+             $$MAIN_CC/cAnalyze.cc \
+             $$MAIN_CC/cAnalyzeUtil.cc \
+             $$MAIN_CC/cAnalyzeGenotype.cc \
              $$MAIN_CC/avida.cc \
-             $$MAIN_CC/avida_driver_analyze.cc \
-             $$MAIN_CC/avida_driver_base.cc \
-             $$MAIN_CC/avida_driver_population.cc \
-             $$MAIN_CC/birth_chamber.cc \
-             $$MAIN_CC/callback_util.cc \
-             $$MAIN_CC/config.cc \
-             $$MAIN_CC/environment.cc \
+             $$MAIN_CC/cAvidaDriver_Analyze.cc \
+             $$MAIN_CC/cAvidaDriver_Base.cc \
+             $$MAIN_CC/cAvidaDriver_Population.cc \
+             $$MAIN_CC/cBirthChamber.cc \
+             $$MAIN_CC/cCallbackUtil.cc \
+             $$MAIN_CC/cConfig.cc \
+             $$MAIN_CC/cEnvironment.cc \
              $$MAIN_CC/fitness_matrix.cc \
              $$MAIN_CC/genebank.cc \
              $$MAIN_CC/genome.cc \
@@ -73,7 +73,7 @@
              $$MAIN_CC/mx_code_array.cc \
              $$MAIN_CC/organism.cc \
              $$MAIN_CC/phenotype.cc \
-             $$MAIN_CC/population_interface.cc \
+             $$MAIN_CC/cPopulationInterface.cc \
              $$MAIN_CC/population.cc \
              $$MAIN_CC/population_cell.cc \
              $$MAIN_CC/reaction.cc \

Modified: trunk/source/main/mx_code_array.cc
===================================================================
--- trunk/source/main/mx_code_array.cc	2005-09-15 23:16:19 UTC (rev 313)
+++ trunk/source/main/mx_code_array.cc	2005-09-16 02:10:20 UTC (rev 314)
@@ -10,7 +10,7 @@
 #endif
 
 #ifndef CONFIG_HH
-#include "config.hh"
+#include "cConfig.h"
 #endif
 #ifndef CPU_TEST_INFO_HH
 #include "cCPUTestInfo.h"

Modified: trunk/source/main/organism.cc
===================================================================
--- trunk/source/main/organism.cc	2005-09-15 23:16:19 UTC (rev 313)
+++ trunk/source/main/organism.cc	2005-09-16 02:10:20 UTC (rev 314)
@@ -7,9 +7,9 @@
 
 #include "organism.hh"
 
-#include "config.hh"
+#include "cConfig.h"
 #include "nHardware.h"
-#include "environment.hh"
+#include "cEnvironment.h"
 #include "functions.hh"
 #include "genome.hh"
 #include "genome_util.hh"

Modified: trunk/source/main/organism.hh
===================================================================
--- trunk/source/main/organism.hh	2005-09-15 23:16:19 UTC (rev 313)
+++ trunk/source/main/organism.hh	2005-09-16 02:10:20 UTC (rev 314)
@@ -30,7 +30,7 @@
 #include "phenotype.hh"
 #endif
 #ifndef POPULATION_INTERFACE_HH
-#include "population_interface.hh"
+#include "cPopulationInterface.h"
 #endif
 #ifndef TBUFFER_HH
 #include "tBuffer.hh"

Modified: trunk/source/main/phenotype.cc
===================================================================
--- trunk/source/main/phenotype.cc	2005-09-15 23:16:19 UTC (rev 313)
+++ trunk/source/main/phenotype.cc	2005-09-16 02:10:20 UTC (rev 314)
@@ -10,10 +10,10 @@
 #endif
 
 #ifndef CONFIG_HH
-#include "config.hh"
+#include "cConfig.h"
 #endif
 #ifndef ENVIRONMENT_HH
-#include "environment.hh"
+#include "cEnvironment.h"
 #endif
 #ifndef REACTION_RESULT_HH
 #include "reaction_result.hh"

Modified: trunk/source/main/population.cc
===================================================================
--- trunk/source/main/population.cc	2005-09-15 23:16:19 UTC (rev 313)
+++ trunk/source/main/population.cc	2005-09-16 02:10:20 UTC (rev 314)
@@ -8,10 +8,10 @@
 #include "population.hh"
 
 #include "change_list.hh"
-#include "config.hh"
+#include "cConfig.h"
 #include "const_schedule.hh"
 #include "data_file.hh"
-#include "environment.hh"
+#include "cEnvironment.h"
 #include "functions.hh"
 #include "genebank.hh"
 #include "genome_util.hh"

Modified: trunk/source/main/population.hh
===================================================================
--- trunk/source/main/population.hh	2005-09-15 23:16:19 UTC (rev 313)
+++ trunk/source/main/population.hh	2005-09-16 02:10:20 UTC (rev 314)
@@ -11,10 +11,10 @@
 #include <fstream>
 
 #ifndef BIRTH_CHAMBER_HH
-#include "birth_chamber.hh"
+#include "cBirthChamber.h"
 #endif
 #ifndef POPULATION_INTERFACE_HH
-#include "population_interface.hh"
+#include "cPopulationInterface.h"
 #endif
 #ifndef RESOURCE_COUNT_HH
 #include "resource_count.hh"

Modified: trunk/source/main/population_cell.cc
===================================================================
--- trunk/source/main/population_cell.cc	2005-09-15 23:16:19 UTC (rev 313)
+++ trunk/source/main/population_cell.cc	2005-09-16 02:10:20 UTC (rev 314)
@@ -10,7 +10,7 @@
 #endif
 
 #ifndef CONFIG_HH
-#include "config.hh"
+#include "cConfig.h"
 #endif
 #ifndef nHardware_h
 #include "nHardware.h"

Deleted: trunk/source/main/population_interface.cc
===================================================================
--- trunk/source/main/population_interface.cc	2005-09-15 23:16:19 UTC (rev 313)
+++ trunk/source/main/population_interface.cc	2005-09-16 02:10:20 UTC (rev 314)
@@ -1,209 +0,0 @@
-//////////////////////////////////////////////////////////////////////////////
-// Copyright (C) 1993 - 2003 California Institute of Technology             //
-//                                                                          //
-// Read the COPYING and README files, or contact 'avida at alife.org',         //
-// before continuing.  SOME RESTRICTIONS MAY APPLY TO USE OF THIS FILE.     //
-//////////////////////////////////////////////////////////////////////////////
-
-#ifndef POPULATION_INTERFACE_HH
-#include "population_interface.hh"
-#endif
-
-#include <assert.h>
-
-#ifndef NULL
-#define NULL 0
-#endif
-
-cPopulationInterface::cPopulationInterface()
-  : population(NULL)
-  , cell_id(-1)
-  , fun_new_hardware(NULL)
-  , fun_recycle(NULL)
-  , fun_divide(NULL)
-  , fun_test_on_divide(NULL)
-  , fun_get_neighbor(NULL)
-  , fun_birth_chamber(NULL)
-  , fun_num_neighbors(NULL)
-  , fun_rotate(NULL)
-  , fun_breakpoint(NULL)
-  , fun_test_fitness(NULL)
-  , fun_get_input(NULL)
-  , fun_get_input_at(NULL)
-  , fun_debug(NULL)
-  , fun_get_resources(NULL)
-  , fun_update_resources(NULL)
-  , fun_kill_cell(NULL)
-  , fun_kill_surround_cell(NULL)
-  , fun_send_message(NULL)
-  , fun_receive_value(NULL)
-  , fun_inject_parasite(NULL)
-  , fun_update_merit(NULL)
-{
-}
-
-
-cPopulationInterface::~cPopulationInterface()
-{
-}
-
-void cPopulationInterface::CopyCallbacks(cPopulationInterface & in_interface)
-{
-  fun_new_hardware     = in_interface.fun_new_hardware;
-  fun_recycle          = in_interface.fun_recycle;
-  fun_divide           = in_interface.fun_divide;
-  fun_test_on_divide   = in_interface.fun_test_on_divide;
-  fun_get_neighbor     = in_interface.fun_get_neighbor;
-  fun_birth_chamber    = in_interface.fun_birth_chamber;
-  fun_num_neighbors    = in_interface.fun_num_neighbors;
-  fun_rotate           = in_interface.fun_rotate;
-  fun_breakpoint       = in_interface.fun_breakpoint;
-  fun_test_fitness     = in_interface.fun_test_fitness;
-  fun_get_input        = in_interface.fun_get_input;
-  fun_debug            = in_interface.fun_debug;
-  fun_get_resources    = in_interface.fun_get_resources;
-  fun_update_resources = in_interface.fun_update_resources;
-  fun_kill_cell        = in_interface.fun_kill_cell;
-  fun_kill_surround_cell = in_interface.fun_kill_surround_cell;
-  fun_send_message     = in_interface.fun_send_message;
-  fun_receive_value    = in_interface.fun_receive_value;
-  fun_inject_parasite  = in_interface.fun_inject_parasite;
-  fun_update_merit     = in_interface.fun_update_merit;
-}
-
-cHardwareBase * cPopulationInterface::NewHardware(cOrganism * owner)
-{
-  assert(fun_new_hardware != NULL);  // All interfaces must have a NewHardware!
-  return (*fun_new_hardware)(population, owner);
-}
-
-
-void cPopulationInterface::RecycleHardware(cHardwareBase * out_hardware)
-{
-  assert(fun_recycle != NULL);  // All interfaces must have a RecycleHArdware!
-  (*fun_recycle)(out_hardware);
-}
-
-
-bool cPopulationInterface::Divide(cOrganism * parent, cGenome & child_genome)
-{
-  assert (fun_divide != NULL);       // All interfaces must have a Divide!
-  return (*fun_divide)(population, cell_id, parent, child_genome);  
-}
-
-bool cPopulationInterface::TestOnDivide() const
-{
-  if (population == NULL) return false;
-  assert(fun_test_on_divide != NULL);
-  return (*fun_test_on_divide)(population, cell_id);
-}
-
-cOrganism * cPopulationInterface::GetNeighbor()
-{
-  if (fun_get_neighbor == NULL) return NULL;
-
-  assert(cell_id >= 0);
-  return (*fun_get_neighbor)(population, cell_id);
-}
-
-cBirthChamber & cPopulationInterface::GetBirthChamber()
-{
-  assert(fun_birth_chamber != NULL);
-  
-  return (*fun_birth_chamber)(population, cell_id);
-}
-
-int cPopulationInterface::GetNumNeighbors()
-{
-  if (fun_num_neighbors == NULL) return 0;
-
-  assert(cell_id >= 0);
-  return (*fun_num_neighbors)(population, cell_id);
-}
-
-void cPopulationInterface::Rotate(int direction)
-{
-  if (fun_rotate == NULL) return;
-
-  assert(cell_id >= 0);
-  (*fun_rotate)(population, cell_id, direction);
-}
-
-void cPopulationInterface::Breakpoint()
-{
-  if (fun_breakpoint == NULL) return;
-  (*fun_breakpoint)();
-}
-
-double cPopulationInterface::TestFitness()
-{
-  if (fun_test_fitness == NULL) return -1.0;
-  return (*fun_test_fitness)(population, cell_id);
-}
-
-int cPopulationInterface::GetInput()
-{
-  assert(fun_get_input != NULL);
-  return (*fun_get_input)(population, cell_id);
-}
-
-int cPopulationInterface::GetInputAt(int & input_pointer)
-{
-  assert(fun_get_input_at != NULL);
-  return (*fun_get_input_at)(population, cell_id, input_pointer);
-}
-
-int cPopulationInterface::Debug()
-{
-  assert(fun_debug != NULL);
-  return (*fun_debug)(population, cell_id);
-}
-
-const tArray<double> & cPopulationInterface::GetResources()
-{
-  assert(fun_get_resources != NULL);
-  return (*fun_get_resources)(population, cell_id);
-}
-
-void cPopulationInterface::UpdateResources(const tArray<double> & res_change)
-{
-  assert(fun_update_resources != NULL);
-  (*fun_update_resources)(population, cell_id, res_change);
-}
-
-void cPopulationInterface::Die()
-{
-  if (fun_kill_cell == NULL) return;
-  (*fun_kill_cell)(population, cell_id);
-}
-
-void cPopulationInterface::Kaboom()
-{
-	if (fun_kill_surround_cell == NULL) return;
-	(*fun_kill_surround_cell)(population, cell_id);
-}
-
-bool cPopulationInterface::SendMessage(cOrgMessage & mess)
-{
-  if (fun_send_message == NULL) return false;
-  return (*fun_send_message)(population, cell_id, mess);
-}
-
-int cPopulationInterface::ReceiveValue()
-{
-  assert(fun_receive_value != NULL);
-  return (*fun_receive_value)(population, cell_id);
-}
-
-bool cPopulationInterface::InjectParasite(cOrganism * parent, 
-					  const cGenome & injected_code)
-{
-  if (fun_inject_parasite == NULL) return false;
-  return (*fun_inject_parasite)(population, cell_id, parent, injected_code);
-}
-
-bool cPopulationInterface::UpdateMerit(double new_merit)
-{
-  if (fun_update_merit == NULL) return false;
-  return (*fun_update_merit)(population, cell_id, new_merit);
-}

Deleted: trunk/source/main/population_interface.hh
===================================================================
--- trunk/source/main/population_interface.hh	2005-09-15 23:16:19 UTC (rev 313)
+++ trunk/source/main/population_interface.hh	2005-09-16 02:10:20 UTC (rev 314)
@@ -1,134 +0,0 @@
-//////////////////////////////////////////////////////////////////////////////
-// Copyright (C) 1993 - 2003 California Institute of Technology             //
-//                                                                          //
-// Read the COPYING and README files, or contact 'avida at alife.org',         //
-// before continuing.  SOME RESTRICTIONS MAY APPLY TO USE OF THIS FILE.     //
-//////////////////////////////////////////////////////////////////////////////
-
-// This class is used by organisms to interface with their population.
-
-#ifndef POPULATION_INTERFACE_HH
-#define POPULATION_INTERFACE_HH
-
-class cHardwareBase;
-class cPopulation;
-class cOrganism;
-class cGenome;
-template <class T> class tArray;
-class cOrgMessage;
-class cBirthChamber;
-
-typedef cHardwareBase * (*tFunNewHardware)(cPopulation *pop, cOrganism *owner);
-typedef void (*tFunRecycle)(cHardwareBase * out_hardware);
-typedef bool (*tFunDivide)
-  (cPopulation * pop, int cell_id, cOrganism * parent, cGenome & child_genome);
-typedef bool (*tFunTestOnDivide)(cPopulation * pop, int cell_id);
-typedef cOrganism * (*tFunGetNeighbor)(cPopulation * pop, int cell_id);
-typedef cBirthChamber & (*tFunBirthChamber)(cPopulation * pop, int cell_id);
-typedef int (*tFunNumNeighbors)(cPopulation * pop, int cell_id);
-typedef void (*tFunRotate)(cPopulation * pop, int cell_id, int direction);
-typedef void (*tFunBreakpoint)();
-typedef double (*tFunTestFitness)(cPopulation * pop, int cell_id);
-typedef int (*tFunGetInput)(cPopulation * pop, int cell_id);
-typedef int (*tFunGetInputAt)(cPopulation * pop, int cell_id, int & input_pointer);
-typedef int (*tFunDebug)(cPopulation * pop, int cell_id);
-typedef const tArray<double> & (*tFunGetResources)
-  (cPopulation * pop, int cell_id);
-typedef void (*tFunUpdateResources)
-  (cPopulation * pop, int cell_id, const tArray<double> & res_change);
-typedef void (*tFunKillCell)(cPopulation * pop, int death_id);
-typedef void (*tFunKillSurroundCell)(cPopulation * pop, int commie_id);
-typedef bool (*tFunSendMessage)(cPopulation * pop, int cell_id, cOrgMessage & mess);
-typedef int (*tFunReceiveValue)(cPopulation * pop, int cell_id);
-typedef bool (*tFunInjectParasite)
-  (cPopulation * pop, int cell_id, cOrganism * parent, const cGenome & injected_code);
-typedef bool (*tFunUpdateMerit)(cPopulation * pop, int cell_id, double new_merit);
-
-class cPopulationInterface {
-private:
-  cPopulation * population;
-  int cell_id;
-
-  tFunNewHardware      fun_new_hardware;
-  tFunRecycle          fun_recycle;
-  tFunDivide           fun_divide;
-  tFunTestOnDivide     fun_test_on_divide;
-  tFunGetNeighbor      fun_get_neighbor;
-  tFunBirthChamber     fun_birth_chamber;
-  tFunNumNeighbors     fun_num_neighbors;
-  tFunRotate           fun_rotate;
-  tFunBreakpoint       fun_breakpoint;
-  tFunTestFitness      fun_test_fitness;
-  tFunGetInput         fun_get_input;
-  tFunGetInputAt       fun_get_input_at;
-  tFunDebug            fun_debug;
-  tFunGetResources     fun_get_resources;
-  tFunUpdateResources  fun_update_resources;
-  tFunKillCell		   fun_kill_cell;
-  tFunKillSurroundCell fun_kill_surround_cell;
-  tFunSendMessage      fun_send_message;
-  tFunReceiveValue	   fun_receive_value;
-  tFunInjectParasite   fun_inject_parasite;
-  tFunUpdateMerit      fun_update_merit;
-public:
-  cPopulationInterface();
-  ~cPopulationInterface();
-
-  cPopulation * GetPopulation() { return population; }
-  void SetPopulation(cPopulation * pop) { population = pop; }
-
-  int GetCellID() { return cell_id; }
-  void SetCellID(int in_id) { cell_id = in_id; }
-
-  void SetFun_NewHardware(tFunNewHardware fun) { fun_new_hardware = fun; }
-  void SetFun_Recycle(tFunRecycle fun) { fun_recycle = fun; }
-  void SetFun_Divide(tFunDivide fun) { fun_divide = fun; }
-  void SetFun_TestOnDivide(tFunTestOnDivide fun) { fun_test_on_divide = fun; }
-  void SetFun_GetNeighbor(tFunGetNeighbor fun) { fun_get_neighbor = fun; }
-  void SetFun_BirthChamber(tFunBirthChamber fun) { fun_birth_chamber = fun; }
-  void SetFun_NumNeighbors(tFunNumNeighbors fun) { fun_num_neighbors = fun; }
-  void SetFun_Rotate(tFunRotate fun) { fun_rotate = fun; }
-  void SetFun_Breakpoint(tFunBreakpoint fun) { fun_breakpoint = fun; }
-  void SetFun_TestFitness(tFunTestFitness fun) { fun_test_fitness = fun; }
-  void SetFun_GetInput(tFunGetInput fun) { fun_get_input = fun; }
-  void SetFun_GetInputAt(tFunGetInputAt fun) { fun_get_input_at = fun; }
-  void SetFun_Debug(tFunDebug fun) { fun_debug = fun; }
-  void SetFun_GetResources(tFunGetResources fun) { fun_get_resources = fun; }
-  void SetFun_UpdateResources(tFunUpdateResources fun)
-    { fun_update_resources = fun; }
-  void SetFun_KillCell(tFunKillCell fun) { fun_kill_cell = fun; }
-  void SetFun_KillSurroundCell(tFunKillSurroundCell fun) {fun_kill_surround_cell = fun; }
-  void SetFun_SendMessage(tFunSendMessage fun) { fun_send_message = fun; }
-  void SetFun_ReceiveValue(tFunReceiveValue fun) { fun_receive_value = fun; }
-  void SetFun_InjectParasite(tFunInjectParasite fun) { fun_inject_parasite = fun; }
-  void SetFun_UpdateMerit(tFunUpdateMerit fun) { fun_update_merit = fun; }
-
-  void CopyCallbacks(cPopulationInterface & in_interface);
-
-  bool InTestPop() { return (cell_id == -1); }
-
-  // Activate callbacks...
-  cHardwareBase * NewHardware(cOrganism * owner);
-  void RecycleHardware(cHardwareBase * out_hardware);
-  bool Divide(cOrganism * parent, cGenome & child_genome);
-  bool TestOnDivide() const;
-  cOrganism * GetNeighbor();
-  cBirthChamber & GetBirthChamber();
-  int GetNumNeighbors();
-  void Rotate(int direction=1);
-  void Breakpoint();
-  double TestFitness();
-  int GetInput();
-  int GetInputAt(int & input_pointer);
-  int Debug();
-  const tArray<double> & GetResources();
-  void UpdateResources(const tArray<double> & res_change);
-  void Die();
-  void Kaboom();
-  bool SendMessage(cOrgMessage & mess);
-  int ReceiveValue();
-  bool InjectParasite(cOrganism * parent, const cGenome & injected_code);
-  bool UpdateMerit(double new_merit);
-};
-
-#endif

Modified: trunk/source/main/primitive.cc
===================================================================
--- trunk/source/main/primitive.cc	2005-09-15 23:16:19 UTC (rev 313)
+++ trunk/source/main/primitive.cc	2005-09-16 02:10:20 UTC (rev 314)
@@ -13,25 +13,25 @@
 #include "avida.hh"
 #endif
 #ifndef AVIDA_DRIVER_ANALYZE_HH
-#include "avida_driver_analyze.hh"
+#include "cAvidaDriver_Analyze.h"
 #endif
 #ifndef AVIDA_DRIVER_BASE_HH
-#include "avida_driver_base.hh"
+#include "cAvidaDriver_Base.h"
 #endif
 #ifndef AVIDA_DRIVER_POPULATION_HH
-#include "avida_driver_population.hh"
+#include "cAvidaDriver_Population.h"
 #endif
 #ifndef CALLBACK_UTIL_HH
-#include "callback_util.hh"
+#include "cCallbackUtil.h"
 #endif
 #ifndef CONFIG_HH
-#include "config.hh"
+#include "cConfig.h"
 #endif
 #ifndef DEFS_HH
 #include "defs.hh"
 #endif
 #ifndef ENVIRONMENT_HH
-#include "environment.hh"
+#include "cEnvironment.h"
 #endif
 #ifndef HARDWARE_4STACK_HH
 #include "cHardware4Stack.h"
@@ -52,7 +52,7 @@
 #include "population.hh"
 #endif
 #ifndef POPULATION_INTERFACE_HH
-#include "population_interface.hh"
+#include "cPopulationInterface.h"
 #endif
 #ifndef RESOURCE_COUNT_HH
 #include "resource_count.hh"

Modified: trunk/source/main/resource.cc
===================================================================
--- trunk/source/main/resource.cc	2005-09-15 23:16:19 UTC (rev 313)
+++ trunk/source/main/resource.cc	2005-09-16 02:10:20 UTC (rev 314)
@@ -10,7 +10,7 @@
 #endif
 
 #ifndef CONFIG_HH
-#include "config.hh"
+#include "cConfig.h"
 #endif
 
 using namespace std;

Modified: trunk/source/main/resource_count.cc
===================================================================
--- trunk/source/main/resource_count.cc	2005-09-15 23:16:19 UTC (rev 313)
+++ trunk/source/main/resource_count.cc	2005-09-16 02:10:20 UTC (rev 314)
@@ -10,7 +10,7 @@
 #endif
 
 #ifndef CONFIG_HH
-#include "config.hh"
+#include "cConfig.h"
 #endif
 
 extern "C" {

Modified: trunk/source/main/spatial_res_count.cc
===================================================================
--- trunk/source/main/spatial_res_count.cc	2005-09-15 23:16:19 UTC (rev 313)
+++ trunk/source/main/spatial_res_count.cc	2005-09-16 02:10:20 UTC (rev 314)
@@ -10,7 +10,7 @@
 #endif
 
 #ifndef CONFIG_HH
-#include "config.hh"
+#include "cConfig.h"
 #endif
 #ifndef FUNCTIONS_HH
 #include "functions.hh"

Modified: trunk/source/main/species_control.cc
===================================================================
--- trunk/source/main/species_control.cc	2005-09-15 23:16:19 UTC (rev 313)
+++ trunk/source/main/species_control.cc	2005-09-16 02:10:20 UTC (rev 314)
@@ -10,7 +10,7 @@
 #endif
 
 #ifndef CONFIG_HH
-#include "config.hh"
+#include "cConfig.h"
 #endif
 #ifndef DEFS_HH
 #include "defs.hh"

Modified: trunk/source/main/stats.cc
===================================================================
--- trunk/source/main/stats.cc	2005-09-15 23:16:19 UTC (rev 313)
+++ trunk/source/main/stats.cc	2005-09-16 02:10:20 UTC (rev 314)
@@ -7,7 +7,7 @@
 
 #include "stats.hh"
 
-#include "config.hh"
+#include "cConfig.h"
 #include "data_file.hh"
 #include "functions.hh"
 #include "string_util.hh"

Modified: trunk/source/testsuites/unit_testsuites/analyze.t.cc
===================================================================
--- trunk/source/testsuites/unit_testsuites/analyze.t.cc	2005-09-15 23:16:19 UTC (rev 313)
+++ trunk/source/testsuites/unit_testsuites/analyze.t.cc	2005-09-16 02:10:20 UTC (rev 314)
@@ -1,7 +1,7 @@
 #include <iostream>
 
 #ifndef ANALYZE_HH
-#include "analyze.hh"
+#include "cAnalyze.h"
 #endif
 #ifndef TEST_CASE_H
 #include "third-party/yaktest/cTestCase.hh"

Modified: trunk/source/testsuites/unit_testsuites/analyze_command.t.cc
===================================================================
--- trunk/source/testsuites/unit_testsuites/analyze_command.t.cc	2005-09-15 23:16:19 UTC (rev 313)
+++ trunk/source/testsuites/unit_testsuites/analyze_command.t.cc	2005-09-16 02:10:20 UTC (rev 314)
@@ -1,7 +1,7 @@
 #include <iostream>
 
 #ifndef ANALYZE_COMMAND_HH
-#include "analyze_command.hh"
+#include "cAnalyzeCommand.h"
 #endif
 #ifndef TEST_CASE_H
 #include "third-party/yaktest/cTestCase.hh"

Modified: trunk/source/testsuites/unit_testsuites/analyze_command_def.t.cc
===================================================================
--- trunk/source/testsuites/unit_testsuites/analyze_command_def.t.cc	2005-09-15 23:16:19 UTC (rev 313)
+++ trunk/source/testsuites/unit_testsuites/analyze_command_def.t.cc	2005-09-16 02:10:20 UTC (rev 314)
@@ -1,7 +1,7 @@
 #include <iostream>
 
 #ifndef ANALYZE_COMMAND_DEF_HH
-#include "analyze_command_def.hh"
+#include "cAnalyzeCommandDef.h"
 #endif
 #ifndef TEST_CASE_H
 #include "third-party/yaktest/cTestCase.hh"

Modified: trunk/source/testsuites/unit_testsuites/analyze_command_def_base.t.cc
===================================================================
--- trunk/source/testsuites/unit_testsuites/analyze_command_def_base.t.cc	2005-09-15 23:16:19 UTC (rev 313)
+++ trunk/source/testsuites/unit_testsuites/analyze_command_def_base.t.cc	2005-09-16 02:10:20 UTC (rev 314)
@@ -1,7 +1,7 @@
 #include <iostream>
 
 #ifndef ANALYZE_COMMAND_DEF_BASE_HH
-#include "analyze_command_def_base.hh"
+#include "cAnalyzeCommandDefBase.h"
 #endif
 #ifndef TEST_CASE_H
 #include "third-party/yaktest/cTestCase.hh"

Modified: trunk/source/testsuites/unit_testsuites/analyze_flow_command.t.cc
===================================================================
--- trunk/source/testsuites/unit_testsuites/analyze_flow_command.t.cc	2005-09-15 23:16:19 UTC (rev 313)
+++ trunk/source/testsuites/unit_testsuites/analyze_flow_command.t.cc	2005-09-16 02:10:20 UTC (rev 314)
@@ -1,7 +1,7 @@
 #include <iostream>
 
 #ifndef ANALYZE_FLOW_COMMAND_HH
-#include "analyze_flow_command.hh"
+#include "cAnalyzeFlowCommand.h"
 #endif
 #ifndef TEST_CASE_H
 #include "third-party/yaktest/cTestCase.hh"

Modified: trunk/source/testsuites/unit_testsuites/analyze_flow_command_def.t.cc
===================================================================
--- trunk/source/testsuites/unit_testsuites/analyze_flow_command_def.t.cc	2005-09-15 23:16:19 UTC (rev 313)
+++ trunk/source/testsuites/unit_testsuites/analyze_flow_command_def.t.cc	2005-09-16 02:10:20 UTC (rev 314)
@@ -1,7 +1,7 @@
 #include <iostream>
 
 #ifndef ANALYZE_FLOW_COMMAND_DEF_HH
-#include "analyze_flow_command_def.hh"
+#include "cAnalyzeFlowCommandDef.h"
 #endif
 #ifndef TEST_CASE_H
 #include "third-party/yaktest/cTestCase.hh"

Modified: trunk/source/testsuites/unit_testsuites/analyze_function.t.cc
===================================================================
--- trunk/source/testsuites/unit_testsuites/analyze_function.t.cc	2005-09-15 23:16:19 UTC (rev 313)
+++ trunk/source/testsuites/unit_testsuites/analyze_function.t.cc	2005-09-16 02:10:20 UTC (rev 314)
@@ -1,7 +1,7 @@
 #include <iostream>
 
 #ifndef ANALYZE_FUNCTION_HH
-#include "analyze_function.hh"
+#include "cAnalyzeFunction.h"
 #endif
 #ifndef TEST_CASE_H
 #include "third-party/yaktest/cTestCase.hh"

Modified: trunk/source/testsuites/unit_testsuites/analyze_genotype.t.cc
===================================================================
--- trunk/source/testsuites/unit_testsuites/analyze_genotype.t.cc	2005-09-15 23:16:19 UTC (rev 313)
+++ trunk/source/testsuites/unit_testsuites/analyze_genotype.t.cc	2005-09-16 02:10:20 UTC (rev 314)
@@ -1,7 +1,7 @@
 #include <iostream>
 
 #ifndef ANALYZE_GENOTYPE_HH
-#include "analyze_genotype.hh"
+#include "cAnalyzeGenotype.h"
 #endif
 #ifndef TEST_CASE_H
 #include "third-party/yaktest/cTestCase.hh"

Modified: trunk/source/testsuites/unit_testsuites/analyze_util.t.cc
===================================================================
--- trunk/source/testsuites/unit_testsuites/analyze_util.t.cc	2005-09-15 23:16:19 UTC (rev 313)
+++ trunk/source/testsuites/unit_testsuites/analyze_util.t.cc	2005-09-16 02:10:20 UTC (rev 314)
@@ -1,7 +1,7 @@
 #include <iostream>
 
 #ifndef ANALYZE_UTIL_HH
-#include "analyze_util.hh"
+#include "cAnalyzeUtil.h"
 #endif
 #ifndef TEST_CASE_H
 #include "third-party/yaktest/cTestCase.hh"

Modified: trunk/source/testsuites/unit_testsuites/avida_driver_analyze.t.cc
===================================================================
--- trunk/source/testsuites/unit_testsuites/avida_driver_analyze.t.cc	2005-09-15 23:16:19 UTC (rev 313)
+++ trunk/source/testsuites/unit_testsuites/avida_driver_analyze.t.cc	2005-09-16 02:10:20 UTC (rev 314)
@@ -1,7 +1,7 @@
 #include <iostream>
 
 #ifndef AVIDA_DRIVER_ANALYZE_HH
-#include "avida_driver_analyze.hh"
+#include "cAvidaDriver_Analyze.h"
 #endif
 #ifndef TEST_CASE_H
 #include "third-party/yaktest/cTestCase.hh"

Modified: trunk/source/testsuites/unit_testsuites/avida_driver_base.t.cc
===================================================================
--- trunk/source/testsuites/unit_testsuites/avida_driver_base.t.cc	2005-09-15 23:16:19 UTC (rev 313)
+++ trunk/source/testsuites/unit_testsuites/avida_driver_base.t.cc	2005-09-16 02:10:20 UTC (rev 314)
@@ -1,7 +1,7 @@
 #include <iostream>
 
 #ifndef AVIDA_DRIVER_BASE_HH
-#include "avida_driver_base.hh"
+#include "cAvidaDriver_Base.h"
 #endif
 #ifndef TEST_CASE_H
 #include "third-party/yaktest/cTestCase.hh"

Modified: trunk/source/testsuites/unit_testsuites/avida_driver_population.t.cc
===================================================================
--- trunk/source/testsuites/unit_testsuites/avida_driver_population.t.cc	2005-09-15 23:16:19 UTC (rev 313)
+++ trunk/source/testsuites/unit_testsuites/avida_driver_population.t.cc	2005-09-16 02:10:20 UTC (rev 314)
@@ -1,7 +1,7 @@
 #include <iostream>
 
 #ifndef AVIDA_DRIVER_POPULATION_HH
-#include "avida_driver_population.hh"
+#include "cAvidaDriver_Population.h"
 #endif
 #ifndef TEST_CASE_H
 #include "third-party/yaktest/cTestCase.hh"

Modified: trunk/source/testsuites/unit_testsuites/avida_triggers.t.cc
===================================================================
--- trunk/source/testsuites/unit_testsuites/avida_triggers.t.cc	2005-09-15 23:16:19 UTC (rev 313)
+++ trunk/source/testsuites/unit_testsuites/avida_triggers.t.cc	2005-09-16 02:10:20 UTC (rev 314)
@@ -1,5 +1,5 @@
 #ifndef AVIDA_TRIGGERS_HH
-#include "avida_triggers.hh"
+#include "cAvidaTriggers.h"
 #endif
 
 #ifndef TEST_CASE_H

Modified: trunk/source/testsuites/unit_testsuites/birth_chamber.t.cc
===================================================================
--- trunk/source/testsuites/unit_testsuites/birth_chamber.t.cc	2005-09-15 23:16:19 UTC (rev 313)
+++ trunk/source/testsuites/unit_testsuites/birth_chamber.t.cc	2005-09-16 02:10:20 UTC (rev 314)
@@ -1,7 +1,7 @@
 #include <iostream>
 
 #ifndef BIRTH_CHAMBER_HH
-#include "birth_chamber.hh"
+#include "cBirthChamber.h"
 #endif
 #ifndef TEST_CASE_H
 #include "third-party/yaktest/cTestCase.hh"

Modified: trunk/source/testsuites/unit_testsuites/callback_util.t.cc
===================================================================
--- trunk/source/testsuites/unit_testsuites/callback_util.t.cc	2005-09-15 23:16:19 UTC (rev 313)
+++ trunk/source/testsuites/unit_testsuites/callback_util.t.cc	2005-09-16 02:10:20 UTC (rev 314)
@@ -1,7 +1,7 @@
 #include <iostream>
 
 #ifndef CALLBACK_UTIL_HH
-#include "callback_util.hh"
+#include "cCallbackUtil.h"
 #endif
 #ifndef TEST_CASE_H
 #include "third-party/yaktest/cTestCase.hh"

Modified: trunk/source/testsuites/unit_testsuites/config.t.cc
===================================================================
--- trunk/source/testsuites/unit_testsuites/config.t.cc	2005-09-15 23:16:19 UTC (rev 313)
+++ trunk/source/testsuites/unit_testsuites/config.t.cc	2005-09-16 02:10:20 UTC (rev 314)
@@ -1,7 +1,7 @@
 #include <iostream>
 
 #ifndef CONFIG_HH
-#include "config.hh"
+#include "cConfig.h"
 #endif
 #ifndef TEST_CASE_H
 #include "third-party/yaktest/cTestCase.hh"

Modified: trunk/source/testsuites/unit_testsuites/environment.t.cc
===================================================================
--- trunk/source/testsuites/unit_testsuites/environment.t.cc	2005-09-15 23:16:19 UTC (rev 313)
+++ trunk/source/testsuites/unit_testsuites/environment.t.cc	2005-09-16 02:10:20 UTC (rev 314)
@@ -1,7 +1,7 @@
 #include <iostream>
 
 #ifndef ENVIRONMENT_HH
-#include "environment.hh"
+#include "cEnvironment.h"
 #endif
 #ifndef TEST_CASE_H
 #include "third-party/yaktest/cTestCase.hh"

Modified: trunk/source/testsuites/unit_testsuites/population_interface.t.cc
===================================================================
--- trunk/source/testsuites/unit_testsuites/population_interface.t.cc	2005-09-15 23:16:19 UTC (rev 313)
+++ trunk/source/testsuites/unit_testsuites/population_interface.t.cc	2005-09-16 02:10:20 UTC (rev 314)
@@ -1,5 +1,5 @@
 #ifndef POPULATION_INTERFACE_HH
-#include "population_interface.hh"
+#include "cPopulationInterface.h"
 #endif
 
 #ifndef TEST_CASE_H

Modified: trunk/source/viewers/bar_screen.cc
===================================================================
--- trunk/source/viewers/bar_screen.cc	2005-09-15 23:16:19 UTC (rev 313)
+++ trunk/source/viewers/bar_screen.cc	2005-09-16 02:10:20 UTC (rev 314)
@@ -7,7 +7,7 @@
 
 #include "population.hh"
 #include "stats.hh"
-#include "environment.hh"
+#include "cEnvironment.h"
 
 #include "bar_screen.hh"
 

Modified: trunk/source/viewers/environment_screen.cc
===================================================================
--- trunk/source/viewers/environment_screen.cc	2005-09-15 23:16:19 UTC (rev 313)
+++ trunk/source/viewers/environment_screen.cc	2005-09-16 02:10:20 UTC (rev 314)
@@ -5,8 +5,8 @@
 // before continuing.  SOME RESTRICTIONS MAY APPLY TO USE OF THIS FILE.     //
 //////////////////////////////////////////////////////////////////////////////
 
-#include "config.hh"
-#include "environment.hh"
+#include "cConfig.h"
+#include "cEnvironment.h"
 #include "genebank.hh"
 #include "genotype.hh"
 #include "population.hh"

Modified: trunk/source/viewers/options_screen.cc
===================================================================
--- trunk/source/viewers/options_screen.cc	2005-09-15 23:16:19 UTC (rev 313)
+++ trunk/source/viewers/options_screen.cc	2005-09-16 02:10:20 UTC (rev 314)
@@ -5,7 +5,7 @@
 // before continuing.  SOME RESTRICTIONS MAY APPLY TO USE OF THIS FILE.     //
 //////////////////////////////////////////////////////////////////////////////
 
-#include "config.hh"
+#include "cConfig.h"
 #include "population.hh"
 
 #include "options_screen.hh"

Modified: trunk/source/viewers/stats_screen.cc
===================================================================
--- trunk/source/viewers/stats_screen.cc	2005-09-15 23:16:19 UTC (rev 313)
+++ trunk/source/viewers/stats_screen.cc	2005-09-16 02:10:20 UTC (rev 314)
@@ -5,8 +5,8 @@
 // before continuing.  SOME RESTRICTIONS MAY APPLY TO USE OF THIS FILE.     //
 //////////////////////////////////////////////////////////////////////////////
 
-#include "config.hh"
-#include "environment.hh"
+#include "cConfig.h"
+#include "cEnvironment.h"
 #include "genebank.hh"
 #include "genotype.hh"
 #include "population.hh"

Modified: trunk/source/viewers/symbol_util.cc
===================================================================
--- trunk/source/viewers/symbol_util.cc	2005-09-15 23:16:19 UTC (rev 313)
+++ trunk/source/viewers/symbol_util.cc	2005-09-16 02:10:20 UTC (rev 314)
@@ -13,7 +13,7 @@
 #include "organism.hh"
 #include "population_cell.hh"
 #include "species.hh"
-#include "config.hh"
+#include "cConfig.h"
 #include "cHardwareBase.h"
 #include "cHardware4Stack.h"
 #include "cHardwareCPU.h"

Modified: trunk/source/viewers/view.cc
===================================================================
--- trunk/source/viewers/view.cc	2005-09-15 23:16:19 UTC (rev 313)
+++ trunk/source/viewers/view.cc	2005-09-16 02:10:20 UTC (rev 314)
@@ -8,7 +8,7 @@
 #include <fstream>
 
 #ifndef ENVIRONMENT_HH
-#include "environment.hh"
+#include "cEnvironment.h"
 #endif
 #include "genotype.hh"
 #include "organism.hh"

Modified: trunk/source/viewers/viewer.cc
===================================================================
--- trunk/source/viewers/viewer.cc	2005-09-15 23:16:19 UTC (rev 313)
+++ trunk/source/viewers/viewer.cc	2005-09-16 02:10:20 UTC (rev 314)
@@ -10,10 +10,10 @@
 #endif
 
 #ifndef CONFIG_HH
-#include "config.hh"
+#include "cConfig.h"
 #endif
 #ifndef ENVIRONMENT_HH
-#include "environment.hh"
+#include "cEnvironment.h"
 #endif
 #ifndef POPULATION_HH
 #include "population.hh"

Modified: trunk/source/viewers/viewer.hh
===================================================================
--- trunk/source/viewers/viewer.hh	2005-09-15 23:16:19 UTC (rev 313)
+++ trunk/source/viewers/viewer.hh	2005-09-16 02:10:20 UTC (rev 314)
@@ -13,13 +13,13 @@
 #endif
 
 #ifndef AVIDA_DRIVER_ANALYZE_HH
-#include "avida_driver_analyze.hh"
+#include "cAvidaDriver_Analyze.h"
 #endif
 #ifndef AVIDA_DRIVER_BASE_HH
-#include "avida_driver_base.hh"
+#include "cAvidaDriver_Base.h"
 #endif
 #ifndef AVIDA_DRIVER_POPULATION_HH
-#include "avida_driver_population.hh"
+#include "cAvidaDriver_Population.h"
 #endif
 
 class cView;

Modified: trunk/source/viewers/zoom_screen.cc
===================================================================
--- trunk/source/viewers/zoom_screen.cc	2005-09-15 23:16:19 UTC (rev 313)
+++ trunk/source/viewers/zoom_screen.cc	2005-09-16 02:10:20 UTC (rev 314)
@@ -6,11 +6,11 @@
 //////////////////////////////////////////////////////////////////////////////
 
 #ifndef ENVIRONMENT_HH
-#include "environment.hh"
+#include "cEnvironment.h"
 #endif
 #include "functions.hh"
 
-#include "config.hh"
+#include "cConfig.h"
 #include "genebank.hh"
 #include "genotype.hh"
 #include "organism.hh"




More information about the Avida-cvs mailing list