inputoutput.doxy

Go to the documentation of this file.
1 
52 bool subdivide false @endcode
53 
54  The results from the program are stored in a similar structure. At
55  the end of a program, it is possible to write the input and output
56  data into one file. The output file has the same syntax and
57  structure as the input file and can therefore be used as an input
58  file to reproduce the results at a later time. See the <a
59  href="#Results">results section</a> for an example.
60 
61  @dontinclude inputoutput.cc
62  @section commented Commented Program
63 
64  The first few lines in a code for concepts are filled with the
65  include files. I put the system includes first here.
66  @until unistd.h
67  Then, there are the Concepts includes:
68  <ul>
69  <li>basics.hh for the exception handling code and other things.
70  <li>toolbox.hh for the toolbox, including the intput file parser
71  and the handling of input and output data.
72  </ul>
73  Since there are no real computations in the code, no more include files
74  from Concepts are needed.
75  @until toolbox.hh
76  @skip main
77  All code in this example is in one large routine, the main program.
78  @until main
79  @skip uint
80  Some default values for the parameters used. \c l and \c p are just two
81  variables. If \c debug is set to true, more information is printed to
82  screen.
83  @until debug
84  A big try block to catch exceptions. More and more runtime errors
85  in Concepts are reported by throwing an exception.
86  @skip try
87  @until try
88  First, set up the input parameter class: some parameters
89  are set up with a default value.
91  @until parameterout
92  The variable outputParameter is for easier access to the output
93  area. There, the results of the computations can be stored and
94  eventually written to disk if necessary.
95  @skip input
96  @until input
97  Prepare an array for values computed later. This array is then
98  added to \c table which is able to nicely format the content of
99  the different arrays (e.g. for later processing with Gnuplot).
100  @skip error
101  @until inputfile
102 
103  @subsection parsing Command Line Parsing
104  Here, we start with the command line parsing. See the man page
105  for \c getopt for more information.
106 
107  In the second line of the following code fragement, the string
108  defines what command line arguments are allowed and if they take a
109  parameter (:) or not. The \c switch statement has an entry
110  for every command line argument listed in the string. There, the
111  parameter is available as \c optarg. The \c default
112  target of the \c switch clause prints some
113  usage information (ie. help for the command line arguments).
114 
115  The parameters are processed in the order they appear on the
116  command line. When first specifying an input file with \c -f, the
117  values in the file can be overridden with additional command line
118  arguments after \c -f.
119  @until }
120  Print the parameters to show the user what is going on.
121  @skip std::cout
122  @until --
123  @until --
124  Next, the parameters from the command line or the input file are
125  stored in the respective variables. This is only used for
126  abbrevation.
127  @skip l
128  @until polynomial
129 
130  @subsection comp Computations
131  Here are some dummy computations to fill the output area with
132  content.
133  @skip outputParameters.addInt
134  @until error
135 
136  @section output Output
137  Finally, the input and output data are written to disk with some more
138  information about the user and the system in the header of the
139  file.
140  @skip std::cout
141  @until delete
142  This prints the table and its content to the screen and also
143  stores it with high precision in a file suitable for later
144  processing with Gnuplot.
145  @skip table
146  @until }
147  Here, all exceptions derived from the base exception class
148  (concepts::ExceptionBase) in Concepts are catched and printed. You
149  can test this out by not giving the name of the input file on the
150  command line. Then the parameter \c parameterout does not exist
151  and the library will throw and exception which is caught here.
152  @until }
153  @until }
154 
155  @section Results
156  The output of the program called without parameters: @code
157 [inputoutput]
158 --
159 Parameters:
160  input file =
161 string author "(empty)"
162 string comment "(empty)"
163 string parameterout "inputoutput.out"
164 string title "(empty)"
165 int level 0
166 int polynomial 1
167 bool debug false
168 --
169 --
170 Writing gathered data to disk: inputoutput.out
171 ResultsTable(
172 error error
173 0 1
174 1 0.5
175 2 0.25
176 3 0.125
177 4 0.0625
178 5 0.03125
179 6 0.015625
180 7 0.0078125
181 8 0.00390625
182 9 0.00195312
183 ) @endcode
184 
185  The program creates the following output files:
186  - \c inputoutput.out: @code
187 /* program: inputoutput
188  * command: inputoutput
189  * input file:
190  */
191 string author "(empty)"
192 string comment "(empty)"
193 string parameterout "inputoutput.out"
194 string title "(empty)"
195 int level 0
196 int polynomial 1
197 bool debug false
198 end
199 // output starts here
200 int nelm 10
201 array double error {
202  0 1
203  1 0.5
204  2 0.25
205  3 0.125
206  4 0.0625
207  5 0.03125
208  6 0.015625
209  7 0.0078125
210  8 0.00390625
211  9 0.00195312
212 } @endcode
213  - \c inputoutput.gnuplot: @code
214 # error error
215 0 1
216 1 0.5
217 2 0.25
218 3 0.125
219 4 0.0625
220 5 0.03125
221 6 0.015625
222 7 0.0078125
223 8 0.00390625
224 9 0.001953125 @endcode
225 
226  Note the \c end keyword at the end of the input
227  part and right before the output part. When reading in this file as
228  input file, the parsing stops right there, ie. the previous output
229  data is not read in.
230 
231  @section complete Complete Source Code
232  @author Philipp Frauenfelder, 2004
233 */
Unit tests.
Definition: testcase.hh:66
Parses an input file and extracts parameters.
Definition: inputOutput.hh:443
Basic namespace for Concepts-2.
Definition: pml_formula.h:16
Page URL: http://wiki.math.ethz.ch/bin/view/Concepts/WebHome
21 August 2020
© 2020 Eidgenössische Technische Hochschule Zürich