mainly polished for “numpy as np”. added alternative expression to parse script filename (excluding file extension).

This commit is contained in:
Philip Eisenlohr 2014-11-05 22:04:59 +00:00
parent 35f8b9786e
commit 9345640dfd
1 changed files with 14 additions and 13 deletions

View File

@ -1,12 +1,13 @@
#!/usr/bin/env python #!/usr/bin/env python
# -*- coding: UTF-8 no BOM -*- # -*- coding: UTF-8 no BOM -*-
import os,sys,string,re,numpy,vtk import os,sys,string,re,vtk
import damask import numpy as np
from optparse import OptionParser, OptionGroup, Option, SUPPRESS_HELP from optparse import OptionParser, OptionGroup, Option, SUPPRESS_HELP
import damask
scriptID = '$Id$' scriptID = string.replace('$Id$','\n','\\n')
scriptName = scriptID.split()[1] scriptName = os.path.splitext(scriptID.split()[1])[0]
#-------------------------------------------------------------------------------------------------- #--------------------------------------------------------------------------------------------------
class extendedOption(Option): class extendedOption(Option):
@ -87,9 +88,9 @@ for file in files:
#--- interpret header ---------------------------------------------------------------------------- #--- interpret header ----------------------------------------------------------------------------
info = { info = {
'grid': numpy.zeros(3,'i'), 'grid': np.zeros(3,'i'),
'size': numpy.zeros(3,'d'), 'size': np.zeros(3,'d'),
'origin': numpy.zeros(3,'d'), 'origin': np.zeros(3,'d'),
'homogenization': 0, 'homogenization': 0,
'microstructures': 0, 'microstructures': 0,
} }
@ -113,10 +114,10 @@ for file in files:
'homogenization: %i\n'%info['homogenization'] + \ 'homogenization: %i\n'%info['homogenization'] + \
'microstructures: %i\n'%info['microstructures']) 'microstructures: %i\n'%info['microstructures'])
if numpy.any(info['grid'] < 1): if np.any(info['grid'] < 1):
file['croak'].write('invalid grid a b c.\n') file['croak'].write('invalid grid a b c.\n')
continue continue
if numpy.any(info['size'] <= 0.0): if np.any(info['size'] <= 0.0):
file['croak'].write('invalid size x y z.\n') file['croak'].write('invalid size x y z.\n')
continue continue
@ -163,14 +164,14 @@ for file in files:
else: else:
writer.SetInputData(grid) writer.SetInputData(grid)
writer.Write() writer.Write()
sys.stdout.write(writer.GetOutputString()[0:writer.GetOutputStringLength()]) file['output'].write(writer.GetOutputString()[0:writer.GetOutputStringLength()])
else: else:
(head,tail) = os.path.split(file['name']) (dir,file) = os.path.split(file['name'])
writer = vtk.vtkXMLRectilinearGridWriter() writer = vtk.vtkXMLRectilinearGridWriter()
writer.SetDataModeToBinary() writer.SetDataModeToBinary()
writer.SetCompressorTypeToZLib() writer.SetCompressorTypeToZLib()
writer.SetFileName(os.path.join(head,'mesh_'+os.path.splitext(tail)[0] writer.SetFileName(os.path.join(dir,'mesh_'+os.path.splitext(file)[0]
+'.'+writer.GetDefaultFileExtension())) +'.'+writer.GetDefaultFileExtension()))
if vtk.VTK_MAJOR_VERSION <= 5: if vtk.VTK_MAJOR_VERSION <= 5:
writer.SetInput(grid) writer.SetInput(grid)
else: else: