Home | History | Annotate | Download | only in utils
      1 //=====================================================
      2 // File   :  dump_file_x_y.hh
      3 // Author :  L. Plagne <laurent.plagne (at) 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 
     28 bool read_xy_file(const std::string & filename, std::vector<int> & tab_sizes,
     29                   std::vector<double> & tab_mflops, bool quiet = false)
     30 {
     31 
     32   std::ifstream input_file (filename.c_str(),std::ios::in);
     33 
     34   if (!input_file){
     35     if (!quiet) {
     36       INFOS("!!! Error opening "<<filename);
     37     }
     38     return false;
     39   }
     40 
     41   int nb_point=0;
     42   int size=0;
     43   double mflops=0;
     44 
     45   while (input_file >> size >> mflops ){
     46     nb_point++;
     47     tab_sizes.push_back(size);
     48     tab_mflops.push_back(mflops);
     49   }
     50   SCRUTE(nb_point);
     51 
     52   input_file.close();
     53   return true;
     54 }
     55 
     56 // The Vector class must satisfy the following part of STL vector concept :
     57 //            resize() method
     58 //            [] operator for seting element
     59 // the vector element must have the << operator define
     60 
     61 using namespace std;
     62 
     63 template<class Vector_A, class Vector_B>
     64 void dump_xy_file(const Vector_A & X, const Vector_B & Y, const std::string & filename){
     65 
     66   ofstream outfile (filename.c_str(),ios::out) ;
     67   int size=X.size();
     68 
     69   for (int i=0;i<size;i++)
     70     outfile << X[i] << " " << Y[i] << endl;
     71 
     72   outfile.close();
     73 }
     74 
     75 #endif
     76