2019-03-09 05:37:26 +05:30
|
|
|
#!/usr/bin/env python3
|
2013-12-14 09:18:50 +05:30
|
|
|
|
2019-06-14 16:33:30 +05:30
|
|
|
import os
|
|
|
|
import sys
|
2019-12-05 15:17:36 +05:30
|
|
|
from io import StringIO
|
2014-10-16 20:26:44 +05:30
|
|
|
from optparse import OptionParser
|
2019-06-14 16:33:30 +05:30
|
|
|
|
2014-10-16 20:26:44 +05:30
|
|
|
import damask
|
2013-12-14 09:18:50 +05:30
|
|
|
|
2019-06-14 16:33:30 +05:30
|
|
|
|
2016-01-27 22:36:00 +05:30
|
|
|
scriptName = os.path.splitext(os.path.basename(__file__))[0]
|
|
|
|
scriptID = ' '.join([scriptName,damask.version])
|
2013-12-14 09:18:50 +05:30
|
|
|
|
2019-06-14 16:33:30 +05:30
|
|
|
|
2013-12-14 09:18:50 +05:30
|
|
|
# --------------------------------------------------------------------
|
|
|
|
# MAIN
|
|
|
|
# --------------------------------------------------------------------
|
|
|
|
|
2019-02-16 22:55:41 +05:30
|
|
|
parser = OptionParser(option_class=damask.extendableOption, usage='%prog options [ASCIItable(s)]', description = """
|
2016-04-29 05:58:45 +05:30
|
|
|
Sort rows by given (or all) column label(s).
|
2013-12-14 09:18:50 +05:30
|
|
|
|
|
|
|
Examples:
|
2014-05-23 19:35:58 +05:30
|
|
|
With coordinates in columns "x", "y", and "z"; sorting with x slowest and z fastest varying index: --label x,y,z.
|
2014-10-16 20:26:44 +05:30
|
|
|
""", version = scriptID)
|
2013-12-14 09:18:50 +05:30
|
|
|
|
|
|
|
|
2015-08-08 00:33:26 +05:30
|
|
|
parser.add_option('-l','--label',
|
2019-12-05 15:17:36 +05:30
|
|
|
dest = 'labels',
|
2015-08-08 00:33:26 +05:30
|
|
|
action = 'extend', metavar = '<string LIST>',
|
|
|
|
help = 'list of column labels (a,b,c,...)')
|
|
|
|
parser.add_option('-r','--reverse',
|
|
|
|
dest = 'reverse',
|
|
|
|
action = 'store_true',
|
|
|
|
help = 'sort in reverse')
|
|
|
|
|
2016-04-29 05:58:45 +05:30
|
|
|
parser.set_defaults(reverse = False,
|
2015-08-08 00:33:26 +05:30
|
|
|
)
|
2013-12-14 09:18:50 +05:30
|
|
|
|
|
|
|
(options,filenames) = parser.parse_args()
|
2015-08-18 20:07:32 +05:30
|
|
|
if filenames == []: filenames = [None]
|
2013-12-14 09:18:50 +05:30
|
|
|
|
2019-12-05 15:17:36 +05:30
|
|
|
if options.labels is None:
|
|
|
|
parser.error('no labels specified.')
|
2015-08-08 00:33:26 +05:30
|
|
|
for name in filenames:
|
2019-12-05 15:17:36 +05:30
|
|
|
damask.util.report(scriptName,name)
|
2013-12-14 09:18:50 +05:30
|
|
|
|
2019-12-05 15:17:36 +05:30
|
|
|
table = damask.Table.from_ASCII(StringIO(''.join(sys.stdin.read())) if name is None else name)
|
|
|
|
table.sort_by(options.labels,not options.reverse)
|
2013-12-14 09:18:50 +05:30
|
|
|
|
2019-12-05 15:17:36 +05:30
|
|
|
table.to_ASCII(sys.stdout if name is None else name)
|