Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
SCDDS-core
Manage
Activity
Members
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Model registry
Analyze
Contributor analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
SPC
SCDDS
SCDDS-core
Commits
26be6b1b
Commit
26be6b1b
authored
4 years ago
by
Federico Felici
Browse files
Options
Downloads
Patches
Plain Diff
Improve struct 2 bus conversions and tests
parent
7f8594a0
Loading
Loading
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
code/functions/SCDconf_createstructfrombus.m
+2
-2
2 additions, 2 deletions
code/functions/SCDconf_createstructfrombus.m
code/functions/SCDconf_structbuscmp.m
+31
-0
31 additions, 0 deletions
code/functions/SCDconf_structbuscmp.m
tests/test_structbus.m
+71
-0
71 additions, 0 deletions
tests/test_structbus.m
with
104 additions
and
2 deletions
code/functions/SCDconf_creates
imdatastruct
.m
→
code/functions/SCDconf_creates
tructfrombus
.m
+
2
−
2
View file @
26be6b1b
...
...
@@ -5,7 +5,7 @@
% and with zero data of the correct kind
% This is enough for passing a ctrl-D with from Workspace bus kind blocks
function
[
out
]
=
SCDconf_creates
imdatastruct
(
dd
,
busname
)
function
[
out
]
=
SCDconf_creates
tructfrombus
(
dd
,
busname
)
bus
=
dd
.
getEntry
(
busname
)
.
getValue
;
% get from data dictionary
bussize
=
size
(
bus
.
Elements
);
...
...
@@ -16,7 +16,7 @@ for ii=1:signalssize
if
contains
(
element
.
DataType
,
'Bus: '
)
busname
=
erase
(
element
.
DataType
,
'Bus: '
);
% recursive call
out
.
(
element
.
Name
)
=
SCDconf_creates
imdatastruct
(
dd
,
busname
);
out
.
(
element
.
Name
)
=
SCDconf_creates
tructfrombus
(
dd
,
busname
);
else
try
cast
(
1
,
element
.
DataType
);
catch
ME
;
error
(
'non-numeric type'
);
end
elementdims
=
element
.
Dimensions
;
...
...
This diff is collapsed.
Click to expand it.
code/functions/SCDconf_structbuscmp.m
0 → 100644
+
31
−
0
View file @
26be6b1b
% Compare the structure of a bus to that of a structure, return 1 if they
% are the same.
function
[
areequal
]
=
SCDconf_structbuscmp
(
mystruct
,
mybus
)
nelem
=
numel
(
mybus
.
Elements
);
for
ielem
=
1
:
nelem
myelem
=
mybus
.
Elements
(
ielem
);
myelementname
=
myelem
.
Name
;
if
~
isfield
(
mystruct
,
myelementname
)
areequal
=
false
;
return
;
end
myfield
=
mystruct
.
(
myelementname
);
if
startsWith
(
myelem
.
DataType
,
'Bus'
)
% recursive call
areequal
=
SCDconf_structbuscmp
(
mystruct
,
mybus
);
if
~
areequal
;
return
;
end
elseif
~
isa
(
myfield
,
'timeseries'
)
% check timeseries
areequal
=
false
;
return
;
elseif
~
isa
(
myfield
.
Data
,
myelem
.
DataType
)
% check data type
areequal
=
false
;
return
;
elseif
~
all
(
size
(
myfield
.
Data
,
2
:
ndims
(
myfield
.
Data
))
==
myelem
.
Dimensions
)
% check dimension
areequal
=
false
;
return
;
end
end
% if we made it this far..
areequal
=
true
;
end
This diff is collapsed.
Click to expand it.
tests/test_structbus.m
0 → 100644
+
71
−
0
View file @
26be6b1b
classdef test_structbus
<
matlab.unittest.TestCase
properties
testBus =
test_structbus.getTestBus();
end
methods
(
Test
,
TestTags=
{'Unit'})
function
testDifferentStruct
(
testCase
)
mystruct =
struct('a',1);
testCase.assertFalse
(
SCDconf_structbuscmp
(
mystruct
,
testCase.testBus
));
end
function
testSameStruct
(
testCase
)
mystruct =
SCDconf_createstructfrombus(testCase.testBus);
%
generate
to
match
bus
areequal =
SCDconf_structbuscmp(mystruct,testCase.testBus);
testCase.assertTrue
(
areequal
);
end
end
methods
(
Static
)
function
testBus =
getTestBus()
testBus =
Simulink.Bus;
testBus.Description =
''
;
testBus.DataScope =
'Auto'
;
testBus.HeaderFile =
''
;
testBus.Alignment =
-1;
saveVarsTmp
{1}
=
Simulink.BusElement
;
saveVarsTmp
{1}
.Name =
'a'
;
saveVarsTmp
{1}
.Complexity =
'real'
;
saveVarsTmp
{1}
.Dimensions =
24;
saveVarsTmp
{1}
.DataType =
'single'
;
saveVarsTmp
{1}
.Min =
[];
saveVarsTmp
{1}
.Max =
[];
saveVarsTmp
{1}
.DimensionsMode =
'Fixed'
;
saveVarsTmp
{1}
.SamplingMode =
'Sample based'
;
saveVarsTmp
{1}
.SampleTime =
-1;
saveVarsTmp
{1}
.DocUnits =
'varies'
;
saveVarsTmp
{1}
.Description =
['References
for
observable
errors
coming
'
...
'
from
the
A
matrix
'];
saveVarsTmp
{1}(2,
1
) =
Simulink.BusElement;
saveVarsTmp
{1}(2,
1
).Name =
'b'
;
saveVarsTmp
{1}(2,
1
).Complexity =
'real'
;
saveVarsTmp
{1}(2,
1
).Dimensions =
8;
saveVarsTmp
{1}(2,
1
).DataType =
'single'
;
saveVarsTmp
{1}(2,
1
).Min =
[];
saveVarsTmp
{1}(2,
1
).Max =
[];
saveVarsTmp
{1}(2,
1
).DimensionsMode =
'Fixed'
;
saveVarsTmp
{1}(2,
1
).SamplingMode =
'Sample based'
;
saveVarsTmp
{1}(2,
1
).SampleTime =
-1;
saveVarsTmp
{1}(2,
1
).DocUnits =
'V'
;
saveVarsTmp
{1}(2,
1
).Description =
['Feed-forwards
for
SCR
E
converters
'
...
'
voltage
commands
'];
saveVarsTmp
{1}(3,
1
) =
Simulink.BusElement;
saveVarsTmp
{1}(3,
1
).Name =
'hyb_FF_f_u'
;
saveVarsTmp
{1}(3,
1
).Complexity =
'real'
;
saveVarsTmp
{1}(3,
1
).Dimensions =
8;
saveVarsTmp
{1}(3,
1
).DataType =
'single'
;
saveVarsTmp
{1}(3,
1
).Min =
[];
saveVarsTmp
{1}(3,
1
).Max =
[];
saveVarsTmp
{1}(3,
1
).DimensionsMode =
'Fixed'
;
saveVarsTmp
{1}(3,
1
).SamplingMode =
'Sample based'
;
saveVarsTmp
{1}(3,
1
).SampleTime =
-1;
saveVarsTmp
{1}(3,
1
).DocUnits =
'V'
;
saveVarsTmp
{1}(3,
1
).Description =
['Feed-forwards
for
SCR
F
converters
'
...
'
voltage
commands
'];
testBus.Elements =
saveVarsTmp{1};
end
end
end
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment