1 /*=========================================================================
4 Module: $RCSfile: toBrainVisa.cxx,v $
6 Date: $Date: 2007/09/13 12:48:37 $
7 Version: $Revision: 1.3 $
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 "gdcmDocument.h"
21 #include "gdcmDataEntry.h"
22 #include "gdcmArgMgr.h"
25 " \n toBrainVisa :\n ",
26 " Extracts user supplied tags (identified by group number-element number)",
27 " and writes their values in a text file. ",
28 " (file will be used as input by BrainVisa software ) ",
30 " toBrainVisa filein=inputFileName (a DICOM file) ",
31 " fileoutout=outputFileName ",
32 " tags= list of tags to process ",
33 " [verbose] [debug] ",
35 " e.g. : tags=0020-0052,0008-0021,0018-1030 (no space!) ",
36 " dirout : will be created (as a text file) if doesn't exist ",
37 " verbose : user wants to run the program in 'verbose mode' ",
38 " debug : *developer* wants to run the program in 'debug mode' ",
41 int main (int argc , char *argv[])
43 // ============== Initialize Arguments Manager =============================
45 GDCM_NAME_SPACE::ArgMgr *am = new GDCM_NAME_SPACE::ArgMgr(argc, argv);
47 if (argc == 1 || am->ArgMgrDefined("usage"))
49 am->ArgMgrUsage(usage); // Display 'usage'
55 filein = am->ArgMgrGetString("filein",".");
58 fileout = am->ArgMgrGetString("fileout",".");
60 int verbose = am->ArgMgrDefined("verbose");
63 uint16_t *tags = am->ArgMgrGetXInt16Enum("tags", &nbTags);
65 // if unused Param we give up
66 if ( am->ArgMgrPrintUnusedLabels() )
68 am->ArgMgrUsage(usage);
72 delete am; // we don't need Argument Manager any longer
74 // ==================== Begin Processing =====================================
77 fp=fopen(fileout, "w");
80 std::cout << "Failed to open [" << fileout << "] for writting" << std::endl;
83 GDCM_NAME_SPACE::File *f = GDCM_NAME_SPACE::File::New();
84 f->SetLoadMode( GDCM_NAME_SPACE::LD_ALL);
85 f->SetFileName( filein );
90 std::cout << "Sorry, [" << filein << "] not a gdcm-readable "
97 std::cout << "[" << filein << "] is readable " << std::endl;
99 for(int i=0; i<nbTags; i++)
101 std::string toto = f->GetEntryString(tags[2*i], tags[2*i+1]);
102 fprintf(fp, "%s\n", toto.c_str() );
104 std::cout << "[" << toto << "]" << std::endl;