% Delivered to the U.S. Government in Accordance with Contract FA8650-10-C-7080.
% 
% (c) 2011 United Technologies Corp.
% Developed with the sponsorship of the Defense Advanced Research Projects Agency (DARPA).
% Permission is hereby granted, free of charge, to any person obtaining a copy of this data,
% including any software or models in source or binary form, as well as any drawings, 
% specifications, and documentation (collectively "the Data"), to deal in the Data without 
% restriction, including without limitation the rights to use, copy, modify, merge, publish,
% distribute, sublicense, and/or sell copies of the Data, and to permit persons to whom the Data
% is furnished to do so, subject to the following conditions:
%  
% The above copyright notice and this permission notice shall be included in all copies or
% substantial portions of the Data.
%  
% THE DATA IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
% BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
% NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS, SPONSORS, DEVELOPERS, CONTRIBUTORS, OR
% COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
% OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE DATA OR THE
% USE OR OTHER DEALINGS IN THE DATA.

% Authors:  Fernando Rodriguez                      John Finn
%           Sr Engineer/Scientist                   Contractor (Summer Intern 2011)
%           Power Electronics Systems               Embedded Systems & Networks
%           United Technologies Research Center     United Technologies Research Center
%           411 Silver Lane                         411 Silver Lane
%           East Hartford,CT 06108                  East Hartford,CT 06108
%           rodrigf@utrc.utc.com                    ccfinnje@utrc.utc.com
%           tel: (860) 610-7102                     tel: +1 860-610-7696
%%

%METAII_busout.m

%  This program prints the power flow solution in a tabulated form
%  on the screen.

% Create Output data matrix
G = 1e-3;    % G: Gain

nbus=length(Vm_);

disp(tech)
fprintf('                      Maximum Power Mismatch = %g \n', maxerror),
fprintf('                             No. of Iterations = %g \n\n', iter),
head =['    Bus  Voltage  Angle    ------Load------    ---Generation---     '
       '    No.  Mag.     Degree     kW       kvar       kW       kvar      '
       '                                                                    '];
disp(head)
for u1=1:max_bus
    u3 = 0;
    for u2=1:length(Mapping(:,1))
        if u1 == Mapping(u2,1)
            n = Mapping(u2,2);
            fprintf(' %5g', u1), fprintf(' %7.3f', Vm_(n)),
            fprintf(' %8.3f', deltad_(n)), fprintf(' %9.3f', Pd_(n)*G),
            fprintf(' %9.3f', Qd_(n)*G),  fprintf(' %9.3f', Pg_(n)*G),
            fprintf(' %9.3f\n', Qg_(n)*G)
            u3 = 1;
            break
        end
    end
    if u3 == 0
         fprintf(' %5g', u1)%, fprintf('\tOFF'),
%         fprintf('\tOFF'), fprintf('\tOFF'),
%         fprintf('\tOFF'),  fprintf('\tOFF'),
        fprintf('\tOFF\n')
    end
end
    fprintf('      \n'), fprintf('    Total              ')
    fprintf(' %9.3f', Pdt_*G), fprintf(' %9.3f', Qdt_*G),
    fprintf(' %9.3f', Pgt_*G), fprintf(' %9.3f\n\n', Qgt_*G)
    
    
% for n=1:nbus
%      fprintf(' %5g', Mapping(n,1)), fprintf(' %7.3f', Vm_(n)),
%      fprintf(' %8.3f', deltad_(n)), fprintf(' %9.3f', Pd_(n)*G),
%      fprintf(' %9.3f', Qd_(n)*G),  fprintf(' %9.3f', Pg_(n)*G),
%      fprintf(' %9.3f\n', Qg_(n)*G)
% end