Initial snark14m import
[snark14.git] / src / snark / mode.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/mode.cpp $
5  $LastChangedRevision: 80 $
6  $Date: 2014-07-01 21:01:54 -0400 (Tue, 01 Jul 2014) $
7  $Author: agulati $
8  ***********************************************************
9
10  SETS THE CONSTRAINT MODE PARAMETERS IN USER COMMON.
11  THESE ARE:
12  LOFL - LOWER CONSTRAINT FLAG
13  LOWER- LOWER CONSTRAINT VALUE
14  UPFL - UPPER CONSTRAINT FLAG
15  UPPER- UPPER CONSTRAINT VALUE
16  */
17
18 #include <cstdlib>
19 #include <cstdio>
20
21 #include "blkdta.h"
22 #include "modefl.h"
23 #include "uiod.h"
24
25 #include "int2str.h"
26 #include "infile.h"
27
28 #include "mode.h"
29
30 void mode()
31 {
32         INTEGER word;
33
34         BOOLEAN eol;
35
36         static const INTEGER mode_codes[2] =
37         { CHAR2INT('l', 'o', 'w', 'e'), CHAR2INT('u', 'p', 'p', 'e') };
38
39         Modefl.lofl = FALSE;
40         Modefl.upfl = FALSE;
41
42         word = InFile.getwrd(FALSE, &eol, mode_codes, 2);
43
44         while (!eol)
45         {
46                 if (word == mode_codes[0])
47                 {
48                         Modefl.lofl = TRUE;
49                         Modefl.lower = InFile.getnum(FALSE, &eol);
50
51                         if (eol)
52                         {
53                                 fprintf(output, "\n **** value after keyword LOWER can not be found\n **** program aborted\n");
54                                 exit(-1);
55                         };
56
57                 };
58
59                 if (word == mode_codes[1])
60                 {
61                         Modefl.upfl = TRUE;
62                         Modefl.upper = InFile.getnum(FALSE, &eol);
63
64                         if (eol)
65                         {
66                                 fprintf(output,
67                                                 "\n **** value after keyword UPPER can not be found\n **** program aborted\n");
68                                 exit(-1);
69                         };
70                 }
71
72                 word = InFile.getwrd(FALSE, &eol, mode_codes, 2);
73
74         }
75
76         //if both flags ('Modefl.lofl' & 'Modefl.upfl') are set to TRUE, but lower
77         //constraint ('Modefl.lower') was given a value greater than that given to upper constraint
78         //('Modefl.upper'), then output complaint to user and exit execution of snark05 (with exit code 111)
79         if (Modefl.lofl && Modefl.upfl)
80         {
81                 if (Modefl.lower > Modefl.upper)
82                 {
83                         fprintf(output,
84                                         "\n **** LOWER must not be greater than UPPER\n **** program aborted\n");
85                         exit(-1);
86                 }
87         }
88
89         if (Modefl.lofl)
90         {
91                 fprintf(output, "\n      lower constraint set to %9.4f", Modefl.lower);
92         }
93
94         if (Modefl.upfl)
95         {
96                 fprintf(output, "\n      upper constraint set to %9.4f", Modefl.upper);
97         }
98 }