Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //need to include iomanip
- vector<vector<vector<vector<double> > > > read_path_rate(std::string fileName)
- {
- std::ifstream route_file;
- route_file.open(fileName.c_str(), ios::in);
- if (route_file.fail ())
- {
- NS_FATAL_ERROR ("File " << fileName.c_str () << " not found");
- }
- //initialize 4d vector: [row][col][numPaths][path]
- vector<double> emptyRoute(1,0);
- vector<vector<double> > numPaths(4, emptyRoute); //assume 4 different paths
- vector<vector<vector<double> > > init2D(66,numPaths);
- vector<vector<vector<vector<double> > > > array(66,init2D);
- while(!route_file.eof())
- {
- string line;
- getline(route_file, line);
- istringstream iss(line);
- int row, col, numPaths;
- iss >> row >> col >> numPaths;
- /*collect all the routes, insert into 4th dimension for corresponding
- row/col/pathNum
- //numPaths should always be 4 according to current iridiumnet.log
- */
- for(int i = 0; i < numPaths; i++)
- {
- vector<double> route;
- string routeLine;
- getline(route_file, routeLine);
- istringstream issRoutes(routeLine);
- double element;
- while (issRoutes >> element)
- {
- route.push_back (element);
- }
- array[row][col][i] = route;
- }
- }
- std::cout<<"##############Here are the paths/rates:################"<<std::endl;
- cout << setprecision(15);
- for(size_t i = 0; i < array.size(); i++)
- {
- for(size_t j = 0; j < init2D.size(); j++)
- {
- for(size_t k = 0; k < array[i][j].size(); k++)
- {
- //ignore routes that are empty/unused
- if(array[i][j][k] != emptyRoute)
- {
- cout << "Path #" << k+1 << " for " << i << "->" << j << ": ";
- vector<double> route = array[i][j][k];
- for(size_t l = 0; l < route.size(); l++)
- {
- cout << route[l] << " ";
- }
- cout << endl;
- }
- }
- }
- }
- std::cout<<"##############End of paths/rates:################"<<std::endl;
- route_file.close ();
- return array;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement