2018-11-17 12:42:12 +05:30
|
|
|
#!/usr/bin/env python3
|
2012-04-23 18:16:38 +05:30
|
|
|
|
2019-05-27 01:00:38 +05:30
|
|
|
import os
|
|
|
|
import sys
|
2019-05-27 02:22:23 +05:30
|
|
|
from io import StringIO
|
2014-08-22 22:28:53 +05:30
|
|
|
from optparse import OptionParser
|
2019-05-27 01:00:38 +05:30
|
|
|
|
2013-06-30 06:09:48 +05:30
|
|
|
import damask
|
2012-09-05 20:45:11 +05:30
|
|
|
|
2019-05-27 01:00:38 +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-07-10 14:45:42 +05:30
|
|
|
|
2019-05-27 01:00:38 +05:30
|
|
|
|
2013-05-13 18:40:31 +05:30
|
|
|
#--------------------------------------------------------------------------------------------------
|
|
|
|
# MAIN
|
|
|
|
#--------------------------------------------------------------------------------------------------
|
2012-04-24 17:01:18 +05:30
|
|
|
|
2016-05-12 12:24:34 +05:30
|
|
|
parser = OptionParser(option_class=damask.extendableOption, usage='%prog [geomfile(s)]', description = """
|
2019-05-27 01:00:38 +05:30
|
|
|
Pack ranges to "a to b" and/or multiples to "n of x".
|
2014-08-25 18:23:11 +05:30
|
|
|
|
2014-08-22 22:28:53 +05:30
|
|
|
""", version = scriptID)
|
2012-04-23 18:16:38 +05:30
|
|
|
|
2012-09-05 20:45:11 +05:30
|
|
|
(options, filenames) = parser.parse_args()
|
2012-04-23 18:16:38 +05:30
|
|
|
|
2015-08-08 00:33:26 +05:30
|
|
|
|
2015-08-21 01:12:05 +05:30
|
|
|
if filenames == []: filenames = [None]
|
2015-08-08 00:33:26 +05:30
|
|
|
|
|
|
|
for name in filenames:
|
2015-09-24 21:04:27 +05:30
|
|
|
damask.util.report(scriptName,name)
|
2015-08-08 00:33:26 +05:30
|
|
|
|
2019-05-28 06:44:09 +05:30
|
|
|
geom = damask.Geom.from_file(StringIO(''.join(sys.stdin.read())) if name is None else name)
|
2019-05-30 14:56:47 +05:30
|
|
|
|
2019-05-28 06:44:09 +05:30
|
|
|
damask.util.croak(geom)
|
|
|
|
geom.add_comments(scriptID + ' ' + ' '.join(sys.argv[1:]))
|
2019-05-30 17:37:49 +05:30
|
|
|
|
2019-05-27 01:00:38 +05:30
|
|
|
compressType = None
|
2015-08-08 00:33:26 +05:30
|
|
|
former = start = -1
|
2012-09-05 20:45:11 +05:30
|
|
|
reps = 0
|
|
|
|
|
2019-05-29 11:19:43 +05:30
|
|
|
if name is None:
|
|
|
|
f = sys.stdout
|
|
|
|
else:
|
|
|
|
f= open(name,'w')
|
|
|
|
|
|
|
|
for current in geom.microstructure.flatten('F'):
|
2019-05-27 01:00:38 +05:30
|
|
|
if abs(current - former) == 1 and (start - current) == reps*(former - current):
|
|
|
|
compressType = 'to'
|
|
|
|
reps += 1
|
|
|
|
elif current == former and start == former:
|
|
|
|
compressType = 'of'
|
|
|
|
reps += 1
|
|
|
|
else:
|
2019-05-27 02:22:23 +05:30
|
|
|
if compressType is None:
|
2019-05-29 11:19:43 +05:30
|
|
|
f.write('\n'.join(geom.get_header())+'\n')
|
2019-05-27 01:00:38 +05:30
|
|
|
elif compressType == '.':
|
2019-05-29 11:19:43 +05:30
|
|
|
f.write('{}\n'.format(former))
|
2019-05-27 01:00:38 +05:30
|
|
|
elif compressType == 'to':
|
2019-05-29 11:19:43 +05:30
|
|
|
f.write('{} to {}\n'.format(start,former))
|
2019-05-27 01:00:38 +05:30
|
|
|
elif compressType == 'of':
|
2019-05-29 11:19:43 +05:30
|
|
|
f.write('{} of {}\n'.format(reps,former))
|
2019-05-27 01:00:38 +05:30
|
|
|
|
|
|
|
compressType = '.'
|
|
|
|
start = current
|
|
|
|
reps = 1
|
|
|
|
|
|
|
|
former = current
|
2019-05-30 17:37:49 +05:30
|
|
|
|
2019-05-27 01:00:38 +05:30
|
|
|
if compressType == '.':
|
2019-05-29 11:19:43 +05:30
|
|
|
f.write('{}\n'.format(former))
|
2019-05-27 01:00:38 +05:30
|
|
|
elif compressType == 'to':
|
2019-05-29 11:19:43 +05:30
|
|
|
f.write('{} to {}\n'.format(start,former))
|
2019-05-27 01:00:38 +05:30
|
|
|
elif compressType == 'of':
|
2019-05-29 11:19:43 +05:30
|
|
|
f.write('{} of {}\n'.format(reps,former))
|