Go to the documentation of this file.00001
00048 bool subdivide false @endcode
00049
00050 The results from the program are stored in a similar structure. At
00051 the end of a program, it is possible to write the input and output
00052 data into one file. The output file has the same syntax and
00053 structure as the input file and can therefore be used as an input
00054 file to reproduce the results at a later time. See the <a
00055 href="#Results">results section</a> for an example.
00056
00057 @dontinclude inputoutput.cc
00058 @section commented Commented Program
00059
00060 The first few lines in a code for concepts are filled with the
00061 include files. I put the system includes first here.
00062 @until unistd.h
00063 Then, there are the Concepts includes:
00064 <ul>
00065 <li>basics.hh for the exception handling code and other things.
00066 <li>toolbox.hh for the toolbox, including the intput file parser
00067 and the handling of input and output data.
00068 </ul>
00069 Since there are no real computations in the code, no more include files
00070 from Concepts are needed.
00071 @until toolbox.hh
00072 @skip main
00073 All code in this example is in one large routine, the main program.
00074 @until main
00075 @skip uint
00076 Some default values for the parameters used. \c l and \c p are just two
00077 variables. If \c debug is set to true, more information is printed to
00078 screen.
00079 @until debug
00080 A big try block to catch exceptions. More and more runtime errors
00081 in Concepts are reported by throwing an exception.
00082 @skip try
00083 @until try
00084 First, set up the input parameter class: some parameters
00085 are set up with a default value.
00086 @skip concepts::InputParser
00087 @until parameterout
00088 The variable outputParameter is for easier access to the output
00089 area. There, the results of the computations can be stored and
00090 eventually written to disk if necessary.
00091 @skip input
00092 @until input
00093 Prepare an array for values computed later. This array is then
00094 added to \c table which is able to nicely format the content of
00095 the different arrays (e.g. for later processing with Gnuplot).
00096 @skip error
00097 @until inputfile
00098
00099 @subsection parsing Command Line Parsing
00100 Here, we start with the command line parsing. See the man page
00101 for \c getopt for more information.
00102
00103 In the second line of the following code fragement, the string
00104 defines what command line arguments are allowed and if they take a
00105 parameter (:) or not. The \c switch statement has an entry
00106 for every command line argument listed in the string. There, the
00107 parameter is available as \c optarg. The \c default
00108 target of the \c switch clause prints some
00109 usage information (ie. help for the command line arguments).
00110
00111 The parameters are processed in the order they appear on the
00112 command line. When first specifying an input file with \c -f, the
00113 values in the file can be overridden with additional command line
00114 arguments after \c -f.
00115 @until }
00116 Print the parameters to show the user what is going on.
00117 @skip std::cout
00118 @until --
00119 @until --
00120 Next, the parameters from the command line or the input file are
00121 stored in the respective variables. This is only used for
00122 abbrevation.
00123 @skip l
00124 @until polynomial
00125
00126 @subsection comp Computations
00127 Here are some dummy computations to fill the output area with
00128 content.
00129 @skip outputParameters.addInt
00130 @until error
00131
00132 @section output Output
00133 Finally, the input and output data are written to disk with some more
00134 information about the user and the system in the header of the
00135 file.
00136 @skip std::cout
00137 @until delete
00138 This prints the table and its content to the screen and also
00139 stores it with high precision in a file suitable for later
00140 processing with Gnuplot.
00141 @skip table
00142 @until }
00143 Here, all exceptions derived from the base exception class
00144 (concepts::ExceptionBase) in Concepts are catched and printed. You
00145 can test this out by not giving the name of the input file on the
00146 command line. Then the parameter \c parameterout does not exist
00147 and the library will throw and exception which is caught here.
00148 @until }
00149 @until }
00150
00151 @section Results
00152 The output of the program called without parameters: @code
00153 [inputoutput]
00154 --
00155 Parameters:
00156 input file =
00157 string author "(empty)"
00158 string comment "(empty)"
00159 string parameterout "inputoutput.out"
00160 string title "(empty)"
00161 int level 0
00162 int polynomial 1
00163 bool debug false
00164 --
00165 --
00166 Writing gathered data to disk: inputoutput.out
00167 ResultsTable(
00168 error error
00169 0 1
00170 1 0.5
00171 2 0.25
00172 3 0.125
00173 4 0.0625
00174 5 0.03125
00175 6 0.015625
00176 7 0.0078125
00177 8 0.00390625
00178 9 0.00195312
00179 ) @endcode
00180
00181 The program creates the following output files:
00182 - \c inputoutput.out: @code
00183
00184
00185
00186
00187 string author "(empty)"
00188 string comment "(empty)"
00189 string parameterout "inputoutput.out"
00190 string title "(empty)"
00191 int level 0
00192 int polynomial 1
00193 bool debug false
00194 end
00195
00196 int nelm 10
00197 array double error {
00198 0 1
00199 1 0.5
00200 2 0.25
00201 3 0.125
00202 4 0.0625
00203 5 0.03125
00204 6 0.015625
00205 7 0.0078125
00206 8 0.00390625
00207 9 0.00195312
00208 } @endcode
00209 - \c inputoutput.gnuplot: @code
00210 # error error
00211 0 1
00212 1 0.5
00213 2 0.25
00214 3 0.125
00215 4 0.0625
00216 5 0.03125
00217 6 0.015625
00218 7 0.0078125
00219 8 0.00390625
00220 9 0.001953125 @endcode
00221
00222 Note the \c end keyword at the end of the input
00223 part and right before the output part. When reading in this file as
00224 input file, the parsing stops right there, ie. the previous output
00225 data is not read in.
00226
00227 @section complete Complete Source Code
00228 @author Philipp Frauenfelder, 2004
00229 */