Advertisement
Guest User

Untitled

a guest
Jun 26th, 2019
146
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.41 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3. #include <stdio.h>
  4. #include <stdlib.h>
  5. #include <vector>
  6. #include <cmath>
  7.  
  8. void merge(int N, std::string appr, std::string title) {
  9. double a;
  10. std::string fin_dir = appr + "-totale";
  11. std::string init_dir = appr + "-risultati-";
  12. std::string num, dir;
  13. std::ifstream ri;
  14. std::ofstream out(fin_dir+title);
  15. std::vector<std::vector<double>> v_ri;
  16.  
  17. for(int j=1; j<=N; j++){
  18. num = std::to_string(j);
  19. dir = init_dir+num+title;
  20. ri.open(dir);
  21. std::vector<double> v;
  22.  
  23. while(ri >> a){
  24. v.push_back(a);
  25. }
  26.  
  27. v_ri.push_back(v);
  28. ri.close();
  29. }
  30.  
  31. a=0;
  32. std::vector<double> weight;
  33. for(int k=2; k<v_ri[0].size(); k=k+4){
  34. for(int j=0; j<v_ri.size(); j++){
  35. a = a+v_ri[j][k]/double(N);
  36. }
  37. weight.push_back(a);
  38. a=0;
  39. }
  40.  
  41. a=0;
  42. std::vector<double> err;
  43. for(int k=3; k<v_ri[0].size(); k=k+4){
  44. for(int j=0; j<v_ri.size(); j++){
  45. a = a+pow(v_ri[j][k], 2)/double(N);
  46. }
  47. a = sqrt(a);
  48. err.push_back(a);
  49. a=0;
  50. }
  51.  
  52. int cont = 0;
  53. for(int i=0; i<v_ri[0].size(); i=i+4){
  54. out << std::scientific << v_ri[0][i] << " " << v_ri[0][i+1] << " ";
  55. out << std::scientific << weight[cont] << " " << err[cont] << std::endl;
  56. cont++;
  57. }
  58. }
  59.  
  60. int main(){
  61. //merge(numeber_of_directories, "exc"/"def", title)
  62. //title: /namefile.dat
  63.  
  64. int N=3;
  65.  
  66. merge(N, "exc", "/ris.dat");
  67. merge(N, "def", "/ris.dat");
  68.  
  69. return 0;
  70. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement