#!/usr/bin/env python
''' Tiny script to write 4D files in any format that we read (nifti,
analyze, MINC, at the moment, as nifti 3D files '''

import os
import sys

import nipy.io.imageformats as nii


if __name__ == '__main__':
    try:
        fname = sys.argv[1]
    except IndexError:
        raise OSError('Expecting 4d image filename')
    img = nii.load(fname)
    imgs = nii.four_to_three(img)
    froot, ext = os.path.splitext(fname)
    if ext in ('.gz', '.bz2'):
        froot, ext = os.path.splitext(froot)
    for i, img3d in enumerate(imgs):
        fname3d = '%s_%04d.nii' % (froot, i)
        nii.save(img3d, fname3d)
        

@@ -151,19 +151,51 @@
  os%0A
+%0A
 import 
-sys%0A
+nipy.externals.argparse as argparse
 %0Aimp
@@ -232,146 +232,261 @@
 i%0A%0A%0A
-if __name__ == '__
+def 
 main
-__'
+()
 :%0A    
-try:%0A        fname = sys.argv%5B1%5D%0A    except IndexError:%0A        raise OSError('Expecting 4d image filename'
+# create the parser%0A    parser = argparse.ArgumentParser()%0A    # add the arguments%0A    parser.add_argument('filename', type=str,%0A                        help='4D image filename')%0A    # parse the command line%0A    args = parser.parse_args(
 )%0A  
@@ -502,17 +502,25 @@
 ii.load(
-f
+args.file
 name)%0A  
@@ -585,17 +585,25 @@
 plitext(
-f
+args.file
 name)%0A  
@@ -791,16 +791,57 @@
 name3d)%0A
+%0A%0Aif __name__ == '__main__':%0A    main()%0A%0A
         

Use argparse for 4D to 3D