-
Notifications
You must be signed in to change notification settings - Fork 0
/
readData.h
66 lines (58 loc) · 2.29 KB
/
readData.h
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
#pragma once
#include "Coef.hpp"
#include <fstream>
#include <sstream>
#include <string>
void readData(std::string nameFile) {
std::ifstream inFile(nameFile);
if (inFile.is_open()) {
std::string line;
while (getline(inFile, line)) {
std::stringstream ss(line);
std::string valueString, nameString;
double value;
ss >> valueString >> nameString;
try {
value = std::stod(valueString);
}
catch (const std::invalid_argument& e) {
std::cerr << "Invalid argument: " << e.what() << '\n';
continue;
}
if (nameString == "<BurnRateCoef>")
KNDX_PROPELLANT[BurnRateCoef] = value;
else if (nameString == "<BurnRateExponent>")
KNDX_PROPELLANT[BurnRateExponent] = value;
else if (nameString == "<Density>")
KNDX_PROPELLANT[Density] = value;
else if (nameString == "<CombustionTemperature>")
KNDX_PROPELLANT[CombustionTemperature] = value;
else if (nameString == "<SpecificHeatRatio>")
KNDX_PROPELLANT[SpecificHeatRatio] = value;
else if (nameString == "<ExchaustMolarMass>")
KNDX_PROPELLANT[ExchaustMolarMass] = value;
else if (nameString == "<GasConstant>")
KNDX_PROPELLANT[GasConstant] = value;
else if (nameString == "<NumberOfGrains>")
GRAIN[NumberOfGrains] = value;
else if (nameString == "<NumberOfGaps>")
GRAIN[NumberOfGaps] = value;
else if (nameString == "<Gap>")
GRAIN[Gap] = value;
else if (nameString == "<InnerDiametre>")
GRAIN[InnerDiametre] = value;
else if (nameString == "<OutDiametre>")
GRAIN[OutDiametre] = value;
else if (nameString == "<Length>")
GRAIN[Length] = value;
else {
std::cerr << "Unknown coefficient name: " << nameString << '\n';
continue;
}
}
inFile.close();
}
else {
std::cerr << "Unable to open file: " << nameFile << '\n';
}
}