made test for spectral packing/unpacking working again, small fixes in the 2 scripts

This commit is contained in:
Martin Diehl 2012-09-28 14:49:07 +00:00
parent 6d97a92913
commit 0a961bef55
2 changed files with 20 additions and 10 deletions

View File

@ -36,11 +36,12 @@ mappings = {
'dimension': lambda x: float(x),
'origin': lambda x: float(x),
'homogenization': lambda x: int(x),
'maxgraincount': lambda x: int(x),
}
parser = OptionParser(option_class=extendedOption, usage='%prog options [file[s]]', description = """
compress geometry files with ranges "a to b" and/or multiples "n of x".
compress geometry files with ranges "a to b" and/or multiples "n copies of x".
""" + string.replace('$Id$','\n','\\n')
)
@ -79,6 +80,7 @@ for file in files:
'dimension': [0.0,0.0,0.0],
'origin': [0.0,0.0,0.0],
'homogenization': 1,
'maxgraincount': 0,
}
new_header = []
@ -117,6 +119,7 @@ for file in files:
info['origin'][1],
info['origin'][2]))
new_header.append("homogenization\t%i\n"%info['homogenization'])
new_header.append("maxGrainCount\t%i\n"%info['maxgraincount'])
# ------------------------------------------ assemble header ---------------------------------------
@ -141,7 +144,7 @@ for file in files:
output = {'': '',
'.': str(former)+'\n',
'to': '%i to %i\n'%(former-reps+1,former),
'of': '%i of %i\n'%(reps,former),
'of': '%i copies of %i\n'%(reps,former),
}[type]
file['output'].write(output)
type = '.'
@ -154,7 +157,7 @@ for file in files:
output = {'.': str(former),
'to': '%i to %i'%(former-reps+1,former),
'of': '%i of %i'%(reps,former),
'of': '%i copies of %i'%(reps,former),
}[type]
file['output'].write(output+'\n')

View File

@ -36,11 +36,12 @@ mappings = {
'dimension': lambda x: float(x),
'origin': lambda x: float(x),
'homogenization': lambda x: int(x),
'maxgraincount': lambda x: int(x),
}
parser = OptionParser(option_class=extendedOption, usage='%prog options [file[s]]', description = """
Unpack geometry files containing ranges "a to b" and/or "n of x" multiples (exclusively in one line).
Unpack geometry files containing ranges "a to b" and/or "n copies of x" multiples (exclusively in one line).
""" + string.replace('$Id: spectral_geomCanvas.py 1576 2012-06-26 18:08:50Z MPIE\p.eisenlohr $','\n','\\n')
)
@ -84,6 +85,7 @@ for file in files:
'dimension': [0.0,0.0,0.0],
'origin': [0.0,0.0,0.0],
'homogenization': 1,
'maxgraincount': 0,
}
new_header = []
@ -125,7 +127,12 @@ for file in files:
info['origin'][1],
info['origin'][2]))
new_header.append("homogenization\t%i\n"%info['homogenization'])
new_header.append("maxGrainCount\t%i\n"%info['maxgraincount'])
if info['maxgraincount'] != 0:
digits = 1+int(math.log10(int(info['maxgraincount'])))
else:
digits = 1+int(math.log10(int(info['resolution'][0]*info['resolution'][1]*info['resolution'][2])))
print digits
# ------------------------------------------ assemble header ---------------------------------------
file['output'].write('%i\theader\n'%(len(new_header))+''.join(new_header))
@ -137,11 +144,11 @@ for file in files:
words = map(str.lower,line.split())
if len(words) > 1: # any packing keywords?
if (words[1] == 'to'): words = map(str,range(int(words[0]),int(words[2])+1))
if (words[1] == 'of'): words = [words[2]]*int(words[0])
if (words[1] == 'copies' and words[2] == 'of'): words = [words[3]]*int(words[0])
for word in words:
wordsWritten += 1
file['output'].write(word+{True:'\n',False:' '}[wordsWritten%format == 0]) # newline every format words
file['output'].write(word.zfill(digits)+{True:'\n',False:' '}[wordsWritten%format == 0]) # newline every format words
# ------------------------------------------ output finalization ---------------------------------------