function [line_pi]=process_line(line)
% Syntax:    [Gbus,Bbus,line_pi]=process_line(line,bus)
% 
% Purpose:   To process the line parameter and form y bus as well as 
%            line parameter in a pi model
% Input:     line        - number of lines
%            bus         - number of buses
%
% Output:    line_pi     - line in pi model
%============================================================
%line in pi model consists of from_bus to_bus
% Gsh_from Bsh_from  Gseries Bseries  Gsh_to Bsh_to in order

%============================================================
nol=length(line(:,1));
line_pi=zeros(nol,8);
line_pi(:,1:2)=line(:,1:2);
line_pi(:,3)=0;line_pi(:,7)=0;
for i=1:length(line)
    if line(i,6)==1
        r_line=line(i,3);x_line=line(i,4);
        temp=1/(r_line+1i*x_line);
        line_pi(i,4)=0.5*line(i,5);
        line_pi(i,8)=0.5*line(i,5);
        line_pi(i,5)=real(temp);
        line_pi(i,6)=imag(temp);
    else
        %Assumption: valid for tranformer tap without susceptance
        tap=line(i,6);
        r_line=line(i,3);x_line=line(i,4);
        temp=1/(r_line+1i*x_line);
        line_pi(i,3)=real(temp*(1/tap-1)/tap);
        line_pi(i,4)=imag(temp*(1/tap-1)/tap);
        line_pi(i,5)=real(temp/tap);
        line_pi(i,6)=imag(temp/tap);
        line_pi(i,7)=real(temp*(1-1/tap));
        line_pi(i,8)=imag(temp*(1-1/tap));
%         temp=-1/line(i,4);
%         tap=line(i,6);
%         line_pi(i,5)=0;
%         line_pi(i,6)=temp/tap;
%         line_pi(i,4)=temp*((1/tap)-1)/tap;
%         line_pi(i,8)=temp*(1-(1/tap));
    end
end
clear temp;
temp=[line_pi(:,2) line_pi(:,1) line_pi(:,7) line_pi(:,8)];
[temp]=[temp line_pi(:,5) line_pi(:,6) line_pi(:,3) line_pi(:,4)];
[line_pi]=[line_pi;temp];