]> Creatis software - gdcm.git/blob - gdcmPython/demo/PrintFile.py.in
* bug fix in the Python demos, due to the recent changes
[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()
30 file.SetFileName(fileName)
31 file.Load()
32 if not file.IsReadable():
33    PrintUse()
34    raise RuntimeError,"The '%s' file is not readable with gdcm." % fileName
35
36 print "File -->",fileName
37 print "##############################################################"
38 print "### Display all the elements and their respective values"
39 print "## found in the ", fileName, " file."
40 print "##############################################################"
41
42 val=file.GetFirstEntry()
43 while(val):
44    val.Print()
45    print ""
46    val=file.GetNextEntry()
47 val=None
48
49 print "##############################################################"
50 val=file.GetFirstEntry()
51 while(val):
52    if(isinstance(val,gdcm.DataEntryPtr)):
53       print "Data %s [%s] [%s] : %s" % (val.GetKey().str(),val.GetVR().str(),
54                                         val.GetName(),val.GetString())
55    val=file.GetNextEntry()
56 val=None
57