]> Creatis software - gdcm.git/blob - gdcmPython/demo/PrintFile.py.in
* Builder/ : add possibility to build an installer on Windows using InnoSetup
[gdcm.git] / gdcmPython / demo / PrintFile.py.in
1 import sys
2 import os.path
3 from gdcmConfigDemo import *
4 from gdcmPython.core import *
5
6 def PrintUse():
7    print ""
8    print "Use :"
9    print "-----"
10    print "%s <fileName>" % sys.argv[0]
11    print "   fileName : path to the DICOM file to parse"
12    print ""
13    print ""
14
15 ### Get filename from command line or default it
16 try:
17    fileName = sys.argv[1]
18 except IndexError:
19    fileName = os.path.join(GDCM_DATA_ROOT, "test.acr")
20    if( not os.path.isfile(fileName) ):
21       fileName=os.path.join(os.path.split(sys.argv[0])[0],"test.acr")
22
23 try:
24    printLevel = int(sys.argv[2])
25 except IndexError:
26    printLevel = 1
27
28 ### Build the file element list
29 file = gdcm.File(fileName)
30 if not file.IsReadable():
31    PrintUse()
32    raise RuntimeError,"The '%s' file is not readable with gdcm." % fileName
33
34 print "File -->",fileName
35 print "##############################################################"
36 print "### Display all the elements and their respective values"
37 print "## found in the ", fileName, " file."
38 print "##############################################################"
39
40 val=file.GetFirstEntry()
41 while(val):
42    val.Print()
43    print ""
44    val=file.GetNextEntry()
45 val=None
46
47 print "##############################################################"
48 val=file.GetFirstEntry()
49 while(val):
50    if(isinstance(val,gdcm.ValEntryPtr)):
51       print "Val %04d|%04d [%s] : %s" % (val.GetGroup(),val.GetElement(),
52                                          val.GetName(),val.GetValue())
53    else:
54       print "Bin %04d|%04d [%s] : %s" % (val.GetGroup(),val.GetElement(),
55                                          val.GetName(),val.GetValue())
56    val=file.GetNextEntry()
57 val=None
58