Skip to content

Commit b45aef5

Browse files
authored
Failure reading temporal values file path file 389 (SimVascular#390)
* Change file name. * Fix checking for the number of lines to be read from a Temporal_values_file_path file.
1 parent c578375 commit b45aef5

File tree

2 files changed

+12
-5
lines changed

2 files changed

+12
-5
lines changed

Code/Source/solver/l_elas.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ void construct_l_elas(ComMod& com_mod, const mshType& lM, const Array<double>& A
6464
{
6565
using namespace consts;
6666

67-
#define debug_construct_l_elas
67+
#define n_debug_construct_l_elas
6868
#ifdef debug_construct_l_elas
6969
DebugMsg dmsg(__func__, com_mod.cm.idcm());
7070
dmsg.banner();

Code/Source/solver/read_files.cpp

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2603,29 +2603,36 @@ void read_temporal_values(const std::string& file_name, bcType& lBc)
26032603
std::vector<std::vector<double>> temporal_values;
26042604
double time, value;
26052605
std::string line;
2606+
int line_number = 1;
2607+
int num_values_per_line = lBc.gt.d + 1;
26062608

26072609
while (std::getline(temporal_values_file, line)) {
26082610
line.erase(std::remove(line.begin(), line.end(), '\r'), line.end());
26092611
if (line == "") {
26102612
continue;
26112613
}
2612-
std::istringstream line_input(line);
2614+
// Remove leading and trailing spaces.
2615+
auto cleaned_line = std::regex_replace(line, std::regex("^ +| +$|( ) +"), "$1");
2616+
std::istringstream line_input(cleaned_line);
26132617
std::vector<double> values;
26142618

26152619
while (!line_input.eof()) {
26162620
line_input >> value;
26172621

26182622
if (line_input.fail()) {
2619-
throw std::runtime_error("1: Error reading values for the temporal values file '" + file_name + "' for line '" + line + "'.");
2623+
throw std::runtime_error("Error reading values for the temporal values file '" + file_name + "' for line " +
2624+
std::to_string(line_number) + ": '" + line + "'; value number " + std::to_string(values.size()+1) + " is not a double.");
26202625
}
26212626
values.push_back(value);
26222627
}
26232628

2624-
if (values.size() != 2) {
2625-
throw std::runtime_error("2: Error reading values for the temporal values file '" + file_name + "' for line '" + line + "'.");
2629+
if (values.size() != num_values_per_line) {
2630+
throw std::runtime_error("Error reading values for the temporal values file '" + file_name + "' for line " +
2631+
std::to_string(line_number) + ": '" + line + "'; expected " + std::to_string(num_values_per_line) + " values per line.");
26262632
}
26272633

26282634
temporal_values.push_back(values);
2635+
line_number += 1;
26292636
}
26302637

26312638
if (lBc.gt.lrmp) {

0 commit comments

Comments
 (0)