#include <iostream>
#include <fstream>
#include <strstream>
#include <cstring>
#include <cfloat>
using namespace std;
int main() {
char inName[80];
cout << "Read text from: ";
cin >> inName;
ifstream inFile;
inFile.open(inName);
if (!inFile.is_open()) {
cout << "ERROR: Cannot open " << inName << " file for reading." << endl;
return(1);
}
char SSIDname[16];
cout << "SSID to watch: ";
cin >> SSIDname;
int SSIDlen=strlen(SSIDname);
double sum=0.0;
int cnt=0;
double max=-DBL_MAX;
unsigned line=0;
for (;;) {
char buffer[1024];
inFile.getline(buffer, 1024);
if (inFile.fail()) {
if (inFile.eof()) break;
cerr << "ERROR: file reading error - data corrupted, exiting at line number " << line << endl;
break;
}
line++;
cout << line << "\r";
if (buffer[0]=='#')
continue;
int p1 = 1;
while (buffer[p1]!='\0' && buffer[p1]!='(') p1++;
if (buffer[p1]=='\0') continue;
if (strncmp(&buffer[p1+2], SSIDname, SSIDlen) !=0 ) continue;
int b1 = p1;
while (buffer[b1]!='\0' && buffer[b1]!='[') b1++;
if (buffer[b1]=='\0') continue;
istrstream inLine(&buffer[b1+1]);
double x, y, z;
inLine >> x >> y >> z;
if (inLine.fail()) {
cerr << "WARNING: Ignored corrupt SNR data in line " << line << endl;
continue;
}
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);
}