if linea==1
    Nombre='Aldea II - Villariño';
    Long = 17.525;
    UN=380000;
    ZSA1=1.248+16.11*1i;
    ZSA0=2.338+23.47*1i;
    ZL1=0.576+5.920*1i;
    ZL0=5.280+18.08*1i;
    ZSB1=1.312+28.17*1i;
    ZSB0=1.264+18*1i;
    ZEQ1=2.240+48.91*1i;
    ZEQ0=30.49+177.6*1i;
    YL1=59.75e-6*1i;
    YL0=42.05e-6*1i;
end

if linea==2
    Nombre='Aldeadavila - Bemposta';
    Long = 20.6;
    UN=220000;
    ZSA1=0.309+3.678*1i;
    ZSA0=0.256+3.049*1i;
    ZL1=2.032+12.33*1i; 
    ZL0=11+35.56*1i;
    ZSB1=0.329+15.12*1i;
    ZSB0=1.147+10.79*1i;
    ZEQ1=26.05+47.37*1i;
    ZEQ0=209.9+367.4*1i;
    YL1=76.42e-6*1i;
    YL0=54.11e-6*1i;
end

if linea==3
    Nombre='Aldeadavila - Pocinho';
    
    UN=220000;
    Long = 40.4;
    
    ZL1=30.97+17.22*1i; 
    ZL0=19.25+55.79*1i;
    YL1=106.7e-6*1i;
    YL0=84.69e-6*1i;
   
    ZSA1=0.203+3.751*1i;
    ZSA0=0.246+3.020*1i;
    ZSB1=0.837+10.74*1i;
    ZSB0=1.210+9.176*1i;
    
    ZEQ1=3.131+18.06*1i;
    ZEQ0=77.34+146.9*1i;
end

if linea==4
    Nombre='Benavente - Vilecha';
    
    UN=138000;
    Long = 61.845;
    
    ZL1=13.44+26.37*1i;
    ZL0=22.38+84.95*1i;
    YL1=165.2e-6*1i;
    YL0=105.6e-6*1i;
   
    ZSA1=9.590+28.50*1i;
    ZSA0=3.282+29.11*1i;
    ZSB1=3.005+11.52*1i;
    ZSB0=7.319+32.30*1i;
    
    ZEQ1=999999+9999999*1i;
    ZEQ0=999999+9999999*1i;
end

if linea==5
    Nombre='Conso - Valparaiso';
    
    UN=220000;
    Long = 89.472;
    
    ZL1=3.688+26.52*1i;
    ZL0=19.93+93.68*1i;
    YL1=297.2e-6*1i;
    YL0=159.8e-6*1i;
   
    ZSA1=1.573+11.83*1i;
    ZSA0=2.826+14.59*1i;
    ZSB1=5.067+43.30*1i;
    ZSB0=8.891+77.99*1i;
    
    ZEQ1=999999+9999999*1i;
    ZEQ0=999999+9999999*1i;
end

if linea==6
    Nombre='Gatica - Hernani';
    
    UN=380000;
    Long = 78.110;
    
    ZL1=2.448+25.55*1i;
    ZL0=22.56+67.02*1i;
    YL1=229.8e-6*1i;
    YL0=215.5e-6*1i;
   
    ZSA1=2.464+28.46i;
    ZSA0=4.864+31.90*1i;
    ZSB1=2.480+26.44*1i;
    ZSB0=3.120+28.06*1i;
    
    ZEQ1=2.736+26.40*1i;
    ZEQ0=59.21+153.1*1i;
end

if linea==7
    Nombre='Gatica - Itxaso';
    
    UN=380000;
    Long = 61.07;
    
    ZL1=1.920+19.84*1i;
    ZL0=18.08+63.18*1i;
    YL1=218e-6*1i;
    YL0=143.9e-6*1i;
   
    ZSA1=3.024+35.64i;
    ZSA0=4.896+33.56*1i;
    ZSB1=1.952+20.88*1i;
    ZSB0=2.672+11.3*1i;
    
    ZEQ1=2.272+22.32*1i;
    ZEQ0=47.02+111.3*1i;
