%Input all data required for state estimator

fprintf('\n\t%s\n\t%s\n','1: MEASUREMENTS TO BE SIMULATED (default)','0: MEASUREMENTS DIRECTLY AVAILABLE');
flag_sim=input('SIMULATION MODE: ');
if isempty(flag_sim)==0 
    if flag_sim~=0
        flag_sim=1;
    end
else
    flag_sim=1;
end
%============================

fprintf('\n\t%s\n','1   GAUSSIAN ERROR DISTRIBUTION(By default)');
fprintf('\t%s\n','2   UNIFORM ERROR DISTRIBUTION');
flag_error=input('Enter Error distribution: ');
if isempty(flag_error)==0
    if flag_error~=1 && flag_error~=2
        flag_error=1;
    end
else
    flag_error=1;
end
if flag_error==2    %UNIFORM ERROR DISTRIBUTION
    %Maximum meas uncertainty [inj flow Vabs Iabs PMU_angle_degree]
    fprintf('\n%s\n%s\n','Need entry for maximum measurement uncertainty?','1 for Yes and otherwise No');
    ans_distr=input('Enter option: ');
    if isempty(ans_distr)==0
        if ans_distr~=1
            err_spec=[3 3 0.02 0.03 0.01]';
        else
            fprintf('\n%s\n','Enter maximum measurement uncertainty in');
            ans_inj=input('Injection measurement: ');
            ans_flow=input('Flow measurement: ');
            ans_Vabs=input('Voltage magnitude: ');
            ans_Iabs=input('Current magnitude: ');
            ans_angle=input('PMU Angle measurement in degree: ');
            err_spec=[ans_inj ans_flow ans_Vabs ans_Iabs ans_angle];
            clear ans_inj ans_flow ans_Vabs ans_Iabs ans_angle;
        end
    else
        err_spec=[3 3 0.02 0.03 0.01]';
    end
    fprintf('\n%s\n','Maximum measurement uncertainty in injection, flow,');
    fprintf('%s\n','voltage magnitude, current magnitude, PMU angle in degree');
    disp(err_spec');
    %fprintf('%d\t%d\t%d\t%d\t%d\n',err_spec(1),)
else                %GAUSSIAN ERROR DISTRIBUTION
    %SD [Inj flow PMU_abs PMU_angle_radian]
    fprintf('\n%s\n%s\n','Need entry for Standard Deviation?','1 for Yes and otherwise No');
    ans_distr=input('Enter option: ');
    if isempty(ans_distr)==0
        if ans_distr~=1
            err_spec=[0.01 0.008 0.002 0.0017]';
        else
            fprintf('\n%s\n','Enter Standard Deviation in');
            ans_inj=input('Injection measurement: ');
            ans_flow=input('Flow measurement: ');
            ans_abs=input('PMU Voltage/Current magnitude: ');
            ans_angle=input('PMU Angle measurement in radian: ');
            err_spec=[ans_inj ans_flow ans_abs ans_angle];
            clear ans_inj ans_flow ans_abs ans_angle;
        end
    else
        err_spec=[0.01 0.008 0.002 0.0017]';
    end
    fprintf('\n%s\n','Standard deviation in injection, flow,');
    fprintf('%s\n', 'PMU magnitude, PMU angle in radian');
    disp(err_spec');
end
clear ans_distr;
%=================================

if flag_sim==1
    %Generate measurement; Three file created namely 
    %'meas_data.xlsx', 'meas_total.xlsx' & 'meas_true.xlsx'
    %'meas_total.xlsx' is all possible meas generated from simulation mode
    %'meas_true.xlsx' is true meas from load flow in simulation mode
    generate_meas;
    if lf_flag==0
        return;
    end
else
    lf_flag=1;
end

fprintf('\t%s\n','1   CONVENTIONAL ONLY(By default)');
fprintf('\t%s\n\t%s','2   PMU ONLY (LINEAR)','3   CONVENTIONAL+PMU');
fprintf('%s\n','(HYBRID)');
flag_SE=input('Enter TYPE OF STATE ESTIMATOR: ');
if isempty(flag_SE)==0
    if flag_SE~=2 && flag_SE~=3
        flag_SE=1;
    end
else
    flag_SE=1;
end
if flag_SE==3   %CONVENTIONAL+PMU
    fprintf('\n\t%s\n','1   HYBRID SE (By default)');
    fprintf('\t%s\n','2   SEQUENTIAL SE');
    flag_PMU=input('Enter PMU BASED SE METHODS: ');
    if isempty(flag_PMU)==0
        if flag_PMU~=1 && flag_PMU~=2
            flag_PMU=1;
        end
    else
        flag_PMU=1;
    end
end

fprintf('\n\t%s\n','1   EQUALITY CONSTRAINT CONSIDERED(By default)');
fprintf('\t%s\n','0   EQUALITY CONSTRAINT NOT CONSIDERED');
flag_eq=input('Enter Option for EQ CONSTRINT CONSIDERATION: ');
if isempty(flag_eq)==0
    if flag_eq~=0 && flag_eq~=1
        flag_eq=1;
    end
else
    flag_eq=1;
end

if flag_SE==2       %ALL PMU BASED SE
    fprintf('\t%s\n','1   CONSIDER VOLTAGE & CURRENT PHASOR DIRECTLY(By defauly)');
    fprintf('\t%s\n','2   CURRENT PHASOR CONVERTED INTO VOLTAGE PHASOR');
    flag_PMUSE=input('Enter TYPE OF ALL PMU STATE ESTIMATOR: ');
    if isempty(flag_PMUSE)==0
        if flag_PMUSE~=2
            flag_PMUSE=1;
        end
    else
        flag_PMUSE=1;
    end
    
elseif flag_SE==3   %CONVENTIONAL+PMU
    fprintf('\n\t%s\n','1   NORMAL SE USING (By default)');
    fprintf('\t%s\n','3   LEAST SQUARE METHOD');
    fprintf('\t%s\n','4   L-curve regularization');
    flag_SE_method=input('Enter TYPE OF STATE ESTIMATOR METHODS: ');
    if isempty(flag_SE_method)==0
        if flag_SE_method~=3 && flag_SE_method~=4
            flag_SE_method=1;
        end
    else
        flag_SE_method=1;
    end
else
    fprintf('\n\t%s\n','1   NORMAL SE USING (By default)');
    fprintf('\t%s\n\t%s\n','2   PETERS WILKINSON METHOD','3   LEAST SQUARE METHOD');
    %fprintf('\t%s\n\t%s\n','4   L-curve regularization','5   LU FACTORIZATION');
    fprintf('\t%s\n','4   L-curve regularization');
    flag_SE_method=input('Enter TYPE OF STATE ESTIMATOR METHODS: ');
    if isempty(flag_SE_method)==0
        if flag_SE_method~=2 && flag_SE_method~=3 && flag_SE_method~=4
            flag_SE_method=1;
        end
    else
        flag_SE_method=1;
    end
    
    if flag_SE_method==2
        flag_eq=0;
    end
end

