using namespace std; #include #include #include #include #include #include #include "version.h" int main(int argc, char **argv) { double avg, dev; double tmp; int zaehler; int col; int flag; int skiplines=0; string zeile; stringstream line; cout << ESPACKVersion << endl; if (argc <= 2) { cout << "Usage: " << argv[0] << " [#skip initial lines]\n"; return(1); } { line.str(argv[1]); line >> col; cout << "Using column " << col << "." << endl; line.clear(); } if (argc > 3) { line.str(argv[3]); line >> skiplines; cout << "Will skip first " << skiplines << " lines." << endl; line.clear(); } // get average avg = 0.; zaehler=0; ifstream test(argv[2]); if (test == NULL) { cout << "Can't open File " << argv[2] << "\n"; return(255); } flag=1; while (getline(test, zeile, '\n')) { if (skiplines) { skiplines--; continue; } line.clear(); line.str(zeile); for (int j=0;j<=col;j++) if (!line.eof()) { line >> ws >> tmp; } else { flag=0; } if (flag) { avg += tmp; zaehler++; } } if (!flag) { cerr << "File does not contain " << col << " column(s)." << endl; exit(1); } else if (zaehler != 0) avg /= zaehler; // goto to beginning again test.clear(); test.seekg(ios::beg); // get deviation dev = 0.; zaehler=0; flag=1; while (getline(test, zeile, '\n')) { if (skiplines) { skiplines--; continue; } line.clear(); line.str(zeile); for (int j=0;j<=col;j++) line >> ws >> tmp; if (!line.eof()) { dev += (tmp - avg)*(tmp - avg); zaehler++; } } test.close(); if (zaehler != 0) dev /= zaehler; cout << setprecision(8) << avg << "\t" << setprecision(8) << sqrt(dev) << "\n"; return(0); }