end

if linea==8
    Nombre='Grijota - S.Sebastian';
    
    UN=380000;
    Long = 264;
    
    ZL1=6.24+66.70*1i;
    ZL0=63.55+216.2*1i;
    YL1=754e-6*1i;
    YL0=501e-6*1i;
   
    ZSA1=0.912+11.98*1i;
    ZSA0=5.856+25.44*1i;
    ZSB1=1.104+16.75*1i;
    ZSB0=4.512+25.18*1i;
    
    ZEQ1=5.12+40.96*1i;
    ZEQ0=109.9+324.5*1i;
end

if linea==9
    Nombre='Gueñes - Gatika';
    
    UN=380000;
    Long = 38.795;
    
    ZL1=1.208+12.64*1i;
    ZL0=18.56+34.24*1i;
    YL1=138.1e-6*1i;
    YL0=96.98e-6*1i;
   
    ZSA1=3.184+34.40*1i;
    ZSA0=5.776+37*1i;
    ZSB1=1.936+22.68*1i;
    ZSB0=2.048+24.43*1i;
    
    ZEQ1=2.048+39*1i;
    ZEQ0=69.42+237.5*1i;
end

if linea==10
    Nombre='Gueñes - Barcina';
    
    UN=380000;
    Long = 55.595;
    
    ZL1=1.76+16.08*1i;
    ZL0=16.8+57.26*1i;
    YL1=201e-6*1i;
    YL0=133e-6*1i;
   
    ZSA1=2.864+30.7*1i;
    ZSA0=16.8+57.26*1i;
    ZSB1=1.424+17.72*1i;
    ZSB0=2.656+22.51*1i;
    
    ZEQ1=3.376+32.75*1i;
    ZEQ0=79.36+201.6*1i;
end

if linea==11
    Nombre='Gueñes - Herrera';
    
    UN=380000;
    Long = 78.110;
    
    ZL1=4.32+44.3*1i;
    ZL0=41.26+141*1i;
    YL1=492e-6*1i;
    YL0=331e-6*1i;
   
    ZSA1=2.496+29.44*1i;
    ZSA0=2.368+20.62*1i;
    ZSB1=0.976+12.49*1i;
    ZSB0=6.304+27.74*1i;
    
    ZEQ1=3.952+33.16*1i;
    ZEQ0=102+247.6*1i;
end

if linea==12
    Nombre='Gueñes - Santurce';
    
    UN=380000;
    Long = 13.692;
    
    ZL1=0.32+4.48*1i;
    ZL0=3.520+14.72*1i;
    YL1=46.36e-6*1i;
    YL0=29.74e-6*1i;
   
    ZSA1=2.496+29.44*1i;
    ZSA0=2.368+20.62*1i;
    ZSB1=0.976+12.49*1i;
    ZSB0=6.304+27.74*1i;
    
    ZEQ1=1.472+82.38*1i;
    ZEQ0=21.77+189.4*1i;
end

if linea==13
    Nombre='Hernani - Arkale';
    
    UN=220000;
    Long = 12.976;
    
    ZL1=0.726+4.162*1i;
    ZL0=3.339+14.95*1i;
    YL1=47.52e-6*1i;
    YL0=26.44e-6*1i;
   
    ZSA1=0.929+9.167*1i;
    ZSA0=0.735+10.33*1i;
    ZSB1=3.286+29.72*1i;
    ZSB0=2.724+25.96*1i;
    
    ZEQ1=0.493+3.359*1i;
    ZEQ0=3.078+13.57*1i;
end

if linea==14
    Nombre='Hernani - Arkale II';
    
    UN=220000;
    Long = 12.976;
    
    ZL1=0.726+4.162*1i;
    ZL0=3.339+14.95*1i;
    YL1=47.52e-6*1i;
    YL0=26.44e-6*1i;
   
    ZSA1=0.929+9.167*1i;
    ZSA0=0.735+10.33*1i;
    ZSB1=3.286+29.72*1i;
    ZSB0=2.724+25.96*1i;
    
    ZEQ1=0.493+3.359*1i;
    ZEQ0=3.078+13.57*1i;
