# Path: blimpy/io/sigproc.py
# def len_header(filename):
# def read_next_header_keyword(fh):
# def is_filterbank(filename):
# def read_header(filename, return_idxs=False):
# def fix_header(filename, keyword, new_value):
# def fil_double_to_angle(angle):
# def to_sigproc_keyword(keyword, value=None):
# def generate_sigproc_header(f):
# def to_sigproc_angle(angle_val):
# def calc_n_ints_in_file(filename):
#     GULP = 4096
# 
# Path: blimpy/io/base_reader.py
# GIGA = 1024 ** 3
# HIRES_THRESHOLD = 2**20
# class Reader(object):
#     def __init__(self):
#     def _setup_selection_range(self, f_start=None, f_stop=None, t_start=None, t_stop=None, init=False):
#         def _dump_parms():
#     def _init_empty_selection(self):
#     def _setup_dtype(self):
#     def _calc_selection_size(self):
#     def _calc_selection_shape(self):
#     def _setup_chans(self):
#     def _setup_freqs(self):
#     def populate_timestamps(self,update_header=False):
#     def populate_freqs(self):
#     def adjust_n_coarse_chan(self, n_coarse_chan, nchans):
#     def calc_n_coarse_chan(self, chan_bw=None):
#     def calc_n_blobs(self, blob_dim):
#     def warn_memory(self, name, size):
#     def isheavy(self):


import os
import numpy as np
from blimpy.io import sigproc
from blimpy.io.base_reader import Reader, logger, GIGA

        n_blobs = self.calc_n_blobs(blob_dim)
        if n_blob > n_blobs or n_blob < 0:
            raise ValueError('Please provide correct n_blob value. Given %i, but max values is %i'%(n_blob,n_blobs))

        # This prevents issues when the last blob is smaller than the others in time.
        if blob_dim[self.time_axis]*(n_blob+1) > self.selection_shape[self.time_axis]:
            updated_blob_dim = (int(self.selection_shape[self.time_axis] - blob_dim[self.time_axis]*n_blob), 1, int(blob_dim[self.freq_axis]))
        else:
            updated_blob_dim = [int(i) for i in blob_dim]

        blob_start = self._find_blob_start()
        blob = np.zeros(updated_blob_dim, dtype=self._d_type)

        # EE: For now; also assuming one polarization and one beam.

        # Assuming the blob will loop over the whole frequency range.
        if self.f_start == self.f_begin and self.f_stop == self.f_end:

            blob_flat_size = np.prod(blob_dim)
            updated_blob_flat_size = np.prod(updated_blob_dim)

            # Load binary data
            with open(self.filename, 'rb') as f:
                f.seek(int(self.idx_data + self._n_bytes  * (blob_start + n_blob*blob_flat_size)))
                dd = np.fromfile(f, count=updated_blob_flat_size, dtype=self._d_type)

            if dd.shape[0] == updated_blob_flat_size:
                blob = dd.reshape(updated_blob_dim)
            else:

# Path: blimpy/io/sigproc.py
# def len_header(filename):
# def read_next_header_keyword(fh):
# def is_filterbank(filename):
# def read_header(filename, return_idxs=False):
# def fix_header(filename, keyword, new_value):
# def fil_double_to_angle(angle):
# def to_sigproc_keyword(keyword, value=None):
# def generate_sigproc_header(f):
# def to_sigproc_angle(angle_val):
# def calc_n_ints_in_file(filename):
#     GULP = 4096
# 
# Path: blimpy/io/base_reader.py
# GIGA = 1024 ** 3
# HIRES_THRESHOLD = 2**20
# class Reader(object):
#     def __init__(self):
#     def _setup_selection_range(self, f_start=None, f_stop=None, t_start=None, t_stop=None, init=False):
#         def _dump_parms():
#     def _init_empty_selection(self):
#     def _setup_dtype(self):
#     def _calc_selection_size(self):
#     def _calc_selection_shape(self):
#     def _setup_chans(self):
#     def _setup_freqs(self):
#     def populate_timestamps(self,update_header=False):
#     def populate_freqs(self):
#     def adjust_n_coarse_chan(self, n_coarse_chan, nchans):
#     def calc_n_coarse_chan(self, chan_bw=None):
#     def calc_n_blobs(self, blob_dim):
#     def warn_memory(self, name, size):
#     def isheavy(self):


# Path: blimpy/io/fil_reader.py
import os
import numpy as np
from blimpy.io import sigproc
from blimpy.io.base_reader import Reader, logger, GIGA


        n_blobs = self.calc_n_blobs(blob_dim)
        if n_blob > n_blobs or n_blob < 0:
            raise ValueError('Please provide correct n_blob value. Given %i, but max values is %i'%(n_blob,n_blobs))

        # This prevents issues when the last blob is smaller than the others in time.
        if blob_dim[self.time_axis]*(n_blob+1) > self.selection_shape[self.time_axis]:
            updated_blob_dim = (int(self.selection_shape[self.time_axis] - blob_dim[self.time_axis]*n_blob), 1, int(blob_dim[self.freq_axis]))
        else:
            updated_blob_dim = [int(i) for i in blob_dim]

        blob_start = self._find_blob_start()
        blob = np.zeros(updated_blob_dim, dtype=self._d_type)

        # EE: For now; also assuming one polarization and one beam.

        # Assuming the blob will loop over the whole frequency range.
        if self.f_start == self.f_begin and self.f_stop == self.f_end:

            blob_flat_size = np.prod(blob_dim)
            updated_blob_flat_size = np.prod(updated_blob_dim)

            # Load binary data
            with open(self.filename, 'rb') as f:
                f.seek(int(self.idx_data + self._n_bytes  * (blob_start + n_blob*blob_flat_size)))
                dd = np.fromfile(f, count=updated_blob_flat_size, dtype=self._d_type)

            if dd.shape[0] == updated_blob_flat_size:
                blob = dd.reshape(updated_blob_dim)
            else:

                logger.info('DD shape != blob shape.')