Skip to content

Allow space-separated entry by default #45

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 42 additions & 11 deletions openfast_toolbox/io/fast_input_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -1130,6 +1130,32 @@ def strIsInt(s):
def strToBool(s):
return s.lower() in ['true','t']

def addToList(l,value):
if l is None:
l = value
elif isinstance(l,int):
if strIsInt(value):
l = [l, value]
elif isinstance(l,float):
if strIsFloat(value):
l = [l, value]
elif isinstance(l,str):
if isStr(value):
l = [l, value]
elif isinstance(l,bool):
if strIsBool(value):
l = [l, value]
else:
if isinstance(l[0],int) and strIsInt(value):
l.append(value)
elif isinstance(l[0],float) and strIsFloat(value):
l.append(value)
elif isinstance(l[0],str) and isStr(value):
l.append(value)
elif isinstance(l[0],bool) and strIsBool(value):
l.append(value)
return l

def hasSpecialChars(s):
# fast allows for parenthesis
# For now we allow for - but that's because of BeamDyn geometry members
Expand Down Expand Up @@ -1235,17 +1261,22 @@ def parseFASTInputLine(line_raw,i,allowSpaceSeparatedList=False):
_merge_value(splits)
s=splits[0]

if strIsInt(s):
d['value']=int(s)
if allowSpaceSeparatedList and len(splits)>1:
if strIsInt(splits[1]):
d['value']=splits[0]+ ' '+splits[1]
elif strIsFloat(s):
d['value']=float(s)
elif strIsBool(s):
d['value']=strToBool(s)
else:
d['value']=s
# The loop below assumes allowSpaceSeparatedList is true
allowSpaceSeparatedList = True

for s in splits:
if strIsInt(s):
d['value'] = addToList(d['value'],int(s))
elif strIsFloat(s):
d['value'] = addToList(d['value'],float(s))
elif strIsBool(s):
d['value'] = addToList(d['value'],strToBool(s))
else:
d['value'] = addToList(d['value'], s)
# For strings, only the first one should be printed
break
if not allowSpaceSeparatedList:
break
iNext=1

# Extracting label (TODO, for now only second split)
Expand Down
Loading