Skip to content

Commit

Permalink
Fix consistent delta_t time check
Browse files Browse the repository at this point in the history
  • Loading branch information
Chrismarsh committed Dec 16, 2024
1 parent 792ad74 commit 7bca696
Showing 1 changed file with 13 additions and 13 deletions.
26 changes: 13 additions & 13 deletions src/timeseries/netcdf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -371,28 +371,28 @@ void netcdf::open_GEM(const std::string &file)

// go through all the timesteps and ensure a consistent timesteping
// best to spend the time up front for this check than to get 90% into a sim and have it die
size_t pred_timestep = dt[0];
for(size_t i=1; // intentional
i < _datetime_length; i++)
if(_datetime_length > 2)
{
pred_timestep = pred_timestep + _delta_t.total_seconds();
auto timestep_dtdiff = dt[1] - dt[0];

if( dt[i] != pred_timestep)
for(size_t i=2; // intentional
i < _datetime_length; i++)
{
std::stringstream expected;
expected << _epoch + _epoch_offset_unit * pred_timestep;
std::stringstream got;
got << _epoch + _epoch_offset_unit * dt[i];
auto cur_diff = dt[i] - dt[i-1];

if( cur_diff != timestep_dtdiff)
{

CHM_THROW_EXCEPTION(forcing_error, "The timesteps in the netcdf file are not constant. At timestep " +
std::to_string(i) + " offset " + std::to_string(pred_timestep) + " was expected but found " +
std::to_string(dt[i]) + ".\n Expected=" + expected.str() + "\n Got=" + got .str()
);
CHM_THROW_EXCEPTION(forcing_error, "The timesteps in the netcdf file are not constant. At timestep " +
std::to_string(i) + " dt " + std::to_string(timestep_dtdiff) + " was expected but found " +
std::to_string(cur_diff)
);

}
}
}


SPDLOG_DEBUG("NetCDF epoch is {}", boost::posix_time::to_simple_string(_epoch));
SPDLOG_DEBUG("NetCDF start is {}", boost::posix_time::to_simple_string(_start));
SPDLOG_DEBUG("NetCDF end is {}",boost::posix_time::to_simple_string(_end));
Expand Down

0 comments on commit 7bca696

Please sign in to comment.