-
Notifications
You must be signed in to change notification settings - Fork 1
/
spectraFiles.m
95 lines (75 loc) · 2.65 KB
/
spectraFiles.m
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
function tcMall = spectraFiles(varargin)
if nargin == 0
error('Input required (either tcMall or runName).')
end
% Initialize the tcMall array (input or create empty):
tcMind = cellfun(@(x) isa(x,'tcMeas'), varargin);
if nnz(tcMind) == 0
tcMall = tcMeas.empty;
else
tcMall = vertcat(varargin{tcMind});
end
% Determine which run names to import/refresh:
if nnz(cellfun(@ischar, varargin)) == 0
runNames = unique({tcMall.runName});
else
runNames = unique([varargin(cellfun(@ischar, varargin)), ...
{tcMall.runName}]);
end
% fileDtbs = struct('toAdd',{},'toSub',{});
fileDtbs.toAdd = {};
fileDtbs.toSub = {};
for i = 1:length(runNames)
fileDtbsi = spectraFilesDatabase(runNames{i});
fileDtbs.toAdd = [fileDtbs.toAdd, fileDtbsi.toAdd];
fileDtbs.toSub = [fileDtbs.toSub, fileDtbsi.toSub];
end
fileDtbs.toAdd = unique(fileDtbs.toAdd);
fileDtbs.toSub = unique(fileDtbs.toSub);
%% Add time capture files from specified files and directories to list:
filenames = {};
for i = 1:length(fileDtbs.toAdd)
filenames = [filenames, locateTCfiles(fileDtbs.toAdd{i})]; %#ok<AGROW>
end
%% Determine which files to import:
% Discard redundant filenames (there shouldn't be any):
filenames = unique(filenames);
% Discard filenames that match those already in tcMall:
[~, m, ~] = unique([filenames, {tcMall.filename}, {tcMall.filenameTC}],...
'last');
filenames = filenames(m(m <= length(filenames)));
% Remove junk captures:
for i = 1:length(fileDtbs.toSub)
filenames(cellfun(@(x) ...
~isempty( strfind(x,fileDtbs.toSub{i}) ), ...
filenames)) = [];
end
%% Import the list of time capture files into tcMeas object array:
for i = 1:length(filenames)
if exist(filenames{i},'file')
tcMall(end+1) = tcMeas(filenames{i}); %#ok<AGROW>
% Check that the file size is not too small (which indicates
% that it wasn't saved correctly):
if getfield(dir(tcMall(end).filenameTC),'bytes') < 1024
warning('spectraFiles:invalidTCfile',...
'Time capture file not saved correctly:\n%s',...
tcMall(end).filenameTC)
tcMall = tcMall(1:end-1);
end
else
warning('spectraFiles:fileNotFound',...
'Missing file will not be imported:\n%s',filenames{i})
end
end
%% Sort the tcMeas array
% Sort by tcMeas array:
if isempty(tcMall)
error('spectraFiles:empty_tcMall','tcMall is empty');
end
[~, ind] = sortrows([[tcMall.T]; [tcMall.SQUID]; [tcMall.flux]; ...
[tcMall.R]; [tcMall.fMax]]',[1 2 3 4 5]);
tcMall = tcMall(ind);
tcMall = reshape(tcMall,length(tcMall),1);
%% Condition the time captures:
% conditionTCs(tcMall);
end