input file handling now save for large file count.
streamlining of input column detection. fixed bug iterating through “grainIDs” instead of “grain”. proper closing and dismissal of output table file.
This commit is contained in:
parent
bb9e080790
commit
b7f98c00d6
|
@ -37,44 +37,38 @@ parser.set_defaults(size = [0.0,0.0,0.0])
|
||||||
|
|
||||||
(options, filenames) = parser.parse_args()
|
(options, filenames) = parser.parse_args()
|
||||||
|
|
||||||
#--- setup file handles --------------------------------------------------------------------------
|
# --- loop over input files -------------------------------------------------------------------------
|
||||||
files = []
|
|
||||||
if filenames == []:
|
if filenames == []:
|
||||||
files.append({'name':'STDIN',
|
filenames = ['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 name == 'STDIN':
|
||||||
files.append({'name':name,
|
file = {'name':'STDIN', 'input':sys.stdin, 'output':sys.stdout, 'croak':sys.stderr}
|
||||||
'input':open(name),
|
file['croak'].write('\033[1m'+scriptName+'\033[0m\n')
|
||||||
'output':sys.stdout,
|
else:
|
||||||
'croak':sys.stdout,
|
if not os.path.exists(name): continue
|
||||||
})
|
file = {'name':name, 'input':open(name), 'output':open(name+'_tmp','w'), 'croak':sys.stderr}
|
||||||
|
file['croak'].write('\033[1m'+scriptName+'\033[0m: '+file['name']+'\n')
|
||||||
|
|
||||||
#--- loop over input files ------------------------------------------------------------------------
|
table = damask.ASCIItable(file['input'],file['output'],buffered = False)
|
||||||
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'])
|
|
||||||
table.head_read()
|
table.head_read()
|
||||||
|
|
||||||
coordsCol = table.labels_index('1_coords')
|
|
||||||
if coordsCol < 0:
|
if np.all(table.label_index(['1_coords','2_coords','3_coords']) != -1):
|
||||||
coordsCol = table.labels_index('x') # try if file is in legacy format
|
labels = ['1_coords','2_coords','3_coords']
|
||||||
if coordsCol < 0:
|
elif np.all(table.label_index(['x','y','z']) != -1):
|
||||||
file['croak'].write('column 1_coords/x not found...\n')
|
labels = ['x','y','z']
|
||||||
|
else:
|
||||||
|
file['croak'].write('no coordinate data (1/2/3_coords | x/y/z) found ...')
|
||||||
continue
|
continue
|
||||||
|
|
||||||
grainCol = table.labels_index('microstructure')
|
hasGrains = table.label_index('microstructure') != -1
|
||||||
hasGrains = grainCol != -1
|
labels += ['microstructure'] if hasGrains else []
|
||||||
|
|
||||||
table.data_readArray()
|
table.data_readArray(labels) # read ASCIItable columns
|
||||||
coords = table.data[:,coordsCol:coordsCol+3]
|
coords = table.data[:,:3] # assign coordinates
|
||||||
grain = table.data[:,grainCol] if hasGrains else 1+np.arange(len(coords))
|
grain = table.data[:,3].astype('i') if hasGrains else 1+np.arange(len(coords),dtype='i') # assign grains
|
||||||
grainIDs = np.unique(grain).astype('i')
|
grainIDs = np.unique(grain).astype('i') # find all grainIDs present
|
||||||
|
|
||||||
#--- interpret header ----------------------------------------------------------------------------
|
#--- interpret header ----------------------------------------------------------------------------
|
||||||
info = {
|
info = {
|
||||||
|
@ -121,7 +115,7 @@ for file in files:
|
||||||
pointIds = vtk.vtkIdList()
|
pointIds = vtk.vtkIdList()
|
||||||
pointIds.InsertId(0, pid)
|
pointIds.InsertId(0, pid)
|
||||||
grid.InsertNextCell(1, pointIds)
|
grid.InsertNextCell(1, pointIds)
|
||||||
IDs.InsertNextValue(grainIDs[i])
|
IDs.InsertNextValue(grain[i])
|
||||||
|
|
||||||
grid.SetPoints(pts)
|
grid.SetPoints(pts)
|
||||||
grid.GetCellData().AddArray(IDs)
|
grid.GetCellData().AddArray(IDs)
|
||||||
|
@ -139,6 +133,7 @@ for file in files:
|
||||||
writer.Write()
|
writer.Write()
|
||||||
sys.stdout.write(writer.GetOutputString()[0:writer.GetOutputStringLength()])
|
sys.stdout.write(writer.GetOutputString()[0:writer.GetOutputStringLength()])
|
||||||
else:
|
else:
|
||||||
|
table.close(dismiss=True)
|
||||||
(head,tail) = os.path.split(file['name'])
|
(head,tail) = os.path.split(file['name'])
|
||||||
writer = vtk.vtkXMLUnstructuredGridWriter()
|
writer = vtk.vtkXMLUnstructuredGridWriter()
|
||||||
writer.SetDataModeToBinary()
|
writer.SetDataModeToBinary()
|
||||||
|
|
Loading…
Reference in New Issue