Skip to content

Commit

Permalink
XTFPingHeader: Emit warning instead of exception when no samples
Browse files Browse the repository at this point in the history
A XTFBathyHeader without any samples is permitted according to the spec
  • Loading branch information
oysstu committed Jul 20, 2018
1 parent c00d8b5 commit 03371b7
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions pyxtf/xtf_ctypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from io import IOBase, BytesIO
from typing import List
import numpy as np
from warnings import warn

from pyxtf.enumerations import *

Expand Down Expand Up @@ -600,7 +601,7 @@ def __new__(cls, buffer: IOBase = None, file_header: XTFFileHeader = None):
n_bytes = p_header.NumBytesThisRecord - ctypes.sizeof(XTFPingHeader)
samples = buffer.read(n_bytes)
if not samples:
raise Exception('XTF data packets missing (file corrupt?)')
warn('XTFBathyHeader without any data encountered.')

# Processed bathy data consists of repeated XTFBeamXYZA structures
# Note: Using a ctypes array is a _lot_ faster than constructing a list of BeamXYZA
Expand All @@ -620,7 +621,7 @@ def __new__(cls, buffer: IOBase = None, file_header: XTFFileHeader = None):
n_bytes = p_header.NumBytesThisRecord - ctypes.sizeof(XTFPingHeader) - ctypes.sizeof(XTFPingChanHeader)
samples = buffer.read(n_bytes)
if not samples:
raise Exception('XTF data packets missing (file corrupt?)')
warn('XTFPingHeader (Reson7018) without any data encountered.')

p_header.data = samples

Expand All @@ -629,7 +630,7 @@ def __new__(cls, buffer: IOBase = None, file_header: XTFFileHeader = None):
n_bytes = p_header.NumBytesThisRecord - ctypes.sizeof(XTFPingHeader)
samples = buffer.read(n_bytes)
if not samples and n_bytes > 0:
raise Exception('XTF data packets missing (file corrupt?)')
warn('XTFPingHeader without any data encountered.')

# The data is the raw bytes following the header
p_header.data = samples
Expand Down

0 comments on commit 03371b7

Please sign in to comment.