Skip to content

Commit 78d8137

Browse files
committed
Fix missing calllib arguments in: Monitors.Channel, Monitors.AsMatrix, Monitors.dblFreq, Monitors.dblHour, ActiveCktElement.Properties
`Monitors.AsMatrix` also had a separate issue. Example updated to test the affected functions. Closes #20
1 parent 9dc0159 commit 78d8137

File tree

4 files changed

+47
-10
lines changed

4 files changed

+47
-10
lines changed

+DSS_MATLAB/ICktElement.m

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -160,9 +160,9 @@
160160

161161
function result = Properties(obj, NameOrIdx)
162162
if ischar(NameOrIdx) || isstring(NameOrIdx)
163-
calllib('dss_capi', 'ctx_DSSProperty_Set_Name', obj.dssctx, NameOrIdx);
163+
calllib(obj.libname, 'ctx_DSSProperty_Set_Name', obj.dssctx, NameOrIdx);
164164
elseif isinteger(NameOrIdx)
165-
calllib('dss_capi', 'ctx_DSSProperty_Set_Index', obj.dssctx, NameOrIdx);
165+
calllib(obj.libname, 'ctx_DSSProperty_Set_Index', obj.dssctx, NameOrIdx);
166166
else
167167
ME = MException(['DSS_MATLAB:Error'], 'Expected char, string or integer');
168168
throw(ME);

+DSS_MATLAB/IMonitors.m

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -63,14 +63,14 @@
6363
result = 0;
6464
return
6565
end
66-
calllib('ctx_Monitors_Get_Channel_GR', obj.dssctx, Index);
66+
calllib(obj.libname, 'ctx_Monitors_Get_Channel_GR', obj.dssctx, Index);
6767
obj.CheckForError();
6868
result = obj.apiutil.get_float64_gr_array();
6969
end
7070

7171
function result = AsMatrix(obj)
7272
% Matrix of the active monitor, containing the hour vector, seconds vector, and all channels (index 3 = channel 1)
73-
calllib('ctx_Monitors_Get_ByteStream_GR', obj.dssctx);
73+
calllib(obj.libname, 'ctx_Monitors_Get_ByteStream_GR', obj.dssctx);
7474
obj.CheckForError();
7575
buffer = obj.apiutil.get_int8_gr_array();
7676
if (numel(buffer) <= 1)
@@ -80,7 +80,7 @@
8080
record_size = typecast(buffer, 'int32');
8181
record_size = record_size(3) + 2;
8282
data = typecast(buffer(273:end), 'single');
83-
data = reshape(data, [int32(data.size() / record_size), record_size]);
83+
data = reshape(data, [record_size, size(data, 2) / record_size]);
8484
result = data;
8585
end
8686

@@ -227,14 +227,14 @@
227227

228228
function result = get.dblFreq(obj)
229229
% (read-only) Array of doubles containing frequency values for harmonics mode solutions; Empty for time mode solutions (use dblHour)
230-
calllib('ctx_Monitors_Get_dblFreq_GR', obj.dssctx);
230+
calllib(obj.libname, 'ctx_Monitors_Get_dblFreq_GR', obj.dssctx);
231231
obj.CheckForError();
232232
result = obj.apiutil.get_float64_gr_array();
233233
end
234234

235235
function result = get.dblHour(obj)
236236
% (read-only) Array of doubles containgin time value in hours for time-sampled monitor values; Empty if frequency-sampled values for harmonics solution (see dblFreq)
237-
calllib('ctx_Monitors_Get_dblHour_GR', obj.dssctx);
237+
calllib(obj.libname, 'ctx_Monitors_Get_dblHour_GR', obj.dssctx);
238238
obj.CheckForError();
239239
result = obj.apiutil.get_float64_gr_array();
240240
end

examples/13Bus.zip

511 Bytes
Binary file not shown.

examples/13Bus/run.m

Lines changed: 40 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@
5252
Solution = DSS.ActiveCircuit.Solution;
5353
Bus = DSS.ActiveCircuit.ActiveBus;
5454
Load = DSS.ActiveCircuit.Loads;
55+
Monitors = DSS.ActiveCircuit.Monitors;
56+
CE = DSS.ActiveCircuit.ActiveCktElement;
5557

5658
% You can get some very basic description of the properties for most of the
5759
% objects:
@@ -115,20 +117,55 @@
115117
ylabel('Bus Y coordinate');
116118
ylabel(handle, 'Voltage (pu)');
117119

120+
%% Monitors, including the AsMatrix function (API extension)
121+
122+
% Let's edit the circuit to add some variation, add a monitor, and solve
123+
Text.Command = 'BatchEdit Load..* Daily=default';
124+
Text.Command = 'New Monitor.test Element=Transformer.Sub Mode=1';
125+
Solution.Mode = int32(DSS_MATLAB.SolveModes.Daily);
126+
Solution.Solve();
127+
128+
% Now plot the first channel of the monitor
129+
figure;
130+
Monitors.Name = 'test';
131+
plot(Monitors.dblHour, Monitors.Channel(1));
132+
Monitors.dblHour
133+
xlabel('Time (h)');
134+
header = Monitors.Header();
135+
ylabel(header(1));
136+
137+
% We can also get all data as a matrix; the first two columns are the
138+
% integer hours and seconds (for a time solution)
139+
figure;
140+
mon_mat = Monitors.AsMatrix();
141+
h = mon_mat(1, :) + mon_mat(2, :) / 3600;
142+
plot(h, mon_mat(3:end, :));
143+
xlabel('Time (h)');
144+
legend(header);
145+
146+
%% Raw DSS properties
147+
148+
% Although the Text interface can be convenient to read properties not
149+
% exposed by the API, OpenDSS also provides a dedicated Properties API
150+
% that can be useful for elements that don't have dedicated APIs.
151+
Circuit.SetActiveElement('Transformer.Sub')
152+
Prop = CE.Properties('Windings');
153+
fprintf('Property Name: %s, Value: %s', Prop.Name, Prop.Val);
154+
118155
%% Loading circuits from ZIP files (API extension, not available in the official OpenDSS)
119156

120157
DSS.ClearAll();
121158
ZIP = DSS.ZIP;
122-
ZIP.Open('../13Bus.zip')
159+
ZIP.Open('../13Bus.zip');
123160

124161
ZIP.List()
125162

126163
% Running the DSS script directly from the ZIP.
127164
% This also restricts loading most files only from the ZIP archive,
128165
% so you have to use relative paths.
129-
ZIP.Redirect('13Bus/IEEE13Nodeckt.dss')
166+
ZIP.Redirect('13Bus/IEEE13Nodeckt.dss');
130167

131-
ZIP.Close()
168+
ZIP.Close();
132169

133170
DSS.ActiveCircuit.NumBuses
134171

0 commit comments

Comments
 (0)