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/pnchfile.cpp $
5 $LastChangedRevision: 80 $
6 $Date: 2014-07-01 21:01:54 -0400 (Tue, 01 Jul 2014) $
8 ***********************************************************
24 PunchFile_class PunchFile;
26 PunchFile_class::PunchFile_class()
31 int PunchFile_class::Open(BOOLEAN append)
33 const char* mode = (append) ? "a+" : "w";
34 if ((PnchFil = fopen("punch", mode)) == NULL)
42 void PunchFile_class::Close()
51 void PunchFile_class::WriteRecHeader(CHAR* recnam, CHAR* algn, INTEGER count,
54 fprintf(PnchFil, "%30s alg %4s iter %4i %30s\n", recnam, algn, count,
59 void PunchFile_class::WritePhantomHeader(CHAR* phnnam)
61 fprintf(PnchFil, "%s\n", phnnam);
66 void PunchFile_class::WriteData(REAL* recon, INTEGER nelem)
70 for (int n = 0; n < nelem; n++)
72 for (int j = 0; j < nelem; j++)
74 fprintf(PnchFil, " %10.4f", *jlo);
76 fprintf(PnchFil, "\n");
81 fprintf(PnchFil, "\n");
85 void PunchFile_class::WriteHeader(BOOLEAN Phantom)
88 static const CHAR keywdStr[40][5] =
89 { "last", "spec", "mono", "poly", "obje", "phan", "aver", "rays", "geom",
90 "para", "dive", "stri", "line", "tang", "arc ", "unif", "vari",
91 "angl", "meas", "perf", "nois", "quan", "scat", "mult", "addi",
92 "seed", "back", "run ", "modi", "save", "pixe", "equa", "user",
93 "and ", "afte", "step", "spac", "pnch", " ", " " };
95 static const CHAR kindStr[5][5] =
96 { "elip", "rect", "tria", "segm", "sect" };
98 static const INTEGER KWI_last = 0;
99 static const INTEGER KWI_spec = 1;
100 static const INTEGER KWI_mono = 2;
101 static const INTEGER KWI_poly = 3;
102 static const INTEGER KWI_obj = 4;
103 static const INTEGER KWI_pixel = 30;
105 // DATA SPACE FOR OBJECTS IN PHANTOM AT TOP OF BLANK COMMON
111 static const REAL one = 1.0;
117 quanfl = NoisePar.quanin > 0;
118 noisfl = quanfl || NoisePar.ultnfl || NoisePar.addnfl;
119 perfct = !(NoisePar.sctnfl || noisfl);
121 // ALSO SET VALUES PROPERLY FOR UNAVAILABLE QUANTITIES
124 Spctrm.energy[0] = -1;
126 // WRITE HEADER INFORMATION ON FILE11 FOR PHANTOM & RAYSUMS
127 // PUNCH OUT THE HEADER INFORMATION FOR THE PHANTOM AND PICTURES
130 if (Spctrm.nergy == 1)
132 fprintf(PnchFil, "%s %s %4i\n", keywdStr[KWI_spec],
133 keywdStr[KWI_mono], Spctrm.energy[0]);
136 if (Spctrm.nergy > 1)
139 fprintf(PnchFil, "%s %4s %4i\n", keywdStr[KWI_spec],
140 keywdStr[KWI_poly], Spctrm.nergy);
142 for (i = 0; i < Spctrm.nergy; i++)
144 fprintf(PnchFil, "%5i %5i ", Spctrm.energy[i], Creacm.percnt[i]);
146 fprintf(PnchFil, "\n");
151 fprintf(PnchFil, "%s\n", keywdStr[KWI_obj]);
153 if (Creacm.nobj != 0)
156 for (i = 0; i < Creacm.nobj; i++)
158 itype = (int) objects[i].type;
160 fprintf(PnchFil, "%4s %9.4f %9.4f %9.4f %9.4f %9.4f %9.4f\n",
161 kindStr[itype], objects[i].cx, objects[i].cy, objects[i].u,
162 objects[i].v, objects[i].ang, objects[i].den1[0]);
164 if (Spctrm.nergy > 1)
166 fprintf(PnchFil, "%4i ", i + 1);
167 for (j = 1; j < Spctrm.nergy; j++)
169 fprintf(PnchFil, " %9.4f", objects[i].den1[j]);
171 fprintf(PnchFil, "\n");
176 fprintf(PnchFil, "%s %9.4f\n", keywdStr[KWI_last], one);
178 // SKIP PHANTOM AVERAGING AND OTHER INFO SUCH AS NELEM FOR RDPROJ
180 fprintf(PnchFil, "phan aver 1\n"); // bug 121 - swr - 6/30/05
181 int nelem; // bug 166 - swr - 9/24/05
182 RecFile.GetNelem(&nelem);
184 RecFile.GetPixSize(&pixsiz);
185 fprintf(PnchFil, "%s %i size %10.4f\n", keywdStr[KWI_pixel], nelem,
188 // IF CALLED FROM PUNCH WE ARE DONE