xy_file.hh
Go to the documentation of this file.
00001 //=====================================================
00002 // File   :  dump_file_x_y.hh
00003 // Author :  L. Plagne <laurent.plagne@edf.fr)>        
00004 // Copyright (C) EDF R&D,  lun sep 30 14:23:20 CEST 2002
00005 //=====================================================
00006 // 
00007 // This program is free software; you can redistribute it and/or
00008 // modify it under the terms of the GNU General Public License
00009 // as published by the Free Software Foundation; either version 2
00010 // of the License, or (at your option) any later version.
00011 // 
00012 // This program is distributed in the hope that it will be useful,
00013 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00014 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015 // GNU General Public License for more details.
00016 // You should have received a copy of the GNU General Public License
00017 // along with this program; if not, write to the Free Software
00018 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
00019 // 
00020 #ifndef XY_FILE_HH
00021 #define XY_FILE_HH
00022 #include <fstream>
00023 #include <iostream>
00024 #include <string>
00025 #include <vector>
00026 using namespace std;
00027 
00028 bool read_xy_file(const std::string & filename, std::vector<int> & tab_sizes,
00029                   std::vector<double> & tab_mflops, bool quiet = false)
00030 {
00031 
00032   std::ifstream input_file (filename.c_str(),std::ios::in);
00033 
00034   if (!input_file){
00035     if (!quiet) {
00036       INFOS("!!! Error opening "<<filename);
00037     }
00038     return false;
00039   }
00040 
00041   int nb_point=0;
00042   int size=0;
00043   double mflops=0;
00044 
00045   while (input_file >> size >> mflops ){
00046     nb_point++;
00047     tab_sizes.push_back(size);
00048     tab_mflops.push_back(mflops);
00049   }
00050   SCRUTE(nb_point);
00051 
00052   input_file.close();
00053   return true;
00054 }
00055 
00056 // The Vector class must satisfy the following part of STL vector concept :
00057 //            resize() method
00058 //            [] operator for seting element
00059 // the vector element must have the << operator define
00060 
00061 using namespace std;
00062 
00063 template<class Vector_A, class Vector_B>
00064 void dump_xy_file(const Vector_A & X, const Vector_B & Y, const std::string & filename){
00065   
00066   ofstream outfile (filename.c_str(),ios::out) ;
00067   int size=X.size();
00068   
00069   for (int i=0;i<size;i++)
00070     outfile << X[i] << " " << Y[i] << endl;
00071 
00072   outfile.close();
00073 } 
00074 
00075 #endif


libicr
Author(s): Robert Krug
autogenerated on Mon Jan 6 2014 11:34:05