-
Notifications
You must be signed in to change notification settings - Fork 2
/
cppread.cxx
117 lines (95 loc) · 4.05 KB
/
cppread.cxx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
#include <vector>
#include <iostream>
#include <stdexcept>
#include "Input.h"
#include "Data_block.h"
template <typename T>
void print_vector(const std::vector<T>& v, const std::string name)
{
std::cout << "vector "<< name << "(" << v.size() << "):" << std::endl;
for (const T& i : v)
std::cout << i << " ";
std::cout << std::endl;
}
int main(int argc, char *argv[])
{
try
{
if (argc != 2)
throw std::runtime_error("Illegal number or arguments");
std::string case_name = std::string(argv[1]);
std::string ini_file_name = case_name + ".ini";
std::string data_file_name = case_name + ".data";
Input input(ini_file_name);
// input.print_itemlist();
int itot = input.get_item<int>("grid", "itot", "");
double xsize = input.get_item<double>("grid", "xsize", "");
double zsize = input.get_item<double>("grid", "zsize", "");
std::string swthermo = input.get_item<std::string>("thermo", "swthermo", "");
std::vector<std::string> crosslist = input.get_list<std::string>("cross", "crosslist", "");
std::vector<double> xy = input.get_list<double>("cross", "xy", "");
std::vector<int> test_list = input.get_list<int>("test", "test", "", std::vector<int>({34, 45, 56}));
double rndamp = input.get_item<double>("fields", "rndamp", "");
double rndampb = input.get_item<double>("fields", "rndamp", "b");
double rndampx = input.get_item<double>("fields", "rndamp", "x");
float visc = input.get_item<float>("fields", "visc", "");
float beta = input.get_item<float>("buffer", "beta", "", 2.);
std::string swspatialorder = input.get_item<std::string>("grid", "swspatialorder", "");
bool adaptivestep = input.get_item<bool>("timeloop", "adaptivestep", "", true);
std::cout << "itot = " << itot << std::endl;
std::cout << "xsize = " << xsize << std::endl;
std::cout << "zsize = " << zsize << std::endl;
std::cout << "swthermo = " << swthermo << std::endl;
std::cout << "crosslist = ";
for (std::string &s : crosslist)
std::cout << "\"" << s << "\"" << " ";
std::cout << std::endl;
std::cout << "test_list = ";
for (const int i : test_list)
std::cout << i << " ";
std::cout << std::endl;
std::cout << "xy = ";
for (const double &i : xy)
std::cout << i << " ";
std::cout << std::endl;
std::cout << "rndamp = " << rndamp << std::endl;
std::cout << "rndamp[b] = " << rndampb << std::endl;
std::cout << "rndamp[x] = " << rndampx << std::endl;
std::cout << "visc = " << visc << std::endl;
std::cout << "beta = " << beta << std::endl;
std::cout << "swspatialorder = " << swspatialorder << std::endl;
std::cout << "adaptivestep = " << adaptivestep << std::endl;
// Read data block.
Data_block data_block(data_file_name);
// First read non-existent vector.
std::vector<double> zeros(4, -999);
data_block.get_vector(zeros, "zeros", 2, 0, 1);
print_vector(zeros, "zeros");
std::vector<std::string> a(4);
data_block.get_vector(a, "a", 4, 0, 0);
std::vector<double> b(4);
data_block.get_vector(b, "b", 1, 0, 0);
std::vector<int> c(6);
data_block.get_vector(c, "c", 4, 0, 1);
std::vector<double> d1(6);
data_block.get_vector(d1, "d", 4, 0, 1);
std::vector<double> d2(6);
data_block.get_vector(d2, "d", 2, 2, 1);
data_block.get_vector(d2, "d", 2, 0, 3);
print_vector(a, "a");
print_vector(b, "b");
print_vector(c, "c");
print_vector(d1, "d1");
print_vector(d2, "d2");
print_vector(d2, "d2");
std::vector<double> too_short(4);
data_block.get_vector(too_short, "d", 4, 0, 1);
print_vector(too_short, "too_short");
}
catch (std::exception &e)
{
std::cout << "EXCEPTION: " << e.what() << std::endl;
return 1;
}
return 0;
}