-
Notifications
You must be signed in to change notification settings - Fork 0
/
DRTypeFinder_V5.cpp
231 lines (172 loc) · 6.16 KB
/
DRTypeFinder_V5.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
// 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.
// V2: Goal is to fix problems with V1 and make working program. -Still not fixed, arrays are being filled with last number in file.
// V3: Reworking reading from files to reading from one file-> this works
// Note: It seems array is being completely filled from 0 to nArray with each entry from file each iteration.
// V4: Fixed the arrays! Seems array needed at least one index filled before being filled.
// V5: Program is now working.
//Note: Truncated files will result in truncated results!!
//Note: sqrt function giving different numbers here then in excel?
# 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 = 1;
//cout<<"Enter the number of files to read (Usually 5): "<<endl;
//cin>>NumOfFiles;
ifstream inFile;
double Mdis1;
double rho1;
double pressure1;
double vel_km_per_s1;
double Temp1;
double Mdis[nArray];
double rho[nArray];
double pressure[nArray];
double vel_km_per_s[nArray];
double Temp[nArray];
////////// Reading Files into Arrays ////////////
cout<<"This program takes a file with columns Mdis, rho, pressure, vel_km_per_s, temperature that is placed in its directory."<<endl;
//for(int i = 0; i < NumOfFiles; i++){
///// Finding File //////
int TryAgain = 1;
while(TryAgain == 1){
char InputFileName[30];
cout<<"Enter Input Files Name (Max Char=30): "<<endl;
cin>>InputFileName;
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<<"File was opened successfully"<<endl;
TryAgain = 0;
}
if(inFile.good()){
cout<<"File is ready for reading"<<endl;
}
}
//reading file
if(inFile.is_open()){
// Putting cursor at start of file
inFile.clear();
inFile >> Mdis[0] >> rho[0] >> pressure[0] >> vel_km_per_s[0] >> Temp[0];
cout<<"zone"<<setw(10)<<"Mdis"<<setw(15)<<"rho"<<setw(15)<<"pressure"<<setw(15)<<"vel_km_per_s"<<setw(15)<<"Temp"<<endl;
for (int a = 1; a <= NumOfZones; a++){
inFile >> Mdis[a] >> rho[a] >> pressure[a] >> vel_km_per_s[a] >> Temp[a];
cout<<(a+1)<<setw(10)<<Mdis[a]<<setw(15)<<rho[a]<<setw(15)<<pressure[a]<<setw(15)<<vel_km_per_s[a]<<setw(15)<<Temp[a]<<endl;
//test loop
// cout<<"Lookup table test inside loop..."<<endl;
// for(int b = 0; b < nArray; b++){
// cout<<Mdis[b]<<setw(15)<<rho[b]<<setw(15)<<pressure[b]<<setw(15)<<vel_km_per_s[b]<<setw(15)<<Temp[b]<<endl;
// }
}
// Close the file.
inFile.close();
}
if(!inFile.is_open()){
cout<<"File closed successfully"<<endl;
}
//test loop
cout<<"Lookup table test..."<<endl;
for(int a = 0; a < NumOfZones; a++){
cout<<(a+1)<<setw(10)<<Mdis[a]<<setw(15)<<rho[a]<<setw(15)<<pressure[a]<<setw(15)<<vel_km_per_s[a]<<setw(15)<<Temp[a]<<endl;
}
Space(2);
//}
///////////////////////////////////////////////////////////////////////
//// Making Output arrays ////
double To;
double Ti;
// Note: Program picks first number before specified values for temp
cout<<"Enter the temp for the neutral side:"<<endl;
cin>>To;
// Temp Finder Loop 1 - Neutral side
for(int a = 0; a < nArray && Temp[a] < To; a++){
double To_found = Temp[a];
int To_zone = a + 1;
cout<<"To_found: "<<To_found<<endl;
cout<<"To_zone: "<<To_zone<<endl;
}
cout<<"Final To_found: "<<To_found<<endl;
cout<<"Final 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 a = 0; a < nArray && Temp[a] < Ti; a++){
double Ti_found = Temp[a];
int Ti_zone = a + 1;
cout<<"Ti_found: "<<Ti_found<<endl;
cout<<"Ti_zone: "<<Ti_zone<<endl;
}
cout<<"Final Ti_found: "<<Ti_found<<endl;
cout<<"Final 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;
}
if(outputfile1.good()){
cout<<OutputFileName<<" is ready"<<endl;
Space(1);
}
//const int nArray2 = nArray - Ti_zone;
double Co;
double Vo;
double Co[nArray];
double Ci[nArray];
double Vo[nArray];
double Vd[nArray];
double Vr[nArray];
////// Calculations ///////
double Co = sqrt(pressure[To_zone-1]/rho[To_zone-1]);
double Vo = vel_km_per_s[To_zone-1];
outputfile1<<setw(2)<<"N_zone"<<setw(25)<<"Co"<<setw(25)<<"Vo"<<endl;
outputfile1<<setw(2)<<To_zone<<setprecision(17)<<setw(25)<<Co<<setw(25)<<setw(25)<<Vo<<endl;
// Calculation loop, starting at Ti_zone that was found
outputfile1<<setw(2)<<"zone"<<setw(25)<<"Ci"<<setw(25)<<"Vd"<<setw(25)<<"Vr"<<endl;
for(int c = Ti_zone-1; 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<<setw(2)<<(c+1)<<setprecision(17)<<setw(25)<<Ci[c]<<setw(25)<<Vd[c]<<setw(25)<<Vr[c]<<endl;
}
outputfile1.close();
if(!outputfile1.is_open()){
cout<<"File was filled and closed successfully"<<endl;
}
return 0;
}
void Space(int Size){
int i = 0;
while (i < Size){
cout<<" "<<endl;
i = i + 1;
}
}