E: DcmFileFormat: Cannot determine Version of MetaHeader

All other questions regarding DCMTK

Moderator: Moderator Team

Post Reply
Message
Author
ajonesfl
Posts: 9
Joined: Wed, 2017-09-13, 13:29

E: DcmFileFormat: Cannot determine Version of MetaHeader

#1 Post by ajonesfl »

I wrote a small test program and I keep getting the error listed in the subject. Here is the code below. I took this from the dcmtk documentation website, but I get the error. Lots of searching on the web has not pointed me in the right direction. Any help would be appreciated. Here is the code:

char uid[100];
DcmFileFormat fileFormat;
DcmDataset *dataset = fileFormat.getDataset(); dataset->putAndInsertUint16(DCM_FileMetaInformationVersion, 0x0001);
dataset->putAndInsertString(DCM_SOPClassUID, UID_SecondaryCaptureImageStorage);
dataset->putAndInsertString(DCM_SOPInstanceUID, dcmGenerateUniqueIdentifier(uid, SITE_INSTANCE_UID_ROOT));
dataset->putAndInsertString(DCM_PatientName, "Doe^John");

OFCondition status = fileFormat.saveFile("./test.dcm", EXS_LittleEndianExplicit);
if (status.bad())
cerr << "Error: cannot write DICOM file (" << status.text() << ")" << endl;

No error prints out either. The status appears to be good. I only get the message listed in the subject.

J. Riesmeier
DCMTK Developer
Posts: 2501
Joined: Tue, 2011-05-03, 14:38
Location: Oldenburg, Germany
Contact:

Re: E: DcmFileFormat: Cannot determine Version of MetaHeader

#2 Post by J. Riesmeier »

See my answer in the newsgroups (please avoid double postings!).

ajonesfl
Posts: 9
Joined: Wed, 2017-09-13, 13:29

Re: E: DcmFileFormat: Cannot determine Version of MetaHeader

#3 Post by ajonesfl »

I removed the dataset->putAndInsertUint16(DCM_FileMetaInformationVersion, 0x0001) line from the code. The new program is below. But I still get the same error.

uid[100];
DcmFileFormat fileFormat;
DcmDataset *dataset = fileFormat.getDataset();


dataset->putAndInsertString(DCM_SOPClassUID, UID_SecondaryCaptureImageStorage);
dataset->putAndInsertString(DCM_SOPInstanceUID, dcmGenerateUniqueIdentifier(uid, SITE_INSTANCE_UID_ROOT));
dataset->putAndInsertString(DCM_PatientName, "Doe^John");


OFCondition status = fileFormat.saveFile("./test.dcm", EXS_LittleEndianImplicit);

if (status.bad())
cerr << "Error: cannot write DICOM file (" << status.text() << ")" << endl;


After running the code above, I still get the following:

E: DcmFileFormat: Cannot determine Version of MetaHeader

NOTE: I will not post in both areas. I will only post dcmtk postings here. I am using dcmtk-3.6.2.
Thanks in Advance

J. Riesmeier
DCMTK Developer
Posts: 2501
Joined: Tue, 2011-05-03, 14:38
Location: Oldenburg, Germany
Contact:

Re: E: DcmFileFormat: Cannot determine Version of MetaHeader

#4 Post by J. Riesmeier »

Are you sure that the data dictionary is loaded? What does dcmDataDict.isDictionaryLoaded() return? What do the various calls to putAndInsertString() return?

ajonesfl
Posts: 9
Joined: Wed, 2017-09-13, 13:29

Re: E: DcmFileFormat: Cannot determine Version of MetaHeader

#5 Post by ajonesfl »

