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