% AutomaticInputMapApplication
% Submitted by      : Engin YAKAR
% Submitted to      : Assoc. Prof. Yagmur Denizhan

% Input:
% InitialPoint: Initial Condition Data Set
% choice: Used to determine for running either My Method or Morgul's Method

% Output:
% returns a vector containing
% meanConvergence: Average convergence value
% meanStabilizing: Average stabilizing value
% minThreshold: Minimum threshold value

function result = AutomaticInputMapApplication(InitialPoint,choice)

[m n] = size (InitialPoint);
ICDataSetSize = n;

% For my method
if choice == 1
    % Set the variables
    period=2;
    endpoint=1000;
    threshold=0.5;
    index = 1;
    for i=1:ICDataSetSize
        mapResult = MyAdjustableHenonMapApplication(period,endpoint,threshold,0,[InitialPoint(1,i);InitialPoint(2,i)]);

        while mapResult(1)==0
            endpoint = endpoint + 1000;
            mapResult = MyAdjustableHenonMapApplication(period,endpoint,threshold,0,[InitialPoint(1,i);InitialPoint(2,i)]);
            endpoint
            mapResult(1)
        end

        convergenceVector(index) = mapResult(2);
        thresholdVector(index) = mapResult(3);
        stabilizingVector(index) = mapResult(4);
        index = index + 1;

        endpoint=1000;
    end
end

% For Morgul's method
if choice == 2
    % Set the variables
    period=2;
    endpoint=1000;
    index = 1;
    for i=1:ICDataSetSize
        
        mapResult = MorgulsHenonMapApplication(period,endpoint,0,[InitialPoint(1,i);InitialPoint(2,i)]);

        while mapResult(1)==0
            endpoint = endpoint + 1000;
            mapResult = MorgulsHenonMapApplication(period,endpoint,0,[InitialPoint(1,i);InitialPoint(2,i)]);
            endpoint
            mapResult(1)
        end

        convergenceVector(index) = mapResult(2);
        thresholdVector(index) = mapResult(3);
        stabilizingVector(index) = mapResult(4);
        index = index + 1;

        endpoint=1000;
    end
end

% Determine average convergence value
meanConvergence = mean(convergenceVector);
% Determine average stabilizing value
meanStabilizing = mean(stabilizingVector);
% Determine minimum threshold value
minThreshold = min(thresholdVector);

result = [meanConvergence,meanStabilizing,minThreshold];
