source: util/stochastik.cpp@ 0fe2ca

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