%------------------------------------------------------------------------------
% Script for finding sheetpile depth manually
% + Use a plot and then visually inspect the results
% + This approach only works for a handful of cases, because multiple cases
%   would take too long.
% Approach:
% + Refresh worksheet
% + Collect data
% + Guess a range of value of D
% + Plot the piledepth equation for each D
% + Visually inspect the plot to find an interval that contains D
%------------------------------------------------------------------------------
% Refresh the workspace
  disp(['Manual method....']);
%------------------------------------------------------------------------------
% Given data:
  Gamma = 18;     % kN/m^3, unit weight of soil
  phi   = pi/6;   % 30deg,  measure of soil friction
  L     = 3;      % m,      height of pile above ground cut
  P     = 30;     % kN/m,   force that soil exerts on pile, per unit m
%------------------------------------------------------------------------------
% Guess range for piledepth D (m)
%------------------------------------------------------------------------------
% I'm being a bit fancy by controlling how the guessing occurs
  lowD = 0; % lowest possible guess of piledepth

% Get initial guess of D
% User must enter a positive number
  disp('Begin guessing. To quit, enter a negative value.');
  newD = input('Enter your largest guess for D [positive only]: ');
  while( ~isnumeric(newD) )
     newD = input('No! You must enter a positive number: ');
  end
%------------------------------------------------------------------------------
% Plot values for each guess
% Could automate this further by letting program decrement D starting
% from initial guess

  while ( newD >=0 )

     % Plot range of D
       pdplot(phi,Gamma,P,L,lowD:newD)
   
     % Ask user to continue
     % I've created functions N and Y that return 0 and 1, respectively
       n=0;y=1; % so user can actually enter the letters n and y
       choice = input('Do you want to stop? [y,n]: ');
       while( ~(choice==0 | choice==1) )
          choice = input('I asked, "Do you want to stop? [y,n]:"! ');
       end
 
     % Stop guessing if 1, otherwise continue
       if choice == y
          newD = -1;
       else
          newD = input('Enter your next guess for D [positive only]: ');
          while( ~isnumeric(newD) )
             newD = input('No! You must enter a positive number: ');
          end
       end
   end
%------------------------------------------------------------------------------
% Flag user when done
  disp('Finished with manual method!')
%------------------------------------------------------------------------------
  restart('manualmethod');
%------------------------------------------------------------------------------
