-
Notifications
You must be signed in to change notification settings - Fork 1
/
load_data.cpp
59 lines (50 loc) · 1.49 KB
/
load_data.cpp
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
#include <load_data.h>
void load_data(int dim1, int dim2, int dim3, std::string path, std::vector<std::vector<std::vector<Complex>>> &threeDArray) {
// 打开CSV文件
std::ifstream file(path);
if (!file.is_open()) {
std::cerr << "无法打开文件" << std::endl;
return; //返回空容器
}
std::string line;
std::getline(file, line);
file.close();
std::stringstream ss(line);
std::string cell;
int op = 0;
int i = 0, j = 0, k = 0;
while (std::getline(ss, cell, ',')) {
float real_part, imag_part;
char plus_sign, imaginary_unit;
op++;
if (op % 1000000 == 0)
{
std::cout << op << std::endl;
}
std::stringstream cell_ss(cell);
cell_ss >> real_part >> plus_sign >> imag_part >> imaginary_unit;
if (plus_sign == '+' && imaginary_unit == 'i') {
threeDArray[i][j][k] = Complex(real_part, imag_part); //此处为-代表共轭采集
}
else if (plus_sign == '-' && imaginary_unit == 'i')
{
threeDArray[i][j][k] = Complex(real_part, -imag_part);
}
else {
std::cerr << "Error: Invalid complex number format in CSV file" << std::endl;
return; //返回空容器
}
k++;
if (k == dim3) {
k = 0;
j++;
if (j == dim2) {
j = 0;
i++;
if (i==dim1)
return;
}
}
}
return;
}