Skip to content

Commit bfb38c0

Browse files
committed
1. add output annotation labels in Input_Process::out()
1 parent 5a19174 commit bfb38c0

File tree

6 files changed

+32
-19
lines changed

6 files changed

+32
-19
lines changed

source/src_io/read_txt_input-general.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ namespace Read_Txt_Input
1616
{
1717
void Input_List::set_items_general()
1818
{
19+
this->output_labels.push_back("Parameters (1.General)");
20+
1921
{
2022
Input_Item item("nspin");
2123
item.default_1(1);

source/src_io/read_txt_input-pw.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ namespace Read_Txt_Input
1515
{
1616
void Input_List::set_items_pw()
1717
{
18+
this->output_labels.push_back("Parameters (2.Pw)");
19+
1820
{
1921
Input_Item item("ecutwfc");
2022
item.default_1(100.0,"eV");

source/src_io/read_txt_input_list.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ namespace Read_Txt_Input
1010
void Input_List::add_item(const Input_Item &input_item)
1111
{
1212
list.insert(make_pair(input_item.label, input_item));
13-
add_order.push_back(input_item.label);
13+
output_labels.push_back(input_item.label);
1414
}
1515

1616
/*

source/src_io/read_txt_input_list.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ namespace Read_Txt_Input
2525
//static void check_value_size(const Input_Item& input_item, const int size_low, const int size_up);
2626

2727
std::map<std::string, Input_Item> list;
28-
std::vector<std::string> add_order;
28+
std::vector<std::string> output_labels;
2929

3030
void set_items_general();
3131
void set_items_pw();

source/src_io/read_txt_input_process.cpp

Lines changed: 25 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -79,29 +79,37 @@ namespace Read_Txt_Input
7979
void Input_Process::out(const std::string &file_name) const
8080
{
8181
std::ofstream ofs(file_name);
82-
for(const std::string &label : input.add_order)
82+
for(const std::string &label : input.output_labels)
8383
{
84-
ofs<<label<<"\t";
85-
const Read_Txt_Input::Input_Item &item = input.list.at(label);
86-
for(size_t i=0; i<item.values.size(); ++i)
84+
const auto ptr = input.list.find(label);
85+
if(ptr==input.list.end())
86+
{
87+
ofs<<std::endl<<"# "<<label<<std::endl;
88+
}
89+
else
8790
{
88-
if(item.values_type[i]=="s")
89-
ofs<<item.values[i].gets()<<" ";
90-
else if(item.values_type[i]=="d")
91-
ofs<<std::to_string(item.values[i].getd())<<" ";
92-
else if(item.values_type[i]=="i")
93-
ofs<<std::to_string(item.values[i].geti())<<" ";
94-
else if(item.values_type[i]=="b")
91+
ofs<<label<<"\t";
92+
const Read_Txt_Input::Input_Item &item = ptr->second;
93+
for(size_t i=0; i<item.values.size(); ++i)
9594
{
96-
if(item.values[i].getb())
97-
ofs<<"true"<<" ";
95+
if(item.values_type[i]=="s")
96+
ofs<<item.values[i].gets()<<" ";
97+
else if(item.values_type[i]=="d")
98+
ofs<<std::to_string(item.values[i].getd())<<" ";
99+
else if(item.values_type[i]=="i")
100+
ofs<<std::to_string(item.values[i].geti())<<" ";
101+
else if(item.values_type[i]=="b")
102+
{
103+
if(item.values[i].getb())
104+
ofs<<"true"<<" ";
105+
else
106+
ofs<<"false"<<" ";
107+
}
98108
else
99-
ofs<<"false"<<" ";
109+
throw invalid_argument("Input_Process::out() value_type["+std::to_string(i)+"]="+item.values_type[i]);
100110
}
101-
else
102-
throw invalid_argument("Input_Process::out() value_type["+std::to_string(i)+"]="+item.values_type[i]);
111+
ofs<<"\t# "<<item.annotation<<std::endl;
103112
}
104-
ofs<<"\t# "<<item.annotation<<std::endl;
105113
}
106114
}
107115

source/src_io/read_txt_stru.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#include "read_txt_tools.h"
88

99
#include <algorithm>
10+
#include <stdexcept>
1011

1112
namespace Read_Txt_Stru
1213
{

0 commit comments

Comments
 (0)