Skip to content

Commit

Permalink
Ensure face-station relation is rebuilt if a multipart nc file is loa…
Browse files Browse the repository at this point in the history
…ded which invalidates this relationship
  • Loading branch information
Chrismarsh committed Dec 10, 2024
1 parent abe1885 commit 9a72279
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/core.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2425,7 +2425,7 @@ void core::run()
else
{
// loading a new netcdf will invalidate all our stations, so we need to rebuild the list of stations
if(_metdata->is_multipart_nc())
if(_metdata->is_multipart_nc() && _metdata->nc_just_loaded())
populate_face_station_lists();
}

Expand Down
11 changes: 11 additions & 0 deletions src/metdata.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ metdata::metdata(std::string mesh_proj4)
_mesh_proj4 = mesh_proj4;
is_first_timestep = true;
_is_multipart_nc = false;
_just_loaded_nc = false;

OGRSpatialReference srs;
srs.importFromProj4(_mesh_proj4.c_str());
Expand Down Expand Up @@ -96,6 +97,7 @@ void metdata::load_from_netcdf(const std::string& path, const triangulation::bou
SPDLOG_DEBUG("Found NetCDF file {}", path);

_use_netcdf = true;
_just_loaded_nc = true;
_nc = std::make_unique<netcdf>();

// only do this once, don't repeat if we have them cached
Expand Down Expand Up @@ -690,9 +692,18 @@ bool metdata::next_ascii()

return true;
}

bool metdata::nc_just_loaded()
{
return _just_loaded_nc;
}

bool metdata::next_nc()
{

// assume we won't have to load a netcdf
_just_loaded_nc = false;

//_current_ts is already ++ from the next() call
if(!_is_multipart_nc && (_current_ts > _end_time))
{
Expand Down
10 changes: 10 additions & 0 deletions src/metdata.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,14 @@ class metdata
std::string start_time_str();
std::string end_time_str();

/**
* Returns true if a netcdf was just loaded.
* Calling next() without having to load a multipart will cause this to begin to return false
**/
bool nc_just_loaded();

///
/// @return
bool is_multipart_nc();

/**
Expand Down Expand Up @@ -265,6 +273,7 @@ class metdata
// Mapped w/ stations ID -> metdata
std::map<std::string, std::unique_ptr<ascii_data>> _ascii_stations;


// -----------------------------------

// This is a different approach than how stations used to work
Expand All @@ -282,6 +291,7 @@ class metdata
size_t _n_timesteps;

bool _is_multipart_nc;
bool _just_loaded_nc; // if a nc file was just loaded

// These two are the start and end time of the simulation. If we have loaded from a single file
// these will be equal to file_*. However, if we are loading from a multi-part file then the file_*
Expand Down

0 comments on commit 9a72279

Please sign in to comment.