[MINC-users] Adding to minc history

Andrew Janke a.janke at gmail.com
Thu Feb 14 15:00:44 EST 2013


Hi Jon,

> I'd like to be able to add entries to the history attribute of a minc file
> so that I can record provenance when I process files with the various
> scripts I've written up. I know many of the minc tools do this
> automatically, but I also want my shell and python scripts to do this as
> well.

Good plan!  I endeavour to do this with all scripts I write. Note that
you sometime also need to add history to xfm files and tag files.

> Is there an already baked tool for this?  I imagine it would be easy to
> roll something on my own by modifying the HDF headers, but I'd rather use
> something that has had some field testing.

There is no pre-baked tool if only because what you want to add
changes from script to script. Or at least this is what I have found.
In perl, the bit(s) of code I use are like this:


$me = &basename($0);

# get history string
chomp($history = `date`);
$history .= '>>>> ' . join(' ', $me, @ARGV) . "\n";

# add the history string to the output file
&do_cmd('minc_modify_header',
   '-sappend', ":history='$history'",
   $outfile);


sub do_cmd {
   print STDOUT "@_\n" if $opt{'verbose'};
   if(!$opt{'fake'}){
      system(@_) == 0 or die;
      }
   }

---

Note that in order to get the history string you must put the first
bits of code before you do any argument processing.

A code example can be found here:

   http://packages.bic.mni.mcgill.ca/scripts/volflip


a


More information about the MINC-users mailing list