function [ZII_I,RII_I,HII_I]=eval_current_sequential(m_IMA,m_IRI,line_pi,nob,slack)
%INPUT:
%   m_IMA  :  current meas in polar column as (line_no, IM, IA, RM, RA)
%   m_IRI  :  current meas in rect column as (line_no, IR, II, RR, RI)
%   line_pi:  line parameters in pi form

%OUTPUT:
%   ZII_I  :  measurement [Ireal;Iimag];
%   RII_I  :  variance [R_Ireal;R_Iimag]
%   HII_I  :  Current jacobian wrt real and reactivevoltage
%             [dIreal/dVreal dIreal/dVimag;dIimag/dVreal dIimag/dVimag]

zreal=[];zimag=[];Rreal=[];Rimag=[];
J_real=[];J_imag=[];
if isempty(m_IMA)==0
    for i=1:length(m_IMA(:,1))
        IM=m_IMA(i,2);IA=m_IMA(i,3);
        RM=m_IMA(i,4);RA=m_IMA(i,5);    
    
        [zreal]=[zreal;IM*cos(IA)];
        [zimag]=[zimag;IM*sin(IA)];
        [Rreal]=[Rreal;(cos(IA)^2)*RM+RA*(IM*sin(IA))^2];
        [Rimag]=[Rimag;(sin(IA)^2)*RM+RA*(IM*cos(IA))^2];    
    
        t_line_no=m_IMA(i,1);
        t_from=line_pi(t_line_no,1);t_to=line_pi(t_line_no,2);
        t_gm=line_pi(t_line_no,3);t_bm=line_pi(t_line_no,4);
        t_g=line_pi(t_line_no,5);t_b=line_pi(t_line_no,6);
        
        temp=zeros(1,2*nob);
        temp(1,t_from)=t_g+t_gm;temp(1,t_to)=-t_g;
        temp(1,nob+t_from)=-(t_b+t_bm);temp(1,nob+t_to)=t_b;
        [J_real]=[J_real;temp];
        
        temp=zeros(1,2*nob);
        temp(1,t_from)=t_b+t_bm;temp(1,t_to)=-t_b;
        temp(1,nob+t_from)=t_g+t_gm;temp(1,nob+t_to)=-t_g;
        [J_imag]=[J_imag;temp];
    end
end
if isempty(m_IRI)==0
    for i=1:length(m_IRI(:,1))
        [zreal]=[zreal;m_IRI(i,2)];
        [zimag]=[zimag;m_IRI(i,3)];
        [Rreal]=[Rreal;m_IRI(i,4)];
        [Rimag]=[Rimag;m_IRI(i,5)];
        
        t_line_no=m_IRI(i,1);
        t_from=line_pi(t_line_no,1);t_to=line_pi(t_line_no,2);
        t_gm=line_pi(t_line_no,3);t_bm=line_pi(t_line_no,4);
        t_g=line_pi(t_line_no,5);t_b=line_pi(t_line_no,6);
        
        temp=zeros(1,2*nob);
        temp(1,t_from)=t_g+t_gm;temp(1,t_to)=-t_g;
        temp(1,nob+t_from)=-(t_b+t_bm);temp(1,nob+t_to)=t_b;
        [J_real]=[J_real;temp];
        
        temp=zeros(1,2*nob);
        temp(1,t_from)=t_b+t_bm;temp(1,t_to)=-t_b;
        temp(1,nob+t_from)=t_g+t_gm;temp(1,nob+t_to)=-t_g;
        [J_imag]=[J_imag;temp];
    end
end

ZII_I=[zreal;zimag];
RII_I=[Rreal;Rimag];

temp_H=[J_real;J_imag];
if isempty(temp_H)==0
    if slack==nob
        HII_I=temp_H(:,1:2*nob-1);
    else
        HII_I=[temp_H(:,1:nob+slack-1) temp_H(:,nob+slack+1:2*nob)];
    end
end
    
