import sys import os sys.path.append('${GDCM_BINARY_DIR}') if os.name == 'posix': sys.path.append('${GDCM_BINARY_DIR}/bin') else: sys.path.append('${GDCM_BINARY_DIR}/bin/Release') sys.path.append('${GDCM_BINARY_DIR}/bin/Debug') from gdcmPython.core import * ### Get filename from command line or default it try: fileName = sys.argv[1] except IndexError: fileName = os.path.join(GDCM_DATA_ROOT, "test.acr") try: printLevel = int(sys.argv[2]) except IndexError: printLevel = 1 ### Build the file element list print fileName, type(fileName) file = gdcm.File(fileName) if not file.IsReadable(): raise RuntimeError,"The '%s' file is not readable with gdcm." % fileName print "##############################################################" print "### Display all the elements and their respective values" print "## found in the ", fileName, " file." print "##############################################################" val=file.GetFirstEntry() while(val): val.Print() print "" val=file.GetNextEntry() val=None print "##############################################################" val=file.GetFirstEntry() while(val): if(isinstance(val,gdcm.ValEntryPtr)): print "Val %04d|%04d [%s] : %s" % (val.GetGroup(),val.GetElement(), val.GetName(),val.GetValue()) else: print "Bin %04d|%04d [%s] : %s" % (val.GetGroup(),val.GetElement(), val.GetName(),val.GetValue()) val=file.GetNextEntry() val=None