mailr18906 - in /trunk: generic_fns/value.py user_functions/value.py


Others Months | Index by Date | Thread Index
>>   [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Header


Content

Posted by edward on March 20, 2013 - 13:29:
Author: bugman
Date: Wed Mar 20 13:29:59 2013
New Revision: 18906

URL: http://svn.gna.org/viewcvs/relax?rev=18906&view=rev
Log:
Added the new 'comment' argument to the value.write user function.

This is used to add user comments to the top of the file.


Modified:
    trunk/generic_fns/value.py
    trunk/user_functions/value.py

Modified: trunk/generic_fns/value.py
URL: 
http://svn.gna.org/viewcvs/relax/trunk/generic_fns/value.py?rev=18906&r1=18905&r2=18906&view=diff
==============================================================================
--- trunk/generic_fns/value.py (original)
+++ trunk/generic_fns/value.py Wed Mar 20 13:29:59 2013
@@ -428,7 +428,7 @@
         pipes.switch(orig_pipe)
 
 
-def write(param=None, file=None, dir=None, scaling=1.0, return_value=None, 
return_data_desc=None, bc=False, force=False):
+def write(param=None, file=None, dir=None, scaling=1.0, return_value=None, 
return_data_desc=None, comment=None, bc=False, force=False):
     """Write data to a file.
 
     @keyword param:             The name of the parameter to write to file.
@@ -443,6 +443,8 @@
     @type return_value:         None or func
     @keyword return_data_desc:  An optional function which if supplied will 
override the default parameter description returning function.
     @type return_data_desc:     None or func
+    @keyword comment:           Text which will be added to the start of the 
file as comments.  All lines will be prefixed by '# '.
+    @type comment:              str
     @keyword bc:                A flag which if True will cause the back 
calculated values to be written.
     @type bc:                   bool
     @keyword force:             A flag which if True will cause any 
pre-existing file to be overwritten.
@@ -461,7 +463,7 @@
     file = open_write_file(file, dir, force)
 
     # Write the data.
-    write_data(param=param, file=file, scaling=scaling, 
return_value=return_value, return_data_desc=return_data_desc, bc=bc)
+    write_data(param=param, file=file, scaling=scaling, 
return_value=return_value, return_data_desc=return_data_desc, 
comment=comment, bc=bc)
 
     # Close the file.
     file.close()
@@ -470,7 +472,7 @@
     add_result_file(type='text', label='Text', file=file_path)
 
 
-def write_data(param=None, file=None, scaling=1.0, bc=False, 
return_value=None, return_data_desc=None):
+def write_data(param=None, file=None, scaling=1.0, bc=False, 
return_value=None, return_data_desc=None, comment=None):
     """The function which actually writes the data.
 
     @keyword param:             The parameter to write.
@@ -485,6 +487,8 @@
     @type return_value:         None or func
     @keyword return_data_desc:  An optional function which if supplied will 
override the default parameter description returning function.
     @type return_data_desc:     None or func
+    @keyword comment:           Text which will be added to the start of the 
file as comments.  All lines will be prefixed by '# '.
+    @type comment:              str
     """
 
     # Get the value and error returning function parameter description 
function if required.
@@ -511,6 +515,16 @@
         file.write("# Parameter description:  %s.\n" % desc)
         file.write("#\n")
 
+    # The comments.
+    if comment:
+        # Split up the lines.
+        lines = comment.splitlines()
+
+        # Write out.
+        for line in lines:
+            file.write("# %s\n" % line)
+        file.write("#\n")
+
     # Loop over the sequence.
     for spin, mol_name, res_num, res_name in spin_loop(full_info=True):
         # Get the value and error.

Modified: trunk/user_functions/value.py
URL: 
http://svn.gna.org/viewcvs/relax/trunk/user_functions/value.py?rev=18906&r1=18905&r2=18906&view=diff
==============================================================================
--- trunk/user_functions/value.py (original)
+++ trunk/user_functions/value.py Wed Mar 20 13:29:59 2013
@@ -437,6 +437,13 @@
     desc = "The factor to scale parameters by."
 )
 uf.add_keyarg(
+    name = "comment",
+    py_type = "str",
+    desc_short = "comment",
+    desc = "Text which will be added to the start of the file as comments.  
All lines will be prefixed by '# '.",
+    can_be_none = True
+)
+uf.add_keyarg(
     name = "bc",
     default = False,
     py_type = "bool",




Related Messages


Powered by MHonArc, Updated Wed Mar 20 13:40:02 2013