1 /*=========================================================================
4 Module: $RCSfile: exExtractTag.cxx,v $
6 Date: $Date: 2005/10/18 08:35:44 $
7 Version: $Revision: 1.2 $
9 Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
10 l'Image). All rights reserved. See Doc/License.txt or
11 http://www.creatis.insa-lyon.fr/Public/Gdcm/License.html for details.
13 This software is distributed WITHOUT ANY WARRANTY; without even
14 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 PURPOSE. See the above copyright notices for more information.
17 =========================================================================*/
19 #include "gdcmFileHelper.h"
20 #include "gdcmCommon.h"
21 #include "gdcmDebug.h"
22 #include "gdcmDocEntry.h"
23 #include "gdcmDataEntry.h"
27 int main(int argc, char *argv[])
33 std::cerr << "Usage :" << argv[0] << " input.dcm group element outputfile" << std::endl;
34 std::cerr << " Ex: " << argv[0] << " /tmp/bla.dcm 0029 2110 /tmp/out.raw" << std::endl;
37 std::string fileName = argv[1];
39 std::cout << fileName << std::endl;
40 // ============================================================
41 // Read the input image.
42 // ============================================================
44 f = new gdcm::File( );
46 //f->SetLoadMode(gdcm::LD_NOSEQ | gdcm::LD_NOSHADOW);
47 f->SetFileName( fileName );
50 if( gdcm::Debug::GetDebugFlag() )
52 std::cout << "---------------------------------------------" << std::endl;
54 std::cout << "---------------------------------------------" << std::endl;
57 std::cerr << "Sorry, " << fileName << " not a gdcm-readable "
63 std::cout << " ... is readable " << std::endl;
65 // Find the dicom tag, and extract the string
67 std::istringstream convert;
68 convert.str( argv[2] );
69 convert >> std::hex >> group;
70 convert.clear(); //important
71 convert.str( argv[3] );
72 convert >> std::hex >> elem;
73 std::cout << "Extracting tag: (0x" << std::hex << std::setw(4) << std::setfill('0')
74 << group << ",0x" << std::setw(4) << std::setfill('0') << elem << ")" << std::endl;
75 std::string dicom_tag_value = f->GetEntryString(group, elem);
76 if (dicom_tag_value == gdcm::GDCM_UNFOUND)
78 gdcm::DictEntry *dictEntry = f->GetPubDict()->GetEntry( group, elem);
79 std::cerr << "Image doesn't contain any tag: " << dictEntry->GetName() << std::endl;
84 gdcm::DocEntry *dicom_tag_doc = f->GetDocEntry(group, elem);
85 gdcm::DataEntry *dicom_tag = dynamic_cast<gdcm::DataEntry *>(dicom_tag_doc);
88 std::cerr << "Sorry DataEntry only please" << std::endl;
93 // Write out the data as a file:
94 std::ofstream o(argv[4]);
97 std::cerr << "Problem opening file: " << argv[4] << std::endl;
101 o.write((char*)dicom_tag->GetBinArea(), dicom_tag->GetLength());