Advertisement
Guest User

multipath input

a guest
Aug 4th, 2015
177
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.22 KB | None | 0 0
  1.  
  2. //need to include iomanip
  3. vector<vector<vector<vector<double> > > > read_path_rate(std::string fileName)
  4. {
  5. std::ifstream route_file;
  6. route_file.open(fileName.c_str(), ios::in);
  7. if (route_file.fail ())
  8. {
  9. NS_FATAL_ERROR ("File " << fileName.c_str () << " not found");
  10. }
  11.  
  12. //initialize 4d vector: [row][col][numPaths][path]
  13. vector<double> emptyRoute(1,0);
  14. vector<vector<double> > numPaths(4, emptyRoute); //assume 4 different paths
  15. vector<vector<vector<double> > > init2D(66,numPaths);
  16. vector<vector<vector<vector<double> > > > array(66,init2D);
  17.  
  18. while(!route_file.eof())
  19. {
  20. string line;
  21. getline(route_file, line);
  22. istringstream iss(line);
  23. int row, col, numPaths;
  24. iss >> row >> col >> numPaths;
  25. /*collect all the routes, insert into 4th dimension for corresponding
  26. row/col/pathNum
  27. //numPaths should always be 4 according to current iridiumnet.log
  28. */
  29. for(int i = 0; i < numPaths; i++)
  30. {
  31. vector<double> route;
  32. string routeLine;
  33. getline(route_file, routeLine);
  34. istringstream issRoutes(routeLine);
  35. double element;
  36. while (issRoutes >> element)
  37. {
  38. route.push_back (element);
  39. }
  40. array[row][col][i] = route;
  41. }
  42. }
  43.  
  44. std::cout<<"##############Here are the paths/rates:################"<<std::endl;
  45. cout << setprecision(15);
  46. for(size_t i = 0; i < array.size(); i++)
  47. {
  48. for(size_t j = 0; j < init2D.size(); j++)
  49. {
  50. for(size_t k = 0; k < array[i][j].size(); k++)
  51. {
  52. //ignore routes that are empty/unused
  53. if(array[i][j][k] != emptyRoute)
  54. {
  55. cout << "Path #" << k+1 << " for " << i << "->" << j << ": ";
  56. vector<double> route = array[i][j][k];
  57. for(size_t l = 0; l < route.size(); l++)
  58. {
  59. cout << route[l] << " ";
  60. }
  61. cout << endl;
  62. }
  63. }
  64. }
  65. }
  66. std::cout<<"##############End of paths/rates:################"<<std::endl;
  67.  
  68. route_file.close ();
  69. return array;
  70. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement