-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBlueEdge_Plotter_V2.cpp
294 lines (210 loc) · 8.7 KB
/
BlueEdge_Plotter_V2.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
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
//V1: Currrently reading LINA data into arrays correctly, but if statement for outputting parameters at blue edge not working.
//Note: if statement worked when using 2D arrays (reading all of LINA data) and inside of NumOfModes loop..however outputted 10 times..did not work outside of loop.
//Note: From testing problem seems to be with outFile not the if statement? outFile worked when right before external loop test
//Note: WORKAROUND - works when no header is added to outputfile. Why? Who knows.. Working program!
//V2: Goal is to add graphics to program so HR diagram of blue edge can be plotted.
//Note: Graphics not working, Root isnt finding the points? Fixed this! Problem was in selectors
//Note: Root cant have x-axis go from highest to lowest? Maybe we dont use root?
# include <iostream>
# include <fstream>
# include <math.h>
# include <iomanip>
# include <cmath>
# include <stdlib.h>
# include <cstdlib>
//# include <fstream.h>
# include <string.h>
# include <string>
//# include <dos.h> //For Sleep()
using namespace std;
int main() {
ifstream inFile;
//Controls//
int NumOfModels = 1000; //20412 is total TypeII models
int NumOfModes = 10;
int NumOfSpaces = 1; // Number of spaces between each models output
char inputFileName[30] = "InputDataFULL.dat"; //File with the model parameters
char outputFileName[30] = "BlueEdgeTest.dat"; //File with organized output
char LINAFileName[30] = "LINA_period_growth.data"; //Normally should be "LINA_period_growth.data"
char log_directory_prefix[30] = "Raw_LINA_data/SetA/LOGS_"; //Prefix to log_directory, suffix is model number. This is where LINA file should be
///////////////////////////////
//Arrays//
const int nArray = NumOfModels + 1;
const int nArray_modes = NumOfModes + 1;
double Mod[nArray];
double z[nArray];
double x[nArray];
double M[nArray];
double L[nArray];
double T[nArray];
double L_Blue[nArray];
double T_Blue[nArray];
double mode[nArray];
double period[nArray];
double growth[nArray];
/////////////////////////////////////////
//Reading input parameters from file into arrays//
inFile.open(inputFileName,ios::in);
// Warning if file cant be opened
if(!inFile.is_open()){
cout << "Error opening file. \n";
//cout << "Giving Retry... \n";
}
if(inFile.is_open()){
cout<<"Input File was opened successfully"<<endl;
}
if(inFile.good()){
cout<<"Input File is ready for reading"<<endl;
}
//reading file
if(inFile.is_open()){
// Putting cursor at start of file
inFile.clear();
//Reading first line - This is needed outside loop otherwise array won't fill.
inFile >> Mod[0] >> z[0] >> x[0] >> M[0] >> L[0] >> T[0];
cout<<"Model"<<setw(10)<<"z"<<setw(15)<<"x"<<setw(15)<<"M"<<setw(15)<<"L"<<setw(15)<<"T"<<endl;
cout<<Mod[0]<<setw(15)<<z[0]<<setw(15)<<x[0]<<setw(15)<<M[0]<<setw(15)<<L[0]<<setw(15)<<T[0]<<endl;
for (int a = 1; a < NumOfModels; a++){
// Reading rest of file
inFile >> Mod[a] >> z[a] >> x[a] >> M[a] >> L[a] >> T[a];
//cout<<Mod[a]<<setw(15)<<z[a]<<setw(15)<<x[a]<<setw(15)<<M[a]<<setw(15)<<L[a]<<setw(15)<<T[a]<<endl;
}
//To show last and first index only, have this line uncommmented and the cout line in loop commented
cout<<Mod[NumOfModels-1]<<setw(15)<<z[NumOfModels-1]<<setw(15)<<x[NumOfModels-1]<<setw(15)<<M[NumOfModels-1]<<setw(15)<<L[NumOfModels-1]<<setw(15)<<T[NumOfModels-1]<<endl;
// Close the file.
inFile.close();
}
if(!inFile.is_open()){
cout<<"Input File closed successfully"<<endl;
}
////////////////////////////////////////
cout<<"Creating output file"<<endl;
ofstream outFile(outputFileName);
//outFile<<"Model"<<setw(10)<<"z"<<setw(15)<<"x"<<setw(15)<<"M"<<setw(15)<<"L"<<setw(15)<<"T"<<endl; //Header
//outFile<<""<<endl;
////////////////////////////////////
//Variables to keep track of stuff
int LINAi = 0;
int BlueEdgei = 0;
int NumOfFailedModels = 0;
int NumOfBlueEdgePoints = 0;
double LowestTemp_Blue = 10000;
double HighestTemp_Blue = 0;
double LowestLum_Blue = 10000;
double HighestLum_Blue = 0;
//Start of outside loop, steping through input data
for(int i = 0; i < NumOfModels; i++){
/////Reading LINA file////////
//Getting model number into string
stringstream stream;
stream<<Mod[i];
string Model = stream.str();
//cout<<"Current Model in string form: "<<Model<<endl;
string LINA_header; //Varible for header of LINA file
string readout; //String thats viewing each line
char LINAFilePath[50]; //log_directory_prefix + Model + "/" + LINAFileName;
strcpy(LINAFilePath, log_directory_prefix);
strcat(LINAFilePath, Model.c_str());
strcat(LINAFilePath, "/");
strcat(LINAFilePath, LINAFileName);
cout<<"Path to LINA file: "<<LINAFilePath<<endl;
inFile.open(LINAFilePath,ios::in);
// Warning if file cant be opened
if(!inFile.is_open()){
cout << "Error opening LINA file. Model did not run. \n";
NumOfFailedModels = NumOfFailedModels + 1;
}
if(inFile.is_open()){
cout<<"LINA File was opened successfully"<<endl;
}
if(inFile.good()){
cout<<"LINA File is being read..."<<endl;
//loop that reads LINA file into temp arrays, saving L and T of input file if Blue Edge
getline(inFile,LINA_header);
cout<<LINA_header<<endl;
inFile>>mode[LINAi]>>period[LINAi]>>growth[LINAi];
cout<<setw(3)<<mode[LINAi]<<setw(17)<<period[LINAi]<<setw(17)<<growth[LINAi]<<endl;
// for(int l = 1; l < NumOfModes; l++){
// inFile>>mode[i]>>period[i]>>growth[i];
// cout<<setw(3)<<mode[i]<<setw(17)<<period[i]<<setw(17)<<growth[i]<<endl;
// }
//if f0 is negative and last was positive, then output model parameters and assign T and L to blue edge arrays
if(LINAi != 0){
if(growth[LINAi] < 0. && growth[LINAi-1] > 0.){
outFile<<Mod[i]<<setw(15)<<z[i]<<setw(15)<<x[i]<<setw(15)<<M[i]<<setw(15)<<L[i]<<setw(15)<<T[i]<<endl;
L_Blue[BlueEdgei] = L[i];
T_Blue[BlueEdgei] = T[i];
//Selectors to keep track of graphics limits
if(L_Blue[BlueEdgei] > HighestLum_Blue){
HighestLum_Blue = L_Blue[BlueEdgei];
}
if(L_Blue[BlueEdgei] < LowestLum_Blue){
LowestLum_Blue = L_Blue[BlueEdgei];
}
if(T_Blue[BlueEdgei] > HighestTemp_Blue){
HighestTemp_Blue = T_Blue[BlueEdgei];
}
if(T_Blue[BlueEdgei] < LowestTemp_Blue){
LowestTemp_Blue = T_Blue[BlueEdgei];
}
BlueEdgei = BlueEdgei + 1;
NumOfBlueEdgePoints = NumOfBlueEdgePoints + 1;
}
}
LINAi = LINAi + 1; //Incrementing LINAi
//Space loop - puts space between each model
// for(int s = 0; s < NumOfSpaces; s++){
// outFile<<""<<endl;
// }
inFile.close();
if(!inFile.is_open()){
cout<<"LINA File closed successfully"<<endl;
}
}
}
cout<<"NumOfBlueEdgePoints: "<<NumOfBlueEdgePoints<<endl;
////////////////////////////////////
// cout<<"Creating output file"<<endl;
// ofstream outFile(outputFileName);
// outFile<<"Model"<<setw(10)<<"z"<<setw(15)<<"x"<<setw(15)<<"M"<<setw(15)<<"L"<<setw(15)<<"T"<<endl; //Header
// outFile<<""<<endl;
////////////////////////////////////
///Test loop for LINA data
// int LINAi_max = LINAi;
// for(int l = 0; l < LINAi_max; l++){
// cout<<setw(3)<<mode[l]<<setw(17)<<period[l]<<setw(17)<<growth[l]<<endl;
// if(l != 0){
// if(growth[l-1] > 0 && growth[l] < 0){
// outFile<<Mod[i]<<setw(15)<<z[i]<<setw(15)<<x[i]<<setw(15)<<M[i]<<setw(15)<<L[i]<<setw(15)<<T[i]<<endl;
// L_Blue[i] = L[i];
// T_Blue[i] = T[i];
// }
// }
// }
////////////////////////////////////////
///Root Graphics///
//create first canvas
TCanvas *c1 = new TCanvas("c1","Blue Edge",200,10,700,500);
c1->SetFillColor(10);
c1->SetGrid();
c1->GetFrame()->SetFillColor(10);
c1->GetFrame()->SetBorderSize(12);
c1->Range(0,0,1,1);
gStyle->SetOptStat(0);
//draw a frame to define the horizontal and vertical scales
TH1F *hr1 = c1->DrawFrame(4000, LowestLum_Blue - 100, 8000, HighestLum_Blue + 100);
hr1->SetXTitle("Temperature (K)");
hr1->SetYTitle("Luminosity");
// create first graph
TGraphErrors *gr1 = new TGraphErrors(NumOfBlueEdgePoints,T_Blue,L_Blue,0,0);
gr1->SetMarkerColor(kBlue);
gr1->SetMarkerSize(0.75); //0.75
gr1->SetMarkerStyle(20);
gr1->SetName("gr1");
gr1->Draw("P");
// leg = new TLegend(0.6,0.7,0.9,0.9);
// leg->SetHeader("Free Fall Calculation");
// leg->AddEntry("gr1","Vertical Position","P");
// leg->Draw();
return 0;
}