Skip to content

Commit

Permalink
Add native_str to MSEED record script.
Browse files Browse the repository at this point in the history
  • Loading branch information
QuLogic committed Jul 8, 2014
1 parent 6eb1440 commit 0bea6e3
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions obspy/mseed/scripts/recordanalyzer.py
Expand Up @@ -23,6 +23,7 @@
from __future__ import (absolute_import, division, print_function,
unicode_literals)
from future.builtins import * # NOQA
from future.utils import native_str

from copy import deepcopy
from obspy import UTCDateTime
Expand Down Expand Up @@ -114,7 +115,7 @@ def _getEndianess(self):
# Seek the year.
self.file.seek(self.record_offset + 20, 0)
# Get the year.
year = unpack('>H', self.file.read(2))[0]
year = unpack(native_str('>H'), self.file.read(2))[0]
if year >= 1900 and year <= 2050:
self.endian = '>'
else:
Expand All @@ -133,7 +134,7 @@ def _readFixedHeader(self):
# Read and unpack.
self.file.seek(self.record_offset, 0)
fixed_header = self.file.read(48)
encoding = ('%s20c2H3Bx4H4Bl2H' % self.endian)
encoding = native_str('%s20c2H3Bx4H4Bl2H' % self.endian)
header_item = unpack(encoding, fixed_header)
# Write values to dictionary.
self.fixed_header['Sequence number'] = int(''.join(header_item[:6]))
Expand Down Expand Up @@ -180,8 +181,8 @@ def _getBlockettes(self):
self.file.seek(cur_blkt_offset, 0)
# Unpack the first two values. This is always the blockette type
# and the beginning of the next blockette.
blkt_type, next_blockette = unpack('%s2H' % self.endian,
self.file.read(4))
encoding = native_str('%s2H' % self.endian)
blkt_type, next_blockette = unpack(encoding, self.file.read(4))
blkt_type = int(blkt_type)
next_blockette = int(next_blockette)
cur_blkt_offset = next_blockette
Expand All @@ -198,17 +199,17 @@ def _parseBlockette(self, blkt_type):
blkt_dict = OrderedDict()
# Check the blockette number.
if blkt_type == 100:
unpack_values = unpack('%sfxxxx' % self.endian,
unpack_values = unpack(native_str('%sfxxxx' % self.endian),
self.file.read(8))
blkt_dict['Sampling Rate'] = float(unpack_values[0])
elif blkt_type == 1000:
unpack_values = unpack('%sBBBx' % self.endian,
unpack_values = unpack(native_str('%sBBBx' % self.endian),
self.file.read(4))
blkt_dict['Encoding Format'] = int(unpack_values[0])
blkt_dict['Word Order'] = int(unpack_values[1])
blkt_dict['Data Record Length'] = int(unpack_values[2])
elif blkt_type == 1001:
unpack_values = unpack('%sBBxB' % self.endian,
unpack_values = unpack(native_str('%sBBxB' % self.endian),
self.file.read(4))
blkt_dict['Timing quality'] = int(unpack_values[0])
blkt_dict['mu_sec'] = int(unpack_values[1])
Expand Down

0 comments on commit 0bea6e3

Please sign in to comment.