Skip to content
Snippets Groups Projects
Commit 3e006c39 authored by Yngve Levinsen's avatar Yngve Levinsen
Browse files

reading and merging of remote data

(to generate a combined partran.out from studies
parent 7d18469c
No related branches found
No related tags found
No related merge requests found
......@@ -229,3 +229,54 @@ class density_file:
if self.ib[self.i]>0:
tabp=numpy.fromfile(self.fin, dtype=numpy.uint32, count=3*step)
class remote_data_merger:
def __init__(self, base='.'):
self._base=base
self._files=[]
def add_file(self,filepath):
import os
if os.path.exists(filepath):
fname=filepath
else:
fullpath=os.path.join(self._base,filepath)
if os.path.exists(fullpath):
fname=fullpath
else:
raise ValueError("Could not find file "+filepath)
if fname not in self._files:
self._files.append(fname)
def generate_partran_out(self,filename=None):
'''
Creates a string to be written to file
each line is a list.
If filename is given, writes directly to output file.
'''
data=[]
count=0
if self._files:
for f in self._files:
string=file(f,'r').read()
split=string.split('$$$')
if split[9]!='Data_Error':
raise ValueError("Magic problem, please complain to Yngve")
thisdata=split[10].strip().split('\n')
if not data:
data=thisdata
else:
data.insert(1+count,thisdata[1])
data.insert(10+2*count,thisdata[10])
data.insert(11+3*count,thisdata[11])
count+=1
if filename:
file(filename,'w').write('\n'.join(data))
return data
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment