function [bus,line,bus_sol,line_flow,nob,nol,slack,lf_flag]=get_data(excelfilename)
% Syntax:    
% 
% Purpose:   To get the System data (bus data as well as line data)
%            in a given format from excel sheet and run load flow
% Input:     nob        - number of bus
%
% Output:    bus        - bus data
%            line       - line data
%            bus_sol    - bus solution after load flow
%            line_flow  - line flow after load flow
%            nob        - no of bus
%            nol        - no of line
%            slack      - slack bus no
%            lf_flag    - flag=0:no convergence
%                         flag=1: converged load flow solution
% Calls:     loadflow.m
%           
%******************************************************************
% Bus  data format is given as
% bus_No volt_mag volt_angle PG QG PD QD G_shunt B_shunt Bus_type
% QGmax QGmin PMU_presence PQmeas_availability
%
% bus type: 1=SWING   2=PV    3=PQ
% PMU/PQ meas availability: 0=not available and 1=available
%******************************************************************
%******************************************************************
% Line data format is given as
% Start_bus End_bus R X Line_charging Tap_ratio phase_shift-angle
% flow_meas_availability
%
% Flow_meas_availability: 0=not available and 1=from_bus to to_bus
% 2=to_bus to from_bus  3=flow from both side
%
% nob=input('Enter no. of the bus:  ');

% if nob==14
%     nol=20;
%     excelfilename='IEEE_14.xlsx';
% elseif nob==30
%     nol=41;
%     excelfilename='IEEE_30.xlsx';
% elseif nob==57
%     nol=80;
%     excelfilename='IEEE_57.xlsx';
% elseif nob==118
%     nol=186;
%     excelfilename='IEEE_118.xlsx';
% else
%     nob=14;
%     nol=20;
%     excelfilename='IEEE_14.xlsx';
% end

[bus]=xlsread(excelfilename,'busdata');
[line]=xlsread(excelfilename,'linedata');

nob=max(bus(:,1)); %no. of bus
nol=length(line(:,1));  %no. of lines
for i=1:nob
    if bus(i,10)==1
        slack=i;
    end
end
temp=bus(:,1:12);temp1=line(:,1:7);
%load flow solution
[bus_sol,line_sol,line_flow,lf_flag] = loadflow(temp,temp1,1e-6,30,1,'y',1);
% clc;
if lf_flag==0
    disp('Load flow not converged');
    return;
else
    disp('Load flow convergence successful');
end
for i=1:nob
    if abs(bus_sol(i,4))<1e-6
        bus_sol(i,4)=0;
    end
    if abs(bus_sol(i,5))<1e-6
        bus_sol(i,5)=0;
    end
    if abs(bus_sol(i,6))<1e-6
        bus_sol(i,6)=0;
    end
    if abs(bus_sol(i,7))<1e-6
        bus_sol(i,7)=0;
    end
    if abs(bus_sol(i,11))==9999
        bus_sol(i,11)=0;
    end
    if abs(bus_sol(i,12))==9999
        bus_sol(i,12)=0;
    end
end
for i=1:2*nol
    if abs(line_flow(i,4))<1e-6
        line_flow(i,4)=0;
    end
    if abs(line_flow(i,5))<1e-6
        line_flow(i,5)=0;
    end
end