Initial snark14m import
[snark14.git] / src / snark / stopex.cpp
1 /*
2  * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
3  *                                                                           *
4  *                              S N A R K   1 4                              *
5  *                                                                           *
6  *                     A PICTURE RECONSTRUCTION PROGRAM                      *
7  *                                                                           *
8  * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
9
10  stopex.cpp,v 1.2 2008/08/25 16:11:09 jklukowska Exp
11
12 DETERMINE THE ALGORITHM STOPPING CRITERION.  SET TERM TO REFLECT
13 IT.  FOR AN ITERATION COUNT, TERM IS THE NEGATIVE OF THAT NUMBER.
14 FOR A TEST NAME, TERM CONTAINS THE INDEX.
15
16 */
17
18
19 #include <cstdio>
20 #include <cstdlib>
21 #include "blkdta.h"
22 #include "consts.h"
23 #include "term.h"
24 #include "trm1.h"
25 #include "trm2.h"
26 #include "trm3.h"
27 #include "trm4.h"
28 #include "trm5.h"
29 #include "trm6.h"
30 #include "trm_weighted_squared_distance.h"
31 #include "uiod.h"
32 #include "int2str.h"
33 #include "infile.h"
34 #include "stopex.h"
35
36 trm1_class trm1;
37 trm2_class trm2;
38 trm3_class trm3;
39 trm4_class trm4;
40 trm5_class trm5;
41 trm6_class trm6;
42 trm_weighted_squared_distance trm_weighted_squared_distance_inst;
43
44 termtest_class* TrmClasses[] =
45 {
46   &trm1,
47   &trm2,
48   &trm3,
49   &trm4,
50   &trm5,
51   &trm6,
52   &trm_weighted_squared_distance_inst
53 };
54
55 void stopex()
56 {
57   static const INTEGER code[] =
58   {
59     CHAR2INT('i','t','e','r'),
60     CHAR2INT('t','e','r','m')
61   };
62
63   static const INTEGER testn[] =
64   {
65     CHAR2INT('t','r','m','1'),
66     CHAR2INT('t','r','m','2'),
67     CHAR2INT('v','a','r','i'),
68     CHAR2INT('m','l','s','t'),
69     CHAR2INT('k','l','d','s'),
70     CHAR2INT('r','e','s','i'),
71     CHAR2INT('w','s','q','d')
72   }; 
73   INTEGER num_termination_criteria = 7;
74
75   INTEGER i;
76
77   INTEGER word;
78   BOOLEAN eol;
79
80   // GET THE TERMINATION CRITERION
81   word = InFile.getwrd(FALSE, &eol, code, 2);
82
83   switch(word)
84   {
85   case CHAR2INT('i','t','e','r'):
86
87     // GET THE NUMBER OF ITERATIONS
88     word = InFile.getint(FALSE, &eol);
89
90     if (word <= 0)
91     {
92       fprintf(output, "\n **** number of iterations must be greater than zero");
93       fprintf(output, "\n **** program aborted\n");
94       exit(-1);
95     }
96
97     Term.iterations = word;
98     Term.termInstance = NULL;
99     fprintf(output, "\n         %4i iterations", word);
100     return;
101
102   case CHAR2INT('t','e','r','m'):
103
104     // READ THE TEST NAME
105     word = InFile.getwrd(FALSE, &eol, testn, num_termination_criteria);
106
107     for(i = 0; i < num_termination_criteria; i++) {
108       if(word == testn[i]) {
109         fprintf(output, "\n         termination test %s", int2str(word));
110
111         Term.termInstance = TrmClasses[i];
112         Term.termInstance->Init();
113         Term.iterations = 0;
114         return;
115
116       }
117     }
118
119     fprintf(output, "\n **** unknown test %s", int2str(word));
120     fprintf(output, "\n **** program aborted\n");
121     exit(-1);
122
123     return;
124
125   default:
126     fprintf(output, "\n **** unknown command %s, ITER or TERM must be specified", int2str(word));
127     fprintf(output, "\n **** program aborted\n");
128     exit(-1);
129     return;
130   }
131 }