From 6b4ab1efd63f3a35939f7d6bec47535176140a61 Mon Sep 17 00:00:00 2001 From: Regis Thedin Date: Wed, 9 Apr 2025 12:26:47 -0600 Subject: [PATCH] FF: allow space-separated entry by default --- openfast_toolbox/io/fast_input_file.py | 53 ++++++++++++++++++++------ 1 file changed, 42 insertions(+), 11 deletions(-) diff --git a/openfast_toolbox/io/fast_input_file.py b/openfast_toolbox/io/fast_input_file.py index 6c0984c..99446d2 100644 --- a/openfast_toolbox/io/fast_input_file.py +++ b/openfast_toolbox/io/fast_input_file.py @@ -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 @@ -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)