#!/usr/bin/env python """ Module to handle Scintec sodar .mnd files. """ __author__ = 'Chris Calloway' __email__ = 'cbc@chriscalloway.org' __copyright__ = 'Copyright 2009 UNC-CH Department of Marine Science' __license__ = 'GPL2' import os class MainData(object): """ Class to parse Scintec sodar .mnd files. Parse a the format header. >>> main_data = MainData(_testSetUp('good','091117.mnd')) >>> main_data.format_header[0] 'FORMAT-1\n' """ def __init__(self, mnd): """ Parse main daily Scintec sodar .mnd file. MainData(mnd) -> Where mnd is a str object containing the complete contents read from a Scintec .mnd daily sodar file including all line endings. """ super(MainData, self).__init__() self.blocks = [block.strip() for block in mnd.split('\n\n') if block.strip()] self.format_header = [line.strip() for line in blocks[0].split('\n') if line.strip()] self.file_header = [line.strip() for line in blocks[1].split('\n') if line.strip()] self.profile_blocks = blocks[2:] def _testSetUp(mnd_dir,mnd_file): current_dir = os.path.abspath(os.path.dirname(__file__)) package_dir = os.path.split(current_dir)[0] data_dir = os.path.join(package_dir,'tests','data') good_dir = os.path.join(data_dir,mnd_dir) mnd_file = os.path.join(good_dir,mnd_file) mnd = open(mnd_file).read() return mnd def _test(): import doctest doctest.testmod() if __name__ == "__main__": _test()