source: util/src/average.cpp@ 59b70a

Last change on this file since 59b70a was ef87ee, checked in by Frederik Heber <heber@…>, 16 years ago

Added versioning to each executable.

  • credits to Ralf Wildenhues for writing the Makefile.am code
  • version.c section added to Makefile.am (pcp, molecuilder and util)
  • src/version.h to each pcp, molecuilder and util
  • each of the executables includes version.h and prints version in main()

Signed-off-by: Frederik Heber <heber@…>

  • Property mode set to 100644
File size: 1.9 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#include "version.h"
10
11int main(int argc, char **argv) {
12
13 double avg, dev;
14 double tmp;
15 int j, zaehler;
16 int firstcol, lastcol;
17 double ecut;
18 int flag;
19 string zeile;
20 stringstream line;
21
22 cout << ESPACKVersion << endl;
23
24 if (argc < 4) {
25 cout << "Usage: " << argv[0] << " <firstCol> <lastCol> <X> <File>\n";
26 return(1);
27 }
28 line.str(argv[1]);
29 line >> firstcol;
30 line.clear();
31 line.str(argv[2]);
32 line >> lastcol;
33 line.clear();
34 line.str(argv[3]);
35 line >> ecut;
36 cout << "Going from " << firstcol << " to " << lastcol << " with Ecut of " << ecut << "." << endl;
37
38 // get average
39 avg = 0.;
40 zaehler=0;
41 ifstream test(argv[4]);
42 if (test == NULL) { cout << "Can't open File " << argv[4] << "\n"; return(255); }
43 flag=1;
44 //cout << "Looking for " << ecut << " \n";
45 while (getline(test, zeile, '\n')) {
46 //cout << zeile;
47 istringstream input(zeile);
48 input >> ws >> tmp;
49 if (tmp==(double)ecut) { // found correct line!
50 for (j=2;j<=lastcol;j++)
51 if (!input.eof()) {
52 input >> ws >> tmp;
53 if (j >= firstcol) {
54 avg += tmp;
55 zaehler++;
56 }
57 }
58 }
59 }
60 test.clear();
61 test.seekg(ios::beg);
62 if (zaehler != 0) avg /= zaehler;
63
64 // get deviation
65 dev = 0.;
66 zaehler=0;
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=2;j<=lastcol;j++)
73 if (!input.eof()) {
74 input >> ws >> tmp;
75 if (j >= firstcol) {
76 dev += (tmp - avg)*(tmp - avg);
77 zaehler++;
78 }
79 }
80 }
81 }
82 test.close();
83 //dev = 1/(zaehler)*dev;
84 if (dev != 0) dev /= zaehler;
85
86 cout << setprecision(8) << avg << "\t" << setprecision(8) << sqrt(dev) << "\n";
87 return(0);
88}
Note: See TracBrowser for help on using the repository browser.