comparison m-toolbox/classes/@ao/export.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 % EXPORT export the data of an analysis object to a text file.
2 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3 %
4 % DESCRIPTION: EXPORT export the data of an analysis object to a text file.
5 % The x-values will be stored in the first column of the text
6 % file and the y-values the second column. If the y-values are
7 % complex then stores this method the real part of the
8 % y-values in the second column and the imaginary part in the
9 % third column.
10 %
11 % CALL: export(a, 'blah.txt');
12 % export(a, plist);
13 %
14 % <a href="matlab:utils.helper.displayMethodInfo('ao', 'export')">Parameters Description</a>
15 %
16 % VERSION: $Id: export.m,v 1.29 2011/04/08 08:56:15 hewitson Exp $
17 %
18 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
19
20 function varargout = export(varargin)
21
22 % Check if this is a call for parameters
23 if utils.helper.isinfocall(varargin{:})
24 varargout{1} = getInfo(varargin{3});
25 return
26 end
27
28 import utils.const.*
29 utils.helper.msg(msg.PROC3, 'running %s/%s', mfilename('class'), mfilename);
30
31 % Collect input variable names
32 in_names = cell(size(varargin));
33 for ii = 1:nargin,in_names{ii} = inputname(ii);end
34
35 % Collect all AOs
36 [as, ao_invars] = utils.helper.collect_objects(varargin(:), 'ao', in_names);
37 [pl, pl_invars, rest] = utils.helper.collect_objects(varargin(:), 'plist', in_names);
38
39 % Combine plists
40 pl = parse(pl, getDefaultPlist);
41
42 % get filename from plist
43 filename = find(pl, 'filename');
44 if isempty(filename)
45 for jj = 1:numel(rest)
46 if ischar(rest{jj})
47 filename = rest{jj};
48 break
49 end
50 end
51 end
52 if isempty(filename)
53 error('### You must specify a filename. Either directly, or in a plist');
54 end
55
56 if length(as) > 1
57 error('### Export can only deal with one AO at a time.');
58 end
59
60 if isa(as.data, 'data2D') && ~isa(as.data, 'data3D')
61 if isreal(as.data.getY)
62 if isempty(as.dy)
63 out = [as.data.getX as.data.getY];
64 else
65 out = [as.data.getX as.data.getY as.dy];
66 end
67 else
68 switch pl.find('complex format')
69 case 'absdeg'
70 out = [as.data.getX abs(as.data.getY) utils.math.phase(as.data.getY)];
71 case 'realimag'
72 out = [as.data.getX real(as.data.getY) imag(as.data.getY)];
73 case 'absrad'
74 out = [as.data.getX abs(as.data.getY) angle(as.data.getY)];
75 otherwise
76 end
77
78 if ~isempty(as.dy)
79 out = [out as.dy];
80 end
81 end
82 elseif isa(as.data, 'cdata')
83 out = as.data.getY;
84 else
85 error('### Please code me up for the class [%s]', class(as.data));
86 end
87
88 save(filename, 'out', '-ASCII', '-DOUBLE', '-TABS');
89
90 end
91
92 %--------------------------------------------------------------------------
93 % Get Info Object
94 %--------------------------------------------------------------------------
95 function ii = getInfo(varargin)
96 if nargin == 1 && strcmpi(varargin{1}, 'None')
97 sets = {};
98 pl = [];
99 else
100 sets = {'Default'};
101 pl = getDefaultPlist;
102 end
103 % Build info object
104 ii = minfo(mfilename, 'ao', 'ltpda', utils.const.categories.output, '$Id: export.m,v 1.29 2011/04/08 08:56:15 hewitson Exp $', sets, pl);
105 ii.setOutmin(0);
106 end
107
108 %--------------------------------------------------------------------------
109 % Get Default Plist
110 %--------------------------------------------------------------------------
111 function plout = getDefaultPlist()
112 persistent pl;
113 if exist('pl', 'var')==0 || isempty(pl)
114 pl = buildplist();
115 end
116 plout = pl;
117 end
118
119 function plo = buildplist()
120 plo = plist({'filename', 'The filename to export to.'}, paramValue.EMPTY_STRING);
121
122 p = param({'complex format', 'The format to write the complex values.'}, {2, {'absdeg', 'realimag', 'absrad'}, paramValue.SINGLE});
123 plo.append(p);
124 end
125
126