-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathcat_io_lazy.m
More file actions
115 lines (111 loc) · 4.39 KB
/
cat_io_lazy.m
File metadata and controls
115 lines (111 loc) · 4.39 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
function run = cat_io_lazy(files,filedates,verb,force)
%cat_io_lazy. Test if a file is newer than another file.
% This function is used to estimated if a file is newer than another given
% file or date. For instance file is the result of anther file that was
% changed in the meantime, it has to be reprocessed.
%
% run = cat_io_lazy(files,filedates,verb)
%
% run .. logical vector with the number of given files
% cell if directories or wildcards are used
% files .. filenames (cellstr or char)
% filedat .. filenames (cellstr or char) or datetimes or datenum
% verb .. print details about the files and about the result
% (default = 0.5 only display if reprocessing is NOT reqired)
% force .. use also in non developer mode (default = 0)
%
% Examples:
% 1) Is the working directory younger than the SPM dir?
% cat_io_lazy(pwd,spm('dir');
%
% 2) Is the working directory younger than one month?
% cat_io_lazy(pwd,clock - [0 1 0 0 0 0])
%
% 3) Is this function younger than one year?
% cat_io_lazy(which('cat_io_lazy'),clock - [1 0 0 0 0 0])
%
% ______________________________________________________________________
%
% Christian Gaser, Robert Dahnke
% Structural Brain Mapping Group (https://neuro-jena.github.io)
% Departments of Neurology and Psychiatry
% Jena University Hospital
% ______________________________________________________________________
% $Id$
if ~exist('verb','var'), verb = 0.5; end
if ~exist('force','var'), force = 1; end
% only use that function in developer mode because it's simply too dangerous
% if files are not processed if already existing and parameter changed
if cat_get_defaults('extopts.expertgui') < 2 && ~force
if verb, cat_io_cprintf([0.5 0.0 0.0],' Reprocessing! \n'); end
run = zeros(size(files));
return
end
files = cellstr(files);
if iscellstr(filedates) || ischar(filedates)
filedates = cellstr(filedates);
if numel(filedates) == 1
filedates = repmat(filedates,numel(files),1);
else
if ~isempty(filedates) && numel(files) ~= numel(filedates)
error('ERROR:cat_io_lazy:inputsize','Number of files and filedates has to be equal.\n')
end
end
else
if size(filedates,1)
filedates = repmat(filedates,numel(files),1);
end
end
run = ones(size(files));
for fi = 1:numel(files)
if ~exist(files{fi},'file')
run(fi) = 1;
else
fdata = dir(files{fi});
if numel(fdata)>1
run = num2cell(run);
end
if exist('filedates','var') && iscellstr(filedates) && exist(filedates{fi},'file')
fdata2 = dir(filedates{fi});
if numel(fdata)>1
run{fi} = [fdata(:).datenum] < fdata2.datenum;
else
run(fi) = fdata.datenum < fdata2.datenum;
end
elseif ~isempty(filedates)
if numel(fdata)>1
run{fi} = [fdata(:).datenum] < datenum( filedates(fi,:) );
else
run(fi) = fdata.datenum < datenum( filedates(fi,:) );
end
end
% be verbose only if verb>=1 or if no reprocessing is required
if verb >= 1 || (verb && ~( (iscell(run) && any(cell2mat(run))) || ( ismatrix(run) && any(run) ) ))
fprintf('\n');
if numel(files)==1
fprintf('\n Input file 1: %50s: %s\n',spm_str_manip( fdata.name , 'a50'),datestr(fdata.datenum) );
fprintf('\n Input file 2: %50s: %s\n',spm_str_manip( fdata2.name, 'a50'),datestr(fdata2.datenum));
else
if fi == 1
fprintf('\n Input file 1: %50s: %s\n', spm_str_manip( fdata.name ,'a50'),datestr(fdata.datenum) );
end
fprintf('\n Input file 2-%02d: %50s: %s\n',fi,spm_str_manip( fdata2.name,'a50'),datestr(fdata2.datenum));
end
end
end
end
% be verbose only if verb>=1 or if no reprocessing is required
if verb >= 1 || ~( (iscell(run) && any(cell2mat(run))) || ( ismatrix(run) && any(run) ) )
if verb >= 1 && ( (iscell(run) && any(cell2mat(run))) || ( ismatrix(run) && any(run) ) )
if all(exf)
cat_io_cprintf([0.5 0.0 0.0],' Reprocessing is required. \n');
elseif all(exf==0) && numel(files)>1
cat_io_cprintf([0.5 0.0 0.0],' (Re)processing is required. \n');
else
cat_io_cprintf([0.5 0.0 0.0],' Processing is required. \n');
end
elseif verb
cat_io_cprintf([0.0 0.5 0.0],' Reprocessing is NOT required. \n');
end
end
end