4 //#include "DIGFileSnarkRec.h"
5 #include <DIGFileSnark/DIGFileSnarkRec.h>
7 #define DIGFILESNARKREC_DEBUG_LEVEL 0
9 const char* DIGFileSnarkRec::TypeStr = "SNARK05 recfil";
10 const char* DIGFileSnarkRec::SchemaStr = "DIGFileSnarkRec.xsd";
12 DIGFileSnarkRec::DIGFileSnarkRec()
17 DIGFileSnarkRec::~DIGFileSnarkRec()
21 ///////////////////////////////////////////////////////////////////////////////
22 ///////////////////////////////////////////////////////////////////////////////
24 ///////////////////////////////////////////////////////////////////////////////
25 ///////////////////////////////////////////////////////////////////////////////
27 ///////////////////////////////////////////////////////////////////////////////
29 ///////////////////////////////////////////////////////////////////////////////
31 int DIGFileSnarkRec::Open(const char* pFileName, RecFileMH* pMainHeader)
33 #if DIGFILESNARKREC_DEBUG_LEVEL > 3
\r
34 fprintf(stderr, "DIGFileSnarkRec::Open\n");
\r
38 pFileName, // file name
39 pMainHeader->Title.Get(), // title
40 pMainHeader->Dimensions, // dimensions
41 pMainHeader->Sampling, // sampling
42 pMainHeader->Comment.Get() // comment
46 int DIGFileSnarkRec::Open(
47 const char* pFileName, // File Name
48 const char* pProjName, // Projection Name
49 unsigned int pNoOfElements, // NELEM
50 double pSampling, // PIXSIZ
51 const char* pComments // Comments
54 #if DIGFILESNARKREC_DEBUG_LEVEL > 3
\r
55 fprintf(stderr, "DIGFileSnarkRec::Open\n");
\r
58 PhantomPresent = false;
64 DIGSampling sampZ = { 0.0, 0.0, 0.0 };
66 dim.x = pNoOfElements;
67 dim.y = pNoOfElements;
79 pFileName, // File Name
84 DIGValueType_REAL, // ValueType
85 DIGDataType_DOUBLE, // DataType
86 DIGDataFormat_BINARY, // DataFormat
88 DIGBasis_VORONOI, // Basis
89 DIGUnit_UNSPECIFIED, // Unit
94 pComments, // Comments
99 ///////////////////////////////////////////////////////////////////////////////
100 // Updating main header after opening file to write
101 ///////////////////////////////////////////////////////////////////////////////
103 ///////////////////////////////////////////////////////////////////////////////
105 ///////////////////////////////////////////////////////////////////////////////
107 int DIGFileSnarkRec::AppendPhanom(RecFilePhanomH* pPhanomHeader, double* pData)
109 #if DIGFILESNARKREC_DEBUG_LEVEL > 3
\r
110 fprintf(stderr, "DIGFileSnarkRec::AppendPhanom\n");
\r
113 return AppendPhantom(pPhanomHeader->Name.Get(), pPhanomHeader->Comment.Get(), pData);
116 int DIGFileSnarkRec::AppendPhantom(const char* pPhanomName, const char* pComment, double* pData)
118 #if DIGFILESNARKREC_DEBUG_LEVEL > 3
\r
119 fprintf(stderr, "DIGFileSnarkRec::AppendPhanom\n");
\r
122 // writes a phantom array into the file
123 // should only be used as first array set
127 #if DIGFILESNARKREC_DEBUG_LEVEL > 0
\r
128 printf("** Error: Reconstructions already in the file\n");
\r
130 return -1; // reconstructions already in the file
133 if(PhantomPresent) {
\r
134 #if DIGFILESNARKREC_DEBUG_LEVEL > 0
\r
135 printf("** Error: Phantom already in the file\n");
\r
137 return -1; // phantom already in the file
140 if(AppendArraySet("PHAN", pPhanomName, "", pComment) != 0) {
\r
144 if(AppendArray(0, "", pData) != 0) {
148 PhantomPresent = true;
153 ///////////////////////////////////////////////////////////////////////////////
154 // Appending reconstruction set
155 ///////////////////////////////////////////////////////////////////////////////
157 int DIGFileSnarkRec::AppendRecSet(RecFileRecSetH* pRecSetHeader)
159 #if DIGFILESNARKREC_DEBUG_LEVEL > 3
\r
160 fprintf(stderr, "DIGFileSnarkRec::AppendRecSet\n");
\r
163 return AppendRecSet(pRecSetHeader->AlgName.Get(), pRecSetHeader->Name.Get(), pRecSetHeader->Comment.Get());
166 int DIGFileSnarkRec::AppendRecSet(const char* pAlgName, const char* pName, const char* pComment)
168 #if DIGFILESNARKREC_DEBUG_LEVEL > 3
\r
169 fprintf(stderr, "DIGFileSnarkRec::AppendRecSet\n");
\r
172 return AppendArraySet(pAlgName, pName, "", pComment);
175 ///////////////////////////////////////////////////////////////////////////////
176 // Appending reconstruction
177 ///////////////////////////////////////////////////////////////////////////////
179 int DIGFileSnarkRec::AppendRec(RecFileRecH* pRecHeader, double* pData)
181 #if DIGFILESNARKREC_DEBUG_LEVEL > 3
\r
182 fprintf(stderr, "DIGFileSnarkRec::AppendRec\n");
\r
185 return AppendRec(pRecHeader->Count, pRecHeader->Comment.Get(), pData);
188 int DIGFileSnarkRec::AppendRec(unsigned int pCount, const char* pComment, double* pData)
190 #if DIGFILESNARKREC_DEBUG_LEVEL > 3
\r
191 fprintf(stderr, "DIGFileSnarkRec::AppendRec\n");
\r
194 return AppendArray(pCount, pComment, pData);
197 ///////////////////////////////////////////////////////////////////////////////
198 ///////////////////////////////////////////////////////////////////////////////
200 ///////////////////////////////////////////////////////////////////////////////
201 ///////////////////////////////////////////////////////////////////////////////
203 ///////////////////////////////////////////////////////////////////////////////
205 ///////////////////////////////////////////////////////////////////////////////
207 int DIGFileSnarkRec::Open(const char* FileName)
209 #if DIGFILESNARKREC_DEBUG_LEVEL > 3
\r
210 fprintf(stderr, "DIGFileSnarkRec::Open\n");
\r
213 if(DIGFile::Open(FileName) != 0) {
\r
214 #if DIGFILESNARKREC_DEBUG_LEVEL > 0
\r
215 printf("** Error: Openning DIG file\n");
\r
217 return -1; // error opening dig file
220 if(strcmp(MainHeader.Type.Get(), TypeStr) != 0) {
\r
221 #if DIGFILESNARKREC_DEBUG_LEVEL > 0
\r
222 printf("** Error: Not a rsnark05 reffil file\n");
\r
224 return -2; // not a RecFile
227 // check if there is a phantom in the file
229 // select first array set
230 if(SelectArraySet(0) != 0) {
236 if(GetArraySetType(&type) != 0) {
240 //// Move to first reconstruction array
241 if(strncmp(type, "PHAN", 4) == 0) { // if first set is phantom set
242 PhantomPresent = true;
245 PhantomPresent = false;
251 ///////////////////////////////////////////////////////////////////////////////
252 // Reading main header
253 ///////////////////////////////////////////////////////////////////////////////
255 int DIGFileSnarkRec::GetMainHeader(RecFileMH* MainHeader)
257 #if DIGFILESNARKREC_DEBUG_LEVEL > 3
\r
258 fprintf(stderr, "DIGFileSnarkRec::GetMainHeader\n");
\r
264 if(GetTitle(&Title) != 0) {
265 printf("Error reading Main Header Title\n");
269 printf("Main Header Title: %s\n", Title);
271 if(MainHeader->Title.Set(Title) != 0) {
272 printf("Error seting Main Header Title\n");
277 if(GetDimensions(&(MainHeader->Dimensions)) != 0) {
278 printf("Error reading Main Header Dimensions\n");
282 printf("Main Header Dimensions: %d\n", MainHeader->Dimensions);
284 if(GetSampling(&(MainHeader->Sampling)) != 0) {
285 printf("Error reading Main Header Sampling\n");
289 printf("Main Header Sampling: %f\n", MainHeader->Sampling);
294 if(GetComment(&Comment) != 0) {
295 printf("Error reading Main Header Comment\n");
299 printf("Main Header Comment: %s\n", Comment);
301 if(MainHeader->Comment.Set(Comment) != 0) {
302 printf("Error Seting Main Header Comment\n");
309 ///////////////////////////////////////////////////////////////////////////////
310 // Reading phantom header
311 ///////////////////////////////////////////////////////////////////////////////
313 int DIGFileSnarkRec::GetPhantomHeader(RecFilePhanomH* pPhantomHeader)
315 #if DIGFILESNARKREC_DEBUG_LEVEL > 3
\r
316 fprintf(stderr, "DIGFileSnarkRec::GetPhantomHeader\n");
\r
323 if(GetPhantomName(&Name) != 0) {
324 printf("Error reading Phantom Name\n");
328 printf("Phantom Name: %s\n", Name);
330 if(pPhantomHeader->Name.Set(Name) != 0) {
331 printf("Error Setting Phantom Name\n");
339 if(GetPhantomComment(&Comment) != 0) {
340 printf("Error reading Phantom Comment\n");
344 printf("Phantom Comment: %s\n", Comment);
346 if(pPhantomHeader->Comment.Set(Comment) != 0) {
347 printf("Error Setting Phantom Comment\n");
354 int DIGFileSnarkRec::GetPhantomName(const char** pPhantomName)
356 #if DIGFILESNARKREC_DEBUG_LEVEL > 3
\r
357 fprintf(stderr, "DIGFileSnarkRec::GetPhantomName\n");
\r
360 if(!PhantomPresent) {
\r
362 #if DIGFILESNARKREC_DEBUG_LEVEL > 0
\r
363 printf("** Error: No phantom in file\n");
\r
365 return -1; // no phantom in file
368 // select first array set
369 if(SelectArraySet(0) != 0) {
\r
371 #if DIGFILESNARKREC_DEBUG_LEVEL > 0
\r
372 printf("** Error: No array sets in file\n");
\r
377 return DIGFile::GetArraySetTitle(pPhantomName);
380 int DIGFileSnarkRec::GetPhantomComment(const char** pPhantomComment)
382 #if DIGFILESNARKREC_DEBUG_LEVEL > 3
\r
383 fprintf(stderr, "DIGFileSnarkRec::GetPhantomComment\n");
\r
386 if(!PhantomPresent) {
\r
388 #if DIGFILESNARKREC_DEBUG_LEVEL > 0
\r
389 printf("** Error: No phantom in file\n");
\r
391 return -1; // no phantom in file
394 // select first array set
395 if(SelectArraySet(0) != 0) {
\r
397 #if DIGFILESNARKREC_DEBUG_LEVEL > 0
\r
398 printf("** Error: No phantom in file\n");
\r
403 return DIGFile::GetArraySetComment(pPhantomComment);
406 ///////////////////////////////////////////////////////////////////////////////
407 // Reading phantom data
408 ///////////////////////////////////////////////////////////////////////////////
410 int DIGFileSnarkRec::GetPhantomData(void* pPhantomData)
412 #if DIGFILESNARKREC_DEBUG_LEVEL > 3
\r
413 fprintf(stderr, "DIGFileSnarkRec::GetPhantomData\n");
\r
416 if(!PhantomPresent) {
417 return -1; // no phantom in file
420 // select first array set
421 if(SelectArraySet(0) != 0) {
\r
422 #if DIGFILESNARKREC_DEBUG_LEVEL > 0
\r
423 printf("** Error: No phantom in file\n");
\r
428 // select first array
429 if(SelectArray(0) != 0) {
\r
430 #if DIGFILESNARKREC_DEBUG_LEVEL > 0
\r
431 printf("** Error: No phantom in file\n");
\r
436 return DIGFile::GetArrayData(pPhantomData);
439 ///////////////////////////////////////////////////////////////////////////////
440 // Reading reconstruction set header
441 ///////////////////////////////////////////////////////////////////////////////
443 int DIGFileSnarkRec::GetRecSetHeader(RecFileRecSetH* pRecSetHeader)
445 #if DIGFILESNARKREC_DEBUG_LEVEL > 3
\r
446 fprintf(stderr, "DIGFileSnarkRec::GetRecSetHeader\n");
\r
453 if(GetRecSetName(&Name) != 0) {
454 printf("Error reading Reconstruction Name\n");
458 printf("Reconstruction Name: %s\n", Name);
460 if(pRecSetHeader->Name.Set(Name) != 0) {
461 printf("Error Setting Reconstruction Name\n");
469 if(GetRecSetAlgName(&AlgName) != 0) {
470 printf("Error reading Reconstruction AlgName\n");
474 printf("Reconstruction Name: %s\n", AlgName);
476 if(pRecSetHeader->Name.Set(AlgName) != 0) {
477 printf("Error Setting Reconstruction AlgName\n");
485 if(GetRecSetComment(&Comment) != 0) {
486 printf("Error reading Reconstruction Set Comment\n");
490 printf("Reconstruction Comment: %s\n", Comment);
492 if(pRecSetHeader->Comment.Set(Comment) != 0) {
493 printf("Error Setting Reconstruction Set Comment\n");
500 int DIGFileSnarkRec::GetRecSetName(const char** pRecName)
502 #if DIGFILESNARKREC_DEBUG_LEVEL > 3
\r
503 fprintf(stderr, "DIGFileSnarkRec::GetRecSetName\n");
\r
506 return DIGFile::GetArraySetTitle(pRecName);
509 int DIGFileSnarkRec::GetRecSetAlgName(const char** pAlgName)
511 #if DIGFILESNARKREC_DEBUG_LEVEL > 3
\r
512 fprintf(stderr, "DIGFileSnarkRec::GetRecSetAlgName\n");
\r
515 return DIGFile::GetArraySetType(pAlgName);
518 int DIGFileSnarkRec::GetRecSetComment(const char** pComment)
520 #if DIGFILESNARKREC_DEBUG_LEVEL > 3
\r
521 fprintf(stderr, "DIGFileSnarkRec::GetRecSetComment\n");
\r
524 return DIGFile::GetArraySetComment(pComment);
527 ///////////////////////////////////////////////////////////////////////////////
528 // Reading reconstruction header
529 ///////////////////////////////////////////////////////////////////////////////
531 int DIGFileSnarkRec::GetRecHeader(RecFileRecH* RecHeader)
533 #if DIGFILESNARKREC_DEBUG_LEVEL > 3
\r
534 fprintf(stderr, "DIGFileSnarkRec::GetRecHeader\n");
\r
537 // read Reconstruction Count
539 if(GetRecCount(&(RecHeader->Count)) != 0) {
540 printf("Error reading Reconstruction Count\n");
544 printf("Reconstruction Count: %u\n", RecHeader->Count);
550 if(GetRecComment(&Comment) != 0) {
551 printf("Error reading Reconstruction Comment\n");
555 printf("Reconstruction Comment: %s\n", Comment);
557 if(RecHeader->Comment.Set(Comment) != 0) {
558 printf("Error Setting Reconstruction Comment\n");
566 int DIGFileSnarkRec::GetRecCount(unsigned int* pCount)
568 #if DIGFILESNARKREC_DEBUG_LEVEL > 3
\r
569 fprintf(stderr, "DIGFileSnarkRec::GetRecCount\n");
\r
572 return DIGFile::GetArrayEnumNo(pCount);
575 int DIGFileSnarkRec::GetRecComment(const char** pComment)
577 #if DIGFILESNARKREC_DEBUG_LEVEL > 3
\r
578 fprintf(stderr, "DIGFileSnarkRec::GetRecComment\n");
\r
581 return DIGFile::GetArrayComment(pComment);