comparison m-toolbox/classes/@ltpda_uoh/fromFile.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 % Construct a ltpda_ob from a file
2 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3 %
4 % FUNCTION: fromFile
5 %
6 % DESCRIPTION: Construct a ltpda_ob from a file
7 %
8 % CALL: obj = obj.fromFile(filename)
9 % obj = obj.fromFile(pl)
10 %
11 % VERSION: $Id: fromFile.m,v 1.25 2011/10/05 09:50:55 ingo Exp $
12 %
13 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
14 function objs = fromFile(obj, pli)
15
16 VERSION = '$Id: fromFile.m,v 1.25 2011/10/05 09:50:55 ingo Exp $';
17
18 % Which file type are we dealing with?
19 if ischar(pli)
20 pli = plist('filename', pli);
21 end
22
23 % get filename
24 filename = find(pli, 'filename');
25
26 % Get the correct parameter set
27 [path, name, ext] = fileparts(filename);
28
29 % Load a MAT file if the file extension doesn't exist
30 if isempty(ext)
31 ext = '.mat';
32 filename = strcat(filename, ext);
33 pli.pset('filename', filename);
34 end
35
36 % Some display information
37 import utils.const.*
38 utils.helper.msg(msg.PROC1, 'load file: %s%s', name, ext);
39
40 switch ext
41
42 case '.fil'
43 objs = obj.fromLISO(pli);
44
45 case '.mat'
46 ii = obj.getInfo(class(obj), 'From MAT File');
47 ii.setMversion([VERSION '-->' ii.mversion]);
48
49 % Combine input and default plist
50 pl = combine(pli, ii.plists);
51
52 % Load MAT-File
53 objs = load(filename);
54
55 fn = fieldnames(objs);
56
57 if (numel(fn) == 1) && (isstruct(objs.(fn{1})))
58 % If the read object have only one entry and the this entry is a
59 % struct then we assume that the struct is a LTPDA object.
60
61 objs = objs.(fn{1});
62
63 scl = utils.helper.classFromStruct(objs);
64 if isempty(scl)
65 if isfield(objs, 'class')
66 scl = objs.class;
67 else
68 error('### The structure does not match any LTPDA object.');
69 end
70 end
71 if ~strcmp(class(obj), scl)
72 error('### The structure does not match the chosen LTPDA object constructor. It seems to be a [%s] object.', scl)
73 end
74 fcn_name = [class(obj) '.update_struct'];
75 if ~isempty(objs(1).hist) && ~isempty(objs(1).hist.plistUsed)
76 struct_ver = sscanf(objs(1).hist.plistUsed.creator.ltpda_version, '%s.%s.%s');
77 else
78 struct_ver = '1.0';
79 end
80 objs = feval(fcn_name, objs, struct_ver);
81 objs = feval(class(obj), objs);
82
83 elseif (numel(fn) == 1) && (isa(objs.(fn{1}), 'ltpda_obj'))
84 % If the read object have only one entry and this entry is a LTPDA
85 % object then return this LTPDA object.
86 objs = objs.(fn{1});
87
88 else
89 objs = obj.fromDataInMAT(objs, pl);
90 end
91
92 case '.xml'
93 ii = obj.getInfo(class(obj), 'From XML File');
94 ii.setMversion([VERSION '-->' ii.mversion]);
95
96 root_node = xmlread(filename);
97 objs = utils.xml.xmlread(root_node, class(obj));
98
99 otherwise
100 % we load an ascii file
101
102 if pli.isparam('complex_type')
103 objs = obj.fromComplexDatafile(pli);
104 else
105 objs = obj.fromDatafile(pli);
106 end
107
108 end
109
110 end
111