Mercurial > hg > ltpda
comparison m-toolbox/classes/@LTPDAworkbench/parseCmd.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 % PARSECMD parses a command string comming from hist2m to information | |
2 % needed to build a block. | |
3 % | |
4 % CALL: out = parseCmd(cmd) | |
5 % | |
6 % Returns a structure: | |
7 % | |
8 % out.outname | |
9 % out.outports | |
10 % out.innames | |
11 % out.inports | |
12 % out.method | |
13 % out.class | |
14 % out.plists | |
15 % | |
16 % M Hewitson 12-11-10 | |
17 % | |
18 % $Id: parseCmd.m,v 1.3 2010/08/06 19:10:49 ingo Exp $ | |
19 % | |
20 function out = parseCmd(cmd) | |
21 | |
22 pcmd = LTPDAworkbench.parse(cmd); | |
23 | |
24 % check for block name from comment | |
25 blockname = ''; | |
26 methodclass = ''; | |
27 if ~isempty(pcmd.comment) | |
28 % look for block name | |
29 st = regexp(pcmd.comment, '\|', 'split'); | |
30 if numel(st)==2 | |
31 blockname = strrep(strtrim(st{2}), ' ', '_'); | |
32 else | |
33 blockname = ''; | |
34 end | |
35 % and method class | |
36 methodclass = strtrim(st{1}); | |
37 end | |
38 | |
39 % get output ports | |
40 outnames = pcmd.outvars; | |
41 outports = zeros(size(outnames)); | |
42 for kk=1:numel(outnames) | |
43 pstrs = regexp(outnames{kk}, '_PORT(\d*)', 'tokens'); | |
44 if ~isempty(pstrs) | |
45 outports(kk) = str2double(pstrs{1}{1}); | |
46 end | |
47 end | |
48 | |
49 % get input ports | |
50 innames = pcmd.invars; | |
51 inports = zeros(size(innames)); | |
52 for kk=1:numel(innames) | |
53 pstrs = regexp(innames{kk}, '_PORT(\d*)', 'tokens'); | |
54 if ~isempty(pstrs) | |
55 inports(kk) = str2double(pstrs{1}{1}); | |
56 end | |
57 end | |
58 | |
59 % either take the block name from the comment, or | |
60 % from the first output name | |
61 if isempty(blockname) | |
62 if numel(outnames) > 0 | |
63 blockname = outnames{1}; | |
64 else | |
65 blockname = 'unknown'; | |
66 end | |
67 end | |
68 | |
69 % If methodclass is empty, we need an alternative | |
70 % = just look for the first class method of LTPDA that | |
71 % matches the function name | |
72 if isempty(methodclass) | |
73 cls = utils.helper.ltpda_userclasses; | |
74 for kk=1:numel(cls) | |
75 cl = cls{kk}; | |
76 mts = methods(cl); | |
77 for ll=1:numel(mts) | |
78 mt = mts{ll}; | |
79 if strcmp(mt, pcmd.method) | |
80 methodclass = cl; | |
81 break; | |
82 end | |
83 end | |
84 end | |
85 end | |
86 if isempty(methodclass) | |
87 error('### Unable to determine the class of method: %s', pcmd.method); | |
88 end | |
89 | |
90 out.outname = strtrim(blockname); | |
91 out.outports = outports; | |
92 out.innames = pcmd.invars; | |
93 out.inports = inports; | |
94 out.method = pcmd.method; | |
95 out.class = methodclass; | |
96 out.plists = pcmd.pls; | |
97 | |
98 end | |
99 | |
100 |