Mercurial > hg > ltpda
comparison m-toolbox/classes/@plist/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.8 2011/02/11 12:44:33 hewitson Exp $ | |
12 % | |
13 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
14 function objs = fromFile(obj, pli) | |
15 | |
16 VERSION = '$Id: fromFile.m,v 1.8 2011/02/11 12:44:33 hewitson 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 switch ext | |
37 | |
38 case '.mat' | |
39 ii = obj.getInfo(class(obj), 'From MAT File'); | |
40 ii.setMversion([VERSION '-->' ii.mversion]); | |
41 | |
42 % Combine input and default plist | |
43 pl = combine(pli, ii.plists); | |
44 | |
45 % Load MAT-File | |
46 objs = load(filename); | |
47 | |
48 if ((isfield(objs, 'objs') && isstruct(objs.objs)) || ... | |
49 (isfield(objs, 'a') && isstruct(objs.a))) | |
50 if isfield(objs, 'a') | |
51 objs = objs.a; | |
52 else | |
53 objs = objs.objs; | |
54 end | |
55 scl = utils.helper.classFromStruct(objs); | |
56 if isempty(scl) | |
57 if isfield(objs, 'class') | |
58 scl = objs.class; | |
59 else | |
60 error('### The structure does not match any LTPDA object.'); | |
61 end | |
62 end | |
63 if ~strcmp(class(obj), scl) | |
64 error('### The structure does not match the chosen LTPDA object constructor. It seems to be a [%s] object.', scl) | |
65 end | |
66 fcn_name = [class(obj) '.update_struct']; | |
67 struct_ver = sscanf(objs(1).creator.ltpda_version, '%s.%s.%s'); | |
68 objs = feval(fcn_name, objs, struct_ver); | |
69 objs = feval(class(obj), objs); | |
70 elseif ismember('a', fieldnames(objs)) | |
71 objs = objs.a; | |
72 elseif ismember('objs', fieldnames(objs)) | |
73 objs = objs.objs; | |
74 else | |
75 objs = obj.fromDataInMAT(objs, pl); | |
76 end | |
77 | |
78 | |
79 case '.xml' | |
80 ii = obj.getInfo(class(obj), 'From XML File'); | |
81 ii.setMversion([VERSION '-->' ii.mversion]); | |
82 | |
83 % Combine input and default plist | |
84 pl = combine(pli, ii.plists); | |
85 | |
86 root_node = xmlread(filename); | |
87 objs = utils.xml.xmlread(root_node, class(obj)); | |
88 | |
89 otherwise | |
90 error('### Unknown file type [%s].', ext(2:end)); | |
91 end | |
92 | |
93 end | |
94 |