Skip to content

Commit c9048d3

Browse files
committed
improve dat import
1 parent 3f37895 commit c9048d3

1 file changed

Lines changed: 15 additions & 5 deletions

File tree

openglider/airfoil/profile_2d.py

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
# You should have received a copy of the GNU General Public License
1919
# along with OpenGlider. If not, see <http://www.gnu.org/licenses/>.
2020
import os
21+
import re
2122
import math
2223
import numpy as np
2324
import tempfile
@@ -138,6 +139,9 @@ def __iadd__(self, other):
138139
point[1] += other[other(x)][1]
139140
return self
140141

142+
_re_number = r"([-+]?\d*\.\d*(?:[eE][+-]?\d+)?|\d+)"
143+
_re_coord_line = re.compile(rf"\s*{_re_number}\s+{_re_number}\s*")
144+
141145
@classmethod
142146
def import_from_dat(cls, path):
143147
"""
@@ -146,12 +150,18 @@ def import_from_dat(cls, path):
146150
profile = []
147151
name = 'imported from {}'.format(path)
148152
with open(path, "r") as p_file:
149-
for line in p_file:
150-
split_line = line.split()
151-
if len(split_line) == 2:
152-
profile.append([float(i) for i in split_line])
153-
else:
153+
for i, line in enumerate(p_file):
154+
if line.endswith(","):
155+
line = line[:-1]
156+
157+
match = cls._re_coord_line.match(line)
158+
159+
if match:
160+
profile.append([float(i) for i in match.groups()])
161+
elif i == 0:
154162
name = line
163+
else:
164+
logger.error(f"error in dat airfoil: {path} {i}:({line.strip()})")
155165
return cls(profile, name)
156166

157167
def export_dat(self, pfad):

0 commit comments

Comments
 (0)