-
Notifications
You must be signed in to change notification settings - Fork 8
/
CubeArgs.m
90 lines (67 loc) · 2.83 KB
/
CubeArgs.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
classdef CubeArgs < inputParser
% inputParser subclass for Cube argument parsing
properties (Constant)
CUBECLASSNAME = 'Cube'
end
methods
function CA = CubeArgs()
CA@inputParser;
% Set these explicitly just to be clear
CA.CaseSensitive = false;
CA.KeepUnmatched = false;
CA.PartialMatching = true;
CA.StructExpand = true;
%% Required arguments
dataValid = @(x)assert(CA.isDataSource(x),...
'Data source must be a data array or a Cube object');
CA.addRequired('data', dataValid);
%% Optional name-value parameters
qtyValid = @(x)assert(CA.isValidQuantity(x),...
'Quantity must be a non-empty char array');
CA.addParameter('quantity', 'Unknown', qtyValid);
fileValid = @(x)assert(CA.isFile(x),...
'Filename must be a valid path to an existing file');
CA.addParameter('file', '', fileValid);
WLValid = @(x)assert(CA.isValidWL(x),...
'Wavelength specification must be a numeric vector');
CA.addParameter('wl', [], WLValid);
WLuValid = @(x)assert(CA.isValidWLu(x),...
'Wavelength unit must be a non-empty char array');
CA.addParameter('wlunit', '', WLuValid);
fwhmValid = @(x)assert(CA.isValidFWHM(x),...
'FWHM specification must be a numeric vector');
CA.addParameter('fwhm', [], fwhmValid);
historyValid = @(x)assert(CA.isValidHistory(x),...
'History entries must be contained in a 1x1 cell array');
CA.addParameter('history', {}, historyValid);
end
end
methods (Static)
%% Validation functions
% Return a logical value
function bool = isFile(x)
bool = ischar(x) && ( exist(x,'file') == 2 );
end
function bool = isCube(x)
bool = isa(x,CubeArgs.CUBECLASSNAME);
end
function bool = isDataSource(x)
bool = CubeArgs.isCube(x) || isnumeric(x);
end
function bool = isValidQuantity(x)
bool = ~isempty(x) && ischar(x);
end
function bool = isValidWL(x)
bool = isnumeric(x) && isvector(x);
end
function bool = isValidWLu(x)
bool = ~isempty(x) && ischar(x);
end
function bool = isValidFWHM(x)
bool = isnumeric(x) && isvector(x);
end
function bool = isValidHistory(x)
bool = iscell(x) && isequal(size(x), [1, 1]);
end
end
end