function [modelA, RR, testA] = regionsA( param )


% estimate indoor areas
load('Cell_Info');

testA = Cell_Info_A;
modelA = Cell_Info_E;

% calculate power regions (8 total)
for i = 1:203
    for j = 1:203
        if Cell_Info_A.ReceivedPowerMap(i,j) == 0
            testA.ReceivedPowerMap(i,j) = 0;
        elseif Cell_Info_A.ReceivedPowerMap(i,j) < -90
            testA.ReceivedPowerMap(i,j) = 1;
        elseif Cell_Info_A.ReceivedPowerMap(i,j) < -88
            testA.ReceivedPowerMap(i,j) = 2;
        elseif Cell_Info_A.ReceivedPowerMap(i,j) < -85
            testA.ReceivedPowerMap(i,j) = 3;
        elseif Cell_Info_A.ReceivedPowerMap(i,j) < -80
            testA.ReceivedPowerMap(i,j) = 4;
        elseif Cell_Info_A.ReceivedPowerMap(i,j) < -75
            testA.ReceivedPowerMap(i,j) = 5;
        elseif Cell_Info_A.ReceivedPowerMap(i,j) < -60
            testA.ReceivedPowerMap(i,j) = 6;
        elseif Cell_Info_A.ReceivedPowerMap(i,j) < -55
            testA.ReceivedPowerMap(i,j) = 7;
        else
            testA.ReceivedPowerMap(i,j) = 8;
        end
    end
end

RR = zeros(203, 203); na = zeros(1,3); nb = zeros(1,3); n = zeros(1,3);

% calculate directionality regions and path loss exponenent(4 total)
for i = 1:203
    for j = 1:203
        R = sqrt((101-i)^2 + (101-j)^2)*10;
        if R == 0
            R = 5;
        end
        PL = modelA.erp - Cell_Info_A.ReceivedPowerMap(i,j) + 20*log10((3*10^8/(850*10^6))/(4*pi));
        ang = atan2(i-101,j-101)*180/pi;
        if ang < 0
            ang = ang + 360;
        end

        % region 1: +/- 58 degrees from azimuth
        if  172  <= ang && ang <= 288         %E
        %if  52  <= ang && ang <= 168        %D
        %if -70 <= ang && ang <= 46          %A
            if Cell_Info_A.ReceivedPowerMap(i,j) ~= 0
                na(1) = na(1) + PL*10*log10(R);
                nb(1) = nb(1) + (10*log10(R))^2;
            end
            RR(i,j) = 1;

        % region 2: +30 degrees from region 1
        elseif 288 < ang && ang <  318        %E
        %elseif 22 < ang && ang <  52         %D
        %elseif 46 < ang && ang < 76          %A
            if Cell_Info_A.ReceivedPowerMap(i,j) ~= 0
                na(2) = na(2) + PL*10*log10(R);
                nb(2) = nb(2) + (10*log10(R))^2;
            end
            RR(i,j) = 2;

        % region 2: -30 degrees from region 1
        elseif 142  < ang && ang < 172           %E
        %elseif 168  < ang && ang < 198           %D
        %elseif -100 < ang && ang < -70          %A
            if Cell_Info_A.ReceivedPowerMap(i,j) ~= 0
                na(2) = na(2) + PL*10*log10(R);
                nb(2) = nb(2) + (10*log10(R))^2;
            end
            RR(i,j) = 2;

        % region 3: other portion of map
        else
            if Cell_Info_A.ReceivedPowerMap(i,j) ~= 0
                na(3) = na(3) + PL*10*log10(R);
                nb(3) = nb(3) + (10*log10(R))^2;
            end
            RR(i,j) = 3;
        end
    end
end

% shift regions to different azimuth
for i = 1:203
    for j = 1:203
        R = sqrt((101-i)^2 + (101-j)^2)*10;
        if RR(i,j) == 1
            if testA.ReceivedPowerMap(i,j) >6
                testA.ReceivedPowerMap(i,j) = testA.ReceivedPowerMap(i,j) + 2;
            elseif testA.ReceivedPowerMap(i,j) > 0
                testA.ReceivedPowerMap(i,j) = testA.ReceivedPowerMap(i,j) + 1;
            end
        elseif RR(i,j) == 2
            if testA.ReceivedPowerMap(i,j) > 6
                testA.ReceivedPowerMap(i,j) = testA.ReceivedPowerMap(i,j) + 1;
            end
        else
            if testA.ReceivedPowerMap(i,j) > 4
                testA.ReceivedPowerMap(i,j) = testA.ReceivedPowerMap(i,j) - 1;
            end
        end
    end
end


n = na ./ nb;

