Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- #include <stdio.h>
- #include <stdlib.h>
- #include <vector>
- #include <cmath>
- void merge(int N, std::string appr, std::string title) {
- double a;
- std::string fin_dir = appr + "-totale";
- std::string init_dir = appr + "-risultati-";
- std::string num, dir;
- std::ifstream ri;
- std::ofstream out(fin_dir+title);
- std::vector<std::vector<double>> v_ri;
- for(int j=1; j<=N; j++){
- num = std::to_string(j);
- dir = init_dir+num+title;
- ri.open(dir);
- std::vector<double> v;
- while(ri >> a){
- v.push_back(a);
- }
- v_ri.push_back(v);
- ri.close();
- }
- a=0;
- std::vector<double> weight;
- for(int k=2; k<v_ri[0].size(); k=k+4){
- for(int j=0; j<v_ri.size(); j++){
- a = a+v_ri[j][k]/double(N);
- }
- weight.push_back(a);
- a=0;
- }
- a=0;
- std::vector<double> err;
- for(int k=3; k<v_ri[0].size(); k=k+4){
- for(int j=0; j<v_ri.size(); j++){
- a = a+pow(v_ri[j][k], 2)/double(N);
- }
- a = sqrt(a);
- err.push_back(a);
- a=0;
- }
- int cont = 0;
- for(int i=0; i<v_ri[0].size(); i=i+4){
- out << std::scientific << v_ri[0][i] << " " << v_ri[0][i+1] << " ";
- out << std::scientific << weight[cont] << " " << err[cont] << std::endl;
- cont++;
- }
- }
- int main(){
- //merge(numeber_of_directories, "exc"/"def", title)
- //title: /namefile.dat
- int N=3;
- merge(N, "exc", "/ris.dat");
- merge(N, "def", "/ris.dat");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement