comparison m-toolbox/classes/@ao/complex.m @ 0:f0afece42f48

Import.
author Daniele Nicolodi <nicolodi@science.unitn.it>
date Wed, 23 Nov 2011 19:22:13 +0100
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:f0afece42f48
1 % COMPLEX overloads the complex operator for Analysis objects.
2 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3 %
4 % DESCRIPTION: COMPLEX overloads the complex operator for Analysis Objects.
5 % A3 = COMPLEX(A1,A2) returns the complex result A1 + A2i,
6 % where A1 and A2 are Analysis Objects containing
7 % identically sized real arrays.
8 %
9 % CALL: ao_out = complex(a1, a2);
10 %
11 % <a href="matlab:utils.helper.displayMethodInfo('ao', 'complex')">Parameters Description</a>
12 %
13 % VERSION: $Id: complex.m,v 1.35 2011/04/08 08:56:13 hewitson Exp $
14 %
15 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
16
17 function varargout = complex(varargin)
18
19 % Check if this is a call for parameters
20 if utils.helper.isinfocall(varargin{:})
21 varargout{1} = getInfo(varargin{3});
22 return
23 end
24
25 import utils.const.*
26 utils.helper.msg(msg.PROC3, 'running %s/%s', mfilename('class'), mfilename);
27
28 % Collect input variable names
29 in_names = cell(size(varargin));
30 for ii = 1:nargin,in_names{ii} = inputname(ii);end
31
32 % Collect all AOs and plists
33 [as, ao_invars] = utils.helper.collect_objects(varargin(:), 'ao', in_names);
34
35 % Decide on a deep copy or a modify
36 bs = copy(as, nargout);
37
38 % Check input arguments number
39 if length(bs) ~= 2
40 error ('### Incorrect inputs. Please enter 2 AOs');
41 end
42
43 if nargout == 0
44 error('### Complex cannot be used as a modifier. Please give an output variable.');
45 end
46
47 % Only support data2D or cdata for now
48 if isa(bs(1).data, 'data3D') || isa(bs(2).data, 'data3D')
49 error('### 3D data objects are currently not supported.');
50 end
51
52 % Check for the same data.
53 if ~strcmp(class(bs(1).data), class(bs(2).data))
54 error ('### The data class of the two AOs must be the same. (%s <-> %s)', ...
55 class(bs(1).data), class(bs(2).data));
56 end
57
58 % Check for the same sample rate
59 fields = fieldnames(bs(1).data);
60 if ismember('fs', fields)
61 if ~isequalwithequalnans(bs(1).data.fs, bs(2).data.fs)
62 error('### The sample rate of the two AOs is not the same. Please resample one of them.');
63 end
64 end
65
66 % Check the length of the AO's
67 if length(bs(1).data.getY) ~= length(bs(2).data.getY)
68 error ('### The length of the data vectors must be the same.')
69 end
70
71 % The x vector, if present, should be the same
72 if ismember('x', fields)
73 if ~isequal(bs(1).data.getX, bs(2).data.getX)
74 error('### The two data series should have the same x values.');
75 end
76 end
77
78 % The time should be the same
79 if ismember('t0', fields)
80 if bs(1).data.t0.utc_epoch_milli ~= bs(2).data.t0.utc_epoch_milli
81 error('### The two data series don''t start at the same time.');
82 end
83 end
84
85 % The x units should match
86 if ismember('xunits', fields)
87 if bs(1).data.xunits ~= bs(2).data.xunits
88 error('### The two data series should have the same x units');
89 end
90 end
91
92 % Copy object 1 for the output
93 bs(1).data.setY(complex(bs(1).data.getY, bs(2).data.getY));
94 if ismember('yunits', fields)
95 if bs(1).data.yunits == bs(2).data.yunits
96 bs(1).data.setYunits(bs(1).data.yunits);
97 else
98 error('### Can''t combine data with different units');
99 end
100 end
101
102 % Set name
103 bs(1).name = sprintf('complex(%s, %s)', ao_invars{1}, ao_invars{2});
104 % Add history
105 bs(1).addHistory(getInfo('None'), getDefaultPlist, ao_invars, [bs(1).hist bs(2).hist]);
106
107 % Set output
108 varargout{1} = bs(1);
109 end
110
111 %--------------------------------------------------------------------------
112 % Get Info Object
113 %--------------------------------------------------------------------------
114 function ii = getInfo(varargin)
115 if nargin == 1 && strcmpi(varargin{1}, 'None')
116 sets = {};
117 pl = [];
118 else
119 sets = {'Default'};
120 pl = getDefaultPlist;
121 end
122 % Build info object
123 ii = minfo(mfilename, 'ao', 'ltpda', utils.const.categories.op, '$Id: complex.m,v 1.35 2011/04/08 08:56:13 hewitson Exp $', sets, pl);
124 ii.setModifier(false);
125 ii.setArgsmin(2);
126 end
127
128 %--------------------------------------------------------------------------
129 % Get Default Plist
130 %--------------------------------------------------------------------------
131
132 function plout = getDefaultPlist()
133 persistent pl;
134 if exist('pl', 'var')==0 || isempty(pl)
135 pl = buildplist();
136 end
137 plout = pl;
138 end
139
140 function pl = buildplist()
141 pl = plist.EMPTY_PLIST;
142 end
143