Repository navigation
Expand file tree
/
Copy pathMain.cpp
More file actions
177 lines (135 loc) · 3.81 KB
/
Copy pathMain.cpp
File metadata and controls
177 lines (135 loc) · 3.81 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
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
//---------------------------------------------------------------------------
#include "Forest.h"
#include <time.h>
#include <string>
using std::string;
#include <fstream>
using std::ifstream;
#include <iostream>
using std::cout;
using std::cin;
using std::endl;
//---------------------------------------------------------------------------
int StringToInt(std::string S)
{
int result;
std::istringstream is(S);
is>>result;
return result;
}
int main(int argc, char* argv[])
{
string SettingsFileName = "Settings1";
//uniform initialization in C++11
string ParaFileName{"Para"};
//string ParaFileName{"ParaGS1"};
string InFileID{"1"};
string OutFileID{"1"};
if (argc == 2){
ParaFileName = argv[1];
}
if (argc == 3){
SettingsFileName = argv[1];
ParaFileName = argv[2];
}
if (argc == 4){
SettingsFileName = argv[1];
ParaFileName = argv[2];
OutFileID = InFileID = argv[3];
}
if (argc == 5){
SettingsFileName = argv[1];
ParaFileName = argv[2];
InFileID = argv[3];
OutFileID = argv[4];
}
SettingsFileName = "Input/" + SettingsFileName + ".txt";
CModelSettings* pSettings = new CModelSettings();
pSettings->ReadSettings(SettingsFileName);
ParaFileName = "Input/"+ParaFileName + InFileID +".csv";
ifstream InFile;
InFile.open(ParaFileName.c_str());
cout<<"Settings-File:\t"<<SettingsFileName<<endl;
cout<<"Parameter-File:\t"<<ParaFileName<<endl;
cout<<"Generations:\t"<<pSettings->nGen<<endl;
cout<<"Replicates:\t"<<pSettings->nRep<<endl;
time_t start, end;
start = time(0);
string line1;
getline(InFile,line1);
CPara* pPara = new CPara();
int seed = start + StringToInt(OutFileID);
//int seed = 99;
CForest* pForest = new CForest(seed, pSettings);
pForest->FileOpen(OutFileID);
int isim;
double jm;
char delim;
if (InFile.good()) {
//read first parameter set
InFile>>isim>>delim;
InFile>>pPara->theta>>delim;
InFile>>jm>>delim;
pPara->Jm = static_cast<int>(jm);
InFile>>pPara->metaSR>>delim;
InFile>>pPara->metaCV>>delim;
InFile>>pPara->m>>delim;
InFile>>pPara->r_max>>delim;
InFile>>pPara->aRec>>delim;
InFile>>pPara->aSurv>>delim;
InFile>>pPara->bSurv>>delim;
InFile>>pPara->m_dm_spec>>delim;
InFile>>pPara->sd_dm_spec>>delim;
InFile>>pPara->m_JCspec>>delim;
InFile>>pPara->cv_JCspec>>delim;
InFile>>pPara->niche_breadth>>delim;
InFile>>pPara->n_hills;
while (InFile.good()) {
cout<<"Sim "<<isim<<endl;
pForest->pPars = pPara;
//pForest->initSpecies();
//pForest->writeInteractMat(isim);
//pForest->writeSpecies(isim);
//run simulations
for (int irep=1; irep <= pSettings->nRep; ++irep) {
cout<<" Rep "<< irep <<endl;
pForest->initSpecies();
//pForest->writeInteractMat(isim, irep);
pForest->initTrees();
pForest->OneRun(OutFileID, isim, irep);
//pForest->GetPPA();
//pForest->writeSpecies(isim, irep);
pForest->clearTrees();
pForest->clearSpecies();
} // end irep
//pForest->clearSpecies();
//try to read new parameter set
InFile>>isim>>delim;
InFile>>pPara->theta>>delim;
InFile>>jm>>delim;
pPara->Jm = static_cast<int>(jm);
InFile>>pPara->metaSR>>delim;
InFile>>pPara->metaCV>>delim;
InFile>>pPara->m>>delim;
InFile>>pPara->r_max>>delim;
InFile>>pPara->aRec>>delim;
InFile>>pPara->aSurv>>delim;
InFile>>pPara->bSurv>>delim;
InFile>>pPara->m_dm_spec>>delim;
InFile>>pPara->sd_dm_spec>>delim;
InFile>>pPara->m_JCspec>>delim;
InFile>>pPara->cv_JCspec>>delim;
InFile>>pPara->niche_breadth>>delim;
InFile>>pPara->n_hills;
}
}
else cout<<"Error SimFile"<<endl;
delete pForest;
delete pPara;
delete pSettings;
end = time(0);
cout<<"\nRuntime: "<<end - start<<" seconds"<<endl;
cin.ignore();
return 0;
}
//---------------------------------------------------------------------------