# coding: utf8
# Part of the bioread package for reading BIOPAC data.
#
# Copyright (c) 2010 Board of Regents of the University of Wisconsin System
#
# Written by John Ollinger <ollinger@wisc.edu> and Nate Vack <njvack@wisc.edu>
# at the Waisman Laboratory for Brain Imaging and Behavior, University of
# Wisconsin-Madison

# This contains the entry point for an executable to convert BIOPAC
# AcqKnowledge files into Matlab files.

import sys
import os.path
from optparse import OptionParser

from bioread.readers import AcqReader
from bioread.writers import MatlabWriter


def main(argv = None):
    if argv is None:
        argv = sys.argv

    amr = AcqToMatRunner(argv)
    amr.run()


class AcqToMatRunner(object):
    """The little wrapper class that converts acq files to mat files"""

    def __init__(self, argv):
        self.argv = argv

    def run(self):
        self.parser = self.__make_parser()
        options, args = self.parser.parse_args(self.argv[1:])
        if len(args) <> 2:
            self.parser.error("Must specify both ACQ_FILE and MAT_FILE.")
        data = AcqReader.read_file(args[0])
        MatlabWriter.write_file(data, args[1], compress=options.compress)

    def __make_parser(self):
        parser = OptionParser("Usage: %prog [options] ACQ_FILE MAT_FILE")
        parser.add_option('-c', '--compress', dest='compress', default=False,
            action='store_true', help="Save compressed Matlab file")

        return parser

if __name__ == '__main__':
    main()
