function [] = plot1(GUILOCATION, FileName, Strain, Modulus, Strain2, Damping, Selection, Type)
%PLOT1 Summary of this function goes here
%   Detailed explanation goes here

StrainOri = Strain;
ModulusOri = Modulus;
Strain2Ori = Strain2;
DampingOri = Damping;

ShearOri = Strain.*Modulus/100;
Shear = Strain.*Modulus/100;
ShearOri = Strain.*Modulus/100;
NYS = length(Strain);

if Type == 3
    ShearStrength = Shear(end);
end

% Loop as long as user wish to modify material
while Selection == 2
    
    % Obtain user input
    num_lines = [1 125; 2 125; 2 125];
    options.Resize='on';
    options.WindowStyle='normal';
    
    if Type == 1 || Type == 2
        
        if Type == 1
            dlg_title = 'Define New Material';
        elseif Type == 2
            dlg_title = 'Modify Existing Material';
        end
        
        prompt = {'Enter File Name:','Enter Strain Values (%) for G/Gmax:', ...
            'Modulus Reduction (G/Gmax):'};
        def = {FileName, num2str(Strain), num2str(Modulus)};
        answer = inputdlg(prompt,dlg_title,num_lines,def,options);
        
        if isempty(answer)
            return
        end
        
        FileName = cell2mat(answer(1));
        Strain = str2num(cell2mat(answer(2)));
        Modulus = str2num(cell2mat(answer(3)));
        
    elseif Type == 3
        
        prompt = {'Enter File Name:','Enter Strain Values (%) for Shear Stress:', ...
            'Enter Shear Stress Values (/Gmax, the last value will be set to equal the Shear Strength set below):',...
            'Enter Shear Strength (one value and divided by Gmax, this value controls the last few values for Shear Stress):'};
        dlg_title = 'Use Shear Strength to Modify Material';
        num_lines = [1 125; 2 125; 2 125; 1 125];
        def = {FileName, num2str(Strain), num2str(Shear),...
            num2str(ShearStrength)};
        answer = inputdlg(prompt,dlg_title,num_lines,def,options);
        
        if isempty(answer)
            return
        end
        
        FileName = cell2mat(answer(1));
        Strain = str2num(cell2mat(answer(2)));
        Shear = str2num(cell2mat(answer(3)));
        ShearStrength = str2num(cell2mat(answer(4)));
        Modulus = Shear./Strain*100;
        
    elseif Type == 4
        
        prompt = {['Enter Desired Number of Yield Surface (should be more than ', num2str(length(Strain)), ')']};
        dlg_title = 'Use Number of Yield Surface to Modify Material';
        num_lines = [1 75];
        def = {num2str(NYS)};
        
        options.Resize='on';
        options.WindowStyle='normal';
        
        answer1 = inputdlg(prompt,dlg_title,num_lines,def,options);
        
        if isempty(answer1)
            return
        end
        
        answer = {FileName};
        NYS = str2num(cell2mat(answer1(1)));
        
        if isempty(NYS)
            errordlg('NYS should be a number.')
            break
        elseif rem(NYS,1) ~= 0
            errordlg('Material Number should be an integer.')
            return
        elseif NYS <= length(Strain)
            errordlg(['NYS should be more than ', num2str(length(Strain))]) 
        end
        
    else
        return
    end
    
    if isempty(Strain)
        errordlg('Strain for modulus should be a vector of numbers.')
        return
    elseif length(Strain) <= 0
        errordlg('No values were assigned.', 'Invalid Input for Strain')
        return
    end
    
    if isempty(Modulus)
        errordlg('Modulus should be a vector of numbers.')
        return
    elseif length(Modulus) <= 0
        errordlg('No values were assigned.', 'Invalid Input for Modulus')
        return
    elseif length(Modulus) ~= length(Strain)
        errordlg('Amount of Strain values do not match the amount for Modulus.', ...
            'Mismatched Vector Lengths for Strain and Modulus')
        return
    end
    
    Shear = Strain/100.*Modulus;
    
    % Check Slope of Stress - Strain curve
    Slope = zeros(1, length(Shear));
    Slope(1) = Shear(1)/Strain(1);
    for i = 1:length(Shear)-1
        Slope(end-i+1) = (Shear(end-i+1) - Shear(end-i))/(Strain(end-i+1) - Strain(end-i));
    end
    
    if Type == 3
        [Shear, Slope] = ShearStrengthAdj(Strain, Shear, Slope, ShearStrength);
        Modulus = Shear./Strain*100;
    end
    
    SlopeRatio = Slope(2:end)./Slope(1:end-1);

    if Type == 4 && NYS > length(Strain)
        [Strain, Shear, Slope, SlopeRatio] = NYSAdj(Strain, Shear, Slope, SlopeRatio, NYS);
        Modulus = Shear./Strain*100;
    end
    
    if Type == 4
        
        if sum(isnan(Shear)) > 0 || length(unique(Strain)) ~= length(Strain)
            
            Strain = StrainOri;
            Shear = ShearOri;
            Modulus = Shear./Strain*100;
            NYS = length(Strain);
            h = errordlg('Entered NYS is too high.');
            uiwait(h)
            
        end
        
    end
        
    
    if sum(SlopeRatio > 1.0001) > 0
        
        if Type == 4
            
            Strain = StrainOri;
            Shear = ShearOri;
            Modulus = Shear./Strain*100;
            NYS = length(Strain);
             h = errordlg('Entered NYS is too high.');
            uiwait(h)
            
        else
            
            h = errordlg('Slope for Stress Strain curve should be always be decreasing or constant.');
            uiwait(h)
            
        end
        
    else
        
        % Plot user input
        size = get(0,'ScreenSize');
        figure('units','normalized','outerposition',[0 0 500/size(3) 1])
        if Type == 1
            
            subplot(2,1,2)
            plot([0 Strain], [0 Shear])
            xlabel('Strain (%)')
            ylabel('Stress (/Gmax)')
            title('Strain (%) vs. Stress (/Gmax)')
            
            subplot(2,1,1)
            semilogx([0 Strain], [1 Modulus])
            xlabel('Strain (%)')
            ylabel('Modulus (G/Gmax)')
            title('Strain (%) vs. Modulus (G/Gmax)')
            
        else
            
            subplot(2,1,2)
            plot([0 StrainOri], [0 ShearOri], 'r')
            hold on
            
            plot([0 Strain], [0 Shear])
            legend('Original', 'Modified', 'Location','Southeast')
            xlabel('Strain (%)')
            ylabel('Stress (/Gmax)')
            title('Strain (%) vs. Stress (/Gmax)')
            hold off
            
            subplot(2,1,1)
            semilogx([0 StrainOri], [1 ModulusOri], 'r')
            hold on
            
            semilogx([0 Strain], [0 Modulus])
            legend('Original', 'Modified')
            xlabel('Strain (%)')
            ylabel('Modulus (G/Gmax)')
            title('Strain (%) vs. Modulus (G/Gmax)')
            hold off
            
        end
        
        % Ask user if they wish to save or not
        choice = questdlg('Would you like to save your inputs?', 'Save Inputs',...
            'Yes', 'No', 'Keep Modifying', 'No');
        adj = 0;
        
        if ~isempty(choice)
            switch choice
                case 'Yes'
                    
                    close
                    Selection = 1;
                    
                    % Check if user is saving over an existing file
                    while exist([GUILOCATION, '\Material\',...
                            FileName, '.txt'])
                        
                        % Ask user if they wish to save over existing file or not
                        choice2 = questdlg('A file with that name already exist are you sure you want to save?', 'Save Inputs',...
                            'Yes', 'No', 'Change Name', 'No');
                        adj = 0;
                        
                        switch choice2
                            case 'Yes'
                                
                                % Check if user is saving over default material file
                                while strcmpi(answer(1), 'Clay') || strcmpi(answer(1), 'Rock') ||...
                                        strcmpi(answer(1), 'Sand') || strcmpi(answer(1), 'PI - 0') ||...
                                        strcmpi(answer(1), 'PI - 15') || strcmpi(answer(1), 'PI - 30')...
                                        || strcmpi(answer(1), 'PI - 50') || strcmpi(answer(1), 'PI - 100')...
                                        || strcmpi(answer(1), 'PI - 200')
                                    
                                    prompt = {'Cannot save over default materials. Enter a Different File Name:'};
                                    dlg_title = 'Enter a Different File Name';
                                    num_lines = [1 75];
                                    def = {FileName};
                                    
                                    options.Resize='on';
                                    options.WindowStyle='normal';
                                    
                                    answer = inputdlg(prompt,dlg_title,num_lines,def,options);
                                    
                                    if isempty(answer)
                                        return
                                    end
                                    FileName = cell2mat(answer(1));
                                    adj = 1;
                                end
                                
                                if adj == 0
                                    break
                                end
                                
                            case 'No'
                                return
                            case 'Change Name'
                                
                                % Prompts user enter new file name
                                prompt = {'Enter a Different File Name:'};
                                dlg_title = 'Enter a Different File Name';
                                num_lines = [1, 50];
                                
                                def = {FileName};
                                
                                options.Resize='on';
                                options.WindowStyle='normal';
                                
                                answer = inputdlg(prompt,dlg_title,num_lines,def,options);
                                
                                if isempty(answer)
                                    return
                                end
                                
                                FileName = cell2mat(answer(1));
                                
                                if isempty(FileName)
                                    return
                                end
                        end
                        
                    end
                    
                    % Save defined material
                    fid = fopen([GUILOCATION, '\Material\', FileName, '.txt'],'w');
                    
                    fprintf(fid, '%s\n', 'Modulus');
                    fprintf(fid, '%2.0f\n', length(Strain));
                    fprintf(fid, '%10s %10s\n', 'Strain', 'Modulus');
                    
                    for i = 1:length(Strain)
                        fprintf(fid, '%f %f\n',Strain(i), Modulus(i));
                    end
                    
                    fprintf(fid, '%s\n', 'Damping');
                    fprintf(fid, '%2.0f\n', length(Strain2));
                    fprintf(fid, '%10s %10s\n', 'Strain', 'Damping');
                    
                    for i = 1:length(Strain2)
                        fprintf(fid, '%f %f\n',Strain2(i), Damping(i));
                    end
                    
                    fclose(fid);
                    
                case 'Keep Modifying'
                    
                    % Allow user to keep modifying material
                    Selection = 2;
                    close
                    
                case 'No'
                    
                    % End
                    Selection = 3;
                    close
                    
            end
        else
            
            Selection = 3;
            close
            fclose('all'); %#ok<*PRTCAL>
            
        end
        
    end
    
end

end

