From c9e55d5ce8c13f4274c36ab815b765d6d068864e Mon Sep 17 00:00:00 2001
From: Yngve Inntjore Levinsen <Yngve.Levinsen@esss.se>
Date: Fri, 25 Sep 2015 16:20:56 +0200
Subject: [PATCH] fix for dst read toutatis distributions has a 7th line of
 zeros now can read both correctly

---
 ess/TraceWin.py | 13 +++++++++----
 1 file changed, 9 insertions(+), 4 deletions(-)

diff --git a/ess/TraceWin.py b/ess/TraceWin.py
index 4eaf6dd..fdfe8e6 100644
--- a/ess/TraceWin.py
+++ b/ess/TraceWin.py
@@ -42,15 +42,20 @@ class dst:
         self.Ib=Header['Ib'][0]
         self.freq=Header['freq'][0]
 
-        Table=numpy.fromfile(fin, dtype=numpy.float64, count=self.Np*6)
-        self._data=Table.reshape(self.Np,6)
+        # Some toutatis distributions has an undocumented 7th line of 0's
+        Table=numpy.fromfile(fin, dtype=numpy.float64, count=self.Np*7+1)
+        if len(Table)==self.Np*7+1:
+            self._data=Table[:-1].reshape(self.Np,7)
+        elif len(Table)==self.Np*6+1: # this is true in most cases
+            self._data=Table[:-1].reshape(self.Np,6)
+        else:
+            raise ValueError("Incorrect table dimensions found:",len(Table))
 
         # convert x,y from cm to m:
         self._data[:,0]*=1e-2
         self._data[:,2]*=1e-2
 
-        Footer=numpy.fromfile(fin, dtype=numpy.float64, count=1)
-        self.mass=Footer[0]
+        self.mass=Table[-1]
 
     def keys(self):
         return self._columns[:]
-- 
GitLab