|
Last change
on this file since 774ae8 was a0bcf1, checked in by Frederik Heber <heber@…>, 18 years ago |
|
-initial commit
-Minimum set of files needed from ESPACK SVN repository
-Switch to three tantamount package parts instead of all relating to pcp (as at some time Ralf's might find inclusion as well)
|
-
Property mode
set to
100644
|
|
File size:
1.6 KB
|
| Line | |
|---|
| 1 | using namespace std;
|
|---|
| 2 | #include <iostream>
|
|---|
| 3 | #include <iomanip>
|
|---|
| 4 | #include <fstream>
|
|---|
| 5 | #include <sstream>
|
|---|
| 6 | #include <math.h>
|
|---|
| 7 | #include <string>
|
|---|
| 8 |
|
|---|
| 9 |
|
|---|
| 10 | int main(int argc, char **argv) {
|
|---|
| 11 |
|
|---|
| 12 | double avg, dev;
|
|---|
| 13 | double tmp;
|
|---|
| 14 | int i, j, zaehler;
|
|---|
| 15 | int firstcol, lastcol;
|
|---|
| 16 | double ecut;
|
|---|
| 17 | int flag;
|
|---|
| 18 | string zeile;
|
|---|
| 19 |
|
|---|
| 20 | if (argc < 4) {
|
|---|
| 21 | cout << "Usage: " << argv[0] << " <firstCol> <lastCol> <X> <File>\n";
|
|---|
| 22 | return(1);
|
|---|
| 23 | }
|
|---|
| 24 | firstcol = atoi(argv[1]);
|
|---|
| 25 | lastcol = atoi(argv[2]);
|
|---|
| 26 | ecut = atof(argv[3]);
|
|---|
| 27 |
|
|---|
| 28 | // get average
|
|---|
| 29 | avg = 0.;
|
|---|
| 30 | zaehler=0;
|
|---|
| 31 | ifstream test(argv[4]);
|
|---|
| 32 | if (test == NULL) { cout << "Can't open File " << argv[4] << "\n"; return(255); }
|
|---|
| 33 | flag=1;
|
|---|
| 34 | //cout << "Looking for " << ecut << " \n";
|
|---|
| 35 | while (getline(test, zeile, '\n')) {
|
|---|
| 36 | //cout << zeile;
|
|---|
| 37 | istringstream input(zeile);
|
|---|
| 38 | input >> ws >> tmp;
|
|---|
| 39 | if (tmp==(double)ecut) { // found correct line!
|
|---|
| 40 | for (j=2;j<=lastcol;j++)
|
|---|
| 41 | if (!input.eof()) {
|
|---|
| 42 | input >> ws >> tmp;
|
|---|
| 43 | if (j >= firstcol) {
|
|---|
| 44 | avg += tmp;
|
|---|
| 45 | zaehler++;
|
|---|
| 46 | }
|
|---|
| 47 | }
|
|---|
| 48 | }
|
|---|
| 49 | }
|
|---|
| 50 | test.clear();
|
|---|
| 51 | test.seekg(ios::beg);
|
|---|
| 52 | if (zaehler != 0) avg /= zaehler;
|
|---|
| 53 |
|
|---|
| 54 | // get deviation
|
|---|
| 55 | dev = 0.;
|
|---|
| 56 | zaehler=0;
|
|---|
| 57 | flag=1;
|
|---|
| 58 | while (getline(test, zeile, '\n')) {
|
|---|
| 59 | istringstream input(zeile);
|
|---|
| 60 | input >> ws >> tmp;
|
|---|
| 61 | if (tmp==(double)ecut) { // found correct line!
|
|---|
| 62 | for (j=2;j<=lastcol;j++)
|
|---|
| 63 | if (!input.eof()) {
|
|---|
| 64 | input >> ws >> tmp;
|
|---|
| 65 | if (j >= firstcol) {
|
|---|
| 66 | dev += (tmp - avg)*(tmp - avg);
|
|---|
| 67 | zaehler++;
|
|---|
| 68 | }
|
|---|
| 69 | }
|
|---|
| 70 | }
|
|---|
| 71 | }
|
|---|
| 72 | test.close();
|
|---|
| 73 | //dev = 1/(zaehler)*dev;
|
|---|
| 74 | if (dev != 0) dev /= zaehler;
|
|---|
| 75 |
|
|---|
| 76 | cout << setprecision(8) << avg << "\t" << setprecision(8) << sqrt(dev) << "\n";
|
|---|
| 77 | return(0);
|
|---|
| 78 | }
|
|---|
Note:
See
TracBrowser
for help on using the repository browser.