Mercurial > hg > ltpda
comparison m-toolbox/classes/@LTPDAworkbench/jpl2mpl.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 % JPL2MPL converts a java plist to a matlab plist | |
2 % | |
3 % CALL: mpl = jpl2mpl(jpl) | |
4 % | |
5 % M Hewitson 23-11-08 | |
6 % | |
7 % $Id: jpl2mpl.m,v 1.7 2010/08/06 19:10:49 ingo Exp $ | |
8 % | |
9 function mpl = jpl2mpl(jpl) | |
10 | |
11 mpl = plist; | |
12 mpl.setName(char(jpl.getName())); | |
13 | |
14 % build java plist | |
15 for aa=1:awtinvoke(jpl, 'getNparams') | |
16 p = awtinvoke(jpl, 'getParam', aa-1); | |
17 if p.isActive | |
18 val = awtinvoke(p, 'getDefaultVal'); | |
19 key = awtinvoke(p, 'getKey'); | |
20 if isempty(val) | |
21 if strcmp(awtinvoke(p,'getValueType'), 'char') | |
22 val = ''; | |
23 else | |
24 val = []; | |
25 end | |
26 end | |
27 if ischar(val) | |
28 % Try to evaluate the string | |
29 disp(sprintf('$$$ checking parameter value %s', val)); | |
30 try | |
31 if any(strcmpi(val, utils.helper.ltpda_classes)) | |
32 % we don't eval strings that are a class name | |
33 pval = val; | |
34 elseif ~isempty(getBaseVariable(val)) | |
35 | |
36 pval = getBaseVariable(val); | |
37 | |
38 elseif strcmpi(val, 'false') || strcmpi(val, 'true') | |
39 | |
40 % Handle true and false as logicals | |
41 pval = eval(lower(val)); | |
42 | |
43 elseif exist(val) ~=0 | |
44 % warning('parameter value ''%s'' is a file on the MATLAB path: not evaluating', val); | |
45 % we don't eval strings that are any kind of MATLAB file | |
46 pval = val; | |
47 | |
48 elseif strcmpi(key, 'start') || strcmpi(key, 'end') || ... | |
49 strcmpi(key, 'startt') || strcmpi(key, 'endt') || ... | |
50 strcmpi(key, 'start_time') || strcmpi(key, 'end_time') || ... | |
51 strcmpi(key, 'starttimes') || ... | |
52 strcmpi(key, 't0') | |
53 | |
54 pval = val; | |
55 | |
56 else | |
57 % then we can eval this | |
58 pval = evalin('base', val); | |
59 end | |
60 catch | |
61 % warning('Evaluation of string parameter value %s failed', val); | |
62 % if the evaluation of the string failed, just return the string | |
63 pval = val; | |
64 end | |
65 else | |
66 % if the value is not a string, just return it | |
67 pval = val; | |
68 end | |
69 mpl.append(param(char(awtinvoke(p,'getKey')), pval)); | |
70 end | |
71 end | |
72 end | |
73 | |
74 % Checks to see if a value from a plist represents a variable in the base | |
75 % workspace. If so, the variable is evaluated and the result returned. | |
76 % | |
77 function res = getBaseVariable(val) | |
78 | |
79 try | |
80 if evalin('base', sprintf('exist(''%s'', ''var'')', val)) | |
81 cmd = ['exist(''' val ''')']; | |
82 res = evalin('base', val); | |
83 else | |
84 res = []; | |
85 end | |
86 catch | |
87 res = []; | |
88 end | |
89 | |
90 end | |
91 |