40bool subdivide
false @endcode
42The 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.
43See the <a href=
"#Results">results section</a>
for an example.
45@dontinclude inputoutput.py
46@section commented Commented Program
48First 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
53All code in this example is in one large routine, the main program.
55 @skip def main(args,argv):
56 @until def main(args,argv):
58Some 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.
63First, 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")
68The 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.
73Prepare 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).
78@subsection parsing Command Line Parsing
79Here, 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()
89Enter \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)
94If 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.")
99Print 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))
104Next, 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
110Here 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
116Finally, 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")
121This 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()
127The output of the program called without parameters: @code
132string author "(empty)"
133string comment "(empty)"
134string parameterout "inputoutput.out"
135string title "(empty)"
141Writing gathered data to disk: inputoutput.out
155The program creates the following output files:
156 - \c inputoutput.out:
162string author "(empty)"
163string comment "(empty)"
164string parameterout "inputoutput.out"
165string title "(empty)"
184 - \c inputoutput.gnuplot:
198Note 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
void addArrayDouble(const char *array, const bool newArray=false)