| Last change
 on this file since cfaf42 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.9 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, col, zaehler; | 
|---|
| 15 | int ecut; | 
|---|
| 16 | int flag; | 
|---|
| 17 | FILE *test; | 
|---|
| 18 | string zeile; | 
|---|
| 19 |  | 
|---|
| 20 | if (argc < 4) { | 
|---|
| 21 | cout << "Usage: " << argv[0] << " <Spalte> <X> <File1> <File2> ...\n"; | 
|---|
| 22 | return(1); | 
|---|
| 23 | } | 
|---|
| 24 | col = atoi(argv[1]); | 
|---|
| 25 | ecut = atoi(argv[2]); | 
|---|
| 26 |  | 
|---|
| 27 | // get average | 
|---|
| 28 | avg = 0.; | 
|---|
| 29 | zaehler=0; | 
|---|
| 30 | for (i=3;i<argc;i++) { | 
|---|
| 31 | //cout << "Reading column " << col << " from file " << argv[i] << "\n"; | 
|---|
| 32 | ifstream test(argv[i]); | 
|---|
| 33 | if (test == NULL) { cout << "Can't open File " << argv[i] << "\n"; return(255); } | 
|---|
| 34 | flag=1; | 
|---|
| 35 | //cout << "Looking for " << ecut << " \n"; | 
|---|
| 36 | while (getline(test, zeile, '\n')) { | 
|---|
| 37 | //cout << zeile; | 
|---|
| 38 | istringstream input(zeile); | 
|---|
| 39 | input >> ws >> tmp; | 
|---|
| 40 | if (tmp==(double)ecut) {        // found correct line! | 
|---|
| 41 | for (j=col;j>0;j--) | 
|---|
| 42 | if (!input.eof()) | 
|---|
| 43 | input >> ws >> tmp; | 
|---|
| 44 | else | 
|---|
| 45 | flag=0; | 
|---|
| 46 | //cout << tmp << "\n"; | 
|---|
| 47 | avg += tmp; | 
|---|
| 48 | } | 
|---|
| 49 | //else cout << " skipping\n"; | 
|---|
| 50 | } | 
|---|
| 51 | zaehler+=flag; | 
|---|
| 52 | test.close(); | 
|---|
| 53 | } | 
|---|
| 54 | if (zaehler != 0) avg /= zaehler; | 
|---|
| 55 |  | 
|---|
| 56 | // get deviation | 
|---|
| 57 | dev = 0.; | 
|---|
| 58 | zaehler=0; | 
|---|
| 59 | for (i=3;i<argc;i++) { | 
|---|
| 60 | //cout << "Reading column " << col << " from file " << argv[i] << "\n"; | 
|---|
| 61 | ifstream test(argv[i]); | 
|---|
| 62 | if (test == NULL) { cout << "Can't open File " << argv[i] << "\n"; return(255); } | 
|---|
| 63 | flag=1; | 
|---|
| 64 | while (getline(test, zeile, '\n')) { | 
|---|
| 65 | istringstream input(zeile); | 
|---|
| 66 | input >> ws >> tmp; | 
|---|
| 67 | if (tmp==(double)ecut) {        // found correct line! | 
|---|
| 68 | for (j=col;j>0;j--) | 
|---|
| 69 | if (!input.eof()) | 
|---|
| 70 | input >> ws >> tmp; | 
|---|
| 71 | else | 
|---|
| 72 | flag=0; | 
|---|
| 73 | //cout << tmp << "\n"; | 
|---|
| 74 | dev += pow(tmp - avg, 2); | 
|---|
| 75 | } | 
|---|
| 76 | } | 
|---|
| 77 | zaehler+=flag; | 
|---|
| 78 | test.close(); | 
|---|
| 79 | } | 
|---|
| 80 | //dev = 1/(zaehler)*dev; | 
|---|
| 81 | 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.