source: util/src/stochastik.cpp@ 1f4209

Last change on this file since 1f4209 was 1f4209, checked in by Frederik Heber <heber@…>, 17 years ago

util now has a src dir too which was necessary due to Makefile.am problems

  • Property mode set to 100644
File size: 2.0 KB
Line 
1using namespace std;
2#include <iostream>
3#include <iomanip>
4#include <fstream>
5#include <sstream>
6#include <math.h>
7#include <string>
8
9
10int main(int argc, char **argv) {
11
12 double avg, dev;
13 double tmp;
14 int i, j, col, zaehler;
15 int ecut;
16 int flag;
17 string zeile;
18 stringstream line;
19
20 if (argc < 4) {
21 cout << "Usage: " << argv[0] << " <Spalte> <X> <File1> <File2> ...\n";
22 return(1);
23 }
24 line.str(argv[1]);
25 line >> col;
26 line.clear();
27 line.str(argv[2]);
28 line >> ecut;
29 cout << "Using " << col << " with Ecut of " << ecut << "." << endl;
30
31 // get average
32 avg = 0.;
33 zaehler=0;
34 for (i=3;i<argc;i++) {
35 //cout << "Reading column " << col << " from file " << argv[i] << "\n";
36 ifstream test(argv[i]);
37 if (test == NULL) { cout << "Can't open File " << argv[i] << "\n"; return(255); }
38 flag=1;
39 //cout << "Looking for " << ecut << " \n";
40 while (getline(test, zeile, '\n')) {
41 //cout << zeile;
42 istringstream input(zeile);
43 input >> ws >> tmp;
44 if (tmp==(double)ecut) { // found correct line!
45 for (j=col;j>0;j--)
46 if (!input.eof())
47 input >> ws >> tmp;
48 else
49 flag=0;
50 //cout << tmp << "\n";
51 avg += tmp;
52 }
53 //else cout << " skipping\n";
54 }
55 zaehler+=flag;
56 test.close();
57 }
58 if (zaehler != 0) avg /= zaehler;
59
60 // get deviation
61 dev = 0.;
62 zaehler=0;
63 for (i=3;i<argc;i++) {
64 //cout << "Reading column " << col << " from file " << argv[i] << "\n";
65 ifstream test(argv[i]);
66 if (test == NULL) { cout << "Can't open File " << argv[i] << "\n"; return(255); }
67 flag=1;
68 while (getline(test, zeile, '\n')) {
69 istringstream input(zeile);
70 input >> ws >> tmp;
71 if (tmp==(double)ecut) { // found correct line!
72 for (j=col;j>0;j--)
73 if (!input.eof())
74 input >> ws >> tmp;
75 else
76 flag=0;
77 //cout << tmp << "\n";
78 dev += pow(tmp - avg, 2);
79 }
80 }
81 zaehler+=flag;
82 test.close();
83 }
84 //dev = 1/(zaehler)*dev;
85 dev /= zaehler;
86
87 cout << setprecision(8) << avg << "\t" << setprecision(8) << sqrt(dev) << "\n";
88 return(0);
89}
Note: See TracBrowser for help on using the repository browser.