From 02ffe7169eee6d0b81fa76abea62dd83c2946cf1 Mon Sep 17 00:00:00 2001
From: KyleKlenk <kyle.c.klenk@gmail.com>
Date: Tue, 4 Oct 2022 21:41:11 +0000
Subject: [PATCH] settings information is now read in from main and propogated
 to the correct actor.  - This allows parent actors to have info for recovery
 and for the information to not have to be read from a file in the case we are
 in a distributed situation

 - also added better error message for read_attribute.f90
---
 Summa-Actors.code-workspace                   |  79 +++++++++++-
 .../file_access_actor/file_access_actor.hpp   |   6 +-
 build/includes/global/settings_functions.hpp  |   7 +-
 build/includes/hru_actor/hru_actor.hpp        |  12 +-
 build/includes/job_actor/job_actor.hpp        |  13 +-
 build/includes/summa_actor/summa_actor.hpp    |  11 +-
 .../file_access_actor/file_access_actor.cpp   |  10 +-
 .../actors/global/settings_functions.cpp      |  10 +-
 build/source/actors/gru_actor/gru_actor.cpp   |  12 +-
 build/source/actors/hru_actor/hru_actor.cpp   |  21 +---
 build/source/actors/job_actor/job_actor.cpp   |  65 +++-------
 build/source/actors/main.cpp                  |  64 +++++-----
 .../source/actors/summa_actor/summa_actor.cpp |  24 ++--
 .../actors/summa_actor/summa_client.cpp       |  10 +-
 build/source/dshare/get_ixname.f90            |   3 +-
 build/source/dshare/popMetadat.f90            |   2 +-
 build/source/dshare/var_lookup.f90            |   3 +-
 build/source/engine/read_attribute.f90        | 117 ++++++++++++++----
 18 files changed, 293 insertions(+), 176 deletions(-)

diff --git a/Summa-Actors.code-workspace b/Summa-Actors.code-workspace
index 8b3da04..563f06c 100644
--- a/Summa-Actors.code-workspace
+++ b/Summa-Actors.code-workspace
@@ -7,5 +7,82 @@
 			"path": "../gladwell"
 		}
 	],
-	"settings": {}
+	"settings": {
+		"files.associations": {
+			"any": "cpp",
+			"array": "cpp",
+			"atomic": "cpp",
+			"bit": "cpp",
+			"*.tcc": "cpp",
+			"bitset": "cpp",
+			"cctype": "cpp",
+			"cfenv": "cpp",
+			"charconv": "cpp",
+			"chrono": "cpp",
+			"cinttypes": "cpp",
+			"clocale": "cpp",
+			"cmath": "cpp",
+			"codecvt": "cpp",
+			"complex": "cpp",
+			"condition_variable": "cpp",
+			"csetjmp": "cpp",
+			"csignal": "cpp",
+			"cstdarg": "cpp",
+			"cstddef": "cpp",
+			"cstdint": "cpp",
+			"cstdio": "cpp",
+			"cstdlib": "cpp",
+			"cstring": "cpp",
+			"ctime": "cpp",
+			"cuchar": "cpp",
+			"cwchar": "cpp",
+			"cwctype": "cpp",
+			"deque": "cpp",
+			"forward_list": "cpp",
+			"list": "cpp",
+			"map": "cpp",
+			"set": "cpp",
+			"unordered_map": "cpp",
+			"unordered_set": "cpp",
+			"vector": "cpp",
+			"exception": "cpp",
+			"algorithm": "cpp",
+			"functional": "cpp",
+			"iterator": "cpp",
+			"memory": "cpp",
+			"memory_resource": "cpp",
+			"numeric": "cpp",
+			"optional": "cpp",
+			"random": "cpp",
+			"ratio": "cpp",
+			"regex": "cpp",
+			"string": "cpp",
+			"string_view": "cpp",
+			"system_error": "cpp",
+			"tuple": "cpp",
+			"type_traits": "cpp",
+			"utility": "cpp",
+			"fstream": "cpp",
+			"future": "cpp",
+			"initializer_list": "cpp",
+			"iomanip": "cpp",
+			"iosfwd": "cpp",
+			"iostream": "cpp",
+			"istream": "cpp",
+			"limits": "cpp",
+			"mutex": "cpp",
+			"new": "cpp",
+			"ostream": "cpp",
+			"scoped_allocator": "cpp",
+			"shared_mutex": "cpp",
+			"sstream": "cpp",
+			"stdexcept": "cpp",
+			"streambuf": "cpp",
+			"thread": "cpp",
+			"typeindex": "cpp",
+			"typeinfo": "cpp",
+			"valarray": "cpp",
+			"variant": "cpp"
+		}
+	}
 }
\ No newline at end of file
diff --git a/build/includes/file_access_actor/file_access_actor.hpp b/build/includes/file_access_actor/file_access_actor.hpp
index 66e2a53..460abcf 100644
--- a/build/includes/file_access_actor/file_access_actor.hpp
+++ b/build/includes/file_access_actor/file_access_actor.hpp
@@ -4,6 +4,7 @@
 #include "output_manager.hpp"
 #include "forcing_file_info.hpp"
 #include "timing_info.hpp"
