Skip to content

Commit 857434c

Browse files
authored
Merge pull request #45 from rthedin/f/spaceseparated
Allow space-separated entry by default
2 parents 51b8d6a + 6b4ab1e commit 857434c

File tree

1 file changed

+42
-11
lines changed

1 file changed

+42
-11
lines changed

openfast_toolbox/io/fast_input_file.py

Lines changed: 42 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1130,6 +1130,32 @@ def strIsInt(s):
11301130
def strToBool(s):
11311131
return s.lower() in ['true','t']
11321132

1133+
def addToList(l,value):
1134+
if l is None:
1135+
l = value
1136+
elif isinstance(l,int):
1137+
if strIsInt(value):
1138+
l = [l, value]
1139+
elif isinstance(l,float):
1140+
if strIsFloat(value):
1141+
l = [l, value]
1142+
elif isinstance(l,str):
1143+
if isStr(value):
1144+
l = [l, value]
1145+
elif isinstance(l,bool):
1146+
if strIsBool(value):
1147+
l = [l, value]
1148+
else:
1149+
if isinstance(l[0],int) and strIsInt(value):
1150+
l.append(value)
1151+
elif isinstance(l[0],float) and strIsFloat(value):
1152+
l.append(value)
1153+
elif isinstance(l[0],str) and isStr(value):
1154+
l.append(value)
1155+
elif isinstance(l[0],bool) and strIsBool(value):
1156+
l.append(value)
1157+
return l
1158+
11331159
def hasSpecialChars(s):
11341160
# fast allows for parenthesis
11351161
# For now we allow for - but that's because of BeamDyn geometry members
@@ -1235,17 +1261,22 @@ def parseFASTInputLine(line_raw,i,allowSpaceSeparatedList=False):
12351261
_merge_value(splits)
12361262
s=splits[0]
12371263

1238-
if strIsInt(s):
1239-
d['value']=int(s)
1240-
if allowSpaceSeparatedList and len(splits)>1:
1241-
if strIsInt(splits[1]):
1242-
d['value']=splits[0]+ ' '+splits[1]
1243-
elif strIsFloat(s):
1244-
d['value']=float(s)
1245-
elif strIsBool(s):
1246-
d['value']=strToBool(s)
1247-
else:
1248-
d['value']=s
1264+
# The loop below assumes allowSpaceSeparatedList is true
1265+
allowSpaceSeparatedList = True
1266+
1267+
for s in splits:
1268+
if strIsInt(s):
1269+
d['value'] = addToList(d['value'],int(s))
1270+
elif strIsFloat(s):
1271+
d['value'] = addToList(d['value'],float(s))
1272+
elif strIsBool(s):
1273+
d['value'] = addToList(d['value'],strToBool(s))
1274+
else:
1275+
d['value'] = addToList(d['value'], s)
1276+
# For strings, only the first one should be printed
1277+
break
1278+
if not allowSpaceSeparatedList:
1279+
break
12491280
iNext=1
12501281

12511282
# Extracting label (TODO, for now only second split)

0 commit comments

Comments
 (0)