Ran update-copyright.py
[hooke.git] / hooke / plugin / cut.py
index d42338ddda176067eb77998d667b4ad1721e2ac4..f8b0d37ea8dac5fb2d5d6614a12c6481bc6488db 100644 (file)
@@ -1,31 +1,31 @@
-# Copyright (C) 2009-2010 Fabrizio Benedetti
-#                         Massimo Sandal <devicerandom@gmail.com>
-#                         W. Trevor King <wking@drexel.edu>
+# Copyright (C) 2009-2012 Massimo Sandal <devicerandom@gmail.com>
+#                         W. Trevor King <wking@tremily.us>
 #
 # This file is part of Hooke.
 #
-# Hooke is free software: you can redistribute it and/or
-# modify it under the terms of the GNU Lesser General Public
-# License as published by the Free Software Foundation, either
-# version 3 of the License, or (at your option) any later version.
+# Hooke is free software: you can redistribute it and/or modify it under the
+# terms of the GNU Lesser General Public License as published by the Free
+# Software Foundation, either version 3 of the License, or (at your option) any
+# later version.
 #
-# Hooke 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 Lesser General Public License for more details.
+# Hooke 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 Lesser General Public License for more
+# details.
 #
-# You should have received a copy of the GNU Lesser General Public
-# License along with Hooke.  If not, see
-# <http://www.gnu.org/licenses/>.
+# You should have received a copy of the GNU Lesser General Public License
+# along with Hooke.  If not, see <http://www.gnu.org/licenses/>.
 
 """The `cut` module provides :class:`CutPlugin` and
 :class:`CutCommand`.
 """
 
+import os.path
+
 import numpy
 
 from ..command import Command, Argument, Failure
-from ..plugin import Plugin
+from . import Plugin
 
 
 class CutPlugin (Plugin):
@@ -57,8 +57,9 @@ CurveArgument = Argument(
 class CutCommand (Command):
     """Cut the selected signal between two points and write it to a file.
 
-    The data is saved in TAB-delimited ASCII text, where the first column
-    is "x" and the second is "y".  There is no header row.
+    The data is saved in TAB-delimited ASCII text.  A "#" prefixed
+    header will optionally appear at the beginning of the file naming
+    the columns.
     """
     def __init__(self, plugin):
         super(CutCommand, self).__init__(
@@ -77,6 +78,10 @@ Indicies of points bounding the selected data.
                 Argument(name='output', type='file', default='cut.dat',
                          help="""
 File name for the output data.
+""".strip()),
+                Argument(name='header', type='bool', default=True,
+                         help="""
+True if you want the column-naming header line.
 """.strip()),
                 ],
             help=self.__doc__, plugin=plugin)
@@ -92,4 +97,8 @@ File name for the output data.
         cut_data = data[i_min:i_max+1,:] # slice rows from row-major data
         # +1 to include data[i_max] row
 
-        numpy.savetxt(params['output'], cut_data, delimiter='\t')
+        f = open(os.path.expanduser(params['output']), 'w')
+        if params['header'] == True:
+            f.write('# %s \n' % ('\t'.join(cut_data.info['columns'])))
+        numpy.savetxt(f, cut_data, delimiter='\t')
+        f.close()