function figure_handle = show_intensity_model(intensity_model, n_sds, max_modes, fig_title, image_width)
% SHOW_INTENSITY_MODEL: Shows the intensity model in the form of
%                       a figure.
%
% Code written by Katherine Smith, 2003
%
%    GENERAL
%
%      show_intensity_model(intensity_model, n_sds, max_modes, fig_title)
%
%    INPUT/S
%
%      -intensity_model:
%           The intensity model to be shown.
%
%      -n_sds:
%           Number of standard deviations.
%
%      -max_modes: 
%           Maximum modes, meaning what??
%
%      -fig_title:
%           Title of the figure to be displayed?
%
%           
%    OUTPUT/S
%
%      -None.
%
%    PENDING WORK
%
%      -
%
%    KNOWN BUG/S
%
%      -None.
%
%    COMMENT/S
%
%      -
%
%    RELATED FUNCTION/S
%
%      SHOW_SHAPE_MODEL, SHOW_COMBINED_MODEL
%
%    ABOUT
%
%      -Created:     November 23rd, 2003
%      -Last update: Novermber 26th, 2003
%      -Revision:    0.0.2
%      -Author:      R. S. Schestowitz, University of Manchester
% ==============================================================

%n_modes = size(intensity_model.pcs,2);

n_modes = min(size(intensity_model.pcs,2),max_modes); 
               % get number of modes. The one above (in comments)
               % is probably the remains of an older version.

fig = figure('Name',([fig_title,'Intensity modes'])); 
                    % prepare figure and assign name input
figure_handle = figure(fig);


for m=1:n_modes % for all modes as resolved above
  for i=-n_sds:n_sds  % for range of negative deviations to possitive ones
                      % with (currently) one unit steps (too large??)
    % Smith: what are the parameters corresponding to this sd
    % create example with these parameters
    example_params = repmat(i*intensity_model.sd(1,m),size(intensity_model.pcs,1),1);
                       % get the parameters of the models
    example = example_params.*intensity_model.pcs(:,m) + intensity_model.mean';
                       % apply the changes according to the mode parameters. Use
                       % them as an offset to the mean intensity model
    figure(fig);

    subplot(n_modes, n_sds * 2 + 1, (m - 1) * (n_sds * 2 + 1) + i + n_sds + 1);
    plot(example);
	                 % plot the different modes of intensity variation
    axis([0 image_width -1 1.4]);
    if (m == 1 & i ==1),
      text(1,1,'Intensity Model');
    end
  end
end