#!/usr/bin/env python
'''
Copyright (c) 2015 Computational Biomechanics (CoBi) Core, Department of
Biomedical Engineering, Cleveland Clinic

Permission is hereby granted, free of charge, to any person obtaining a
copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to permit
persons to whom the Software is furnished to do so, subject to the
following conditions:

The above copyright notice and this permission notice shall be included
in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
USE OR OTHER DEALINGS IN THE SOFTWARE.
-------------------

tdms_contents.py

DESCRIPTION:

Python script to read a tdms file and output labels for groups and channels.

REQUIREMENTS:

Python (http://www.python.org)
nptdms (https://pypi.python.org/pypi/npTDMS/)

DEVELOPERS:

Ahmet Erdemir
Computational Biomodeling (CoBi) Core
Department of Biomedical Engineering
Lerner Research Institute
Cleveland Clinic
Cleveland, OH
erdemira@ccf.org

'''

import sys
from nptdms import TdmsFile

def tdms_contents(argv):

    # Set tdms file name
    tdms_file = TdmsFile(argv[-1])
    groups = tdms_file.groups()
    for group in groups:
        print group
        channels = tdms_file.group_channels(group)
        for channel in channels:
            try:
                channel_label = channel.properties['NI_ChannelName']
                channel_data = channel.data
            except:
                break
            print ' -> ' + channel_label
            print channel_data
#			print channel.properties
#			channel_object = tdms_file.object(group, channel_label)

#			channel_time = channel.time_track()
            print ' '

if __name__ == "__main__":
    tdms_contents(sys.argv)


