1 /*=========================================================================
4 Module: $RCSfile: MakeDicomDir.cxx,v $
6 Date: $Date: 2006/01/10 16:10:02 $
7 Version: $Revision: 1.18 $
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 =========================================================================*/
18 #include "gdcmDocEntry.h"
19 #include "gdcmDicomDir.h"
20 #include "gdcmDicomDirPatient.h"
21 #include "gdcmDirList.h"
22 #include "gdcmDebug.h"
23 #include "gdcmArgMgr.h"
28 * \brief Explores recursively the given directory
29 * orders the gdcm-readable found Files
30 * according their Patient/Study/Serie/Image characteristics
31 * makes the gdcmDicomDir
32 * and writes a file named NewDICOMDIR..
35 int main(int argc, char *argv[])
38 " \n MakeDicomDir :\n ",
39 " Explores recursively the given directory, makes the relevant DICOMDIR ",
40 " and writes it as 'NewDICOMDIR' ",
42 " usage: MakeDicomDir dirname=rootDirectoryName ",
43 " [noshadowseq][noshadow][noseq] [debug] ",
45 " noshadowseq: user doesn't want to load Private Sequences ",
46 " noshadow : user doesn't want to load Private groups (odd number) ",
47 " noseq : user doesn't want to load Sequences ",
48 " debug : user wants to run the program in 'debug mode' ",
51 // ----- Initialize Arguments Manager ------
52 gdcm::ArgMgr *am = new gdcm::ArgMgr(argc, argv);
54 if (argc == 1 || am->ArgMgrDefined("usage"))
56 am->ArgMgrUsage(usage); // Display 'usage'
62 dirName = am->ArgMgrGetString("dirName",(char *)".");
64 int loadMode = gdcm::LD_ALL;
65 if ( am->ArgMgrDefined("noshadowseq") )
66 loadMode |= gdcm::LD_NOSHADOWSEQ;
69 if ( am->ArgMgrDefined("noshadow") )
70 loadMode |= gdcm::LD_NOSHADOW;
71 if ( am->ArgMgrDefined("noseq") )
72 loadMode |= gdcm::LD_NOSEQ;
75 if (am->ArgMgrDefined("debug"))
76 gdcm::Debug::DebugOn();
78 // if unused Param we give up
79 if ( am->ArgMgrPrintUnusedLabels() )
81 am->ArgMgrUsage(usage);
86 delete am; // we don't need Argument Manager any longer
88 // ----- Begin Processing -----
90 gdcm::DicomDir *dcmdir;
92 // we ask for Directory parsing
94 dcmdir = gdcm::DicomDir::New( );
96 dcmdir->SetLoadMode(loadMode);
97 dcmdir->SetDirectoryName(dirName);
98 //dcmdir->SetParseDir(true);
101 if ( gdcm::Debug::GetDebugFlag() )
102 std::cout << "======================= End Parsing Directory" << std::endl;
104 // ----- Check the result
106 if ( !dcmdir->GetFirstPatient() )
108 std::cout << "makeDicomDir: no patient found. Exiting."
114 // ----- Create the corresponding DicomDir
116 dcmdir->Write("NewDICOMDIR");
118 if ( gdcm::Debug::GetDebugFlag() )
119 std::cout << "======================= End Writting DICOMDIR" << std::endl;
121 // Read from disc the just written DicomDir
122 gdcm::DicomDir *newDicomDir = gdcm::DicomDir::New();
123 newDicomDir->SetFileName( "NewDICOMDIR" );
125 if ( gdcm::Debug::GetDebugFlag() )
126 std::cout << "======================= End Parsing DICOMDIR" << std::endl;
127 if( !newDicomDir->IsReadable() )
129 std::cout<<" Written DicomDir 'NewDICOMDIR'"
130 <<" is not readable"<<std::endl
131 <<" ...Failed"<<std::endl;
133 newDicomDir->Delete();
137 if( !newDicomDir->GetFirstPatient() )
139 std::cout<<" Written DicomDir 'NewDICOMDIR'"
140 <<" has no patient"<<std::endl
141 <<" ...Failed"<<std::endl;
143 newDicomDir->Delete();
147 std::cout<<std::flush;
149 newDicomDir->Delete();