Initial snark14m import
[snark14.git] / src / snark / SARTConfig.cpp
1 /*
2  ***********************************************************
3  $SNARK_Header: S N A R K  1 4 - A PICTURE RECONSTRUCTION PROGRAM $
4  $HeadURL: svn://dig.cs.gc.cuny.edu/snark/trunk/src/snark/SARTConfig.cpp $
5  $LastChangedRevision: 123 $
6  $Date: 2014-07-11 09:44:57 -0400 (Fri, 11 Jul 2014) $
7  $Author: bprommegger $
8  ***********************************************************
9  */
10
11 #include "SARTConfig.h"
12 #include <cstdio>
13 #include "uiod.h"
14 #include "int2str.h"
15 #include "infile.h"
16 #include "consts.h"
17
18 REAL SARTConfig::relaxiation = 1;
19 REAL SARTConfig::zeroThreshold = Consts.zero;
20
21 SARTConfig::SARTConfig()
22 {
23 }
24
25 SARTConfig::~SARTConfig()
26 {
27 }
28
29 void SARTConfig::printErrorMessage(char* errorString)
30 {
31         fprintf(output, "\n          wrong configuration for SART --> default values might be applied ...");
32         fprintf(output, "\n          error message: %s", errorString);
33         fprintf(output, "\n              check documentation for further details !!!");
34 }
35
36 BOOLEAN SARTConfig::readSARTConfiguration()
37 {
38
39         // definition of possible set-up parameters
40         static const INTEGER strParameterRelaxation = CHAR2INT('r', 'e', 'l', 'a');
41         static const INTEGER strParameterConstValue = CHAR2INT('c', 'o', 'n', 's');
42
43         INTEGER currentParameterValueInt;
44         REAL currentParameterValueReal;
45         BOOLEAN eol;
46         INTEGER* allowedExpressions = new INTEGER[10];
47         INTEGER numberOfAllowedExpressions = 0;
48
49         // FORMAT OF INPUT COMMAND:
50
51         // EXECUTE SART
52         // LINE OF COMMENT
53         // RELAXATION CONSTANT r ... optional
54
55         // Example:
56
57         // EXECUTE SART
58         // SART Execution Sample
59         // RELAXATION CONSTANT 1.9
60
61         // check RELAXATION
62         allowedExpressions[0] = strParameterRelaxation;
63         numberOfAllowedExpressions = 1;
64         currentParameterValueInt = InFile.getwrd(TRUE, &eol, allowedExpressions,
65                         numberOfAllowedExpressions);
66
67         // optional parameters --> EOL causes no error
68         if (!eol)
69         {
70                 switch (currentParameterValueInt)
71                 {
72
73                 case strParameterRelaxation:
74
75                         // check CONSTANT
76                         allowedExpressions[0] = strParameterConstValue;
77                         numberOfAllowedExpressions = 1;
78                         currentParameterValueInt = InFile.getwrd(FALSE, &eol,
79                                         allowedExpressions, numberOfAllowedExpressions);
80
81                         switch (currentParameterValueInt)
82                         {
83                         case strParameterConstValue:
84
85                                 // check if 0 < r <= 2
86                                 currentParameterValueReal = InFile.getnum(FALSE, &eol);
87                                 if (currentParameterValueReal > 0.0 && currentParameterValueReal <= 2.0)
88                                 {
89                                         SARTConfig::relaxiation = currentParameterValueReal;
90                                 }
91                                 else
92                                 {
93                                         SARTConfig::printErrorMessage("relaxation parameter must fit to 0.0 < r <= 2.0");
94                                 }
95
96                                 break;
97                         default:
98                                 SARTConfig::printErrorMessage("second parameter must be CONS[TANT]");
99                                 break;
100                         }
101                         break;
102                 default:
103                         SARTConfig::printErrorMessage("first parameter must be RELA[XATION]");
104                         break;
105                 }
106         }
107
108         fprintf(output, "\n          relaxation parameter is %4.3f",
109                         SARTConfig::relaxiation);
110
111         delete[] allowedExpressions;
112
113         return true;
114 }