-
Notifications
You must be signed in to change notification settings - Fork 0
/
GTMmain.cc
359 lines (306 loc) · 9.25 KB
/
GTMmain.cc
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
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
#include "defs.h"
using namespace std;
float int22[LINES_INT22][COLS_INT22];
float int21[LINES_INT21][COLS_INT21];
float dangle[LINES_DANGLE][COLS_DANGLE];
float int11[LINES_INT11][COLS_INT11];
float loop[LINES_LOOP][COLS_LOOP];
float stack[LINES_STACK][COLS_STACK];
float tloop[LINES_TLOOP];
std::string stringTloop[LINES_TLOOP];
float tstackh[LINES_TSTACKH][COLS_TSTACKH];
float tstacki[LINES_TSTACKI][COLS_TSTACKI];
float int22_ORIG[LINES_INT22][COLS_INT22];
float int21_ORIG[LINES_INT21][COLS_INT21];
float dangle_ORIG[LINES_DANGLE][COLS_DANGLE];
float int11_ORIG[LINES_INT11][COLS_INT11];
float loop_ORIG[LINES_LOOP][COLS_LOOP];
float stack_ORIG[LINES_STACK][COLS_STACK];
float tloop_ORIG[LINES_TLOOP];
std::string stringTloop_ORIG[LINES_TLOOP];
float tstackh_ORIG[LINES_TSTACKH][COLS_TSTACKH];
float tstacki_ORIG[LINES_TSTACKI][COLS_TSTACKI];
std::string CURRENT_WORKING_DIR;
unsigned RANDOMSEED;
std::ofstream logfile;
int getNumLines(FILE *fp)
{
int count = 0;
char tempBuffer[500];
while(fgets(tempBuffer, 500, fp) != NULL)
{
count++;
}
return count;
}
void loadInt21(string fpath)
{
FILE *fp;
fp = fopen(fpath.c_str(),"r");
if(fp == NULL)
{cout<<"\n>>Error loading param files....exiting"; exit(0);}
for(int i=0; i<LINES_INT21; i++)
{
fscanf(fp, "%f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f", &int21[i][0], &int21[i][1],&int21[i][2],&int21[i][3],&int21[i][4],&int21[i][5],&int21[i][6],&int21[i][7],&int21[i][8],&int21[i][9],&int21[i][10],&int21[i][11],&int21[i][12],&int21[i][13],&int21[i][14],&int21[i][15],&int21[i][16],&int21[i][17],&int21[i][18],&int21[i][19],&int21[i][20],&int21[i][21],&int21[i][22],&int21[i][23]);
}
fclose(fp);
//store also in ORIG arrays
for(int i=0; i<LINES_INT21; i++)
{
for(int j=0; j<COLS_INT21; j++)
{
int21_ORIG[i][j] = int21[i][j];
}
}
//cout<<int21_ORIG[2][4];
}
void loadInt22(string fpath)
{
FILE *fp;
fp = fopen(fpath.c_str(),"r");
//numLines = getNumLines(fp);
//rewind(fp);
//cout<<numLines;
if(fp == NULL)
{cout<<"\n>>Error loading param files....exiting"; exit(0);}
for(int i=0; i < LINES_INT22; i++)
{
fscanf(fp, "%f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f", &int22[i][0], &int22[i][1], &int22[i][2], &int22[i][3], &int22[i][4], &int22[i][5], &int22[i][6], &int22[i][7], &int22[i][8], &int22[i][9], &int22[i][10], &int22[i][11], &int22[i][12], &int22[i][13], &int22[i][14], &int22[i][15]);
}
fclose(fp);
//store also in ORIG arrays
for(int i=0; i<LINES_INT22; i++)
{
for(int j=0; j<COLS_INT22; j++)
{
int22_ORIG[i][j] = int22[i][j];
}
}
}
void loadDangle(string fpath)
{
FILE *fp;
fp = fopen(fpath.c_str(),"r");
if(fp == NULL)
{cout<<"\n>>Error loading param files....exiting"; exit(0);}
for(int i=0; i< LINES_DANGLE; i++)
{
fscanf(fp,"%f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f",&dangle[i][0],&dangle[i][1],&dangle[i][2],&dangle[i][3],&dangle[i][4],&dangle[i][5],&dangle[i][6],&dangle[i][7],&dangle[i][8],&dangle[i][9],&dangle[i][10],&dangle[i][11],&dangle[i][12],&dangle[i][13],&dangle[i][14],&dangle[i][15]);
}
//cout<<dangle[7][15];
fclose(fp);
//store also in ORIG arrays
for(int i=0; i<LINES_DANGLE; i++)
{
for(int j=0; j<COLS_DANGLE; j++)
{
dangle_ORIG[i][j] = dangle[i][j];
}
}
}
void loadInt11(string fpath)
{
FILE *fp;
fp = fopen(fpath.c_str(),"r");
if(fp == NULL)
{cout<<"\n>>Error loading param files....exiting"; exit(0);}
for(int i=0; i<LINES_INT11; i++)
{
fscanf(fp, "%f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f", &int11[i][0], &int11[i][1],&int11[i][2],&int11[i][3],&int11[i][4],&int11[i][5],&int11[i][6],&int11[i][7],&int11[i][8],&int11[i][9],&int11[i][10],&int11[i][11],&int11[i][12],&int11[i][13],&int11[i][14],&int11[i][15],&int11[i][16],&int11[i][17],&int11[i][18],&int11[i][19],&int11[i][20],&int11[i][21],&int11[i][22],&int11[i][23]);
}
//cout<<int11[3][0];
fclose(fp);
//store also in ORIG arrays
for(int i=0; i<LINES_INT11; i++)
{
for(int j=0; j<COLS_INT11; j++)
{
int11_ORIG[i][j] = int11[i][j];
}
}
}
void loadLoop(string fpath)
{
FILE *fp;
fp = fopen(fpath.c_str(),"r");
if(fp == NULL)
{cout<<"\n>>Error loading param files....exiting"; exit(0);}
for(int i=0;i<LINES_LOOP;i++)
{
fscanf(fp, "%f %f %f %f",&loop[i][0], &loop[i][1],&loop[i][2], &loop[i][3]);
}
//cout<<loop[0][1];
fclose(fp);
//store also in ORIG arrays
for(int i=0; i<LINES_LOOP; i++)
{
for(int j=0; j<COLS_LOOP; j++)
{
loop_ORIG[i][j] = loop[i][j];
}
}
}
void loadStack(string fpath)
{
FILE *fp;
fp = fopen(fpath.c_str(),"r");
if(fp == NULL)
{cout<<"\n>>Error loading param files....exiting"; exit(0);}
for(int i=0; i< LINES_STACK; i++)
{
fscanf(fp,"%f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f",&stack[i][0],&stack[i][1],&stack[i][2],&stack[i][3],&stack[i][4],&stack[i][5],&stack[i][6],&stack[i][7],&stack[i][8],&stack[i][9],&stack[i][10],&stack[i][11],&stack[i][12],&stack[i][13],&stack[i][14],&stack[i][15]);
}
//cout<<stack[15][15];
fclose(fp);
//store also in ORIG arrays
for(int i=0; i<LINES_STACK; i++)
{
for(int j=0; j<COLS_STACK; j++)
{
stack_ORIG[i][j] = stack[i][j];
}
}
}
void loadTloop(string fpath)
{
FILE *fp;
fp = fopen(fpath.c_str(),"r");
if(fp == NULL)
{cout<<"\n>>Error loading param files....exiting"; exit(0);}
//make a temp char * string buffer
char tempStrTloop[LINES_TLOOP][7];
for(int i=0; i<LINES_TLOOP; i++)
{
fscanf(fp, "%s %f",tempStrTloop[i], &tloop[i]);
}
for(int i=0;i< LINES_LOOP; i++)
{
stringTloop[i].assign(tempStrTloop[i]);
}
fclose(fp);
//store also in ORIG arrays
for(int i=0; i<LINES_TLOOP; i++)
{
tloop_ORIG[i] = tloop[i];
}
for(int i=0; i<LINES_TLOOP; i++)
{
stringTloop_ORIG[i] = stringTloop[i];
}
}
void loadTstackh(string fpath)
{
FILE *fp;
fp = fopen(fpath.c_str(),"r");
if(fp == NULL)
{cout<<"\n>>Error loading param files....exiting"; exit(0);}
for(int i=0; i< LINES_TSTACKH; i++)
{
fscanf(fp,"%f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f",&tstackh[i][0],&tstackh[i][1],&tstackh[i][2],&tstackh[i][3],&tstackh[i][4],&tstackh[i][5],&tstackh[i][6],&tstackh[i][7],&tstackh[i][8],&tstackh[i][9],&tstackh[i][10],&tstackh[i][11],&tstackh[i][12],&tstackh[i][13],&tstackh[i][14],&tstackh[i][15]);
}
fclose(fp);
//store also in ORIG arrays
for(int i=0; i<LINES_TSTACKH; i++)
{
for(int j=0; j<COLS_TSTACKH; j++)
{
tstackh_ORIG[i][j] = tstackh[i][j];
}
}
}
void loadTstacki(string fpath)
{
FILE *fp;
fp = fopen(fpath.c_str(),"r");
if(fp == NULL)
{cout<<"\n>>Error loading param files....exiting"; exit(0);}
for(int i=0; i< LINES_TSTACKI; i++)
{
fscanf(fp,"%f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f",&tstacki[i][0],&tstacki[i][1],&tstacki[i][2],&tstacki[i][3],&tstacki[i][4],&tstacki[i][5],&tstacki[i][6],&tstacki[i][7],&tstacki[i][8],&tstacki[i][9],&tstacki[i][10],&tstacki[i][11],&tstacki[i][12],&tstacki[i][13],&tstacki[i][14],&tstacki[i][15]);
}
//cout<<tstacki[2][15];
fclose(fp);
//store also in ORIG arrays
for(int i=0; i<LINES_TSTACKI; i++)
{
for(int j=0; j<COLS_TSTACKI; j++)
{
tstacki_ORIG[i][j] = tstacki[i][j];
}
}
}
int main(int argc,char **argv)
{
///////////////////////////////////////////////////////////////////////////////
//------------------------ Some initialization code--------------------------//
//////////////////////////////////////////////////////////////////////////////
if(getCurrentWorkingDir() == "")
{
cout<<"\n>>Error getting Current Working Dir...exiting\n";
return 0;
}
CURRENT_WORKING_DIR = getCurrentWorkingDir();
RANDOMSEED = chrono::system_clock::now().time_since_epoch().count();
char tempBuffer[500];
logfile.open("Logfile.txt", ios::out | ios::app);
if(logfile.is_open())
{
//do nothing
}
else
{
cout<<"\n>>Error opening LogFile...exiting program";
return -1;
}
///////////////////////////////////////////////////////////////////////////////
//-------------------- Start GTMmain code block-----------------------------//
//////////////////////////////////////////////////////////////////////////////
//load from the current working directory the param files on start-up
string pathInt22 = CURRENT_WORKING_DIR+"/int22.DAT";
string pathInt21 = CURRENT_WORKING_DIR+"/int21.DAT";
string pathDangle = CURRENT_WORKING_DIR+"/dangle.DAT";
string pathInt11 = CURRENT_WORKING_DIR+"/int11.DAT";
string pathLoop = CURRENT_WORKING_DIR+"/loop.DAT";
string pathStack = CURRENT_WORKING_DIR+"/stack.DAT";
string pathTloop = CURRENT_WORKING_DIR+"/tloop.DAT";
string pathTstackh = CURRENT_WORKING_DIR+"/tstackh.DAT";
string pathTstacki = CURRENT_WORKING_DIR+"/tstacki.DAT";
loadInt22(pathInt22);
loadInt21(pathInt21);
loadDangle(pathDangle);
loadInt11(pathInt11);
loadLoop(pathLoop);
loadStack(pathStack);
loadTloop(pathTloop);
loadTstackh(pathTstackh);
loadTstacki(pathTstacki);
//start Reading Input
string choice;
do
{
cout<<"\n>>ROOT: Run (run), keep (m)odifying, (e)xit, (l)oad, (s)ave, (u)ndo: ";
cin >> choice;
if(choice == "run")
{
computeFunction();
}
if(choice == "m" || choice == "M")
{
readCategory();
}
if(choice == "s")
{
saveModule();
}
if(choice == "l")
{
loadModule();
}
if(choice == "u")
{
undoModule();
}
}while(choice == "m" || choice == "M" || choice == "run" || choice == "s" || choice == "l" || choice == "u");
exitFunction();
return 0;
}