0001 function [cmap, warnstr] = pr_getcmap(acmapname)
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020 cmap = []; warnstr = [];
0021 if nargin < 1
0022 acmapname = '';
0023 end
0024 if isempty(acmapname)
0025 warnstr = 'No colormap name passed';
0026 return
0027 end
0028
0029 cmap = evalin('base',acmapname,'[]');
0030 if ~isempty(cmap)
0031 if size(cmap, 2)~=3
0032 warnstr = ['Colormap matrix ' acmapname ' was not N by 3'];
0033 cmap = [];
0034 end
0035 return
0036 end
0037
0038
0039 tmp = strcmpi(acmapname, {'red','green','blue','cyan', 'magenta', ...
0040 'yellow', 'black', 'white'});
0041 coldefs = [1 0 0;
0042 0 1 0;
0043 0 0 1;
0044 0 1 1;
0045 1 0 1;
0046 1 1 0;
0047 0 0 0;
0048 1 1 1];
0049
0050 if any(tmp)
0051 coldef = coldefs(tmp, :);
0052 if ~any(diff(coldef))
0053 cmap = coldef;
0054 else
0055 cmap = (0:63)' * coldef / 63;
0056 end
0057 return
0058 end
0059
0060 oname = acmapname;
0061 [p f e] = fileparts(acmapname);
0062
0063 if isempty(e)
0064 e = '.mat';
0065 acmapname = fullfile(p, [f e]);
0066 end
0067 ef = exist(acmapname, 'file');
0068
0069 if ~ef
0070 mfp = fileparts(which(mfilename));
0071 acmapname = fullfile(mfp, [f e]);
0072 ef = exist(acmapname, 'file');
0073 end
0074 if ~ef
0075 warnstr = ['No matrix or file ''' oname ''''];
0076 return
0077 end
0078
0079 switch lower(e)
0080 case '.mat'
0081
0082 s = load(acmapname);
0083 if isfield(s, f)
0084 cmap = getfield(s, f);
0085 else
0086 s = struct2cell(s);
0087 cmap = s{1};
0088 end
0089 if size(cmap, 2)~=3
0090 warnstr = ['Colormap from ' acmapname ' was not an N by 3 matrix'];
0091 cmap = [];
0092 end
0093 case '.lut'
0094 fid = fopen(acmapname, 'rb');
0095 if fid~=-1
0096 cmap = fread(fid, Inf);
0097 l = length(cmap);
0098 if ~rem(l,3)
0099 cmap = reshape(cmap, l/3, 3) / 255;
0100 else
0101 warnstr = ['LUT map ' acmapname ' was wrong size'];
0102 end
0103 else
0104 warnstr = ['Cannot open LUT colormap file ' acmapname];
0105 end
0106 otherwise
0107 warnstr = ['Unrecognized file extension ' e ' for ' acmapname];
0108 end
0109 return