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.
38 std::vector
<std::string
> states
;
39 std::vector
<double> energies
;
40 std::vector
< std::vector
<double> > weights
;
41 std::vector
<int> lengths
;
44 void createarrays (std::string filename
, Result
& res
, const int each
, double c
, bool use_log
= true) {
45 const int len
= *(res
.lengths
.end());
47 double *v
= new double[len
];
49 for (int j
=0;j
<len
;j
++) v
[i
] = 0;
50 std::string line_string
= "";
51 std::string state
= "";
52 std::ifstream
f(filename
.c_str(), std::fstream::in
);
56 getline(f
, line_string
);
57 std::stringstream
line(line_string
);
58 if (line_string
[0]=='#') {
59 res
.prepend
.append(line_string
);
60 } else if (line_string
.size()!=0) {
61 double nw
= use_log
?0.0:1.0;
62 line
>> state
>> energy
>> weight
;
63 res
.states
.push_back(state
);
64 res
.energies
.push_back(energy
);
66 weight
= std::log(weight
) - c
;
68 weight
= weight
* std::exp(-c
);
72 for (int j
=0;j
<len
;j
++) {
74 nw
+= v
[(len
+i
-j
)%len
];
76 nw
*= v
[(len
+i
-j
)%len
];
78 if (j
==res
.lengths
[which_l
]) {
79 res
.weights
[which_l
].push_back(use_log
?std::exp(nw
):nw
);
90 void analyze_data_file (std::string filename
, std::ostream
& out
, const int len
, double c
, bool use_log
= true) {
92 double *v
= new double[len
];
94 for (int j
=0;j
<len
;j
++) v
[i
] = 0;
95 std::string line_string
= "";
96 std::string state
= "";
97 std::ifstream
f(filename
.c_str(), std::fstream::in
);
101 getline(f
, line_string
);
102 std::stringstream
line(line_string
);
103 if (line_string
[0]=='#') {
104 out
<< line_string
<< "\n";
105 } else if (line_string
.size()!=0) {
106 double nw
= use_log
?0.0:1.0;
107 line
>> state
>> energy
>> weight
;
109 weight
= std::log(weight
) - c
;
111 weight
= weight
* std::exp(-c
);
113 out
<< state
<< " " << energy
;
115 for (int j
=0;j
<len
;j
++) {
117 nw
+= v
[(len
+i
-j
)%len
];
119 nw
*= v
[(len
+i
-j
)%len
];
122 out
<< " " << (use_log
?std::exp(nw
):nw
);
131 int main (int argc
, char **argv
) {
132 string len_s
= "1000";
135 vector
<string
> files
;
136 for (int i
=1;i
<argc
;i
++) {
137 if (argv
[i
][0]=='-') {
138 switch (argv
[i
][1]) {
140 corr
= atof(argv
[++i
]);
143 len
= atoi(argv
[++i
]);
148 files
.push_back(argv
[i
]);
151 for (vector
<string
>::iterator iter
= files
.begin();iter
!= files
.end();iter
++) {
156 fstream
o(ofn
.c_str(), fstream::out
);
158 o
<< "#!prepend " << len_s
<< "\n";
159 analyze_data_file(*iter
, o
, len
, corr
);