File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 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/>.
2020import os
21+ import re
2122import math
2223import numpy as np
2324import 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 ):
You can’t perform that action at this time.
0 commit comments