From 3705b2a39f7627fadbac04e65d78887b438234cd Mon Sep 17 00:00:00 2001
From: "Christoph.Knote" <christoph.knote@physik.uni-muenchen.de>
Date: Tue, 19 Dec 2017 09:59:02 +0100
Subject: [PATCH] Updated ConcentrationOutput reading routine (faster).
 Exposing InputFileOrig, InputFile17 for documentation.

---
 boxmox/__init__.py |  2 +-
 boxmox/data.py     | 13 ++++++++++++-
 docs/index.rst     |  4 +++-
 3 files changed, 16 insertions(+), 3 deletions(-)

diff --git a/boxmox/__init__.py b/boxmox/__init__.py
index 29c3ce1..d0ebe91 100644
--- a/boxmox/__init__.py
+++ b/boxmox/__init__.py
@@ -5,7 +5,7 @@ except:
 
 import _installation
 
-from data import InputFile, Output, ConcentrationOutput, RatesOutput, AdjointOutput, JacobianOutput, HessianOutput
+from data import InputFile, InputFileOrig, InputFile17, Output, ConcentrationOutput, RatesOutput, AdjointOutput, JacobianOutput, HessianOutput
 from fluxes import FluxParser
 
 work_path = _installation.validate()
diff --git a/boxmox/data.py b/boxmox/data.py
index dfcce78..8a875f8 100644
--- a/boxmox/data.py
+++ b/boxmox/data.py
@@ -43,6 +43,11 @@ def _mygenfromtxt(f):
     return np.array(dat, dtype=[(_, float) for _ in hdr])
 
 def InputFile(fpath=None, version=1.7):
+    '''
+    Returns an instance of a BOXMOX input file class, either old format if
+    version < 1.7 (class InputFileOrig), or the current file format
+    (class InputFile17).
+    '''
     if not fpath is None:
         # file format discovery: 3 lines with numbers ==> 1.7
         with open(fpath, 'rb') as f:
@@ -324,7 +329,13 @@ class ConcentrationOutput(Output):
     def __init__(self, fpath, vars=None):
         self.fpath = fpath
         with open(fpath, 'rb') as f:
-            self.data = _mygenfromtxt(f)
+            # not using mygenfromtxt as we know the file format and this is way faster...
+            spamreader = csv.reader(f, skipinitialspace = True, delimiter=" ")
+            hdr = spamreader.next()
+            dat = []
+            for row in spamreader:
+                dat.append( tuple(map(float, row)) )
+        self.data = np.array(dat, dtype=[(_, float) for _ in hdr])
         self.times = self.data['time']
         if not vars is None:
             self.data = self.data[vars]
diff --git a/docs/index.rst b/docs/index.rst
index 1e49be7..33bfede 100644
--- a/docs/index.rst
+++ b/docs/index.rst
@@ -129,7 +129,9 @@ Experiment
 Input/Output
 ^^^^^^^^^^^^
 
-.. autoclass:: InputFile
+.. autofunction:: InputFile
+.. autoclass:: InputFile17
+.. autoclass:: InputFileOrig
 
 .. autoclass:: ConcentrationOutput
    :inherited-members:
-- 
GitLab