Last change
on this file since 0fe2ca was 0fe2ca, checked in by Frederik Heber <heber@…>, 17 years ago |
atoi() and atof() were replaced by stringstream construct (g++-4.3.0 admonished as cstring was included)
|
-
Property mode
set to
100644
|
File size:
1.8 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 | stringstream line;
|
---|
20 |
|
---|
21 | if (argc < 4) {
|
---|
22 | cout << "Usage: " << argv[0] << " <firstCol> <lastCol> <X> <File>\n";
|
---|
23 | return(1);
|
---|
24 | }
|
---|
25 | line.str(argv[1]);
|
---|
26 | line >> firstcol;
|
---|
27 | line.clear();
|
---|
28 | line.str(argv[2]);
|
---|
29 | line >> lastcol;
|
---|
30 | line.clear();
|
---|
31 | line.str(argv[3]);
|
---|
32 | line >> ecut;
|
---|
33 | cout << "Going from " << firstcol << " to " << lastcol << " with Ecut of " << ecut << "." << endl;
|
---|
34 |
|
---|
35 | // get average
|
---|
36 | avg = 0.;
|
---|
37 | zaehler=0;
|
---|
38 | ifstream test(argv[4]);
|
---|
39 | if (test == NULL) { cout << "Can't open File " << argv[4] << "\n"; return(255); }
|
---|
40 | flag=1;
|
---|
41 | //cout << "Looking for " << ecut << " \n";
|
---|
42 | while (getline(test, zeile, '\n')) {
|
---|
43 | //cout << zeile;
|
---|
44 | istringstream input(zeile);
|
---|
45 | input >> ws >> tmp;
|
---|
46 | if (tmp==(double)ecut) { // found correct line!
|
---|
47 | for (j=2;j<=lastcol;j++)
|
---|
48 | if (!input.eof()) {
|
---|
49 | input >> ws >> tmp;
|
---|
50 | if (j >= firstcol) {
|
---|
51 | avg += tmp;
|
---|
52 | zaehler++;
|
---|
53 | }
|
---|
54 | }
|
---|
55 | }
|
---|
56 | }
|
---|
57 | test.clear();
|
---|
58 | test.seekg(ios::beg);
|
---|
59 | if (zaehler != 0) avg /= zaehler;
|
---|
60 |
|
---|
61 | // get deviation
|
---|
62 | dev = 0.;
|
---|
63 | zaehler=0;
|
---|
64 | flag=1;
|
---|
65 | while (getline(test, zeile, '\n')) {
|
---|
66 | istringstream input(zeile);
|
---|
67 | input >> ws >> tmp;
|
---|
68 | if (tmp==(double)ecut) { // found correct line!
|
---|
69 | for (j=2;j<=lastcol;j++)
|
---|
70 | if (!input.eof()) {
|
---|
71 | input >> ws >> tmp;
|
---|
72 | if (j >= firstcol) {
|
---|
73 | dev += (tmp - avg)*(tmp - avg);
|
---|
74 | zaehler++;
|
---|
75 | }
|
---|
76 | }
|
---|
77 | }
|
---|
78 | }
|
---|
79 | test.close();
|
---|
80 | //dev = 1/(zaehler)*dev;
|
---|
81 | if (dev != 0) dev /= zaehler;
|
---|
82 |
|
---|
83 | cout << setprecision(8) << avg << "\t" << setprecision(8) << sqrt(dev) << "\n";
|
---|
84 | return(0);
|
---|
85 | }
|
---|
Note:
See
TracBrowser
for help on using the repository browser.