]> Creatis software - gdcm.git/blob - gdcmPython/demo/PrintHeader.py
52a1ae587732cf797ec0db11526389ed17547698
[gdcm.git] / gdcmPython / demo / PrintHeader.py
1 from gdcmPython import *
2 import sys
3
4 ### Get filename from command line or default it
5 try:
6    FileName = sys.argv[1]
7 except IndexError:
8    FileName = os.path.join(GDCM_DATA_PATH, "test.acr")
9
10 try:
11    printLevel = int(sys.argv[2])
12 except IndexError:
13    printLevel = 1
14
15 #if not os.path.isfile(FileName):
16 #   print "Cannot open file ", FileName
17 #   sys.exit()
18
19 # On debugging purposes uncomment the next line
20 #s = raw_input("Hit any key in this window to exit")
21
22 ### Build the header element list
23 toRead = gdcmHeader(FileName)
24 if not toRead.IsReadable():
25    print "The ", FileName, " file is not readable with gdcm. Sorry."
26    sys.exit()
27
28 print "##############################################################"
29 print "### Display all the elements and their respective values"
30 print "## found in the ", FileName, " file."
31 print "##############################################################"
32 ###toRead.SetPrintLevel(printLevel)
33 ###toRead.Print()
34
35 ValDict = toRead.GetEntry()
36 for key in ValDict.keys():
37         print "[%s] = [%s]" %(key, ValDict[key])
38