Which library contains a function to dump information of a file? in c, something similar to dcmdump

All other questions regarding DCMTK

Moderator: Moderator Team

Post Reply
Message
Author
ruben.cruz
Posts: 43
Joined: Fri, 2019-05-03, 15:06

Which library contains a function to dump information of a file? in c, something similar to dcmdump

#1 Post by ruben.cruz »

Hi,

We have been trying to finish a process in a workflow where we copy some files from one folder to the other.

When this process is finished we need to to create a file with a list of data about patient and the exam.
This data we can retrieve from any file, but since we are doing this in c++ we have been struggle to find the correct library with the function to do this.

Can you give us any tip? we know that there is the dcmdump (https://support.dcmtk.org/docs/dcmdump.html) but we need to find the correct function in C libraries.

Michael Onken
DCMTK Developer
Posts: 2048
Joined: Fri, 2004-11-05, 13:47
Location: Oldenburg, Germany
Contact:

Re: Which library contains a function to dump information of a file? in c, something similar to dcmdump

#2 Post by Michael Onken »

Hi,

there is no C but a C++ method that does the printing. It is called...print () :-) That's the method that is called by dcmdump (a good place to look for it, right? :idea: ). You can call print() on a DICOM file (DcmFileFormat) or any other class of the DCMTK dcmdata class hierarchy that is used to model items, sequences, elements and so on.

Best regards,
Michael

ruben.cruz
Posts: 43
Joined: Fri, 2019-05-03, 15:06

Re: Which library contains a function to dump information of a file? in c, something similar to dcmdump

#3 Post by ruben.cruz »

Hi,

Thank you for the print tip.
We now encounter an error probably on loading the file.

our code is something like this:

Code: Select all

				DcmDataset dataset;

				std::filebuf fb;
				fb.open("C:\\Users\\User\\Documents\\test.txt", std::ios::out);
				std::ostream os(&fb);

				OFString filename;
				
				//szFilePath is the correct path to the file 
				const OFFilename result = OFStandard::combineDirAndFilename(filename, "", szFilePath, true);
				
				dataset.loadFile(result);
				
				dataset.print(os);

				fb.close();
we get and error in our dataset

Code: Select all

0x00007ff7645b9c38 "I/O suspension or premature end of stream"
and file test has the follwing:

Code: Select all


# Dicom-Data-Set
# Used TransferSyntax: Little Endian Implicit
(0000,0000) UL (no value available)                     #   0, 0 CommandGroupLength
(0004,00c2) ?? (not loaded)                             # 131072, 1 Unknown Tag & Data
(047f,0481) ?? (not loaded)                             # 60228667, 1 Unknown Tag & Data
(4944,4d43) ?? 55\4c                                    #   2, 1 Unknown Tag & Data
any thing we are doing wrong?

Michael Onken
DCMTK Developer
Posts: 2048
Joined: Fri, 2004-11-05, 13:47
Location: Oldenburg, Germany
Contact:

Re: Which library contains a function to dump information of a file? in c, something similar to dcmdump

#4 Post by Michael Onken »

Hi,

I don't now std::filebuf, but can't you just do:

Code: Select all

OFFilename f = ":\\Users\\User\\Documents\\test.txt"; // or simply: OFString f = ...
OFCondition cond;
cond = dataset.loadFile(f);
if (cond.bad()) std::cerr << "Cannot load file " << f << ": " << cond.text() << std::endl;
Also your dataset looks kind of broken...but if it's a valid DICOM data structure (I have doubts) then DCMTK would read it.
The error you get could occur if for example the length of an element (like 60228667 in your dataset) is too large, i.e. if the parser tries to skip to that position, it skips 60228667 bytes forward but recognizes that the file itself is shorter than those 60228667 bytes.

Maybe first try parsing a file that you know is valid DICOM.

Best regards,
Michael

Jan Schlamelcher
OFFIS DICOM Team
OFFIS DICOM Team
Posts: 318
Joined: Mon, 2014-03-03, 09:51
Location: Oldenburg, Germany

Re: Which library contains a function to dump information of a file? in c, something similar to dcmdump

#5 Post by Jan Schlamelcher »

You're supposed to use DcmFileFormat on DICOM files and not DcmDataset directly. DcmFileFormat handles parsing the file meta header and then uses an appropriately configured DcmDataset to actually load it. Also, use OFpath to handle concatination of szFilePath and filename.

ruben.cruz
Posts: 43
Joined: Fri, 2019-05-03, 15:06

Re: Which library contains a function to dump information of a file? in c, something similar to dcmdump

#6 Post by ruben.cruz »

Hi,
Thank you both for your time and your answers.

Of course you were both correct. I believe i was missing something so i did .getDataset()

Code: Select all

DcmDataset* dset = NULL;
DcmFileFormat dataset;
*&dset = dataset.getDataset();

OFFilename f = szCopyPath;

OFCondition cond;
cond = dataset.loadFile(f);

std::ostringstream oss;
std::ostream& os = oss;

dataset.print(os);
From this i kind of got what we need.
I was trying to get the .print() into an array but i don't have the knowledge to do it so i just made that a into a string and work from there.

Thank you again.

Post Reply

Who is online

Users browsing this forum: Google [Bot] and 1 guest