Initial snark14m import
[snark14.git] / src / snark / art_readin.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/art_readin.cpp $
5  $LastChangedRevision: 85 $
6  $Date: 2014-07-02 16:07:08 -0400 (Wed, 02 Jul 2014) $
7  $Author: agulati $
8  ***********************************************************
9
10  READ IN INPUT OPTIONS AND SET DEFAULTS
11  */
12
13 #include <cstdio>
14
15 #include "blkdta.h"
16 #include "geom.h"
17 #include "modefl.h"
18 #include "consts.h"
19 #include "uiod.h"
20
21 #include "int2str.h"
22 #include "infile.h"
23 #include "raysel.h"
24
25 #include "art.h"
26
27 /// !!! list & weight never used !!!
28
29 void art_class::readin(REAL* recon, INTEGER* list, REAL* weight, BOOLEAN* flag)
30 {
31         static const INTEGER bound = CHAR2INT('b', 'o', 'u', 'n');
32         static const INTEGER vari = CHAR2INT('v', 'a', 'r', 'i');
33         static const INTEGER noise = CHAR2INT('n', 'o', 'i', 's');
34         static const INTEGER art2 = CHAR2INT('a', 'r', 't', '2');
35         static const INTEGER cons = CHAR2INT('c', 'o', 'n', 's');
36         static const INTEGER bart = CHAR2INT('b', 'a', 'r', 't');
37         static const INTEGER fixed = CHAR2INT('f', 'i', 'x', 'e');
38
39         static const INTEGER norm = CHAR2INT('n', 'o', 'r', 'm');
40         static const INTEGER rela = CHAR2INT('r', 'e', 'l', 'a');
41         static const INTEGER art4 = CHAR2INT('a', 'r', 't', '4');
42         static const INTEGER tole = CHAR2INT('t', 'o', 'l', 'e');
43         static const INTEGER conr = CHAR2INT('c', 'o', 'n', 'r');
44         static const INTEGER step = CHAR2INT('s', 't', 'e', 'p');
45         static const INTEGER noml = CHAR2INT('n', 'o', 'm', 'l');
46         static const INTEGER baye = CHAR2INT('b', 'a', 'y', 'e');
47         static const INTEGER art3 = CHAR2INT('a', 'r', 't', '3');
48
49         int i;
50
51         BOOLEAN eol;
52         BOOLEAN boundf;
53
54         INTEGER word;
55         //REAL* delta; ///!!!!
56
57         // DEFAULT INITIALIZATION
58
59         ArtIn.p = 2;
60         ArtIn.relax = 1.0;
61         ArtIn.toler = 0.0;
62         //ArtIn.kount = GeoPar.prjnum * GeoPar.usrays; // change nrays to usrays. hstau 7/2003
63         {
64                 if (RaySel.useray)  // select user
65                         ArtIn.kount = GeoPar.prjnum * GeoPar.usrays;
66                 else
67                         //select snark
68                         ArtIn.kount = GeoPar.prjnum * GeoPar.snrays;
69         }  // set value to kount for select user or select snark. Wei   11/2004
70
71         ArtIn.npin = -1;
72         ArtIn.rconsf = TRUE;
73         ArtIn.cr = 1.0;
74         ArtIn.crf = TRUE;
75         ArtIn.art2f = FALSE;
76         ArtIn.art3f = FALSE;
77         ArtIn.art4f = FALSE;
78         ArtIn.tolerf = TRUE;
79         ArtIn.nomlf = FALSE;
80         boundf = FALSE;
81         ArtIn.bartf = FALSE;
82         ArtIn.bayef = FALSE;
83         ArtIn.noisef = FALSE;
84         *flag = FALSE;
85
86         INTEGER exp0[3] =
87         { art3, art4, baye };
88
89         word = InFile.getwrd(TRUE, &eol, exp0, 3);
90
91         if (eol)
92         {
93                 fprintf(output,
94                                 "\n          **** error - one and only one of the following options must be specified : art3, art4, bayesian***");
95                 *flag = TRUE;
96                 return;
97         }
98
99         if (word == art3)
100         {
101                 ArtIn.art3f = TRUE;
102                 fprintf(output, "\n          art3 method");
103         }
104
105         else if (word == art4)
106         {
107                 ArtIn.art4f = TRUE;
108                 fprintf(output, "\n          art4 method");
109         }
110
111         else
112         { //word == baye
113                 ArtIn.bayef = TRUE;
114                 ArtIn.snr = InFile.getnum(FALSE, &eol);
115                 if (eol)
116                 {
117                         fprintf(output,
118                                         "\n          **** error - must specify the snr in Bayesian option***");
119                         *flag = TRUE;
120                         return;
121                 }
122
123                 ArtIn.snr2 = ArtIn.snr * ArtIn.snr;
124                 if (ArtIn.snr2 <= Consts.zero)
125                 {
126                         fprintf(output,
127                                         "\n          **** error - snr**2= %10.6f must be greater than %12.4e***",
128                                         ArtIn.snr2, Consts.zero);
129
130                         *flag = TRUE;
131                         return;
132                 }
133
134                 fprintf(output, "\n          Bayesian method with  snr = %9.5f",
135                                 ArtIn.snr);
136         }  // baye
137
138         INTEGER exp1[3] =
139         { rela, norm, tole };
140         word = InFile.getwrd(FALSE, &eol, exp1, 3);
141
142         if (eol)
143         {
144                 fprintf(output, "\n          relaxation parameter is 1.0");
145                 fprintf(output, "\n          norm is 2");
146                 fprintf(output, "\n          tolerance is 0.0");
147                 goto L20;
148                 // read next line
149         }
150
151         if (word == rela)
152         {
153                 INTEGER exp2[2] =
154                 { cons, vari };
155                 word = InFile.getwrd(FALSE, &eol, exp2, 2);
156
157                 if (eol)
158                 {
159                         fprintf(output,
160                                         "\n          **** error - with the option relaxation, one and only one of the following options must be specified : constant or variable***");
161                         *flag = TRUE;
162                         return;
163                 }
164
165                 if (word == cons)
166                 {
167                         ArtIn.relax = InFile.getnum(FALSE, &eol);
168
169                         if (eol)
170                         {
171                                 fprintf(output,
172                                                 "\n          **** error - must specify the relaxation constant***");
173                                 *flag = TRUE;
174                                 return;
175                         }
176                         else
177                         {
178                                 fprintf(output, "\n          relaxation parameter is %9.4f",
179                                                 ArtIn.relax);
180                         }
181                 }
182
183                 else
184                 {  //relax=vari
185                         ArtIn.rconsf = FALSE;
186                         fprintf(output, "\n          relaxation parameter is variable");
187                 }
188
189                 INTEGER exp1a[2] =
190                 { norm, tole };
191                 word = InFile.getwrd(FALSE, &eol, exp1a, 2);
192
193                 if (word == norm)
194                         goto L10;
195                 else if (word == tole)
196                         goto L15;
197                 else
198                 {
199                         fprintf(output, "\n          norm is 2");
200                         fprintf(output, "\n          tolerance is 0.0");
201                         goto L20;
202                         // eol: read next line
203                 }
204         } // word == rela
205
206         else if (word == norm)
207         {
208                 L10: ArtIn.p = InFile.getint(FALSE, &eol);
209
210                 if (eol)
211                 {
212                         fprintf(output,
213                                         "\n          **** error - must specify the norm***");
214                         *flag = TRUE;
215                         return;
216                 }
217                 else if (ArtIn.p < 0)
218                 {
219                         fprintf(output, "\n          norm cannot be negative");
220                         *flag = TRUE;
221                         return;
222                 }
223                 else
224                 {
225                         fprintf(output, "\n          norm is %5i", ArtIn.p);
226                 }
227
228                 INTEGER exp1b[1] =
229                 { tole };
230                 word = InFile.getwrd(FALSE, &eol, exp1b, 1);
231
232                 if (word == tole)
233                         goto L15;
234                 else
235                 {
236                         fprintf(output, "\n          tolerance is 0.0");
237                         goto L20;
238                         // eol: read next line
239                 }
240         }  // word == norm
241
242         else
243         { //word = tole
244
245                 L15:
246                 INTEGER exp3[3] =
247                 { fixed, vari, noise };
248                 word = InFile.getwrd(FALSE, &eol, exp3, 3);
249
250                 if (eol)
251                 {
252                         fprintf(output,
253                                         "\n          **** error - with the option tolerance, one and only one of the following options must be specified : fixed, variable, or noise***");
254                         *flag = TRUE;
255                         return;
256                 }
257
258                 if (word == fixed)
259                 {
260                         ArtIn.toler = InFile.getnum(FALSE, &eol);
261
262                         if (eol)
263                         {
264                                 fprintf(output,
265                                                 "\n          **** error - must specify tolerance ***");
266                                 *flag = TRUE;
267                                 return;
268                         }
269
270                         else if (ArtIn.toler < 0.0)
271                         {
272                                 fprintf(output,
273                                                 "\n          **** error - tolerance can not be less than 0.0***");
274                                 *flag = TRUE;
275                                 return;
276                         }
277
278                         else
279                         {
280                                 fprintf(output, "\n          tolerance is %9.4f", ArtIn.toler);
281                         }
282                 } // fixed
283
284                 else if (word == vari)
285                 {
286                         ArtIn.tolerf = FALSE;
287                         fprintf(output, "\n          tolerance is variable");
288                 }
289
290                 else
291                 { // noise
292                         ArtIn.noisef = TRUE;
293                         ArtIn.ct = InFile.getnum(FALSE, &eol);
294
295                         if (eol)
296                         {
297                                 fprintf(output,
298                                                 "\n          **** error - must specify tolerance ***");
299                                 *flag = TRUE;
300                                 return;
301                         }
302
303                         else if (ArtIn.ct < 0.0)
304                         {
305                                 fprintf(output,
306                                                 "\n          **** error - tolerance can not be less than 0.0***");
307                                 *flag = TRUE;
308                                 return;
309                         }
310
311                         else
312                         {
313                                 fprintf(output,
314                                                 "\n          tolerance is data dependent, noise factor%9.4f",
315                                                 ArtIn.ct);
316                         }
317                 } //noise
318         } //word == tole
319
320         L20:
321
322         INTEGER exp4[1] =
323         { cons };
324
325         word = InFile.getwrd(TRUE, &eol, exp4, 1);
326
327         if (eol)
328         {
329                 fprintf(output,
330                                 "\n          **** error - keyword constraint is missing***");
331                 *flag = TRUE;
332                 return;
333         }
334
335         INTEGER exp5[3] =
336         { art2, bound, bart };
337
338         word = InFile.getwrd(FALSE, &eol, exp5, 3);
339
340         if (eol)
341         {
342                 fprintf(output,
343                                 "\n          **** error - with the option constraint, one and only one of the following options must be specified : art2, bound, or bart***");
344                 *flag = TRUE;
345                 return;
346         }
347
348         if (word == art2)
349         {
350                 ArtIn.art2f = TRUE;
351                 fprintf(output, "\n          constraint art2 way");
352         }
353
354         else if (word == bound)
355         {
356                 boundf = TRUE;
357                 fprintf(output, "\n          constraint set to boundaries");
358         }
359
360         else
361         { //word == bart
362                 ArtIn.bartf = TRUE;
363                 if (!(Modefl.lofl && Modefl.upfl))
364                 {
365                         fprintf(output,
366                                         "\n          *** error - both upfl and lofl must be on when bart is specified***");
367                         *flag = TRUE;
368                         return;
369                 }
370
371                 fprintf(output, "\n          constraint bart");
372
373         }  //bart
374
375         INTEGER exp6[3] =
376         { conr, step, noml };
377         word = InFile.getwrd(FALSE, &eol, exp6, 3);
378
379         if (eol)
380         {
381                 fprintf(output, "\n          relaxation constraints with cr = 1.0");
382                 fprintf(output, "\n          picture is not normalized");
383                 goto L40;
384                 // finished reading input
385         }
386         if (word == conr)
387         {
388                 INTEGER exp7[2] =
389                 { cons, vari };
390                 word = InFile.getwrd(FALSE, &eol, exp7, 2);
391
392                 if (eol)
393                 {
394                         fprintf(output,
395                                         "\n          **** error - with the option conrelax, one and only one of the following options must be specified : constant or variable***");
396                         *flag = TRUE;
397                         return;
398                 }
399
400                 if (word == cons)
401                 {
402                         ArtIn.cr = InFile.getnum(FALSE, &eol);
403
404                         if (eol)
405                         {
406                                 fprintf(output,
407                                                 "\n          **** error - must specify constraint relaxation constant***");
408                                 *flag = TRUE;
409                                 return;
410                         }
411                         fprintf(output, "\n          relax constraints with cr= %9.4f",
412                                         ArtIn.cr);
413                 }
414                 else
415                 { //variable relax constaints
416                         ArtIn.crf = FALSE;
417                         fprintf(output, "\n          relax constraints with variable cr");
418                 }
419
420                 INTEGER exp6a[2] =
421                 { step, noml };
422                 word = InFile.getwrd(FALSE, &eol, exp6a, 2);
423
424                 if (word == step)
425                         goto L30;
426                 else if (word == noml)
427                         goto L35;
428                 else
429                 {
430                         fprintf(output, "\n          picture is not normalized");
431                         goto L40;
432                         // eol: finished
433                 }
434         } // constraint relaxation
435
436         else if (word == step)
437         {
438                 L30: ArtIn.kount = InFile.getint(FALSE, &eol);
439
440                 if (eol)
441                 {
442                         fprintf(output, "\n          **** error - must specify kount***");
443                         *flag = TRUE;
444                         return;
445                 }
446                 else if (ArtIn.kount <= 0)
447                 {
448                         fprintf(output,
449                                         "\n          **** error - kount can not be less than 0 **");
450                         *flag = TRUE;
451                         return;
452                 }
453
454                 INTEGER exp6b[1] =
455                 { noml };
456                 word = InFile.getwrd(FALSE, &eol, exp6b, 1);
457
458                 if (word == noml)
459                         goto L35;
460                 else
461                 {
462                         fprintf(output, "\n          picture is not normalized");
463                         goto L40;
464                         // eol: finished
465                 }
466         }  // word = step
467
468         L35: //nomlz
469         ArtIn.nomlf = TRUE;
470         fprintf(output,
471                         "\n          picture is normalized to %9.4f after each iteration",
472                         GeoPar.aveden);
473
474         L40: if (!ArtIn.art3f)
475         {
476
477                 // ALLOCATE AND INITIALIZE DUAL VARIABLES IN ART4
478                 // OR IN BAYESIAN
479
480                 //Ran, bug 266
481                 ArtIn.totalRays = new REAL[GeoPar.nrays * GeoPar.prjnum];
482                 for (i = 0; i < (GeoPar.nrays * GeoPar.prjnum); i++)
483                 {
484                         ArtIn.totalRays[i] = 0.0;
485                 }
486         }
487
488         fprintf(output, "\n          %5i rays are used for each iteration",
489                         ArtIn.kount);
490
491         if (Modefl.lofl)
492         {
493                 fprintf(output, "\n          lower constraint = %9.4f", Modefl.lower);
494         }
495         if (Modefl.upfl)
496         {
497                 fprintf(output, "\n          upper constraint = %9.4f", Modefl.upper);
498         }
499
500         return;
501 }
502