Initial snark14m import
[snark14.git] / src / snark / pnch.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/pnch.cpp $
5  $LastChangedRevision: 80 $
6  $Date: 2014-07-01 21:01:54 -0400 (Tue, 01 Jul 2014) $
7  $Author: agulati $
8  ***********************************************************
9
10  POST-PROCESSING ROUTINE TO OUTPUT RECONSTRUCTIONS IN THE SNARK
11  PICTURE FORMAT.
12  */
13
14 #include <cstdlib>
15 #include <cstdio>
16
17 #include "blkdta.h"
18 #include "uiod.h"
19
20 #include "recfile.h"
21 #include "pnchfile.h"
22 #include "infile.h"
23
24 #include "post.h"
25
26 #include "pnch.h"
27
28 void pnch()
29 {
30         // was in post but it is really local
31         CHAR prjnam[81];
32         CHAR phnnam[81];
33         CHAR recnam[81];
34
35         // was in geo but it is realy local
36         INTEGER nelem;
37         INTEGER area;
38
39         //commented out since it is never used. Lajos, Dec 16, 2004
40         static const INTEGER hphan = CHAR2INT('p', 'h', 'a', 'n');
41
42         // modified calls to getwrd() to use the 4-parameter version. Lajos, Dec 13, 2004
43         static const INTEGER pnch_codes[1] =
44         { CHAR2INT('p', 'h', 'a', 'n') };
45
46         BOOLEAN eol, phan;
47         INTEGER flags[51];
48         CHAR algn[5];
49         unsigned INTEGER count, iter;
50         REAL* recon;
51
52         static bool called = FALSE;
53
54         // if first time call open new punch file
55         if (!called)
56         {
57                 if (PunchFile.Open(false) != 0)
58                 {
59                         fprintf(output, "\n **** unable to open file: punch");
60                         fprintf(output, "\n **** PUNCH execution aborted\n");
61                         return;
62                 }
63                 called = true;
64         }
65         else
66         { // otherwise append
67                 if (PunchFile.Open(true) != 0)
68                 {
69                         fprintf(output, "\n **** unable to open file: punch");
70                         fprintf(output, "\n **** PUNCH execution aborted\n");
71                         return;
72                 }
73         }
74
75         if (RecFile.Open("recfil") != 0)
76         {
77                 fprintf(output, "\n **** unable to open file: punch");
78                 fprintf(output, "\n **** PUNCH execution aborted\n");
79                 PunchFile.Close();
80                 return;
81         }
82
83         if (RecFile.GetNelem(&nelem) != 0)
84         {
85                 ;
86         }
87
88         if (RecFile.GetProjName(prjnam) != 0)
89         {
90                 ;
91         }
92
93         area = nelem * nelem;
94
95         phan = (InFile.getwrd(FALSE, &eol, pnch_codes, 1) == hphan);
96
97         InFile.listit(flags);
98
99         recon = new REAL[area];
100
101         if (phan)
102         {
103                 if (RecFile.ReadPhan(phnnam, recon) != 0)
104                 {
105                         fprintf(output, "\n **** phantom not present\n");
106                 }
107                 else
108                 {
109                         PunchFile.WritePhantomHeader(phnnam);
110
111                         PunchFile.WriteData(recon, nelem);
112                 }
113         }
114
115         prjnam[30] = 0;
116
117         while (RecFile.ReadRec(recnam, algn, &count, &iter, recon) == 0)
118         {
119
120                 recnam[30] = 0;
121
122                 if (flags[iter - 1] != 0)
123                 {
124
125                         fprintf(output,
126                                         "\n          reconstruction of %4s using %s iter %5i,   %s",
127                                         recnam, algn, count, prjnam);
128
129                         PunchFile.WriteRecHeader(recnam, algn, count, prjnam);
130
131                         PunchFile.WriteData(recon, nelem);
132                 }
133         }
134
135         delete[] recon;  // bug 92 - Lajos - 03/02/2005
136
137         RecFile.Close();
138         PunchFile.Close();
139 }
140