%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% loadandplot
%
% Loads an ASCII file representing scalar values on 
% a plane into a Matlab variable, and generates different
% plots from it.
%
% Author:  Carlos J. Cela <carlos.cela@utah.edu>
% Version: V1.0, 2012-01-08
% License: Please feel free to use this for anything you need.
%
% Use:
%       loadandplot( fileName, sizeX, sizeY, labelX, labelY, plotTitle)
%
%           Where:
%                     fileName  = Name of ASCII file to read.
%                     sizeX     = Size of array in the X direction.
%                     sizeY     = Size of the array in the Y direction.
%                     labelX    = Label for X-axis of plot.
%                     labelY    = Label for Y-axis of plot.
%                     plotTitle = Title of plot.
%
% Example:
%       loadandplot("test.txt", 100, 100, "X-axis", "Y-axis", "Scalar Field Plot")
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

function [ ret ] = loadandplot( fileName, sizeX, sizeY, labelX, labelY, plotTitle)

  % Load data into array, sizing array as requested 
  data = load( fileName );
  data = reshape(data, sizeX, sizeY);

  % Calculate number of values read
  s = size(data);
  ret = s(1)*s(2);

  % Plot scaled image
  figure(1);
  imagesc(data);
  colormap hot;
  set(gca,'YDir','normal'); % Flip the Y axis to set origin on lower left
  xlabel(labelX);
  ylabel(labelY);
  title(plotTitle);
  set(gca, 'fontsize', 14);
  colorbar();

  % Line plot of center row of image
  center = ceil(sizeX/2);
  figure(2);
  plot(data(center,:),'r', 'linewidth',3);
  grid on;

  % Plot contour
  figure(3);
  contour(data);

  % Plot surface
  figure(4);
  surf(data);

end
