+2003-03-27 Eric Boix <Eric.Boix@creatis.insa-lyon.fr>
+      * setup.py fixed for un*x (needed macro for stdint.h)
+      * Test/test.cxx renamed to PrintHeader.cxx to avoid collision on
+        un*ces with sh-utils test utility.
+      * gdcmPython/demo/test.py renamed to PrintHeader.py
+      * gdcmPython/demo/ReorganiseFiles.py new demo script added.
+
 2003-03-26 Eric Boix <Eric.Boix@creatis.insa-lyon.fr>
       * src/gdcmHeader[h, cxx] gdcmHeader now has an IsReadable predicate.
       * gdcmPython/demo/test.py changed accordingly.
 
--- /dev/null
+# Rename the dcm extension files of a given drectory according
+# to series and image number information extracted in each respective header.
+
+from gdcmPython import *
+import glob
+import os
+import sys
+
+def PrintUsage():
+   print "Usage: python ReorganiseFiles.py <SourceDirectory>"
+   print "       <SourceDirectory> is the directory containing the source"
+   print "                         images (defaulted to invocation directory."
+
+def Warning(DirName):
+   print "Warning: this script will rename files in the"
+   print "        ", DirName, " directory."
+   a = raw_input("Proceed ?[y/n]")
+   if a != "y":
+      sys.exit()
+
+try:
+   SourceDirectory = sys.argv[1]
+except IndexError:
+   SourceDirectory = os.getcwd()
+
+if not os.path.isdir(SourceDirectory):
+   PrintUsage
+Warning(SourceDirectory)
+SourceFiles=glob.glob(os.path.join(SourceDirectory, "*.dcm"))
+
+for file in SourceFiles:
+   header = gdcmHeader(file)
+   info = header.GetPubElVal()
+   try:
+      ImNum = info["Image Number"]
+      if len(ImNum) == 0 or ImNum == "gdcm::Unfound":
+         raise KeyError
+   except KeyError:
+      print "Skipped file ", file, " (unfound Image Number tag)."
+      continue
+   try:
+      SeNum = info["Series Number"]
+      if len(SeNum) == 0 or SeNum == "gdcm::Unfound":
+         raise KeyError
+   except KeyError:
+      print "Skipped file ", file, " (unfound Series Number tag)."
+      continue
+   DestFile = "image_%02d_%04d.dcm"
+   DestFile %= (int(info["Image Number"]), int(info["Series Number"]))
+   DestFile = os.path.join(SourceDirectory, DestFile)
+   # necessary to close the file descriptor to enable further rename.
+   del header
+   if os.path.isfile(DestFile):
+      print "Skipped file ", file, " (allready existing destination"
+      print "     file ", DestFile
+      continue
+   os.rename(file, DestFile)
 
 # Due to a disutil oddity on Unices : see
 # http://aspn.activestate.com/ASPN/Mail/Message/distutils-sig/588325
 if(os.name=='posix'):
-       targetDir=os.path.join('lib','python'+sys.version[:3],'site-packages')
-       libraries=["stdc++"]
+   targetDir=os.path.join('lib','python'+sys.version[:3],'site-packages')
+   libraries=["stdc++"]
+   macros   =[('__STDC_LIMIT_MACROS', '1')]
 else:
-       targetDir=os.path.join('lib','site-packages')
-       libraries=["WSOCK32"]
+   targetDir=os.path.join('lib','site-packages')
+   libraries=["WSOCK32"]
+   macros   =[]
 
 targetDir=os.path.join(targetDir, ThisModule)
 
                    sources=Sources,
                    include_dirs=[gdcmSrcDir],
                    libraries=libraries,
+                   define_macros=macros,
                    swig_cpp=1,
                    swig_include=[ gdcmSrcDir] ) ],
       data_files=[(os.path.join(targetDir,"Data"),