forked from neumeist/twobody
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmerge_ascii.py
More file actions
executable file
·107 lines (84 loc) · 2.26 KB
/
merge_ascii.py
File metadata and controls
executable file
·107 lines (84 loc) · 2.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
#!/usr/bin/env python
################################################
#
# This script merges ASCII output of zprime
# batch jobs into one ASCII file, sorted
# by mass (first column) in the ascending order
#
#
# Gena Kukartsev, November 2010
#
################################################
import fileinput
import sys
def compare_columns(a, b):
# sort on ascending index 0, then 1
return cmp(a[0], b[0]) or cmp(a[1], b[1])
#return cmp(b[0], a[0]) or cmp(a[1], b[1])
def compare_columns_second(a, b):
# sort on ascending index 0, then 1
return cmp(a[1], b[1]) or cmp(a[0], b[0])
def fix_lines():
#print legend, 'about to fix missing newlines'
for line in fileinput.input():
_words = line.strip().split()
if _words[0][0] == '#':
continue
_i = 0
for w in _words:
print w,
_i +=1
if _i == 6:
print
#print 'HUJ!!!!!!!!!!!'
_i=0
legend = '[ASCII merge]:'
# if an output file is specified, write in the file
# otherwise to stdout
sort_by_second_column = False
if sys.argv[1] == '-f':
if len(sys.argv)>2:
ofile = open(sys.argv[2], "w")
sys.stdout = ofile
sys.argv.pop(1)
sys.argv.pop(1)
elif sys.argv[1] == '--fix':
sys.argv.pop(1)
fix_lines()
#print legend, 'done fixing missing newlines'
sys.exit(0)
if sys.argv[1] == '-r':
sys.argv.pop(1)
sort_by_second_column = True
#observed number
item_to_find = None
if sys.argv[1] == '-o':
item_to_find = sys.argv.pop(2)
sys.argv.pop(1)
sys.argv.pop(1)
_limits =[]
for line in fileinput.input():
#print legend, line.strip()
_words = line.strip().split()
if _words[0][0] == '#':
continue
_number = []
for word in _words:
_number.append(float(word))
_limits.append(_number)
if sort_by_second_column:
_limits.sort(compare_columns_second)
else:
_limits.sort(compare_columns)
counter = 0
for l in _limits:
#print l[0],l[1]
counter +=1
for n in l:
print n, ' ',
#print '#',item_to_find, l[1]
if item_to_find and float(item_to_find) < float(l[1]):
print counter, '(found',item_to_find, ')'
print
if item_to_find:
print item_to_find