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.da t
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").s uppress()
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=Lite ral("wd")
cas_datei= Word(alphanums)
iteration= Word(nums)
write= Word(alphanums)
file_read_data= "file/read-data " + hexnums.setResu ltsName("rd")
logEntry = threadname_read _case.setResult sName("threadna me")
+ cas_datei.setRe sultsName("cas_ datei")+file_re ad_data
logEntry = file_read_data
logEntryNew = threadname_it.s etResultsName(" threadname") +
iteration.setRe sultsName("iter ation")
logEntryWD = write_data.setR esultsName("thr eadname") +
write.setResult sName("write")
#------------------------------------------------------------------------
for tokens in logEntryNew.sea rchString(data) :
Â*Â*Â*Â*print
Â*Â*Â*Â*printÂ* "IterationÂ*Com mand=\tÂ*"+Â*to kens.threadname
Â*Â*Â*Â*printÂ* "NumberÂ*ofÂ*It erations=\tÂ*"+ Â*tokens.iterat ion
Â*Â*Â*Â*forÂ*x *inÂ*tokens.con dition:
Â*Â*Â*Â*Â*Â*Â*p rintÂ*x
Â*Â*Â*Â*printÂ* 50*"-"
for tokens in logEntryWD.sear chString(data):
Â*Â*Â*Â*print
Â*Â*Â*Â*printÂ* "WriteÂ*DataÂ*C ommand=\tÂ*"+Â* tokens.threadna me
Â*Â*Â*Â*printÂ* "DataÂ*FileÂ*Na me=\tÂ*"+Â*toke ns.write
Â*Â*Â*Â*forÂ*x *inÂ*tokens.con dition:
Â*Â*Â*Â*Â*Â*Â*p rintÂ*x
Â*Â*Â*Â*printÂ* 50*"-"
for tokens in logEntry.search String(data):
Â*Â*Â*Â*print
Â*Â*Â*Â*printÂ* "noÂ*idea=\tÂ*" +Â*tokens.threa dname
Â*Â*Â*Â*printÂ* "DataÂ*File=\t *"+Â*tokens. rd
Â*Â*Â*Â*print
Â*Â*Â*Â*forÂ*x *inÂ*tokens.con dition:
Â*Â*Â*Â*Â*Â*Â*p rintÂ*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