Skip to content

Commit

Permalink
Better handle weird netcdfiles with epochs with a hour but not m or s…
Browse files Browse the repository at this point in the history
…. Fix manual computation of dt
  • Loading branch information
Chrismarsh committed Dec 17, 2024
1 parent 7bca696 commit dc7db80
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions src/timeseries/netcdf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -296,17 +296,26 @@ void netcdf::open_GEM(const std::string &file)
//If it's 3, means there is a T b/w date and time, remove it.
std::string s = strs[2];
auto tpos = s.find("T");
bool removed_a_t = false; // keep track if we remove a T
if (tpos != std::string::npos)
{
s.replace(s.find("T"),1," ");
removed_a_t = true;
}

// midnight times can be reported without the 00:00 suffix. If we get this far and don't have : in the epoch
// then we need to add it

tpos = s.find(":");
if (tpos == std::string::npos)
{
s = s + " 00:00:00";
// if we removed a T above, BUT there is no :, it is probably something funny like
// 1950-01-01T01
// which is then 1950-01-01 01
if(removed_a_t)
s = s + ":00:00";
else
// midnight times can be reported without the 00:00 suffix. If we get this far and don't have : in the epoch
// then we need to add it
s = s + " 00:00:00";
}

try
Expand Down Expand Up @@ -357,7 +366,9 @@ void netcdf::open_GEM(const std::string &file)
{
CHM_THROW_EXCEPTION(forcing_error,"There needs to be at least 2 timesteps in order to determine model dt or the time coordinate needs to have the attribute 'delta_t:<step in seconds'.");
}
_delta_t = boost::posix_time::seconds(dt[1]-dt[0]);
// e.g., dt = [0 1 2] hours since epoch
// 1-0 * hour(1) -> total_seconds
_delta_t = boost::posix_time::seconds( (_epoch_offset_unit*(dt[1]-dt[0])).total_seconds());
}

//need to handle a start that is different from our epoch
Expand Down

0 comments on commit dc7db80

Please sign in to comment.