Hi,
me again :-)
I would like to parse a small batch file:
file/read-case kepstop.cas
file/read-data keps1500.dat
solve/monitors/residual/plot no
solve/monitors/residual/print yes
/define/boundary-conditions in velocity-inlet 10 0.1 0.1 no 1
it 500
wd keps1500_500.dat
yes
exit
Right now, I use this little example:
from pyparsing import *
input =
open("/home/fab/HOME/Dissertation/CFD/Fluent/Batch/fluent_batch",
'r')
data = input.read()
#------------------------------------------------------------------------
# Define Grammars
#------------------------------------------------------------------------
integer = Word(nums)
hexnums = Word(alphanums)
end = Literal("\n").suppress()
all = SkipTo(end)
#threadname = dblQuotedString
threadname_read_case = Literal("file/read-case")
threadname_read_data= Literal("file/read-data")
threadname_it = Literal("it")
write_data=Literal("wd")
cas_datei= Word(alphanums)
iteration= Word(nums)
write= Word(alphanums)
file_read_data= "file/read-data " + hexnums.setResultsName("rd")
logEntry = threadname_read_case.setResultsName("threadname")
+ cas_datei.setResultsName("cas_datei")+file_read_da ta
logEntry = file_read_data
logEntryNew = threadname_it.setResultsName("threadname") +
iteration.setResultsName("iteration")
logEntryWD = write_data.setResultsName("threadname") +
write.setResultsName("write")
#------------------------------------------------------------------------
for tokens in logEntryNew.searchString(data):
Â*Â*Â*Â*print
Â*Â*Â*Â*printÂ*"IterationÂ*Command=\tÂ*"+Â*tokens. threadname
Â*Â*Â*Â*printÂ*"NumberÂ*ofÂ*Iterations=\tÂ*"+Â*tok ens.iteration
Â*Â*Â*Â*forÂ*xÂ*inÂ*tokens.condition:
Â*Â*Â*Â*Â*Â*Â*printÂ*x
Â*Â*Â*Â*printÂ*50*"-"
for tokens in logEntryWD.searchString(data):
Â*Â*Â*Â*print
Â*Â*Â*Â*printÂ*"WriteÂ*DataÂ*Command=\tÂ*"+Â*token s.threadname
Â*Â*Â*Â*printÂ*"DataÂ*FileÂ*Name=\tÂ*"+Â*tokens.wr ite
Â*Â*Â*Â*forÂ*xÂ*inÂ*tokens.condition:
Â*Â*Â*Â*Â*Â*Â*printÂ*x
Â*Â*Â*Â*printÂ*50*"-"
for tokens in logEntry.searchString(data):
Â*Â*Â*Â*print
Â*Â*Â*Â*printÂ*"noÂ*idea=\tÂ*"+Â*tokens.threadname
Â*Â*Â*Â*printÂ*"DataÂ*File=\tÂ*"+Â*tokens.rd
Â*Â*Â*Â*print
Â*Â*Â*Â*forÂ*xÂ*inÂ*tokens.condition:
Â*Â*Â*Â*Â*Â*Â*printÂ*x
Â*Â*Â*Â*printÂ*50*"-"
Unfortunately, it does not parse the whole file names with
the underscore and I do not know yet, how I can access the
line with 'define/boundary-conditions'. Every 'argument' of
that command should become a separate python variable!?
Does anyone have an idea, how I can achieve this!?
Regards!
Fabian