Is there a very simple example you can point me to in order to save a file. I found a very simple explain to load a file (https://github.com/marcinwol/dcmtk-basic-example).

Thanks in advance.

J. Riesmeier
DCMTK Developer
Posts: 2501
Joined: Tue, 2011-05-03, 14:38
Location: Oldenburg, Germany
Contact:

Re: E: DcmFileFormat: Cannot determine Version of MetaHeader

#6 Post by J. Riesmeier »

I tested your code. It works (if the data dictionary "dicom.dic" is loaded correctly).

ajonesfl
Posts: 9
Joined: Wed, 2017-09-13, 13:29

Re: E: DcmFileFormat: Cannot determine Version of MetaHeader

#7 Post by ajonesfl »

I found code to load the dicom.dic. That appears to have taken care of the issue:

DcmDataDictionary &dict = dcmDataDict.wrlock();
dict.loadDictionary("/home/Project/dcmtk/dcmtk-3.6.2/dcmdata/data/dicom.dic");
dcmDataDict.unlock();

I no longer get that error in the subject line. Thanks!

J. Riesmeier
DCMTK Developer
Posts: 2501
Joined: Tue, 2011-05-03, 14:38
Location: Oldenburg, Germany
Contact:

Re: E: DcmFileFormat: Cannot determine Version of MetaHeader

#8 Post by J. Riesmeier »

Great, but usually there is no need to load the data dictionary manually. By default (on Unix systems), it is loaded from the installed directory as specified by the "configure --prefix" option. Alternatively, one can specify the environment variable DCMDICTPATH or activate the built-in dictionary (which is also the default on Windows systems). All this is also described (in detail) in the corresponding documentation file.

ajonesfl
Posts: 9
Joined: Wed, 2017-09-13, 13:29

Re: E: DcmFileFormat: Cannot determine Version of MetaHeader

#9 Post by ajonesfl »

Thanks! But removing that code causes those errors. So with my install, I must not have set something up so dicom.dic is loaded automatically. I am on a Linux Posix system using cmake to install dcmtk. DCMTK_ENABLE_BUILTIN_DICTIONARY I set to BOOL=ON in the CMakeCache.txt file, and set DCMTK_ENABLE_EXTERNAL_DICTIONARY BOOL=OFF. Is that the correct thing to do? Or is there some other place to set these. My understanding is that CMakeCache.txt can get overwritten.

With this new build and libs installed it is working correctly now. Only issue is, if I put the changes listed above in the correct file, or is there a place to tell the system about the dicom.dic file. Any Thoughts?

J. Riesmeier
DCMTK Developer
Posts: 2501
Joined: Tue, 2011-05-03, 14:38
Location: Oldenburg, Germany
Contact:

Re: E: DcmFileFormat: Cannot determine Version of MetaHeader

#10 Post by J. Riesmeier »

You shouldn't modify the CMakeCache.txt file manually but set the corresponding option within "ccmake" or when calling "cmake".
With this new build and libs installed it is working correctly now. Only issue is, if I put the changes listed above in the correct file, or is there a place to tell the system about the dicom.dic file.
Not sure what you mean by that.

ajonesfl
Posts: 9
Joined: Wed, 2017-09-13, 13:29

Re: E: DcmFileFormat: Cannot determine Version of MetaHeader

#11 Post by ajonesfl »

I have it working correctly without having to load the dicom.dic in code. It loads automatically now. I made changes to the CMakeCache.txt file in order for the build to include the dicom.dic file and load it automatically. I set the following values in the file:

DCMTK_ENABLE_BUILTIN_DICTIONARY BOOL=ON
DCMTK_ENABLE_EXTERNAL_DICTIONARY BOOL=OFF

You are saying not to do it in CMakeCache.txt, but use cmake or ccmake for those two values. Once I figure out how to do that, I will post for others to see, or if you have an example to do it with either cmake or ccmake that would be appreciated.

ajonesfl
Posts: 9
Joined: Wed, 2017-09-13, 13:29

Re: E: DcmFileFormat: Cannot determine Version of MetaHeader

#12 Post by ajonesfl »

Figured it out. You have to do the following:

cmake -DDCMTK_ENABLE_BUILTIN_DICTIONARY=ON -DDCMTK_ENABLE_EXTERNAL_DICTIONARY=OFF ../dcmtk-3.6.2

I hope this can help others who run into this.

Post Reply

Who is online

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