Package prompt :: Module results
[hide private]
[frames] | no frames]

Source Code for Module prompt.results

  1  ############################################################################### 
  2  #                                                                             # 
  3  # Copyright (C) 2003, 2004 Edward d'Auvergne                                  # 
  4  #                                                                             # 
  5  # This file is part of the program relax.                                     # 
  6  #                                                                             # 
  7  # relax is free software; you can redistribute it and/or modify               # 
  8  # it under the terms of the GNU General Public License as published by        # 
  9  # the Free Software Foundation; either version 2 of the License, or           # 
 10  # (at your option) any later version.                                         # 
 11  #                                                                             # 
 12  # relax is distributed in the hope that it will be useful,                    # 
 13  # but WITHOUT ANY WARRANTY; without even the implied warranty of              # 
 14  # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the               # 
 15  # GNU General Public License for more details.                                # 
 16  #                                                                             # 
 17  # You should have received a copy of the GNU General Public License           # 
 18  # along with relax; if not, write to the Free Software                        # 
 19  # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA   # 
 20  #                                                                             # 
 21  ############################################################################### 
 22   
 23  import sys 
 24   
 25  import help 
 26   
 27   
28 -class Results:
29 - def __init__(self, relax):
30 # Help. 31 self.__relax_help__ = \ 32 """Class for manipulating results.""" 33 34 # Add the generic help string. 35 self.__relax_help__ = self.__relax_help__ + "\n" + help.relax_class_help 36 37 # Place relax in the class namespace. 38 self.__relax__ = relax
39 40
41 - def display(self, run=None, format='columnar'):
42 """Function for displaying the results of the run. 43 44 Keyword Arguments 45 ~~~~~~~~~~~~~~~~~ 46 47 run: The name of the run. 48 49 format: The format of the output. 50 """ 51 52 # Function intro text. 53 if self.__relax__.interpreter.intro: 54 text = sys.ps3 + "results.display(" 55 text = text + "run=" + `run` 56 text = text + ", format=" + `format` + ")" 57 print text 58 59 # The run name. 60 if type(run) != str: 61 raise RelaxStrError, ('run', run) 62 63 # Execute the functional code. 64 self.__relax__.generic.results.display(run=run)
65 66
67 - def read(self, run=None, file='results', dir='run', format='columnar'):
68 """Function for reading results from a file. 69 70 Keyword Arguments 71 ~~~~~~~~~~~~~~~~~ 72 73 run: The name of the run. 74 75 file: The name of the file to read results from. 76 77 dir: The directory where the file is located. 78 79 80 Description 81 ~~~~~~~~~~~ 82 83 If no directory name is given, the results file will be searched for in a directory named 84 after the run name. To search for the results file in the current working directory, set 85 dir to None. 86 87 This function is able to handle uncompressed, bzip2 compressed files, or gzip compressed 88 files automatically. The full file name including extension can be supplied, however, if 89 the file cannot be found, this function will search for the file name with '.bz2' appended 90 followed by the file name with '.gz' appended. 91 """ 92 93 # Function intro text. 94 if self.__relax__.interpreter.intro: 95 text = sys.ps3 + "results.read(" 96 text = text + "run=" + `run` 97 text = text + ", file=" + `file` 98 if dir == 'run': 99 text = text + ", dir=" + `run` 100 else: 101 text = text + ", dir=" + `dir` 102 text = text + ", format=" + `format` + ")" 103 print text 104 105 # The run argument. 106 if type(run) != str: 107 raise RelaxStrError, ('run', run) 108 109 # File. 110 if type(file) != str: 111 raise RelaxStrError, ('file name', file) 112 113 # Directory. 114 if dir != None and type(dir) != str: 115 raise RelaxNoneStrError, ('directory name', dir) 116 117 # Format. 118 if type(format) != str: 119 raise RelaxStrError, ('format', format) 120 121 # Execute the functional code. 122 self.__relax__.generic.results.read(run=run, file=file, directory=dir, format=format)
123 124
125 - def write(self, run=None, file='results', dir='run', force=0, format='columnar', compress_type=1):
126 """Function for writing results of the run to a file. 127 128 Keyword Arguments 129 ~~~~~~~~~~~~~~~~~ 130 131 run: The name of the run. 132 133 file: The name of the file to output results to. The default is 'results'. 134 135 dir: The directory name. 136 137 force: A flag which, if set to 1, will cause the results file to be overwritten. 138 139 format: The format of the output. 140 141 compress_type: The type of compression to use when creating the file. 142 143 144 Description 145 ~~~~~~~~~~~ 146 147 If no directory name is given, the results file will be placed in a directory named after 148 the run name. To place the results file in the current working directory, set dir to None. 149 150 The default behaviour of this function is to compress the file using bzip2 compression. If 151 the extension '.bz2' is not included in the file name, it will be added. The compression 152 can, however, be changed to either no compression or gzip compression. This is controlled 153 by the compress_type argument which can be set to: 154 0 - No compression (no file extension). 155 1 - bzip2 compression ('.bz2' file extension). 156 2 - gzip compression ('.gz' file extension). 157 The complementary read function will automatically handle the compressed files. 158 """ 159 160 # Function intro text. 161 if self.__relax__.interpreter.intro: 162 text = sys.ps3 + "results.write(" 163 text = text + "run=" + `run` 164 text = text + ", file=" + `file` 165 if dir == 'run': 166 text = text + ", dir=" + `run` 167 else: 168 text = text + ", dir=" + `dir` 169 text = text + ", force=" + `force` 170 text = text + ", format=" + `format` 171 text = text + ", compress_type=" + `compress_type` + ")" 172 print text 173 174 # The run argument. 175 if type(run) != str: 176 raise RelaxStrError, ('run', run) 177 178 # File. 179 if type(file) != str: 180 raise RelaxStrError, ('file name', file) 181 182 # Directory. 183 if dir != None and type(dir) != str: 184 raise RelaxNoneStrError, ('directory name', dir) 185 186 # The force flag. 187 if type(force) != int or (force != 0 and force != 1): 188 raise RelaxBinError, ('force flag', force) 189 190 # Format. 191 if type(format) != str: 192 raise RelaxStrError, ('format', format) 193 194 # Compression type. 195 if type(compress_type) != int: 196 raise RelaxIntError, ('compression type', compress_type) 197 198 # Execute the functional code. 199 self.__relax__.generic.results.write(run=run, file=file, directory=dir, force=force, format=format, compress_type=compress_type)
200