end

if linea==15
    Nombre='Hernani - CNTEGRI';
    
    UN=380000;
    Long = 128.61;
    
    ZL1=4+40.94*1i;
    ZL0=40.3+143*1i;
    YL1=541.7e-6*1i;
    YL0=324e-6*1i;
   
    ZSA1=2.016+21.82*1i;
    ZSA0=3.2+23.13*1i;
    ZSB1=1.824+25.42*1i;
    ZSB0=16.94+71.31*1i;
    
    ZEQ1=30.11+251.8*1i;
    ZEQ0=338+1197*1i;
end

if linea==16
    Nombre='Itxaso - Barcina';
    
    UN=220000;
    Long = 100;
    
    ZL1=2.72+25.12*1i;
    ZL0=21.28+76.62*1i;
    YL1=356.1e-6*1i;
    YL0=227.44e-6*1i;
   
    ZSA1=2.688+27.23*1i;
    ZSA0=2.6+22.99*1i;
    ZSB1=1.392+18.35*1i;
    ZSB0=2.336+20.51*1i;
    
    ZEQ1=2.816+29.13*1i;
    ZEQ0=65.95+174.7*1i;
end

if linea==17
    Nombre='Itxaso - Hernani';
    
    UN=220000;
    Long = 37.806;
    
    ZL1=2.323+12.14*1i;
    ZL0=17.51+76.06*1i;
    YL1=138.4e-6*1i;
    YL0=52.66e-6*1i;
   
    ZSA1=1.432+20.01*1i;
    ZSA0=0.609+11.08*1i;
    ZSB1=0.745+7.1*1i;
    ZSB0=0.663+6.054*1i;
    
    ZEQ1=1.147+7.777*1i;
    ZEQ0=4.772+30.15*1i;
end

if linea==18
    Nombre='La Lomba - Herrera';
    
    UN=380000;
    Long = 189.29;
    
    ZL1=6.24+54.06*1i;
    ZL0=56.3+181.8*1i;
    YL1=751.3e-6*1i;
    YL0=542.6e-6*1i;
   
    ZSA1=0.544+10.88*1i;
    ZSA0=1.248+10.70*1i;
    ZSB1=1.216+15.95*1i;
    ZSB0=6.304+29.23*1i;
    
    ZEQ1=2.768+22.84*1i;
    ZEQ0=54.32+146.8*1i;
end

if linea==19
    Nombre='Logroño - Sequero';
    
    UN=220000;
    Long = 27.461;
    
    ZL1=1.936+10.84*1i;
    ZL0=6.146+36.15*1i;
    YL1=95.84e-6*1i;
    YL0=44.83e-6*1i;
   
    ZSA1=4.138+28.71*1i;
    ZSA0=7.526+49.75*1i;
    ZSB1=7.768+47.95*1i;
    ZSB0=13.2+100.9*1i;
    
    ZEQ1=9999999+9999999*1i;
    ZEQ0=9999999+9999999*1i;
end

if linea==20
    Nombre='Lomba - Compostilla';
    
    UN=380000;
    Long = 6.756;
    
    ZL1=0.160+1.6*1i;
    ZL0=1.44+7.2*1i;
    YL1=21.24e-6*1i;
    YL0=14.37e-6*1i;
   
    ZSA1=0.752+14.62*1i;
    ZSA0=1.136+12.96*1i;
    ZSB1=1.072+15.98*1i;
    ZSB0=3.312+22.01*1i;
    
    ZEQ1=0.32+4.32*1i;
    ZEQ0=3.536+17.02*1i;
end

if linea==21
    Nombre='Miranda - Logroño';
    
    UN=220000;
    Long = 45.709;
    
    ZL1=3.339+18.67*1i;
    ZL0=16.2+56.03*1i;
    YL1=130e-6*1i;
    YL0=91e-6*1i;
   
    ZSA1=1.505+12.62*1i;
    ZSA0=4.201+24.08*1i;
    ZSB1=9.955+62.44*1i;
    ZSB0=4.307+66.05*1i;
    
    ZEQ1=9999999+9999999*1i;
    ZEQ0=9999999+9999999*1i;
