-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinput.cpp
142 lines (107 loc) · 3.63 KB
/
input.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
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
#include<iostream>
#include<fstream>
#include<complex>
#include <time.h>
#include <cstdlib>
#include <cstring>
#include "config.h"
#include "default.h"
#ifdef use_mpi
#include "minictqmcworld.h"
static CTQMC_TAG FINISH_MESSAGE=5744;
#endif
default_dict internal_input;
#ifdef use_mpi
#define STREAM CTQMC.getStream()
#else
#define STREAM std::cout
#endif
#define DEBUG(X) //STREAM << X << flush;
//===================file input ======================
char input_values [255]="_input.dat";
int MAX_NUMBER_OF_VARS=2000, MAX_NUMBER_OF_COMMENT_CHARS=10000;
n_type value_(char* name, int index=0)
{
return internal_input.value(name);
}
n_type value(char* name, int index=0)
{
static int numb=0; numb++; if (numb>MAX_NUMBER_OF_VARS) {cout<<"VALUE is called too many times. Check the code!\n"; numb=0;}
char x [255];
ifstream inf(input_values);
int f, count=0;
do
{
int g=0; do {inf>>x;g++;} while (x[0]!='$' && g<MAX_NUMBER_OF_COMMENT_CHARS);
{for (int i=0; x[i]!=0 && i<1000; i++) {x[i]=x[i+1]; if (x[i]=='$') {x[i]=0; x[i+1]=0;};};}
f=1; int i=-1;
do
{i++; if (x[i]!=name[i]) f=0;}
while (x[i]!=0 && name[i]!=0 && i<255 && f==1);
count++;
if (g==MAX_NUMBER_OF_COMMENT_CHARS) count=MAX_NUMBER_OF_VARS; //EOF
;}
while (f==0 && count<MAX_NUMBER_OF_VARS);
if (count==MAX_NUMBER_OF_VARS) return value_(name,index);
n_type r; for(int i=0; i<index+1; i++) inf>>r; return r;
;}
int int_value_(char* name, int index=0)
{
return internal_input.int_value(name);
}
int int_value(char* name, int index=0)
{
static int numb=0; numb++; if (numb>MAX_NUMBER_OF_VARS) {cout<<"INT_VALUE is called too many times. Check the code!\n"; numb=0;}
char x [255];
ifstream inf(input_values);
int f, count=0;
do
{
int g=0; do {inf>>x;g++;} while (x[0]!='$' && g<MAX_NUMBER_OF_COMMENT_CHARS);
{for (int i=0; x[i]!=0 && i<1000; i++) {x[i]=x[i+1]; if (x[i]=='$') {x[i]=0; x[i+1]=0;};};}
f=1; int i=-1;
do
{i++; if (x[i]!=name[i]) f=0;}
while (x[i]!=0 && name[i]!=0 && i<255 && f==1);
count++;
if (g==MAX_NUMBER_OF_COMMENT_CHARS) count=MAX_NUMBER_OF_VARS; //EOF
;}
while (f==0 && count<MAX_NUMBER_OF_VARS);
if (count==MAX_NUMBER_OF_VARS) return int_value_(name,index);
int r=3; for(int i=0; i<index+1; i++) inf>>r; return r;
;}
void change_parameter(char *argv, n_type val)
{
char * text; int L;
{
ifstream inp("_input.dat",ios::in|ios::binary|ios::ate);
if (!inp.is_open()) {ofstream ou("_input.dat",ios::binary); ou<<"Added by \"change\"\n$"<<argv<<"$\n"<<val<<"\n\n"; return;}
L=inp.tellg();inp.seekg (0, ios::beg);
text=new char[L+256];inp.read (text, L);
;}
int length_name=0; for (;argv[length_name]!=0;length_name++);
bool found=false; int i1, i2;
for (int i=0; i<L-1; i++)
if (text[i]=='$')
{
int j; for (j=i+1; j<L; j++)
if (text[j]=='$')
{
found=(length_name==j-i-1);
for (int k=i+1; k<j; k++) if (text[k]!=argv[k-i-1]) found=false;
break;
;}
if (found)
{
i1=j; for(;text[i1]!='\n';i1++);
i2=i1+1; for(;text[i2]!='\n';i2++);
break;
;}
;}
ofstream ou("_input.dat",ios::binary);
if (!found) {ou<<text<<"\n$"<<argv<<"$\n"<<val<<"\nAdded by \"change\"\n"; return;}
{for (int j=0; j<=i1; j++) ou<<text[j];}
ou<<val;
{for (int j=i2; j<L; j++) ou<<text[j];}
return;
;}