0001 function [bus, gen, branch, areas] = int2ext(i2e, bus, gen, branch, areas)
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033
0034
0035
0036
0037
0038
0039
0040
0041
0042
0043
0044 if isstruct(i2e)
0045 mpc = i2e;
0046 if nargin == 1
0047 if ~isfield(mpc, 'order')
0048 error('int2ext: mpc does not have the ''order'' field required for conversion back to external numbering.');
0049 end
0050 o = mpc.order;
0051
0052 if o.state == 'i'
0053
0054 [PQ, PV, REF, NONE, BUS_I] = idx_bus;
0055 GEN_BUS = idx_gen;
0056 [F_BUS, T_BUS] = idx_brch;
0057
0058
0059 if isfield(mpc, 'userfcn')
0060 mpc = run_userfcn(mpc.userfcn, 'int2ext', mpc);
0061 end
0062
0063
0064 if isfield(mpc, 'gencost')
0065 ordering = {'gen'};
0066 if size(mpc.gencost, 1) == 2*size(mpc.gen, 1)
0067 ordering{2} = 'gen';
0068 end
0069 mpc = i2e_field(mpc, 'gencost', ordering);
0070 end
0071
0072
0073
0074 if isfield(mpc, 'A')
0075 o.int.A = mpc.A;
0076 mpc.A = o.ext.A;
0077 end
0078 if isfield(mpc, 'N')
0079 o.int.N = mpc.N;
0080 mpc.N = o.ext.N;
0081 end
0082
0083
0084 o.int.bus = mpc.bus;
0085 o.int.branch = mpc.branch;
0086 o.int.gen = mpc.gen;
0087 mpc.bus = o.ext.bus;
0088 mpc.branch = o.ext.branch;
0089 mpc.gen = o.ext.gen;
0090
0091
0092 nci = size(o.int.bus, 2);
0093 [nr, nc] = size(mpc.bus);
0094 if nc < nci
0095 mpc.bus = [mpc.bus zeros(nr, nci-nc)];
0096 end
0097 nci = size(o.int.branch, 2);
0098 [nr, nc] = size(mpc.branch);
0099 if nc < nci
0100 mpc.branch = [mpc.branch zeros(nr, nci-nc)];
0101 end
0102 nci = size(o.int.gen, 2);
0103 [nr, nc] = size(mpc.gen);
0104 if nc < nci
0105 mpc.gen = [mpc.gen zeros(nr, nci-nc)];
0106 end
0107
0108
0109 mpc.bus(o.bus.status.on, :) = o.int.bus;
0110 mpc.branch(o.branch.status.on, :) = o.int.branch;
0111 mpc.gen(o.gen.status.on, :) = o.int.gen(o.gen.i2e, :);
0112
0113
0114 mpc.bus(o.bus.status.on, BUS_I) = ...
0115 o.bus.i2e( mpc.bus(o.bus.status.on, BUS_I) );
0116 mpc.branch(o.branch.status.on, F_BUS) = ...
0117 o.bus.i2e( mpc.branch(o.branch.status.on, F_BUS) );
0118 mpc.branch(o.branch.status.on, T_BUS) = ...
0119 o.bus.i2e( mpc.branch(o.branch.status.on, T_BUS) );
0120 mpc.gen(o.gen.status.on, GEN_BUS) = ...
0121 o.bus.i2e( mpc.gen(o.gen.status.on, GEN_BUS) );
0122
0123 if isfield(o, 'ext')
0124 o = rmfield(o, 'ext');
0125 end
0126 o.state = 'e';
0127 mpc.order = o;
0128 else
0129 error('int2ext: mpc claims it is already using external numbering.');
0130 end
0131
0132 bus = mpc;
0133 else
0134 if ischar(bus) || iscell(bus)
0135 warning('Calls of the form MPC = INT2EXT(MPC, ''FIELD_NAME'', ...) have been deprecated. Please replace INT2EXT with I2E_FIELD.');
0136 if nargin > 3
0137 dim = branch;
0138 else
0139 dim = 1;
0140 end
0141 bus = i2e_field(mpc, bus, gen, dim);
0142 else
0143 warning('Calls of the form VAL = INT2EXT(MPC, VAL, ...) have been deprecated. Please replace INT2EXT with I2E_DATA.');
0144 if nargin > 4
0145 dim = areas;
0146 else
0147 dim = 1;
0148 end
0149 bus = i2e_data(mpc, bus, gen, branch, dim);
0150 end
0151 end
0152 else
0153
0154 [PQ, PV, REF, NONE, BUS_I] = idx_bus;
0155 [GEN_BUS] = idx_gen;
0156 [F_BUS, T_BUS] = idx_brch;
0157
0158 bus(:, BUS_I) = i2e( bus(:, BUS_I) );
0159 gen(:, GEN_BUS) = i2e( gen(:, GEN_BUS) );
0160 branch(:, F_BUS) = i2e( branch(:, F_BUS) );
0161 branch(:, T_BUS) = i2e( branch(:, T_BUS) );
0162 end