+#include "settings_functions.hpp"
 
 namespace caf {
 struct file_access_state {
@@ -24,6 +25,8 @@ struct file_access_state {
     int filesLoaded;
     int err;
 
+    File_Access_Actor_Settings file_access_actor_settings;
+
     std::vector<Forcing_File_Info> forcing_file_list; // list of steps in file
     std::vector<bool> outputFileInitHRU;
 
@@ -32,7 +35,8 @@ struct file_access_state {
 };
 
 behavior file_access_actor(stateful_actor<file_access_state>* self, int startGRU, int numGRU, 
-    int outputStrucSize, std::string configPath, actor parent);
+    int outputStrucSize, File_Access_Actor_Settings file_access_actor_settings, actor parent);
+
 void initalizeFileAccessActor(stateful_actor<file_access_state>* self);
 int writeOutput(stateful_actor<file_access_state>* self, int indxGRU, int indxHRU, int numStepsToWrite, int returnMessage, caf::actor actorRef);
 int readForcing(stateful_actor<file_access_state>* self, int currentFile);
diff --git a/build/includes/global/settings_functions.hpp b/build/includes/global/settings_functions.hpp
index e609103..b6f1295 100644
--- a/build/includes/global/settings_functions.hpp
+++ b/build/includes/global/settings_functions.hpp
@@ -29,21 +29,20 @@ bool inspect(Inspector& inspector, Distributed_Settings& distributed_settings) {
 
 
 struct Summa_Actor_Settings {
-    int output_structure_size;
     int max_gru_per_job;
 };
 
 template<class Inspector>
 bool inspect(Inspector& inspector, Summa_Actor_Settings& summa_actor_settings) {
     return inspector.object(summa_actor_settings).fields(
-                inspector.field("output_structure_size", summa_actor_settings.output_structure_size),
-                inspector.field("max_gru_per_job",       summa_actor_settings.max_gru_per_job));  
+                inspector.field("max_gru_per_job",  summa_actor_settings.max_gru_per_job));  
 }
 
 
 struct File_Access_Actor_Settings {
     int num_vectors_in_output_manager;
 };
+
 template<class Inspector>
 bool inspect(Inspector& inspector, File_Access_Actor_Settings& file_access_actor_settings) {
     return inspector.object(file_access_actor_settings).fields(
@@ -53,6 +52,7 @@ bool inspect(Inspector& inspector, File_Access_Actor_Settings& file_access_actor
 
 struct Job_Actor_Settings {
     std::string file_manager_path;
+    int output_structure_size;
     bool output_csv;
     std::string csv_path;
 };
@@ -61,6 +61,7 @@ template<class Inspector>
 bool inspect(Inspector& inspector, Job_Actor_Settings& job_actor_settings) {
     return inspector.object(job_actor_settings).fields(
                 inspector.field("file_manager_path", job_actor_settings.file_manager_path),
+                inspector.field("output_structure_size", job_actor_settings.output_structure_size),
                 inspector.field("output_csv",        job_actor_settings.output_csv),
                 inspector.field("csv_path",          job_actor_settings.csv_path));
 }
diff --git a/build/includes/hru_actor/hru_actor.hpp b/build/includes/hru_actor/hru_actor.hpp
index cb0b725..de46b8d 100644
--- a/build/includes/hru_actor/hru_actor.hpp
+++ b/build/includes/hru_actor/hru_actor.hpp
@@ -3,7 +3,7 @@
 #include "caf/all.hpp"
 #include "fortran_data_types.hpp"
 #include "timing_info.hpp"
-
+#include "settings_functions.hpp"
 #include <chrono>
 #include <string>
 
@@ -79,11 +79,15 @@ struct hru_state {
     bool        printOutput;
     int         outputFrequency;
 
-
     // Julian Day variables
     double      fracJulDay;
     double      tmZoneOffsetFracDay;
     int         yearLength;
+
+    // Settings
+    HRU_Actor_Settings hru_actor_settings;
+
+
     int         err = 0;			            // error conotrol
 
     TimingInfo hru_timing;
@@ -91,8 +95,8 @@ struct hru_state {
 };
 
 behavior hru_actor(stateful_actor<hru_state>* self, int refGRU, int indxGRU,
-    std::string configPath,
-    caf::actor file_access_actor, int outputStrucSize, caf::actor parent);
+    HRU_Actor_Settings hru_actor_settings, caf::actor file_access_actor, 
+    int outputStrucSize, caf::actor parent);
 
 /**
  Function to initalize the HRU for running
diff --git a/build/includes/job_actor/job_actor.hpp b/build/includes/job_actor/job_actor.hpp
index 1c89afb..9b50fbc 100644
--- a/build/includes/job_actor/job_actor.hpp
+++ b/build/includes/job_actor/job_actor.hpp
@@ -3,6 +3,7 @@
 #include "caf/io/all.hpp"
 #include "GRUinfo.hpp"
 #include "timing_info.hpp"
+#include "settings_functions.hpp"
 
 namespace caf {
 struct job_state {
@@ -14,9 +15,6 @@ struct job_state {
     int start_gru;                 // Starting GRU for this job
     int num_gru;                   // Number of GRUs for this job
     int num_hru;
-    std::string config_path;
-
-    std::string file_manager;      // Path of the fileManager.txt file
 
     // Variables for GRU monitoring
     int dt_init_start_factor = 1;   // Initial Factor for dt_init (coupled_em)
@@ -33,17 +31,22 @@ struct job_state {
 
     
     // Output File Names for Timings
-    bool output_csv;
     std::string csv_out;
     std::string csv_path;
     std::string success_output_file;
     std::string failed_output_file = "failedHRU";
     std::string file_access_actor_stats = "fileAccessActor.csv";
 
+    // settings for all child actors (save in case we need to recover)
+    File_Access_Actor_Settings file_access_actor_settings;
+    Job_Actor_Settings job_actor_settings; 
+    HRU_Actor_Settings hru_actor_settings;
+
 };
 
 behavior job_actor(stateful_actor<job_state>* self, int start_gru, int num_gru, 
-    std::string config_path, int output_struct_size, actor parent);
+    File_Access_Actor_Settings file_access_actor_settings, Job_Actor_Settings job_actor_settings, 
+    HRU_Actor_Settings hru_actor_settings, actor parent);
 
 void initCsvOutputFile(stateful_actor<job_state>* self);
 
diff --git a/build/includes/summa_actor/summa_actor.hpp b/build/includes/summa_actor/summa_actor.hpp
index c87c6a5..d1a1603 100644
--- a/build/includes/summa_actor/summa_actor.hpp
+++ b/build/includes/summa_actor/summa_actor.hpp
@@ -3,6 +3,7 @@
 #include "caf/all.hpp"
 #include "caf/io/all.hpp"
 #include "timing_info.hpp"
+#include "settings_functions.hpp"
 
 #include <chrono>
 #include <string>
@@ -36,9 +37,17 @@ struct summa_actor_state {
     caf::actor currentJob;  // Reference to the current job actor
     caf::actor parent;
 
+
+    // settings for all child actors (save in case we need to recover)
+    Summa_Actor_Settings summa_actor_settings;
+    File_Access_Actor_Settings file_access_actor_settings;
+    Job_Actor_Settings job_actor_settings; 
+    HRU_Actor_Settings hru_actor_settings;
 };
 
-behavior summa_actor(stateful_actor<summa_actor_state>* self, int startGRU, int numGRU, std::string configPath, actor parent);
+behavior summa_actor(stateful_actor<summa_actor_state>* self, int startGRU, int numGRU, 
+    Summa_Actor_Settings summa_actor_settings, File_Access_Actor_Settings file_access_actor_settings,
+    Job_Actor_Settings job_actor_settings, HRU_Actor_Settings hru_actor_settings, actor parent);
 
 void spawnJob(stateful_actor<summa_actor_state>* self);
 
diff --git a/build/source/actors/file_access_actor/file_access_actor.cpp b/build/source/actors/file_access_actor/file_access_actor.cpp
index fd9842f..9624661 100644
--- a/build/source/actors/file_access_actor/file_access_actor.cpp
+++ b/build/source/actors/file_access_actor/file_access_actor.cpp
@@ -16,25 +16,23 @@ bool debug;
 namespace caf {
 
 behavior file_access_actor(stateful_actor<file_access_state>* self, int startGRU, int numGRU, 
-    int outputStrucSize, std::string configPath, actor parent) {
+    int output_structure_size, File_Access_Actor_Settings file_access_actor_settings, actor parent) {
     aout(self) << "\n----------File_Access_Actor Started----------\n";
     // Set Up timing Info we wish to track
     self->state.file_access_timing = TimingInfo();
     self->state.file_access_timing.addTimePoint("read_duration");
     self->state.file_access_timing.addTimePoint("write_duration");
 
+    self->state.file_access_actor_settings = file_access_actor_settings;
 
     self->state.parent = parent;
     self->state.numGRU = numGRU;
     self->state.startGRU = startGRU;
-    self->state.outputStrucSize = outputStrucSize;
+    self->state.outputStrucSize = output_structure_size;
     self->state.handle_forcing_file_info = new_handle_file_info();
     self->state.handle_ncid = new_handle_var_i();
     self->state.err = 0;
 
-    // Get Settings from configuration file
-    self->state.num_vectors_in_output_manager = getSettings(configPath, "FileAccessActor", "num_vectors_in_output_manager", 
-		self->state.num_vectors_in_output_manager).value_or(1);
         
     initalizeFileAccessActor(self);
 
@@ -278,7 +276,7 @@ void initalizeFileAccessActor(stateful_actor<file_access_state>* self) {
     }
 
     // Initalize the output manager  
-    self->state.output_manager = new OutputManager(self->state.num_vectors_in_output_manager, self->state.numGRU);
+    self->state.output_manager = new OutputManager(self->state.file_access_actor_settings.num_vectors_in_output_manager, self->state.numGRU);
     
     self->send(self->state.parent, done_file_access_actor_init_v);
     // initalize the forcingFile array
diff --git a/build/source/actors/global/settings_functions.cpp b/build/source/actors/global/settings_functions.cpp
index 3616b13..37f1270 100644
--- a/build/source/actors/global/settings_functions.cpp
+++ b/build/source/actors/global/settings_functions.cpp
@@ -28,10 +28,7 @@ int read_settings_from_json(std::string json_settings_file,
 
     
     // read settings for summa actor
-    parent_key = "Summa_Actor";
-    summa_actor_settings.output_structure_size = getSettings(json_settings_file, parent_key,
-        "output_structure_size", summa_actor_settings.output_structure_size).value_or(250);
-    
+    parent_key = "Summa_Actor";    
     summa_actor_settings.max_gru_per_job = getSettings(json_settings_file, parent_key,
         "max_gru_per_job", summa_actor_settings.max_gru_per_job).value_or(250);
 
@@ -47,6 +44,9 @@ int read_settings_from_json(std::string json_settings_file,
     job_actor_settings.file_manager_path = getSettings(json_settings_file, parent_key,
         "file_manager_path", job_actor_settings.file_manager_path).value_or("");
 
+    job_actor_settings.output_structure_size = getSettings(json_settings_file, parent_key,
+        "output_structure_size", job_actor_settings.output_structure_size).value_or(250);
+
     job_actor_settings.output_csv = getSettings(json_settings_file, parent_key,
         "output_csv", job_actor_settings.output_csv).value_or(false);
 
@@ -78,7 +78,6 @@ void check_settings_from_json(Distributed_Settings &distributed_settings,
     std::cout << distributed_settings.num_hru_per_batch << "\n\n\n";
 
     std::cout << "************ SUMMA_ACTOR_SETTINGS ************\n";
-    std::cout << summa_actor_settings.output_structure_size << "\n";
     std::cout << summa_actor_settings.max_gru_per_job << "\n\n\n";
 
     std::cout << "************ FILE_ACCESS_ACTOR_SETTINGS ************\n";
@@ -86,6 +85,7 @@ void check_settings_from_json(Distributed_Settings &distributed_settings,
 
     std::cout << "************ JOB_ACTOR_SETTINGS ************\n";
     std::cout << job_actor_settings.file_manager_path << "\n";
+    std::cout << job_actor_settings.output_structure_size << "\n";
     std::cout << job_actor_settings.output_csv << "\n";
     std::cout << job_actor_settings.csv_path << "\n\n\n";
 
diff --git a/build/source/actors/gru_actor/gru_actor.cpp b/build/source/actors/gru_actor/gru_actor.cpp
index ef0e1ca..d9177c2 100644
--- a/build/source/actors/gru_actor/gru_actor.cpp
+++ b/build/source/actors/gru_actor/gru_actor.cpp
@@ -30,12 +30,12 @@ behavior gru_actor(stateful_actor<gru_state>* self,
 
         [=](init_hru) {
             for (int i = 0; i < self->state.num_hrus; i++) {
-                auto hru = self->spawn(hru_actor,
-                        self->state.ref_gru, self->state.indx_gru, 
-                        self->state.config_path, self->state.file_access_actor,
-                        self->state.output_struc_size,
-                        self);
-                self->state.hru_list.push_back(hru);
+                // auto hru = self->spawn(hru_actor,
+                //         self->state.ref_gru, self->state.indx_gru, 
+                //         self->state.config_path, self->state.file_access_actor,
+                //         self->state.output_struc_size,
+                //         self);
+                // self->state.hru_list.push_back(hru);
             }
         },
 
diff --git a/build/source/actors/hru_actor/hru_actor.cpp b/build/source/actors/hru_actor/hru_actor.cpp
index 0a62507..931357f 100644
--- a/build/source/actors/hru_actor/hru_actor.cpp
+++ b/build/source/actors/hru_actor/hru_actor.cpp
@@ -8,7 +8,7 @@
 namespace caf {
 
 behavior hru_actor(stateful_actor<hru_state>* self, int refGRU, int indxGRU,
-    std::string configPath, caf::actor file_access_actor, int outputStrucSize, caf::actor parent) {
+    HRU_Actor_Settings hru_actor_settings, caf::actor file_access_actor, int outputStrucSize, caf::actor parent) {
     
     // Timing Information
     self->state.hru_timing = TimingInfo();
@@ -39,20 +39,7 @@ behavior hru_actor(stateful_actor<hru_state>* self, int refGRU, int indxGRU,
     self->state.iFile = 1;
 
     // Get the settings for the HRU
-    // parseSettings(self, configPath);
-
-    self->state.printOutput = getSettings(configPath, "HRUActor", "printOutput", 
-		self->state.printOutput).value_or(true);
-    self->state.outputFrequency = getSettings(configPath, "HRUActor", "outputFrequency", 
-		self->state.outputFrequency).value_or(500);
-    
-    // We only want to print this once
-    if (indxGRU == 1) {
-        aout(self) << "\nSETTINGS FOR HRU_ACTOR\n";
-        aout(self) << "Print Output = " << self->state.printOutput << "\n";
-        aout(self) << "Print Output every " << self->state.outputFrequency << " timesteps\n\n";
-    }
-
+    self->state.hru_actor_settings = hru_actor_settings;
 
     Initialize_HRU(self);
     self->state.hru_timing.updateEndPoint("total_duration");
@@ -252,8 +239,8 @@ int Run_HRU(stateful_actor<hru_state>* self) {
     }
     self->state.hru_timing.updateEndPoint("forcing_duration");
 
-    if (self->state.printOutput && 
-        self->state.timestep % self->state.outputFrequency == 0) {
+    if (self->state.hru_actor_settings.print_output && 
+        self->state.timestep % self->state.hru_actor_settings.output_frequency == 0) {
         printOutput(self);
     }
     
diff --git a/build/source/actors/job_actor/job_actor.cpp b/build/source/actors/job_actor/job_actor.cpp
index 57c7dff..9c5ee98 100644
--- a/build/source/actors/job_actor/job_actor.cpp
+++ b/build/source/actors/job_actor/job_actor.cpp
@@ -20,49 +20,27 @@ namespace caf {
  * @return behavior 
  */
 behavior job_actor(stateful_actor<job_state>* self, int start_gru, int num_gru, 
-    std::string config_path, int output_struct_size, caf::actor parent) {
+    File_Access_Actor_Settings file_access_actor_settings, Job_Actor_Settings job_actor_settings, 
+    HRU_Actor_Settings hru_actor_settings, caf::actor parent) {
+
     // Timinig Information
     self->state.job_timing = TimingInfo();
     self->state.job_timing.addTimePoint("total_duration");
     self->state.job_timing.updateStartPoint("total_duration");
 
-
     // Set Job Variables
     self->state.start_gru = start_gru;
     self->state.num_gru = num_gru;
-    self->state.config_path = config_path;
     self->state.parent = parent;
-    self->state.output_struct_size = output_struct_size;
-
-    // Get All Settings
-    self->state.file_manager = getSettings(self->state.config_path, "JobActor", "FileManagerPath", 
-        self->state.file_manager).value_or("");
-    if(self->state.file_manager == "") {
-        aout(self) << "ERROR: Job_Actor - getSettings() - file_manager_path\n";
-        self->quit();
-        return {}; // Failure
-    }
-    self->state.output_csv = getSettings(self->state.config_path, "JobActor", "outputCSV",
-        self->state.output_csv).value_or(false);
-    if (self->state.output_csv) {
-        self->state.csv_path = getSettings(self->state.config_path, "JobActor", "csvPath",
-        self->state.csv_path).value_or("");
-        if (self->state.csv_path == ""){ // check if we found the value if not set output_csv to false
-            self->state.output_csv = false;
-        }
-    }
-    
-    // Print Settings
-    aout(self) << "\nSETTINGS FOR JOB_ACTOR\n" << 
-        "File Manager Path = " << self->state.file_manager << "\n" <<
-        "output_csv = " << self->state.output_csv << "\n";
-    if (self->state.output_csv) {
-        aout(self) << "csv_path = " << self->state.csv_path << "\n";
-    }
 
+    self->state.file_access_actor_settings = file_access_actor_settings;
+    self->state.job_actor_settings = job_actor_settings;
+    self->state.hru_actor_settings = hru_actor_settings;
+
+    
     // Initalize global variables
     int err = 0;
-    setTimesDirsAndFiles(self->state.file_manager.c_str(), &err);
+    setTimesDirsAndFiles(self->state.job_actor_settings.file_manager_path.c_str(), &err);
     if (err != 0) {
         aout(self) << "ERROR: Job_Actor - setTimesDirsAndFiles\n";
         return {}; // Failure
@@ -92,7 +70,7 @@ behavior job_actor(stateful_actor<job_state>* self, int start_gru, int num_gru,
 
     // Spawn the file_access_actor. This will return the number of forcing files we are working with
     self->state.file_access_actor = self->spawn(file_access_actor, self->state.start_gru, self->state.num_gru, 
-        self->state.output_struct_size, self->state.config_path, self);
+        self->state.job_actor_settings.output_structure_size, self->state.file_access_actor_settings, self);
 
 
     aout(self) << "Job Actor Initalized \n";
@@ -124,7 +102,7 @@ behavior job_actor(stateful_actor<job_state>* self, int start_gru, int num_gru,
             self->state.gru_list[indx_gru - 1]->doneRun(total_duration, init_duration, forcing_duration,
                 run_physics_duration, write_output_duration);
             
-            if (self->state.output_csv) {
+            if (self->state.job_actor_settings.output_csv) {
                 self->state.gru_list[indx_gru - 1]->writeSuccess(self->state.success_output_file);            
             }
             
@@ -161,12 +139,9 @@ behavior job_actor(stateful_actor<job_state>* self, int start_gru, int num_gru,
         },
 
         [=](done_file_access_actor_init) {
-            // Init GRU Actors and the Output Structure
+            // Init HRU Actors and the Output Structure
             self->send(self, init_hru_v);
-            // auto gru = self->spawn(gru_actor, 1, 1, 
-            //     self->state.config_path,
-            //     self->state.output_struct_size, self);
-            // self->send(gru, init_gru_v);
+
         },
 
         [=](done_init_gru) {
@@ -216,7 +191,7 @@ behavior job_actor(stateful_actor<job_state>* self, int start_gru, int num_gru,
                 aout(self) << "Error with the output file, will try creating it agian\n";
                 std::this_thread::sleep_for(std::chrono::seconds(5));
                 self->state.file_access_actor = self->spawn(file_access_actor, self->state.start_gru, self->state.num_gru, 
-                    self->state.output_struct_size, self->state.config_path, self);
+                    self->state.job_actor_settings.output_structure_size, self->state.file_access_actor_settings, self);
             } else {
                 aout(self) << "Letting Parent Know we are quitting\n";
                 self->send(self->state.parent, err_v);
@@ -225,16 +200,12 @@ behavior job_actor(stateful_actor<job_state>* self, int start_gru, int num_gru,
 
 
         }
-    // *******************************************************************************************
-    // ************************** END INTERFACE WITH FileAccessActor *****************************
-    // *******************************************************************************************
-
     };
 }
 
 void initCsvOutputFile(stateful_actor<job_state>* self) {
     std::string success = "Success"; // allows us to build the string
-    if (self->state.output_csv) {
+    if (self->state.job_actor_settings.output_csv) {
         std::ofstream file;
         self->state.success_output_file = self->state.csv_path += success += 
             std::to_string(self->state.start_gru) += ".csv";
@@ -257,10 +228,10 @@ void initalizeGRU(stateful_actor<job_state>* self) {
     for(int i = 0; i < self->state.num_gru; i++) {
         int start_gru = self->state.gru_list.size() + self->state.start_gru;
         int index_gru = self->state.gru_list.size() + 1; // Fortran reference starts at 1
-        auto gru = self->spawn(gru_actor, 
+        auto gru = self->spawn(hru_actor, 
                                start_gru, 
                                index_gru, 
-                               self->state.config_path, 
+                               self->state.hru_actor_settings,
                                self->state.file_access_actor, 
                                self->state.output_struct_size, 
                                self);
@@ -291,7 +262,7 @@ void restartFailures(stateful_actor<job_state>* self) {
             self->send(self->state.file_access_actor, reset_outputCounter_v, gru->getIndxGRU());
             gru->updateDt_init();
             auto newGRU = self->spawn(hru_actor, gru->getRefGRU(), gru->getIndxGRU(), 
-                self->state.config_path,self->state.file_access_actor, 
+                self->state.hru_actor_settings, self->state.file_access_actor, 
                 self->state.output_struct_size, self);
             gru->updateGRU(newGRU);
             gru->updateCurrentAttempt();
diff --git a/build/source/actors/main.cpp b/build/source/actors/main.cpp
index 57d13a8..02da6f2 100644
--- a/build/source/actors/main.cpp
+++ b/build/source/actors/main.cpp
@@ -97,45 +97,41 @@ void caf_main(actor_system& sys, const config& cfg) {
                                   job_actor_settings, 
                                   hru_actor_settings);
 
+
+    aout(self) << "Printing Settings For SUMMA Simulation\n";
     check_settings_from_json(distributed_settings,
         summa_actor_settings, file_access_actor_settings, job_actor_settings,
         hru_actor_settings);
 
+    if (distributed_settings.distributed_mode) {
+        // only command line arguments needed are config_file and server-mode
+        auto system = cfg.server_mode ? run_server : run_client;
+        system(sys, cfg);
 
-
-    // std::string key_1 = "DistributedSettings";
-    // std::string key_2 = "distributed-mode";
-    // bool distributed_mode = false;
-
-    // distributed_mode = getSettings(cfg.config_file, key_1, key_2, distributed_mode).value_or(false);
-    // if (distributed_mode) {
-    //     // only command line arguments needed are config_file and server-mode
-    //     auto system = cfg.server_mode ? run_server : run_client;
-    //     system(sys, cfg);
-
-    // } else {
-    //     // Configure command line arguments
-    //     if (cfg.startGRU == -1) {
-    //         aout(self) << "Starting GRU was not defined!! " << 
-    //             "startGRU is set with the \"-g\" option\n";
-    //         aout(self) << "EXAMPLE: ./summaMain -g 1 -n 10 -c location/of/config \n";
-    //         return;
-    //     }
-    //     if (cfg.countGRU == -1) {
-    //         aout(self) << "Number of GRUs was not defined!! " <<
-    //             "countGRU is set with the \"-n\" option\n";
-    //         aout(self) << "EXAMPLE: ./summaMain -g 1 -n 10 -c location/of/config \n";
-    //         return;
-    //     }
-    //     if (cfg.config_file == "") {
-    //         aout(self) << "File Manager was not defined!! " << 
-    //             "fileManger is set with the \"-c\" option\n";
-    //         aout(self) << "EXAMPLE: ./summaMain -g 1 -n 10 -c location/of/config \n";
-    //         return;
-    //     }
-
-    //     auto summa = sys.spawn(summa_actor, cfg.startGRU, cfg.countGRU, cfg.config_file, self);
-    // }
+    } else {
+        // Configure command line arguments
+        if (cfg.startGRU == -1) {
+            aout(self) << "Starting GRU was not defined!! " << 
+                "startGRU is set with the \"-g\" option\n";
+            aout(self) << "EXAMPLE: ./summaMain -g 1 -n 10 -c location/of/config \n";
+            return;
+        }
+        if (cfg.countGRU == -1) {
+            aout(self) << "Number of GRUs was not defined!! " <<
+                "countGRU is set with the \"-n\" option\n";
+            aout(self) << "EXAMPLE: ./summaMain -g 1 -n 10 -c location/of/config \n";
+            return;
+        }
+        if (cfg.config_file == "") {
+            aout(self) << "File Manager was not defined!! " << 
+                "fileManger is set with the \"-c\" option\n";
+            aout(self) << "EXAMPLE: ./summaMain -g 1 -n 10 -c location/of/config \n";
+            return;
+        }
+
+        auto summa = sys.spawn(summa_actor, cfg.startGRU, cfg.countGRU, summa_actor_settings, 
+            file_access_actor_settings, job_actor_settings, hru_actor_settings, self);
+    }
     
 }
 
diff --git a/build/source/actors/summa_actor/summa_actor.cpp b/build/source/actors/summa_actor/summa_actor.cpp
index a62e5fb..9f9d42f 100644
--- a/build/source/actors/summa_actor/summa_actor.cpp
+++ b/build/source/actors/summa_actor/summa_actor.cpp
@@ -14,7 +14,10 @@ using json = nlohmann::json;
 
 namespace caf {
 
-behavior summa_actor(stateful_actor<summa_actor_state>* self, int startGRU, int numGRU, std::string configPath, actor parent) {
+behavior summa_actor(stateful_actor<summa_actor_state>* self, int startGRU, int numGRU, 
+	Summa_Actor_Settings summa_actor_settings, File_Access_Actor_Settings file_access_actor_settings,
+    Job_Actor_Settings job_actor_settings, HRU_Actor_Settings hru_actor_settings, actor parent) {
+
  	// Set Timing Variables
 	self->state.summa_actor_timing = TimingInfo();
 	self->state.summa_actor_timing.addTimePoint("total_duration");
@@ -22,17 +25,12 @@ behavior summa_actor(stateful_actor<summa_actor_state>* self, int startGRU, int
 	// Set Variables
 	self->state.startGRU = startGRU;
 	self->state.numGRU = numGRU;
-	self->state.configPath = configPath;
 	self->state.parent = parent;
 
-	self->state.outputStrucSize = getSettings(self->state.configPath, "SummaActor", "OuputStructureSize", 
-		self->state.outputStrucSize).value_or(250);
-	self->state.maxGRUPerJob = getSettings(self->state.configPath, "SummaActor", "maxGRUPerJob",
-		self->state.maxGRUPerJob).value_or(100);
-
-	aout(self) << "SETTINGS FOR SUMMA_ACTOR\n";
-	aout(self) << "Output Structure Size = " << self->state.outputStrucSize << "\n";
-	aout(self) << "Max GRUs Per Job = " << self->state.maxGRUPerJob << "\n";
+	self->state.summa_actor_settings = summa_actor_settings;
+	self->state.file_access_actor_settings = file_access_actor_settings;
+	self->state.job_actor_settings = job_actor_settings;
+	self->state.hru_actor_settings = hru_actor_settings;
 
 	// Create the job_actor and start SUMMA
 	spawnJob(self);
@@ -96,7 +94,8 @@ void spawnJob(stateful_actor<summa_actor_state>* self) {
 		// spawn the job actor
 		aout(self) << "\n Starting Job with startGRU = " << self->state.startGRU << "\n";
 		self->state.currentJob = self->spawn(job_actor, self->state.startGRU, self->state.maxGRUPerJob, 
-			self->state.configPath, self->state.outputStrucSize, self);
+			self->state.file_access_actor_settings, self->state.job_actor_settings, 
+			self->state.hru_actor_settings, self);
 		
 		// Update GRU count
 		self->state.numGRU = self->state.numGRU - self->state.maxGRUPerJob;
@@ -105,7 +104,8 @@ void spawnJob(stateful_actor<summa_actor_state>* self) {
 	} else {
 
 		self->state.currentJob = self->spawn(job_actor, self->state.startGRU, self->state.numGRU, 
-			self->state.configPath, self->state.outputStrucSize, self);
+			self->state.file_access_actor_settings, self->state.job_actor_settings, 
+			self->state.hru_actor_settings, self);
 		self->state.numGRU = 0;
 	}
 }
diff --git a/build/source/actors/summa_actor/summa_client.cpp b/build/source/actors/summa_actor/summa_client.cpp
index 1a7b87c..f22ae2f 100644
--- a/build/source/actors/summa_actor/summa_client.cpp
+++ b/build/source/actors/summa_actor/summa_client.cpp
@@ -83,11 +83,11 @@ behavior running(stateful_actor<summa_client_state>* self, const actor& server_a
             self->state.batch_id = batch_id;
 
             
-            self->state.summa_actor_ref = self->spawn(summa_actor, 
-                start_hru, 
-                num_hru, 
-                self->state.config_path.value_or(config_path), 
-                self);
+            // self->state.summa_actor_ref = self->spawn(summa_actor, 
+            //     start_hru, 
+            //     num_hru, 
+            //     self->state.config_path.value_or(config_path), 
+            //     self);
             
         },
 
diff --git a/build/source/dshare/get_ixname.f90 b/build/source/dshare/get_ixname.f90
index a7866a4..88704da 100755
--- a/build/source/dshare/get_ixname.f90
+++ b/build/source/dshare/get_ixname.f90
@@ -561,7 +561,8 @@ contains
   case('scalarVolLatHt_fus'             ); get_ixdiag = iLookDIAG%scalarVolLatHt_fus               ! volumetric latent heat of fusion     (J m-3)
   ! number of function evaluations
   case('numFluxCalls'                   ); get_ixdiag = iLookDIAG%numFluxCalls                     ! number of flux calls (-)
-  ! get to here if cannot find the variable
+  case('wallClockTime'                  ); get_ixdiag = iLookDIAG%wallClockTime                    ! wall clock time (s)
+    ! get to here if cannot find the variable
   case default
    get_ixdiag = integerMissing
  end select
diff --git a/build/source/dshare/popMetadat.f90 b/build/source/dshare/popMetadat.f90
index 3ec9511..52f6f0f 100755
--- a/build/source/dshare/popMetadat.f90
+++ b/build/source/dshare/popMetadat.f90
@@ -423,7 +423,7 @@ subroutine popMetadat(err,message)
   diag_meta(iLookDIAG%scalarVolLatHt_fus)              = var_info('scalarVolLatHt_fus'             , 'volumetric latent heat of fusion'                                 , 'J m-3'           , get_ixVarType('scalarv'), iMissVec, iMissVec, .false.)
   ! number of function evaluations
   diag_meta(iLookDIAG%numFluxCalls)                    = var_info('numFluxCalls'                   , 'number of flux calls'                                             , '-'               , get_ixVarType('scalarv'), iMissVec, iMissVec, .false.)
-
+  diag_meta(iLookDIAG%wallClockTime)                   = var_info('wallClockTime'                  , 'wall clock time'                                                  , 's'               , get_ixVarType('scalarv'), iMissVec, iMissVec, .false.)
   ! -----
   ! * local model fluxes...
   ! -----------------------
diff --git a/build/source/dshare/var_lookup.f90 b/build/source/dshare/var_lookup.f90
index f165761..127ea51 100755
--- a/build/source/dshare/var_lookup.f90
+++ b/build/source/dshare/var_lookup.f90
@@ -439,6 +439,7 @@ MODULE var_lookup
   integer(i4b)    :: scalarVolLatHt_fus              = integerMissing ! volumetric latent heat of fusion     (J m-3)
   ! number of function evaluations
   integer(i4b)    :: numFluxCalls                    = integerMissing ! number of flux calls (-)
+  integer(i4b)    :: wallClockTime                   = integerMissing ! wall clock time (s)
  endtype iLook_diag
 
  ! ***********************************************************************************************************
@@ -825,7 +826,7 @@ MODULE var_lookup
                                                                          51, 52, 53, 54, 55, 56, 57, 58, 59, 60,&
                                                                          61, 62, 63, 64, 65, 66, 67, 68, 69, 70,&
                                                                          71, 72, 73, 74, 75, 76, 77, 78, 79, 80,&
-                                                                         81, 82, 83)
+                                                                         81, 82, 83, 84)
  ! named variables: model fluxes
  type(iLook_flux),    public,parameter :: iLookFLUX     =iLook_flux    (  1,  2,  3,  4,  5,  6,  7,  8,  9, 10,&
                                                                          11, 12, 13, 14, 15, 16, 17, 18, 19, 20,&
diff --git a/build/source/engine/read_attribute.f90 b/build/source/engine/read_attribute.f90
index cb5f3d5..40b5b95 100644
--- a/build/source/engine/read_attribute.f90
+++ b/build/source/engine/read_attribute.f90
@@ -54,44 +54,76 @@ subroutine read_dimension(numGRUs,numHRUs,startGRU,err) bind(C, name="readDimens
   integer(c_int),intent(out)             :: err                ! error code
   
   ! Local Variables
-  character(len=256)                   :: attrFile           ! name of attributed file
-  integer(i4b)                         :: fileGRU            ! number of GRUs in the input file
-  integer(i4b)                         :: fileHRU            ! number of HRUs in the input file
-  integer(i4b)                         :: iHRU               ! HRU couinting index
-  integer(i4b)                         :: iGRU               ! GRU loop index
-  integer(8),allocatable               :: gru_id(:),hru_id(:)! read gru/hru IDs in from attributes file
-  integer(8),allocatable               :: hru2gru_id(:)      ! read hru->gru mapping in from attributes file
-  integer(i4b),allocatable             :: hru_ix(:)          ! hru index for search
-  character(len=256)                   :: message            ! error message
+  character(len=256)                     :: attrFile           ! name of attributed file
+  integer(i4b)                           :: fileGRU            ! number of GRUs in the input file
+  integer(i4b)                           :: fileHRU            ! number of HRUs in the input file
+  integer(i4b)                           :: iHRU               ! HRU couinting index
+  integer(i4b)                           :: iGRU               ! GRU loop index
+  integer(8),allocatable                 :: gru_id(:),hru_id(:)! read gru/hru IDs in from attributes file
+  integer(8),allocatable                 :: hru2gru_id(:)      ! read hru->gru mapping in from attributes file
+  integer(i4b),allocatable               :: hru_ix(:)          ! hru index for search
+  character(len=256)                     :: message            ! error message
 
 
   ! define variables for NetCDF file operation
-  integer(i4b)                         :: ncID               ! NetCDF file ID
-  integer(i4b)                         :: varID              ! NetCDF variable ID
-  integer(i4b)                         :: gruDimId           ! variable id of GRU dimension from netcdf file
-  integer(i4b)                         :: hruDimId           ! variable id of HRU dimension from netcdf file
-  character(len=256)                   :: cmessage           ! error message for downwind routine
+  integer(i4b)                           :: ncID               ! NetCDF file ID
+  integer(i4b)                           :: varID              ! NetCDF variable ID
+  integer(i4b)                           :: gruDimId           ! variable id of GRU dimension from netcdf file
+  integer(i4b)                           :: hruDimId           ! variable id of HRU dimension from netcdf file
+  character(len=256)                     :: cmessage           ! error message for downwind routine
 
   err=0; message="read_dimension/"
   attrFile = trim(SETTINGS_PATH)//trim(LOCAL_ATTRIBUTES)
 
   ! open nc file
   call nc_file_open(trim(attrFile),nf90_noWrite,ncID,err,cmessage)
-  if(err/=0)then; message=trim(message)//trim(cmessage); return; end if
+  if(err/=0)then
+    message=trim(message)//trim(cmessage) 
+    print*, message
+    print*, attrFile
+    return
+  end if
   
   ! *********************************************************************************************
   ! read and set GRU dimensions
   ! **********************************************************************************************
   ! get gru dimension of whole file
-  err = nf90_inq_dimid(ncID,"gru",gruDimId);                   if(err/=nf90_noerr)then; message=trim(message)//'problem finding gru dimension/'//trim(nf90_strerror(err)); return; end if
-  err = nf90_inquire_dimension(ncID, gruDimId, len = fileGRU); if(err/=nf90_noerr)then; message=trim(message)//'problem reading gru dimension/'//trim(nf90_strerror(err)); return; end if
+  err = nf90_inq_dimid(ncID,"gru",gruDimId)
+  if(err/=nf90_noerr)then
+    message=trim(message)//'problem finding gru dimension/'//trim(nf90_strerror(err))
+    print*, message
+    return
+  end if
+
+  err = nf90_inquire_dimension(ncID, gruDimId, len = fileGRU)
+  if(err/=nf90_noerr)then; 
+    message=trim(message)//'problem reading gru dimension/'//trim(nf90_strerror(err))
+    print*, message
+    return
+  end if
 
   ! get hru dimension of whole file
-  err = nf90_inq_dimid(ncID,"hru",hruDimId);                   if(err/=nf90_noerr)then; message=trim(message)//'problem finding hru dimension/'//trim(nf90_strerror(err)); return; end if
-  err = nf90_inquire_dimension(ncID, hruDimId, len = fileHRU); if(err/=nf90_noerr)then; message=trim(message)//'problem reading hru dimension/'//trim(nf90_strerror(err)); return; end if
+  err = nf90_inq_dimid(ncID,"hru",hruDimId)
+  if(err/=nf90_noerr)then
+    message=trim(message)//'problem finding hru dimension/'//trim(nf90_strerror(err))
+    print*, message
+    return
+  end if
+
+  err = nf90_inquire_dimension(ncID, hruDimId, len = fileHRU)
+  if(err/=nf90_noerr)then
+    message=trim(message)//'problem reading hru dimension/'//trim(nf90_strerror(err))
+    print*, message
+    return
+  end if
 
   ! check dimensions
-  if(numGRUs > fileGRU .or. numGRUs < 1) then; err=20; message=trim(message)//"numGRUs is out of range"; return; end if
+  if(numGRUs > fileGRU .or. numGRUs < 1) then; 
+    err=20
+    message=trim(message)//"numGRUs is out of range"
+    print*, message
+    return
+  end if
 
   ! *********************************************************************************************
   ! read mapping vectors and populate mapping structures
@@ -101,16 +133,49 @@ subroutine read_dimension(numGRUs,numHRUs,startGRU,err) bind(C, name="readDimens
   allocate(hru_ix(fileHRU),hru_id(fileHRU),hru2gru_id(fileHRU))
 
   ! read gru_id from netcdf file
-  err = nf90_inq_varid(ncID,"gruId",varID);     if (err/=0) then; message=trim(message)//'problem finding gruId'; return; end if
-  err = nf90_get_var(ncID,varID,gru_id);        if (err/=0) then; message=trim(message)//'problem reading gruId'; return; end if
+  err = nf90_inq_varid(ncID,"gruId",varID)
+  if (err/=0) then
+    message=trim(message)//'problem finding gruId'
+    print*, message
+    return
+  end if
+
+  err = nf90_get_var(ncID,varID,gru_id)
+  if (err/=0) then
+    message=trim(message)//'problem reading gruId'
+    print*, message
+    return
+  end if
 
   ! read hru_id from netcdf file
-  err = nf90_inq_varid(ncID,"hruId",varID);     if (err/=0) then; message=trim(message)//'problem finding hruId'; return; end if
-  err = nf90_get_var(ncID,varID,hru_id);        if (err/=0) then; message=trim(message)//'problem reading hruId'; return; end if
+  err = nf90_inq_varid(ncID,"hruId",varID)
+  if (err/=0) then
+    message=trim(message)//'problem finding hruId'
+    print*, message
+    return
+  end if
+
+  err = nf90_get_var(ncID,varID,hru_id)
+  if (err/=0) then
+    message=trim(message)//'problem reading hruId'
+    print*, message
+    return
+  end if
 
   ! read hru2gru_id from netcdf file
-  err = nf90_inq_varid(ncID,"hru2gruId",varID); if (err/=0) then; message=trim(message)//'problem finding hru2gruId'; return; end if
-  err = nf90_get_var(ncID,varID,hru2gru_id);    if (err/=0) then; message=trim(message)//'problem reading hru2gruId'; return; end if
+  err = nf90_inq_varid(ncID,"hru2gruId",varID)
+  if (err/=0) then
+    message=trim(message)//'problem finding hru2gruId'
+    print*, message
+    return
+  end if
+
+  err = nf90_get_var(ncID,varID,hru2gru_id)
+  if (err/=0) then
+    message=trim(message)//'problem reading hru2gruId'
+    print*, message
+    return
+  end if
   
   ! array from 1 to total # of HRUs in attributes file
   hru_ix=arth(1,1,fileHRU)
-- 
GitLab