2 * Copyright (c) 2009 Mauro Iazzi
4 * Permission is hereby granted, free of charge, to any person
5 * obtaining a copy of this software and associated documentation
6 * files (the "Software"), to deal in the Software without
7 * restriction, including without limitation the rights to use,
8 * copy, modify, merge, publish, distribute, sublicense, and/or sell
9 * copies of the Software, and to permit persons to whom the
10 * Software is furnished to do so, subject to the following
13 * The above copyright notice and this permission notice shall be
14 * included in all copies or substantial portions of the Software.
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
18 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
20 * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
21 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
22 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
23 * OTHER DEALINGS IN THE SOFTWARE.
36 void analyze_data_file (std::string filename
, std::ostream
& out
, const int len
, double c
, bool use_log
= true) {
38 double *v
= new double[len
];
40 for (int j
=0;j
<len
;j
++) v
[i
] = 0;
41 std::string line_string
= "";
42 std::string state
= "";
43 std::ifstream
f(filename
.c_str(), std::fstream::in
);
47 getline(f
, line_string
);
48 std::stringstream
line(line_string
);
49 if (line_string
[0]=='#') {
50 out
<< line_string
<< "\n";
51 } else if (line_string
.size()!=0) {
52 double nw
= use_log
?0.0:1.0;
53 line
>> state
>> energy
>> weight
;
55 weight
= std::log(weight
) - c
;
57 weight
= weight
* std::exp(-c
);
59 out
<< state
<< " " << energy
;
61 for (int j
=0;j
<len
;j
++) {
63 nw
+= v
[(len
+i
-j
)%len
];
65 nw
*= v
[(len
+i
-j
)%len
];
68 out
<< " " << (use_log
?std::exp(nw
):nw
);
77 int main (int argc
, char **argv
) {
78 string len_s
= "1000";
82 for (int i
=1;i
<argc
;i
++) {
83 if (argv
[i
][0]=='-') {
86 corr
= atof(argv
[++i
]);
89 len
= atoi(argv
[++i
]);
94 files
.push_back(argv
[i
]);
97 for (vector
<string
>::iterator iter
= files
.begin();iter
!= files
.end();iter
++) {
101 fstream
o(ofn
.c_str(), fstream::out
);
103 o
<< "#!prepend " << len_s
<< "\n";
104 analyze_data_file(*iter
, o
, len
, corr
);