Index: /issm/trunk-jpl/externalpackages/cm_and_cb_utilities/Contents.m
===================================================================
--- /issm/trunk-jpl/externalpackages/cm_and_cb_utilities/Contents.m	(revision 11804)
+++ /issm/trunk-jpl/externalpackages/cm_and_cb_utilities/Contents.m	(revision 11804)
@@ -0,0 +1,16 @@
+% Utilities for coloring with MATLAB by Carlos Vargas.
+%
+% COLORMAP utilites:
+%   cmapping - Colormap linear mapping/interpolation.                        v1.1    (Sep 02, 2009)
+%   cmfit    - Sets the COLORMAP and CAXIS to specific color bands.          v1.0    (Jun 08, 2009)
+%   cmjoin   - Joins colormaps at certain levels.                            v2.0    (Jun 08, 2009)
+%   cmlines  - Change the color of plotted lines using the colormap.         v1.0    (Jun 08, 2009)
+%
+% COLORBAR utilities:
+%   cbfit    - Draws a colorbar with specific color bands between its ticks. v2.1    (Sep 30, 2009)
+%   cbfreeze - Freezes the colormap of a colorbar.                           v1.1    (Sep 02, 2009)
+%   cbhandle - Handle of current colorbar axes.                              v1.1    (Aug 20, 2009)
+%   cblabel  - Adds a label to the colorbar.                                 v2.0    (Jun 08, 2009)
+%   cbunits  - Adds units to the colorbar ticklabels.                        v3.0    (Sep 30, 2009)
+%
+% Sep 30, 2009
Index: /issm/trunk-jpl/externalpackages/cm_and_cb_utilities/cbfit.m
===================================================================
--- /issm/trunk-jpl/externalpackages/cm_and_cb_utilities/cbfit.m	(revision 11804)
+++ /issm/trunk-jpl/externalpackages/cm_and_cb_utilities/cbfit.m	(revision 11804)
@@ -0,0 +1,252 @@
+function CBH = cbfit(varargin)
+%CBFIT   Draws a colorbar with specific color bands between its ticks.
+% 
+%   SYNTAX:
+%           cbfit
+%           cbfit(NBANDS)               % May be LBANDS instead of NBANDS
+%           cbfit(NBANDS,CENTER)
+%           cbfit(...,MODE)
+%           cbfit(...,OPT)
+%           cbfit(CBH,...)
+%     CBH = cbfit(...);
+%
+%   INPUT:
+%     NBANDS - Draws a colorbar with NBANDS bands colors between each tick
+%      or      mark or a colorband between the specifies level bands
+%     LBANDS   (LBANDS=NBANDS).
+%              DEFAULT: 5     
+%     CENTER - Center the colormap to this CENTER reference.
+%              DEFAULT: [] (do not centers)
+%     MODE   - Specifies the ticks mode (should be before AP,AV). One of:
+%                'manual' - Forces color ticks on the new bands. 
+%                'auto'   - Do not forces
+%              DEFAULT: 'auto'
+%     OPT    - Normal optional arguments of the COLORBAR function (should
+%              be the last arguments).
+%              DEFAULT: none.
+%     CBH    - Uses this colorbar handle instead of current one.
+%
+%   OUTPUT (all optional):
+%     CBH  - Returns the colorbar axes handle.
+%
+%   DESCRIPTION:
+%     Draws a colorbar with specified number of color bands between its
+%     ticks by modifying the current colormap and caxis.
+%
+%   NOTE:
+%     * Optional inputs use its DEFAULT value when not given or [].
+%     * Optional outputs may or not be called.
+%     * Sets the color limits, CAXIS, and color map, COLORMAP, before using
+%       this function. Use them after this function to get the
+%       modifications.
+%
+%   EXAMPLE:
+%     figure, surf(peaks+2), colormap(jet(14)), colorbar
+%      title('Normal colorbar.m')
+%     figure, surf(peaks+2),                    cbfit(2,0)
+%      title('Fitted 2 color bands and centered on zero')
+%     figure, surf(peaks+2), caxis([0 10]),     cbfit(4,8)
+%      title('Fitted 4 color bands and centered at 8')
+%
+%   SEE ALSO:
+%     COLORBAR
+%     and
+%     CBFREEZE, CMFIT by Carlos Vargas
+%     at http://www.mathworks.com/matlabcentral/fileexchange
+%
+%
+%   ---
+%   MFILE:   cbfit.m
+%   VERSION: 2.1 (Sep 30, 2009) (<a href="matlab:web('http://www.mathworks.com/matlabcentral/fileexchange/authors/11258')">download</a>) 
+%   MATLAB:  7.7.0.471 (R2008b)
+%   AUTHOR:  Carlos Adrian Vargas Aguilera (MEXICO)
+%   CONTACT: nubeobscura@hotmail.com
+
+%   REVISIONS:
+%   1.0      Released as COLORBARFIT.M. (Mar 11, 2008)
+%   1.1      Fixed bug when CAXIS is used before this function. (Jul 01,
+%            2008)
+%   1.2      Works properly when CAXIS is used before this function. Bug
+%            fixed on subfunction and rewritten code. (Aug 21, 2008)
+%   2.0      Rewritten code. Instead of the COLORBAND subfunction, now uses
+%            the CMFIT function. Changed its name from COLORBARFIT to
+%            CBFIT. (Jun 08, 2008)
+%   2.1      Fixed bug and help with CBH input. (Sep 30, 2009)
+
+%   DISCLAIMER:
+%   cbfit.m is provided "as is" without warranty of any kind, under the
+%   revised BSD license.
+
+%   Copyright (c) 2008,2009 Carlos Adrian Vargas Aguilera
+
+
+% INPUTS CHECK-IN
+% -------------------------------------------------------------------------
+
+% Sets defaults:
+NBANDS = 5;
+CENTER = [];
+MODE   = 'auto';            
+CBH    = [];
+pax    = [];        % Peer axes
+
+% Checks if first argument is a handle: Fixed bug Sep 2009
+if (~isempty(varargin) && (length(varargin{1})==1) && ...
+  ishandle(varargin{1})) && strcmp(get(varargin{1},'Type'),'axes')
+ if strcmp(get(varargin{1},'Tag'),'Colorbar')
+  CBH = varargin{1};
+ else
+  warning('CVARGAS:cbfit:incorrectHInput',...
+   'Unrecognized first input handle.')
+ end
+ varargin(1) = [];
+end
+ 
+% Reads NBANDS and CENTER:
+if ~isempty(varargin) && isnumeric(varargin{1})
+ if ~isempty(varargin{1})
+  NBANDS = varargin{1};
+ end
+ if (length(varargin)>1) && isnumeric(varargin{2})
+  CENTER = varargin{2};
+  varargin(2) = [];
+ end
+ varargin(1) = [];
+end
+
+% Reads MODE:
+if (~isempty(varargin) && (rem(length(varargin),2)==1))
+ if (~isempty(varargin{1}) && ischar(varargin{1}))
+  switch lower(varargin{1})
+   case 'auto'  , MODE = 'auto';
+   case 'manual', MODE = 'manual';
+   otherwise % 'off', 'hide' and 'delete'
+    warning('CVARGAS:cbfit:incorrectStringInput',...
+     'No pair string input must be one of ''auto'' or ''manual''.')
+  end
+ end
+ varargin(1) = [];
+end
+
+% Reads peer axes:
+for k = 1:2:length(varargin)
+ if ~isempty(varargin{k})
+  switch lower(varargin{k})
+   case 'peer', pax = varargin{k+1}; break
+  end
+ end
+end
+if isempty(pax)
+ pax = gca;
+end
+
+% -------------------------------------------------------------------------
+% MAIN
+% -------------------------------------------------------------------------
+
+% Generates a preliminary colorbar:
+if isempty(CBH)
+ CBH = colorbar(varargin{:});
+end
+
+% Gets limits and orientation:
+s     = 'Y';
+ticks = get(CBH,[s 'Tick']);
+if isempty(ticks)             
+ s     = 'X';
+ ticks = get(CBH,[s 'Tick']);
+end
+zlim = get(CBH,[s 'Lim']);
+
+% Gets width and ref:
+if ~isempty(NBANDS)
+
+ NL = length(NBANDS);
+ 
+ if (NL==1)
+  
+  % Force positive integers:
+  NBANDS = round(abs(NBANDS));
+ 
+  % Ignores ticks outside the limits:
+  if zlim(1)>ticks(1)
+   ticks(1) = [];
+  end
+  if zlim(2)<ticks(end)
+   ticks(end) = [];
+  end
+
+  % Get the ticks step and colorband:
+  tstep = ticks(2)-ticks(1);
+  WIDTH = tstep/NBANDS;
+  
+  % Sets color limits
+  if strcmp(get(pax,'CLimMode'),'auto')
+   caxis(zlim);
+  end
+  
+  % Forces old colorbar ticks: 
+  set(CBH,[s 'Lim'],zlim,[s 'Tick'],ticks)
+  
+  % Levels:
+  if strcmp(MODE,'manual')
+   LBANDS = [fliplr(ticks(1)-WIDTH:-WIDTH:zlim(1)) ticks(1):WIDTH:zlim(2)];
+  end
+  
+ else
+  
+  % Nonlinear colorbar:
+  ticks = NBANDS;
+  WIDTH = ticks;
+  
+  % Scales to CLIM:
+  if strcmp(get(pax,'CLimMode'),'manual')
+   ticks = ticks-ticks(1);
+   ticks = ticks/ticks(end);
+   ticks = ticks*diff(zlim) + zlim(1);
+  end
+  zlim = [ticks(1) ticks(end)];
+  caxis(pax,zlim)
+  CBIH = get(CBH,'Children');
+  
+  % Change ticks:
+  set(CBIH,[s 'Data'],ticks)
+  
+  % Sets limits:
+  set(CBH,[s 'Lim'],zlim)
+  
+  % Levels:
+  if strcmp(MODE,'manual')
+   LBANDS = NBANDS;
+  end
+  
+ end
+ 
+ % Get reference mark
+ if ~isempty(CENTER)
+  REF    = CENTER;
+  CENTER = true;
+ else
+  REF    = ticks(1);
+  CENTER = false;
+ end
+  
+end
+
+% Fits the colormap and limits:
+cmfit(get(get(pax,'Parent'),'Colormap'),zlim,WIDTH,REF,CENTER)
+
+% Sets ticks:
+if strcmp(MODE,'manual')
+ set(CBH,[s 'Tick'],LBANDS)
+end
+
+% OUTPUTS CHECK-OUT
+% -------------------------------------------------------------------------
+
+if ~nargout
+ clear CBH
+end
+
+
+% [EOF]   cbfit.m
Index: /issm/trunk-jpl/externalpackages/cm_and_cb_utilities/cbfreeze.m
===================================================================
--- /issm/trunk-jpl/externalpackages/cm_and_cb_utilities/cbfreeze.m	(revision 11804)
+++ /issm/trunk-jpl/externalpackages/cm_and_cb_utilities/cbfreeze.m	(revision 11804)
@@ -0,0 +1,382 @@
+function CBH = cbfreeze(varargin)
+%CBFREEZE   Freezes the colormap of a colorbar.
+%
+%   SYNTAX:
+%           cbfreeze
+%           cbfreeze('off')
+%           cbfreeze(H,...)
+%     CBH = cbfreeze(...);
+%
+%   INPUT:
+%     H     - Handles of colorbars to be freezed, or from figures to search
+%             for them or from peer axes (see COLORBAR).
+%             DEFAULT: gcf (freezes all colorbars from the current figure)
+%     'off' - Unfreezes the colorbars, other options are:
+%               'on'    Freezes
+%               'un'    same as 'off'
+%               'del'   Deletes the colormap(s).
+%             DEFAULT: 'on' (of course)
+%
+%   OUTPUT (all optional):
+%     CBH - Color bar handle(s).
+%
+%   DESCRIPTION:
+%     MATLAB works with a unique COLORMAP by figure which is a big
+%     limitation. Function FREEZECOLORS by John Iversen allows to use
+%     different COLORMAPs in a single figure, but it fails freezing the
+%     COLORBAR. This program handles this problem.
+%
+%   NOTE:
+%     * Optional inputs use its DEFAULT value when not given or [].
+%     * Optional outputs may or not be called.
+%     * If no colorbar is found, one is created.
+%     * The new frozen colorbar is an axes object and does not behaves
+%       as normally colorbars when resizing the peer axes. Although, some
+%       time the normal behavior is not that good.
+%     * Besides, it does not have the 'Location' property anymore.
+%     * But, it does acts normally: no ZOOM, no PAN, no ROTATE3D and no
+%       mouse selectable.
+%     * No need to say that CAXIS and COLORMAP must be defined before using
+%       this function. Besides, the colorbar location. Anyway, 'off' or
+%       'del' may help.
+%     * The 'del' functionality may be used whether or not the colorbar(s)
+%       is(are) froozen. The peer axes are resized back. Try: 
+%        >> colorbar, cbfreeze del
+%
+%   EXAMPLE:
+%     surf(peaks(30))
+%     colormap jet
+%     cbfreeze
+%     colormap gray
+%     title('What...?')
+%
+%   SEE ALSO:
+%     COLORMAP, COLORBAR, CAXIS
+%     and
+%     FREEZECOLORS by John Iversen
+%     at http://www.mathworks.com/matlabcentral/fileexchange
+%
+%
+%   ---
+%   MFILE:   cbfreeze.m
+%   VERSION: 1.1 (Sep 02, 2009) (<a href="matlab:web('http://www.mathworks.com/matlabcentral/fileexchange/authors/11258')">download</a>) 
+%   MATLAB:  7.7.0.471 (R2008b)
+%   AUTHOR:  Carlos Adrian Vargas Aguilera (MEXICO)
+%   CONTACT: nubeobscura@hotmail.com
+
+%   REVISIONS:
+%   1.0      Released. (Jun 08, 2009)
+%   1.1      Fixed BUG with image handle on MATLAB R2009a. Thanks to Sergio
+%            Muniz. (Sep 02, 2009)
+
+%   DISCLAIMER:
+%   cbfreeze.m is provided "as is" without warranty of any kind, under the
+%   revised BSD license.
+
+%   Copyright (c) 2009 Carlos Adrian Vargas Aguilera
+
+
+% INPUTS CHECK-IN
+% -------------------------------------------------------------------------
+
+% Parameters:
+cbappname = 'Frozen';         % Colorbar application data with fields:
+                              % 'Location' from colorbar
+                              % 'Position' from peer axes befor colorbar
+                              % 'pax'      handle from peer axes.
+axappname = 'FrozenColorbar'; % Peer axes application data with frozen
+                              % colorbar handle.
+ 
+% Set defaults:
+S = 'on';                   Sopt = {'on','un','off','del'};
+H = get(0,'CurrentFig');
+
+% Check inputs:
+if nargin==2 && (~isempty(varargin{1}) && all(ishandle(varargin{1})) && ...
+  isempty(varargin{2}))
+ 
+ % Check for CallBacks functionalities:
+ % ------------------------------------
+ 
+ varargin{1} = double(varargin{1});
+ 
+ if strcmp(get(varargin{1},'BeingDelete'),'on') 
+  % Working as DeletFcn:
+
+  if (ishandle(get(varargin{1},'Parent')) && ...
+      ~strcmpi(get(get(varargin{1},'Parent'),'BeingDeleted'),'on'))
+    % The handle input is being deleted so do the colorbar:
+    S = 'del'; 
+    
+   if ~isempty(getappdata(varargin{1},cbappname))
+    % The frozen colorbar is being deleted:
+    H = varargin{1};
+   else
+    % The peer axes is being deleted:
+    H = ancestor(varargin{1},{'figure','uipanel'}); 
+   end
+   
+  else
+   % The figure is getting close:
+   return
+  end
+  
+ elseif (gca==varargin{1} && ...
+                     gcf==ancestor(varargin{1},{'figure','uipanel'}))
+  % Working as ButtonDownFcn:
+  
+  cbfreezedata = getappdata(varargin{1},cbappname);
+  if ~isempty(cbfreezedata) 
+   if ishandle(cbfreezedata.ax)
+    % Turns the peer axes as current (ignores mouse click-over):
+    set(gcf,'CurrentAxes',cbfreezedata.ax);
+    return
+   end
+  else
+   % Clears application data:
+   rmappdata(varargin{1},cbappname) 
+  end
+  H = varargin{1};
+ end
+ 
+else
+ 
+ % Checks for normal calling:
+ % --------------------------
+ 
+ % Looks for H:
+ if nargin && ~isempty(varargin{1}) && all(ishandle(varargin{1}))
+  H = varargin{1};
+  varargin(1) = [];
+ end
+
+ % Looks for S:
+ if ~isempty(varargin) && (isempty(varargin{1}) || ischar(varargin{1}))
+  S = varargin{1};
+ end
+end
+
+% Checks S:
+if isempty(S)
+ S = 'on';
+end
+S = lower(S);
+iS = strmatch(S,Sopt);
+if isempty(iS)
+ error('CVARGAS:cbfreeze:IncorrectStringOption',...
+  ['Unrecognized ''' S ''' argument.' ])
+else
+ S = Sopt{iS};
+end
+
+% Looks for CBH:
+CBH = cbhandle(H);
+
+if ~strcmp(S,'del') && isempty(CBH)
+ % Creates a colorbar and peer axes:
+ pax = gca;
+ CBH = colorbar('peer',pax);
+else
+ pax = [];
+end
+
+
+% -------------------------------------------------------------------------
+% MAIN 
+% -------------------------------------------------------------------------
+% Note: only CBH and S are necesary, but I use pax to avoid the use of the
+%       "hidden" 'Axes' COLORBAR's property. Why... ¿?
+
+% Saves current position:
+fig = get(  0,'CurrentFigure');
+cax = get(fig,'CurrentAxes');
+
+% Works on every colorbar:
+for icb = 1:length(CBH)
+ 
+ % Colorbar axes handle:
+ h  = double(CBH(icb));
+ 
+ % This application data:
+ cbfreezedata = getappdata(h,cbappname);
+ 
+ % Gets peer axes:
+ if ~isempty(cbfreezedata)
+  pax = cbfreezedata.pax;
+  if ~ishandle(pax) % just in case
+   rmappdata(h,cbappname)
+   continue
+  end
+ elseif isempty(pax) % not generated
+  try
+   pax = double(get(h,'Axes'));  % NEW feature in COLORBARs
+  catch
+   continue
+  end
+ end
+ 
+ % Choose functionality:
+ switch S
+  
+  case 'del'
+   % Deletes:
+   if ~isempty(cbfreezedata)
+    % Returns axes to previous size:
+    oldunits = get(pax,'Units');
+    set(pax,'Units','Normalized');
+    set(pax,'Position',cbfreezedata.Position)
+    set(pax,'Units',oldunits)
+    set(pax,'DeleteFcn','')
+    if isappdata(pax,axappname)
+     rmappdata(pax,axappname)
+    end
+   end
+   if strcmp(get(h,'BeingDelete'),'off') 
+    delete(h)
+   end
+   
+  case {'un','off'}
+   % Unfrozes:
+   if ~isempty(cbfreezedata)
+    delete(h);
+    set(pax,'DeleteFcn','')
+    if isappdata(pax,axappname)
+     rmappdata(pax,axappname)
+    end
+    oldunits = get(pax,'Units');
+    set(pax,'Units','Normalized')
+    set(pax,'Position',cbfreezedata.Position)
+    set(pax,'Units',oldunits)
+    CBH(icb) = colorbar(...
+     'peer'    ,pax,...
+     'Location',cbfreezedata.Location);
+   end
+ 
+  otherwise % 'on'
+   % Freezes:
+ 
+   % Gets colorbar axes properties:
+   cb_prop  = get(h);
+   
+   % Gets colorbar image handle. Fixed BUG, Sep 2009
+   hi = findobj(h,'Type','image');
+    
+   % Gets image data and transform it in a RGB:
+   CData = get(hi,'CData'); 
+   if size(CData,3)~=1
+    % It's already frozen:
+    continue
+   end
+  
+   % Gets image tag:
+   Tag = get(hi,'Tag');
+  
+   % Deletes previous colorbar preserving peer axes position:
+   oldunits = get(pax,'Units');
+              set(pax,'Units','Normalized')
+   Position = get(pax,'Position');
+   delete(h)
+   cbfreezedata.Position = get(pax,'Position');
+              set(pax,'Position',Position)
+              set(pax,'Units',oldunits)
+  
+   % Generates new colorbar axes:
+   % NOTE: this is needed because each time COLORMAP or CAXIS is used,
+   %       MATLAB generates a new COLORBAR! This eliminates that behaviour
+   %       and is the central point on this function.
+   h = axes(...
+    'Parent'  ,cb_prop.Parent,...
+    'Units'   ,'Normalized',...
+    'Position',cb_prop.Position...
+   );
+  
+   % Save location for future call:
+   cbfreezedata.Location = cb_prop.Location;
+  
+   % Move ticks because IMAGE draws centered pixels:
+   XLim = cb_prop.XLim;
+   YLim = cb_prop.YLim;
+   if     isempty(cb_prop.XTick)
+    % Vertical:
+    X = XLim(1) + diff(XLim)/2;
+    Y = YLim    + diff(YLim)/(2*length(CData))*[+1 -1];
+   else % isempty(YTick)
+    % Horizontal:
+    Y = YLim(1) + diff(YLim)/2;
+    X = XLim    + diff(XLim)/(2*length(CData))*[+1 -1];
+   end
+  
+   % Draws a new RGB image:
+   image(X,Y,ind2rgb(CData,colormap),...
+    'Parent'            ,h,...
+    'HitTest'           ,'off',...
+    'Interruptible'     ,'off',...
+    'SelectionHighlight','off',...
+    'Tag'               ,Tag...
+   )  
+
+   % Removes all   '...Mode'   properties:
+   cb_fields = fieldnames(cb_prop);
+   indmode   = strfind(cb_fields,'Mode');
+   for k=1:length(indmode)
+    if ~isempty(indmode{k})
+     cb_prop = rmfield(cb_prop,cb_fields{k});
+    end
+   end
+   
+   % Removes special COLORBARs properties:
+   cb_prop = rmfield(cb_prop,{...
+    'CurrentPoint','TightInset','BeingDeleted','Type',...       % read-only
+    'Title','XLabel','YLabel','ZLabel','Parent','Children',...  % handles
+    'UIContextMenu','Location',...                              % colorbars
+    'ButtonDownFcn','DeleteFcn',...                             % callbacks
+    'CameraPosition','CameraTarget','CameraUpVector','CameraViewAngle',...
+    'PlotBoxAspectRatio','DataAspectRatio','Position',... 
+    'XLim','YLim','ZLim'});
+   
+   % And now, set new axes properties almost equal to the unfrozen
+   % colorbar:
+   set(h,cb_prop)
+
+   % CallBack features:
+   set(h,...
+    'ActivePositionProperty','position',...
+    'ButtonDownFcn'         ,@cbfreeze,...  % mhh...
+    'DeleteFcn'             ,@cbfreeze)     % again
+   set(pax,'DeleteFcn'      ,@cbfreeze)     % and again!  
+  
+   % Do not zoom or pan or rotate:
+   setAllowAxesZoom  (zoom    ,h,false)
+   setAllowAxesPan   (pan     ,h,false)
+   setAllowAxesRotate(rotate3d,h,false)
+   
+   % Updates data:
+   CBH(icb) = h;   
+
+   % Saves data for future undo:
+   cbfreezedata.pax       = pax;
+   setappdata(  h,cbappname,cbfreezedata);
+   setappdata(pax,axappname,h);
+   
+ end % switch functionality   
+
+end  % MAIN loop
+
+
+% OUTPUTS CHECK-OUT
+% -------------------------------------------------------------------------
+
+% Output?:
+if ~nargout
+ clear CBH
+else
+ CBH(~ishandle(CBH)) = [];
+end
+
+% Returns current axes:
+if ishandle(cax) 
+ set(fig,'CurrentAxes',cax)
+end
+
+
+% [EOF]   cbfreeze.m
Index: /issm/trunk-jpl/externalpackages/cm_and_cb_utilities/cbhandle.m
===================================================================
--- /issm/trunk-jpl/externalpackages/cm_and_cb_utilities/cbhandle.m	(revision 11804)
+++ /issm/trunk-jpl/externalpackages/cm_and_cb_utilities/cbhandle.m	(revision 11804)
@@ -0,0 +1,93 @@
+function CBH = cbhandle(varargin)
+%CBHANDLE   Handle of current colorbar axes.
+%
+%   SYNTAX:
+%     CBH = cbhandle;
+%     CBH = cbhandle(H);
+%
+%   INPUT:
+%     H - Handles axes, figures or uipanels to look for colorbars.
+%         DEFAULT: gca (current axes)
+%
+%   OUTPUT:
+%     CBH - Color bar handle(s).
+%
+%   DESCRIPTION:
+%     By default, color bars are hidden objects. This function searches for
+%     them by its 'axes' type and 'Colorbar' tag.
+%    
+%   SEE ALSO:
+%     COLORBAR
+%     and
+%     CBUNITS, CBLABEL, CBFREEZE by Carlos Vargas
+%     at http://www.mathworks.com/matlabcentral/fileexchange
+%
+%
+%   ---
+%   MFILE:   cbhandle.m
+%   VERSION: 1.1 (Aug 20, 2009) (<a href="matlab:web('http://www.mathworks.com/matlabcentral/fileexchange/authors/11258')">download</a>) 
+%   MATLAB:  7.7.0.471 (R2008b)
+%   AUTHOR:  Carlos Adrian Vargas Aguilera (MEXICO)
+%   CONTACT: nubeobscura@hotmail.com
+
+%   REVISIONS:
+%   1.0      Released. (Jun 08, 2009)
+%   1.1      Fixed bug with colorbar handle input. (Aug 20, 2009)
+
+%   DISCLAIMER:
+%   cbhandle.m is provided "as is" without warranty of any kind, under the
+%   revised BSD license.
+
+%   Copyright (c) 2009 Carlos Adrian Vargas Aguilera
+
+
+% INPUTS CHECK-IN
+% -------------------------------------------------------------------------
+
+% Parameters:
+axappname = 'FrozenColorbar'; % Peer axes application data with frozen
+                              % colorbar handle.
+
+% Sets default:
+H = get(get(0,'CurrentFigure'),'CurrentAxes');
+
+if nargin && ~isempty(varargin{1}) && all(ishandle(varargin{1}))
+ H = varargin{1};
+end
+
+% -------------------------------------------------------------------------
+% MAIN
+% -------------------------------------------------------------------------
+
+% Looks for CBH:
+CBH = [];
+% set(0,'ShowHiddenHandles','on')
+for k = 1:length(H)
+ switch get(H(k),'type')
+  case {'figure','uipanel'}
+   % Parents axes?:
+   CBH = [CBH; ...
+    findobj(H(k),'-depth',1,'Tag','Colorbar','-and','Type','axes')];
+  case 'axes'
+   % Peer axes?:
+   hin  = double(getappdata(H(k),'LegendColorbarInnerList'));
+   hout = double(getappdata(H(k),'LegendColorbarOuterList'));
+   if     (~isempty(hin)  && ishandle(hin))
+    CBH = [CBH; hin];
+   elseif (~isempty(hout) && ishandle(hout))
+    CBH = [CBH; hout];
+   elseif isappdata(H(k),axappname)
+    % Peer from frozen axes?:
+    CBH = [CBH; double(getappdata(H(k),axappname))];
+   elseif strcmp(get(H(k),'Tag'),'Colorbar') % Fixed BUG Aug 2009
+    % Colorbar axes?
+    CBH = [CBH; H(k)];
+   end
+  otherwise
+   % continue
+ end
+end
+% set(0,'ShowHiddenHandles','off')
+
+
+% [EOF]   cbhandle.m
Index: /issm/trunk-jpl/externalpackages/cm_and_cb_utilities/cblabel.m
===================================================================
--- /issm/trunk-jpl/externalpackages/cm_and_cb_utilities/cblabel.m	(revision 11804)
+++ /issm/trunk-jpl/externalpackages/cm_and_cb_utilities/cblabel.m	(revision 11804)
@@ -0,0 +1,160 @@
+function CBLH = cblabel(varargin)
+%CBLABEL   Adds a label to the colorbar.
+%
+%   SYNTAX:
+%            cblabel(LABEL)
+%            cblabel(LABEL,..,TP,TV);
+%            cblabel(H,...)
+%     CBLH = cblabel(...);
+%
+%   INPUT:
+%     LABEL - String (or cell of strings) specifying the colorbar label.
+%     TP,TV - Optional text property/property value arguments (in pairs).
+%             DEFAULT:  (none)
+%     H     - Color bar or peer axes (see COLORBAR) or figure handle(s) to
+%             search for a single color bar handle.
+%             DEFAULT: gca (current axes color bar)
+%
+%   OUTPUT (all optional):
+%     CBLH  - Returns the colorbar label handle(s).
+%           - Labels modified on the colorbar of the current figure or
+%             the one(s) specified by CBH.
+%
+%   DESCRIPTION:
+%     This function sets the label of the colorbar(s) in the current
+%     figure.
+%
+%   NOTE:
+%     * Optional inputs use its DEFAULT value when not given or [].
+%     * Optional outputs may or not be called.
+%
+%   EXAMPLE:
+%     figure, colorbar, cblabel(['           T, °C'],'Rotation',0)
+%     figure
+%      subplot(211), h1 = colorbar;
+%      subplot(212), h2 = colorbar('Location','south');
+%      cblabel([h1 h2],{'$1-\alpha$','$\beta^3$'},'Interpreter','latex')   
+%
+%   SEE ALSO: 
+%     COLORBAR
+%     and 
+%     CBUNITS, CBHANDLE, CBFREEZE by Carlos Vargas
+%     at http://www.mathworks.com/matlabcentral/fileexchange
+%
+%
+%   ---
+%   MFILE:   cblabel.m
+%   VERSION: 2.0 (Jun 08, 2009) (<a href="matlab:web('http://www.mathworks.com/matlabcentral/fileexchange/authors/11258')">download</a>) 
+%   MATLAB:  7.7.0.471 (R2008b)
+%   AUTHOR:  Carlos Adrian Vargas Aguilera (MEXICO)
+%   CONTACT: nubeobscura@hotmail.com
+
+%   REVISIONS:
+%   1.0      Released. (Aug 21, 2008)
+%   2.0      Minor changes. Added CBHANDLE dependency. (Jun 08, 2009)
+
+%   DISCLAIMER:
+%   cblabel.m is provided "as is" without warranty of any kind, under the
+%   revised BSD license.
+
+%   Copyright (c) 2008,2009 Carlos Adrian Vargas Aguilera
+
+
+% INPUTS CHECK-IN
+% -------------------------------------------------------------------------
+
+% Parameters:
+cbappname = 'Frozen';         % Colorbar application data with fields:
+                              % 'Location' from colorbar
+                              % 'Position' from peer axes befor colorbar
+                              % 'pax'      handle from peer axes.
+
+% Sets defaults:
+H     = get(get(0,'CurrentFigure'),'CurrentAxes');
+LABEL = '';
+TOPT  = {};
+CBLH  = [];
+
+% Number of inputs:
+if nargin<1
+ error('CVARGAS:cblabel:incorrectNumberOfInputs',...
+        'At least one input is required.')
+end
+
+% Looks for H:
+if nargin && ~isempty(varargin{1}) && all(ishandle(varargin{1}))
+ H = varargin{1};
+ varargin(1) = [];
+end
+
+% Looks for CBH:
+CBH = cbhandle(H);
+if isempty(CBH), if ~nargout, clear CBLH, end, return, end
+
+% Looks for LABEL:
+if ~isempty(varargin) && (ischar(varargin{1}) || iscellstr(varargin{1}))  
+ LABEL = varargin{1};
+ varargin(1) = [];
+end
+
+% Forces cell of strings:
+if ischar(LABEL)
+ % Same label to all the color bars:
+ LABEL = repmat({LABEL},length(CBH),1);
+elseif iscellstr(LABEL) && (length(LABEL)==length(CBH))
+  % Continue...
+else
+ error('CVARGAS:cblabel:incorrectInputLabel',...
+        ['LABEL must be a string or cell of strings of equal size as ' ...
+         'the color bar handles: ' int2str(length(CBH)) '.'])
+end
+
+% OPTIONAL arguments:
+if ~isempty(varargin)
+ TOPT = varargin;
+end
+if length(TOPT)==1
+ TOPT = repmat({TOPT},size(CBH));
+end
+
+% -------------------------------------------------------------------------
+% MAIN
+% -------------------------------------------------------------------------
+% NOTE: Only CBH, LABEL and TOPT are needed.
+
+% Applies to each colorbar:
+CBLH = repmat(NaN,size(CBH));
+for icb = 1:length(CBH)
+ 
+ % Searches for label location:
+ try 
+  % Normal colorbar:
+  location = get(CBH(icb),'Location');
+ catch
+  % Frozen colorbar:
+  location = getappdata(CBH(icb),cbappname);
+  location = location.Location;
+ end
+ switch location(1)
+  case 'E', as  = 'Y';
+  case 'W', as  = 'Y';
+  case 'N', as  = 'X';
+  case 'S', as  = 'X';
+ end
+ % Gets label handle:
+ CBLH(icb) = get(CBH(icb),[as 'Label']);
+ % Updates label:
+ set(CBLH(icb),'String',LABEL{icb},TOPT{:});
+ 
+end
+
+% OUTPUTS CHECK-OUT
+% -------------------------------------------------------------------------
+
+% Sets output:
+if ~nargout
+ clear CBLH
+end
+
+
+% [EOF]   cblabel.m
Index: /issm/trunk-jpl/externalpackages/cm_and_cb_utilities/cbunits.m
===================================================================
--- /issm/trunk-jpl/externalpackages/cm_and_cb_utilities/cbunits.m	(revision 11804)
+++ /issm/trunk-jpl/externalpackages/cm_and_cb_utilities/cbunits.m	(revision 11804)
@@ -0,0 +1,235 @@
+function CBH = cbunits(varargin)
+%CBUNITS   Adds units to the colorbar ticklabels.
+%
+%   SYNTAX:
+%           cbunits(UNITS)
+%           cbunits(UNITS,SPACE)
+%           cbunits -clear
+%           cbunits(H,...)
+%     CBH = cbunits(...);
+%
+%   INPUT:
+%     UNITS - String (or cell of strings) with the colorbar(s) units or
+%             '-clear' to eliminate any unit. 
+%     SPACE - Logical indicating whether an space should be put between
+%             quantity and units. Useful when using '3°C', for example.
+%             DEFAULT: true (use an space)
+%     H     - Colorbar, or peer axes (see COLORBAR) or figure handle(s) to
+%             search for color bars. 
+%             DEFAULT: gca (current axes color bar)
+%
+%   OUTPUT (all optional):
+%     CBH   - Returns the colorbar handle(s).
+%             DEFAULT: Not returned if not required.
+%           - Ticklabels modified on the colorbar of the current axes or
+%             the one(s) specified by CBH.
+%
+%   DESCRIPTION:
+%     This function adds units to the current colorbar, by writting them
+%     after the biggest ticklabel.
+%
+%   NOTE:
+%     * Optional inputs use its DEFAULT value when not given or [].
+%     * Optional outputs may or not be called.
+%     * Scientific notation is included in the units (if any).
+%     * When more than one colorbar handle is given or founded and a single
+%       UNITS string is given, it is applied to all of them.
+%     * Use a cell of strings for UNITS when more than one colorbar handles
+%       are given in order to give to each one their proper units. This
+%       also works when the handlesare founded but the units order is
+%       confusing and not recommended.
+%     * Once applied, CAXIS shouldn't be used.
+%     * To undo sets the ticklabelmode to 'auto'.
+%
+%   EXAMPLE:
+%     % Easy to use:
+%       figure, caxis([1e2 1e8]), colorbar, cbunits('°F',false)
+%     % Vectorized:
+%       figure
+%       subplot(211), h1 = colorbar;
+%       subplot(212), h2 = colorbar;
+%       cbunits([h1;h2],{'°C','dollars'},[false true])
+%     % Handle input:
+%       figure
+%       subplot(211), colorbar;
+%       subplot(212), colorbar('Location','North');
+%       caxis([1e2 1e8])
+%       cbunits(gcf,'m/s')
+%
+%   SEE ALSO: 
+%     COLORBAR
+%     and
+%     CBLABEL, CBHANDLE, CBFREEZE by Carlos Vargas
+%     at http://www.mathworks.com/matlabcentral/fileexchange
+%
+%
+%   ---
+%   MFILE:   cbunits.m
+%   VERSION: 3.0 (Sep 30, 2009) (<a href="matlab:web('http://www.mathworks.com/matlabcentral/fileexchange/authors/11258')">download</a>) 
+%   MATLAB:  7.7.0.471 (R2008b)
+%   AUTHOR:  Carlos Adrian Vargas Aguilera (MEXICO)
+%   CONTACT: nubeobscura@hotmail.com
+
+%   REVISIONS:
+%   1.0      Released. (Aug 21, 2008)
+%   2.0      Minor changes. Added 'clear' option and CBHANDLE dependency.
+%            (Jun 08, 2009)
+%   3.0      Fixed bug when inserting units on lower tick and ticklabel
+%            justification. Added SPACE option. (Sep 30, 2009)
+
+%   DISCLAIMER:
+%   cbunits.m is provided "as is" without warranty of any kind, under the
+%   revised BSD license.
+
+%   Copyright (c) 2008,2009 Carlos Adrian Vargas Aguilera
+
+
+% INPUTS CHECK-IN
+% -------------------------------------------------------------------------
+
+% Sets defaults:
+H     = get(get(0,'CurrentFigure'),'CurrentAxes');
+UNITS = '';
+SPACE = true;
+
+% Checks inputs/outputs number:
+if     nargin<1
+ error('CVARGAS:cbunits:notEnoughInputs',...
+  'At least 1 input is required.')
+elseif nargin>3
+ error('CVARGAS:cbunits:tooManyInputs',...
+  'At most 3 inputs are allowed.')
+elseif nargout>1
+ error('CVARGAS:cbunits:tooManyOutputs',...
+  'At most 1 output is allowed.')
+end
+
+% Looks for H:
+if nargin && ~isempty(varargin{1}) && all(ishandle(varargin{1}))
+ H = varargin{1};
+ varargin(1) = [];
+end
+
+% Looks for CBH:
+CBH = cbhandle(H);
+if isempty(CBH), if ~nargout, clear CBH, end, return, end
+
+% Looks for UNITS:
+if ~isempty(varargin) && ~isempty(varargin{1}) && ...
+  (ischar(varargin{1}) || iscellstr(varargin{1}))  
+ UNITS = varargin{1};
+ varargin(1) = [];
+end
+if isempty(UNITS), if ~nargout, clear CBH, end, return, end
+
+% Forces cell of strings:
+if ischar(UNITS)
+ if numel(UNITS)~=size(UNITS,2)
+  error('CVARGAS:cbunits:IncorrectUnitsString',...
+        'UNITS string must be a row vector.')
+ end
+ % Same units to all the color bars:
+ UNITS = repmat({UNITS},length(CBH),1);
+elseif iscellstr(UNITS) && (length(UNITS)==length(CBH))
+  % Continue...
+else
+ error('CVARGAS:cbunits:IncorrectInputUnits',...
+        ['UNITS must be a string or cell of strings of equal size as ' ...
+         'the color bar handles: ' int2str(length(CBH)) '.'])
+end
+
+% Looks for SPACE:
+Nunits = length(UNITS);
+if ~isempty(varargin) && ~isempty(varargin{1}) && ...
+  ((length(varargin{1})==1) || (length(varargin{1})==Nunits))  
+ SPACE = varargin{1};
+end
+SPACE = logical(SPACE);
+
+% Forces equal size of SPACE and UNITS.
+if (length(SPACE)==1) && (Nunits~=1)
+ SPACE = repmat(SPACE,Nunits,1);
+end
+
+
+% -------------------------------------------------------------------------
+% MAIN
+% -------------------------------------------------------------------------
+% Note: Only CBH and UNITS are required.
+
+% Applies to each colorbar:
+for icb = 1:length(CBH)
+ 
+ units  = UNITS{icb};
+ space  = SPACE(icb);
+ cbh    = CBH(icb);
+ append = [];
+ 
+ % Gets tick labels:
+ as  = 'Y';
+ at  = get(cbh,[as 'Tick']);
+ if isempty(at)
+  as = 'X';
+  at = get(cbh,[as 'Tick']);
+ end
+ 
+ % Checks for elimitation:
+ if strcmpi(units,'-clear')
+  set(cbh,[as 'TickLabelMode'],'auto')
+  continue
+ end
+
+             set(cbh,[as 'TickLabelMode'],'manual');
+ old_ticks = get(cbh,[as 'TickLabel']);
+
+ % Adds scientific notation:
+ if strcmp(get(cbh,[as 'Scale']),'linear')
+  ind = 1;
+  if at(ind)==0
+   ind = 2;
+  end
+  o  = log10(abs(at(ind)/str2double(old_ticks(ind,:))));
+  sg = '';
+  if at(ind)<0, sg = '-'; end
+  if o>0
+   append = [' e' sg int2str(o) ''];
+  end
+ end
+ 
+ % Updates ticklabels:
+ Nu = length(units);
+ Na = length(append);
+ Nt = size(old_ticks,1);
+ loc = Nt; % Fixed bug, Sep 2009
+ if (strcmp(as,'Y') && ((abs(at(1))>abs(at(Nt))) && ...
+    (length(fliplr(deblank(fliplr(old_ticks( 1,:))))) > ...
+     length(fliplr(deblank(fliplr(old_ticks(Nt,:)))))))) || ...
+     (strcmp(as,'X') && strcmp(get(cbh,[as 'Dir']),'reverse'))
+  loc = 1; 
+ end
+ new_ticks  = [old_ticks repmat(' ',Nt,Nu+(Na-(Na>0))+space)];
+ new_ticks(loc,end-Nu-Na-space+1:end) = [append repmat(' ',1,space) units];
+ if strcmp(as,'Y') % Fixed bug, Sep 2009
+  if strcmp(get(cbh,[as 'AxisLocation']),'right')
+   new_ticks = strjust(new_ticks,'left');
+  else
+   new_ticks = strjust(new_ticks,'right');
+  end
+ else
+  new_ticks = strjust(new_ticks,'center');
+ end
+ set(cbh,[as 'TickLabel'],new_ticks)
+ 
+end % MAIN LOOP
+
+
+% OUTPUTS CHECK-OUT
+% -------------------------------------------------------------------------
+
+% Sets output:
+if ~nargout
+ clear CBH
+end
+
+
+% [EOF]   cbunits.m
Index: /issm/trunk-jpl/externalpackages/cm_and_cb_utilities/cmapping.m
===================================================================
--- /issm/trunk-jpl/externalpackages/cm_and_cb_utilities/cmapping.m	(revision 11804)
+++ /issm/trunk-jpl/externalpackages/cm_and_cb_utilities/cmapping.m	(revision 11804)
@@ -0,0 +1,515 @@
+function RGB = cmapping(varargin)
+%CMAPPING   Colormap linear mapping/interpolation.
+%
+%   SYNTAX:
+%           cmapping
+%           cmapping(U)
+%           cmapping(U,CMAP)
+%           cmapping(U,CMAP,...,CNAN)
+%           cmapping(U,CMAP,...,TYPE)
+%           cmapping(U,CMAP,...,MODE)
+%           cmapping(U,CMAP,...,MAPS)
+%           cmapping(U,CMAP,...,CLIM)
+%           cmapping(AX,...)
+%     RGB = cmapping(...);
+%
+%   INPUT:
+%     U     - May be one of the following options:
+%              a) An scalar specifying the output M number of colors.
+%              b) A vector of length M specifying the values at which
+%                 the function CMAP(IMAP) will be mapped.
+%              c) A matrix of size M-by-N specifying intensities to be
+%                 mapped to an RGB (3-dim) image. May have NaNs elements. 
+%             DEFAULT: Current colormap length.
+%     CMAP  - A COLORMAP defined by its name or handle-function or RGB
+%             matrix (with 3 columns) or by a combination of colors chars
+%             specifiers ('kbcw', for example) to be mapped. See NOTE below
+%             for more options.
+%             DEFAULT: Current colormap
+%     CNAN  - Color for NaNs values on U, specified by a 1-by-3 RGB color
+%             or a char specifier.
+%             DEFAULT: Current axes background (white color: [1 1 1])
+%     TYPE  - String specifying the result type. One of:
+%               'colormap'  Forces a RGB colormap matrix result (3 columns)
+%               'image'     Forces a RGB image result (3 dimensions)
+%             DEFAULT: 'image' if U is a matrix, otherwise is 'colormap'
+%     MODE  - Defines the mapping way. One of:
+%               'discrete'     For discrete colors
+%               'continuous'   For continuous color (interpolates)
+%             DEFAULT: 'continuous' (interpolates between colors)
+%     MAPS  - Specifies the mapping type. One of (see NOTES below):
+%               'scaled'   Scales mapping, also by using CLIM (as IMAGESC).
+%               'direct'   Do not scales the mapping (as IMAGE).
+%             DEFAULT: 'scaled' (uses CLIM)
+%     CLIM  - Two element vector that, if given, scales the mapping within
+%             this color limits. Ignored if 'direct' is specified.
+%             DEFAULT: [0 size(CMAP,1)] or [0 1].
+%     AX    - Uses specified axes or figure handle to set/get the colormap.
+%             If used, must be the first input.
+%             DEFAULT: gca
+%
+%   OUTPUT (all optional):
+%     RGB - If U is not a matrix, this is an M-by-3 colormap matrix with
+%           RGB colors in its rows, otherwise is an RGB image: M-by-N-by-3,
+%           with the color red intensities defined by RGB(:,:,1), the green
+%           ones by RGB(:,:,2) and the blue ones by RGB(:,:,3).
+%
+%   DESCRIPTION:
+%     This functions has various functionalities like: colormap generator,
+%     colormap expansion/contraction, color mapping/interpolation, matrix
+%     intensities convertion to RGB image, etc.
+%
+%     The basic idea is a linear mapping between the CMAP columns
+%     [red green blue] and the U data, ignoring its NaNs.
+%
+%   NOTE:
+%     * Optional inputs use its DEFAULT value when not given or [].
+%     * Optional outputs may or not be called.
+%     * If a single value of U is required for interpolation, use [U U].
+%     * If the char '-' is used before the CMAP name, the colors will be
+%       flipped. The same occurs if U is a negative integer.
+%
+%   EXAMPLE:
+%     % Colormaps:
+%       figure, cmapping( 256,'krgby')            , colorbar
+%       figure, cmapping(-256,'krgby' ,'discrete'), colorbar
+%       figure, cmapping(log(1:100),[],'discrete'), colorbar
+%     % Images:
+%       u = random('chi2',2,20,30); u(15:16,7:9) = NaN;
+%       u = peaks(30);  u(15:16,7:9) = NaN;
+%       v = cmapping(u,jet(64),'discrete','k');
+%       w = cmapping(u,cmapping(log(0:63),'jet','discrete'),'discrete');
+%       figure, imagesc(u), cmapping(64,'jet'), colorbar
+%        title('u')
+%       figure, imagesc(v), cmapping(64,'jet'), colorbar
+%        title('u transformed to RGB (look the colored NaNs)')
+%       figure, imagesc(w) ,cmapping(64,'jet'), colorbar
+%        title('u mapped with log(colormap)')
+%       figure, imagesc(u), cmapping(log(0:63),'jet','discrete'), colorbar
+%        title('u with log(colormap)')
+%    
+%   SEE ALSO:
+%     COLORMAP, IND2RGB
+%     and
+%     CMJOIN by Carlos Vargas
+%     at http://www.mathworks.com/matlabcentral/fileexchange
+%
+%
+%   ---
+%   MFILE:   cmapping.m
+%   VERSION: 1.1 (Sep 02, 2009) (<a href="matlab:web('http://www.mathworks.com/matlabcentral/fileexchange/authors/11258')">download</a>) 
+%   MATLAB:  7.7.0.471 (R2008b)
+%   AUTHOR:  Carlos Adrian Vargas Aguilera (MEXICO)
+%   CONTACT: nubeobscura@hotmail.com
+
+%   REVISIONS:
+%   1.0      Released. (Jun 08, 2009)
+%   1.0.1    Fixed little bug with 'm' magenta color. (Jun 30, 2009)
+%   1.1      Fixed BUG with empty CMAP, thanks to Andrea Rumazza. (Sep 02,
+%            2009) 
+
+%   DISCLAIMER:
+%   cmapping.m is provided "as is" without warranty of any kind, under the
+%   revised BSD license.
+
+%   Copyright (c) 2009 Carlos Adrian Vargas Aguilera
+
+
+% INPUTS CHECK-IN
+% -------------------------------------------------------------------------
+
+% Sets defaults:
+AX     = {};                     % Calculated inside.
+U      = [];                     % Calculated inside.
+CMAP   = [];                     % Calculated inside.
+TYPE   = 'colormap';             % Changes to 'image' if U is a matrix.
+CLIM   = [];                     % To use in scaling
+CNAN   = [1 1 1];                % White 'w'
+MODE   = 'continuous';           % Scaling to CLIM
+MAPS   = 'scaled';               % Scaled mapping
+method = 'linear';               % Interpolation method
+mflip  = false;                  % Flip the colormap
+
+% Gets figure handle and axes handle (just in case the default colormap or
+% background color axes will be used.
+HF     = get(0,'CurrentFigure');
+HA     = [];
+if ~isempty(HF)
+ HA    = get(HF,'CurrentAxes');
+ if ~isempty(HA)
+  CNAN = get(HA,'Color');        % NaNs colors
+ end
+end
+
+% Checks inputs:
+if nargin>8
+ error('CVARGAS:cmapping:tooManyInputs', ...
+  'At most 8 inputs are allowed.')
+elseif nargout>1
+ error('CVARGAS:cmapping:tooManyOutputs', ...
+  'At most 1 output is allowed.')
+end
+
+% Checks AX:
+if (~isempty(varargin)) && ~isempty(varargin{1}) && ...
+  (numel(varargin{1})==1) && ishandle(varargin{1}) && ...
+  strcmp(get(varargin{1},'Type'),'axes')
+ % Gets AX and moves all other inputs to the left:
+ AX          = varargin(1);
+ HA          = AX{1};
+ CNAN        = get(HA,'Color');
+ varargin(1) = [];
+end
+
+% Checks U:
+Nargin = length(varargin);
+if ~isempty(varargin)
+ U           = varargin{1};
+ varargin(1) = [];
+end
+
+% Checks CMAP:
+if ~isempty(varargin)
+ CMAP        = varargin{1};
+ varargin(1) = []; 
+end
+
+% Checks input U, if not given uses as default colormap length:
+% Note: it is not converted to a vector in case CMAP is a function and IMAP
+%       was not given.
+if isempty(U)
+ % Gets default COLORMAP length:
+ if ~isempty(HA)
+  U = size(colormap(HA),1);
+ else
+  U = size(get(0,'DefaultFigureColormap'),1);
+ end
+elseif ndims(U)>2
+ error('CVARGAS:cmapping:incorrectXInput', ...
+  'U must be an scalar, a vector or a 2-dimensional matrix.')
+end
+
+% Checks input CMAP:
+if isempty(CMAP)
+ % CMAP empty, then uses default:
+ if ~isempty(HA)
+  CMAP = colormap(HA);
+  if isempty(CMAP) % Fixed BUG, Sep 2009.
+   CMAP = get(0,'DefaultFigureColormap');
+   if isempty(CMAP)
+    CMAP = jet(64);
+   end
+  end
+ else
+  CMAP = get(0,'DefaultFigureColormap');
+  if isempty(CMAP)
+   CMAP = jet(64);
+  end
+ end
+ Ncmap = size(CMAP,1);
+elseif isnumeric(CMAP)
+ % CMAP as an [R G B] colormap:
+ Ncmap = size(CMAP,1);
+ if (size(CMAP,2)~=3) || ...
+  ((min(CMAP(:))<0) || (max(CMAP(:))>1)) || any(~isfinite(CMAP(:)))
+  error('CVARGAS:cmapping:incorrectCmapInput', ...
+        'CMAP is an incorrect 3 columns RGB colors.')
+ end
+elseif ischar(CMAP)
+ % String CMAP
+ % Checks first character:
+ switch CMAP(1)
+  case '-'
+   mflip = ~mflip;
+   CMAP(1) = [];
+   if isempty(CMAP)
+    error('CVARGAS:cmapping:emptyCmapInput',...
+     'CMAP function is empty.')
+   end
+ end
+ if ~((exist(CMAP,'file')==2) || (exist(CMAP,'builtin')==5))
+  % CMAP as a combination of color char specifiers:
+  CMAP  = lower(CMAP);
+  iy    = (CMAP=='y');
+  im    = (CMAP=='m');
+  ic    = (CMAP=='c');
+  ir    = (CMAP=='r');
+  ig    = (CMAP=='g');
+  ib    = (CMAP=='b');
+  iw    = (CMAP=='w');
+  ik    = (CMAP=='k');
+  Ncmap = length(CMAP);
+  if (sum([iy im ic ir ig ib iw ik])~=Ncmap)
+   error('CVARGAS:cmapping:incorrectCmapStringInput', ...
+   ['String CMAP must be a valid colormap name or a combination of '...
+    '''ymcrgbwk''.'])
+  end
+  % Convertion to [R G B]:
+  CMAP       = zeros(Ncmap,3);
+  CMAP(iy,:) = repmat([1 1 0],sum(iy),1);
+  CMAP(im,:) = repmat([1 0 1],sum(im),1); % BUG fixed Jun 2009
+  CMAP(ic,:) = repmat([0 1 1],sum(ic),1);
+  CMAP(ir,:) = repmat([1 0 0],sum(ir),1);
+  CMAP(ig,:) = repmat([0 1 0],sum(ig),1);
+  CMAP(ib,:) = repmat([0 0 1],sum(ib),1);
+  CMAP(iw,:) = repmat([1 1 1],sum(iw),1);
+  CMAP(ik,:) = repmat([0 0 0],sum(ik),1);
+ else
+  % CMAP as a function name
+  % Changes function name to handle:
+  CMAP = str2func(CMAP);
+  Ncmap = []; % This indicates a CMAP function input
+ end
+elseif isa(CMAP,'function_handle')
+ Ncmap = []; % This indicates a CMAP function input
+else
+ % CMAP input unrecognized:
+ error('CVARGAS:cmapping:incorrectCmapInput', ...
+  'Not recognized CMAP input.') 
+end
+
+% Checks CMAP function handle:
+if isempty(Ncmap)
+ % Generates the COLORMAP from function:
+ try
+  temp = CMAP(2);
+  if ~all(size(temp)==[2 3]) || any(~isfinite(temp(:))), error(''), end
+  clear temp
+ catch
+  error('CVARGAS:cmapping:incorrectCmapFunction', ...
+   ['CMAP function ''' func2str(CMAP) ''' must result in RGB colors.'])
+ end
+end
+
+% Checks varargin:
+while ~isempty(varargin)
+ if     isempty(varargin{1})
+  % continue
+ elseif ischar(varargin{1})
+  % string input
+  switch lower(varargin{1})
+   % CNAN:
+   case 'y'         , CNAN = [1 1 0];
+   case 'm'         , CNAN = [1 0 0];
+   case 'c'         , CNAN = [0 1 1];
+   case 'r'         , CNAN = [1 0 0];
+   case 'g'         , CNAN = [0 1 0];
+   case 'b'         , CNAN = [0 0 1];
+   case 'w'         , CNAN = [1 1 1];
+   case 'k'         , CNAN = [0 0 0];
+   % MODE:
+   case 'discrete'  , MODE = 'discrete';
+   case 'continuous', MODE = 'continuous';
+   % TYPE:
+   case 'colormap'  , TYPE = 'colormap';
+   case 'image'     , TYPE = 'image';
+   % MAPS:
+   case 'direct'    , MAPS = 'direct';
+   case 'scaled'    , MAPS = 'scaled';
+   % Incorrect input:
+   otherwise
+    error('CVARGAS:cmapping:incorrectStringInput',...
+     ['Not recognized optional string input: ''' varargin{1} '''.'])
+  end
+ elseif isnumeric(varargin{1}) && all(isfinite(varargin{1}(:)))
+  % numeric input
+  nv = numel(varargin{1});
+  if (nv==3) && (size(varargin{1},1)==1)
+   % CNAN:
+   CNAN = varargin{1}(:)';
+   if (max(CNAN)>1) || (min(CNAN)<0)
+    error('CVARGAS:cmapping:incorrectCnanInput',...
+     'CNAN elements must be between 0 and 1.')
+   end
+  elseif (nv==2) && (size(varargin{1},1)==1)
+   % CLIM:
+   CLIM = sort(varargin{1},'ascend');
+   if (diff(CLIM)==0)
+    error('CVARGAS:cmapping:incorrectClimValues',...
+     'CLIM must have 2 distint elements.')
+   end
+  else
+   error('CVARGAS:cmapping:incorrectNumericInput',...
+   'Not recognized numeric input.')
+  end
+ else
+  error('CVARGAS:cmapping:incorrectInput',...
+   'Not recognized input.')
+ end
+ % Clears current optional input:
+ varargin(1) = [];
+end % while
+
+
+% -------------------------------------------------------------------------
+% MAIN
+% -------------------------------------------------------------------------
+
+% U size:
+[m,n] = size(U);
+mn    = m*n;
+
+% Checks TYPE:
+if ~any([m n]==1)
+ % Forces image TYPE if U is a matrix:
+ TYPE = 'image';
+elseif strcmp(TYPE,'colormap') && ~nargout && isempty(AX)
+ % Changes the colormap on the specified or current axes if no output
+ % argument:
+ AX = {gca};
+end
+
+% Forces positive integer if U is an scalar, and flips CMAP if is negative:
+if (mn==1)
+ U = round(U);
+ if (U==0)
+  if ~nargout && strcmp(TYPE,'colormap')
+   warning('CVARGAS:cmapping:incorrectUInput',...
+    'U was zero and produces no colormap')
+  else
+   RGB = [];
+  end
+  return
+ elseif (U<0)
+  mflip = ~mflip;
+  U     = abs(U);
+ end
+end
+
+% Gets CMAP from function handle:
+if isempty(Ncmap)
+ if (mn==1)
+  % From U:
+  Ncmap = U(1);
+ else
+  % From default colormap:
+  if ~isempty(HA)
+   Ncmap = size(colormap(HA),1);
+  else
+   Ncmap = size(get(0,'DefaultFigureColormap'),1);
+  end
+ end
+ CMAP = CMAP(Ncmap);
+end
+
+% Flips the colormap
+if mflip
+ CMAP = flipud(CMAP);
+end
+
+% Check CMAP when U is an scalar::
+if (mn==1) && (U==Ncmap)
+ % Finishes:
+ if ~nargout && strcmp(TYPE,'colormap')
+  if Nargin==0
+   RGB = colormap(AX{:},CMAP);
+  else
+   colormap(AX{:},CMAP)
+  end
+ else
+  RGB = CMAP;
+  if strcmp(TYPE,'image')
+   RGB = reshape(RGB,Ncmap,1,3);
+  end
+ end
+ return
+end
+
+% Sets scales:
+if strcmp(MAPS,'scaled')
+ % Scaled mapping:
+ if ~isempty(CLIM)
+  if (mn==1)
+   mn = U;
+   U = linspace(CLIM(1),CLIM(2),mn)';
+  else
+   % Continue  
+  end
+ else
+  CLIM = [0 1];
+  if (mn==1)
+   mn = U;
+   U = linspace(CLIM(1),CLIM(2),mn)';
+  else
+   % Scales U to [0 1]:
+   U = U-min(U(isfinite(U(:))));
+   U = U/max(U(isfinite(U(:))));
+   % Scales U to CLIM:
+   U = U*diff(CLIM)+CLIM(1);
+  end
+ end
+else
+ % Direct mapping:
+ CLIM = [1 Ncmap];
+end
+
+% Do not extrapolates:
+U(U<CLIM(1)) = CLIM(1);
+U(U>CLIM(2)) = CLIM(2);
+
+% Sets CMAP argument:
+umap = linspace(CLIM(1),CLIM(2),Ncmap)';
+
+% Sets U:
+if (mn==2) && (U(1)==U(2))
+ % U = [Uo Uo] implicates U = Uo:
+ U(2) = [];
+ mn   = 1;
+ m    = 1;
+ n    = 1;
+end
+
+% Sets discretization:
+if strcmp(MODE,'discrete')
+ umap2 = linspace(umap(1),umap(end),Ncmap+1)';
+ for k = 1:Ncmap
+  U((U>umap2(k)) & (U<=umap2(k+1))) = umap(k);
+ end
+ clear umap2
+end
+
+% Forces column vector:
+U = U(:);
+
+% Gets finite data:
+inan = ~isfinite(U);
+
+% Initializes:
+RGB  = repmat(reshape(CNAN,[1 1 3]),[mn 1 1]);
+
+% Interpolates:
+if (Ncmap>1) && (sum(~inan)>1)
+ [Utemp,a,b]    = unique(U(~inan));
+ RGBtemp = [...
+  interp1(umap,CMAP(:,1),Utemp,method) ...
+  interp1(umap,CMAP(:,2),Utemp,method) ...
+  interp1(umap,CMAP(:,3),Utemp,method) ...
+  ];
+ RGB(~inan,:) = RGBtemp(b,:);
+else
+ % single color:
+ RGB(~inan,1,:) = repmat(reshape(CMAP,[1 1 3]),[sum(~inan) 1 1]);
+end
+
+% Just in case
+RGB(RGB>1) = 1; 
+RGB(RGB<0) = 0;
+
+% OUTPUTS CHECK-OUT
+% -------------------------------------------------------------------------
+
+% Output type:
+if strcmp(TYPE,'colormap')
+ RGB = reshape(RGB,mn,3);
+ if ~isempty(AX)
+  colormap(AX{:},RGB)
+  if ~nargout 
+   clear RGB
+  end
+ end
+else
+ RGB = reshape(RGB,[m n 3]);
+end
+
+
+% [EOF]   cmapping.m
Index: /issm/trunk-jpl/externalpackages/cm_and_cb_utilities/cmfit.m
===================================================================
--- /issm/trunk-jpl/externalpackages/cm_and_cb_utilities/cmfit.m	(revision 11804)
+++ /issm/trunk-jpl/externalpackages/cm_and_cb_utilities/cmfit.m	(revision 11804)
@@ -0,0 +1,360 @@
+function [CMAP,CLIM,WIDTH,REF,LEVELS] = ...
+                                 cmfit(CMAP,CLIM,WIDTH,REF,CENTER,varargin) 
+%CMFIT   Sets the COLORMAP and CAXIS to specific color bands. 
+%
+%   SYNTAX:
+%                                      cmfit
+%                                      cmfit(CMAP)
+%                                      cmfit(CMAP,CLIM)
+%                                      cmfit(CMAP,CLIM,WIDTH or LEVELS)
+%                                      cmfit(CMAP,CLIM,WIDTH,REF)
+%                                      cmfit(CMAP,CLIM,WIDTH,REF,CENTER)
+%                                      cmfit(AX,...)
+%     [CMAPF,CLIMF,WIDTHF,REFF,LEVF] = cmfit(...);
+%
+%   INPUT:
+%     CMAP   - Fits the specified colormap function or RGB colors. 
+%              DEFAULT: (current figure colormap)
+%     CLIM   - 2 element vector spacifying the limits of CMAP. 
+%              DEFAULT: (limits of a COLORBAR)
+%     WIDTH  - Color band width (limits are computed with CAXIS) for each
+%     or       band or a row vector specifying the LEVELS on each band (see
+%     LEVELS   NOTE below).
+%              DEFAULT: (fills the ticks of a COLORBAR)
+%     REF    - Reference level to start any of the color bands.
+%              DEFAULT: (generally the middle of CLIM)
+%     CENTER - Logical specifying weather the colormap should be center in
+%              the REF value or not.
+%              DEFAULT: false (do not centers)
+%     AX     - Uses the specified figure or axes handle.
+%
+%   OUTPUT (all optional):
+%     CMAPF  - RGB fitted color map (with 3 columns).
+%     CLIMF  - Limits of CMAPF.
+%     WIDTHF - Width of fitted colorbands.
+%     REFF   - Reference of fitted colorbands.
+%     LEVF   - Levels for the color bands.
+%
+%   DESCRIPTION:
+%     This program sets the current figure colormap with specified
+%     band-widths of colors taking the CAXIS limits as reference. When the 
+%     optional input argument CENTER is true, the colormap is moved and
+%     expanded so its middle color will be right at REF. This will help for
+%     distinguish between positive and negative values (REF=0).
+%
+%   NOTE:
+%     * Optional inputs use its DEFAULT value when not given or [].
+%     * Optional outputs may or not be called.
+%     * When one of the first two inputs is missing, they are automatically
+%       calculated by using a COLORBAR (created temporarly if necesary). In
+%       this case CBHANDLE is necesary.
+%     * When CMAP is used as output, the current figure colormap won't be
+%       modificated. Use 
+%         >> colormap(CMAP)
+%       after this function, if necesary.
+%     * When LEVELS are used instead of band WINDTH, it shoud be
+%       monotonically increasing free of NaNs and of length equal to the
+%       number of colors minus one, on the output colormap.
+% 
+%   SEE ALSO:
+%     COLORMAP
+%     and 
+%     CMAPPING, CBFIT by Caros Vargas
+%     at http://www.mathworks.com/matlabcentral/fileexchange
+%
+%
+%   ---
+%   MFILE:   cmfit.m
+%   VERSION: 1.0 (Jun 08, 2009) (<a href="matlab:web('http://www.mathworks.com/matlabcentral/fileexchange/authors/11258')">download</a>) 
+%   MATLAB:  7.7.0.471 (R2008b)
+%   AUTHOR:  Carlos Adrian Vargas Aguilera (MEXICO)
+%   CONTACT: nubeobscura@hotmail.com
+
+%   REVISIONS:
+%   1.0      Released. (Jun 08, 2009)
+
+%   DISCLAIMER:
+%   cmfit.m is provided "as is" without warranty of any kind, under the
+%   revised BSD license.
+
+%   Copyright (c) 2008,2009 Carlos Adrian Vargas Aguilera
+
+
+% INPUTS CHECK-IN
+% -------------------------------------------------------------------------
+
+% Sets defaults: 
+AX  = {};    % Axes input
+tol = 1;     % Adds this tolerance to the decimal precision
+hfig = {get(0,'CurrentFigure')};
+if ~isempty(hfig)
+ hax = {get(hfig{1},'CurrentAxes')};
+ if isempty(hax{1}), hax = {}; end
+else
+ hfig = {};
+ hax  = {};
+end
+
+% Checks inputs:
+if nargin>6
+ error('CVARGAS:cmfit:tooManyInputs', ...
+  'At most 6 inputs are allowed.')
+end
+if nargin>5
+ error('CVARGAS:cmfit:tooManyOutputs', ...
+  'At most 5 outputs are allowed.')
+end
+
+% Saves number of arguments:
+Nargin = nargin;
+
+% Checks AX input:
+if (Nargin>0) && ~isempty(CMAP) && (numel(CMAP)==1) && ...
+  ishandle(CMAP)
+ % Gets AX and moves all other inputs to the left:
+ AX = {CMAP};
+ switch get(AX{1},'Type')
+  case 'axes'
+   hax  = AX;
+   hfig = {get(hax{1},'Parent')};
+  case {'figure','uipanel'}
+   hfig = {AX{1}};
+   hax  = {get(hfig{1},'CurrentAxes')};
+   if isempty(hax{1}), hax = {}; end
+  otherwise
+   error('CVARGAS:cmfit:incorrectAxHandle',...
+    'AX must be a valid axes or figure handle.')
+ end
+ if (Nargin>1)
+  CMAP = CLIM;
+  if (Nargin>2)
+   CLIM = WIDTH;
+   if (Nargin>3)
+    WIDTH = REF;
+    if (Nargin>4)
+     REF = CENTER;
+     if (Nargin>5)
+      CENTER = varargin{1};
+     end
+    end
+   end
+  end
+ end
+ Nargin = Nargin-1;
+end
+
+% Checks CMAP input:
+if Nargin<1 || isempty(CMAP)
+ if ~isempty(hax)
+  CMAP = colormap(hax{1});
+ else
+  CMAP = get(0,'DefaultFigureColormap');
+ end
+end
+
+% Checks CLIM input:
+if Nargin<2
+ CLIM = [];
+end
+
+% Checks WIDTH input:
+if Nargin<3
+ WIDTH = [];
+end
+
+% Checks REf input:
+if Nargin<4
+ REF = [];
+end
+
+% Checks CENTER input:
+if Nargin<5 || isempty(CENTER)
+ CENTER = false;
+end
+
+% Look for WIDTH and REF from a (temporarly) colorbar:
+if isempty(WIDTH) || (length(WIDTH)==1 && (isempty(REF) || ...
+  (isempty(CLIM) && (isempty(hax) || ...
+  ~strcmp(get(hax{1},'CLimMode'),'manual')))))
+ if ~isempty(CLIM)
+  caxis(hax{:},CLIM)
+ end
+ if ~isempty(AX) && ~isempty(cbhandle(AX{1}))
+  h = cbhandle(AX{1}); doclear = false; h = h(1);
+ elseif ~isempty(hax) && ~isempty(cbhandle(hax{1}))
+  h = cbhandle(hax{1}); doclear = false; h = h(1);
+ elseif ~isempty(hfig) && ~isempty(cbhandle(hfig{1}))
+  h = cbhandle(hfig{1}); doclear = false; h = h(1);
+ else
+  h = colorbar; doclear = true;
+ end
+ ticks = get(h,'XTick');
+ lim   = get(h,'XLim');
+ if isempty(ticks)
+  ticks = get(h,'YTick');
+  lim   = get(h,'YLim');
+ end
+ if isempty(WIDTH)
+  WIDTH = diff(ticks(1:2));
+ end
+ if isempty(CLIM)
+  CLIM = lim;
+ end
+ if isempty(REF) && ~CENTER
+  REF = ticks(1);
+ end
+ if doclear
+  delete(h)
+ end
+end
+
+% Centers at the middle:
+if CENTER && isempty(REF)
+ REF = 0;
+end 
+
+% -------------------------------------------------------------------------
+% MAIN
+% -------------------------------------------------------------------------
+
+
+% Gets minimum width from specified levels:
+NL = length(WIDTH); 
+if (NL>1)
+ 
+ %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+ % NONLINEAR CASE %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+ %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+ 
+ LEVELS = sort(WIDTH);
+ 
+ % Gets LEVELS width:
+ wLEVELS = diff(LEVELS);
+ 
+ % Scales to CLIM:
+ if ~isempty(CLIM)
+  % Scales to [0 1]
+  LEVELS = LEVELS-LEVELS(1);
+  LEVELS = LEVELS/LEVELS(end);
+  % Scales to CLIM:
+  LEVELS = LEVELS*diff(CLIM)+CLIM(1);
+ else
+  CLIM  = [LEVELS(1) LEVELS(end)]; 
+ end
+ 
+ % Gets precision:
+ if isinteger(wLEVELS) % Allows integer input: uint8, etc. 
+  wLEVELS = double(wLEVELS);
+ end
+ temp = warning('off','MATLAB:log:logOfZero');
+ precision = floor(log10(abs(wLEVELS))); % wLEVELS = Str.XXX x 10^precision.
+ precision(wLEVELS==0) = 0; % M=0 if x=0.
+ warning(temp.state,'MATLAB:log:logOfZero')
+ precision = min(precision)-tol;
+ 
+ % Sets levels up to precision:
+ wLEVELS = round(wLEVELS*10^(-precision));
+ 
+ % Gets COLORMAP for each LEVEL:
+ if CENTER
+  % Centers the colormap:
+  ind = (REF==LEVELS);
+  if ~any(ind)
+   error('CVARGAS:cmfit:uncorrectRefLevel',...
+    'When CENTER, REF level must be on of the specifyied LEVELS.')
+  end
+  Nl     = sum(~ind(1:find(ind)));
+  [Nl,l] = max([Nl (NL-1-Nl)]);
+  wCMAP  = cmapping(2*Nl,CMAP);
+  if l==1
+   wCMAP = wCMAP(1:NL-1,:);
+  else
+   wCMAP = wCMAP(end-NL+2:end,:);
+  end
+ else
+  wCMAP  = cmapping(NL-1,CMAP);
+ end
+ 
+ % Gets minimum band width:
+ WIDTH = wLEVELS(1);
+ for k = 1:NL-1
+  wlev    = wLEVELS;
+  wlev(k) = [];
+  WIDTH   = min(min(gcd(wLEVELS(k),wlev)),WIDTH);
+ end
+ 
+ % Gets number of bands:
+ wLEVELS = wLEVELS/WIDTH;
+ 
+ % Gets new CMAP:
+ N = sum(wLEVELS);
+ try
+  CMAP = repmat(wCMAP(1,:),N,1);
+ catch
+  error('CVARGAS:cmfit:memoryError',...
+   ['The number of colors (N=' int2str(N) ') for the new colormap ' ...
+    'is extremely large. Try other LEVELS.'])
+ end
+ ko = wLEVELS(1);
+ for k = 2:NL-1;
+  CMAP(ko+(1:wLEVELS(k)),:) = repmat(wCMAP(k,:),wLEVELS(k),1);
+  ko = ko+wLEVELS(k);
+ end
+ 
+else
+ 
+ %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+ % LINEAR CASE %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+ %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+ 
+ % Gets CLIM:
+ if isempty(CLIM)
+  CLIM = caxis(hax{:});
+ end
+
+ % Sets color limits to be a multipler of WIDTH passing through REF:
+ N1   = ceil((+REF-CLIM(1))/WIDTH);
+ N2   = ceil((-REF+CLIM(2))/WIDTH);
+ CLIM = REF + [-N1 N2]*WIDTH;
+
+ % Sets colormap with NC bands:
+ Nc = round(diff(CLIM)/WIDTH);
+ if CENTER
+  % Necesary colorbands number to be centered:
+  Nmin        = [N1 N2];
+  [Nmax,imax] = max(Nmin);
+  Nmin(imax)  = [];
+  Nc2         = Nc + Nmax - Nmin;
+  % Generate a colormap with this size:
+  CMAP = cmapping(Nc2,CMAP);
+  if imax==1
+   CMAP = CMAP(1:Nc,:);
+  else
+   CMAP = flipud(CMAP);
+   CMAP = CMAP(1:Nc,:);
+   CMAP = flipud(CMAP);
+  end
+ else
+  CMAP = cmapping(Nc,CMAP);
+ end
+ 
+ % Sets levels:
+ LEVELS = linspace(CLIM(1),CLIM(2),size(CMAP,1))';
+end
+
+% OUTPUTS CHECK-OUT
+% -------------------------------------------------------------------------
+if ~isempty(AX)
+ colormap(AX{:},CMAP)
+ caxis(AX{:},CLIM)
+end
+if ~nargout
+ if isempty(AX)
+  colormap(CMAP)
+  caxis(CLIM)
+ end
+ clear CMAP
+end
+
+
+% [EOF]   cmfit.m
Index: /issm/trunk-jpl/externalpackages/cm_and_cb_utilities/cmjoin.m
===================================================================
--- /issm/trunk-jpl/externalpackages/cm_and_cb_utilities/cmjoin.m	(revision 11804)
+++ /issm/trunk-jpl/externalpackages/cm_and_cb_utilities/cmjoin.m	(revision 11804)
@@ -0,0 +1,462 @@
+function [CMAP,LEV,WID,CLIM] = cmjoin(varargin)
+%CMJOIN   Joins colormaps at certain levels.
+%
+%   SYNTAX:
+%                           cmjoin(CMAPS)
+%                           cmjoin(CMAPS,LEV)
+%                           cmjoin(CMAPS,LEV,WID)
+%                           cmjoin(CMAPS,LEV,WID,CLIM)
+%                           cmjoin(AX,...)
+%     [CMAP,LEV,WID,CLIM] = cmjoin(...);
+%
+%   INPUT:
+%     CMAPS - Cell with the N colormaps handles, names or RGB colors to be
+%             joined. See NOTE below.
+%     LEV   - One of:
+%               a) N-1 scalars specifying the color levels where the
+%                  colormaps will be joined (uses CAXIS). See NOTE below.
+%               b) N integers specifying the number of colors for each
+%                  colormap.
+%               c) N+1 scalars specifying the color limits for each
+%                  colormap (sets CAXIS). See NOTE below.
+%             DEFAULT: Tries to generate a CMAP with default length.
+%     WID   - May be one (or N) positive scalar specifying the width for
+%             every (or each) color band. See NOTE below.
+%             DEFAULT: uses CAXIS and LEV to estimate it.  
+%     CLIM  - 2 elements row vector specifying the color limits values. May
+%             be changed at the end, because of the discretization of the
+%             colormaps.
+%             DEFAULT: uses CAXIS or [0 1] if there are no axes.
+%     AX    - Uses the specified axes handle to get/set the CMAPS. If used,
+%             must be the first input.
+%             DEFAULT: gca
+%
+%   OUTPUT (all optional):
+%     CMAP - RGB colormap output matrix, M-by-3.
+%     LEV  - Final levels used.
+%     WID  - Final widths used.
+%     CLIM - Final color limits used.
+%
+%   DESCRIPTION:
+%     This function join two colormaps at specific level. Useful for
+%     joining colormaps at zero (for example) and distinguish from positive
+%     and negative values.
+%
+%   NOTE:
+%     * Optional inputs use its DEFAULT value when not given or [].
+%     * Optional outputs may or not be called.
+%     * If no output is required or an axes handle were given, the current
+%       COLORMAP and CAXIS are changed.
+%     * If any of the inputs on CMAPS is a function name, 'jet', for
+%       example, it can be used backwards (because CMAPPING is used) if
+%       added a '-' at the beggining of its name: '-jet'.
+%     * When LEV is type b) and WID is specifyed, the latter is taken as
+%       relative colorbans widths between colormaps.
+%
+%   EXAMPLE:
+%     figure(1), clf, surf(peaks)
+%     cmjoin({'copper','-summer'},2.5)
+%      shading interp, colorbar, axis tight, zlabel('Meters')
+%      title('Union at 2.5 m')
+%     %
+%     figure(2), clf, surf(peaks) 
+%     cmjoin({'copper','-summer'},2.5,0.5)
+%      shading interp, colorbar, axis tight, zlabel('Meters')
+%      title('Union at 2.5 m and different color for each 0.5 m band')
+%     %
+%     figure(3), clf, surf(peaks)
+%     cmjoin({'copper','summer'},2.5,[2 0.5])
+%      shading interp, colorbar, axis tight, zlabel('Metros')
+%      title('Union at 2.5 m with lengths 2 and 0.5')
+%     %
+%     figure(4), clf, surf(peaks)
+%     cmjoin({'copper','summer'},[-10 2.5 10],[2 0.5])
+%      shading interp, colorbar, axis tight, zlabel('Metros')
+%      title('Union at 2.5 m with lengths 2 and 0.5 and specified levels')
+%     %
+%     figure(5), clf, surf(peaks)
+%     cmjoin({'copper','summer'},[10 8],[4 1])
+%      shading interp, colorbar, axis tight, zlabel('Metros')
+%      title('Union at 2.5 m with specified levels number of colors and widths 4:1')
+%    
+%   SEE ALSO:
+%     COLORMAP, COLORMAPEDITOR
+%     and
+%     CMAPPING by Carlos Vargas
+%     at http://www.mathworks.com/matlabcentral/fileexchange
+%
+%
+%   ---
+%   MFILE:   cmjoin.m
+%   VERSION: 2.0 (Jun 08, 2009) (<a href="matlab:web('http://www.mathworks.com/matlabcentral/fileexchange/authors/11258')">download</a>) 
+%   MATLAB:  7.7.0.471 (R2008b)
+%   AUTHOR:  Carlos Adrian Vargas Aguilera (MEXICO)
+%   CONTACT: nubeobscura@hotmail.com
+
+%   REVISIONS:
+%   1.0       Released as SETCOLORMAP. (Nov 07, 2006)
+%   1.1       English translation. (Nov 11, 2006)
+%   2.0       Rewritten and renamed code (from SETCOLORMAPS to CMJOIN. Now
+%             joins multiple colormaps. Inputs changed. (Jun 08, 2009)
+
+%   DISCLAIMER:
+%   cmjoin.m is provided "as is" without warranty of any kind, under the
+%   revised BSD license.
+
+%   Copyright (c) 2006,2009 Carlos Adrian Vargas Aguilera
+
+% INPUTS CHECK-IN
+% -------------------------------------------------------------------------
+
+% Parameters:
+tol  = 1;            % When rounding the levels.
+
+% Checks inputs and outputs number:
+if nargin<1
+ error('CVARGAS:cmjoin:notEnoughInputs',...
+  'At least 1 input is required.')
+end
+if nargin>5
+ error('CVARGAS:cmjoin:tooManyInputs',...
+  'At most 5 inputs are allowed.')
+end
+if nargout>4
+ error('CVARGAS:cmjoin:tooManyOutputs',...
+  'At most 4 outputs are allowed.')
+end
+
+% Checks AX:
+AX = {get(get(0,'CurrentFigure'),'CurrentAxes')};
+if isempty(AX{1})
+ AX = {};
+end
+if (length(varargin{1})==1) && ishandle(varargin{1}) && ...
+  strcmp(get(varargin{1},'Type'),'axes')
+ AX = varargin(1);
+ varargin(1) = [];
+ if isempty(varargin)
+  error('CVARGAS:cmjoin:notEnoughInputs',...
+   'CMAPS input must be given.')
+ end
+end
+
+% Checks CMAPS:
+CMAPS  = varargin{1};
+Ncmaps = length(CMAPS);
+if ~iscell(CMAPS) || (Ncmaps<2)
+ error('CVARGAS:cmjoin:incorrectCmapsType',...
+  'CMAPS must be a cell input with at least 2 colormaps.')
+end
+varargin(1) = [];
+Nopt        = length(varargin);
+
+% Checks LEV and sets Ncol and Jlev:
+Ncol = []; % Number of colors for each colormap.
+Jlev = []; % Join levels.
+LEV  = []; % Levels at which each CMAPS begins and ends.
+if (Nopt<1) || isempty(varargin{1})
+ % continue as empty
+elseif ~all(isfinite(varargin{1}(:)))
+ error('CVARGAS:cmjoin:incorrectLevValue',...
+  'LEV must be integers or scalars.')
+else
+ Nopt1 = length(varargin{1}(:));
+ if (Nopt1==Ncmaps)
+  % Specifies number of colors:
+  Ncol = varargin{1}(:);
+  if ~all(Ncol==round(Ncol))
+   error('CVARGAS:cmjoin:incorrectLevInput',...
+    'LEV must be integers when defines number of colors.')
+  end
+ elseif ~all(sort(varargin{1})==varargin{1})
+  error('CVARGAS:cmjoin:incorrectLevInput',...
+   'LEV must be monotonically increasing.')
+ elseif Nopt1==(Ncmaps-1) 
+  Jlev = varargin{1}(:);
+ elseif Nopt1==(Ncmaps+1)
+  LEV = varargin{1}(:);
+ else
+  error('CVARGAS:cmjoin:incorrectLevLength',...
+   'LEV must have any of length(CMAPS)+[-1 0 1] elements.')
+ end
+end
+
+% Checks WID:
+Tcol = []; % Total number of colors for output colormap.
+if (Nopt<2) || isempty(varargin{2})
+ % Tries to generate a colormap with default length with every colorband
+ % of the same width:
+ WID = [];
+ if ~isempty(AX)
+  Tcol = size(colormap(AX{:}),1);
+ else
+  Tcol = size(get(0,'DefaultFigureColormap'),1);
+ end
+else
+ WID = varargin{2}(:);
+ WID(~isfinite(WID) | (WID<0)) = 0;
+ if ~any(WID>0)
+  error('CVARGAS:cmjoin:incorrectWidInput',...
+   'At least one WID must be positive.')
+ end
+ if length(WID)==1
+  WID = repmat(abs(varargin{2}),Ncmaps,1);
+ elseif length(WID)~=Ncmaps
+  error('CVARGAS:cmjoin:incorrectWidLength',...
+   'WID must have length 1 or same as CMAPS.')
+ end
+end
+
+% Checks CLIM:
+if (Nopt<3) || isempty(varargin{3})
+ % Sets default CLIM:
+ if ~isempty(LEV)
+  CLIM = [LEV(1) LEV(end)];
+ elseif ~isempty(AX)
+  CLIM = caxis(AX{:});
+ else
+  CLIM = [0 1];
+ end
+else
+ CLIM = varargin{3}(:).';
+ if (length(CLIM)==2) && (diff(CLIM)>0) && isfinite(diff(CLIM))
+  % continue
+ else
+  error('CVARGAS:cmjoin:incorrectClimInput',...
+   'CLIM must be a valid color limits. See CAXIS for details.')
+ end
+end
+
+
+% -------------------------------------------------------------------------
+% MAIN
+% -------------------------------------------------------------------------
+
+% Gets rounding precision:
+temp = warning('off','MATLAB:log:logOfZero');
+if ~isempty(WID)
+ tempp               = WID;
+ precision           = floor(log10(abs(tempp)));
+ precision(tempp==0) = 0;
+ precision           = min(precision)-tol;
+ % Rounds:
+ WID   = round(WID*10^(-precision))*10^precision;
+ if ~isempty(LEV)
+  LEV(1)        = floor(LEV(1)       *10^(-precision))*10^precision;
+  LEV(2:end-1)  = round(LEV(2:end-1) *10^(-precision))*10^precision;
+  LEV(end)      = ceil(LEV(end)      *10^(-precision))*10^precision;
+ elseif ~isempty(Jlev)
+  Jlev(1)       = floor(Jlev(1)      *10^(-precision))*10^precision;
+  Jlev(2:end-1) = round(Jlev(2:end-1)*10^(-precision))*10^precision;
+  Jlev(end)     = ceil(Jlev(end)     *10^(-precision))*10^precision;
+ end
+elseif ~isempty(LEV)
+ tempp               = diff(LEV);
+ precision           = floor(log10(abs(tempp)));
+ precision(tempp==0) = 0;
+ precision           = min(precision)-tol;
+ % Rounds:
+ LEV(1)       = floor(LEV(1)      *10^(-precision))*10^precision;
+ LEV(2:end-1) = round(LEV(2:end-1)*10^(-precision))*10^precision;
+ LEV(end)     = ceil(LEV(end)     *10^(-precision))*10^precision;
+elseif ~isempty(Jlev)
+ tempp               = diff(Jlev);
+ if isempty(tempp)
+  tempp              = Jlev;
+ end
+ precision           = floor(log10(abs(tempp)));
+ precision(tempp==0) = 0;
+ precision           = min(precision)-tol;
+ % Rounds:
+ if length(Jlev)==1
+  Jlev          = round(Jlev*10^(-precision))*10^precision;
+ else
+  Jlev(1)       = floor(Jlev(1)      *10^(-precision))*10^precision;
+  Jlev(2:end-1) = round(Jlev(2:end-1)*10^(-precision))*10^precision;
+  Jlev(end)     = ceil(Jlev(end)     *10^(-precision))*10^precision;
+ end
+else
+ tempp               = CLIM;
+ precision           = floor(log10(abs(tempp)));
+ precision(tempp==0) = 0;
+ precision           = min(precision)-tol;
+end
+% Rounds:
+CLIM(1) = floor(CLIM(1)*10^(-precision))*10^precision;
+CLIM(2) =  ceil(CLIM(2)*10^(-precision))*10^precision;
+warning(temp.state,'MATLAB:log:logOfZero')
+
+% Completes levels when only join levels are specified:
+if ~isempty(Jlev)
+ cedge = CLIM;
+ % First limit:
+ if cedge(1)<=Jlev(1)
+  if ~isempty(WID)
+   cedge(1) = Jlev(1);
+   if WID(1)~=0
+    cedge(1) = cedge(1) - WID(1)*ceil((Jlev(1)-CLIM(1))/WID(1));
+   end
+  else
+   % continue
+  end
+ else
+  if (Ncmaps==2)
+   cedge(1) = Jlev(1);
+  else
+   for k = 2:length(Jlev)
+    if cedge(1)<=Jlev(k)
+     cedge(1) = Jlev(k-1);
+     break
+    else
+     Jlev(k-1) = Jlev(k);
+    end
+   end
+  end
+ end
+ % Last limit:
+ if cedge(2)>=Jlev(end)
+  if ~isempty(WID)
+   cedge(2) = Jlev(end);
+   if WID(end)~=0
+    cedge(2) = cedge(2) + WID(end)*ceil((CLIM(2)-Jlev(end))/WID(end));
+   end
+  else
+   % continue
+  end
+ else
+  if (Ncmaps==2)
+   cedge(2) = Jlev(end);
+  else
+   for k = length(Jlev)-1:-1:1
+    if cedge(2)>=Jlev(k)
+     cedge(2) = Jlev(k+1);
+     break
+    else
+     Jlev(k+1) = Jlev(k);
+    end
+   end
+  end
+ end
+ % New Levels:
+ LEV = [cedge(1); Jlev; cedge(2)];
+ 
+end
+
+% Gets colorband width and sets WID:
+if ~isempty(Ncol)
+ if isempty(WID)
+  % Treats all colorbands with equal widths:
+  Cwid = diff(CLIM)/sum(abs(Ncol));
+  Cwid = round(Cwid*10^(-(precision-1)))*10^(precision-1);
+  WID  = repmat(Cwid,Ncmaps,1);
+  LEV  = [CLIM(1); CLIM(1)+cumsum(abs(Ncol))*Cwid];
+ else
+  % Treats WID as colorbands withs relations:
+  WID   = WID/min(WID(WID~=0));
+  Ncol2 = WID.*Ncol;
+  Cwid  = diff(CLIM)/sum(abs(Ncol2));
+  Cwid  = round(Cwid*10^(-(precision-1)))*10^(precision-1);
+  WID   = WID*Cwid;
+  LEV   = [CLIM(1); CLIM(1)+cumsum(abs(Ncol2))*Cwid];
+ end
+elseif ~isempty(WID)
+ % Gets colorband width:
+ Cwid  = WID(1)*10^(-precision);
+ for k = 2:Ncmaps
+  Cwid = gcd(Cwid,WID(k)*10^(-precision));
+ end
+ Cwid  = Cwid*10^precision;
+else
+ % Gets relation between colomaps width:
+ if isempty(LEV)
+  r    = ones(Ncmaps,1);
+  d    = diff(CLIM);
+ else
+  r         = diff(LEV);
+  temp      = warning('off','MATLAB:log:logOfZero');
+  precision = floor(log10(abs(r))); % r = Str.XXX x 10^precision.
+  precision(r==0) = 0; % precision=0 if Ncol=0.
+  warning(temp.state,'MATLAB:log:logOfZero')
+  precision = min(precision)-tol;
+  r  = round(r*10^(-precision));
+  rgcd  = r(1);
+  for k = 2:Ncmaps
+   rgcd = gcd(rgcd,r(k));
+  end
+  r = r/rgcd;
+  d = (LEV(end)-LEV(1));
+ end
+ % Gets colorband width:
+ r    = r*ceil(Tcol/sum(r));
+ Cwid = d/sum(r);
+ WID  = repmat(Cwid,Ncmaps,1);
+end
+
+% Sets LEV when empty:
+if isempty(LEV)
+ LEV = linspace(CLIM(1),CLIM(2),Ncmaps+1)';
+end
+
+% Gets number of colors for each colormap:
+Ncol2 = round(diff(LEV)/Cwid);
+if ~isempty(Ncol)
+ % continue
+else
+ Ncol = round(diff(LEV)./WID);
+ Ncol(~isfinite(Ncol)) = 0;
+ if ~all(Ncol==round(Ncol))
+  error('CVARGAS:cmjoin:incorrectWidColor',...
+   'Colorband do not match each colormap width. Modify LEV or WID.')
+ end
+end
+
+% Generates the colormaps:
+CMAP  = zeros(sum(abs(Ncol2)),3);
+xband = zeros(sum(abs(Ncol2))+1,1);
+tempr = [];
+for k = 1:Ncmaps
+ if Ncol(k)
+  r          = sum(abs(Ncol2(1:k-1)))+(1:abs(Ncol2(k)));
+  if Ncol(k)~=Ncol2(k)
+   CMAP(r,:) = cmapping(Ncol2(k),cmapping(Ncol(k),CMAPS{k}),'discrete');
+  else
+   CMAP(r,:) = cmapping(Ncol(k),CMAPS{k});
+  end
+  tempr      = linspace(LEV(k),LEV(k+1),abs(Ncol2(k))+1)';
+  xband(r)   = tempr(1:end-1); 
+ end
+end
+if ~isempty(tempr)
+ xband(end) = tempr(end);
+end
+
+% Cuts edges:
+ind = find((xband>=CLIM(1)) & (xband<=CLIM(2)));
+if (ind(1)~=1) && ~(any(xband==CLIM(1)))
+ ind = [ind(1)-1; ind];
+end
+if (ind(end)~=length(ind)) && ~(any(xband==CLIM(2)))
+ ind = [ind; ind(end)+1];
+end
+CMAP  = CMAP(ind(1:end-1),:);
+clim2 = xband(ind([1 end]));
+
+
+% OUTPUTS CHECK-OUT
+% -------------------------------------------------------------------------
+
+if ~nargout
+ colormap(AX{:},CMAP)
+ caxis(AX{:},clim2(:)');
+ clear CMAP
+else
+ if ~isempty(AX)
+  colormap(AX{:},CMAP)
+  caxis(AX{:},clim2(:)');
+ end
+ CLIM = clim2;
+ WID  = diff(LEV)./max([Ncol ones(Ncmaps,1)],[],2);
+end
+
+
+% [EOF]   cmjoin.m
Index: /issm/trunk-jpl/externalpackages/cm_and_cb_utilities/cmlines.m
===================================================================
--- /issm/trunk-jpl/externalpackages/cm_and_cb_utilities/cmlines.m	(revision 11804)
+++ /issm/trunk-jpl/externalpackages/cm_and_cb_utilities/cmlines.m	(revision 11804)
@@ -0,0 +1,152 @@
+function [HL,CLIN] = cmlines(varargin)
+% CMLINES   Change the color of plotted lines using the colormap.
+%
+%   SYNTAX:
+%                 cmlines
+%                 cmlines(CMAP)
+%                 cmlines(H,...)
+%     [HL,CLIN] = cmlines(...);
+%   
+%   INPUT:
+%     CMAP - Color map name or handle to be used, or a Nx3 matrix of colors
+%            to be used for each of the N lines or color char specifiers.
+%            DEFAULT: jet.
+%     H    - Handles of lines or from a axes to search for lines or from
+%            figures to search for exes. If used, must be the first input.
+%            DEFAULT: gca (sets colors for lines in current axes)
+%
+%   OUTPUT (all optional):
+%     HL   - Returns the handles of lines. Is a cell array if several axes
+%            handle were used as input.
+%     CLIN - Returns the RGB colors of the lines. Is a cell array if
+%            several axes handle were used as input.
+%
+%   DESCRIPTION:
+%     Ths function colored the specified lines with the spectrum of the
+%     given colormap. Ideal for lines on the same axes which means increase
+%     (or decrease) monotonically.
+%
+%   EXAMPLE:
+%     plot(reshape((1:10).^2,2,5))
+%     cmlines
+%
+%   NOTE:
+%     * Optional inputs use its DEFAULT value when not given or [].
+%     * Optional outputs may or not be called.
+%    
+%   SEE ALSO:
+%     PLOT and COLORMAP.
+%     and
+%     CMAPPING
+%     at http://www.mathworks.com/matlabcentral/fileexchange
+%
+%
+%   ---
+%   MFILE:   cmlines.m
+%   VERSION: 1.0 (Jun 08, 2009) (<a href="matlab:web(['www.mathworks.com/matlabcentral/fileexchange/loadAuthor.do',char(63),'objectType',char(61),'author',char(38),'objectId=1093874'])">download</a>) 
+%   MATLAB:  7.7.0.471 (R2008b)
+%   AUTHOR:  Carlos Adrian Vargas Aguilera (MEXICO)
+%   CONTACT: nubeobscura@hotmail.com
+
+%   REVISIONS:
+%   1.0      Released. (Jun 08, 2009)
+
+%   DISCLAIMER:
+%   cmlines.m is provided "as is" without warranty of any kind, under the
+%   revised BSD license.
+
+%   Copyright (c) 2009 Carlos Adrian Vargas Aguilera
+
+% INPUTS CHECK-IN
+% -------------------------------------------------------------------------
+
+% Set defaults:
+HL   = {};
+Ha   = gca;
+CMAP = colormap;
+
+% Checks number of inputs:
+if nargin>2
+ error('CVARGAS:cmlines:tooManyInputs', ...
+  'At most 2 inputs are allowed.')
+end
+if nargout>2
+ error('CVARGAS:cmlines:tooManyOutputs', ...
+  'At most 2 outputs are allowed.')
+end
+
+% Checks handles of lines, axes or figure inputs:
+Hl = [];
+if (nargin~=0) && ~isempty(varargin{1}) && all(ishandle(varargin{1}(:))) ...
+ && ((length(varargin{1})>1) || ~isa(varargin{1},'function_handle'))
+ Ha = [];
+ for k = 1:length(varargin{1})
+  switch get(varargin{1}(k),'Type')
+   case 'line'
+    Hl = [Hl varargin{1}(k)];
+   case 'axes'
+    Ha = [Ha varargin{1}(k)];
+   case {'figure','uipanel'}
+    Ha = [Ha findobj(varargin{1}(k),'-depth',1,'Type','axes',...
+                      '-not',{'Tag','Colorbar','-or','Tag','legend'})];
+   otherwise
+     warning('CVARGAS:cmlines:unrecognizedHandleInput',...
+      'Ignored handle input.')
+  end
+ end
+ varargin(1) = [];
+end
+
+% Looks for CMAP input:
+if nargin && ~isempty(varargin) && ~isempty(varargin{1})
+ CMAP = varargin{1};
+end
+
+% Gets line handles:
+if ~isempty(Hl)
+ HL{1} = Hl;
+end
+if ~isempty(Ha)
+ for k = 1:length(Ha)
+  Hl = findobj(Ha(k),'Type','line');
+  if ~isempty(Hl)
+   HL{end+1} = Hl;
+  end
+ end
+end
+if isempty(HL)
+ if ~nargout
+  clear HL
+ end
+ return
+end
+
+% -------------------------------------------------------------------------
+% MAIN
+% -------------------------------------------------------------------------
+
+% Sets color lines for each set of lines:
+Nlines = length(HL);
+CLIN   = cell(1,Nlines);
+for k  = 1:length(HL)
+ 
+ % Interpolates the color map:
+ CLIN{k} = cmapping(length(HL{k}),CMAP);
+
+ % Changes lines colors:
+ set(HL{k},{'Color'},mat2cell(CLIN{k},ones(1,size(CLIN{k},1)),3))
+ 
+end
+
+% OUTPUTS CHECK-OUT
+% -------------------------------------------------------------------------
+
+if ~nargout
+ clear HL
+elseif Nlines==1
+ HL   = HL{1};
+ CLIN = CLIN{1};
+end
+
+
+% [EOF]   cmlines.m
