-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfm_del.m
158 lines (138 loc) · 5.28 KB
/
fm_del.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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
function [nomi,numero] = fm_del(nomi,numero,list_box)
% FM_DEL delete a UDM variable or function
%
% (...) = FM_DEL(...)
%
%This function is generally called by a callback within
%the FM_MAKE function
%
%Author: Federico Milano
%Date: 11-Nov-2002
%Version: 1.0.0
%
%E-mail: [email protected]
%Web-site: faraday1.ucd.ie/psat.html
%
% Copyright (C) 2002-2019 Federico Milano
global Algeb Buses Initl Param Servc State Fig
if numero == 0; return; end
% general operations
hlist = findobj(Fig.make,'Tag',list_box);
hdl = get(Fig.make,'UserData');
delbus = strcmp(list_box,'ListboxBuses');
if delbus
actualnum = Buses.n;
numero = Buses.n;
else
actualnum = get(hlist,'Value');
nome = nomi{actualnum,1};
end
nomi(actualnum) = [];
numero = numero-1;
set(hlist,'String',nomi,'Value',1);
% other operations
switch list_box
case 'ListboxBuses'
% algebraic variables and equations
Algeb.idx([Buses.n 2*Buses.n]) = [];
alg_idx = strmatch(['V',int2str(Buses.n)],Algeb.name,'exact');
alg_idx = [alg_idx, strmatch(['theta',int2str(Buses.n)],Algeb.name,'exact')];
Algeb.n = Algeb.n - length(alg_idx);
Algeb.name(alg_idx) = [];
Algeb.eqidx([Algeb.neq-1 Algeb.neq]) = [];
Algeb.eq([Algeb.neq-1 Algeb.neq]) = [];
Algeb.neq = Algeb.neq - 2;
% service variables
ser_idx = strmatch(['P',int2str(Buses.n)],Servc.idx,'exact');
ser_idx = [ser_idx, strmatch(['Q',int2str(Buses.n)],Servc.idx,'exact')];
Servc.idx(ser_idx) = [];
ser_idx = strmatch(['P',int2str(Buses.n)],Servc.name,'exact');
ser_idx = [ser_idx,strmatch(['Q',int2str(Buses.n)],Servc.name,'exact')];
Servc.name(ser_idx) = [];
Servc.n = Servc.n - length(ser_idx);
% initial variables
ini_idx = strmatch(['V',int2str(Buses.n),'_0'],Initl.idx,'exact');
ini_idx = [ini_idx,strmatch(['theta',int2str(Buses.n),'_0'],Initl.idx,'exact')];
ini_idx = [ini_idx,strmatch(['P',int2str(Buses.n),'_0'],Initl.idx,'exact')];
ini_idx = [ini_idx,strmatch(['Q',int2str(Buses.n),'_0'],Initl.idx,'exact')];
Initl.idx(ini_idx) = [];
ini_idx = strmatch(['V',int2str(Buses.n),'_0'],Initl.name,'exact');
ini_idx = [ini_idx,strmatch(['theta',int2str(Buses.n),'_0'],Initl.name,'exact')];
ini_idx = [ini_idx,strmatch(['P',int2str(Buses.n),'_0'],Initl.name,'exact')];
ini_idx = [ini_idx,strmatch(['Q',int2str(Buses.n),'_0'],Initl.name,'exact')];
Initl.name(ini_idx) = [];
Initl.n = Initl.n-length(ini_idx);
% GUI settings
if isempty(Algeb.idx), set(hdl(13),'String',' ','Value',1);
else, set(hdl(13),'String',Algeb.idx,'Value',length(Algeb.idx));
end
set(hdl(6),'String',Algeb.name,'Value',Algeb.n)
set(hdl(14),'String',Servc.idx,'Value',length(Servc.idx))
set(hdl(7),'String',Servc.name,'Value',Servc.n)
if isempty(Initl.idx), set(hdl(15),'String',' ','Value',1)
else, set(hdl(15),'String',Initl.idx,'Value',1)
end
set(hdl(9),'String',Initl.name,'Value',max(Initl.n,1))
if isempty(Algeb.eq), set(hdl(11),'String',Algeb.eq,'Value',1)
else, set(hdl(11),'String',fm_strjoin(Algeb.eqidx,'=',Algeb.eq),'Value',Algeb.neq)
end
case 'ListboxServiceVar'
a = strmatch(nome,Servc.idx(end-2*Buses.n+1:end-Buses.n),'exact');
b = strmatch(nome,Servc.idx(end-Buses.n+1:end),'exact');
if isempty(a), a = 0; end
if isempty(b), b = 0; end
if a || b, return, end
Servc.type(actualnum) = [];
Servc.limit(actualnum,:) = [];
Servc.init(actualnum) = [];
Servc.offset(actualnum) = [];
Servc.un(actualnum) = [];
Servc.fn(actualnum) = [];
ser_idx = strmatch(nome,Servc.eqidx,'exact');
Servc.eqidx(ser_idx) = [];
Servc.eq(ser_idx) = [];
Servc.neq = Servc.neq - length(ser_idx);
% initial variables
init_idx = strmatch([nome,'_0'],Initl.name,'exact');
Initl.name(init_idx) = [];
Initl.n = Initl.n - 1;
init_idx = strmatch([nome,'_0'],Initl.idx,'exact');
Initl.idx(init_idx) = [];
% GUI settings
if isempty(Servc.eq), set(hdl(12),'String',Servc.eq,'Value',1)
else, set(hdl(12),'String',fm_strjoin(Servc.eqidx,'=',Servc.eq),'Value',Servc.neq)
end
set(hdl(9),'String',Initl.name,'Value',max(Initl.n,1));
if isempty(Initl.idx), set(hdl(15),'String',' ','Value',1);
else, set(hdl(15),'String',Initl.idx,'Value',1);
end
case 'ListboxState'
State.limit(actualnum,:) = [];
State.time(actualnum) = [];
State.nodyn(actualnum) = [];
State.init(actualnum) = [];
State.offset(actualnum) = [];
State.un(actualnum) = [];
State.fn(actualnum) = [];
State.neq = State.neq - 1;
State.eqidx(actualnum) = [];
State.eq(actualnum) = [];
% initial variables
init_idx = strmatch([nome,'_0'],Initl.name,'exact');
Initl.name(init_idx) = [];
Initl.n = Initl.n - 1;
init_idx = strmatch([nome,'_0'],Initl.idx,'exact');
Initl.idx(init_idx) = [];
% GUI settings
if ~State.neq, set(hdl(10),'String',State.eq,'Value',1)
else, set(hdl(10),'String',fm_strjoin(State.eqidx,' = (',State.eq,')/',State.time),'Value',State.neq);
end
set(hdl(9),'String',Initl.name,'Value',max(Initl.n,1));
if isempty(Initl.idx), set(hdl(15),'String',' ','Value',1);
else, set(hdl(15),'String',Initl.idx,'Value',1);
end
case 'ListboxParameter'
Param.type(actualnum) = [];
Param.unit(actualnum) = [];
Param.descr(actualnum) = [];
end