% calculate path loss and apply it to map
for i = 1:203
    for j = 1:203
        R = sqrt((101-i)^2 + (101-j)^2)*10;
        region = testA.ReceivedPowerMap(i,j);
        if R ~= 0
            if RR(i,j) == 1
                if region == 1
                    PL = 46.3 + 33.9*log10(850*10^6)-13.82*log(305)+(44.9-6.55*log(305))*log10(R) - 2;
                elseif region == 2
                    PL = 46.3 + 33.9*log10(850*10^6)-13.82*log(305)+(44.9-6.55*log(305))*log10(R) - 7;
                elseif region == 3
                    PL = 46.3 + 33.9*log10(850*10^6)-13.82*log(305)+(44.9-6.55*log(305))*log10(R) - 12;
                elseif region == 4
                    PL = 46.3 + 33.9*log10(850*10^6)-13.82*log(305)+(44.9-6.55*log(305))*log10(R) - 16;
                elseif region == 5
                    PL = 46.3 + 33.9*log10(850*10^6)-13.82*log(305)+(44.9-6.55*log(305))*log10(R) - 18;
                elseif region == 6
                    PL = 46.3 + 33.9*log10(850*10^6)-13.82*log(305)+(44.9-6.55*log(305))*log10(R) - 25;
                elseif region == 7
                    PL = 46.3 + 33.9*log10(850*10^6)-13.82*log(305)+(44.9-6.55*log(305))*log10(R) - 32;
                else
                    PL = 46.3 + 33.9*log10(850*10^6)-13.82*log(305)+(44.9-6.55*log(305))*log10(R) - 36;
                end

                if testA.ReceivedPowerMap(i,j) ~= 0
                    modelA.ReceivedPowerMap(i,j) = modelA.erp + 20*log10((3*10^8/(850*10^6))/(4*pi)) - PL+ 201; %243
                else
                    modelA.ReceivedPowerMap(i,j) = modelA.erp + 20*log10((3*10^8/(850*10^6))/(4*pi)) - 10*n(1)*log10(R);
                end

            elseif RR(i,j) == 2
                if region == 1
                    PL = 46.3 + 33.9*log10(850*10^6)-13.82*log(305)+(44.9-6.55*log(305))*log10(R) + 5;
                elseif region == 2
                    PL = 46.3 + 33.9*log10(850*10^6)-13.82*log(305)+(44.9-6.55*log(305))*log10(R) - 4;
                elseif region == 3
                    PL = 46.3 + 33.9*log10(850*10^6)-13.82*log(305)+(44.9-6.55*log(305))*log10(R) - 7;
                elseif region == 4
                    PL = 46.3 + 33.9*log10(850*10^6)-13.82*log(305)+(44.9-6.55*log(305))*log10(R) - 10;
                elseif region == 5
                    PL = 46.3 + 33.9*log10(850*10^6)-13.82*log(305)+(44.9-6.55*log(305))*log10(R) - 13;
                elseif region == 6
                    PL = 46.3 + 33.9*log10(850*10^6)-13.82*log(305)+(44.9-6.55*log(305))*log10(R) - 22;
                elseif region == 7
                    PL = 46.3 + 33.9*log10(850*10^6)-13.82*log(305)+(44.9-6.55*log(305))*log10(R) - 28;
                else
                    PL = 46.3 + 33.9*log10(850*10^6)-13.82*log(305)+(44.9-6.55*log(305))*log10(R) - 30;
                end

                if testA.ReceivedPowerMap(i,j) ~= 0
                    modelA.ReceivedPowerMap(i,j) = modelA.erp + 20*log10((3*10^8/(850*10^6))/(4*pi)) - PL+ 202; %245
                else
                    modelA.ReceivedPowerMap(i,j) = modelA.erp + 20*log10((3*10^8/(850*10^6))/(4*pi)) - 10*n(2)*log10(R);
                end

            elseif RR(i,j) == 3
                if region == 1
                    PL = 46.3 + 33.9*log10(850*10^6)-13.82*log(305)+(44.9-6.55*log(305))*log10(R) + 7;
                elseif region == 2
                    PL = 46.3 + 33.9*log10(850*10^6)-13.82*log(305)+(44.9-6.55*log(305))*log10(R) - 1;
                elseif region == 3
                    PL = 46.3 + 33.9*log10(850*10^6)-13.82*log(305)+(44.9-6.55*log(305))*log10(R) - 6;
                elseif region == 4
                    PL = 46.3 + 33.9*log10(850*10^6)-13.82*log(305)+(44.9-6.55*log(305))*log10(R) - 9;
                elseif region == 5
                    PL = 46.3 + 33.9*log10(850*10^6)-13.82*log(305)+(44.9-6.55*log(305))*log10(R) - 14;
                elseif region == 6
                    PL = 46.3 + 33.9*log10(850*10^6)-13.82*log(305)+(44.9-6.55*log(305))*log10(R) - 19;
                elseif region == 7
                    PL = 46.3 + 33.9*log10(850*10^6)-13.82*log(305)+(44.9-6.55*log(305))*log10(R) - 27;
                else
                    PL = 46.3 + 33.9*log10(850*10^6)-13.82*log(305)+(44.9-6.55*log(305))*log10(R) - 30;
                end

                if R < 50
                    PL = PL + 15;
                end
                if testA.ReceivedPowerMap(i,j) ~= 0
                    modelA.ReceivedPowerMap(i,j) = modelA.erp + 20*log10((3*10^8/(850*10^6))/(4*pi)) - PL+ 202; %245
                else
                    modelA.ReceivedPowerMap(i,j) = modelA.erp + 20*log10((3*10^8/(850*10^6))/(4*pi)) - 10*n(3)*log10(R);

                end
            end
        end
    end
end

save actualA.mat Cell_Info_D;
Cell_Info_D = modelA;
save modelA.mat Cell_Info_D;
CompareMaps('actualA', 'modelA')