diff options
author | Tom Rondeau | 2012-11-21 17:27:09 -0500 |
---|---|---|
committer | Tom Rondeau | 2012-11-21 18:12:11 -0500 |
commit | c5d29f9029cd08393e8c91e7ff0d1aa966f10bdb (patch) | |
tree | e337ca581bdbb8626c628baeb7046ca18b86dcdf /gr-utils | |
parent | eb4163c7bdd63783e570fb28ba87144a4c86d22f (diff) | |
download | gnuradio-c5d29f9029cd08393e8c91e7ff0d1aa966f10bdb.tar.gz gnuradio-c5d29f9029cd08393e8c91e7ff0d1aa966f10bdb.tar.bz2 gnuradio-c5d29f9029cd08393e8c91e7ff0d1aa966f10bdb.zip |
core: adding Python files to easily parse header info of a file.
Also a utility script that you pass a filename to and it prints out the meta data.
Diffstat (limited to 'gr-utils')
-rw-r--r-- | gr-utils/src/python/CMakeLists.txt | 1 | ||||
-rw-r--r-- | gr-utils/src/python/gr_read_file_metadata | 59 |
2 files changed, 60 insertions, 0 deletions
diff --git a/gr-utils/src/python/CMakeLists.txt b/gr-utils/src/python/CMakeLists.txt index 90caeb234..13fa06bbc 100644 --- a/gr-utils/src/python/CMakeLists.txt +++ b/gr-utils/src/python/CMakeLists.txt @@ -50,6 +50,7 @@ GR_PYTHON_INSTALL( gr_plot_short gr_plot_qt gr_filter_design + gr_read_file_metadata DESTINATION ${GR_RUNTIME_DIR} COMPONENT "utils" ) diff --git a/gr-utils/src/python/gr_read_file_metadata b/gr-utils/src/python/gr_read_file_metadata new file mode 100644 index 000000000..657ad7c2b --- /dev/null +++ b/gr-utils/src/python/gr_read_file_metadata @@ -0,0 +1,59 @@ +#!/usr/bin/env python +# +# Copyright 2012 Free Software Foundation, Inc. +# +# This file is part of GNU Radio +# +# GNU Radio is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3, or (at your option) +# any later version. +# +# GNU Radio is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with GNU Radio; see the file COPYING. If not, write to +# the Free Software Foundation, Inc., 51 Franklin Street, +# Boston, MA 02110-1301, USA. +# + +import sys +from optparse import OptionParser + +from gnuradio import gr +from gnuradio import parse_file_metadata + +def main(filename): + handle = open(filename, "rb") + + # just read out header bytes + header_str = handle.read(parse_file_metadata.HEADER_LENGTH) + + # Convert from string to PMT (should be a dictionary) + try: + header = gr.pmt_deserialize_str(header_str) + except RuntimeError: + sys.stderr.write("Could not deserialize header: invalid or corrupt data file.\n") + sys.exit(1) + #gr.pmt_print(header) + + info = parse_file_metadata.parse_header(header, True) + #print info + +if __name__ == "__main__": + usage="%prog: [options] filename" + description = "Read in a GNU Radio file with meta data, extracts the header and prints it." + + parser = OptionParser(conflict_handler="resolve", + usage=usage, description=description) + (options, args) = parser.parse_args () + + if(len(args) < 1): + sys.stderr.write("No filename given\n") + sys.exit(1) + + filename = args[0] + main(filename) |