#include <iostream>
#include <fstream>
#include <sstream>
#include <string>
#include <cfloat>
using namespace std;
int main() {
string inName;
cout << "Read text from: ";
cin >> inName;
ifstream inFile;
inFile.open(inName.c_str());
if (!inFile.is_open()) {
cout << "ERROR: Cannot open " << inName << " file for reading." << endl;
return(1);
}
string SSIDname;
cout << "SSID to watch: ";
cin >> SSIDname;
double sum=0.0;
int cnt=0;
double max=-DBL_MAX;
unsigned line=0;
for (;;) {
char c;
c=inFile.peek();
if (inFile.fail())
break;
line++;
cout << line << "\r";
if (c=='#') {
inFile.ignore(1024,'\n');
continue;
}
while( (! inFile.fail()) && c!='(') inFile.get(c);
inFile.get(c);
string SSIDcurrent;
inFile >> SSIDcurrent;
if (inFile.fail()) break;
if (SSIDcurrent != SSIDname) continue;
while( (! inFile.fail()) && c!='[') inFile.get(c);
inFile.get(c);
double x, y, z;
inFile >> x >> y >> z;
if (inFile.fail()) {
cerr << "WARNING: Ignored corrupt SNR data in line " << line << endl;
inFile.clear();
inFile.ignore(1024,'\n');
continue;
}
inFile.ignore(1024,'\n');
sum=sum+x;
cnt++;
if (max<x)
max=x;
}
inFile.clear();
inFile.close();
if (cnt==0)
cout << "No data!" << endl;
else {
cout << "total: " << line << endl;
cout << "data = " << cnt << endl;
cout << "avg = " << sum/cnt << endl;
cout << "max = " << max << endl;
}
return(0);
}