diff --git a/build/includes/file_access_actor/file_access_actor.hpp b/build/includes/file_access_actor/file_access_actor.hpp index 500ef4b566e042b61d26a250cfb769602cca8493..ccc0dd621e762f929cc4a4b5412dce396c97a9b8 100644 --- a/build/includes/file_access_actor/file_access_actor.hpp +++ b/build/includes/file_access_actor/file_access_actor.hpp @@ -108,6 +108,9 @@ void readInitConditions(stateful_actor<file_access_state>* self); void initalizeOutputHandles(stateful_actor<file_access_state>* self); +/* Setup and call the fortran routine that writes the output */ +void writeOutput(stateful_actor<file_access_state>* self, Output_Partition* partition); + void deallocateOutputHandles(stateful_actor<file_access_state>* self); } // end namespace \ No newline at end of file diff --git a/build/includes/file_access_actor/file_access_actor_subroutine_wrappers.hpp b/build/includes/file_access_actor/file_access_actor_subroutine_wrappers.hpp index d4240f270aea69cc23a19f623efe62215ce1f776..77f8e6c058fef7e3a5cd75255cd17a1f9e0ef94c 100644 --- a/build/includes/file_access_actor/file_access_actor_subroutine_wrappers.hpp +++ b/build/includes/file_access_actor/file_access_actor_subroutine_wrappers.hpp @@ -14,7 +14,7 @@ extern "C" { // OutputStructure and Output functions void initOutputStructure(void* handle_forcFileInfo, int* max_steps, int* numGRU, int* err); void deallocateOutputStructure(int* err); - void writeOutput(void* handle_ncid, int* num_steps, int* start_gru, int* max_gru, int* err); + void writeOutput_fortran(void* handle_ncid, int* num_steps, int* start_gru, int* max_gru, int* err); void initOutputTimeStep(int* num_gru, int* err); // Attributes Files- called inside initalizeFileAccessActor diff --git a/build/source/actors/file_access_actor/cpp_code/file_access_actor.cpp b/build/source/actors/file_access_actor/cpp_code/file_access_actor.cpp index 4c8f335ec9758dd9383030d9610b0b920d8d2eea..af86a92f0a35009d66df000e3b2744b9e3e08de0 100644 --- a/build/source/actors/file_access_actor/cpp_code/file_access_actor.cpp +++ b/build/source/actors/file_access_actor/cpp_code/file_access_actor.cpp @@ -30,7 +30,6 @@ behavior file_access_actor(stateful_actor<file_access_state>* self, int start_gr self->state.num_output_steps = self->state.file_access_actor_settings.num_timesteps_in_output_buffer; - initalizeFileAccessActor(self); // Set up the output container @@ -162,27 +161,8 @@ behavior file_access_actor(stateful_actor<file_access_state>* self, int start_gr output_partition->setGRUReadyToWrite(hru_actor); - if (output_partition->isReadyToWrite()) { - int num_timesteps_to_write = output_partition->getNumStoredTimesteps(); - int start_gru = output_partition->getStartGRUIndex(); - int max_gru = output_partition->getMaxGRUIndex(); - - writeOutput(self->state.handle_ncid, &num_timesteps_to_write, - &start_gru, &max_gru, &self->state.err); - - output_partition->updateTimeSteps(); - - int num_steps_before_next_write = output_partition->getNumStoredTimesteps(); - - std::vector<caf::actor> hrus_to_update = output_partition->getReadyToWriteList(); - - for (int i = 0; i < hrus_to_update.size(); i++) { - self->send(hrus_to_update[i], num_steps_before_write_v, num_steps_before_next_write); - self->send(hrus_to_update[i], run_hru_v); - } - - output_partition->resetReadyToWriteList(); + writeOutput(self, output_partition); } self->state.file_access_timing.updateEndPoint("write_duration"); @@ -193,35 +173,16 @@ behavior file_access_actor(stateful_actor<file_access_state>* self, int start_gr }, [=](run_failure, int local_gru_index) { + self->state.file_access_timing.updateStartPoint("write_duration"); + Output_Partition *output_partition = self->state.output_container->getOutputPartition(local_gru_index); output_partition->addFailedGRUIndex(local_gru_index); - int active_grus = output_partition->getNumActiveGRUs(); - - if (output_partition->isReadyToWrite() && active_grus > 0) { - int num_timesteps_to_write = output_partition->getNumStoredTimesteps(); - int start_gru = output_partition->getMaxGRUIndex(); - int max_gru = output_partition->getStartGRUIndex(); - - writeOutput(self->state.handle_ncid, &num_timesteps_to_write, - &start_gru, &max_gru, &self->state.err); - - output_partition->updateTimeSteps(); - - int num_steps_before_next_write = output_partition->getNumStoredTimesteps(); - - std::vector<caf::actor> hrus_to_update = output_partition->getReadyToWriteList(); - - for (int i = 0; i < hrus_to_update.size(); i++) { - self->send(hrus_to_update[i], num_steps_before_write_v, num_steps_before_next_write); - self->send(hrus_to_update[i], run_hru_v); - } - - output_partition->resetReadyToWriteList(); - + if (output_partition->isReadyToWrite()) { + writeOutput(self, output_partition); } - + self->state.file_access_timing.updateEndPoint("write_duration"); }, @@ -263,7 +224,6 @@ void initalizeFileAccessActor(stateful_actor<file_access_state>* self) { self->state.handle_forcing_file_info, &self->state.numFiles, &err); if (err != 0) { aout(self) << "Error: ffile_info_C - File_Access_Actor \n"; - std::string function = "ffile_info_C"; self->send(self->state.parent, file_access_error::unhandleable_error, self); self->quit(); return; @@ -273,7 +233,6 @@ void initalizeFileAccessActor(stateful_actor<file_access_state>* self) { mDecisions_C(&self->state.num_steps, &err); if (err != 0) { aout(self) << "ERROR: File_Access_Actor in mDecisions\n"; - std::string function = "mDecisions"; self->send(self->state.parent, file_access_error::unhandleable_error, self); self->quit(); return; @@ -453,6 +412,28 @@ void readParameters(stateful_actor<file_access_state>* self) { closeParamFile(&self->state.param_ncid, &err); } +void writeOutput(stateful_actor<file_access_state>* self, Output_Partition* partition) { + + int num_timesteps_to_write = partition->getNumStoredTimesteps(); + int start_gru = partition->getStartGRUIndex(); + int max_gru = partition->getMaxGRUIndex(); + + writeOutput_fortran(self->state.handle_ncid, &num_timesteps_to_write, + &start_gru, &max_gru, &self->state.err); + + partition->updateTimeSteps(); + + int num_steps_before_next_write = partition->getNumStoredTimesteps(); + + std::vector<caf::actor> hrus_to_update = partition->getReadyToWriteList(); + + for (int i = 0; i < hrus_to_update.size(); i++) { + self->send(hrus_to_update[i], num_steps_before_write_v, num_steps_before_next_write); + self->send(hrus_to_update[i], run_hru_v); + } + + partition->resetReadyToWriteList(); +} void readInitConditions(stateful_actor<file_access_state>* self) { int err; diff --git a/build/source/actors/file_access_actor/fortran_code/writeOutputFromOutputStructure.f90 b/build/source/actors/file_access_actor/fortran_code/writeOutputFromOutputStructure.f90 index 484e90eca739ea682d29a57b9939b9b7e0c1ca56..3e159d536b9c98bbd3cc8cd19deec82b6e82a657 100644 --- a/build/source/actors/file_access_actor/fortran_code/writeOutputFromOutputStructure.f90 +++ b/build/source/actors/file_access_actor/fortran_code/writeOutputFromOutputStructure.f90 @@ -75,7 +75,7 @@ USE var_lookup, only: maxvarStat ! number of statistics implicit none private -public::writeOutput +public::writeOutput_fortran public::writeParm public::writeData public::writeBasin @@ -89,7 +89,7 @@ contains ! ********************************************************************************************************** ! public subroutine writeParm: write model parameters ! ********************************************************************************************************** -subroutine writeOutput(handle_ncid, num_steps, start_gru, max_gru, err) bind(C, name="writeOutput") +subroutine writeOutput_fortran(handle_ncid, num_steps, start_gru, max_gru, err) bind(C, name="writeOutput_fortran") USE var_lookup,only:maxVarFreq ! # of available output frequencies USE globalData,only:structInfo USE globalData,only:bvarChild_map,forcChild_map,progChild_map,diagChild_map,fluxChild_map,indxChild_map ! index of the child data structure: stats bvar @@ -179,7 +179,7 @@ subroutine writeOutput(handle_ncid, num_steps, start_gru, max_gru, err) bind(C, outputTimeStep(start_gru)%dat(iFreq) = outputTimeStep(start_gru)%dat(iFreq) + outputTimeStepUpdate(iFreq) end do ! ifreq -end subroutine writeOutput +end subroutine writeOutput_fortran ! ********************************************************************************************************** @@ -380,9 +380,9 @@ subroutine writeScalar(ncid, outputTimestep, outputTimestepUpdate, nSteps, minGR character(*) ,intent(inout) :: message ! local variables - integer(i4b) :: gruCounter ! counter for the realVecs - integer(i4b) :: iStep ! counter for looping over nSteps - integer(i4b) :: stepCounter ! counter for the realVec + integer(i4b) :: gruCounter=0 ! counter for the realVecs + integer(i4b) :: iStep=1 ! counter for looping over nSteps + integer(i4b) :: stepCounter=0 ! counter for the realVec integer(i4b) :: iGRU ! output array real(rkind) :: realVec(numGRU, nSteps)! real vector for all HRUs in the run domain @@ -401,16 +401,19 @@ subroutine writeScalar(ncid, outputTimestep, outputTimestepUpdate, nSteps, minGR realVec(gruCounter, stepCounter) = stat%gru(iGRU)%hru(1)%var(map(iVar))%tim(iStep)%dat(iFreq) outputTimeStepUpdate(iFreq) = stepCounter end do ! iStep - end do ! iGRU - - err = nf90_put_var(ncid%var(iFreq),meta(iVar)%ncVarID(iFreq),realVec(1:gruCounter, 1:stepCounter),start=(/minGRU,outputTimestep(iFreq)/),count=(/numGRU,stepCounter/)) + end do ! iGRU + if (outputTimeStepUpdate(iFreq) /= stepCounter ) then print*, "ERROR Missmatch in Steps - stat doubleVec" print*, " outputTimeStepUpdate(iFreq) = ", outputTimeStepUpdate(iFreq) print*, " stepCounter = ", stepCounter print*, " iFreq = ", iFreq - + print*, " minGRU = ", minGRU + print*, " maxGRU = ", maxGRU + err = 20 return + + err = nf90_put_var(ncid%var(iFreq),meta(iVar)%ncVarID(iFreq),realVec(1:gruCounter, 1:stepCounter),start=(/minGRU,outputTimestep(iFreq)/),count=(/numGRU,stepCounter/)) endif class default; err=20; message=trim(message)//'stats must be scalarv and of type gru_hru_doubleVec'; return end select ! stat diff --git a/build/source/actors/file_access_actor/fortran_code/write_to_netcdf.f90 b/build/source/actors/file_access_actor/fortran_code/write_to_netcdf.f90 index 91bbaaf25a8b9d263c2a94320bb4d6d8e3473e6e..959fd3e4118870ae21da8fc4f08dc02278596abd 100644 --- a/build/source/actors/file_access_actor/fortran_code/write_to_netcdf.f90 +++ b/build/source/actors/file_access_actor/fortran_code/write_to_netcdf.f90 @@ -84,7 +84,7 @@ subroutine writeParamToNetCDF(handle_ncid, & end subroutine writeParamToNetCDF -subroutine writeDataToNetCDF(handle_ncid, & +subroutine writeDataToNetCDF(handle_ncid, & index_gru, & index_hru, & handle_finalize_stats, & @@ -199,11 +199,6 @@ subroutine writeDataToNetCDF(handle_ncid, & end do ! (looping through structures) end subroutine writeDataToNetCDF -! subroutine setOutputStructure(index_gru, index_timestep, -! handle_finalize_stats, handle_output_timestep, handle_output_timestep, ) - -! end subroutine setOutputStructure - subroutine writeBasinToNetCDF(handle_ncid, index_gru, handle_finalize_stats, & handle_output_timestep, handle_bvar_stat, handle_bvar_struct, err) bind(C, name="writeBasinToNetCDF") USE modelwrite_module,only:writeBasin diff --git a/build/source/dshare/data_types.f90 b/build/source/dshare/data_types.f90 index 1fc4a54e686f11b23b38259d8f6eebf0a64720da..4329a15a1ac27f9e0c9366ca5267116efc95912a 100755 --- a/build/source/dshare/data_types.f90 +++ b/build/source/dshare/data_types.f90 @@ -459,42 +459,6 @@ MODULE data_types type, public :: gru_hru_z_vLookup type(hru_z_vLookup),allocatable :: gru(:) ! gru(:)%hru(:)%z(:)%var(:)%lookup(:) endtype gru_hru_z_vLookup - ! type, public :: summa_output_type - - ! ! define the statistics structures - ! type(gru_hru_time_doubleVec),allocatable :: forcStat(:) ! x%gru(:)%hru(:)%var(:)%tim(:)%dat -- model forcing data - ! type(gru_hru_time_doubleVec),allocatable :: progStat(:) ! x%gru(:)%hru(:)%var(:)%tim(:)%dat -- model prognostic (state) variables - ! type(gru_hru_time_doubleVec),allocatable :: diagStat(:) ! x%gru(:)%hru(:)%var(:)%tim(:)%dat -- model diagnostic variables - ! type(gru_hru_time_doubleVec),allocatable :: fluxStat(:) ! x%gru(:)%hru(:)%var(:)%tim(:)%dat -- model fluxes - ! type(gru_hru_time_doubleVec),allocatable :: indxStat(:) ! x%gru(:)%hru(:)%var(:)%tim(:)%dat -- model indices - ! type(gru_hru_time_doubleVec),allocatable :: bvarStat(:) ! x%gru(:)%hru(:)%var(:)%tim(:)%dat -- basin-average variabl - - ! ! define the primary data structures (scalars) - ! type(gru_hru_time_int),allocatable :: timeStruct(:) ! x%gru(:)%hru(:)%var(:)%tim(:) -- model time data - ! type(gru_hru_time_double),allocatable :: forcStruct(:) ! x%gru(:)%hru(:)%var(:)%tim(:) -- model forcing data - ! type(gru_hru_double),allocatable :: attrStruct(:) ! x%gru(:)%hru(:)%var(:) -- local attributes for each HRU, DOES NOT CHANGE OVER TIMESTEPS - ! type(gru_hru_int),allocatable :: typeStruct(:) ! x%gru(:)%hru(:)%var(:)%tim(:) -- local classification of soil veg etc. for each HRU, DOES NOT CHANGE OVER TIMESTEPS - ! type(gru_hru_int8),allocatable :: idStruct(:) ! x%gru(:)%hru(:)%var(:) - - ! ! define the primary data structures (variable length vectors) - ! type(gru_hru_time_intVec),allocatable :: indxStruct(:) ! x%gru(:)%hru(:)%var(:)%tim(:)%dat -- model indices - ! type(gru_hru_doubleVec),allocatable :: mparStruct(:) ! x%gru(:)%hru(:)%var(:)%dat -- model parameters, DOES NOT CHANGE OVER TIMESTEPS TODO: MAYBE - ! type(gru_hru_time_doubleVec),allocatable :: progStruct(:) ! x%gru(:)%hru(:)%var(:)%tim(:)%dat -- model prognostic (state) variables - ! type(gru_hru_time_doubleVec),allocatable :: diagStruct(:) ! x%gru(:)%hru(:)%var(:)%tim(:)%dat -- model diagnostic variables - ! type(gru_hru_time_doubleVec),allocatable :: fluxStruct(:) ! x%gru(:)%hru(:)%var(:)%tim(:)%dat -- model fluxes - - ! ! define the basin-average structures - ! type(gru_double),allocatable :: bparStruct(:) ! x%gru(:)%var(:) -- basin-average parameters, DOES NOT CHANGE OVER TIMESTEPS - ! type(gru_hru_time_doubleVec),allocatable :: bvarStruct(:) ! x%gru(:)%hru(:)%var(:)%tim(:)%dat -- basin-average variables - - ! ! define the ancillary data structures - ! type(gru_hru_double),allocatable :: dparStruct(:) ! x%gru(:)%hru(:)%var(:) - - ! ! finalize stats structure - ! type(gru_hru_time_flagVec),allocatable :: finalizeStats(:) ! x%gru(:)%hru(:)%tim(:)%dat -- flags on when to write to file - - ! integer(i4b) :: nTimeSteps - ! end type summa_output_type END MODULE data_types