# Path: blimpy/io/sigproc.py
# def generate_sigproc_header(f):
#     """ Generate a serialzed sigproc header which can be written to disk.
# 
#     Args:
#         f (Filterbank object): Filterbank object for which to generate header
# 
#     Returns:
#         header_str (str): Serialized string corresponding to header
#     """
# 
#     header_string = b''
#     header_string += to_sigproc_keyword('HEADER_START')
# 
#     for keyword in f.header.keys():
#         if keyword == 'src_raj':
#             header_string += to_sigproc_keyword('src_raj')  + to_sigproc_angle(f.header['src_raj'])
#         elif keyword == 'src_dej':
#             header_string += to_sigproc_keyword('src_dej')  + to_sigproc_angle(f.header['src_dej'])
#         elif keyword in ('az_start', 'za_start'):
#             header_string += to_sigproc_keyword(keyword)  + np.float64(f.header[keyword]).tobytes()
#         elif keyword not in header_keyword_types.keys():
#             pass
#         else:
#             header_string += to_sigproc_keyword(keyword, f.header[keyword])
# 
#     header_string += to_sigproc_keyword('HEADER_END')
#     return header_string


import time
import numpy as np
from .sigproc import generate_sigproc_header
        fileh.write(generate_sigproc_header(wf))

        # For each blob
        for ii in range(0, n_blobs):

            wf.logger.info('__write_to_fil_heavy: Processing %i of %i' % (ii + 1, n_blobs))
            bob = wf.container.read_blob(blob_dim, n_blob=ii)

            # Write data of .fil file.
            if n_bytes == 4:
                np.float32(bob.ravel()).tofile(fileh)
            elif n_bytes == 2:
                np.int16(bob.ravel()).tofile(fileh)
            elif n_bytes == 1:
                np.int8(bob.ravel()).tofile(fileh)


def __write_to_fil_light(wf, filename_out):
    """ Write data to .fil file.

    Args:
        wf : Waterfall object
        filename_out : str
            Name of output file
    """

    wf.logger.info("__write_to_fil_light: Writing the spectra matrix for {} in one go."
                   .format(filename_out))
    n_bytes = wf.header['nbits'] / 8
    with open(filename_out, "wb") as fileh:

# Path: blimpy/io/sigproc.py
# def generate_sigproc_header(f):
#     """ Generate a serialzed sigproc header which can be written to disk.
# 
#     Args:
#         f (Filterbank object): Filterbank object for which to generate header
# 
#     Returns:
#         header_str (str): Serialized string corresponding to header
#     """
# 
#     header_string = b''
#     header_string += to_sigproc_keyword('HEADER_START')
# 
#     for keyword in f.header.keys():
#         if keyword == 'src_raj':
#             header_string += to_sigproc_keyword('src_raj')  + to_sigproc_angle(f.header['src_raj'])
#         elif keyword == 'src_dej':
#             header_string += to_sigproc_keyword('src_dej')  + to_sigproc_angle(f.header['src_dej'])
#         elif keyword in ('az_start', 'za_start'):
#             header_string += to_sigproc_keyword(keyword)  + np.float64(f.header[keyword]).tobytes()
#         elif keyword not in header_keyword_types.keys():
#             pass
#         else:
#             header_string += to_sigproc_keyword(keyword, f.header[keyword])
# 
#     header_string += to_sigproc_keyword('HEADER_END')
#     return header_string


# Path: blimpy/io/fil_writer.py
import time
import numpy as np
from .sigproc import generate_sigproc_header

        fileh.write(generate_sigproc_header(wf))

        # For each blob
        for ii in range(0, n_blobs):

            wf.logger.info('__write_to_fil_heavy: Processing %i of %i' % (ii + 1, n_blobs))
            bob = wf.container.read_blob(blob_dim, n_blob=ii)

            # Write data of .fil file.
            if n_bytes == 4:
                np.float32(bob.ravel()).tofile(fileh)
            elif n_bytes == 2:
                np.int16(bob.ravel()).tofile(fileh)
            elif n_bytes == 1:
                np.int8(bob.ravel()).tofile(fileh)


def __write_to_fil_light(wf, filename_out):
    """ Write data to .fil file.

    Args:
        wf : Waterfall object
        filename_out : str
            Name of output file
    """

    wf.logger.info("__write_to_fil_light: Writing the spectra matrix for {} in one go."
                   .format(filename_out))
    n_bytes = wf.header['nbits'] / 8
    with open(filename_out, "wb") as fileh:

        fileh.write(generate_sigproc_header(wf))