40 bool subdivide
false @endcode
42 The results from the program are stored in a similar structure. At the end of a program, it is possible to write the input and output data into one file. The output file has the same syntax and structure as the input file and can therefore be used as an input file to reproduce the results at a later time.
43 See the <a href=
"#Results">results section</a>
for an example.
45 @dontinclude inputoutput.py
46 @section commented Commented Program
48 First we have to
import certain modules from the \c libconceptspy
package and other required python modules.
50 @skip from libconceptspy import concepts
51 @until import argparse
53 All code in this example is in one large routine, the main program.
55 @skip def main(args,argv):
56 @until def main(args,argv):
58 Some default values for the parameters used. \c l and \c p are just two variables. If \c debug is set to true, more information is printed to screen.
63 First, set up the input parameter class: some parameters are set up with a default value.
65 @skip inp = concepts.InputParser(True)
66 @until inputParameters.addString('parameterout',"inputoutput.out")
68 The variable outputParameter is for easier access to the output area. There, the results of the computations can be stored and eventually written to disk if necessary.
70 @skip outputParameters = concepts.InOutParameters()
71 @until outputParameters = concepts.InOutParameters()
73 Prepare an array for values computed later. This array is then added to \c table which is able to nicely format the content of the different arrays (e.g. for later processing with Gnuplot).
75 @skip outputParameters.addArrayDouble("error")
78 @subsection parsing Command Line Parsing
79 Here, we start with the command line parsing.
81 parser = argparse.ArgumentParser()
82 parser.add_argument('-l',help='LEVEL: level of refinement',required=False, type = int)
83 parser.add_argument('-p',help='DEGREE: polynomial degree', required=False, type = int)
84 parser.add_argument('-f',help='FILE: name of the input file',required=False, type = str)
85 parser.add_argument('-d',action = "store_true",help='-d: print the matrices',required=False)
86 args = parser.parse_args()
89 Enter \c -h as command line argument for more information. The parameters are processed in the order they appear in the command line. When first specifying an input file with \c -f, the values in the file can be overridden with additional command line arguments after \c -f.
91 @skip if (len(argv)>1):
92 @until inputParameters.addBool('debug', True)
94 If there is an error reading the input file, then an exception error message is returned.
96 @skip except RuntimeError:
97 @until print("Input file not found.Cannot open input file.")
99 Print the parameters to show the user what is going on.
101 @skip print('['+argv[0]+']')
102 @until print(' input file = %s\n%s'%(inputfile,inputParameters))
104 Next, the parameters from the command line or the input file are stored in the respective variables. This is only used for abbrevation.
106 @skip l = inputParameters.getInt('level')
107 @until p = inputParameters.getInt('polynomial')
109 @subsection comp Computations
110 Here are some dummy computations to fill the output area with content.
112 @skip outputParameters.addInt("nelm", 10)
113 @until outputParameters.addArrayDouble("error",i,1.0/(1<<i))
115 @section output Output
116 Finally, the input and output data are written to disk with some more information about the user and the system in the header of the file.
118 @skip print 'Writing gathered data to disk: ',inputParameters.getString("parameterout")
121 This prints the table and its content to the screen and also stores it with high precision in a file suitable for later processing with Gnuplot.
124 @until gnu_file.close()
127 The output of the program called without parameters: @code
132 string author "(empty)"
133 string comment "(empty)"
134 string parameterout "inputoutput.out"
135 string title "(empty)"
141 Writing gathered data to disk: inputoutput.out
155 The program creates the following output files:
156 - \c inputoutput.out:
162 string author "(empty)"
163 string comment "(empty)"
164 string parameterout "inputoutput.out"
165 string title "(empty)"
184 - \c inputoutput.gnuplot:
196 9 0.00195312 @endcode
198 Note the \c end keyword at the end of the input part and right before the output part. When reading in this file as input file, the parsing stops right there, ie. the previous output data is not read in.
200 @section complete Complete Source Code