Writing .Cdf file

Dear users/developers,

I am trying to create a program that will write experimental results to the appropriate .Cdf ascii format. I am using this loop:

char buffer [20];
sprintf(buffer, “CDF_CstrProj.Cdf”);
pFile = fopen (buffer, “w”);
for (id1=0; id1<bins_elts; id1++)
{
for (id2=0; id2<nCrystalsTot; id2++)
{
fprintf(pFile,"%6d “,timeMS[id1][id2]);
fprintf(pFile,”%6d “,data[id1][id2]);
fprintf(pFile,”%6d “,id1);
fprintf(pFile,”%6d ",id2);
}
}

Where id1 is the projectionID (0-35) and id2 is the pixelID (0-2997). Data are the counts. I am using integers in data but I have also try it with floats. Then by using a .Cdh I try to reconstruct. There is a problem there. Probably castor-recon does not recognize the file correct, because I am getting this fault repeatedly (the “Projection index” only change:

***** oIterativeAlgorithm::StepInnerLoopInsideSubsetLoop() → A problem occured while computing the projection line !
***** iScannerSPECTConv::GetPositionsAndOrientations() → Projection index (538976288) out of range [0:35] !
***** vProjector::Project() → A problem occured while getting positions and orientations from scanner !
***** oProjectorManager::ComputeProjectionLine() → A problem occured while forward projecting an event !

I am attaching the file in order that you take a look and help me.

Thank you in advance,

Konstantinos

CDF_CstrProj.Cdh (640 Bytes)

CDF_CstrProj.Cdf (2.88 MB)

Hi Konstantinos,

The out of range projection index errors usually means the code can’t correctly read the binary datafile as you said. Judging from the values in your cdf file, I think something went wrong during your conversion. Expected types are float for the data, and unsigned integers (4 bytes) for time & ids. I suggest trying something like this in your program:

uint32_t id1, id2,** timeMS; float** data;

// recover data

for (id1=0; id1<bins_elts; id1++)
{
for (id2=0; id2<nCrystalsTot; id2++)
{
fwrite((char*)(&timeMS[id1][id2]) , sizeof(uint32_t), 1, pFile);
fwrite((char*)(&data[id1][id2]) , sizeof(float), 1, pFile);
fwrite((char*)(&id1) , sizeof(uint32_t), 1, pFile);
fwrite((char*)(&id2) , sizeof(uint32_t), 1, pFile);
}
}

Besides, I am not sure why your datafile header states 188811 events, while I would expect 107928 events from your numbers (nb of projections * nb of pixels).

Best regards,

Thibaut

Hello,

It worked, thank you very much. I have one more question.

I created the files I am attaching. There is something wrong again. The reconstructed image is empty… All black…

Can you help me on this?

Many thanks,

Konstantinos

Στις 15-05-2017 18:24, tmerlin έγραψε:

header.Cdh (648 Bytes)

data.Cdf (1.65 MB)

Hi again,

Sorry about this. I am re-attaching the files. Something is wrong in the previous ones. Question still the same. What is wrong?

Kind Regards,

Konstantinos

Στις 15-05-2017 23:54, Konstantinos P. Chatzipapas, MSc έγραψε:

header.Cdh (649 Bytes)

data.Cdf (1.65 MB)

Hi Konstantinos,

Data values in your datafile appear to be very small, around 10^-44 (see attached, Float32). I think there is still something wrong in your conversion.

Best regards,

Thibaut