def __init__(self, handle):
        '''Initialize this C3D file by reading header and parameter data.

        Parameters
        ----------
        handle : file handle
            Read metadata and C3D motion frames from the given file handle. This
            handle is assumed to be `seek`-able and `read`-able. The handle must
            remain open for the life of the `Reader` instance. The `Reader` does
            not `close` the handle.

        Raises
        ------
        ValueError
            If the processor metadata in the C3D file is anything other than 84
            (Intel format).
        '''
        super(Reader, self).__init__(Header(handle))

        self._handle = handle
        self._handle.seek((self.header.parameter_block - 1) * 512)

        # metadata header
        buf = self._handle.read(4)
        _, _, parameter_blocks, processor = struct.unpack('BBBB', buf)
        if processor != PROCESSOR_INTEL:
            raise ValueError(
                'we only read Intel C3D files (got processor {})'.
                format(processor))

        # read all parameter blocks as a single chunk to avoid block
        # boundary issues.
        bytes = self._handle.read(512 * parameter_blocks - 4)
        while bytes:
            buf = io.BytesIO(bytes)

            chars_in_name, group_id = struct.unpack('bb', buf.read(2))
            if group_id == 0 or chars_in_name == 0:
                # we've reached the end of the parameter section.
                break

            name = buf.read(abs(chars_in_name)).decode('utf-8').upper()
            offset_to_next, = struct.unpack('<h', buf.read(2))

            if group_id > 0:
                # we've just started reading a parameter. if its group doesn't
                # exist, create a blank one. add the parameter to the group.
                self.groups.setdefault(group_id, Group()).add_param(name, handle=buf)
            else:
                # we've just started reading a group. if a group with the
                # appropriate id exists already (because we've already created
                # it for a parameter), just set the name of the group.
                # otherwise, add a new group.
                group_id = abs(group_id)
                size, = struct.unpack('B', buf.read(1))
                desc = size and buf.read(size) or ''
                group = self.get(group_id)
                if group is not None:
                    group.name = name
                    group.desc = desc
                    self.groups[name] = group
                else:
                    self.add_group(group_id, name, desc)

            bytes = bytes[2 + abs(chars_in_name) + offset_to_next:]

        self.check_metadata()
def __init__ ( self , handle ) : super ( Reader , self ) . __init__ ( Header ( handle ) ) self . _handle = handle self . _handle . seek ( ( self . header . parameter_block - 1 ) * 512 ) buf = self . _handle . read ( 4 ) _ , _ , parameter_blocks , processor = struct . unpack ( 'BBBB' , buf ) if processor != PROCESSOR_INTEL : raise ValueError ( 'we only read Intel C3D files (got processor {})' . format ( processor ) ) bytes = self . _handle . read ( 512 * parameter_blocks - 4 ) while bytes : buf = io . BytesIO ( bytes ) chars_in_name , group_id = struct . unpack ( 'bb' , buf . read ( 2 ) ) if group_id == 0 or chars_in_name == 0 : break name = buf . read ( abs ( chars_in_name ) ) . decode ( 'utf-8' ) . upper ( ) offset_to_next , = struct . unpack ( '<h' , buf . read ( 2 ) ) if group_id > 0 : self . groups . setdefault ( group_id , Group ( ) ) . add_param ( name , handle = buf ) else : group_id = abs ( group_id ) size , = struct . unpack ( 'B' , buf . read ( 1 ) ) desc = size and buf . read ( size ) or '' group = self . get ( group_id ) if group is not None : group . name = name group . desc = desc self . groups [ name ] = group else : self . add_group ( group_id , name , desc ) bytes = bytes [ 2 + abs ( chars_in_name ) + offset_to_next : ] self . check_metadata ( )
Initialize this C3D file by reading header and parameter data.

        Parameters
        ----------
        handle : file handle
            Read metadata and C3D motion frames from the given file handle. This
            handle is assumed to be `seek`-able and `read`-able. The handle must
            remain open for the life of the `Reader` instance. The `Reader` does
            not `close` the handle.

        Raises
        ------
        ValueError
            If the processor metadata in the C3D file is anything other than 84
            (Intel format).