Collapses a 'continuous' acquisition into a single dataset.
        This must be performed before calling *get* function for *key* in these 
        modes.

        :param key: name of the dataset to consolidate.
        :type key: str

def consolidate(self, key):
        """
        Collapses a 'continuous' acquisition into a single dataset.
        This must be performed before calling *get* function for *key* in these 
        modes.

        :param key: name of the dataset to consolidate.
        :type key: str
        """
        if self.meta[key]['mode'] not in ['continuous']:
            print "consolidation not supported for mode: ", self.meta[key]['mode']
            return

        # get a copy of the attributes saved, then delete placeholder
        attr_tmp = self.hdf5[key].attrs.items()
        del self.hdf5[key]

        setnum = self.meta[key]['set_counter']
        setnum -= 1 # convert from 1-indexed to 0-indexed
        current_index = self.meta[key]['cursor']
        total_samples = (self.chunk_size * setnum) + current_index
        self.datasets[key] = self.hdf5.create_dataset(key, (total_samples,))
        self.datasets[key].attrs['stim'] = '[ ' # space in case empty, closing replaces the space and not the [
        self.datasets[key].attrs['start'] = self.meta[key]['start']
        self.datasets[key].attrs['mode'] = 'continuous'

        for iset in range(0, setnum):
            self.datasets[key][iset*self.chunk_size:(iset+1)*self.chunk_size] = self.datasets[key+'_set'+str(iset+1)][:]
            self.datasets[key].attrs['stim'] = self.datasets[key].attrs['stim'] + self.datasets[key+'_set'+str(iset+1)].attrs['stim']
        
        # last set may not be complete
        if current_index != 0:
            self.datasets[key][setnum*self.chunk_size:(setnum*self.chunk_size)+current_index] = self.datasets[key+'_set'+str(setnum+1)][:current_index]
            self.datasets[key].attrs['stim'] = self.datasets[key].attrs['stim'] + self.datasets[key+'_set'+str(setnum+1)].attrs['stim']

        # make sure we have a closing bracket
        if self.datasets[key].attrs['stim'][-1] != ']':
            self.datasets[key].attrs['stim'] = self.datasets[key].attrs['stim'] + ']'
        
        # copy back attributes from placeholder
        for k, v in attr_tmp:
            self.datasets[key].attrs[k] = v

        # now go ahead and delete fractional sets.
        for iset in range(setnum+1):
            del self.datasets[key+'_set'+str(iset+1)]
            del self.hdf5[key+'_set'+str(iset+1)]

        print 'consolidated', self.hdf5.keys()
        print 'stim attr', self.datasets[key].attrs['stim']
        print
        self.needs_repack = True