From 04a4007c21123e7fb95947c5636c8e31080c9f73 Mon Sep 17 00:00:00 2001
From: Hal Simpson <hasimpson@usgs.gov>
Date: Thu, 12 Nov 2015 12:26:25 -0700
Subject: [PATCH] Added try/except block to catch bad lines as seen from Guam.

---
 geomagio/imfv283/IMFV283Parser.py | 38 +++++++++++++++++++------------
 1 file changed, 23 insertions(+), 15 deletions(-)

diff --git a/geomagio/imfv283/IMFV283Parser.py b/geomagio/imfv283/IMFV283Parser.py
index 1a8895306..467b75d01 100644
--- a/geomagio/imfv283/IMFV283Parser.py
+++ b/geomagio/imfv283/IMFV283Parser.py
@@ -75,22 +75,30 @@ class IMFV283Parser(object):
                 sys.stderr.write('Bad Header length\n')
                 continue
 
-            msg_header = self._parse_msg_header(line)
+            try:
+                msg_header = self._parse_msg_header(line)
+                print msg_header
+
+                data_len = msg_header['data_len']
+                # check message size indicates data exists
+                if data_len < MSG_SIZE_100B or data_len > MSG_SIZE_300B:
+                    sys.stderr.write('Incorrect data Length \n')
+                    continue
+
+                goes_data = self._process_ness_block(
+                        line,
+                        imfv283_codes.OBSERVATORIES[msg_header['obs']],
+                        data_len)
+
+                goes_header = self._parse_goes_header(goes_data)
+                print goes_header
+                data = self._get_data(goes_header, goes_data)
+                self._post_process(data, msg_header, goes_header)
+            except KeyError as e:
+                print "Incorrect data line"
+                print e
+                print line
 
-            data_len = msg_header['data_len']
-            # check message size indicates data exists
-            if data_len < MSG_SIZE_100B or data_len > MSG_SIZE_300B:
-                sys.stderr.write('Incorrect data Length \n')
-                continue
-
-            goes_data = self._process_ness_block(
-                    line,
-                    imfv283_codes.OBSERVATORIES[msg_header['obs']],
-                    data_len)
-
-            goes_header = self._parse_goes_header(goes_data)
-            data = self._get_data(goes_header, goes_data)
-            self._post_process(data, msg_header, goes_header)
 
     def _get_data(self, header, data):
         """get data from data packet
-- 
GitLab