function ScaledMat = trueColorScale(keywords, inp1, inp2)

%function ScaledMat = trueColorScale(keywords, inp1, inp2)
% possible keywords = {'BT', 'R', 'diff','flip'};
% examples:
%    ScaledMat = trueColorScale({'BT'}, BT_ofa_Band);
%    ScaledMat = trueColorScale({'BT', 'flip'}, BT_ofa_Band);
%    ScaledMat = trueColorScale({'R'}, Ref_ofa_Band,  szen_in_radians);
%    ScaledMat = trueColorScale({'diff'}, BT_ofa_Band,  BT_ofanother_Band);


 nargs = nargin;

 if nargs < 1
    error('Must have at least 2 inputs')
 end
 
 if ~iscellstr(keywords)
    error('first input must be cellstring of keywords')
 end

 keywords = upper(keywords); 
  
 scale_case = intersect(keywords, {'BT','R', 'DIFF'});
 
 if isempty(scale_case)
    error('keywords must contain either ''BT'', ''R'', or ''diff''.');
 elseif length(scale_case) > 1
    error(['keywords must contain only one of ' ...
	   '''BT'', ''R'', or ''diff''.']); 
    
 end

% set some constants
 btmax = 310;
 btmin = 210;
 btmax_extreme = 330;
 btmin_extreme = 180;
 diffmin = -10;
 diffmax = 10;
 Rmax_extreme = 1.0;
 Rmax = 1;
 switch char(scale_case)
  case 'BT'
   bt = inp1;
   waytoohot = find(bt >= btmax_extreme);
   waytoocool = find(bt <= btmin_extreme);
   bt(waytoohot) = NaN;
   bt(waytoocool) = NaN;
   toohot = find(bt > btmax & bt < btmax_extreme);
   bt(toohot) = btmax;
   toocool = find(bt < btmin & bt > btmin_extreme);
   bt(toocool) = btmin;
   plotval = bt ./ btmax;
  case 'DIFF'
   bt1 = inp1;
   bt2 = inp2;
   waytoohot = find(bt2 > btmax_extreme);
   waytoocool = find(bt2 < btmin_extreme);
   bt1(waytoohot) = NaN;
   bt1(waytoocool) = NaN;
   bt2(waytoohot) = NaN;
   bt2(waytoocool) = NaN;
   diff = bt1 - bt2;
   
   toodiff = find(diff > diffmax);
   notdiffenough = find(diff < diffmin);
   diff(toodiff) = diffmax;
   diff(notdiffenough) = diffmin;
   diffplot = diff + abs(diffmin); % (to scale from 0 to 20 rather than -10 to 10);
   plotval = diffplot./ (diffmax + abs(diffmin));
 otherwise % 'R'
   ref_unszen_scaled = inp1;
   szen = inp2;
   ref = ref_unszen_scaled ./ cos(szen);
   waytoodark = find(ref < 0);
   waytoobright = find(ref >= Rmax_extreme);
   ref(waytoodark) = NaN;
   ref(waytoobright) = NaN;
   toobright = find(ref > Rmax & ref < Rmax_extreme);
   ref(toobright) = Rmax;
   plotval = ref ./ Rmax;
 end
 
 if ismember('FLIP', keywords)
    plotval = 1 - plotval;
 end
 
 ScaledMat = plotval; 
 
    
