Skip to content

Commit 7ef0528

Browse files
authored
Fix: fix the stoi failure for output flag out_chg (#5526)
We still encourage user to use `1` or `True`, although there are more has been supported... secretely...
1 parent f041019 commit 7ef0528

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

source/module_io/read_input_item_output.cpp

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -40,18 +40,18 @@ void ReadInput::item_output()
4040
item.annotation = "> 0 output charge density for selected electron steps"
4141
", second parameter controls the precision, default is 3.";
4242
item.read_value = [](const Input_Item& item, Parameter& para) {
43-
size_t count = item.get_size();
44-
std::vector<int> out_chg(count); // create a placeholder vector
45-
std::transform(item.str_values.begin(), item.str_values.end(), out_chg.begin(), [](std::string s) {
46-
return std::stoi(s);
47-
});
48-
// assign non-negative values to para.input.out_chg
49-
std::copy(out_chg.begin(), out_chg.end(), para.input.out_chg.begin());
43+
const size_t count = item.get_size();
44+
if (count != 1 && count != 2)
45+
{
46+
ModuleBase::WARNING_QUIT("ReadInput", "out_chg should have 1 or 2 values");
47+
}
48+
para.input.out_chg[0] = assume_as_boolean(item.str_values[0]);
49+
para.input.out_chg[1] = (count == 2) ? std::stoi(item.str_values[1]) : 3;
5050
};
5151
item.reset_value = [](const Input_Item& item, Parameter& para) {
5252
para.input.out_chg[0] = (para.input.calculation == "get_wf" || para.input.calculation == "get_pchg")
53-
? 1
54-
: para.input.out_chg[0];
53+
? 1
54+
: para.input.out_chg[0];
5555
};
5656
sync_intvec(input.out_chg, 2, 0);
5757
this->add_item(item);

0 commit comments

Comments
 (0)