From 31ce74bf0a1c73455e7b864a90603fc740d7a084 Mon Sep 17 00:00:00 2001
From: Anders Blomdell <anders.blomdell@control.lth.se>
Date: Sun, 4 Dec 2016 22:58:48 +0100
Subject: [PATCH] Description allowed in .select files, generate matlab file
 for each selected interval

---
 OP1.select     | 16 ++++++++--------
 README         |  3 +++
 data_select.py | 26 ++++++++++++++++++++++++--
 3 files changed, 35 insertions(+), 10 deletions(-)

diff --git a/OP1.select b/OP1.select
index 5cf4f7c..6335d3e 100644
--- a/OP1.select
+++ b/OP1.select
@@ -1,8 +1,8 @@
-2016-10-17:12:44:00,2016-10-17:12:47:00
-2016-10-18:11:33:00,2016-10-18:11:37:00
-2016-10-24:13:05:00,2016-10-24:13:10:00
-2016-11-01:12:43:30,2016-11-01:12:48:30
-2016-11-01:12:48:30,2016-11-01:12:53:30
-2016-11-01:12:53:30,2016-11-01:12:58:20
-2016-11-28:12:17:30,2016-11-28:12:21:00
-2016-11-30:11:12:00,2016-11-30:11:17:00
+2016-10-17:12:44:00,2016-10-17:12:47:00,kalman
+2016-10-18:11:33:00,2016-10-18:11:37:00,kalman
+2016-10-24:13:05:00,2016-10-24:13:10:00,kalman
+2016-11-01:12:43:30,2016-11-01:12:48:30,raw
+2016-11-01:12:48:30,2016-11-01:12:53:30,kalman
+2016-11-01:12:53:30,2016-11-01:12:58:20,average
+2016-11-28:12:17:30,2016-11-28:12:21:00,raw
+2016-11-30:11:12:00,2016-11-30:11:17:00,kalman
diff --git a/README b/README
index 36a787d..26b5e9b 100644
--- a/README
+++ b/README
@@ -1,3 +1,6 @@
 ./grab.py 1609200030 1609262200
 ./data_select.py OP1.select data/*
 ./plot.py --seconds selected/OP1
+
+# Select some columns to fit Matlab/Octave load command
+  cut -d, -f5-10  data/data_2016-11-01 > matlab/data_2016-11-01
diff --git a/data_select.py b/data_select.py
index 729adf8..d70691f 100755
--- a/data_select.py
+++ b/data_select.py
@@ -11,7 +11,17 @@ if __name__ == '__main__':
     segment = []
     for l in open(sys.argv[1]):
         # print(l)
-        t1,t2 = l.strip().split(',')
+        tmp = l.strip().split(',')
+        print(tmp)
+        if len(tmp) < 2:
+            print('No selection interval "%s"', l.strip())
+        if len(tmp) >= 2:
+            t1,t2 = tmp[0:2]
+        if len(tmp) >= 3:
+            description = tmp[2]
+        else:
+            description = ''
+        
         # print(t1,t2)
         # Get selection interval
         s1 = time.mktime(time.strptime(t1, '%Y-%m-%d:%H:%M:%S')) - Y2K
@@ -41,7 +51,7 @@ if __name__ == '__main__':
         t_total += s[-1][0] - s[0][0]
     time_jump = int(t_total * 0.2 / len(segment))
 
-    # Output selection
+    # Output selection suitable for plot program
     outfile = open('selected/%s' % op, 'w')
 
     # Empty space at start of plot
@@ -66,4 +76,16 @@ if __name__ == '__main__':
         pass
     pass
 
+    # Output selection suitable for matlab/octave
+    if not os.path.exists('matlab'):
+        os.mkdir('matlab')
+    if not os.path.exists('matlab/%s' % op):
+        os.mkdir('matlab/%s' % op)
+    for s in segment:
+        outfile = open('matlab/%s/%s' % (op, s[0][1].strip()), 'w')
+        for row in s:
+            print("%s" % (",".join(row[5:11])),
+                  file=outfile)
+        
+
         
-- 
GitLab