fixed bug in OIMang_hex2cub.py, added test for correct number of microstructures (should be equal to header info)
This commit is contained in:
parent
9c34c1b871
commit
e1e76cb257
|
@ -48,12 +48,12 @@ addPoints = -1
|
||||||
#--- setup file handles ---------------------------------------------------------------------------
|
#--- setup file handles ---------------------------------------------------------------------------
|
||||||
files = []
|
files = []
|
||||||
if filenames == []:
|
if filenames == []:
|
||||||
if filenames == []:
|
|
||||||
files.append({'name':'STDIN',
|
files.append({'name':'STDIN',
|
||||||
'input':sys.stdin,
|
'input':sys.stdin,
|
||||||
'output':sys.stdout,
|
'output':sys.stdout,
|
||||||
'croak':sys.stderr,
|
'croak':sys.stderr,
|
||||||
})
|
})
|
||||||
|
|
||||||
else:
|
else:
|
||||||
for name in filenames:
|
for name in filenames:
|
||||||
if os.path.exists(name):
|
if os.path.exists(name):
|
||||||
|
|
|
@ -106,8 +106,9 @@ for file in files:
|
||||||
words = line.split()
|
words = line.split()
|
||||||
if words[0] == '#': # process initial comments block
|
if words[0] == '#': # process initial comments block
|
||||||
if len(words) > 2:
|
if len(words) > 2:
|
||||||
if words[1] == 'HexGrid':
|
if words[2].lower() == 'hexgrid':
|
||||||
file['croak'].write('The file has HexGrid format. Please first convert to SquareGrid...\n'); break
|
file['croak'].write('The file has HexGrid format. Please first convert to SquareGrid...\n')
|
||||||
|
sys.exit()
|
||||||
if words[1] == 'XSTEP:': step[0] = float(words[2])
|
if words[1] == 'XSTEP:': step[0] = float(words[2])
|
||||||
if words[1] == 'YSTEP:': step[1] = float(words[2])
|
if words[1] == 'YSTEP:': step[1] = float(words[2])
|
||||||
if words[1] == 'NCOLS_ODD:':
|
if words[1] == 'NCOLS_ODD:':
|
||||||
|
@ -115,19 +116,16 @@ for file in files:
|
||||||
if words[1] == 'NROWS:':
|
if words[1] == 'NROWS:':
|
||||||
info['grid'][1] = int(words[2]); formatwidth = 1+int(math.log10(info['grid'][0]*info['grid'][1]))
|
info['grid'][1] = int(words[2]); formatwidth = 1+int(math.log10(info['grid'][0]*info['grid'][1]))
|
||||||
else: # finished with comments block
|
else: # finished with comments block
|
||||||
if options.config: # write configuration (line by line)
|
point += 1
|
||||||
point += 1
|
me = str(point).zfill(formatwidth)
|
||||||
me = str(point).zfill(formatwidth)
|
microstructure += ['[Grain%s]\n'%me + \
|
||||||
microstructure += ['[Grain%s]\n'%me + \
|
'crystallite\t%i\n'%options.crystallite + \
|
||||||
'crystallite\t%i\n'%options.crystallite + \
|
'(constituent)\tphase %i\ttexture %s\tfraction 1.0\n'%(options.phase[{True:0,False:1}[float(words[options.column-1])<options.threshold]],me)
|
||||||
'(constituent)\tphase %i\ttexture %s\tfraction 1.0\n'%(options.phase[{True:0,False:1}[float(words[options.column-1])<options.threshold]],me)
|
]
|
||||||
]
|
texture += ['[Grain%s]\n'%me + \
|
||||||
texture += ['[Grain%s]\n'%me + \
|
'axes %s %s %s\n'%(options.axes[0],options.axes[1],options.axes[2]) +\
|
||||||
'axes %s %s %s\n'%(options.axes[0],options.axes[1],options.axes[2]) +\
|
'(gauss)\tphi1 %4.2f\tPhi %4.2f\tphi2 %4.2f\tscatter 0.0\tfraction 1.0\n'%tuple(map(lambda x: float(x)*180.0/math.pi, words[:3]))
|
||||||
'(gauss)\tphi1 %4.2f\tPhi %4.2f\tphi2 %4.2f\tscatter 0.0\tfraction 1.0\n'%tuple(map(lambda x: float(x)*180.0/math.pi, words[:3]))
|
]
|
||||||
]
|
|
||||||
else: # only info from header needed
|
|
||||||
break
|
|
||||||
|
|
||||||
info['microstructures'] = info['grid'][0]*info['grid'][1]
|
info['microstructures'] = info['grid'][0]*info['grid'][1]
|
||||||
info['size'] = step[0]*info['grid'][0],step[1]*info['grid'][1],min(step)
|
info['size'] = step[0]*info['grid'][0],step[1]*info['grid'][1],min(step)
|
||||||
|
@ -145,6 +143,9 @@ for file in files:
|
||||||
if numpy.any(info['size'] <= 0.0):
|
if numpy.any(info['size'] <= 0.0):
|
||||||
file['croak'].write('invalid size x y z.\n')
|
file['croak'].write('invalid size x y z.\n')
|
||||||
sys.exit()
|
sys.exit()
|
||||||
|
if info['grid'].prod() != len(microstructure) -1:
|
||||||
|
file['croak'].write('found %s microstructures. Header info in ang file might be wrong.\n'%point)
|
||||||
|
sys.exit()
|
||||||
|
|
||||||
#--- write data -----------------------------------------------------------------------------------
|
#--- write data -----------------------------------------------------------------------------------
|
||||||
if options.config:
|
if options.config:
|
||||||
|
|
Loading…
Reference in New Issue