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