-
Notifications
You must be signed in to change notification settings - Fork 0
/
rdcol2.py
38 lines (34 loc) · 1.04 KB
/
rdcol2.py
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
# Takes in Filename, reads file columnwise, and returns dictionary such that:
# import rdcol
# a = rdcol.read('filename',headline,datastartline)
# a["Column_Name"] -> returns the list for that column
#
# headline and datastartline are always > 0
#
# By Dillon Brout
# dbrout@physics.upenn.edu
def read(filename,headline,startline):
linenum = 0
go = 0
column_list = []
return_cols = {}
inf = open(filename)
print 'found file'
for line in inf:
cols = line.split()
if linenum == headline - 1:
for col in cols:
return_cols[col] = []
column_list.append(col)
go = go + 1
if (linenum >= startline - 1):
index = 0
for col in cols:
try:
return_cols[column_list[index]].append(float(col))
except:
return_cols[column_list[index]].append(col)
index = index + 1
linenum = linenum + 1
inf.close()
return return_cols