Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038 #include <stdlib.h>
00039 #include <math.h>
00040 #include <vector>
00041 #include <fstream>
00042 #include <sstream>
00043 #include <iostream>
00044 #include <cstring>
00045
00046 using namespace std;
00047
00048 #define RESOLUTION 1.0 // seconds
00049
00050 #define MAXIDLENESS 500.0 // seconds
00051
00052 int main (int argc, char **argv)
00053 {
00054 if (argc<2) {
00055 cout << "Use: " << argv[0] << " <filename> " << endl;
00056 exit(-1);
00057 }
00058
00059 int n = (int)(MAXIDLENESS/RESOLUTION)+1;
00060 int v[n]; for (int k=0; k<n; k++) v[k]=0;
00061
00062 ifstream f;
00063 f.open(argv[1]);
00064
00065 double time,idleness; int robot,node,interferences; char ch;
00066 int sum=0;
00067 while (f.good()) {
00068 char line[80];
00069 f.getline(line,80);
00070 stringstream ss(line);
00071
00072 ss >> time; ss>>ch;
00073 ss >> robot; ss>>ch;
00074 ss >> node; ss>>ch;
00075 ss >> idleness; ss>>ch;
00076 ss >> interferences;
00077
00078
00079
00080 if (idleness>MAXIDLENESS) {
00081 cout << "WARNING: Idleness " << idleness << " out of range! Discarded!" << endl;
00082 }
00083 else {
00084 int b = (int)(idleness/RESOLUTION);
00085 v[b]++; sum++;
00086 }
00087 }
00088 f.close();
00089
00090 char nf[strlen(argv[1])+8], cnf[strlen(argv[1])+8];
00091 strcpy(nf,argv[1]);
00092 nf[strlen(nf)-4]='\0';
00093 strcpy(cnf,nf);
00094 strcat(nf,".hist");
00095 strcat(cnf,".chist");
00096 cout << "Histogram output file: " << nf << endl;
00097 ofstream of1; of1.open(nf);
00098 ofstream of2; of2.open(cnf);
00099 double c=0;
00100 for (int k=0; k<n; k++) {
00101 of1 << k*RESOLUTION << " " << (double)v[k]/sum << endl;
00102 c += (double)v[k]/sum;
00103 of2 << k*RESOLUTION << " " << c << endl;
00104 }
00105
00106 of1.close(); of2.close();
00107
00108 }
00109
00110
00111
00112
00113
00114
00115
00116
00117
00118
00119
00120
00121
00122
00123