end

if linea==22
    Nombre='Orcoyen - Tafalla';
    
    UN=220000;
    Long = 37.059;
    
    ZL1=2.226+11.17*1i;
    ZL0=13.69+39.62*1i;
    YL1=137e-6*1i;
    YL0=89e-6*1i;
   
    ZSA1=2.095+11.17*1i;
    ZSA0=13.69+39.62*1i;
    ZSB1=7.221+49.76*1i;
    ZSB0=17.58+86.31*1i;
    
    ZEQ1=0.171+0.579*1i;
    ZEQ0=9999999+9999999*1i;
end

if linea==23
    Nombre='Sanguesa - Cordovil';
    
    UN=220000;
    Long = 38.656;
    
    ZL1=3.072+12.38*1i;
    ZL0=11.61+55.31*1i;
    YL1=137e-6*1i;
    YL0=89e-6*1i;
   
    ZSA1=2.095+11.17*1i;
    ZSA0=4.569+26.23*1i;
    ZSB1=9.263+36.99*1i;
    ZSB0=13.41+94.56*1i;
    
    ZEQ1=9999999+9999999*1i;
    ZEQ0=9999999+9999999*1i;
end

if linea==24
    Nombre='Sanguesa - Lafortu';
    
    UN=220000;
    Long = 73.877;
    
    ZL1=7.889+25.21*1i;
    ZL0=19.64+100*1i;
    YL1=287e-6*1i;
    YL0=143e-6*1i;
   
    ZSA1=5.183+23.97*1i;
    ZSA0=11.35+68.96*1i;
    ZSB1=1.668+10.47*1i;
    ZSB0=2.468+20.35*1i;
    
    ZEQ1=116.9+326.2*1i;
    ZEQ0=9999999+9999999*1i;
end

if linea==25
    Nombre='Tafalla - Tudela';
    
    UN=220000;
    Long = 52.426;
    
    ZL1=3.146+16.59*1i;
    ZL0=20.12+43.69*1i;
    YL1=194e-6*1i;
    YL0=135e-6*1i;
   
    ZSA1=3.905+21.50*1i;
    ZSA0=13.05+54.53*1i;
    ZSB1=4.539+30.14*1i;
    ZSB0=8.148+64*1i;
    
    ZEQ1=0.206+0.725*1i;
    ZEQ0=9999999+9999999*1i;
end

if linea==26
    Nombre='Trives - Belesar';
    
    UN=220000;
    Long = 43.300;
    
    ZL1=3.484+20.17*1i;
    ZL0=15.72+62.76*1i;
    YL1=132e-6*1i;
    YL0=103e-6*1i;
   
    ZSA1=0.542+5.933*1i;
    ZSA0=0.958+6.984*1i;
    ZSB1=1.224+13.47*1i;
    ZSB0=0.842+10.46*1i;
    
    ZEQ1=0.043+0.170*1i;
    ZEQ0=9999999+9999999*1i;
end

if linea==27
    Nombre='Valparaiso - Tordesillas';
    
    UN=220000;
    Long = 120.43;
    
    ZL1=5.507+39.66*1i;
    ZL0=29.95+140.4*1i;
    YL1=444e-6*1i;
    YL0=239e-6*1i;
   
    ZSA1=1.732+12.39*1i;
    ZSA0=4.714+21.6*1i;
    ZSB1=4.283+35*1i;
    ZSB0=8.058+61.68*1i;
    
    ZEQ1=9999999+9999999*1i;
    ZEQ0=9999999+9999999*1i;
end

if linea==28
    Nombre='Velilla - Herrera';
    
    UN=380000;
    Long = 49.654;
    
    ZL1=1.6+16*1i;
    ZL0=12.8+53.42*1i;
    YL1=178e-6*1i;
    YL0=107e-6*1i;
   
    ZSA1=1.472+27.6*1i;
    ZSA0=3.44+28.16*1i;
    ZSB1=1.136+13.47*1i;
    ZSB0=7.856+30.78*1i;
    
    ZEQ1=12.32+92.12*1i;
    ZEQ0=593.5+1248*1i;
