Initial snark14m import
[snark14.git] / src / snark / rdpict.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/rdpict.cpp $
5  $LastChangedRevision: 91 $
6  $Date: 2014-07-02 17:34:27 -0400 (Wed, 02 Jul 2014) $
7  $Author: agulati $
8  ***********************************************************
9
10  READ A TEST PICTURE FROM FILE 'FILE11' AND CONVERT TO SNARK
11  INTERNAL REPRESENTATION
12  */
13
14 #include <cstdlib>       
15 #include <cstdio>
16
17 #include "blkdta.h"
18 #include "creacm.h"
19 #include "geom.h"
20 #include "consts.h"
21 #include "uiod.h"
22
23 #include "creaer.h"
24 #include "recfile.h"
25
26 #include "file11.h"
27 #include "infile.h"
28
29 #include "rdpict.h"
30
31 //CHAR pictf[20];
32
33 void rdpict()
34 {
35         static BOOLEAN rdpict_called = false;
36
37         BOOLEAN eol;
38
39         INTEGER tword;
40         static const INTEGER pict_codes[2] =
41         { CHAR2INT('r', 'e', 'c', 'o'), CHAR2INT('t', 'e', 's', 't') };
42
43         // TEST FOR MULTIPLE CALLS AND ISSUE WARNING
44         if (rdpict_called)
45                 creaer(1);
46
47         rdpict_called = TRUE;
48         Creacm.test = NULL;
49
50         // DETERMINE WHETHER PICTURE TEST OR RECON.
51
52         tword = InFile.getwrd(FALSE, &eol, pict_codes, 2);
53
54         if (eol)
55         {
56                 fprintf(output, "\n **** TEST or RECONSTRUCTION must be specified");
57                 fprintf(output, "\n **** program aborted\n");
58                 exit(-1);
59         };
60
61         if (tword == pict_codes[0])
62         {
63                 // FOR PICT RECON GET NELEM, PIXSIZ, WRITE ON RECFIL QUIT
64                 GeoPar.nelem = InFile.getint(FALSE, &eol);
65                 // The following line added for SNARK89 Version 1.01 7/13/90
66                 if ((GeoPar.nelem <= 0) || (GeoPar.nelem / 2 * 2 == GeoPar.nelem))
67                         creaer(9);
68                 GeoPar.area = GeoPar.nelem * GeoPar.nelem;
69                 GeoPar.midpix = (GeoPar.nelem + 1) / 2;
70                 GeoPar.pixsiz = InFile.getnum(FALSE, &eol);
71                 // The following line added for SNARK89 Version 1.01 7/13/90
72                 if (GeoPar.pixsiz < Consts.zero)
73                         creaer(10);
74
75                 // OPEN RECONSTRUCTION FILE FOR PICTURE RECONSTRUCTION CASE
76
77                 if (RecFile.Open("recfil", GeoPar.nelem, GeoPar.pixsiz) != 0)
78                 {
79                         fprintf(output, "\n **** unable to open recfil");
80                         fprintf(output, "\n **** program aborted\n");
81                         exit(-1);
82                 }
83         }
84         else
85         {
86                 // READ PICTURE HEADER INFORMATION
87
88                 if (File11.Open(FALSE) != 0)
89                 {
90                         fprintf(output, "\n **** unable to open file11 for reading");
91                         fprintf(output, "\n **** program aborted\n");
92                         exit(-1);
93                 };
94                 File11.isOpen = TRUE;
95
96                 File11.CreaInPicture();
97
98                 if (Creacm.erflag)
99                         exit(444);
100
101                 // WRITE HEADER ON RECFIL
102                 // OPEN RECONSTRUCTION FILE FOR PICTURE TEST CASE
103
104                 if (RecFile.Open("recfil", GeoPar.nelem, GeoPar.pixsiz) != 0)
105                 {
106                         fprintf(output, "\n **** unable to open recfil");
107                         fprintf(output, "\n **** program aborted\n");
108                         exit(-1);
109                 }
110
111                 // ALLOCATE SPACE FOR THE PICTURE
112                 Creacm.test = new REAL[GeoPar.area];
113
114                 // READ IN THE TEST PICTURE INTO THE WORK AREA
115
116                 File11.ReadPicture(Creacm.test, GeoPar.nelem);
117
118                 // WRITE TEST PICTURE ON RECFIL
119                 RecFile.WritePhan(Creacm.name, Creacm.test);
120
121                 fprintf(output, "\n         test picture read");
122                 fprintf(output, "\n         %s", Creacm.name);
123         }
124
125         return;
126 }