updated to new ASCII table style
This commit is contained in:
parent
53c574033a
commit
419a612d0e
|
@ -68,89 +68,47 @@ else:
|
||||||
options.center = np.array(options.center)
|
options.center = np.array(options.center)
|
||||||
invRotation = rotation.conjugated() # rotation of gridpos into primitive coordinate system
|
invRotation = rotation.conjugated() # rotation of gridpos into primitive coordinate system
|
||||||
|
|
||||||
#--- setup file handles --------------------------------------------------------------------------
|
# --- loop over input files -------------------------------------------------------------------------
|
||||||
files = []
|
|
||||||
if filenames == []:
|
if filenames == []: filenames = ['STDIN']
|
||||||
files.append({'name':'STDIN',
|
|
||||||
'input':sys.stdin,
|
|
||||||
'output':sys.stdout,
|
|
||||||
'croak':sys.stderr,
|
|
||||||
})
|
|
||||||
else:
|
|
||||||
for name in filenames:
|
for name in filenames:
|
||||||
if os.path.exists(name):
|
if not (name == 'STDIN' or os.path.exists(name)): continue
|
||||||
files.append({'name':name,
|
table = damask.ASCIItable(name = name, outname = name+'_tmp',
|
||||||
'input':open(name),
|
buffered = False, labeled = False)
|
||||||
'output':open(name+'_tmp','w'),
|
table.croak('\033[1m'+scriptName+'\033[0m'+(': '+name if name != 'STDIN' else ''))
|
||||||
'croak':sys.stdout,
|
|
||||||
})
|
|
||||||
|
|
||||||
#--- loop over input files ------------------------------------------------------------------------
|
|
||||||
for file in files:
|
|
||||||
file['croak'].write('\033[1m' + scriptName + '\033[0m: ' + (file['name'] if file['name'] != 'STDIN' else '') + '\n')
|
|
||||||
|
|
||||||
table = damask.ASCIItable(file['input'],file['output'],labels = False)
|
|
||||||
table.head_read()
|
|
||||||
|
|
||||||
# --- interpret header ----------------------------------------------------------------------------
|
# --- interpret header ----------------------------------------------------------------------------
|
||||||
info = {
|
|
||||||
'grid': np.zeros(3,'i'),
|
|
||||||
'size': np.zeros(3,'d'),
|
|
||||||
'origin': np.zeros(3,'d'),
|
|
||||||
'homogenization': 0,
|
|
||||||
'microstructures': 0,
|
|
||||||
}
|
|
||||||
newInfo = {
|
|
||||||
'grid': np.zeros(3,'i'),
|
|
||||||
'origin': np.zeros(3,'d'),
|
|
||||||
'microstructures': 0,
|
|
||||||
}
|
|
||||||
extra_header = []
|
|
||||||
|
|
||||||
for header in table.info:
|
table.head_read()
|
||||||
headitems = map(str.lower,header.split())
|
info,extra_header = table.head_getGeom()
|
||||||
if len(headitems) == 0: continue # skip blank lines
|
|
||||||
if headitems[0] in mappings.keys():
|
|
||||||
if headitems[0] in identifiers.keys():
|
|
||||||
for i in xrange(len(identifiers[headitems[0]])):
|
|
||||||
info[headitems[0]][i] = \
|
|
||||||
mappings[headitems[0]](headitems[headitems.index(identifiers[headitems[0]][i])+1])
|
|
||||||
else:
|
|
||||||
info[headitems[0]] = mappings[headitems[0]](headitems[1])
|
|
||||||
else:
|
|
||||||
extra_header.append(header)
|
|
||||||
|
|
||||||
file['croak'].write('grid a b c: %s\n'%(' x '.join(map(str,info['grid']))) + \
|
table.croak(['grid a b c: %s'%(' x '.join(map(str,info['grid']))),
|
||||||
'size x y z: %s\n'%(' x '.join(map(str,info['size']))) + \
|
'size x y z: %s'%(' x '.join(map(str,info['size']))),
|
||||||
'origin x y z: %s\n'%(' : '.join(map(str,info['origin']))) + \
|
'origin x y z: %s'%(' : '.join(map(str,info['origin']))),
|
||||||
'homogenization: %i\n'%info['homogenization'] + \
|
'homogenization: %i'%info['homogenization'],
|
||||||
'microstructures: %i\n'%info['microstructures'])
|
'microstructures: %i'%info['microstructures'],
|
||||||
|
])
|
||||||
|
|
||||||
if np.any(info['grid'] < 1):
|
errors = []
|
||||||
file['croak'].write('invalid grid a b c.\n')
|
if np.any(info['grid'] < 1): errors.append('invalid grid a b c.')
|
||||||
continue
|
if np.any(info['size'] <= 0.0): errors.append('invalid size x y z.')
|
||||||
if np.any(info['size'] <= 0.0):
|
if errors != []:
|
||||||
file['croak'].write('invalid size x y z.\n')
|
table.croak(errors)
|
||||||
|
table.close(dismiss = True)
|
||||||
continue
|
continue
|
||||||
|
|
||||||
#--- read data ------------------------------------------------------------------------------------
|
#--- read data ------------------------------------------------------------------------------------
|
||||||
microstructure = np.zeros(info['grid'].prod(),'i') # initialize as flat array
|
|
||||||
i = 0
|
|
||||||
|
|
||||||
while table.data_read():
|
microstructure = table.microstructure_read(info['grid']) # read microstructure
|
||||||
items = table.data
|
|
||||||
if len(items) > 2:
|
|
||||||
if items[1].lower() == 'of': items = [int(items[2])]*int(items[0])
|
|
||||||
elif items[1].lower() == 'to': items = xrange(int(items[0]),1+int(items[2]))
|
|
||||||
else: items = map(int,items)
|
|
||||||
else: items = map(int,items)
|
|
||||||
|
|
||||||
s = len(items)
|
|
||||||
microstructure[i:i+s] = items
|
|
||||||
i += s
|
|
||||||
|
|
||||||
# --- do work ------------------------------------------------------------------------------------
|
# --- do work ------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
newInfo = {
|
||||||
|
'microstructures': 0,
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
if options.fill == 0:
|
if options.fill == 0:
|
||||||
options.fill = microstructure.max()+1
|
options.fill = microstructure.max()+1
|
||||||
|
|
||||||
|
@ -176,30 +134,33 @@ for file in files:
|
||||||
|
|
||||||
|
|
||||||
# --- report ---------------------------------------------------------------------------------------
|
# --- report ---------------------------------------------------------------------------------------
|
||||||
if (newInfo['microstructures'] != info['microstructures']):
|
|
||||||
file['croak'].write('--> microstructures: %i\n'%newInfo['microstructures'])
|
remarks = []
|
||||||
|
if ( newInfo['microstructures'] != info['microstructures']): remarks.append('--> microstructures: %i'%newInfo['microstructures'])
|
||||||
|
if remarks != []: table.croak(remarks)
|
||||||
|
|
||||||
#--- write header ---------------------------------------------------------------------------------
|
#--- write header ---------------------------------------------------------------------------------
|
||||||
table.labels_clear()
|
|
||||||
table.info_clear()
|
table.info_clear()
|
||||||
table.info_append(extra_header+[
|
table.info_append([
|
||||||
scriptID + ' ' + ' '.join(sys.argv[1:]),
|
scriptID + ' ' + ' '.join(sys.argv[1:]),
|
||||||
"grid\ta %i\tb %i\tc %i"%(info['grid'][0],info['grid'][1],info['grid'][2],),
|
"grid\ta {grid[0]}\tb {grid[1]}\tc {grid[2]}".format(grid=info['grid']),
|
||||||
"size\tx %f\ty %f\tz %f"%(info['size'][0],info['size'][1],info['size'][2],),
|
"size\tx {size[0]}\ty {size[1]}\tz {size[2]}".format(size=info['size']),
|
||||||
"origin\tx %f\ty %f\tz %f"%(info['origin'][0],info['origin'][1],info['origin'][2],),
|
"origin\tx {origin[0]}\ty {origin[1]}\tz {origin[2]}".format(origin=info['origin']),
|
||||||
"homogenization\t%i"%info['homogenization'],
|
"homogenization\t{homog}".format(homog=info['homogenization']),
|
||||||
"microstructures\t%i"%(newInfo['microstructures']),
|
"microstructures\t{microstructures}".format(microstructures=newInfo['microstructures'])
|
||||||
])
|
])
|
||||||
|
table.labels_clear()
|
||||||
table.head_write()
|
table.head_write()
|
||||||
table.output_flush()
|
table.output_flush()
|
||||||
|
|
||||||
# --- write microstructure information ------------------------------------------------------------
|
# --- write microstructure information ------------------------------------------------------------
|
||||||
|
|
||||||
formatwidth = int(math.floor(math.log10(microstructure.max())+1))
|
formatwidth = int(math.floor(math.log10(microstructure.max())+1))
|
||||||
table.data = microstructure.reshape((info['grid'][0],info['grid'][1]*info['grid'][2]),order='F').transpose()
|
table.data = microstructure.reshape((info['grid'][0],info['grid'][1]*info['grid'][2]),order='F').transpose()
|
||||||
table.data_writeArray('%%%ii'%(formatwidth),delimiter = ' ')
|
table.data_writeArray('%%%ii'%(formatwidth),delimiter = ' ')
|
||||||
|
|
||||||
# --- output finalization --------------------------------------------------------------------------
|
# --- output finalization --------------------------------------------------------------------------
|
||||||
if file['name'] != 'STDIN':
|
|
||||||
table.input_close()
|
table.close() # close ASCII table
|
||||||
table.output_close()
|
if name != 'STDIN': os.rename(name+'_tmp',name) # overwrite old one with tmp new
|
||||||
os.rename(file['name']+'_tmp',file['name'])
|
|
||||||
|
|
Loading…
Reference in New Issue