end

if linea==29
    Nombre='Villalbi - Villal I';
    
    UN=220000;
    Long = 220.78;
    
    ZL1=9.728+70.56*1i;
    ZL0=65+239.5*1i;
    YL1=803e-6*1i;
    YL0=517e-6*1i;
   
    ZSA1=1.161+10.55*1i;
    ZSA0=2.565+16.11*1i;
    ZSB1=0.629+6.582*1i;
    ZSB0=1.306+8.421*1i;
    
    ZEQ1=9.534+52.27*1i;
    ZEQ0=430.2+776.6*1i;
end

if linea==30
    Nombre='Villarin - Grijota';
    
    UN=380000;
    Long = 195.3;
    
    ZL1=5.92+52.64*1i;
    ZL0=43.68+206.2*1i;
    YL1=834e-6*1i;
    YL0=448e-6*1i;
   
    ZSA1=1.44+20.16*1i;
    ZSA0=43.68+206.2*1i;
    ZSB1=0.96+12.32*1i;
    ZSB0=6.72+28*1i;
    
    ZEQ1=3.52+29.92*1i;
    ZEQ0=38.72+143.5*1i;
end

RSA1=real(ZSA1);
LSA1=imag(ZSA1)/pi/100;
RSA0=real(ZSA0);
LSA0=imag(ZSA0)/pi/100;


RL1k=real(ZL1)/Long; 
RL0k=real(ZL0)/Long;
LL1k=imag(ZL1)/100/pi/Long;  
LL0k=imag(ZL0)/100/pi/Long;
CL1k=imag(YL1)/100/pi/Long;
CL0k=imag(YL0)/100/pi/Long;

RSB1=real(ZSB1);  
LSB1=imag(ZSB1)/pi/100;
RSB0=real(ZSB0);
LSB0=imag(ZSB0)/pi/100;

REQ1=real(ZEQ1);  
LEQ1=imag(ZEQ1)/pi/100;
REQ0=real(ZEQ0); 
LEQ0=imag(ZSB0)/pi/100;

SIR_A=abs(ZSA1/ZL1);
SIR_B=abs(ZSB1/ZL1);

SIR_A0=abs(ZSA0/ZL0);
SIR_B0=abs(ZSB0/ZL0);

RL1=real(ZL1)/abs(ZL1);
XL1=imag(ZL1)/abs(ZL1);

M=1;
N=24;


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
%             CALCULO DE LA PREFALTA
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

XT=imag(ZSA1+ZL1+ZSB1);

if UN==220000
    P=200e6;
elseif UN==400000
    P=400e6;
else
    P=150e6;
end

delta=asin((P*XT)/UN^2)*180/pi;

warning off


sim Localizador

% save('Valores_Falta','Valores_Falta','-v4')
% save ('Nombre','Nombre','-v4')


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
%           CALCULO DE LA DISTANCIA
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%


%Va_A=Valores_Falta(:,1);
%Vb_A=Valores_Falta(:,2);
%Vc_A=Valores_Falta(:,3);
%Ia_A=Valores_Falta(:,4);
%Ib_A=Valores_Falta(:,5);
%Ic_A=Valores_Falta(:,6);
%Ia_B=Valores_Falta(:,7);
%Ib_B=Valores_Falta(:,8);
%Ic_B=Valores_Falta(:,9);
%Va_B=Valores_Falta(:,10);
%Vb_B=Valores_Falta(:,11);
%Vc_B=Valores_Falta(:,12);



%linea
%delta
%Rff
%Rfg
%dist_real=dist
%dist_calc=imag(Vbc_A(84)*conj(IF(84)))/(imag((Vbc_A(84)-Vbc_B(84))*conj(IF(84)))+eps)
%Error_porcen=(dist_calc-dist)*100
%Error_abs=(dist_calc-dist)*Long*1e3