From 2b0dfb5f2e1272a7302a6846a95ffd9fac8b5175 Mon Sep 17 00:00:00 2001
From: Christopher Baker <csb048@usask.ca>
Date: Tue, 30 Apr 2024 15:31:54 -0600
Subject: [PATCH] added rollback so indecies of summa_struct can be rewriten
 when partition is full (not 100% stable)

---
 build/source/file_access_actor/file_access_actor.cpp | 4 ++--
 build/source/hru_actor/hru_actor.cpp                 | 8 +++++---
 2 files changed, 7 insertions(+), 5 deletions(-)

diff --git a/build/source/file_access_actor/file_access_actor.cpp b/build/source/file_access_actor/file_access_actor.cpp
index 6b3abf3..0b2eded 100644
--- a/build/source/file_access_actor/file_access_actor.cpp
+++ b/build/source/file_access_actor/file_access_actor.cpp
@@ -178,7 +178,7 @@ behavior file_access_actor(stateful_actor<file_access_state>* self,
       self->state.file_access_timing.updateEndPoint("write_duration");
     },
 
-    [=] (write_restart, int gru, int gru_timestep, int gru_checkpoint, int year, int month, int day, int hour){
+    [=] (write_restart, int gru, int gru_timestep, int gru_checkpoint, int output_stucture_index, int year, int month, int day, int hour){
     // update hru progress vecs 
     int gru_index = abs(self->state.start_gru - gru); 
     self->state.hru_timesteps[gru_index] = gru_timestep;
@@ -191,7 +191,7 @@ behavior file_access_actor(stateful_actor<file_access_state>* self,
     // if the slowest hru is past the ith checkpoint (current threshold)            
     if ( slowest_checkpoint >= (self->state.completed_checkpoints)){// temp for dubuging
         Output_Partition *output_partition = self->state.output_container->getOutputPartition(gru-1);
-        writeRestart(self, output_partition, self->state.start_gru, self->state.hru_timesteps.size(), gru_checkpoint,
+        writeRestart(self, output_partition, self->state.start_gru, self->state.hru_timesteps.size(), output_stucture_index,
                      year, month, day, hour);
         // update checkpint counter
         self->state.completed_checkpoints++;
diff --git a/build/source/hru_actor/hru_actor.cpp b/build/source/hru_actor/hru_actor.cpp
index 56207af..061e313 100644
--- a/build/source/hru_actor/hru_actor.cpp
+++ b/build/source/hru_actor/hru_actor.cpp
@@ -442,9 +442,10 @@ int Run_HRU(stateful_actor<hru_state>* self) {
     // send an update to the FAA
     if (isCheckpoint(self)){
         self->state.checkpoint++;
+
         hru_writeRestart(&self->state.indxHRU, 
                         &self->state.indxGRU,
-                        &self->state.checkpoint,
+                        &self->state.output_structure_step_index,
                         &self->state.output_structure_step_index, //unused
                         self->state.hru_data,
                         &self->state.err);
@@ -454,6 +455,7 @@ int Run_HRU(stateful_actor<hru_state>* self) {
             self->state.refGRU,
             self->state.timestep,
             self->state.checkpoint,
+            self->state.output_structure_step_index,
             self->state.currentDate.y,
             self->state.currentDate.m,
             self->state.currentDate.d,
@@ -471,8 +473,8 @@ bool isCheckpoint(stateful_actor<hru_state>* self){
     switch(self->state.restartFrequency){
         case 0: // restart not enabled
             break;
-        case 1: // hourly, not supported, would need to extract minute info from hru_data
-            break;
+        case 1: // every timestep
+            return true;
         case 2: // daily
             if (self->state.startDate.h == self->state.currentDate.h){
                 return true;
-- 
GitLab