Skip to content

Commit ccaed43

Browse files
author
PROG\yxiong
committed
clean comments and format file.
1 parent a7e0048 commit ccaed43

File tree

1 file changed

+13
-25
lines changed

1 file changed

+13
-25
lines changed

MatFileReader.h

+13-25
Original file line numberDiff line numberDiff line change
@@ -127,9 +127,8 @@
127127
class SubsystemMaterial {
128128
public:
129129
std::string subsystemId;
130-
std::string type; // Material type
130+
std::string type;
131131
std::vector<double> properties;
132-
//std::vector<std::pair<double, double>> freqProperties;
133132
std::map<int, std::vector<std::pair<double, double>>> freqProperties;
134133

135134
SubsystemMaterial(std::string id, std::string tp)
@@ -139,18 +138,16 @@ class SubsystemMaterial {
139138
class MatFileReader {
140139
private:
141140
std::map<std::string, SubsystemMaterial> materials;
142-
std::map<int, std::vector<std::pair<double, double>>> freqValTables; // Map to store frequency values by index
143-
std::vector<std::pair<double, double>> freqValTables0;
141+
std::map<int, std::vector<std::pair<double, double>>> freqValTables;
142+
std::vector<std::pair<double, double>> freqValTables0;
144143
public:
145144

146-
// Function to check if a string is numeric (simple version)
147145
bool isNumeric(const std::string& str) {
148146
char* end;
149-
std::strtod(str.c_str(), &end); // Use strtod to try to convert the string to a double
150-
return end != str.c_str() && *end == '\0'; // Check if conversion was successful and consumed the entire string
147+
std::strtod(str.c_str(), &end);
148+
return end != str.c_str() && *end == '\0';
151149
}
152150

153-
// Function to parse a line containing mixed data and tags
154151
void parseLine(const std::string& line) {
155152
std::istringstream iss(line);
156153
std::string field;
@@ -159,16 +156,12 @@ class MatFileReader {
159156

160157
while (iss >> field) {
161158
if (isNumeric(field)) {
162-
// Convert and store numeric value
163159
numbers.push_back(std::strtod(field.c_str(), nullptr));
164160
}
165161
else {
166-
// Store tag directly
167162
tags.push_back(field);
168163
}
169164
}
170-
171-
// Example output to demonstrate parsing
172165
std::cout << "Numbers: ";
173166
for (double num : numbers) {
174167
std::cout << num << " ";
@@ -190,7 +183,7 @@ class MatFileReader {
190183
}
191184

192185
bool inFreqValSection = false;
193-
int freqValIndex = 0; // Index to track frequency-dependent sections
186+
int freqValIndex = 0;
194187
std::string currentSubsystemId;
195188
std::string currentType;
196189
int lineCount = 1;
@@ -209,48 +202,43 @@ class MatFileReader {
209202

210203
if (!line.empty() && line[0] != '(' && line[0] != '!' && lineCount == 1) {
211204

212-
// Read subsystem ID and type
213205
iss >> currentSubsystemId >> currentType;
214206
materials.insert({ currentSubsystemId, SubsystemMaterial(currentSubsystemId, currentType) });
215207
lineCount = 2;
216208
continue;
217209
}
218210
std::vector<int> tempFreqValTableId;
219211
if (!line.empty() && line[0] != '(' && line[0] != '!' && lineCount == 2) {
220-
// Read properties
221212

222213
std::string field;
223214
std::vector<double> numbers;
224215
std::vector<std::pair<std::string, std::string>> tags;
225216
while (iss >> field) {
226217
auto it = materials.find(currentSubsystemId);
227218
if (isNumeric(field)) {
228-
// Convert and store numeric value
229219
it->second.properties.push_back(std::strtod(field.c_str(), nullptr));
230220
}
231221
else {
232-
// Store tag directly
233-
tags.emplace_back(currentSubsystemId,field );
222+
tags.emplace_back(currentSubsystemId, field);
234223
}
235224
}
236225
lineCount = 1;
237226
}
238-
// Detecting frequency-dependent section
239227
if (line.find("(FREQVAL") != std::string::npos) {
240228
inFreqValSection = true;
241229
std::string nextLine;
242230
getline(file, nextLine);
243231
std::istringstream issNextLine(nextLine);
244-
issNextLine >> std::ws; // Eat up any leading whitespace
245-
issNextLine >> freqValIndex; // Read the frequency table index
232+
issNextLine >> std::ws;
233+
issNextLine >> freqValIndex;
246234
while (getline(file, nextLine)) {
247-
if (nextLine[0] == ')' && nextLine[1] != ')') {
248-
lineCount = 1;
249-
break; }
235+
if (nextLine[0] == ')' && nextLine[1] != ')') {
236+
lineCount = 1;
237+
break;
238+
}
250239
double freq, val;
251240
std::istringstream issNextLineAgain(nextLine);
252241
issNextLineAgain >> freq >> val;
253-
//freqValTables[freqValIndex].emplace_back(freq, val);
254242
freqValTables0.emplace_back(freq, val);
255243

256244
}

0 commit comments

Comments
 (0)