From c6fe28d5674d12928dc26eb03efd9d97725816ea Mon Sep 17 00:00:00 2001
From: KyleKlenk <kyle.c.klenk@gmail.com>
Date: Fri, 1 Apr 2022 13:37:14 -0600
Subject: [PATCH] moved sending of message for writing in HRU to start of while
 loop in run_hru message

---
 build/source/actors/HRUActor.h | 25 +++++++++++++------------
 1 file changed, 13 insertions(+), 12 deletions(-)

diff --git a/build/source/actors/HRUActor.h b/build/source/actors/HRUActor.h
index 30474ad..9ef3e0a 100644
--- a/build/source/actors/HRUActor.h
+++ b/build/source/actors/HRUActor.h
@@ -105,6 +105,17 @@ behavior hru_actor(stateful_actor<hru_state>* self, int refGRU, int indxGRU,
 
             while( err == 0 ) {
 
+                // Check if we need to write - call is here because when we ask for more forcing we may need to write
+                if (self->state.outputStep >= self->state.outputStrucSize) {
+                    if(debug)
+                        aout(self) << "Sending Write, outputStep = " << self->state.outputStep << std::endl;
+
+                    self->send(self->state.file_access_actor, write_output_v, 
+                        self->state.indxGRU, self->state.indxHRU, self->state.outputStep, self);
+                    self->state.outputStep = 1;
+                    break;
+                }
+
                 err = Run_HRU(self);
                 if (err != 0) {
                     // RUN FAILURE!!! Notify Parent
@@ -131,21 +142,11 @@ behavior hru_actor(stateful_actor<hru_state>* self, int refGRU, int indxGRU,
 
                 // check if we need more forcing information
                 if (self->state.forcingStep > self->state.stepsInCurrentFFile) {
-                    // aout(self) << "Asking for more forcing data" << std::endl;
+                    if (debug)
+                        aout(self) << "Asking for more forcing data, outputStep =" << self->state.outputStep << std::endl;
                     self->send(self->state.file_access_actor, access_forcing_v, self->state.iFile + 1, self);
                     break;
                 }
-                // check if we need to write our output
-                if (self->state.outputStep >= self->state.outputStrucSize) {
-                    if(debug)
-                        aout(self) << "Sending Write, outputStep = " << self->state.outputStep << std::endl;
-
-                    self->send(self->state.file_access_actor, write_output_v, 
-                        self->state.indxGRU, self->state.indxHRU, self->state.outputStep, self);
-                    self->state.outputStep = 1;
-                    break;
-                }
-               
             }
      
             self->state.end = std::chrono::high_resolution_clock::now();
-- 
GitLab