-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMain.cpp
124 lines (95 loc) · 2.42 KB
/
Main.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
//---------------------------------------------------------------------------
#include "Forest.h"
#include <time.h>
#include <string>
using namespace std;
//---------------------------------------------------------------------------
int StringToInt(std::string S)
{
int result;
std::istringstream is(S);
is>>result;
return result;
}
int main(int argc, char* argv[])
{
int SquareSize = 20;
int NRep = 30; //number replicates
bool StepsOut = true;
string SimFileName = "Para";
string FileLabel = "1";
if (argc == 2){
SimFileName = argv[1];
}
if (argc == 3){
SimFileName = argv[1];
FileLabel = argv[2];
}
if (argc == 4){
SimFileName = argv[1];
FileLabel = argv[2];
NRep = StringToInt(argv[3]);
}
if (argc == 5){
SimFileName = argv[1];
FileLabel = argv[2];
NRep = StringToInt(argv[3]);
SquareSize = StringToInt(argv[4]);
}
SimFileName = "InOut/"+SimFileName + FileLabel +".txt";
ifstream InFile;
InFile.open(SimFileName.c_str());
cout<<"Input-File:\t"<<SimFileName<<endl;
cout<<"Sim-Label:\t"<<FileLabel<<endl;
cout<<"Size of squares:\t"<<SquareSize<<endl;
time_t start, end;
start = time(0);
string line1;
getline(InFile,line1);
CPara* pPara = new CPara();
int seed = (int) start;
//int seed = 99;
CForest* pForest = new CForest(seed, SquareSize, StepsOut);
pForest->FileOpen(FileLabel);
int isim;
if (InFile.good()) {
//read first parameter set
InFile>>isim;
InFile>>pPara->Tmax;
InFile>>pPara->pImmi;
InFile>>pPara->pMortRec;
InFile>>pPara->pLDD;
InFile>>pPara->meanDisp;
InFile>>pPara->sdDisp;
InFile>>pPara->Scenario;
pPara->GetDispPars();
while (InFile.good()) {
cout<<"Sim "<<isim<<endl;
pForest->Pars = pPara;
//run simulations
for (int irep=1; irep <= NRep; ++irep) {
cout<<" Rep "<<irep<<endl;
pForest->OneRun(isim, irep, FileLabel);
pForest->ClearForest();
} // end irep
//try to read new parameter set
InFile>>isim;
InFile>>pPara->Tmax;
InFile>>pPara->pImmi;
InFile>>pPara->pMortRec;
InFile>>pPara->pLDD;
InFile>>pPara->meanDisp;
InFile>>pPara->sdDisp;
InFile>>pPara->Scenario;
pPara->GetDispPars();
}
}
else cout<<"Error SimFile"<<endl;
delete pForest;
delete pPara;
end = time(0);
cout<<"\nRuntime: "<<end - start<<" seconds"<<endl;
cin.ignore();
return 0;
}
//---------------------------------------------------------------------------