1 /*=========================================================================
4 Module: $RCSfile: MakeDicomDir.cxx,v $
6 Date: $Date: 2007/09/28 14:09:20 $
7 Version: $Revision: 1.25 $
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"
25 //#include <sys/times.h> // Linux Only
30 * \brief Explores recursively the given directory
31 * orders the gdcm-readable found Files
32 * according their Patient/Study/Serie/Image characteristics
33 * makes the gdcmDicomDir
34 * and writes a file named DICOMDIR. (user may choose an other name)
37 int main(int argc, char *argv[])
40 " \n MakeDicomDir :\n ",
41 " Explores recursively the given directory, makes the relevant DICOMDIR ",
42 " and writes it as 'DICOMDIR' ",
44 " usage: MakeDicomDir dirname=rootDirectoryName ",
45 " name=DICOMDIR file name ",
46 " [noshadowseq][noshadow][noseq] [debug] [check] ",
48 " name : the default name for the generated dicomdir is 'DICOMDIR' ",
49 " noshadowseq: user doesn't want to load Private Sequences ",
50 " noshadow : user doesn't want to load Private groups (odd number) ",
51 " noseq : user doesn't want to load Sequences ",
52 " debug : developper wants to run the program in 'debug mode' ",
53 " check : the dicomdir is checked as 'gdcm readable' ",
56 // ----- Initialize Arguments Manager ------
57 GDCM_NAME_SPACE::ArgMgr *am = new GDCM_NAME_SPACE::ArgMgr(argc, argv);
59 if (argc == 1 || am->ArgMgrDefined("usage"))
61 am->ArgMgrUsage(usage); // Display 'usage'
67 dirName = am->ArgMgrGetString("dirName",".");
70 name = am->ArgMgrGetString("name","DICOMDIR");
72 int loadMode = GDCM_NAME_SPACE::LD_ALL;
73 if ( am->ArgMgrDefined("noshadowseq") )
74 loadMode |= GDCM_NAME_SPACE::LD_NOSHADOWSEQ;
77 if ( am->ArgMgrDefined("noshadow") )
78 loadMode |= GDCM_NAME_SPACE::LD_NOSHADOW;
79 if ( am->ArgMgrDefined("noseq") )
80 loadMode |= GDCM_NAME_SPACE::LD_NOSEQ;
83 if (am->ArgMgrDefined("debug"))
84 GDCM_NAME_SPACE::Debug::DebugOn();
86 int check = am->ArgMgrDefined("check");
88 // if unused Param we give up
89 if ( am->ArgMgrPrintUnusedLabels() )
91 am->ArgMgrUsage(usage);
96 delete am; // we don't need Argument Manager any longer
98 // ----- Begin Processing -----
100 GDCM_NAME_SPACE::DicomDir *dcmdir;
102 // we ask for Directory parsing
104 dcmdir = GDCM_NAME_SPACE::DicomDir::New( );
106 dcmdir->SetLoadMode(loadMode);
107 dcmdir->SetDirectoryName(dirName);
108 //dcmdir->SetParseDir(true);
110 // struct tms tms1, tms2; // Time measurements
113 dcmdir->Load(); // Reads all the files and creates the GDCM_NAME_SPACE::DicomDir
117 // << (long) ((tms2.tms_utime) - (tms1.tms_utime))
120 if ( GDCM_NAME_SPACE::Debug::GetDebugFlag() )
121 std::cout << "======================= End Parsing Directory" << std::endl;
123 // ----- Check the result
125 if ( !dcmdir->GetFirstPatient() )
127 std::cout << "makeDicomDir: no patient found. Exiting."
133 // ----- Writes the corresponding DICOMDIR file (from the GDCM_NAME_SPACE::DicomDir)
140 if ( GDCM_NAME_SPACE::Debug::GetDebugFlag() )
141 std::cout << "======================= End Writting DICOMDIR"
144 // Read from disc the just written DicomDir
146 GDCM_NAME_SPACE::DicomDir *newDicomDir = GDCM_NAME_SPACE::DicomDir::New();
147 newDicomDir->SetFileName( name );
149 if ( GDCM_NAME_SPACE::Debug::GetDebugFlag() )
150 std::cout << "======================= End Parsing DICOMDIR"
152 if( !newDicomDir->IsReadable() )
154 std::cout<<" Written DicomDir [" << name << "] "
155 <<" is not readable"<<std::endl
156 <<" ...Failed"<<std::endl;
158 newDicomDir->Delete();
162 if( !newDicomDir->GetFirstPatient() )
164 std::cout <<" Written DicomDir [" << name << "] "
165 <<" has no patient"<<std::endl
166 <<" ...Failed"<<std::endl;
168 newDicomDir->Delete();
171 std::cout<<std::flush;
172 newDicomDir->Delete();