xy_file.hh 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. //=====================================================
  2. // File : dump_file_x_y.hh
  3. // Author : L. Plagne <laurent.plagne@edf.fr)>
  4. // Copyright (C) EDF R&D, lun sep 30 14:23:20 CEST 2002
  5. //=====================================================
  6. //
  7. // This program is free software; you can redistribute it and/or
  8. // modify it under the terms of the GNU General Public License
  9. // as published by the Free Software Foundation; either version 2
  10. // of the License, or (at your option) any later version.
  11. //
  12. // This program is distributed in the hope that it will be useful,
  13. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. // GNU General Public License for more details.
  16. // You should have received a copy of the GNU General Public License
  17. // along with this program; if not, write to the Free Software
  18. // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  19. //
  20. #ifndef XY_FILE_HH
  21. #define XY_FILE_HH
  22. #include <fstream>
  23. #include <iostream>
  24. #include <string>
  25. #include <vector>
  26. using namespace std;
  27. bool read_xy_file(const std::string & filename, std::vector<int> & tab_sizes,
  28. std::vector<double> & tab_mflops, bool quiet = false)
  29. {
  30. std::ifstream input_file (filename.c_str(),std::ios::in);
  31. if (!input_file){
  32. if (!quiet) {
  33. INFOS("!!! Error opening "<<filename);
  34. }
  35. return false;
  36. }
  37. int nb_point=0;
  38. int size=0;
  39. double mflops=0;
  40. while (input_file >> size >> mflops ){
  41. nb_point++;
  42. tab_sizes.push_back(size);
  43. tab_mflops.push_back(mflops);
  44. }
  45. SCRUTE(nb_point);
  46. input_file.close();
  47. return true;
  48. }
  49. // The Vector class must satisfy the following part of STL vector concept :
  50. // resize() method
  51. // [] operator for setting element
  52. // the vector element must have the << operator define
  53. using namespace std;
  54. template<class Vector_A, class Vector_B>
  55. void dump_xy_file(const Vector_A & X, const Vector_B & Y, const std::string & filename){
  56. ofstream outfile (filename.c_str(),ios::out) ;
  57. int size=X.size();
  58. for (int i=0;i<size;i++)
  59. outfile << X[i] << " " << Y[i] << endl;
  60. outfile.close();
  61. }
  62. #endif