-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmc_input.cc
More file actions
158 lines (139 loc) · 3.68 KB
/
Copy pathmc_input.cc
File metadata and controls
158 lines (139 loc) · 3.68 KB
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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
#include <stdio.h>
#include <stdlib.h>
#include <fstream>
#include <sstream>
#include <iomanip>
#include "mc_confg.h"
#include "mc_input.h"
#include "mc_utils.h"
#include "mc_poten.h"
#include "mc_setup.h"
const char IO_OUTPUTDIR[] = "OUTPUTDIR";
const char IO_FILENAMEPREFIX[] = "FILENAMEPREFIX";
const char IO_TEMPERATURE[] = "TEMPERATURE";
const char IO_ATOM[] = "ATOM";
const char IO_NUMBEROFSTEPS[] = "NUMBEROFSTEPS";
const char IO_NUMBEROFBLOCKS[] = "NUMBEROFBLOCKS";
const char IO_MCSKIP_RATIO[] = "MCSKIP_RATIO";
const char IO_MCSKIP_TOTAL[] = "MCSKIP_TOTAL";
const char IO_MCSKIP_AVERG[] = "MCSKIP_AVERG";
string OutputDir;
string FNPrefix;
string MCFileName; // mc output file name (no extension)
void IOReadParams(const char in_file[])
{
const char *_proc_=__func__; // "MCReadInput()";
NDIM=3;
string params;
ifstream inf(in_file,ios::in);
if (!inf.good())
_io_error(_proc_,IO_ERR_FOPEN,in_file);
while (inf>>params)
{
if (params==IO_OUTPUTDIR)
{
inf>>OutputDir;
}
else
if (params==IO_FILENAMEPREFIX)
{
inf>>FNPrefix;
}
else
if (params==IO_TEMPERATURE)
{
inf>>Temperature;
}
else
if (params==IO_ATOM)
{
inf>>MCAtom.type; //[1]
inf>>MCAtom.mcstep; //[2]
inf>>MCAtom.fpot; //[3]
inf>>MCAtom.fpos; //[4]
}
else
if (params==IO_NUMBEROFBLOCKS)
{
inf>>NumberOfMCBlocks>>NumberOfEQBlocks;
}
else
if (params==IO_NUMBEROFSTEPS)
{
inf>>NumberOfMCSteps;
}
else
if (params==IO_MCSKIP_RATIO)
{
inf >> MCSKIP_RATIO;
}
else
if (params==IO_MCSKIP_TOTAL)
{
inf >> MCSKIP_TOTAL;
}
else
if (params==IO_MCSKIP_AVERG)
{
inf >> MCSKIP_AVERG;
}
else
{}
getline(inf,params,'\n'); // skip comments at the end of the line
}
inf.close();
MCFileName = (OutputDir+FNPrefix);
// begin DUMP
cout << "OutPut " <<OutputDir<<endl;
cout << "File Name Prefix "<<FNPrefix<<endl;
cout << "Temperature "<<Temperature<<endl;
int w=6;
cout << setw(w) << MCAtom.type << BLANK;
cout << setw(w) << MCAtom.mcstep << BLANK;
cout << setw(w) << MCAtom.fpot << BLANK;
cout << setw(w) << MCAtom.fpos << BLANK;
cout << endl;
cout << "Number of Steps in block = " << NumberOfMCSteps << endl;
cout << "Number of Blocks = " << NumberOfMCBlocks << BLANK << NumberOfEQBlocks << endl;
cout << endl;
cout << "Number of steps to skip to save ACCEPT RATIO" << BLANK << MCSKIP_RATIO << endl;
cout << "Number of steps to skip to save ACCUML AVERG" << BLANK << MCSKIP_TOTAL << endl;
cout << "Number of steps to skip to evaluate AVERAGES" << BLANK << MCSKIP_AVERG << endl;
}
int FileExist (const char fileName [])
{
FILE *infile = fopen (fileName, "r");
// ifstream infile(fileName,ios::in);
int ret_code=0;
if (infile == NULL)
ret_code = 0; // file doesn't exist
else
{
ret_code = 1; // file exists
fclose (infile);
}
return (ret_code);
}
void io_setout(fstream &out, int set_precision)
{
out<<setprecision(set_precision);
out<<setiosflags (ios::scientific);
// out<<setiosflags (ios::right);
}
void IOFileBackUp(const char file_name[])
{
#ifdef DEBUG_PIMC
const char *_proc_=__func__;
#endif
string cmd="cp";
if (FileExist(file_name))
{
cmd += " " + (string)file_name;
cmd += " " + (string)file_name+(string)FBACKUP_EXTENSION;
int status = system(cmd.c_str());
#ifdef DEBUG_PIMC
if (status < 0)
nrerror(_proc_,IO_ERR_SCALL);
#endif
}
}