]> Creatis software - gdcm.git/blob - gdcmPython/demo/PrintFile.py.in
Fix mistypings
[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 try:
16    print gdcm.DataEntry
17    print gdcm.DataEntryPtr
18 except:
19    pass
20
21 ### Get filename from command line or default it
22 try:
23    fileName = sys.argv[1]
24 except IndexError:
25    fileName = os.path.join(GDCM_DATA_ROOT, "test.acr")
26    if( not os.path.isfile(fileName) ):
27       fileName=os.path.join(os.path.split(sys.argv[0])[0],"test.acr")
28
29 try:
30    printLevel = int(sys.argv[2])
31 except IndexError:
32    printLevel = 1
33
34 ### Build the file element list
35 file = gdcm.File.New()
36 file.SetFileName(fileName)
37 file.Load()
38 if not file.IsReadable():
39    PrintUse()
40    raise RuntimeError,"The '%s' file is not readable with gdcm." % fileName
41
42 print "File -->",fileName
43 print "##############################################################"
44 print "### Display all the elements and their respective values"
45 print "## found in the ", fileName, " file."
46 print "##############################################################"
47
48 val=file.GetFirstEntry()
49 while(val):
50    val.Print()
51    print ""
52    val=file.GetNextEntry()
53 val=None
54
55 print "##############################################################"
56 val=file.GetFirstEntry()
57 while(val):
58    if(isinstance(val,gdcm.DataEntry)):
59       print "Data %s [%s] [%s] : %s" % (val.GetKey().str(),val.GetVR().str(),
60                                         val.GetName(),val.GetString())
61    val=file.GetNextEntry()
62 val=None
63