Home > matpower5.1 > printpf.m

printpf

PURPOSE ^

PRINTPF Prints power flow results.

SYNOPSIS ^

function printpf(baseMVA, bus, gen, branch, f, success, et, fd, mpopt)

DESCRIPTION ^

PRINTPF   Prints power flow results.
   PRINTPF(RESULTS, FD, MPOPT)
   PRINTPF(BASEMVA, BUS, GEN, BRANCH, F, SUCCESS, ET, FD, MPOPT)

   Prints power flow and optimal power flow results to FD (a file
   descriptor which defaults to STDOUT), with the details of what
   gets printed controlled by the optional MPOPT argument, which is a
   MATPOWER options struct (see MPOPTION for details).

   The data can either be supplied in a single RESULTS struct, or
   in the individual arguments: BASEMVA, BUS, GEN, BRANCH, F, SUCCESS
   and ET, where F is the OPF objective function value, SUCCESS is
   true if the solution converged and false otherwise, and ET is the
   elapsed time for the computation in seconds. If F is given, it is
   assumed that the output is from an OPF run, otherwise it is assumed
   to be a simple power flow run.

   Examples:
       mpopt = mpoptions('out.gen', 1, 'out.bus', 0, 'out.branch', 0);
       [fd, msg] = fopen(fname, 'at');
       results = runopf(mpc);
       printpf(results);
       printpf(results, fd);
       printpf(results, fd, mpopt);
       printpf(baseMVA, bus, gen, branch, f, success, et);
       printpf(baseMVA, bus, gen, branch, f, success, et, fd);
       printpf(baseMVA, bus, gen, branch, f, success, et, fd, mpopt);
       fclose(fd);

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function printpf(baseMVA, bus, gen, branch, f, success, et, fd, mpopt)
0002 %PRINTPF   Prints power flow results.
0003 %   PRINTPF(RESULTS, FD, MPOPT)
0004 %   PRINTPF(BASEMVA, BUS, GEN, BRANCH, F, SUCCESS, ET, FD, MPOPT)
0005 %
0006 %   Prints power flow and optimal power flow results to FD (a file
0007 %   descriptor which defaults to STDOUT), with the details of what
0008 %   gets printed controlled by the optional MPOPT argument, which is a
0009 %   MATPOWER options struct (see MPOPTION for details).
0010 %
0011 %   The data can either be supplied in a single RESULTS struct, or
0012 %   in the individual arguments: BASEMVA, BUS, GEN, BRANCH, F, SUCCESS
0013 %   and ET, where F is the OPF objective function value, SUCCESS is
0014 %   true if the solution converged and false otherwise, and ET is the
0015 %   elapsed time for the computation in seconds. If F is given, it is
0016 %   assumed that the output is from an OPF run, otherwise it is assumed
0017 %   to be a simple power flow run.
0018 %
0019 %   Examples:
0020 %       mpopt = mpoptions('out.gen', 1, 'out.bus', 0, 'out.branch', 0);
0021 %       [fd, msg] = fopen(fname, 'at');
0022 %       results = runopf(mpc);
0023 %       printpf(results);
0024 %       printpf(results, fd);
0025 %       printpf(results, fd, mpopt);
0026 %       printpf(baseMVA, bus, gen, branch, f, success, et);
0027 %       printpf(baseMVA, bus, gen, branch, f, success, et, fd);
0028 %       printpf(baseMVA, bus, gen, branch, f, success, et, fd, mpopt);
0029 %       fclose(fd);
0030 
0031 %   MATPOWER
0032 %   Copyright (c) 1996-2015 by Power System Engineering Research Center (PSERC)
0033 %   by Ray Zimmerman, PSERC Cornell
0034 %
0035 %   $Id: printpf.m 2644 2015-03-11 19:34:22Z ray $
0036 %
0037 %   This file is part of MATPOWER.
0038 %   Covered by the 3-clause BSD License (see LICENSE file for details).
0039 %   See http://www.pserc.cornell.edu/matpower/ for more info.
0040 
0041 %%----- initialization -----
0042 %% define named indices into bus, gen, branch matrices
0043 [PQ, PV, REF, NONE, BUS_I, BUS_TYPE, PD, QD, GS, BS, BUS_AREA, VM, ...
0044     VA, BASE_KV, ZONE, VMAX, VMIN, LAM_P, LAM_Q, MU_VMAX, MU_VMIN] = idx_bus;
0045 [GEN_BUS, PG, QG, QMAX, QMIN, VG, MBASE, GEN_STATUS, PMAX, PMIN, ...
0046     MU_PMAX, MU_PMIN, MU_QMAX, MU_QMIN, PC1, PC2, QC1MIN, QC1MAX, ...
0047     QC2MIN, QC2MAX, RAMP_AGC, RAMP_10, RAMP_30, RAMP_Q, APF] = idx_gen;
0048 [F_BUS, T_BUS, BR_R, BR_X, BR_B, RATE_A, RATE_B, RATE_C, ...
0049     TAP, SHIFT, BR_STATUS, PF, QF, PT, QT, MU_SF, MU_ST, ...
0050     ANGMIN, ANGMAX, MU_ANGMIN, MU_ANGMAX] = idx_brch;
0051 
0052 %% default arguments
0053 if isstruct(baseMVA)
0054     have_results_struct = 1;
0055     results = baseMVA;
0056     if nargin < 3 || isempty(gen)
0057         mpopt = mpoption;   %% use default options
0058     else
0059         mpopt = gen;
0060     end
0061     if mpopt.out.all == 0
0062         return;         %% nothin' to see here, bail out now
0063     end
0064     if nargin < 2 || isempty(bus)
0065         fd = 1;         %% print to stdio by default
0066     else
0067         fd = bus;
0068     end
0069     [baseMVA, bus, gen, branch, success, et] = ...
0070         deal(results.baseMVA, results.bus, results.gen, results.branch, ...
0071             results.success, results.et);
0072     if isfield(results, 'f') && ~isempty(results.f)
0073         f = results.f;
0074     else
0075         f = [];
0076     end
0077 else
0078     have_results_struct = 0;
0079     if nargin < 9
0080         mpopt = mpoption;   %% use default options
0081         if nargin < 8
0082             fd = 1;         %% print to stdio by default
0083         end
0084     end
0085     if mpopt.out.all == 0
0086         return;         %% nothin' to see here, bail out now
0087     end
0088 end
0089 isOPF = ~isempty(f);    %% FALSE -> only simple PF data, TRUE -> OPF data
0090 
0091 %% options
0092 isDC            = strcmp(upper(mpopt.model), 'DC');
0093 
0094 SUPPRESS        = mpopt.out.suppress_detail;
0095 if SUPPRESS == -1
0096     if size(bus, 1) > 500
0097         SUPPRESS = 1;
0098     else
0099         SUPPRESS = 0;
0100     end
0101 end
0102 OUT_ALL         = mpopt.out.all;
0103 OUT_FORCE       = mpopt.out.force;
0104 OUT_ANY         = OUT_ALL == 1;     %% set to true if any pretty output is to be generated
0105 OUT_SYS_SUM     = OUT_ALL == 1 || (OUT_ALL == -1 && mpopt.out.sys_sum);
0106 OUT_AREA_SUM    = OUT_ALL == 1 || (OUT_ALL == -1 && ~SUPPRESS && mpopt.out.area_sum);
0107 OUT_BUS         = OUT_ALL == 1 || (OUT_ALL == -1 && ~SUPPRESS && mpopt.out.bus);
0108 OUT_BRANCH      = OUT_ALL == 1 || (OUT_ALL == -1 && ~SUPPRESS && mpopt.out.branch);
0109 OUT_GEN         = OUT_ALL == 1 || (OUT_ALL == -1 && ~SUPPRESS && mpopt.out.gen);
0110 OUT_ANY         = OUT_ANY || (OUT_ALL == -1 && ...
0111                     (OUT_SYS_SUM || OUT_AREA_SUM || OUT_BUS || ...
0112                     OUT_BRANCH || OUT_GEN));
0113 if OUT_ALL == -1
0114     OUT_ALL_LIM = ~SUPPRESS * mpopt.out.lim.all;
0115 elseif OUT_ALL == 1
0116     OUT_ALL_LIM = 2;
0117 else
0118     OUT_ALL_LIM = 0;
0119 end
0120 OUT_ANY         = OUT_ANY || OUT_ALL_LIM >= 1;
0121 if OUT_ALL_LIM == -1
0122     OUT_V_LIM       = ~SUPPRESS * mpopt.out.lim.v;
0123     OUT_LINE_LIM    = ~SUPPRESS * mpopt.out.lim.line;
0124     OUT_PG_LIM      = ~SUPPRESS * mpopt.out.lim.pg;
0125     OUT_QG_LIM      = ~SUPPRESS * mpopt.out.lim.qg;
0126 else
0127     OUT_V_LIM       = OUT_ALL_LIM;
0128     OUT_LINE_LIM    = OUT_ALL_LIM;
0129     OUT_PG_LIM      = OUT_ALL_LIM;
0130     OUT_QG_LIM      = OUT_ALL_LIM;
0131 end
0132 OUT_ANY         = OUT_ANY || (OUT_ALL_LIM == -1 && (OUT_V_LIM || OUT_LINE_LIM || OUT_PG_LIM || OUT_QG_LIM));
0133 
0134 %%----- print the stuff -----
0135 if OUT_ANY
0136     ptol = 1e-4;        %% tolerance for displaying shadow prices
0137     if isOPF && ~isDC && strcmp(upper(mpopt.opf.ac.solver), 'SDPOPF')
0138         isSDP = 1;
0139         ptol = 0.1;     %% tolerance for displaying shadow prices
0140         if have_results_struct && isfield(results, 'mineigratio') && ~isempty(results.mineigratio)
0141             mineigratio = results.mineigratio;
0142         else
0143             mineigratio = [];
0144         end
0145         if have_results_struct && isfield(results, 'zero_eval') && ~isempty(results.zero_eval)
0146             zero_eval = results.zero_eval;
0147         else
0148             zero_eval = [];
0149         end
0150     else
0151         isSDP = 0;
0152     end
0153 
0154     %% create map of external bus numbers to bus indices
0155     i2e = bus(:, BUS_I);
0156     e2i = sparse(max(i2e), 1);
0157     e2i(i2e) = (1:size(bus, 1))';
0158 
0159     %% sizes of things
0160     nb = size(bus, 1);      %% number of buses
0161     nl = size(branch, 1);   %% number of branches
0162     ng = size(gen, 1);      %% number of generators
0163 
0164     %% zero out some data to make printout consistent for DC case
0165     if isDC
0166         bus(:, [QD, BS])            = zeros(nb, 2);
0167         gen(:, [QG, QMAX, QMIN])    = zeros(ng, 3);
0168         branch(:, [BR_R, BR_B])     = zeros(nl, 2);
0169     end
0170 
0171     %% parameters
0172     ties = find(bus(e2i(branch(:, F_BUS)), BUS_AREA) ~= bus(e2i(branch(:, T_BUS)), BUS_AREA));
0173                             %% area inter-ties
0174     xfmr = find(branch(:, TAP));                    %% indices of transformers
0175     nzld = find((bus(:, PD) | bus(:, QD)) & bus(:, BUS_TYPE) ~= NONE);
0176     sorted_areas = sort(bus(:, BUS_AREA));
0177     s_areas = sorted_areas([1; find(diff(sorted_areas))+1]);    %% area numbers
0178     nzsh = find((bus(:, GS) | bus(:, BS)) & bus(:, BUS_TYPE) ~= NONE);
0179     allg = find( ~isload(gen) );
0180     alld = find(  isload(gen) );
0181     ong  = find( gen(:, GEN_STATUS) > 0 & ~isload(gen) );
0182     onld = find( gen(:, GEN_STATUS) > 0 &  isload(gen) );
0183     V = bus(:, VM) .* exp(sqrt(-1) * pi/180 * bus(:, VA));
0184     if isDC
0185         loss = zeros(nl, 1);
0186         fchg = loss;
0187         tchg = loss;
0188     else
0189         [loss, fchg, tchg] = get_losses(baseMVA, bus, branch);
0190     end
0191 
0192     %% convergence & elapsed time
0193     if success
0194         if isSDP
0195             fprintf(fd, '\nSolution satisfies rank and consistency conditions, %.2f seconds.\nmineigratio = %0.5g, zero_eval = %0.5g', et, mineigratio, zero_eval);
0196         else
0197             fprintf(fd, '\nConverged in %.2f seconds', et);
0198         end
0199     else
0200         if isSDP
0201             fprintf(fd, '\n>>>>>  Solution does NOT satisfy rank and/or consistency conditions (%.2f seconds).  <<<<<\nmineigratio = %0.5g, zero_eval = %0.5g\n', et, mineigratio, zero_eval);
0202         else
0203             fprintf(fd, '\n>>>>>  Did NOT converge (%.2f seconds)  <<<<<\n', et);
0204         end
0205     end
0206 
0207     %% objective function value
0208     if isOPF && (success || OUT_FORCE)
0209         fprintf(fd, '\nObjective Function Value = %.2f $/hr', f);
0210     end
0211 end
0212 if OUT_SYS_SUM && (success || OUT_FORCE)
0213     fprintf(fd, '\n================================================================================');
0214     fprintf(fd, '\n|     System Summary                                                           |');
0215     fprintf(fd, '\n================================================================================');
0216     fprintf(fd, '\n\nHow many?                How much?              P (MW)            Q (MVAr)');
0217     fprintf(fd, '\n---------------------    -------------------  -------------  -----------------');
0218     fprintf(fd, '\nBuses         %6d     Total Gen Capacity   %7.1f       %7.1f to %.1f', nb, sum(gen(allg, PMAX)), sum(gen(allg, QMIN)), sum(gen(allg, QMAX)));
0219     fprintf(fd, '\nGenerators     %5d     On-line Capacity     %7.1f       %7.1f to %.1f', length(allg), sum(gen(ong, PMAX)), sum(gen(ong, QMIN)), sum(gen(ong, QMAX)));
0220     fprintf(fd, '\nCommitted Gens %5d     Generation (actual)  %7.1f           %7.1f', length(ong), sum(gen(ong, PG)), sum(gen(ong, QG)));
0221     fprintf(fd, '\nLoads          %5d     Load                 %7.1f           %7.1f', length(nzld)+length(onld), sum(bus(nzld, PD))-sum(gen(onld, PG)), sum(bus(nzld, QD))-sum(gen(onld, QG)));
0222     fprintf(fd, '\n  Fixed        %5d       Fixed              %7.1f           %7.1f', length(nzld), sum(bus(nzld, PD)), sum(bus(nzld, QD)));
0223     fprintf(fd, '\n  Dispatchable %5d       Dispatchable       %7.1f of %-7.1f%7.1f', length(onld), -sum(gen(onld, PG)), -sum(gen(onld, PMIN)), -sum(gen(onld, QG)));
0224     fprintf(fd, '\nShunts         %5d     Shunt (inj)          %7.1f           %7.1f', length(nzsh), ...
0225         -sum(bus(nzsh, VM) .^ 2 .* bus(nzsh, GS)), sum(bus(nzsh, VM) .^ 2 .* bus(nzsh, BS)) );
0226     fprintf(fd, '\nBranches       %5d     Losses (I^2 * Z)     %8.2f          %8.2f', nl, sum(real(loss)), sum(imag(loss)) );
0227     fprintf(fd, '\nTransformers   %5d     Branch Charging (inj)     -            %7.1f', length(xfmr), sum(fchg) + sum(tchg) );
0228     fprintf(fd, '\nInter-ties     %5d     Total Inter-tie Flow %7.1f           %7.1f', length(ties), sum(abs(branch(ties, PF)-branch(ties, PT))) / 2, sum(abs(branch(ties, QF)-branch(ties, QT))) / 2);
0229     fprintf(fd, '\nAreas          %5d', length(s_areas));
0230     fprintf(fd, '\n');
0231     fprintf(fd, '\n                          Minimum                      Maximum');
0232     fprintf(fd, '\n                 -------------------------  --------------------------------');
0233     [minv, mini] = min(bus(:, VM));
0234     [maxv, maxi] = max(bus(:, VM));
0235     fprintf(fd, '\nVoltage Magnitude %7.3f p.u. @ bus %-4d     %7.3f p.u. @ bus %-4d', minv, bus(mini, BUS_I), maxv, bus(maxi, BUS_I));
0236     [minv, mini] = min(bus(:, VA));
0237     [maxv, maxi] = max(bus(:, VA));
0238     fprintf(fd, '\nVoltage Angle   %8.2f deg   @ bus %-4d   %8.2f deg   @ bus %-4d', minv, bus(mini, BUS_I), maxv, bus(maxi, BUS_I));
0239     if ~isDC
0240         [maxv, maxi] = max(real(loss));
0241         fprintf(fd, '\nP Losses (I^2*R)             -              %8.2f MW    @ line %d-%d', maxv, branch(maxi, F_BUS), branch(maxi, T_BUS));
0242         [maxv, maxi] = max(imag(loss));
0243         fprintf(fd, '\nQ Losses (I^2*X)             -              %8.2f MVAr  @ line %d-%d', maxv, branch(maxi, F_BUS), branch(maxi, T_BUS));
0244     end
0245     if isOPF
0246         [minv, mini] = min(bus(:, LAM_P));
0247         [maxv, maxi] = max(bus(:, LAM_P));
0248         fprintf(fd, '\nLambda P        %8.2f $/MWh @ bus %-4d   %8.2f $/MWh @ bus %-4d', minv, bus(mini, BUS_I), maxv, bus(maxi, BUS_I));
0249         [minv, mini] = min(bus(:, LAM_Q));
0250         [maxv, maxi] = max(bus(:, LAM_Q));
0251         fprintf(fd, '\nLambda Q        %8.2f $/MWh @ bus %-4d   %8.2f $/MWh @ bus %-4d', minv, bus(mini, BUS_I), maxv, bus(maxi, BUS_I));
0252     end
0253     fprintf(fd, '\n');
0254 end
0255 
0256 if OUT_AREA_SUM && (success || OUT_FORCE)
0257     fprintf(fd, '\n================================================================================');
0258     fprintf(fd, '\n|     Area Summary                                                             |');
0259     fprintf(fd, '\n================================================================================');
0260     fprintf(fd, '\nArea  # of      # of Gens        # of Loads         # of    # of   # of   # of');
0261     fprintf(fd, '\n Num  Buses   Total  Online   Total  Fixed  Disp    Shunt   Brchs  Xfmrs   Ties');
0262     fprintf(fd, '\n----  -----   -----  ------   -----  -----  -----   -----   -----  -----  -----');
0263     for i=1:length(s_areas)
0264         a = s_areas(i);
0265         ib = find(bus(:, BUS_AREA) == a);
0266         ig = find(bus(e2i(gen(:, GEN_BUS)), BUS_AREA) == a & ~isload(gen));
0267         igon = find(bus(e2i(gen(:, GEN_BUS)), BUS_AREA) == a & gen(:, GEN_STATUS) > 0 & ~isload(gen));
0268         ildon = find(bus(e2i(gen(:, GEN_BUS)), BUS_AREA) == a & gen(:, GEN_STATUS) > 0 & isload(gen));
0269         inzld = find(bus(:, BUS_AREA) == a & (bus(:, PD) | bus(:, QD)) & bus(:, BUS_TYPE) ~= NONE);
0270         inzsh = find(bus(:, BUS_AREA) == a & (bus(:, GS) | bus(:, BS)) & bus(:, BUS_TYPE) ~= NONE);
0271         ibrch = find(bus(e2i(branch(:, F_BUS)), BUS_AREA) == a & bus(e2i(branch(:, T_BUS)), BUS_AREA) == a);
0272         in_tie = find(bus(e2i(branch(:, F_BUS)), BUS_AREA) == a & bus(e2i(branch(:, T_BUS)), BUS_AREA) ~= a);
0273         out_tie = find(bus(e2i(branch(:, F_BUS)), BUS_AREA) ~= a & bus(e2i(branch(:, T_BUS)), BUS_AREA) == a);
0274         if isempty(xfmr)
0275             nxfmr = 0;
0276         else
0277             nxfmr = length(find(bus(e2i(branch(xfmr, F_BUS)), BUS_AREA) == a & bus(e2i(branch(xfmr, T_BUS)), BUS_AREA) == a));
0278         end
0279         fprintf(fd, '\n%3d  %6d   %5d  %5d   %5d  %5d  %5d   %5d   %5d  %5d  %5d', ...
0280             a, length(ib), length(ig), length(igon), ...
0281             length(inzld)+length(ildon), length(inzld), length(ildon), ...
0282             length(inzsh), length(ibrch), nxfmr, length(in_tie)+length(out_tie));
0283     end
0284     fprintf(fd, '\n----  -----   -----  ------   -----  -----  -----   -----   -----  -----  -----');
0285     fprintf(fd, '\nTot: %6d   %5d  %5d   %5d  %5d  %5d   %5d   %5d  %5d  %5d', ...
0286         nb, length(allg), length(ong), length(nzld)+length(onld), ...
0287         length(nzld), length(onld), length(nzsh), nl, length(xfmr), length(ties));
0288     fprintf(fd, '\n');
0289     fprintf(fd, '\nArea      Total Gen Capacity           On-line Gen Capacity         Generation');
0290     fprintf(fd, '\n Num     MW           MVAr            MW           MVAr             MW    MVAr');
0291     fprintf(fd, '\n----   ------  ------------------   ------  ------------------    ------  ------');
0292     for i=1:length(s_areas)
0293         a = s_areas(i);
0294         ig = find(bus(e2i(gen(:, GEN_BUS)), BUS_AREA) == a & ~isload(gen));
0295         igon = find(bus(e2i(gen(:, GEN_BUS)), BUS_AREA) == a & gen(:, GEN_STATUS) > 0 & ~isload(gen));
0296         fprintf(fd, '\n%3d   %7.1f  %7.1f to %-7.1f  %7.1f  %7.1f to %-7.1f   %7.1f %7.1f', ...
0297             a, sum(gen(ig, PMAX)), sum(gen(ig, QMIN)), sum(gen(ig, QMAX)), ...
0298             sum(gen(igon, PMAX)), sum(gen(igon, QMIN)), sum(gen(igon, QMAX)), ...
0299             sum(gen(igon, PG)), sum(gen(igon, QG)) );
0300     end
0301     fprintf(fd, '\n----   ------  ------------------   ------  ------------------    ------  ------');
0302     fprintf(fd, '\nTot:  %7.1f  %7.1f to %-7.1f  %7.1f  %7.1f to %-7.1f   %7.1f %7.1f', ...
0303             sum(gen(allg, PMAX)), sum(gen(allg, QMIN)), sum(gen(allg, QMAX)), ...
0304             sum(gen(ong, PMAX)), sum(gen(ong, QMIN)), sum(gen(ong, QMAX)), ...
0305             sum(gen(ong, PG)), sum(gen(ong, QG)) );
0306     fprintf(fd, '\n');
0307     fprintf(fd, '\nArea    Disp Load Cap       Disp Load         Fixed Load        Total Load');
0308     fprintf(fd, '\n Num      MW     MVAr       MW     MVAr       MW     MVAr       MW     MVAr');
0309     fprintf(fd, '\n----    ------  ------    ------  ------    ------  ------    ------  ------');
0310     Qlim = (gen(:, QMIN) == 0) .* gen(:, QMAX) + (gen(:, QMAX) == 0) .* gen(:, QMIN);
0311     for i=1:length(s_areas)
0312         a = s_areas(i);
0313         ildon = find(bus(e2i(gen(:, GEN_BUS)), BUS_AREA) == a & gen(:, GEN_STATUS) > 0 & isload(gen));
0314         inzld = find(bus(:, BUS_AREA) == a & (bus(:, PD) | bus(:, QD)));
0315         fprintf(fd, '\n%3d    %7.1f %7.1f   %7.1f %7.1f   %7.1f %7.1f   %7.1f %7.1f', ...
0316             a, -sum(gen(ildon, PMIN)), ...
0317             -sum(Qlim(ildon)), ...
0318             -sum(gen(ildon, PG)), -sum(gen(ildon, QG)), ...
0319             sum(bus(inzld, PD)), sum(bus(inzld, QD)), ...
0320             -sum(gen(ildon, PG)) + sum(bus(inzld, PD)), ...
0321             -sum(gen(ildon, QG)) + sum(bus(inzld, QD)) );
0322     end
0323     fprintf(fd, '\n----    ------  ------    ------  ------    ------  ------    ------  ------');
0324     fprintf(fd, '\nTot:   %7.1f %7.1f   %7.1f %7.1f   %7.1f %7.1f   %7.1f %7.1f', ...
0325             -sum(gen(onld, PMIN)), ...
0326             -sum(Qlim(onld)), ...
0327             -sum(gen(onld, PG)), -sum(gen(onld, QG)), ...
0328             sum(bus(nzld, PD)), sum(bus(nzld, QD)), ...
0329             -sum(gen(onld, PG)) + sum(bus(nzld, PD)), ...
0330             -sum(gen(onld, QG)) + sum(bus(nzld, QD)) );
0331     fprintf(fd, '\n');
0332     fprintf(fd, '\nArea      Shunt Inj        Branch      Series Losses      Net Export');
0333     fprintf(fd, '\n Num      MW     MVAr     Charging      MW     MVAr       MW     MVAr');
0334     fprintf(fd, '\n----    ------  ------    --------    ------  ------    ------  ------');
0335     for i=1:length(s_areas)
0336         a = s_areas(i);
0337         inzsh = find(bus(:, BUS_AREA) == a & (bus(:, GS) | bus(:, BS)));
0338         ibrch = find(bus(e2i(branch(:, F_BUS)), BUS_AREA) == a & bus(e2i(branch(:, T_BUS)), BUS_AREA) == a & branch(:, BR_STATUS));
0339         in_tie = find(bus(e2i(branch(:, F_BUS)), BUS_AREA) ~= a & bus(e2i(branch(:, T_BUS)), BUS_AREA) == a & branch(:, BR_STATUS));
0340         out_tie = find(bus(e2i(branch(:, F_BUS)), BUS_AREA) == a & bus(e2i(branch(:, T_BUS)), BUS_AREA) ~= a & branch(:, BR_STATUS));
0341         fprintf(fd, '\n%3d    %7.1f %7.1f    %7.1f    %7.2f %7.2f   %7.1f %7.1f', ...
0342             a, -sum(bus(inzsh, VM) .^ 2 .* bus(inzsh, GS)), ...
0343             sum(bus(inzsh, VM) .^ 2 .* bus(inzsh, BS)), ...
0344             sum(fchg(ibrch)) + sum(tchg(ibrch)) + sum(fchg(out_tie)) + sum(tchg(in_tie)), ...
0345             sum(real(loss(ibrch))) + sum(real(loss([in_tie; out_tie]))) / 2, ...
0346             sum(imag(loss(ibrch))) + sum(imag(loss([in_tie; out_tie]))) / 2, ...
0347             sum(branch(in_tie, PT))+sum(branch(out_tie, PF)) - sum(real(loss([in_tie; out_tie]))) / 2, ...
0348             sum(branch(in_tie, QT))+sum(branch(out_tie, QF)) - sum(imag(loss([in_tie; out_tie]))) / 2  );
0349     end
0350     fprintf(fd, '\n----    ------  ------    --------    ------  ------    ------  ------');
0351     fprintf(fd, '\nTot:   %7.1f %7.1f    %7.1f    %7.2f %7.2f       -       -', ...
0352         -sum(bus(nzsh, VM) .^ 2 .* bus(nzsh, GS)), ...
0353         sum(bus(nzsh, VM) .^ 2 .* bus(nzsh, BS)), ...
0354         sum(fchg) + sum(tchg), sum(real(loss)), sum(imag(loss)) );
0355     fprintf(fd, '\n');
0356 end
0357 
0358 %% generator data
0359 if OUT_GEN && (success || OUT_FORCE)
0360     if isOPF
0361         genlamP = bus(e2i(gen(:, GEN_BUS)), LAM_P);
0362         genlamQ = bus(e2i(gen(:, GEN_BUS)), LAM_Q);
0363     end
0364     fprintf(fd, '\n================================================================================');
0365     fprintf(fd, '\n|     Generator Data                                                           |');
0366     fprintf(fd, '\n================================================================================');
0367     fprintf(fd, '\n Gen   Bus   Status     Pg        Qg   ');
0368     if isOPF, fprintf(fd, '   Lambda ($/MVA-hr)'); end
0369     fprintf(fd, '\n  #     #              (MW)     (MVAr) ');
0370     if isOPF, fprintf(fd, '     P         Q    '); end
0371     fprintf(fd, '\n----  -----  ------  --------  --------');
0372     if isOPF, fprintf(fd, '  --------  --------'); end
0373     for k = 1:length(allg)
0374         i = allg(k);
0375         fprintf(fd, '\n%3d %6d     %2d ', i, gen(i, GEN_BUS), gen(i, GEN_STATUS));
0376         if gen(i, GEN_STATUS) > 0 && (gen(i, PG) || gen(i, QG))
0377             fprintf(fd, '%10.2f%10.2f', gen(i, PG), gen(i, QG));
0378         else
0379             fprintf(fd, '       -         -  ');
0380         end
0381         if isOPF, fprintf(fd, '%10.2f%10.2f', genlamP(i), genlamQ(i)); end
0382     end
0383     fprintf(fd, '\n                     --------  --------');
0384     fprintf(fd, '\n            Total: %9.2f%10.2f', sum(gen(ong, PG)), sum(gen(ong, QG)));
0385     fprintf(fd, '\n');
0386     if ~isempty(alld)
0387         fprintf(fd, '\n================================================================================');
0388         fprintf(fd, '\n|     Dispatchable Load Data                                                   |');
0389         fprintf(fd, '\n================================================================================');
0390         fprintf(fd, '\n Gen   Bus   Status     Pd        Qd   ');
0391         if isOPF, fprintf(fd, '   Lambda ($/MVA-hr)'); end
0392         fprintf(fd, '\n  #     #              (MW)     (MVAr) ');
0393         if isOPF, fprintf(fd, '     P         Q    '); end
0394         fprintf(fd, '\n----  -----  ------  --------  --------');
0395         if isOPF, fprintf(fd, '  --------  --------'); end
0396         for k = 1:length(alld)
0397             i = alld(k);
0398             fprintf(fd, '\n%3d %6d     %2d ', i, gen(i, GEN_BUS), gen(i, GEN_STATUS));
0399             if gen(i, GEN_STATUS) > 0 && (gen(i, PG) || gen(i, QG))
0400                 fprintf(fd, '%10.2f%10.2f', -gen(i, PG), -gen(i, QG));
0401             else
0402                 fprintf(fd, '       -         -  ');
0403             end
0404             if isOPF, fprintf(fd, '%10.2f%10.2f', genlamP(i), genlamQ(i)); end
0405         end
0406         fprintf(fd, '\n                     --------  --------');
0407         fprintf(fd, '\n            Total: %9.2f%10.2f', -sum(gen(onld, PG)), -sum(gen(onld, QG)));
0408         fprintf(fd, '\n');
0409     end
0410 end
0411 
0412 %% bus data
0413 if OUT_BUS && (success || OUT_FORCE)
0414     fprintf(fd, '\n================================================================================');
0415     fprintf(fd, '\n|     Bus Data                                                                 |');
0416     fprintf(fd, '\n================================================================================');
0417     fprintf(fd, '\n Bus      Voltage          Generation             Load        ');
0418     if isOPF, fprintf(fd, '  Lambda($/MVA-hr)'); end
0419     fprintf(fd, '\n  #   Mag(pu) Ang(deg)   P (MW)   Q (MVAr)   P (MW)   Q (MVAr)');
0420     if isOPF, fprintf(fd, '     P        Q   '); end
0421     fprintf(fd, '\n----- ------- --------  --------  --------  --------  --------');
0422     if isOPF, fprintf(fd, '  -------  -------'); end
0423     for i = 1:nb
0424         fprintf(fd, '\n%5d%7.3f%9.3f', bus(i, [BUS_I, VM, VA]));
0425         if bus(i, BUS_TYPE) == REF
0426             fprintf(fd, '*');
0427         elseif bus(i, BUS_TYPE) == NONE
0428             fprintf(fd, 'x');
0429         else
0430             fprintf(fd, ' ');
0431         end
0432         g  = find(gen(:, GEN_STATUS) > 0 & gen(:, GEN_BUS) == bus(i, BUS_I) & ...
0433                     ~isload(gen));
0434         ld = find(gen(:, GEN_STATUS) > 0 & gen(:, GEN_BUS) == bus(i, BUS_I) & ...
0435                     isload(gen));
0436         if ~isempty(g)
0437             fprintf(fd, '%9.2f%10.2f', sum(gen(g, PG)), sum(gen(g, QG)));
0438         else
0439             fprintf(fd, '      -         -  ');
0440         end
0441         if bus(i, PD) || bus(i, QD) || ~isempty(ld)
0442             if ~isempty(ld)
0443                 fprintf(fd, '%10.2f*%9.2f*', bus(i, PD) - sum(gen(ld, PG)), ...
0444                                              bus(i, QD) - sum(gen(ld, QG)));
0445             else
0446                 fprintf(fd, '%10.2f%10.2f ', bus(i, [PD, QD]));
0447             end
0448         else
0449             fprintf(fd, '       -         -   ');
0450         end
0451         if isOPF
0452             fprintf(fd, '%9.3f', bus(i, LAM_P));
0453             if abs(bus(i, LAM_Q)) > ptol
0454                 fprintf(fd, '%8.3f', bus(i, LAM_Q));
0455             else
0456                 fprintf(fd, '     -');
0457             end
0458         end
0459     end
0460     fprintf(fd, '\n                        --------  --------  --------  --------');
0461     fprintf(fd, '\n               Total: %9.2f %9.2f %9.2f %9.2f', ...
0462         sum(gen(ong, PG)), sum(gen(ong, QG)), ...
0463         sum(bus(nzld, PD)) - sum(gen(onld, PG)), ...
0464         sum(bus(nzld, QD)) - sum(gen(onld, QG)));
0465     fprintf(fd, '\n');
0466 end
0467 
0468 %% branch data
0469 if OUT_BRANCH && (success || OUT_FORCE)
0470     fprintf(fd, '\n================================================================================');
0471     fprintf(fd, '\n|     Branch Data                                                              |');
0472     fprintf(fd, '\n================================================================================');
0473     fprintf(fd, '\nBrnch   From   To    From Bus Injection   To Bus Injection     Loss (I^2 * Z)  ');
0474     fprintf(fd, '\n  #     Bus    Bus    P (MW)   Q (MVAr)   P (MW)   Q (MVAr)   P (MW)   Q (MVAr)');
0475     fprintf(fd, '\n-----  -----  -----  --------  --------  --------  --------  --------  --------');
0476     fprintf(fd, '\n%4d%7d%7d%10.2f%10.2f%10.2f%10.2f%10.3f%10.2f', ...
0477             [   (1:nl)', branch(:, [F_BUS, T_BUS]), ...
0478                 branch(:, [PF, QF]), branch(:, [PT, QT]), ...
0479                 real(loss), imag(loss) ...
0480             ]');
0481     fprintf(fd, '\n                                                             --------  --------');
0482     fprintf(fd, '\n                                                    Total:%10.3f%10.2f', ...
0483             sum(real(loss)), sum(imag(loss)));
0484     fprintf(fd, '\n');
0485 end
0486 
0487 %%-----  constraint data  -----
0488 if isOPF && (success || OUT_FORCE)
0489     ctol = mpopt.opf.violation; %% constraint violation tolerance
0490     %% voltage constraints
0491     if ~isDC && (OUT_V_LIM == 2 || (OUT_V_LIM == 1 && ...
0492                          (any(bus(:, VM) < bus(:, VMIN) + ctol) || ...
0493                           any(bus(:, VM) > bus(:, VMAX) - ctol) || ...
0494                           any(bus(:, MU_VMIN) > ptol) || ...
0495                           any(bus(:, MU_VMAX) > ptol))))
0496         fprintf(fd, '\n================================================================================');
0497         fprintf(fd, '\n|     Voltage Constraints                                                      |');
0498         fprintf(fd, '\n================================================================================');
0499         fprintf(fd, '\nBus #  Vmin mu    Vmin    |V|   Vmax    Vmax mu');
0500         fprintf(fd, '\n-----  --------   -----  -----  -----   --------');
0501         for i = 1:nb
0502             if OUT_V_LIM == 2 || (OUT_V_LIM == 1 && ...
0503                          (bus(i, VM) < bus(i, VMIN) + ctol || ...
0504                           bus(i, VM) > bus(i, VMAX) - ctol || ...
0505                           bus(i, MU_VMIN) > ptol || bus(i, MU_VMAX) > ptol))
0506                 fprintf(fd, '\n%5d', bus(i, BUS_I));
0507                 if bus(i, VM) < bus(i, VMIN) + ctol || bus(i, MU_VMIN) > ptol
0508                     fprintf(fd, '%10.3f', bus(i, MU_VMIN));
0509                 else
0510                     fprintf(fd, '      -   ');
0511                 end
0512                 fprintf(fd, '%8.3f%7.3f%7.3f', bus(i, [VMIN, VM, VMAX]));
0513                 if bus(i, VM) > bus(i, VMAX) - ctol || bus(i, MU_VMAX) > ptol
0514                     fprintf(fd, '%10.3f', bus(i, MU_VMAX));
0515                 else
0516                     fprintf(fd, '      -    ');
0517                 end
0518             end
0519         end
0520         fprintf(fd, '\n');
0521     end
0522 
0523     %% generator P constraints
0524     if OUT_PG_LIM == 2 || ...
0525             (OUT_PG_LIM == 1 && (any(gen(ong, PG) < gen(ong, PMIN) + ctol) || ...
0526                                 any(gen(ong, PG) > gen(ong, PMAX) - ctol) || ...
0527                                 any(gen(ong, MU_PMIN) > ptol) || ...
0528                                 any(gen(ong, MU_PMAX) > ptol))) || ...
0529             (~isDC && (OUT_QG_LIM == 2 || ...
0530             (OUT_QG_LIM == 1 && (any(gen(ong, QG) < gen(ong, QMIN) + ctol) || ...
0531                                 any(gen(ong, QG) > gen(ong, QMAX) - ctol) || ...
0532                                 any(gen(ong, MU_QMIN) > ptol) || ...
0533                                 any(gen(ong, MU_QMAX) > ptol)))))
0534         fprintf(fd, '\n================================================================================');
0535         fprintf(fd, '\n|     Generation Constraints                                                   |');
0536         fprintf(fd, '\n================================================================================');
0537     end
0538     if OUT_PG_LIM == 2 || (OUT_PG_LIM == 1 && ...
0539                              (any(gen(ong, PG) < gen(ong, PMIN) + ctol) || ...
0540                               any(gen(ong, PG) > gen(ong, PMAX) - ctol) || ...
0541                               any(gen(ong, MU_PMIN) > ptol) || ...
0542                               any(gen(ong, MU_PMAX) > ptol)))
0543         fprintf(fd, '\n Gen   Bus                  Active Power Limits');
0544         fprintf(fd, '\n  #     #     Pmin mu     Pmin       Pg       Pmax    Pmax mu');
0545         fprintf(fd, '\n----  -----   -------   --------  --------  --------  -------');
0546         for k = 1:length(ong)
0547             i = ong(k);
0548             if OUT_PG_LIM == 2 || (OUT_PG_LIM == 1 && ...
0549                         (gen(i, PG) < gen(i, PMIN) + ctol || ...
0550                          gen(i, PG) > gen(i, PMAX) - ctol || ...
0551                          gen(i, MU_PMIN) > ptol || gen(i, MU_PMAX) > ptol))
0552                 fprintf(fd, '\n%4d%6d ', i, gen(i, GEN_BUS));
0553                 if gen(i, PG) < gen(i, PMIN) + ctol || gen(i, MU_PMIN) > ptol
0554                     fprintf(fd, '%10.3f', gen(i, MU_PMIN));
0555                 else
0556                     fprintf(fd, '      -   ');
0557                 end
0558                 if gen(i, PG)
0559                     fprintf(fd, '%10.2f%10.2f%10.2f', gen(i, [PMIN, PG, PMAX]));
0560                 else
0561                     fprintf(fd, '%10.2f       -  %10.2f', gen(i, [PMIN, PMAX]));
0562                 end
0563                 if gen(i, PG) > gen(i, PMAX) - ctol || gen(i, MU_PMAX) > ptol
0564                     fprintf(fd, '%10.3f', gen(i, MU_PMAX));
0565                 else
0566                     fprintf(fd, '      -   ');
0567                 end
0568             end
0569         end
0570         fprintf(fd, '\n');
0571     end
0572 
0573     %% generator Q constraints
0574     if ~isDC && (OUT_QG_LIM == 2 || (OUT_QG_LIM == 1 && ...
0575                              (any(gen(ong, QG) < gen(ong, QMIN) + ctol) || ...
0576                               any(gen(ong, QG) > gen(ong, QMAX) - ctol) || ...
0577                               any(gen(ong, MU_QMIN) > ptol) || ...
0578                               any(gen(ong, MU_QMAX) > ptol))))
0579         fprintf(fd, '\n Gen   Bus                 Reactive Power Limits');
0580         fprintf(fd, '\n  #     #     Qmin mu     Qmin       Qg       Qmax    Qmax mu');
0581         fprintf(fd, '\n----  -----   -------   --------  --------  --------  -------');
0582         for k = 1:length(ong)
0583             i = ong(k);
0584             if OUT_QG_LIM == 2 || (OUT_QG_LIM == 1 && ...
0585                         (gen(i, QG) < gen(i, QMIN) + ctol || ...
0586                          gen(i, QG) > gen(i, QMAX) - ctol || ...
0587                          gen(i, MU_QMIN) > ptol || gen(i, MU_QMAX) > ptol))
0588                 fprintf(fd, '\n%4d%6d ', i, gen(i, GEN_BUS));
0589                 if gen(i, QG) < gen(i, QMIN) + ctol || gen(i, MU_QMIN) > ptol
0590                     fprintf(fd, '%10.3f', gen(i, MU_QMIN));
0591                 else
0592                     fprintf(fd, '      -   ');
0593                 end
0594                 if gen(i, QG)
0595                     fprintf(fd, '%10.2f%10.2f%10.2f', gen(i, [QMIN, QG, QMAX]));
0596                 else
0597                     fprintf(fd, '%10.2f       -  %10.2f', gen(i, [QMIN, QMAX]));
0598                 end
0599                 if gen(i, QG) > gen(i, QMAX) - ctol || gen(i, MU_QMAX) > ptol
0600                     fprintf(fd, '%10.3f', gen(i, MU_QMAX));
0601                 else
0602                     fprintf(fd, '      -   ');
0603                 end
0604             end
0605         end
0606         fprintf(fd, '\n');
0607     end
0608 
0609     %% dispatchable load P constraints
0610     if ~isempty(onld) && (OUT_PG_LIM == 2 || OUT_QG_LIM == 2 || ...
0611             (OUT_PG_LIM == 1 && (any(gen(onld, PG) < gen(onld, PMIN) + ctol) || ...
0612                                 any(gen(onld, PG) > gen(onld, PMAX) - ctol) || ...
0613                                 any(gen(onld, MU_PMIN) > ptol) || ...
0614                                 any(gen(onld, MU_PMAX) > ptol))) || ...
0615             (OUT_QG_LIM == 1 && (any(gen(onld, QG) < gen(onld, QMIN) + ctol) || ...
0616                                 any(gen(onld, QG) > gen(onld, QMAX) - ctol) || ...
0617                                 any(gen(onld, MU_QMIN) > ptol) || ...
0618                                 any(gen(onld, MU_QMAX) > ptol))))
0619         fprintf(fd, '\n================================================================================');
0620         fprintf(fd, '\n|     Dispatchable Load Constraints                                            |');
0621         fprintf(fd, '\n================================================================================');
0622     end
0623     if ~isempty(onld) && (OUT_PG_LIM == 2 || (OUT_PG_LIM == 1 && ...
0624                              (any(gen(onld, PG) < gen(onld, PMIN) + ctol) || ...
0625                               any(gen(onld, PG) > gen(onld, PMAX) - ctol) || ...
0626                               any(gen(onld, MU_PMIN) > ptol) || ...
0627                               any(gen(onld, MU_PMAX) > ptol))))
0628         fprintf(fd, '\n Gen   Bus                  Active Power Limits');
0629         fprintf(fd, '\n  #     #     Pmin mu     Pmin       Pg       Pmax    Pmax mu');
0630         fprintf(fd, '\n----  -----   -------   --------  --------  --------  -------');
0631         for k = 1:length(onld)
0632             i = onld(k);
0633             if OUT_PG_LIM == 2 || (OUT_PG_LIM == 1 && ...
0634                         (gen(i, PG) < gen(i, PMIN) + ctol || ...
0635                          gen(i, PG) > gen(i, PMAX) - ctol || ...
0636                          gen(i, MU_PMIN) > ptol || gen(i, MU_PMAX) > ptol))
0637                 fprintf(fd, '\n%4d%6d ', i, gen(i, GEN_BUS));
0638                 if gen(i, PG) < gen(i, PMIN) + ctol || gen(i, MU_PMIN) > ptol
0639                     fprintf(fd, '%10.3f', gen(i, MU_PMIN));
0640                 else
0641                     fprintf(fd, '      -   ');
0642                 end
0643                 if gen(i, PG)
0644                     fprintf(fd, '%10.2f%10.2f%10.2f', gen(i, [PMIN, PG, PMAX]));
0645                 else
0646                     fprintf(fd, '%10.2f       -  %10.2f', gen(i, [PMIN, PMAX]));
0647                 end
0648                 if gen(i, PG) > gen(i, PMAX) - ctol || gen(i, MU_PMAX) > ptol
0649                     fprintf(fd, '%10.3f', gen(i, MU_PMAX));
0650                 else
0651                     fprintf(fd, '      -   ');
0652                 end
0653             end
0654         end
0655         fprintf(fd, '\n');
0656     end
0657 
0658     %% dispatchable load Q constraints
0659     if ~isDC && ~isempty(onld) && (OUT_QG_LIM == 2 || (OUT_QG_LIM == 1 && ...
0660                              (any(gen(onld, QG) < gen(onld, QMIN) + ctol) || ...
0661                               any(gen(onld, QG) > gen(onld, QMAX) - ctol) || ...
0662                               any(gen(onld, MU_QMIN) > ptol) || ...
0663                               any(gen(onld, MU_QMAX) > ptol))))
0664         fprintf(fd, '\n Gen   Bus                 Reactive Power Limits');
0665         fprintf(fd, '\n  #     #     Qmin mu     Qmin       Qg       Qmax    Qmax mu');
0666         fprintf(fd, '\n----  -----   -------   --------  --------  --------  -------');
0667         for k = 1:length(onld)
0668             i = onld(k);
0669             if OUT_QG_LIM == 2 || (OUT_QG_LIM == 1 && ...
0670                         (gen(i, QG) < gen(i, QMIN) + ctol || ...
0671                          gen(i, QG) > gen(i, QMAX) - ctol || ...
0672                          gen(i, MU_QMIN) > ptol || gen(i, MU_QMAX) > ptol))
0673                 fprintf(fd, '\n%4d%6d ', i, gen(i, GEN_BUS));
0674                 if gen(i, QG) < gen(i, QMIN) + ctol || gen(i, MU_QMIN) > ptol
0675                     fprintf(fd, '%10.3f', gen(i, MU_QMIN));
0676                 else
0677                     fprintf(fd, '      -   ');
0678                 end
0679                 if gen(i, QG)
0680                     fprintf(fd, '%10.2f%10.2f%10.2f', gen(i, [QMIN, QG, QMAX]));
0681                 else
0682                     fprintf(fd, '%10.2f       -  %10.2f', gen(i, [QMIN, QMAX]));
0683                 end
0684                 if gen(i, QG) > gen(i, QMAX) - ctol || gen(i, MU_QMAX) > ptol
0685                     fprintf(fd, '%10.3f', gen(i, MU_QMAX));
0686                 else
0687                     fprintf(fd, '      -   ');
0688                 end
0689             end
0690         end
0691         fprintf(fd, '\n');
0692     end
0693 
0694     %% line flow constraints
0695     if upper(mpopt.opf.flow_lim(1)) == 'P' || isDC  %% |P| limit
0696         Ff = branch(:, PF);
0697         Ft = branch(:, PT);
0698         str = '\n  #     Bus    Pf  mu     Pf      |Pmax|      Pt      Pt  mu   Bus';
0699     elseif upper(mpopt.opf.flow_lim(1)) == 'I'      %% |I| limit
0700         Ff = abs( (branch(:, PF) + 1j * branch(:, QF)) ./ V(e2i(branch(:, F_BUS))) );
0701         Ft = abs( (branch(:, PT) + 1j * branch(:, QT)) ./ V(e2i(branch(:, T_BUS))) );
0702         str = '\n  #     Bus   |If| mu    |If|     |Imax|     |It|    |It| mu   Bus';
0703     else                                            %% |S| limit
0704         Ff = abs(branch(:, PF) + 1j * branch(:, QF));
0705         Ft = abs(branch(:, PT) + 1j * branch(:, QT));
0706         str = '\n  #     Bus   |Sf| mu    |Sf|     |Smax|     |St|    |St| mu   Bus';
0707     end
0708     if any(branch(:, RATE_A) ~= 0) && (OUT_LINE_LIM == 2 || (OUT_LINE_LIM == 1 && ...
0709                         (any(abs(Ff) > branch(:, RATE_A) - ctol) || ...
0710                          any(abs(Ft) > branch(:, RATE_A) - ctol) || ...
0711                          any(branch(:, MU_SF) > ptol) || ...
0712                          any(branch(:, MU_ST) > ptol))))
0713         fprintf(fd, '\n================================================================================');
0714         fprintf(fd, '\n|     Branch Flow Constraints                                                  |');
0715         fprintf(fd, '\n================================================================================');
0716         fprintf(fd, '\nBrnch   From     "From" End        Limit       "To" End        To');
0717         fprintf(fd, str);
0718         fprintf(fd, '\n-----  -----  -------  --------  --------  --------  -------  -----');
0719         for i = 1:nl
0720             if branch(i, RATE_A) ~= 0 && (OUT_LINE_LIM == 2 || (OUT_LINE_LIM == 1 && ...
0721                    (abs(Ff(i)) > branch(i, RATE_A) - ctol || ...
0722                     abs(Ft(i)) > branch(i, RATE_A) - ctol || ...
0723                     branch(i, MU_SF) > ptol || branch(i, MU_ST) > ptol)))
0724                 fprintf(fd, '\n%4d%7d', i, branch(i, F_BUS));
0725                 if Ff(i) > branch(i, RATE_A) - ctol || branch(i, MU_SF) > ptol
0726                     fprintf(fd, '%10.3f', branch(i, MU_SF));
0727                 else
0728                     fprintf(fd, '      -   ');
0729                 end
0730                 fprintf(fd, '%9.2f%10.2f%10.2f', ...
0731                     [Ff(i), branch(i, RATE_A), Ft(i)]);
0732                 if Ft(i) > branch(i, RATE_A) - ctol || branch(i, MU_ST) > ptol
0733                     fprintf(fd, '%10.3f', branch(i, MU_ST));
0734                 else
0735                     fprintf(fd, '      -   ');
0736                 end
0737                 fprintf(fd, '%6d', branch(i, T_BUS));
0738             end
0739         end
0740         fprintf(fd, '\n');
0741     end
0742 end
0743 
0744 %% execute userfcn callbacks for 'printpf' stage
0745 if have_results_struct && isfield(results, 'userfcn') && (success || OUT_FORCE)
0746     if ~isOPF   %% turn off option for all constraints if it isn't an OPF
0747         mpopt = mpoption(mpopt, 'out.lim.all', 0);
0748     end
0749     run_userfcn(results.userfcn, 'printpf', results, fd, mpopt);
0750 end
0751 if OUT_ANY && ~success
0752     if OUT_FORCE
0753         if isSDP
0754             fprintf(fd, '\n>>>>>  Solution does NOT satisfy rank and/or consistency conditions (%.2f seconds).  <<<<<\nmineigratio = %0.5g, zero_eval = %0.5g\n', et, mineigratio, zero_eval);
0755         else
0756             fprintf(fd, '\n>>>>>  Did NOT converge (%.2f seconds)  <<<<<\n', et);
0757         end
0758     end
0759     fprintf('\n');
0760 end

Generated on Fri 20-Mar-2015 18:23:34 by m2html © 2005