-
Notifications
You must be signed in to change notification settings - Fork 0
/
driver.cpp
106 lines (90 loc) · 3.33 KB
/
driver.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
/*
* driver.cpp
*
* Newton interpolating polynomials for free energy estimates
* Copyright (C) 2008 Conrad Shyu (conradshyu at hotmail.com)
* Department of Physics, University of Idaho
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* Author's comments
* -----------------
* the template for the main driver program
*
* written by Conrad Shyu (conradshyu at hotmail.com)
* Department of Physics
* University of Idaho
*
* revised on September 1, 2008
* revised on September 3, 2008
* revised on March 11, 2014
*/
#include <newton.h>
const char* DELIMIT_TOKEN = "\n\t,; ";
const unsigned int MAX_BUFFER = 1024;
/*
* open the file and load the data into memory
*/
unsigned int LoadData(
std::ifstream& _file, std::list<stNEWTON>& _sample )
{
char buffer[ MAX_BUFFER ];
stNEWTON data;
_sample.clear();
while ( _file.getline( buffer, MAX_BUFFER ) )
{
if ( buffer[ 0 ] == '#' )
{
continue;
} // skip the comments
data.x = atof( strtok( buffer, DELIMIT_TOKEN ) ); // lambda
data.y = atof( strtok( NULL, DELIMIT_TOKEN ) ); // dg/dl value
_sample.push_back( data );
} // parse the file
return( _sample.size() );
} // end of LoadData()
/*
* the main program
*/
int main( int argc, char** argv )
{
// print out GLP licencse V3
std::cout << "Copyright (C) 2014 Conrad Shyu ([email protected])" << std::endl;
std::cout << "This free software and comes with ABSOLUTELY NO WARRANTY." << std::endl << std::endl;
if ( argc < 2 )
{
std::cout << argv[ 0 ] << " input_file [plot_file [data_points]]" << std::endl;
std::cout << " input_file: file contains thermodynamic integration data" << std::endl;
std::cout << " plot_file: file for the plot data [optional]" << std::endl;
std::cout << "data_points: number of data points for plot [optional]" << std::endl;
std::cout << std::endl << "see readme.txt for more information" << std::endl;
return( 0 );
} // check the number of parameters
std::ifstream ifs( argv[ 1 ], std::ios::in );
if ( ifs.bad() )
{
std::cout << "failed to open the file " << argv[ 1 ] << std::endl; return( 1 );
} // make sure the file can be opened successfully
std::list<stNEWTON> sample; LoadData( ifs, sample ); ifs.close();
Newton a( sample ); a.GetPolynomial( true );
printf( "\nFree energy difference\n Newton: %.8f\nTrapezoid: %.8f\n",
a.DoIntegral(), a.DoQuadrature() );
if ( argc > 2 )
{
a.GetEstimate(
argv[ 2 ], // filename for plot data
( argc > 3 ) ? atoi( argv[ 3 ] ) : ( sample.size() - 1 ) );
} // need to write the estimates
return( 0 );
} // end of main