function [ ls, vs ] = plotLS(times, type, infinity, plotType, figHandle)
% function to plot the results of an LS run
%
% Ian Mitchell 6/23/00
%
% figHandle	== 0:	current figure is used (hold is not toggled)
%		>  0:   draw within that figure (hold is not toggled)
%		<  0:   create a new figure
%
% $Id: plotLS.m,v 1.1 2000/10/11 16:45:02 imitchel Exp imitchel $

fileroot = '/tmp/Aircraft3D/air.100';
fileTimeMultiplier = 100;

stride = 1;

scaleFactors = [ 25; 25; 2*pi ];                        % for aircraft3D 
%scaleFactors = [ 1; 1; 1 ];				% unscaled

aspectRatio = [ 1; 1; 0.5 ];                            % for aircraft3D 
%aspectRatio = [ 1; 1; 1 ];				% display as is

if(nargin < 1)
  times = 0;
end

if(nargin < 2)
  type = 'curr';
end

if(nargin < 3)
  infinity = inf;
end

if((nargin < 5) | (figHandle < 0))
  figure;
  grid on;
elseif(figHandle > 0)
  figure(figHandle)
end

% need to make sure that h has a value
h = [];

for i = 1:length(times)

  if((type(1) == '/') | (type(1) == '~') | (type(1) == '.') | (type(2) == ':'))
    filename = type;
  else
    filename = sprintf('%s.%s.%04.0f', fileroot, type, ...
                                       fileTimeMultiplier * times(i));
  end

  if(i == 1)
    [ ls, vs ] = loadFunc(filename, stride);

    if(~isempty(scaleFactors) & (length(vs) > length(scaleFactors)))
      error('wrong number of dimensions in scaleFactors');
    else
      for j = 1:length(vs)
        vs{j} = vs{j} * scaleFactors(j);
      end
    end

    % default settings for visualization type
    if(nargin < 4)
      if(length(vs) == 2)
        if(strcmp(type, 'curr') | strcmp(type, 'min'))
          plotType = 'contour';
        else
          plotType = 'surf';
        end
      elseif(length(vs) == 3)
        plotType = 'mesh';
      else
        plotType = 'other';
      end
    end

  else
    ls = loadFunc(filename, stride, infinity);
  end

  % strip off "infinite" values
  ls(find(abs(ls) == infinity)) = NaN;

  if(all(isnan(ls)))
    disp([ 'level set at time ' num2str(times(i)) ...
           ' contains no finite values; terminating.' ]);
    return;
  end

  if(i > 1)
    pause;
    if(~isempty(h))  delete(h);  end
  end

  if(length(times) > 1)
    disp([ 'Time: ' num2str(times(i)) ]);
  end

  h = dispLS(ls, vs, plotType, aspectRatio);

  %drawnow;
end
