From b2f64a80187e61510144f424a7d577d4bee501dd Mon Sep 17 00:00:00 2001
From: Yngve Inntjore Levinsen <Yngve.Levinsen@esss.se>
Date: Wed, 2 Dec 2015 15:35:06 +0100
Subject: [PATCH] the counting has changed also some cosmetic cleaning

---
 ess/TraceWin.py | 21 +++++++++++----------
 1 file changed, 11 insertions(+), 10 deletions(-)

diff --git a/ess/TraceWin.py b/ess/TraceWin.py
index 9c1a961..8d7bead 100644
--- a/ess/TraceWin.py
+++ b/ess/TraceWin.py
@@ -496,19 +496,19 @@ class density_file:
         version=numpy.fromfile(self.fin, dtype=numpy.int16, count=1)[0]
         year=numpy.fromfile(self.fin, dtype=numpy.int16, count=1)[0]
 
-        # there is much more data written, but it is undocumented. Our trick to get back "on line":
+        # in case we did not read all data, this will detect our mistake:
         shift=0
         while year!=2011 or version!=8:
             shift+=1
             version=year
             year=numpy.fromfile(self.fin, dtype=numpy.int16, count=1)[0]
 
-        self.vlong=numpy.fromfile(self.fin, dtype=numpy.int16, count=1)[0]
-        self.Nrun=numpy.fromfile(self.fin, dtype=numpy.int32, count=1)[0]
-
         if shift:
             raise ValueError("ERROR, shifted "+str(shift*2)+" bytes")
 
+        self.vlong=numpy.fromfile(self.fin, dtype=numpy.int16, count=1)[0]
+        self.Nrun=numpy.fromfile(self.fin, dtype=numpy.int32, count=1)[0]
+
         self.version=version
         self.year=year
 
@@ -517,15 +517,16 @@ class density_file:
         import numpy
 
         self._getHeader()
-        
+
         if self.envelope:
             numpy.fromfile(self.fin, dtype=numpy.int16, count=292/2)
+        elif self.version==8:
+            numpy.fromfile(self.fin, dtype=numpy.int16, count=12344/2)
+        elif self.Nrun>1:
+            #WARN not 100% sure if this is correct..
+            numpy.fromfile(self.fin, dtype=numpy.int16, count=((5588+self.Nrun*12)/2))
         else:
-            if self.version==8:
-                numpy.fromfile(self.fin, dtype=numpy.int16, count=8344/2)
-            if self.Nrun>1:
-                #WARN not 100% sure if this is correct..
-                numpy.fromfile(self.fin, dtype=numpy.int16, count=((5588+self.Nrun*12)/2))
+            raise TypeError("It is not possible to read this format..")
 
     def _get_7dim_array(array):
         '''
-- 
GitLab