From 3e006c3983fc4d3ee350707cd1f72daa2fc5b095 Mon Sep 17 00:00:00 2001
From: Yngve Inntjore Levinsen <Yngve.Levinsen@esss.se>
Date: Thu, 8 Jan 2015 15:10:58 +0100
Subject: [PATCH] reading and merging of remote data (to generate a combined
 partran.out from studies

---
 ess/TraceWin.py | 51 +++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 51 insertions(+)

diff --git a/ess/TraceWin.py b/ess/TraceWin.py
index a125c79..2a26daa 100644
--- a/ess/TraceWin.py
+++ b/ess/TraceWin.py
@@ -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
+
-- 
GitLab