Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Reader + Parser
- veCo readFile(string str) {
- veCo res;
- ifstream myfile;
- myfile.open(str);
- int i = 0;
- try
- {
- string line, cell;
- myfile.is_open();
- // read each line into line
- while (getline(myfile, line))
- {
- //cout << "Line contains: " << line << endl;
- // copy the line into lineSteam, so we can store them into a string delimited
- stringstream lineStream(line);
- if ((line.find("+") == string::npos) && (line.find("+") == string::npos))
- {
- getline(lineStream, cell, ' ');
- complex<double> el(stod(cell), 0.0);
- res.push_back(el);
- }
- else
- {
- vector<string> tmp;
- while (getline(lineStream, cell, ' ')) tmp.push_back(cell);
- complex<double> el(stod(tmp[0]), stod(tmp[2]));
- res.push_back(el);
- }
- }
- }
- catch (ifstream::failure e) {
- cout << "Exception opening/reading file: " << e.what();
- }
- //to Check myself
- //coShow(res);
- return res;
- }
- void coShow(veCo x) {
- for (size_t i = 0; i < x.size(); i++)
- {
- cout << x[i].real() << " " << x[i].imag() << "_i" << endl;
- //default Way:
- //cout << x[i] << endl;
- }
- }
- void task2() {
- string str = "../../../1_input.txt";
- veCo x = readFile(str);
- coShow(x);
- int N = x.size();
- comp *arr = &x[0];
- veCo v=fft(arr, N);
- cout << "_______FFT________" << endl;
- coShow(v);
- v=ifft(arr, N);
- cout << "_______IFFT________" << endl;
- coShow(v);
- }
- int main()
- {
- /*const int N = 150;
- double * x = new double[N];
- string str = "../../../1_input.txt";
- readFile(str);
- */
- //task1();
- task2();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement