some beautifications

This commit is contained in:
Martin Diehl 2015-05-10 10:58:32 +00:00
parent c0a9141c8f
commit 8bf7a7ef6a
3 changed files with 24 additions and 23 deletions

View File

@ -20,16 +20,13 @@ Rotate vector and/or tensor column data by given angle around given axis.
""", version = scriptID)
parser.add_option('-v','--vector', dest = 'vector', action = 'extend', metavar = '<string LIST>',
help = 'column heading of vector to rotate')
help = 'column heading of vector to rotate')
parser.add_option('-t','--tensor', dest = 'tensor', action = 'extend', metavar = '<string LIST>',
help = 'column heading of tensor to rotate')
help = 'column heading of tensor to rotate')
parser.add_option('-r', '--rotation',dest = 'rotation', type = 'float', nargs = 4, metavar = ' '.join(['float']*4),
help = 'angle and axis to rotate data %default')
help = 'angle and axis to rotate data [%default]')
parser.add_option('-d', '--degrees', dest = 'degrees', action = 'store_true',
help = 'angles are given in degrees [%default]')
parser.set_defaults(vector = [])
parser.set_defaults(tensor = [])
help = 'angles are given in degrees [%default]')
parser.set_defaults(rotation = (0.,1.,1.,1.)) # no rotation about 1,1,1
parser.set_defaults(degrees = False)
@ -42,8 +39,8 @@ datainfo = {
'label':[]},
}
if options.vector != []: datainfo['vector']['label'] += options.vector
if options.tensor != []: datainfo['tensor']['label'] += options.tensor
if options.vector != None: datainfo['vector']['label'] += options.vector
if options.tensor != None: datainfo['tensor']['label'] += options.tensor
toRadians = math.pi/180.0 if options.degrees else 1.0 # rescale degrees to radians
r = damask.Quaternion().fromAngleAxis(toRadians*options.rotation[0],options.rotation[1:])

View File

@ -18,17 +18,22 @@ Show components of given ASCIItable(s).
""", version = scriptID)
parser.add_option('-a','--head', dest='head', action='store_true', help='output all heading (info + labels)')
parser.add_option('-i','--info', dest='info', action='store_true', help='output info lines')
parser.add_option('-l','--labels', dest='labels', action='store_true', help='output labels')
parser.add_option('-d','--data', dest='data', action='store_true', help='output data')
parser.add_option('-c','--column', dest='col', action='store_true', help='switch to label column format')
parser.add_option('--nolabels', dest='nolabels', action='store_true', help='table has no labels')
parser.add_option('-a','--head', dest='head', action='store_true',
help='output all heading (info + labels)')
parser.add_option('-i','--info', dest='info', action='store_true',
help='output info lines')
parser.add_option('-l','--labels', dest='labels', action='store_true',
help='output labels')
parser.add_option('-d','--data', dest='data', action='store_true',
help='output data')
parser.add_option('-c','--column', dest='col', action='store_true',
help='switch to label column format')
parser.add_option('--nolabels', dest='nolabels', action='store_true',
help='table has no labels')
parser.set_defaults(col = False)
parser.set_defaults(nolabels = False)
(options,filenames) = parser.parse_args()
(options,filenames) = parser.parse_args()
# ------------------------------------------ setup file handles ---------------------------------------
@ -46,16 +51,16 @@ for file in files:
if file['name'] != 'STDIN': file['croak'].write('\033[1m'+scriptName+'\033[0m: '+file['name']+'\n')
else: file['croak'].write('\033[1m'+scriptName+'\033[0m\n')
table = damask.ASCIItable(file['input'],file['output'],buffered=False,labels=not options.nolabels) # make unbuffered ASCII_table
table.head_read() # read ASCII header info
table = damask.ASCIItable(file['input'],file['output'],buffered=False,labels=not options.nolabels)# make unbuffered ASCII_table
table.head_read() # read ASCII header info
if options.head or options.info: file['output'].write('\n'.join(table.info)+'\n')
if options.head or options.labels: file['output'].write({True:'\n',False:'\t'}[options.col].join(table.labels)+'\n')
# ------------------------------------------ output data ---------------------------------------
outputAlive = options.data
while outputAlive and table.data_read(): # read next data line of ASCII table
outputAlive = table.data_write() # output line
while outputAlive and table.data_read(): # read next data line of ASCII table
outputAlive = table.data_write() # output line
outputAlive and table.output_flush()

View File

@ -79,8 +79,7 @@ for file in files:
else: # tag individual candidates
for datatype,info in datainfo.items():
for label in info['label']:
key = {True :'1_%s',
False:'%s' }[info['len']>1]%label
key = '1_%s' if [info['len']>1]%label else '%'
if key not in table.labels:
sys.stderr.write('column %s not found...\n'%key)
else: