-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDRTypeFinder_V1.cpp
224 lines (170 loc) · 4.86 KB
/
DRTypeFinder_V1.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
// Program to read from file into arrays, and to output values for D/R type analysis
// V1: Copy of program ReadingFromFileIntoArrays_V4, fitted to do stuff with the arrays, output results
// Note: Temp and temp zone findings not working right? Keeps getting either 0 or last num.
# include <iostream>
# include <fstream>
# include <math.h>
# include <iomanip>
# include <cmath>
# include <stdlib.h>
# include <cstdlib>
using namespace std;
int main(){
///// Controls /////
const int NumOfZones = 300;
const int nArray = NumOfZones + 1;
int NumOfFiles;
cout<<"Enter the number of files to read (Usually 5): "<<endl;
cin>>NumOfFiles;
ifstream infile;
double Mdis;
double rho;
double pressure;
double vel_km_per_s;
double Temp;
double Mdis[nArray];
double rho[nArray];
double pressure[nArray];
double vel_km_per_s[nArray];
double Temp[nArray];
////////// Reading Files into Arrays ////////////
for(int i = 0; i < NumOfFiles; i++){
///// Finding File //////
int TryAgain = 1;
while(TryAgain == 1){
char InputFileName[30];
cout<<"Enter Input File "<<i+1<<"s Name (Max Char=30): "<<endl;
cin>>InputFileName;
infile.open(InputFileName);
// Warning if file cant be opened
if(!infile.is_open()){
cout << "Error opening file. \n";
cout << "Giving Retry... \n";
}
if(infile.is_open()){
cout<<"File was opened successfully"<<endl;
TryAgain = 0;
}
}
if(infile.is_open()){
//cout<<"Enter the output file name: "<<endl;
//ofstream outputfile1("FreeFall_Analytical_wArrays_output.dat");
// Putting cursor at start of file
infile.clear();
// Mdis loop //
if(i == 0){
for (int a = 0; a < NumOfZones; a++){
infile >> Mdis[a];
cout<<Mdis[a]<<endl;
}
}
// rho loop //
if(i == 1){
for (int a = 0; a < NumOfZones; a++){
infile >> rho[a];
cout<<rho[a]<<endl;
}
}
// pressure loop //
if(i == 2){
for (int a = 0; a < NumOfZones; a++){
infile >> pressure[a];
cout<<pressure[a]<<endl;
}
}
// vel_km_per_s loop //
if(i == 3){
for (int a = 0; a < NumOfZones; a++){
infile >> vel_km_per_s[a];
cout<<vel_km_per_s[a]<<endl;
}
}
// Temp loop //
if(i == 4){
for (int a = 0; a < NumOfZones; a++){
infile >> Temp[a];
cout<<Temp[a]<<endl;
}
}
}
// Close the file.
infile.close();
if(!infile.is_open()){
cout<<"File closed successfully"<<endl;
}
Space(2);
}
///////////////////////////////////////////////////////////////////////
//// Making Output arrays ////
double To;
double Ti;
// Note: Program picks first number after specified values for temp
cout<<"Enter the temp for the neutral side:"<<endl;
cin>>To;
// Temp Finder Loop 1 - Neutral side
for(int T1 = 0; T1 < NumOfZones && Temp[T1] < To; T1++){
double To_found = Temp[T1];
double To_zone = T1 + 1;
}
cout<<"To_found: "<<To_found<<endl;
cout<<"To_zone: "<<To_zone<<endl;
Space(1);
cout<<"Enter the temp for the ionized side:"<<endl;
cin>>Ti;
// Temp Finder Loop 2 - Ionized side
for(int T2 = 0; T2 < NumOfZones && Temp[T2] < Ti; T2++){
double Ti_found = Temp[T2];
double Ti_zone = T2 + 1;
}
cout<<"Ti_found: "<<Ti_found<<endl;
cout<<"Ti_zone: "<<Ti_zone<<endl;
Space(1);
Space(1);
int Response1 = 0;
while(Response1 != 1){
cout<<"Enter the desired output file name (Max Char=30): "<<endl;
char OutputFileName[30];
cin>>OutputFileName;
Space(1);
cout<<"Is this correct? Enter 1 for yes and 0 for no."<<endl;
cout<<"File name: "<<OutputFileName<<endl;
cin>>Response1;
Space(1);
}
ofstream outputfile1(OutputFileName);
if(outputfile1){
cout<<"File created successfully"<<endl;
Space(2);
}
const int nArray2 = nArray - Ti_zone;
double Co[nArray2];
double Ci[nArray2];
double Vo[nArray2];
double Vd[nArray2];
double Vr[nArray2];
////// Calculations ///////
double Co = sqrt(pressure[To_zone]/rho[To_zone]);
double Vo = vel_km_per_s[Ti_Zone];
outputfile1<<"Co"<<endl;
outputfile1<<Co<<endl;
outputfile1<<"Vo"<<endl;
outputfile1<<Vo<<endl;
// Calculation loop, starting at Ti_zone that was found
outputfile1<<"Co"<<setw(10)<<"Vo"<<setw(10)<<"Ci"<<setw(10)<<"Vd"<<setw(10)<<"Vr"<<endl;
for(int c = Ti_zone; c < NumOfZones; c++){
Co[c] = Co;
Vo[c] = Vo;
Ci[c] = sqrt(pressure[c]/rho[c]);
Vd[c] = Ci[c] - sqrt((Ci[c]*Ci[c])-(Co*Co));
Vr[c] = Ci[c] + sqrt((Ci[c]*Ci[c])-(Co*Co));
outputfile1<<Co[c]<<setw(10)<<Vo[c]<<setw(10)<<Ci[c]<<setw(10)<<Vd[c]<<setw(10)<<Vr[c]<<endl;
}
return 0;
}
void Space(int Size){
int i = 0;
while (i < Size){
cout<<" "<<endl;
i = i + 1;
}
}