From 7459a5dcbb49443c435dbed88a1fa5de261d8c92 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Adjemian=20=28Charybdis=29?= Date: Mon, 1 Jul 2013 16:50:02 +0200 Subject: [PATCH] Changed the behaviour of @dynSeries/save method when the chosen file name corresponds to an existing file in the same folder. --- matlab/@dynSeries/save.m | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/matlab/@dynSeries/save.m b/matlab/@dynSeries/save.m index d417897e7..a399a8a95 100644 --- a/matlab/@dynSeries/save.m +++ b/matlab/@dynSeries/save.m @@ -29,10 +29,9 @@ end switch format case 'm' if exist([basename, '.m'],'file') - fid = fopen([basename, '.new', '.m'],'w'); - else - fid = fopen([basename, '.m'],'w'); + copyfile([basename, '.m'],[basename, '.old.m']) end + fid = fopen([basename, '.m'],'w'); fprintf(fid,'%% File created on %s.\n',datestr(now)); fprintf(fid,'\n'); fprintf(fid,'FREQ__ = %s;\n',num2str(A.freq)); @@ -71,17 +70,14 @@ switch format end eval(str); if exist([basename, '.mat'],'file') - save([basename '.new.mat'],'INIT__','FREQ__','NAMES__','TEX__',A.name{:}); - else - save([basename '.mat'],'INIT__','FREQ__','NAMES__','TEX__',A.name{:}); + copyfile([basename, '.mat'],[basename, '.old.mat']) end - + save([basename '.mat'],'INIT__','FREQ__','NAMES__','TEX__',A.name{:}); case 'csv' if exist([basename, '.csv'],'file') - fid = fopen([basename, '.new', '.csv'],'w'); - else - fid = fopen([basename, '.csv'],'w'); + copyfile([basename, '.csv'],[basename, '.old.csv']) end + fid = fopen([basename, '.csv'],'w'); fprintf(fid,',%s', A.name{:}); fprintf(fid,'\n'); for t=1:A.nobs