1 //=====================================================
2 // File   :  regularize.cxx
3 // Author :  L. Plagne <laurent.plagne@edf.fr)>
4 // Copyright (C) EDF R&D,  lun sep 30 14:23:15 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 #include "utilities.h"
21 #include <vector>
22 #include <string>
23 #include <iostream>
24 #include <fstream>
25 #include "bench_parameter.hh"
26 #include <set>
27 
28 using namespace std;
29 
30 void read_xy_file(const string & filename, vector<int> & tab_sizes, vector<double> & tab_mflops);
31 void regularize_curve(const string & filename,
32 		      const vector<double> & tab_mflops,
33 		      const vector<int> & tab_sizes,
34 		      int start_cut_size, int stop_cut_size);
35 /////////////////////////////////////////////////////////////////////////////////////////////////
36 
main(int argc,char * argv[])37 int main( int argc , char *argv[] )
38 {
39 
40   // input data
41 
42   if (argc<4){
43     INFOS("!!! Error ... usage : main filename start_cut_size stop_cut_size regularize_filename");
44     exit(0);
45   }
46   INFOS(argc);
47 
48   int start_cut_size=atoi(argv[2]);
49   int stop_cut_size=atoi(argv[3]);
50 
51   string filename=argv[1];
52   string regularize_filename=argv[4];
53 
54   INFOS(filename);
55   INFOS("start_cut_size="<<start_cut_size);
56 
57   vector<int> tab_sizes;
58   vector<double> tab_mflops;
59 
60   read_xy_file(filename,tab_sizes,tab_mflops);
61 
62   // regularizeing
63 
64   regularize_curve(regularize_filename,tab_mflops,tab_sizes,start_cut_size,stop_cut_size);
65 
66 
67 }
68 
69 //////////////////////////////////////////////////////////////////////////////////////
70 
regularize_curve(const string & filename,const vector<double> & tab_mflops,const vector<int> & tab_sizes,int start_cut_size,int stop_cut_size)71 void regularize_curve(const string & filename,
72 		      const vector<double> & tab_mflops,
73 		      const vector<int> & tab_sizes,
74 		      int start_cut_size, int stop_cut_size)
75 {
76   int size=tab_mflops.size();
77   ofstream output_file (filename.c_str(),ios::out) ;
78 
79   int i=0;
80 
81   while(tab_sizes[i]<start_cut_size){
82 
83     output_file << tab_sizes[i] << " " <<  tab_mflops[i] << endl ;
84     i++;
85 
86   }
87 
88   output_file << endl ;
89 
90   while(tab_sizes[i]<stop_cut_size){
91 
92     i++;
93 
94   }
95 
96   while(i<size){
97 
98     output_file << tab_sizes[i] << " " <<  tab_mflops[i] << endl ;
99     i++;
100 
101   }
102 
103   output_file.close();
104 
105 }
106 
107 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
108 
read_xy_file(const string & filename,vector<int> & tab_sizes,vector<double> & tab_mflops)109 void read_xy_file(const string & filename, vector<int> & tab_sizes, vector<double> & tab_mflops){
110 
111   ifstream input_file (filename.c_str(),ios::in) ;
112 
113   if (!input_file){
114     INFOS("!!! Error opening "<<filename);
115     exit(0);
116   }
117 
118   int nb_point=0;
119   int size=0;
120   double mflops=0;
121 
122   while (input_file >> size >> mflops ){
123     nb_point++;
124     tab_sizes.push_back(size);
125     tab_mflops.push_back(mflops);
126   }
127   SCRUTE(nb_point);
128 
129   input_file.close();
130 }
131 
132