4

I'm using matlab to write figures as eps files for use in LaTeX, using:

print( '-depsc', 'filename.eps');

and I'm keeping those eps files in version control. As I'm generating a lot of figures at once, but only changing one or two of them, often the only change in a particular eps file is:

-%%CreationDate: 06/29/2011  17:52:57
+%%CreationDate: 06/30/2011  19:18:03

which isn't valuable information. Is there a way to stop matlab from writing the CreationDate?

Dirty solutions encouraged...

Alex
  • 5,863
  • 2
  • 29
  • 46
  • You could write a script for overwriting the line of `CreationDate` after the file is created, which IS dirty - but isn't that information is useful? Isn't it better to just skip the creation of the files that haven't changed? – Itamar Katz Jun 30 '11 at 09:09
  • The useful information is that the file is different, which the version control will pick up on, not that it has a new creation time. I could avoid recreating the files that don't change, but not as easily as fixing this, if fixing this is easy. – Alex Jun 30 '11 at 10:12
  • 1
    So, as I said, you can use any conventional tool in order to discard (or change) that line from the output file. If you are using Linux, it can be as easy (and dirty) as `cat input.eps | sed -e '4d' > output.eps` (writing to output.eps all but line #4), or any other shell commands, depending on your platform. You can of course as well do it from within Matlab, using file I/O to read the input file and write it without the problematic line. – Itamar Katz Jun 30 '11 at 12:04

1 Answers1

4

One solution is to remove that line altogether, and rely on the file system to keep track of creation/modification date. This can be done in a lot of ways using common shell tools:

# sed
sed -i file.eps '/^%%CreationDate: /d'

or

# grep
grep -v '^%%CreationDate: ' file.eps > tmp && mv tmp file.eps

If you are on a Windows machine, MATLAB should have a Perl interpreter included:

# perl
perl -i -ne 'print if not /^%%CreationDate: /' file.eps

From inside MATLAB, you can maybe do the following to call a one-line Perl program:

%# construct command, arguments and input filename (with quotes to escape spaces)
cmd = ['"' fullfile(matlabroot, 'sys\perl\win32\bin\perl.exe') '"'];
args = ' -i.bak -ne "print if not /^%%CreationDate: /" ';
fname = ['"' fullfile(pwd,'file.eps') '"'];

%# execute command
system([cmd args fname])
Amro
  • 123,847
  • 25
  • 243
  • 454