function [xx, yy] = less_simple_plot(fname,cols_to_plot,plot_type)
% Function  [xx, yy] = less_simple_plot(fname, cols_to_plot, plot_type)
%
% This m-file is a less simple plotting utility than really_simple_plot.m.
% It accepts the following arguments:
%   fname        :  The name of the input file of column data to read in
%   cols_to_plot :  A vector indicating which columns of fname to plot 
%                   (optional)
%   plot_type    :  A string indicating if the plot should be a log plot 
%                   (optional).  Possibilities are 'lin', 'logx', 'logy', 
%                   and 'logxy'.
% Its outputs are the following:
%   xx           :  The first column of fname, assumed to be the independent
%                   variable
%   yy           :  A matrix comprised of the columns of fname given by the 
%                   vector cols_to_plot


% As before, read in the data from the file fname and determine its size.
data = load(fname);
[m n] = size(data);

% In Matlab, nargin is a function that determines how many input arguments
% were passed to the function.
% We can use nargin to set up default values for the optional arguments:
if nargin == 1
  cols_to_plot = 2:n;
  plot_type = 'lin';
elseif nargin == 2
  plot_type = 'lin';
end

% As before, the first column is assumed to define the x-axis and 
% the remaining columns, defined now by cols_to_plot, 
% are to be plotted against this.
x = data(:,1);
y = data(:,cols_to_plot);

% Test to see what type of plot it is and use the appropriate plotting 
% command:
switch plot_type
  case {'lin'}
    plot(x,y);
  case {'logx'}
    semilogx(x,y);
  case {'logy'}
    semilogy(x,y);
  case {'logxy'}
    loglog(x,y);
  otherwise
    error('Unknown plot_type argument.  Quitting.');
end

% Also note that in this code, the output [x y] is the x and y data 
% defined by the first column of fname and the columns defined
% by cols_to_plot, respectively.  
% So, if there are two output arguments present, 
% assign x and y to them:
if nargout == 2
  xx = x;
  yy = y;
end

%% Question:  What are the pitfalls and limitations of this code?