Initial snark14m import
[snark14.git] / src / snark / infile.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/infile.cpp $
5  $LastChangedRevision: 80 $
6  $Date: 2014-07-01 21:01:54 -0400 (Tue, 01 Jul 2014) $
7  $Author: agulati $
8  ***********************************************************
9  */
10
11 #include <cstdlib>       
12 #include <cstdio>
13 #include <cctype>
14
15 #include "blkdta.h"
16 #include "uiod.h"
17 #include "creacm.h"
18 #include "geom.h"
19
20 #include "anglst.h"
21 #include "creaer.h"
22 #include <cmath> // to go
23 #include "consts.h" // to go
24
25 #include "infile.h"
26 #include "int2str.h"
27
28 InFile_class InFile;
29
30 BOOLEAN InFile_class::GetFormat(BOOLEAN NewLine, CHAR* pictf)
31 {
32         if (fscanf(infile, "%s", pictf) != 1)
33         {
34                 return FALSE;
35         }
36
37         int c;
38
39         while (((c = fgetc(infile)) != '\n') && (c != EOF))
40         { // added check for EOF. Lajos, Nov 18, 2004
41         }
42
43         return TRUE;
44 }
45
46 void InFile_class::GetComment(CHAR* head)
47 {
48         signed CHAR ch; // changed "CHAR" to "signed CHAR". Lajos, Nov 18, 2004
49         int i;
50
51         fprintf(output, "\n");
52
53         for (i = 0; i < 80; i++)
54         {
55                 if (((ch = fgetc(infile)) == '\n') || (ch == EOF))
56                 {
57                         break;
58                 }
59                 head[i] = (CHAR) ch;
60         }
61
62         // read the rest of the line if more than 80 characters
63         while ((ch != '\n') && (ch != EOF))
64         { // added check for EOF. Lajos, Nov 18, 2004
65                 ch = fgetc(infile);
66         }
67
68         head[i] = 0;
69 }
70
71 // READ THE ITERATION FLAG CARD AND ECHO A DECODED VERSION OF IT.
72
73 void InFile_class::listit(INTEGER* iter)
74 {
75         int n, i;
76         INTEGER list[50];
77         CHAR nextch;
78
79
80         // get next line
81         getnxt(TRUE);
82
83         ptr++;
84
85         for (i = 0; i < 51; i++)
86         {
87                 nextch = data[ptr++];
88                 if (nextch == 0)
89                 { // if end of line encountered
90                         break;
91                 }
92                 if (!isdigit(nextch))
93                 { // if not digit
94                         iter[i] = 0; // set to zero
95                 }
96                 else
97                 {
98                         iter[i] = nextch - '0'; // convert to digit
99                 }
100         }
101
102         for (; i < 51; i++)
103         {
104                 iter[i] = 0;
105         }
106
107         n = 0;
108         for (i = 1; i < 51; i++)
109         {
110
111                 if (iter[i] == 0)
112                         continue;
113                 list[n++] = i - 1;
114         }
115
116         if (n != 0)
117         {
118                 fprintf(output, "\n         iterations ");
119
120                 for (int i = 0; i < n; i++)
121                 {
122                         if ((i != 0) && (i % 10 == 0))
123                         {
124                                 fprintf(output, "\n                    ");
125                         }
126                         fprintf(output, " %3i", list[i] + 1);
127                 }
128         }
129
130         if (iter[0] != 0)
131         {
132                 fprintf(output, "\n         last iteration\n");
133
134         }
135         return;
136
137 }
138
139 void InFile_class::GetRunOptions()
140 {
141         BOOLEAN eol;
142         INTEGER tword;
143
144         static const INTEGER run_codes[3] =
145         { CHAR2INT('r', 'u', 'n', ' '), CHAR2INT('m', 'o', 'd', 'i'), CHAR2INT('s',
146                         'a', 'v', 'e') };
147
148         tword = getwrd(TRUE, &eol, run_codes, 1);
149
150         if (tword != run_codes[0])
151                 creaer(run_codes[0]);
152
153         tword = getwrd(FALSE, &eol, &(run_codes[1]), 2);
154         Creacm.modif = (tword == run_codes[1]);
155         Creacm.crt12 = (tword == run_codes[2]);
156
157 }
158
159 void InFile_class::CreaInCrea()
160 {
161
162         static const INTEGER crea = CHAR2INT('c', 'r', 'e', 'a');
163
164         GetName();
165
166         // READ ENERGY SPECTRAL DISTRIBUTION
167         ReadEnergySpectralDistribution();
168
169         // READ OBJECTS MAKING UP THE PHANTOM
170         ReadObjects(crea);
171
172         // GET INFORMATION ABOUT CREATION OF PHANTOM
173         // THIS IS NOT RELEVANT FOR RDPROJ.  SO SKIP IN THE CASE OF RDPROJ
174         GetInformationABoutCreationOfPhantom(crea);
175
176         // READ RAYSUM INFORMATION
177         ReadRaysumInformation();
178
179         if (!Creacm.prjflg)
180         {
181
182                 /// original snark does not allow combinig pseudo with RUN options
183 #ifdef SEMINAR_RUN_OPTIONS
184                 GetRunOptions(); // !!!! for seminar
185 #endif
186                 return;
187         }
188
189         // READ IN AVERAGING INFORMATION FOR COMPUTING RAYSUMS
190
191         fprintf(output, "\n         this run will generate projection data");
192
193         ReadIfoForComputionRaysums();
194
195         // INPUT ENTIRE GEOMETRY DATA
196         ReadGeometryData(crea);
197
198         // READ NUMBER OF RAYS AND RAY SPACING
199         ReadNumberOfRaysAndRaySpacing(crea);
200
201         // READ NUMBER OF PROJECTIONS
202         // READ LIST OF PROJECTION ANGLES INTO WORK AREA
203         ReadProjectionAngles(FALSE);
204
205         // MEASUREMENT STATISTICS  --  NOISE AND SCATTER
206         GetMesurementStatistics();
207
208         // READ BACKGROUND ABSORPTION
209         ReadBackgroundAbsorption();
210
211         // IS THIS A MODIFY RUN OR DOES IT CREATE A FILE TAPE12 FOR FUTURE
212         fprintf(output, "\n ");
213         GetRunOptions();
214 }
215
216 void InFile_class::CreaInProj()
217 {
218
219         static const INTEGER proj = CHAR2INT('p', 'r', 'o', 'j');
220
221         GetName();
222
223         // INPUT ENTIRE GEOMETRY DATA
224         ReadGeometryData(proj);
225
226         // READ NUMBER OF RAYS AND RAY SPACING
227         ReadNumberOfRaysAndRaySpacing(proj);
228
229         // READ NUMBER OF PROJECTIONS
230         // READ LIST OF PROJECTION ANGLES INTO WORK AREA
231         ReadProjectionAngles(FALSE);
232
233         // MEASUREMENT STATISTICS  --  NOISE AND SCATTER
234         GetMesurementStatistics();
235
236         // READ BACKGROUND ABSORPTION
237         ReadBackgroundAbsorption();
238 }
239