adapting to current format of spectral out file

now using regular expressions to match "magic" lines
This commit is contained in:
Christoph Kords 2012-02-15 12:07:00 +00:00
parent db06c797cd
commit bd32f1bf1a
1 changed files with 18 additions and 20 deletions

View File

@ -1,7 +1,7 @@
#!/usr/bin/env python #!/usr/bin/env python
# -*- coding: UTF-8 no BOM -*- # -*- coding: UTF-8 no BOM -*-
import os,sys,string import os,sys,string,re
from optparse import OptionParser, OptionGroup, Option, SUPPRESS_HELP from optparse import OptionParser, OptionGroup, Option, SUPPRESS_HELP
# ----------------------------- # -----------------------------
@ -56,15 +56,11 @@ else:
for file in files: for file in files:
print file['name'] print file['name']
inc = 1
loadcase = 1
step = 1
iter = 0
# ------------------------------------------ assemble header --------------------------------------- # ------------------------------------------ assemble header ---------------------------------------
output = '1\theader\n' + \ output = '1\theader\n' + \
'\t'.join(['inc','iteration']) + '\n' '\t'.join(['loadcase','increment','iterations']) + '\n'
if options.memory: if options.memory:
data = file['input'].readlines() data = file['input'].readlines()
@ -75,25 +71,27 @@ for file in files:
# ------------------------------------------ read file --------------------------------------- # ------------------------------------------ read file ---------------------------------------
pattern = re.compile('Loadcase\s+(\d+)\s+Increment\s+(\d+)/\d+\s+@\s+Iteration\s+(\d+)/\d+.*')
lastIteration = 0
for line in {True : data, for line in {True : data,
False : file['input']}[options.memory]: False : file['input']}[options.memory]:
items = line.split() m = re.match(pattern, line)
if len(items) > 8 and items[1] == 'Loadcase': # 'magic' line? if m:
if int(items[6]) == step and int(items[3]) == loadcase: thisLoadcase = int(m.group(1))
iter += 1 # next iteration found thisIncrement = int(m.group(2))
else: thisIteration = int(m.group(3))
output += '\t'.join(map(str,[inc,iter])) + '\n' if thisIteration <= lastIteration: # indicator for new increment or loadcase
loadcase = int(items[2]) # store current loadcase count output += '\t'.join(map(str,[lastLoadcase,lastIncrement,lastIteration])) + '\n'
step = int(items[5]) # store current step count
inc += 1 # is next inc
iter = 1 # was first iteration of next step/inc
if not options.memory: if not options.memory:
file['output'].write(output) file['output'].write(output)
output = '' output = ''
lastLoadcase = thisLoadcase
lastIncrement = thisIncrement
lastIteration = thisIteration
output += '\t'.join(map(str,[inc,iter])) + '\n' # process last step (for which, of course, no further step can be found) output += '\t'.join(map(str,[lastLoadcase,lastIncrement,lastIteration])) + '\n' # process last iteration (for which, of course, no further iteration can be found)
file['input'].close() file['input'].close()