Advertisement
Guest User

Untitled

a guest
Apr 25th, 2018
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.57 KB | None | 0 0
  1.  
  2. //Reader + Parser
  3. veCo readFile(string str) {
  4.     veCo res;
  5.     ifstream myfile;
  6.     myfile.open(str);
  7.     int i = 0;
  8.     try
  9.     {
  10.         string line, cell;
  11.         myfile.is_open();
  12.         // read each line into line
  13.         while (getline(myfile, line))
  14.         {
  15.             //cout << "Line contains: " << line << endl;
  16.             // copy the line into lineSteam, so we can store them into a string delimited
  17.             stringstream  lineStream(line);
  18.             if ((line.find("+") == string::npos) && (line.find("+") == string::npos))
  19.             {
  20.                 getline(lineStream, cell, ' ');
  21.                 complex<double> el(stod(cell), 0.0);
  22.                 res.push_back(el);
  23.             }
  24.             else
  25.             {
  26.                 vector<string> tmp;
  27.  
  28.                 while (getline(lineStream, cell, ' '))  tmp.push_back(cell);
  29.  
  30.                 complex<double> el(stod(tmp[0]), stod(tmp[2]));
  31.                 res.push_back(el);
  32.             }
  33.         }
  34.     }
  35.     catch (ifstream::failure e) {
  36.         cout << "Exception opening/reading file: " << e.what();
  37.     }
  38.     //to Check myself
  39.     //coShow(res);
  40.     return res;
  41. }
  42. void coShow(veCo x) {
  43.     for (size_t i = 0; i < x.size(); i++)
  44.     {
  45.         cout << x[i].real() << " " << x[i].imag() << "_i" << endl;
  46.  
  47.         //default Way:
  48.         //cout << x[i] << endl;
  49.     }
  50. }
  51.  
  52.  
  53.  
  54. void task2() {
  55.     string str = "../../../1_input.txt";
  56.     veCo x = readFile(str);
  57.     coShow(x);
  58.     int N = x.size();
  59.     comp *arr = &x[0];
  60.     veCo v=fft(arr, N);
  61.     cout << "_______FFT________" << endl;
  62.     coShow(v);
  63.  
  64.     v=ifft(arr, N);
  65.  
  66.     cout << "_______IFFT________" << endl;
  67.     coShow(v);
  68.  
  69.  
  70. }
  71.  
  72.  
  73.  
  74.  
  75. int main()
  76. {
  77.     /*const int N = 150;
  78.     double * x = new double[N];
  79.     string str = "../../../1_input.txt";
  80.     readFile(str);
  81.     */
  82.  
  83.  
  84.     //task1();
  85.     task2();
  86.  
  87.  
  88.     return 0;
  89. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement