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