function h=som_show(sMap, varargin)

% SOM_SHOW Basic map visualizations: component planes, u-matrix etc.
%
% h=som_show(sMap, ['argID', value, ...])
% 
%  som_show(sMap);
%  som_show(sMap,'bar','none');
%  som_show(sMap,'comp',1:3, 'umat',[]);
%  som_show(sMap, 'comp',[1 2], 'umat',{[1 2],'1,2 only'}, 'comp',3:6, ...
%   'umat',[]);
%  som_show(sMap,'size',m,'bar','vert','edge','off');
%
% INPUT ARGUMENTS ([]'s are optional)
%
%  sMap           (struct) map struct
%  ['argID', value] These are given as argID-value pairs (see below): 
%
%   Argument ID (case insensitive)
%
%  'comp'         (vector,string) which component planes to draw: a vector of 
%                  component indices, or string 'all' (or []) for all 
%                  components. 
%  'compi'        as 'comp' but uses interpolated shading
%  'umat'         (vector,string,cell) 
%                  - a vector defines the indices of variables which are 
%                    used to evaluate the u-matrix. 
%                  - empty vector [] or string 'all' means use 'all components'
%                  - cell of form {v, str} uses 'v' as the vector, and
%                    puts the string 'str' as title instead of the default
%                    title 'U-matrix'
%                  Default value is 'all'.
%  'empty'        (string) make an empty plane. String value is used as
%                  title. Default is no title.
%  'color'        (matrix,cell) 
%                  - M x 3 matrix of RGB triples defines the fixed 
%                    unit colors
%                  - a cell of from {rgb, str} uses 'rgb' as the M x 3 RGB
%                    triple matrix and string 'str' as title. 
%                  No default values.
%  'colori'       as 'color' but uses interpolated shading of colors 
%  'norm'         (string) 'n' or 'd' whether to show normalized or 
%                  denormalized data values on the colorbar: 'd' for 
%                  denormalized and 'n' normalized. Default is 'n'.
%  'bar'          (string) colorbar direction: 'horiz', 'vert' or 'none'.
%                  Default is 'vert'.
%  'size'         (scalar, vector) vector specifying the size of each 
%                  node, scalar or size Nx1. Default is 1.
%  'edge'         (string) node edges on component planes 
%                   'on' or 'off'. Default: 'on'
%
% OUTPUT ARGUMENTS 
%
%   h             (struct) struct with the following fields:
%    .plane         (vector) handles to the axes objecets (subplots)
%    .colorbar      (vector) handles to the colorbars. Colorbars for empty
%                     grids & RGB color planes do not exist: they are marked
%                     with -1 in the vector. 
%    .label         (vector) handles to the axis labels
%
% This function shows the component planes and the u-matrix of sMap to the
% current figure. 
% 
% If identifiers 'comp(i)', 'umat(i)', 'color(i)' or 'empty' are not
% specified at all, e.g.: som_show(sMap); som_show(sMap,'bar','none'); etc. 
% the  u-matrix is shown first and then the component planes according to
% their order in the corresponding variables in the map struct. 
%
% For more help, try 'type som_show' or check out the helpdesk. 
% See also SOM_SHOW_ADD, SOM_SHOW_CLEAR, SOM_UMAT, SOM_VIS

%%%%%%%%%%%% DETAILED DESCRIPTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% som_show
%
% PURPOSE 
%
% Shows basic visualizations of SOM's: component planes, unified distance
% matrices - and empty grids or fixed color planes.
%
% SYNTAX
%
%  h=som_show(sMap);
%  h=som_show(sMap, 'argID', value, ...);
%
% DESCRIPTION 
%
% The default operation  - which is set by giving only the map struct as
% input - is to show first the u-matrix followed by all the
% variables in the map presented as component planes. Using different
% optional arguments, their amount and order may be changed. 
%
% Optionally, two other kind of grid visualizations may be used: an empty
% grid, which may be used as a base for, e.g., hit histogram visualization
% or labeling and a fixed color representation which may be used for e.g. 
% clustering visualization or for showing other color codings on the SOM grid. 
%
% The component planes and u-matrices may have colorbars showing the scale for
% the variable. The scale shows by default the values that variables have 
% in the map struct. It may be changed to show the original data values
% (estimated by som_denormalize). In this case a small 'd' appears below the
% colorbar. The orientation of these colorbars may be
% changed, too. If a presentation with no colorbars is desired, you should
% use routine som_vis instead of som_show.
%
% By default the u-matrix is calculated using all the variables. It is
% possible to define the specific variables to be used in calculation. 
%
% REQUIRED INPUT ARGUMENTS
%
% sMap (a map struct) Map to be shown. If only this argument is 
%       specified, the function draws first the u-matrix calculated using 
%       all the variables followed by all the component planes.
%
% OPTIONAL INPUT ARGUMENTS
% 
% (M is the number of map units)
%
% Optional arguments must be given as 'argument identifier', value -pairs
% 
% 'comp'   Defines the variabels to be shown as component planes
%
%    (vector) 1xN or Nx1 vector with integer positive numbers ranging from 
%      1 to the number of variables in the map codebook (d). This vector 
%      determines the variables to be show as component planes and their 
%      order. 
%
%    (string) 'all' or []. This uses all variables, that is, it causes the 
%      same result as using value 1:d where d is the number of variables in
%      the codebook.
% 
%    Note that the same component plane (the same variable index) may occur 
%    several times. Default value for 'comps' is 1:d, where d is the number 
%    of variables in the codebook. Default value is used if an empty object 
%    (e.g. []) is given for value.
%
% 'compi'  Defines the variabels to be shown as component planes  
%
%    Same as 'comp' but uses an Gouraud shaded color plane (made using
%    som_grid command) instead of the cell like visualization of 'comp'
%    (made using som_cplane). Note that the color interpolation doesn't work
%    strictly correctly on 'hexa' grid, as it uses rectangular grid (see SURF).
% 
% 'umat'   Defines the variables to be used while calcualting a u-matrix
% 
%    (vector) of same kind as in 'comps'. However, multiple occurences of
%      the same variable (same variable index) are ignored. 
%
%    (string) 'all' or []. This uses all variables, that is, it causes the 
%      same result as using value 1:d where d is the number of variables in 
%      the codebook.
% 
%    (cell) of form {v, str} where v is a valid index vector for 'umat' 
%      (as in previous cases) and str is a string that is used as a title 
%      for the u-matrix instead of the default title 'U-matrix'. This may 
%      be useful if several u-matrices are shown in the same figure. The 
%      default value for v is 'all' but but for 'str' there is no default 
%      value, that is, an empty string gives no title.
%  
%    Default value for 'umat' is vector 1:d. Default value is used if an 
%    empty object (e.g. []) is given for value. 
% 
% 'empty'   Show an empty grid (patch edges only)
%
%    (string) is used as title. There is no default value here: empty string
%      causes a missing title.
% 
% 'color'   Define fixed RGB colors for the map units
%
%    (matrix): a Mx3 matrix with RGB values as rows. Each row of the matrix 
%      must be a valid RGB value
%             
%    (cell) of form {rgb, str} where rgb is a Mx3 matrix of RGB values as
%      rows and 'str' is a string that is used as title. There is no default
%      values here.
%
% 'colori'  Define fixed RGB colors for the map units
%
%    Same as 'color' but uses an Gouraud shaded color plane (made using
%    som_grid command) instead of the cell like visualization of 'color'
%    (made using som_cplane). Note that the color interpolation doesn't work
%    strictly correctly on 'hexa' grid, as it uses rectangular grid (see SURF).
%
% 'norm'    Defines wheter to use normalized or denormalized values
%
%    (string) 'n' or 'd'. 'n' is default and just uses the values in
%      codebook to determine the scales in colorbars. 'd' uses the
%      normalization information in the map struct to 'dernormalize' the
%      values in colorbars back to the original data scale. If value 'd' is
%      given, a small 'd' appears below the colorbars.
%   
% 'bar'     Define the direction of the colorbars for component planes and 
%           u-matrices or turn them completely off
%
%    (string) 'vert', 'horiz' or 'none'. 'vert' gives vertical and 'horiz'
%      horizontal colorbars. 'none' shows no colorbars at all. 
%      Default value is 'vert'.
%
% 'size'    Define sizes of the units. 
%     
%    - Mx1 vector: each unit gets individual size scaling (as in som_cplane). 
%    - scalar: the units get the same size. 
%
%    Default value is 1.
%
% 'edge'    Unit edges on component plane visualizations
%   
%    (string) 'on' or 'off' determines wheter the unit edges on component 
%      planes ('comp') are shown or not. Default is 'off'. Note that
%      u-matrix and color planes are always drawn without edges.
%
% 'footnote' Text on the figure
%
%    (string) is printed as a movable text object on the figure 
%      where it may be moved using mouse. Default value is the string in 
%      the field 'name' on the map struct. Note: value [] gives the
%      default as usual, but input value '' gives no footnote a all.
%      See vis_footnote for more information on the text object and 
%      ways to change its font size.
%
% OUTPUT ARGUMENTS
%
% h (struct)
%    .plane         (vector) handles to the axes objecets (subplots)
%    .colorbar      (vector) handles to the colorbars. Colorbars of empty
%                            & color planes do not exist: they are marked
%                            with -1 in the vector. 
%    .label         (vector) handles to the axis labels
%
% OBJECT TAGS
%
% The property field 'Tag' of the axis objects created by this function 
% are set to contain string 'Cplane' if the axis contains component plane
% ('comp'), color plane ('color') or empty plane ('empty') and string
% 'Uplane' if it contains a u-matrix ('umat'). The tag is set to 
% 'CplaneI' for planes created using 'compi' and 'colori', and 
% 'UplaneI' for 'umati'.
%
% FEATURES
%
% Note that when interpolated shading is used in coloring ('compi' and
% 'colori') the standard built-in bilinear Gouraud interpolation for a 
% SURF object is used. If the lattice is hexagonal - or anything else than 
% rectangular in general - the result is not strictly what is looked 
% for, especially if the map is small. 
%
% EXAMPLES
%
% % Make random data, normalize it, and give component names
% % Make a map
%
% data=som_data_struct(rand(1000,3),'comp_names',{'One','Two','Three'});
% data=som_normalize(data,'var');
% map=som_make(data);
%
% % Do the basic visualization with som_show: u-matrix and all
% % component planes
%
% som_show(map);   
%
% % The previous command used the values in the codebook (default). The option
% % ...,'norm','d',... would denormalize the codebook values back to the 
% % original data scale (if possible).
%
% som_show(map,'norm','d')
%
% % Something more complex:
% % Show 1-2. Component planes 1 and 2 (variables 'One' and 'Two')
% %        3. U-matrix that is calculated only using variables 'One' and 'Two' 
% %           with title '1,2 only'
% %        4. U-matrix that is calculated using all variables with the 
% %           deafult title 'U-matrix'
% %        5. The color code (in c) with title 'Color code'
% %        6. Component plane 3 (variable 'Three')
% % and  use vertical colorbars and and the values      
% % But first: make a continuous color code (see som_colorcode)
% %
%
% c=som_colorcode(map,'rgb1');
% 
% som_show(map,'comp',[1 2],'umat',{1:2,'1,2 only'},'umat','all', ...
%  'color',{c,'Color code'},'bar','vert','norm','n','comp',3)
%
%  SEE ALSO
%
% SOM_GRID       Visualization of a SOM grid
% SOM_SHOW_ADD   Show hits, labels and trajectories on SOM_SHOW visualization
% SOM_SHOW_CLEAR Clear hit marks, labels or trajectories from current figure. 
% SOM_UMAT       Compute unified distance matrix of self-organizing map.
% SOM_VIS        Advanced SOM visualization tool

% Copyright (c) 1997-1999 by the SOM toolbox programming team.
% http://www.cis.hut.fi/projects/somtoolbox/             
% Version 1.0beta Johan 231097, bug fix 121297, added som_showtitle 100298 
% Version 2.0alpha modifications juha 140699, major modifications johan 201099

%% Check arguments %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

error(nargchk(1,Inf,nargin))     % check no. of input args

if isstruct(sMap),               % check map
  [tmp,ok,tmp]=som_set(sMap);
  if all(ok) & strcmp(sMap.type,'som_map') 
    ;
  else
    error('Map struct is invalid!');
  end
else
  error('Requires a map struct!')
end

munits=size(sMap.codebook,1); % numb. of map units
d=size(sMap.codebook,2);      % numb. of components
msize=sMap.topol.msize;       % size of the map
lattice=sMap.topol.lattice;   % lattice

if length(msize)>2 
  error('This visualizes only 2D maps!')
end

if rem(length(varargin),2)
  error('Mismatch in identifier-value  pairs.');
end

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%  read in optional arguments
 
if isempty(varargin),
  varargin = { 'umat','all','comp','all'};
end

%% check the varargin and build visualization infostrcuts
% Vis:       what kind of planes, in which order, what are the values in
%            the units
% Vis_param: general properties
% see subfunction

% The try-catch construction is here just for avoiding the
% possible termination to happen in subfunction because an error
% message containing subfunction line numbers etc. might be confusing, as
% there probably is nothing wrong with the subfunction but with the 
% input. Ok, this isn't proper programming sytle... 

try       
  [Plane, General]= check_varargin(varargin, munits, d, sMap.name);
catch
  error(lasterr);
end

% Set default values for missing ones

% No planes at all (only general properties given in varargin):
% set default visualization

if isempty(Plane)
  varargin = [varargin, { 'umat','all','comp','all'}];
  % and again we go...
  try
    [Plane, General]= check_varargin(varargin, munits, d, sMap.name);
  catch
    error(lasterr);
  end
end

% set defaults for general properties

if isempty(General.colorbardir)
  General.colorbardir='vert';
end

if isempty(General.scale)
  General.scale='normalized';
end

if isempty(General.size)
  General.size=1;
end

if isempty(General.edgecolor)
  General.edgecolor='none';
end

%% Action %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

n=length(Plane);                     % the number of subfigures

% get the unique component indices
c=General.comp(General.comp>0);
c=setdiff(unique(c),[0 -1]); 
c=c(~isnan(c));                   

% estimate the suitable dimension for
y=ceil(sqrt(n));                   % subplots
x=ceil(n/y);

clf;                               % clear figure

for i=1:n,                         % main loop
  h_axes(i,1)=subplot(x,y,i);      % open a new subplot
  
  % Main switch: select function according to the flags set in comps  

  switch Plane{i}.mode
  
  case 'comp'
    %%% Component plane

    tmp_h=som_cplane(lattice,msize, sMap.codebook(:,General.comp(i)), ...
		     General.size);
    set(tmp_h,'EdgeColor', General.edgecolor);
    set(h_axes(i),'Tag','Cplane');
    h_label(i,1)=xlabel(sMap.comp_names{General.comp(i)});
    

  case 'compi'
    %%% Component plane (interpolated shading)
    
    tmp_h=som_grid(lattice, msize, 'surf', sMap.codebook(:,Plane{i}.value), ...
	'Marker', 'none', 'Line', 'none');
    set(h_axes(i),'Tag','CplaneI');
    h_label(i,1)=xlabel(sMap.comp_names(Plane{i}.value));
    vis_PlaneAxisProperties(gca,lattice,msize,NaN);
  
  case 'color'
    %%% Color plane  
    
    tmp_h=som_cplane(lattice,msize,Plane{i}.value,General.size);
    set(tmp_h,'EdgeColor','none');
    set(h_axes(i),'Tag','Cplane');
    h_label(i,1)=xlabel(Plane{i}.name);
    
  case 'colori'
    %%% Color plane (interpolated shading)
    
    tmp_h=som_grid(lattice, msize, 'surf', Plane{i}.value, 'Marker', 'none', ...
	'Line', 'none');
    set(h_axes(i),'Tag','CplaneI');
    h_label(i,1)=xlabel(Plane{i}.name);
    vis_PlaneAxisProperties(gca,lattice,msize,NaN);
  
  case 'empty'      
    %%% Empty plane
    
    tmp_h=som_cplane(lattice,msize,'none');
    h_label(i,1)=xlabel(Plane{i}.name);
    set(h_axes(i),'Tag','Cplane');
    
  case 'umat'
    %%% Umatrix  
    
    u=som_umat(sMap.codebook(:,Plane{i}.value),sMap.topol,'median',...
	'mask',sMap.mask(Plane{i}.value)); u=u(:);
    tmp_h=som_cplane([lattice 'U'],msize,u);
    set(tmp_h,'EdgeColor','none');
    set(h_axes(i),'Tag','Uplane');
    h_label(i,1)=xlabel(Plane{i}.name);

  case 'umati'
    %%% Umatrix (interpolated shading) 
    
    u=som_umat(sMap.codebook(:,Plane{i}.value),sMap.topol,'mean',...
	'mask',sMap.mask(Plane{i}.value)); u=u(1:2:end,1:2:end);
    u=u(:);
    tmp_h=som_grid('rect', msize, 'surf', u, ...
	'Marker', 'none', 'Line', 'none', ...
	'coord', som_vis_coords(lattice,msize));
    set(h_axes(i),'Tag','UplaneI');
    h_label(i,1)=xlabel(Plane{i}.name);
    vis_PlaneAxisProperties(gca,lattice,msize,NaN);
    
  otherwise
    error('INTERNAL ERROR: unknown visualization mode.');
  end

  %%% Adjust axis ratios to optimal (only 2D!) and put the
  %%% title as close to axis as possible

  set(h_label,'Visible','on','verticalalignment','top');
  set(gca,'plotboxaspectratio',[msize(2) msize(1) msize(1)]);
  
  %%% Draw colorbars if they are turned on and the plane is umat or c-plane

  if General.comp(i)> -1 & ~strcmp(General.colorbardir,'none'),
    h_colorbar(i,1)=colorbar(General.colorbardir);           % colorbars
  else
    h_colorbar(i,1)=-1;
    General.comp(i)=-1;
  end
end         %% main loop ends
  
% Set window name

set(gcf,'Name',[ 'Map name: ' sMap.name]);

%% Set axes handles to the UserData field (for som_addxxx functions
%% and som_recolorbar) 
%% set component indexes and normalization struct for som_recolorbar

SOM_SHOW.subplotorder=h_axes;
SOM_SHOW.msize=msize;
SOM_SHOW.lattice=lattice;
SOM_SHOW.dim=d;
SOM_SHOW.comps=General.comp;
SOM_SHOW.comp_norm=sMap.comp_norm(General.comp(find(General.comp>0)));

set(gcf,'UserData', SOM_SHOW);

% Set text property 'interp' to 'none' in title texts

set(h_label,'interpreter','none');

h_colorbar=som_recolorbar('all','auto', General.scale);   %refresh colorbars

% Set a movable text to lower corner pointsize 12.

vis_footnote(General.footnote);  vis_footnote(12);  

%% Build output %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 

if nargout > 0
  h.plane=h_axes; h.colorbar=h_colorbar; h.label=h_label;
end


%%%%%% SUBFUNCTIONS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

function [Plane, General]=check_varargin(args, munits, dim, name)

% args: varargin of the main function
% munits: number of map units
% dim: map codebook dimension
% name: map name
% Define some variables (they must exist later)

Plane={};           % stores the visualization data for each subplot
General.comp=[];    % information stored on SOM_SHOW figure (which component)
General.size=[];            % unit size
General.scale=[];           % normalization
General.colorbardir=[];     % colorbar direction
General.edgecolor=[];       % edge colors
General.footnote=name;      % footnote text

for i=1:2:length(args),
  %% Check that all argument types are strings
  
  if ~ischar(args{i}),
    error('Invalid input identifier names or input argument order.');
  end
  
  %% Lower/uppercase in identifier types doesn't matter: 
  
  identifier=lower(args{i});     % identifier (lowercase)
  value=args{i+1};
  
  %%% Check first the identifiers that define planes and get values
  %%% to the visualization data struct array Plane.
  %%% (comps,compi,umat,color,empty) Note that name, value and comp_
  %%% must be specified in these cases 
  %%% comp_ are collected to comp in order. This is stored to the
  %%% SOM_SHOW user property field to give information for SOM_RECOLROBAR
  %%% how to operate, i.e., which component is in which subplot:
  %%% comp(i)=0: draw colorbar, but no normalization (umat) 
  %%% comp(i)=1...N: a component plane of variable comp(i)
  %%% comp(i)=-1: no colorbar (color or empty plane)    
  
  switch identifier  
   case {'comp','compi'}
    %%% Component planes: check values & set defaults
    
    if ~vis_valuetype(value,{'nx1','1xn','string'}) & ~isempty(value),
      error([ 'A vector argument or string ''all'' expected for ''' ...
	      identifier '''.'])
    end
    if isempty(value) 
      value=1:dim;
    elseif ischar(value), 
      if ~strcmp(value,'all')
	error([ 'Only string value ''all'' is valid for ''' ...
		identifier '''.']);
      else
	value=1:dim;
      end
    else
      value=round(value);
      if min(value)<1 | max(value)>dim,
	error([ 'Component indices out of range in ''' identifier '''.']) 
      end
    end
    if size(value,1)==1, value=value';end
    comp_=value; 
    name=[]; % name is taken form sMap by index in main loop 
    
  case {'umat','umati'}
    %%% Check first the possible cell input
    
    if iscell(value),
      if ndims(value) ~= 2 | any(size(value) ~= [1 2]) | ...
	    ~vis_valuetype(value{2},{'string'}),
	error('Cell input for ''umat'' has to be of form {vector, string}.');
      else
	name=value{2}; value=value{1};
      end
    else 
      name='U-matrix'; % no cell: default title is set
    end
    if ~vis_valuetype(value,{'nx1','1xn','string'}) & ~isempty(value),
      error('Vector, string ''all'', or cell {vector, string} expected for ''umat''.')
    end
    if isempty(value)
      value=1:dim;
    elseif ischar(value), 
      if ~strcmp(value,'all')
	error('Only string value ''all'' is valid for ''umat''.')
      else
	value=1:dim;
      end
    else
      value=unique(round(value));
    end
    if min(value)<1 | max(value)>dim,
      error('Component indices out of ranage in ''umat''.') 
    end
    
    if size(value,1)==1, value=value';end
    comp_=0;
    
  case 'empty'
    %%% Empty plane: check values & set defaults
    
    if ~vis_valuetype(value,{'string'}), 
      error('A string value for title name expected for ''empty''.');
    end
    name=value;
    comp_=-1;
    
  case { 'color','colori'}
    %%% Color plane: check values & set defaults
    
    % Check first the possible cell input
    if iscell(value),
      if ndims(value)~=2 | any(size(value) ~= [1 2]) | ...
	    ~vis_valuetype(value{2},{'string'}),
	error([ 'Cell input for ''' identifier ...
	      ''' has to be of form {RGBmatrix, string}.']);
      else
	name=value{2}; value=value{1};
      end
    else 
      name='Color code'; % no cell: default title is set
    end
    if ~vis_valuetype(value,{ 'nx3rgb',[munits 3]},'all')
      error(['A munits x 3 RGB matrix or cell {RGBmatrix, string}' ...
	     ' expected for ''' identifier '''.']);
    end
    comp_=-1;
    
    %%%% The next things are general properties of the visualization---
    %%%%
    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    
  case 'size'
    %%% Unit size: check & set
  
    if ~vis_valuetype(value,{'1x1',[munits 1]})
      error('A munits x 1 vector or a scalar expected for ''size''.')
    end
    if isempty(value),
      General.size=1;
    else
      General.size=value;
    end
    
   case 'bar'
    %%% Colorbar existence & direction: check & set
    
    if ~vis_valuetype(value,{'string'})
      error('String value expected for ''bar''.')
    elseif isempty(value)
      value='vert';
    end
    if any(strcmp(value,{'vert','horiz','none'})),
      General.colorbardir=value;
    else
      error('String ''vert'', ''horiz'' or ''none'' expected for ''bar''.');
    end
    
  case 'norm' 
    %%% Value normalization: check & set
    
    if ~vis_valuetype(value,{'string'})
      error('String ''n'' or ''d'' expected for ''norm''.');
    elseif isempty(value)
      value='n';
    end
    if strcmp(value(1),'n'), 
      General.scale='normalized';
    elseif strcmp(value(1),'d'),
      General.scale='denormalized';
    else
      error('String ''n(ormalized)'' or ''d(enormalized)'' expected for ''norm''.');
    end
    
  case 'edge'
    %%% Edge on or off : check % set 
    
    if ~vis_valuetype(value,{'string'}) & ~isempty(value),
      error('String value expected for ''edge''.')
    elseif ~isempty(value),
      switch value
      case 'on'
	General.edgecolor='k';
      case 'off' 
	General.edgecolor='none';
      otherwise
	error('String value ''on'' or ''off'' expected for ''edge''.')  
      end
    end
    
  case 'footnote'
    %%% Set the movable footnote text  
    
    if ~vis_valuetype(value,{'string'}) 
      if ~isempty(value),
	error('String value expected for ''footnote''.');
      else
	General.footnote=sMap.name;
      end
    else
      General.footnote=value;
    end
  
  otherwise
    %%% Unknown identifier
    
    error(['Invalid argument identifier ''' identifier '''!']);
  end
  
  %%% Set new entry to the Plane array if the indentifier means 
  %%% making a new plane/planes
  
  tail=length(Plane);
  switch identifier
  case {'comp','compi'}
    for i=1:length(value)
      Plane{tail+i}.mode=identifier;
      Plane{tail+i}.value=value(i);
      Plane{tail+i}.name=name; % not used actually
    end
    General.comp = [General.comp; comp_];
  case {'umat','umati','color','colori','empty'}
    Plane{tail+1}.mode=identifier;
    Plane{tail+1}.value=value;
    Plane{tail+1}.name=name;
    General.comp = [General.comp; comp_];
  otherwise
    ; % do nothing
  end
end

