127
127
class SubsystemMaterial {
128
128
public:
129
129
std::string subsystemId;
130
- std::string type; // Material type
130
+ std::string type;
131
131
std::vector<double > properties;
132
- // std::vector<std::pair<double, double>> freqProperties;
133
132
std::map<int , std::vector<std::pair<double , double >>> freqProperties;
134
133
135
134
SubsystemMaterial (std::string id, std::string tp)
@@ -139,18 +138,16 @@ class SubsystemMaterial {
139
138
class MatFileReader {
140
139
private:
141
140
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;
144
143
public:
145
144
146
- // Function to check if a string is numeric (simple version)
147
145
bool isNumeric (const std::string& str) {
148
146
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 ' ;
151
149
}
152
150
153
- // Function to parse a line containing mixed data and tags
154
151
void parseLine (const std::string& line) {
155
152
std::istringstream iss (line);
156
153
std::string field;
@@ -159,16 +156,12 @@ class MatFileReader {
159
156
160
157
while (iss >> field) {
161
158
if (isNumeric (field)) {
162
- // Convert and store numeric value
163
159
numbers.push_back (std::strtod (field.c_str (), nullptr ));
164
160
}
165
161
else {
166
- // Store tag directly
167
162
tags.push_back (field);
168
163
}
169
164
}
170
-
171
- // Example output to demonstrate parsing
172
165
std::cout << " Numbers: " ;
173
166
for (double num : numbers) {
174
167
std::cout << num << " " ;
@@ -190,7 +183,7 @@ class MatFileReader {
190
183
}
191
184
192
185
bool inFreqValSection = false ;
193
- int freqValIndex = 0 ; // Index to track frequency-dependent sections
186
+ int freqValIndex = 0 ;
194
187
std::string currentSubsystemId;
195
188
std::string currentType;
196
189
int lineCount = 1 ;
@@ -209,48 +202,43 @@ class MatFileReader {
209
202
210
203
if (!line.empty () && line[0 ] != ' (' && line[0 ] != ' !' && lineCount == 1 ) {
211
204
212
- // Read subsystem ID and type
213
205
iss >> currentSubsystemId >> currentType;
214
206
materials.insert ({ currentSubsystemId, SubsystemMaterial (currentSubsystemId, currentType) });
215
207
lineCount = 2 ;
216
208
continue ;
217
209
}
218
210
std::vector<int > tempFreqValTableId;
219
211
if (!line.empty () && line[0 ] != ' (' && line[0 ] != ' !' && lineCount == 2 ) {
220
- // Read properties
221
212
222
213
std::string field;
223
214
std::vector<double > numbers;
224
215
std::vector<std::pair<std::string, std::string>> tags;
225
216
while (iss >> field) {
226
217
auto it = materials.find (currentSubsystemId);
227
218
if (isNumeric (field)) {
228
- // Convert and store numeric value
229
219
it->second .properties .push_back (std::strtod (field.c_str (), nullptr ));
230
220
}
231
221
else {
232
- // Store tag directly
233
- tags.emplace_back (currentSubsystemId,field );
222
+ tags.emplace_back (currentSubsystemId, field);
234
223
}
235
224
}
236
225
lineCount = 1 ;
237
226
}
238
- // Detecting frequency-dependent section
239
227
if (line.find (" (FREQVAL" ) != std::string::npos) {
240
228
inFreqValSection = true ;
241
229
std::string nextLine;
242
230
getline (file, nextLine);
243
231
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;
246
234
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
+ }
250
239
double freq, val;
251
240
std::istringstream issNextLineAgain (nextLine);
252
241
issNextLineAgain >> freq >> val;
253
- // freqValTables[freqValIndex].emplace_back(freq, val);
254
242
freqValTables0.emplace_back (freq, val);
255
243
256
244
}
0 commit comments