/
preprocess_editFunctionHead.m
40 lines (32 loc) · 1.35 KB
/
preprocess_editFunctionHead.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
function [obj, Fname_old] = preprocess_editFunctionHead(mtreeobj)
% notation:
% cIndex -> column index; refers to a property type
% rIndex -> row index of some object; refers to the entire row.
cIndex = mtree_cIndex();
rIndex = mtree_rIndex(mtreeobj);
Fname_old = mtreeobj.C{mtreeobj.T(rIndex.HEAD.Fname, cIndex.stringTableIndex)};
% change functon name; add preprocess_ to the function name
mtreeobj = mtree_createAndAdd_NewNode(mtreeobj, ...
rIndex.HEAD.ETC2, ...
cIndex.indexLeftchild, ...
{mtreeobj.K.ID, ['preprocessed_', Fname_old]});
% add datahandle as input variable of the function
% required, s.th. ctrlif works within the function
[mtreeobj, rIndex_datahandle] = mtree_createAndAdd_NewNode(mtreeobj, ...
rIndex.HEAD.ETC2, ...
cIndex.indexRightchild, ...
{mtreeobj.K.ID, 'datahandle'}, ...
rIndex.HEAD.Arg(:,1), ...
cIndex.indexNextNode);
% add function index to distinguish the function calls from each other
% within the integration (ODE solving algorithm with switching point
% detection)
[mtreeobj, ~] = mtree_createAndAdd_NewNode(mtreeobj, ...
rIndex.HEAD.ETC2, ...
cIndex.indexRightchild, ...
{mtreeobj.K.ID, 'function_index'}, ...
rIndex_datahandle, ...
cIndex.indexNextNode);
mtreeobj.C{mtreeobj.T(rIndex.HEAD.Fname, cIndex.stringTableIndex)} = 'old_fcn_name';
obj = mtreeobj;
end