function [x,y,xaxes,yaxes] = ndlookico(action, option, blkMaskType, tableData, interp_or_bp, varargin)
%NDLOOKICO icon data for LookupNDInterp blocks
%

% Rob Aberg,  28-July-1999
% Copyright 1990-2003 The MathWorks, Inc.
% $Revision: 1.7.2.3 $  $Date: 2004/04/15 00:31:56 $

% --- Init
errFlag  = 0;
doSelect = false;

% --- Definition of a "big" table - if a table has more
%     points than this, plot a default icon for performance
%     reasons.

tableLengthThreshold = 1000; 
  
% --- Cache the block handle
blk = gcbh;

% --- Default 1-D icon table values
default1Ddata = [-0.9999, -0.9993, -0.9951, -0.9640, -0.7616, 0, ...
                 0.7616,  0.9640,  0.9951,  0.9993,  0.9999 ]; 


%==============================================================================
%
% Handle special cases: plot data, default plot, bare call
%

if (nargin == 0)

  action = 'dynamic';  % mask callback

elseif ~any(strcmp(action, {'kfdyn','predyn','bpplotdata','bppatchdata'})),

  if strcmp( blkMaskType, 'LookupNDInterpIdx' ),
    
    % --- Make plot data for the Interpolation n-D Using Prelookup block, 
    %     check table shape before proceeding
    %
    %     tableData    - table data 
    %     interp_or_bp - interpMethod

    doSelect = true;
    if isempty(tableData) || isempty(interp_or_bp) || ~isnumeric(tableData)
      
      % empty table data or non-numeric array
      errFlag = 1;
      
    else
      
      tableSize = size(tableData); % vector
      numDims = length(tableSize);
      tableLength = prod(tableSize); % length
      
      if tableLength > tableLengthThreshold,
        
        % --- The data is "big", 
        %     so plot a default icon
        
        if option == 1,
          
          % 1-D lookup table
          bpData = -5:5;
          value = default1Ddata; %this is tanh(bpData);
          
        else
          
          % >1-D lookup table
          bpData = 1:3;
          value  = [4 5 6;16 19 20;10 18 23];
          
        end
        
        switch interp_or_bp
         case 1
          action = 'flatplot';
         otherwise
          action = 'lineplot';
        end
        
      else
        
        % --- Have some actual values to plot, see if table data is OK
        
        if numDims == 2

          if ~( (option == 1 && (tableSize(1)==1 || tableSize(2)==1)) || option == 2 )
            
            % non-vector table for 1-D or 
            % matrix table for not 2-D lookup
            errFlag = 1;
            
          end
          
        elseif numDims ~= option
          
          errFlag = 1;
          
        end
        
        % --- Create some dummy X values since this block doesn't 
        %     have any breakpoints to go with the table data
        
        if errFlag == 0,
          
          switch interp_or_bp
           case 1
            action = 'flatplot';
           otherwise
            action = 'lineplot';
            dims = size(tableData);
            if option == 1,
              bpData = 1:tableLength;
              value  = double(tableData);
            elseif option == 2,
              % only need the 1st breakpoint set
              bpData = 1:dims(1);
              value  = double(tableData);
            elseif option == 3,
              % only need the 1st breakpoint set and
              % first 2-D table subset to plot
              bpData = 1:dims(1);
              value  = double(tableData(:,:,1));
            end
          end % switch get_param(blk,'interpMethod')
          
        end % if errFlag == 0,
        
      end % if tableLength > tableLengthThreshold,
      
    end % isempty(varargin{1}) | ~isnumeric(varargin{1})
    
  elseif strcmp( blkMaskType, 'LookupNDInterp' ),
    
    % --- Make plot data for the n-D Lookup block, 
    %     check table shape before proceeding
    
    % tableData    - table data
    % interp_or_bp - first breakpoints    
    
    if isempty(interp_or_bp) || ~isnumeric(interp_or_bp)
      
      % empty breakpoint data
      errFlag = 1;

    elseif isempty(tableData) || ~isnumeric(tableData)
      
      % empty table data
      errFlag = 1;
      
    else
      
      [bpR, bpC] = size(interp_or_bp);
      length_bp = (bpR * bpC);
      
      if (bpR > 1) && (bpC > 1)
        
        % break points are not vector
        errFlag = 1;

      else

        tableSize = size(tableData); % vector
        numDims = length(tableSize);   % number
       
        tableLength = prod(tableSize); % length
        
        if tableLength > tableLengthThreshold,
          
          % --- The data is "big", 
          %     so plot the default icon
          
          if option == 1,
            bpData = -5:5;
            value  = default1Ddata; % this is tanh(bpData);
          else
            bpData = 1:3;
            value  = [4 5 6;16 19 20;10 18 23];
          end
        
        else
          
          % --- Have some data to convert for plotting
          
          if numDims == 2,
            
            if option == 1 && (tableSize(1)==1 || tableSize(2)==1)

              % 1-D lookup table
              if length_bp ~= tableSize(1) && ...
                 length_bp ~= tableSize(2)
            
                % inconsistent size of breakpoints and table data
                errFlag = 1;
                
              end
              
            elseif option == 2

              % 2-D lookup table
              if length_bp ~= tableSize(1)
            
                % inconsistent size of breakpoints and table data
                errFlag = 1;

              end
              
            else
              
              errFlag = 1;

            end
            
          else
            
            % >2-D lookup table
            if numDims ~= option || length_bp ~= tableSize(1)
              
              % inconsistent size of breakpoints and table data
              errFlag = 1;
              
            end
              
          end
          
          % --- If all is well, extract some numbers for making
          %     plot coordinates
          
          if errFlag == 0 && strcmp(action,'lineplot'),
            if option < 3,
              bpData = double(interp_or_bp);
              value = double(tableData);
            elseif option == 3,
              bpData = double(interp_or_bp);
              value = double(tableData(:,:,1));
            end
          end
          
        end % if length(varargin{2}) == 1,
        
      end %if (bpR > 1) & (bpC > 1)
      
    end % if interp_or_bp
    
  end % if blkMaskType == <lookup icon plot>
  
end % if (nargin == 0),



% if table given doesn't match dimensions specified, 
% draw a question mark and return immediately

if errFlag == 1
  x = 0.1 * [ 3.5 4 5 6 5 4 4 NaN 4 3.5 4 4.5 4 ];
  y = 0.1 * [ 6.5 7 7 6 5 5 4 NaN 3 2.5 2 2.5 3 ];
  xaxes = [ 0.05 0.05 0.9 ];
  yaxes = [ 0.8  0.05 0.05 ];
  return;
end


%
% =============================================================================
%
% Handle each type of action request
%
% The final opertion performed depends on the ACTION and OPTION variables
%

switch (action)
 case 'flatplot'
  Xoff   = 0.05;
  Xscale = 0.85;
  Yoff   = (-0.05);
  Yscale = 0.75;

  x_flatplot = [0.1000  0.1125  0.1000  0.0875  0.1000  0.1125  0.1000 ...
       0.2625  0.2625  0.2750  0.2625  0.2500  0.2625  0.2750 ...
       0.2625  0.4250  0.4250  0.4375  0.4250  0.4125  0.4250 ...
       0.4375  0.4250  0.6125  0.6125  0.6250  0.6125  0.6000 ...
       0.6125  0.6250  0.6125  0.7750  0.7750  0.7875  0.7750 ...
       0.7625  0.7750  0.7875  0.7750  0.8875  0.8875  0.9000 ...
       0.8875  0.8750  0.8875  0.9000  0.8875  0.9500  0.9500 ...
       0.9625  0.9500  0.9375  0.9500  0.9625  0.9500 ];
  y_flatplot = [0.2500  0.2500  0.2625  0.2500  0.2375  0.2500  0.2500 ...
       0.2500  0.4375  0.4375  0.4500  0.4375  0.4250  0.4375 ...
       0.4375  0.4375  0.5125  0.5125  0.5250  0.5125  0.5000 ...
       0.5125  0.5125  0.5125  0.4250  0.4250  0.4375  0.4250 ...
       0.4125  0.4250  0.4250  0.4250  0.7375  0.7375  0.7500 ...
       0.7375  0.7250  0.7375  0.7375  0.7375  0.9500  0.9500 ...
       0.9625  0.9500  0.9375  0.9500  0.9500  0.9500  0.6500 ...
       0.6500  0.6625  0.6500  0.6375  0.6500  0.6500 ];
  x = x_flatplot * Xscale + Xoff;
  y = y_flatplot * Yscale + Yoff;
  
 case 'lineplot'
  
  Xoff   = 0.05;
  Xscale = 0.85;
  Yoff   = 0.05;
  Yscale = 0.70;
  
  switch (option)
   case 1
    
    % 1-D table
    
    [nr,nc] = size(value);
    minx = bpData(1);
    maxx = bpData(length(bpData));
    den = (maxx - minx);
    if den == 0,
      den = 1;
    end
    
    x = Xoff + Xscale*(bpData-minx)/den;
    x = reshape(x,length(x),1);
    
    if nr > 1 && nc > 1
      % Never hit here
      x = [0.33 0.66 NaN 0.33 0.66];
      y = [0.33 0.66 NaN 0.66 0.33];
      
    else
      minv = min(value);
      maxv = max(value);
      den  = maxv - minv;
      if den == 0,
        if maxv == 0,
          den  = 1;
          minv = (-0.5);
        else
          den = 2*maxv;
          minv = 0;
        end
      end
      
      y = Yoff + Yscale*(value-minv)/den;
      y = reshape(y,length(y),1);
    end
    
   case 2
    
    % 2-D table
    
    [nr,nc] = size(value);
    
    minx = bpData(1);
    maxx = bpData(nr);
    den  = maxx - minx;
    if den == 0,
      if maxx == 0,
        den  = 1.0;
        minx = (-0.5);
      else
        den  = 2*maxx;
        minx = 0;
      end
    end
    
    x = Xoff + Xscale*(bpData(1:nr) - minx)/den;
    x = reshape(x,length(x),1);

    % x = repmat(x,1,nc) is implemented be the following
    % code for better performance
    x_rep = x; 
    for i = 1 : nc-1
      x = [x, x_rep];
    end
    
    minv = min(min(value));
    maxv = max(max(value));
    den  = maxv - minv;
    if den == 0,
      if maxv == 0,
        den  = 1;
        minv = (-0.5);
      else
        den = 2*maxv;
        minv = 0;
      end
    end
    
    y = Yoff + Yscale*(value-minv)/den;
    
   case 3
    
    % 3-D table
    
    dims = size(value);
    
    minx = bpData(1);
    maxx = bpData(dims(1));
    den = (maxx - minx);
    if den == 0,
      den = 1;
    end
    
    x  = Xoff + Xscale*(bpData(1:dims(1)) - minx)/den;
    x = reshape(x,length(x),1);
    x = repmat(x,1,dims(2));
    
    v    = value(:,:,1);
    minv = min(min(v));
    maxv = max(max(v));
    den  = maxv - minv;
    if den == 0,
      if maxv == 0,
        den  = 1;
        minv = (-0.5);
      else
        den = 2*maxv;
        minv = 0;
      end
    end
    
    y  = Yoff + Yscale*(v-minv)/den;
    
   otherwise
    
    % 4-D table or higher
    
    x_other = [0.8000  0.8222  0.7222  0.9556  0.9000  0.7889  0.6778 ...
         0.5556  0.4444  0.3111  0.2333  0.2000  0.2222  0.2889 ...
         0.3556  0.4000  0.4889  0.3444  0.2778  0.2444  0.1333 ...
         0.0889  0.0556  0.0222  0.0333  0.0889  0.2667  0.3111 ...
         0.3667  0.4778  0.4444  0.3111  0.1333  0.0556  0.1000 ...
         0.2333  0.3556  0.4667  0.5556  0.5778  0.7556  0.6778 ...
         0.6000  0.5333  0.4000  0.2556  0.1333  0.2000  0.1556 ...
         0.1333  0.1000  0.0556  0.0222  0.0556  0.1444  0.2000 ...
         0.2444  0.2667  0.3667  0.4778  0.5778  0.7111  0.9000 ...
         0.8000  0.6556  0.4889  0.3444  0.2000 ];
    x = x_other * Xscale + Xoff;
    y_other = [0.7375  0.6625  0.6750  0.6500  0.9500  0.7375  0.7125 ...
         0.7125  0.7125  0.7375  0.7250  0.6250  0.6000  0.6000 ...
         0.6000  0.5625  0.5125  0.4375  0.4750  0.5125  0.5000 ...
         0.5000  0.5000  0.4375  0.4125  0.5000  0.6375  0.7375 ...
         0.8000  0.8250  0.7125  0.6125  0.5000  0.3875  0.3625 ...
         0.5000  0.6000  0.6625  0.7250  0.8750  0.9125  0.7250 ...
         0.6625  0.6125  0.5625  0.4625  0.3750  0.2500  0.3375 ...
         0.3750  0.3625  0.3875  0.4375  0.5000  0.5625  0.6250 ...
         0.7375  0.8000  0.8000  0.8250  0.8750  0.9000  0.9500 ...
         0.7375  0.6125  0.5125  0.4375  0.2500 ];
    y = y_other * Yscale + Yoff;
  end
  
 case 'splineplot'
  
  Xoff   = 0.15;
  Xscale = 0.75;
  Yoff   = (-0.15);
  Yscale = 0.85;
  
  switch option
    
   case 1
    
    % 1-D table -- show standard spline curve
    
    x_splineplot1 = [0.1000  0.1125  0.1000  0.0875  0.1000  0.1125  0.1000 ...
         0.1000  0.1125  0.1250  0.1375  0.1500  0.1625  0.1750 ...
         0.1875  0.2000  0.2125  0.2250  0.2375  0.2500  0.2625 ...
         0.2625  0.2750  0.2625  0.2500  0.2625  0.2750  0.2625 ...
         0.2625  0.2750  0.2875  0.3000  0.3125  0.3250  0.3375 ...
         0.3500  0.3625  0.3750  0.3875  0.4000  0.4125  0.4250 ...
         0.4250  0.4375  0.4250  0.4125  0.4250  0.4375  0.4250 ...
         0.4250  0.4375  0.4500  0.4625  0.4750  0.4875  0.5000 ...
         0.5125  0.5250  0.5375  0.5500  0.5625  0.5750  0.5875 ...
         0.6000  0.6125  0.6125  0.6250  0.6125  0.6000  0.6125 ...
         0.6250  0.6125  0.6125  0.6250  0.6375  0.6500  0.6625 ...
         0.6750  0.6875  0.7000  0.7125  0.7250  0.7375  0.7500 ...
         0.7625  0.7750  0.7750  0.7875  0.7750  0.7625  0.7750 ...
         0.7875  0.7750  0.7750  0.7875  0.8000  0.8125  0.8250 ...
         0.8375  0.8500  0.8625  0.8750  0.8875  0.8875  0.9000 ...
         0.8875  0.8750  0.8875  0.9000  0.8875  0.8875  0.9000 ...
         0.9125  0.9250  0.9375  0.9500  0.9500  0.9625  0.9500 ...
         0.9375  0.9500  0.9625  0.9500 ];
    y_splineplot1 = [0.2500  0.2500  0.2625  0.2500  0.2375  0.2500  0.2500 ...
         0.2500  0.2634  0.2773  0.2917  0.3064  0.3214  0.3365 ...
         0.3516  0.3667  0.3816  0.3962  0.4105  0.4243  0.4375 ...
         0.4375  0.4375  0.4500  0.4375  0.4250  0.4375  0.4375 ...
         0.4375  0.4501  0.4619  0.4728  0.4828  0.4917  0.4994 ...
         0.5059  0.5110  0.5146  0.5167  0.5171  0.5157  0.5125 ...
         0.5125  0.5125  0.5250  0.5125  0.5000  0.5125  0.5125 ...
         0.5125  0.5074  0.5006  0.4926  0.4837  0.4742  0.4645 ...
         0.4549  0.4458  0.4375  0.4304  0.4249  0.4212  0.4198 ...
         0.4209  0.4250  0.4250  0.4250  0.4375  0.4250  0.4125 ...
         0.4250  0.4250  0.4250  0.4323  0.4428  0.4563  0.4728 ...
         0.4922  0.5143  0.5391  0.5664  0.5962  0.6283  0.6626 ...
         0.6991  0.7375  0.7375  0.7375  0.7500  0.7375  0.7250 ...
         0.7375  0.7375  0.7375  0.7776  0.8177  0.8562  0.8912 ...
         0.9208  0.9433  0.9569  0.9597  0.9500  0.9500  0.9500 ...
         0.9625  0.9500  0.9375  0.9500  0.9500  0.9500  0.9259 ...
         0.8857  0.8275  0.7495  0.6500  0.6500  0.6500  0.6625 ...
         0.6500  0.6375  0.6500  0.6500 ];
    
    x = x_splineplot1 * Xscale + Xoff;
    y = y_splineplot1 * Yscale + Yoff;
    
   otherwise
    
    % 2-D table or higher -- show a bicubic surface
    
    x_splineplot = [0.0668  0.0753  0.0925  0.1096  0.1781  0.2123  0.2171 ...
         0.2218  0.2263  0.2308  0.2352  0.2396  0.2438  0.2479 ...
         0.2521  0.2562  0.2600  0.2640  0.2677  0.2714  0.2751 ...
         0.2786  0.2821  0.2855  0.2922  0.2985  0.3047  0.3105 ...
         0.3160  0.3215  0.3266  0.3315  0.3362  0.3407  0.3449 ...
         0.3490  0.3529  0.3567  0.3603  0.3668  0.3729  0.3785 ...
         0.3836  0.3873  0.3910  0.3948  0.3986  0.4005  0.4026 ...
         0.4045  0.4066  0.4085  0.4105  0.4127  0.4148  0.4168 ...
         0.4190  0.4212  0.4234  0.4256  0.4278  0.4301  0.4325 ...
         0.4371  0.4419  0.4470  0.4521  0.4559  0.4600  0.4644 ...
         0.4690  0.4740  0.4790  0.4844  0.4897  0.4955  0.5012 ...
         0.5071  0.5130  0.5192  0.5252  0.5314  0.5377  0.5438 ...
         0.5500  0.5560  0.5622  0.5681  0.5741  0.5799  0.5855 ...
         0.5910  0.5963  0.6014  0.6063  0.6110  0.6153  0.6195 ...
         0.6233  0.6270  0.6304  0.6338  0.6371  0.6403  0.6433 ...
         0.6462  0.6490  0.6518  0.6544  0.6568  0.6593  0.6616 ...
         0.6640  0.6662  0.6684  0.6704  0.6725  0.6745  0.6764 ...
         0.6784  0.6803  0.6821  0.6840  0.6858  0.6875  0.6893 ...
         0.6911  0.6929  0.6947  0.6964  0.6982  0.7001  0.7019 ...
         0.7038  0.7058  0.7078  0.7097  0.7118  0.7140  0.7162 ...
         0.7184  0.7207  0.7230  0.7256  0.7281  0.7308  0.7336 ...
         0.7363  0.7393  0.7423  0.7455  0.7489  0.7523  0.7558 ...
         0.7595  0.7633  0.7673  0.7715  0.7758  0.7801  0.7848 ...
         0.7896  0.7945  0.7992  0.8037  0.8082  0.8126  0.8170 ...
         0.8214  0.8255  0.8297  0.8338  0.8379  0.8421  0.8460 ...
         0.8501  0.8541  0.8581  0.8622  0.8662  0.8701  0.8742 ...
         0.8784  0.8804  0.8825  0.8845  0.8866  0.8886  0.8908 ...
         0.8929  0.8951  0.8971  0.8993  0.9015  0.9037  0.9059 ...
         0.9081  0.9103  0.9126  0.9149  0.9171  0.9195  0.9219 ...
         0.9242  0.9266  0.9290  0.9315     NaN  0.1781  0.1819 ...
         0.1858  0.1896  0.1932  0.1968  0.2004  0.2038  0.2073 ...
         0.2138  0.2201  0.2263  0.2322  0.2378  0.2432  0.2484 ...
         0.2533  0.2579  0.2625  0.2667  0.2708  0.2748  0.2785 ...
         0.2821  0.2855  0.2918  0.2974  0.3026  0.3071  0.3114 ...
         0.3151  0.3178  0.3203  0.3225  0.3242  0.3251  0.3259 ...
         0.3267  0.3275  0.3282  0.3289  0.3297  0.3304  0.3312 ...
         0.3319  0.3327  0.3336  0.3345  0.3355  0.3364  0.3375 ...
         0.3399  0.3426  0.3458  0.3493  0.3527  0.3567  0.3608 ...
         0.3653  0.3701  0.3751  0.3804  0.3859  0.3915  0.3974 ...
         0.4034  0.4095  0.4158  0.4219  0.4284  0.4347  0.4410 ...
         0.4473  0.4536  0.4599  0.4659  0.4719  0.4778  0.4836 ...
         0.4890  0.4944  0.4995  0.5042  0.5088  0.5130  0.5170 ...
         0.5205  0.5252  0.5295  0.5336  0.5374  0.5410  0.5426 ...
         0.5442  0.5459  0.5475  0.5490  0.5505  0.5521  0.5536 ...
         0.5551  0.5564  0.5579  0.5593  0.5607  0.5622  0.5636 ...
         0.5649  0.5664  0.5678  0.5693  0.5708  0.5723  0.5738 ...
         0.5753  0.5770  0.5785  0.5803  0.5819  0.5837  0.5855 ...
         0.5874  0.5893  0.5912  0.5933  0.5953  0.5975  0.5999 ...
         0.6022  0.6047  0.6097  0.6152  0.6211  0.6274  0.6341 ...
         0.6378  0.6414  0.6452  0.6492  0.6533  0.6575  0.6621 ...
         0.6663  0.6707     NaN  0.1096  0.1152  0.1205  0.1258 ...
         0.1307  0.1355  0.1401  0.1445  0.1488  0.1529  0.1568 ...
         0.1607  0.1642  0.1711  0.1774  0.1832  0.1885  0.1933 ...
         0.1978  0.2019  0.2056  0.2123  0.2170  0.2216  0.2262 ...
         0.2305  0.2327  0.2349  0.2371  0.2392  0.2414  0.2434 ...
         0.2456  0.2477  0.2497  0.2518  0.2540  0.2560  0.2581 ...
         0.2601  0.2622  0.2642  0.2684  0.2725  0.2767  0.2808 ...
         0.2863  0.2929  0.2964  0.3001  0.3041  0.3082  0.3126 ...
         0.3170  0.3215  0.3260  0.3307  0.3355  0.3401  0.3449 ...
         0.3497  0.3545  0.3592  0.3638  0.3685  0.3730  0.3774 ...
         0.3816  0.3859  0.3899  0.3936  0.3971  0.4037  0.4093 ...
         0.4155  0.4185  0.4214  0.4241  0.4268  0.4295  0.4321 ...
         0.4347  0.4373  0.4399  0.4425  0.4452  0.4478  0.4507 ...
         0.4534  0.4564  0.4595  0.4626  0.4659  0.4693  0.4729 ...
         0.4766  0.4805  0.4847  0.4890  0.4937  0.4985  0.5036 ...
         0.5089  0.5147  0.5205  0.5274     NaN  0.0925  0.0970 ...
         0.1014  0.1056  0.1097  0.1137  0.1175  0.1212  0.1247 ...
         0.1314  0.1375  0.1432  0.1484  0.1532  0.1577  0.1618 ...
         0.1655  0.1722  0.1781  0.1841  0.1868  0.1897  0.1925 ...
         0.1951  0.1977  0.2003  0.2029  0.2053  0.2079  0.2104 ...
         0.2130  0.2156  0.2208  0.2273  0.2308  0.2347  0.2388 ...
         0.2432  0.2475  0.2523  0.2571  0.2621  0.2671  0.2723 ...
         0.2775  0.2829  0.2882  0.2936  0.2990  0.3044  0.3097 ...
         0.3149  0.3201  0.3252  0.3301  0.3351  0.3397  0.3442 ...
         0.3485  0.3526  0.3564  0.3600  0.3664  0.3730  0.3760 ...
         0.3790  0.3821  0.3849  0.3878  0.3907  0.3934  0.3962 ...
         0.3990  0.4018  0.4047  0.4075  0.4104  0.4133  0.4164 ...
         0.4195  0.4227  0.4260  0.4295  0.4329  0.4366  0.4404 ...
         0.4444  0.4486  0.4529  0.4574  0.4622  0.4671  0.4723 ...
         0.4778  0.4844     NaN  0.0753  0.0795  0.0834  0.0871 ...
         0.0908  0.0944  0.0978  0.1042  0.1101  0.1158  0.1208 ...
         0.1255  0.1299  0.1338  0.1375  0.1410  0.1471  0.1523 ...
         0.1574  0.1629  0.1685  0.1744  0.1800  0.1855  0.1907 ...
         0.1952  0.2005  0.2068  0.2101  0.2138  0.2175  0.2214 ...
         0.2253  0.2295  0.2336  0.2378  0.2422  0.2464  0.2508 ...
         0.2552  0.2597  0.2641  0.2684  0.2727  0.2770  0.2811 ...
         0.2852  0.2892  0.2930  0.2967  0.3003  0.3036  0.3097 ...
         0.3151  0.3204  0.3256  0.3307  0.3332  0.3356  0.3379 ...
         0.3404  0.3429  0.3453  0.3478  0.3503  0.3527  0.3553 ...
         0.3581  0.3607  0.3634  0.3663  0.3692  0.3722  0.3753 ...
         0.3786  0.3853  0.3890  0.3927  0.3966  0.4007  0.4049 ...
         0.4093  0.4152     NaN  0.0668  0.0704  0.0740  0.0807 ...
         0.0868  0.0926  0.0979  0.1029  0.1074  0.1115  0.1153 ...
         0.1189  0.1252  0.1305  0.1353  0.1389  0.1432  0.1478 ...
         0.1526  0.1574  0.1621  0.1662  0.1696  0.1747  0.1804 ...
         0.1870  0.1904  0.1940  0.1977  0.2015  0.2053  0.2093 ...
         0.2133  0.2173  0.2214  0.2255  0.2295  0.2336  0.2375 ...
         0.2415  0.2455  0.2493  0.2530  0.2567  0.2603  0.2637 ...
         0.2701  0.2759  0.2808  0.2856  0.2905  0.2959  0.3012 ...
         0.3070  0.3127  0.3186  0.3248  0.3310  0.3371  0.3434 ...
         0.3497  0.3562  0.3625  0.3688  0.3751  0.3785  0.3822 ...
         NaN  0.3836  0.3800  0.3764  0.3699  0.3637  0.3581 ...
         0.3527  0.3478  0.3433  0.3392  0.3353  0.3318  0.3253 ...
         0.3199  0.3151  0.3104  0.3049  0.2989  0.2925  0.2890 ...
         0.2855  0.2819  0.2784  0.2747  0.2710  0.2671  0.2634 ...
         0.2596  0.2559  0.2522  0.2485  0.2449  0.2414  0.2379 ...
         0.2345  0.2281  0.2222  0.2168  0.2123  0.2075  0.2026 ...
         0.2001  0.1977  0.1953  0.1930  0.1907  0.1885  0.1864 ...
         0.1845  0.1810  0.1781  0.1751  0.1734  0.1718  0.1699 ...
         0.1681  0.1662  0.1644  0.1625  0.1607  0.1590  0.1574 ...
         0.1559  0.1545  0.1523  0.1508  0.1490  0.1479  0.1468 ...
         0.1453  0.1447  0.1438     NaN  0.4521  0.4466  0.4412 ...
         0.4362  0.4311  0.4264  0.4218  0.4174  0.4132  0.4090 ...
         0.4052  0.4014  0.3978  0.3910  0.3847  0.3789  0.3736 ...
         0.3688  0.3642  0.3600  0.3562  0.3526  0.3493  0.3460 ...
         0.3425  0.3385  0.3342  0.3297  0.3251  0.3203  0.3155 ...
         0.3105  0.3058  0.3011  0.2964  0.2922  0.2881  0.2842 ...
         0.2808  0.2749  0.2715  0.2677  0.2638  0.2597  0.2555 ...
         0.2511  0.2468  0.2426  0.2384  0.2344  0.2305  0.2270 ...
         0.2208  0.2178  0.2152  0.2129  0.2110  0.2092  0.2074 ...
         0.2056  0.2038  0.2004  0.1953  0.1921  0.1881  0.1834 ...
         NaN  0.6233  0.6179  0.6129  0.6079  0.6032  0.5985 ...
         0.5941  0.5899  0.5858  0.5818  0.5779  0.5742  0.5707 ...
         0.5640  0.5577  0.5519  0.5464  0.5415  0.5367  0.5323 ...
         0.5282  0.5242  0.5205  0.5155  0.5099  0.5034  0.5001 ...
         0.4966  0.4930  0.4893  0.4855  0.4816  0.4777  0.4738 ...
         0.4697  0.4658  0.4618  0.4578  0.4538  0.4499  0.4459 ...
         0.4421  0.4382  0.4345  0.4310  0.4274  0.4208  0.4147 ...
         0.4093  0.4049  0.3997  0.3940  0.3878  0.3818  0.3759 ...
         0.3707  0.3664  0.3611  0.3548  0.3512  0.3477  0.3440 ...
         0.3404  0.3367  0.3330  0.3296  0.3262  0.3200  0.3151 ...
         0.3099  0.3067  0.3030  0.2986  0.2936  0.2877  0.2844 ...
         0.2808     NaN  0.7945  0.7908  0.7873  0.7837  0.7801 ...
         0.7733  0.7667  0.7604  0.7544  0.7485  0.7429  0.7374 ...
         0.7322  0.7273  0.7225  0.7178  0.7133  0.7090  0.7049 ...
         0.7011  0.6973  0.6937  0.6901  0.6836  0.6775  0.6721 ...
         0.6668  0.6621  0.6575  0.6511  0.6475  0.6438  0.6399 ...
         0.6358  0.6315  0.6271  0.6226  0.6181  0.6133  0.6085 ...
         0.6037  0.5988  0.5938  0.5889  0.5840  0.5790  0.5741 ...
         0.5693  0.5645  0.5599  0.5552  0.5507  0.5463  0.5422 ...
         0.5381  0.5341  0.5304  0.5268  0.5205  0.5163  0.5111 ...
         0.5053  0.4992  0.4930  0.4871  0.4819  0.4778  0.4710 ...
         0.4668  0.4626  0.4579  0.4532  0.4484  0.4433  0.4384 ...
         0.4336  0.4288  0.4242  0.4199  0.4159  0.4093  0.4040 ...
         0.4008  0.3971  0.3927  0.3877  0.3818  0.3751     NaN ...
         0.9315  0.9278  0.9242  0.9207  0.9171  0.9104  0.9038 ...
         0.8975  0.8915  0.8856  0.8800  0.8747  0.8695  0.8644 ...
         0.8596  0.8551  0.8505  0.8463  0.8422  0.8382  0.8345 ...
         0.8308  0.8274  0.8208  0.8148  0.8092  0.8040  0.7990 ...
         0.7945  0.7878  0.7841  0.7801  0.7760  0.7716  0.7671 ...
         0.7625  0.7577  0.7527  0.7478  0.7426  0.7375  0.7323 ...
         0.7270  0.7218  0.7164  0.7112  0.7060  0.7008  0.6958 ];
    y_splineplot = [0.6645  0.6316  0.5658  0.5000  0.4013  0.3355  0.3388 ...
         0.3421  0.3453  0.3484  0.3516  0.3546  0.3576  0.3605 ...
         0.3634  0.3663  0.3691  0.3718  0.3746  0.3772  0.3799 ...
         0.3824  0.3849  0.3874  0.3922  0.3968  0.4013  0.4057 ...
         0.4099  0.4139  0.4179  0.4217  0.4253  0.4288  0.4324 ...
         0.4357  0.4388  0.4420  0.4451  0.4509  0.4566  0.4620 ...
         0.4671  0.4714  0.4764  0.4822  0.4887  0.4920  0.4955 ...
         0.4991  0.5026  0.5063  0.5100  0.5137  0.5175  0.5212 ...
         0.5249  0.5286  0.5321  0.5357  0.5391  0.5425  0.5458 ...
         0.5518  0.5572  0.5620  0.5658  0.5680  0.5700  0.5717 ...
         0.5733  0.5746  0.5758  0.5768  0.5776  0.5784  0.5791 ...
         0.5796  0.5800  0.5804  0.5807  0.5811  0.5813  0.5817 ...
         0.5820  0.5824  0.5828  0.5833  0.5839  0.5846  0.5855 ...
         0.5864  0.5876  0.5889  0.5904  0.5921  0.5941  0.5962 ...
         0.5987  0.6014  0.6043  0.6076  0.6111  0.6147  0.6187 ...
         0.6228  0.6270  0.6314  0.6362  0.6409  0.6459  0.6511 ...
         0.6563  0.6617  0.6672  0.6728  0.6786  0.6843  0.6903 ...
         0.6962  0.7022  0.7084  0.7145  0.7207  0.7270  0.7332 ...
         0.7393  0.7457  0.7518  0.7582  0.7643  0.7705  0.7766 ...
         0.7826  0.7887  0.7946  0.8005  0.8062  0.8120  0.8175 ...
         0.8229  0.8283  0.8334  0.8384  0.8434  0.8480  0.8526 ...
         0.8570  0.8612  0.8651  0.8689  0.8725  0.8758  0.8789 ...
         0.8818  0.8843  0.8867  0.8888  0.8905  0.8921  0.8933 ...
         0.8942  0.8947  0.8950  0.8950  0.8946  0.8941  0.8932 ...
         0.8920  0.8905  0.8887  0.8866  0.8841  0.8812  0.8780 ...
         0.8746  0.8707  0.8664  0.8618  0.8568  0.8513  0.8455 ...
         0.8393  0.8361  0.8328  0.8292  0.8257  0.8220  0.8182 ...
         0.8143  0.8103  0.8062  0.8020  0.7976  0.7932  0.7886 ...
         0.7838  0.7789  0.7741  0.7691  0.7638  0.7586  0.7532 ...
         0.7476  0.7420  0.7362  0.7303     NaN  0.4013  0.4036 ...
         0.4058  0.4080  0.4101  0.4124  0.4143  0.4164  0.4186 ...
         0.4225  0.4263  0.4301  0.4337  0.4372  0.4407  0.4441 ...
         0.4472  0.4504  0.4536  0.4564  0.4595  0.4622  0.4651 ...
         0.4678  0.4705  0.4757  0.4808  0.4857  0.4905  0.4953 ...
         0.5000  0.5043  0.5095  0.5153  0.5214  0.5247  0.5280 ...
         0.5316  0.5350  0.5386  0.5422  0.5458  0.5495  0.5530 ...
         0.5567  0.5603  0.5638  0.5674  0.5708  0.5741  0.5774 ...
         0.5836  0.5892  0.5943  0.5987  0.6020  0.6050  0.6079 ...
         0.6107  0.6132  0.6157  0.6179  0.6200  0.6221  0.6239 ...
         0.6258  0.6276  0.6293  0.6309  0.6325  0.6341  0.6357 ...
         0.6372  0.6388  0.6403  0.6418  0.6436  0.6453  0.6470 ...
         0.6488  0.6507  0.6526  0.6547  0.6570  0.6593  0.6618 ...
         0.6645  0.6687  0.6736  0.6789  0.6850  0.6914  0.6949 ...
         0.6984  0.7020  0.7058  0.7096  0.7134  0.7174  0.7214 ...
         0.7255  0.7297  0.7339  0.7382  0.7425  0.7467  0.7512 ...
         0.7555  0.7599  0.7643  0.7687  0.7732  0.7775  0.7818 ...
         0.7862  0.7905  0.7949  0.7991  0.8033  0.8075  0.8116 ...
         0.8157  0.8196  0.8236  0.8274  0.8311  0.8347  0.8383 ...
         0.8417  0.8451  0.8513  0.8571  0.8624  0.8670  0.8709 ...
         0.8726  0.8741  0.8755  0.8766  0.8775  0.8783  0.8788 ...
         0.8792  0.8793     NaN  0.5000  0.5012  0.5022  0.5034 ...
         0.5045  0.5055  0.5066  0.5076  0.5087  0.5097  0.5107 ...
         0.5117  0.5126  0.5146  0.5166  0.5184  0.5204  0.5224 ...
         0.5243  0.5264  0.5286  0.5329  0.5368  0.5417  0.5472 ...
         0.5534  0.5567  0.5601  0.5636  0.5671  0.5708  0.5745 ...
         0.5782  0.5818  0.5857  0.5893  0.5930  0.5967  0.6003 ...
         0.6038  0.6072  0.6105  0.6168  0.6225  0.6275  0.6316 ...
         0.6359  0.6401  0.6422  0.6442  0.6463  0.6484  0.6505 ...
         0.6525  0.6546  0.6566  0.6587  0.6607  0.6628  0.6647 ...
         0.6667  0.6688  0.6708  0.6728  0.6749  0.6768  0.6789 ...
         0.6809  0.6830  0.6850  0.6871  0.6891  0.6932  0.6974 ...
         0.7037  0.7074  0.7114  0.7158  0.7204  0.7254  0.7305 ...
         0.7358  0.7413  0.7470  0.7526  0.7586  0.7643  0.7703 ...
         0.7762  0.7820  0.7878  0.7936  0.7991  0.8045  0.8097 ...
         0.8147  0.8195  0.8239  0.8282  0.8321  0.8355  0.8387 ...
         0.8413  0.8437  0.8454  0.8468     NaN  0.5658  0.5661 ...
         0.5664  0.5667  0.5671  0.5674  0.5678  0.5680  0.5684 ...
         0.5692  0.5700  0.5709  0.5718  0.5728  0.5739  0.5750 ...
         0.5763  0.5791  0.5822  0.5872  0.5904  0.5939  0.5979 ...
         0.6021  0.6063  0.6108  0.6151  0.6195  0.6237  0.6276 ...
         0.6313  0.6346  0.6397  0.6441  0.6461  0.6480  0.6500 ...
         0.6518  0.6537  0.6555  0.6572  0.6589  0.6607  0.6624 ...
         0.6639  0.6657  0.6672  0.6688  0.6705  0.6721  0.6737 ...
         0.6754  0.6770  0.6787  0.6804  0.6821  0.6838  0.6857 ...
         0.6875  0.6893  0.6913  0.6933  0.6974  0.7032  0.7066 ...
         0.7103  0.7143  0.7187  0.7233  0.7280  0.7330  0.7382 ...
         0.7436  0.7489  0.7543  0.7600  0.7655  0.7711  0.7766 ...
         0.7821  0.7875  0.7928  0.7979  0.8029  0.8076  0.8121 ...
         0.8164  0.8205  0.8242  0.8275  0.8305  0.8332  0.8354 ...
         0.8371  0.8384     NaN  0.6316  0.6317  0.6317  0.6318 ...
         0.6320  0.6321  0.6322  0.6325  0.6328  0.6332  0.6336 ...
         0.6339  0.6345  0.6351  0.6357  0.6364  0.6379  0.6397 ...
         0.6424  0.6462  0.6508  0.6559  0.6609  0.6657  0.6697 ...
         0.6726  0.6753  0.6778  0.6789  0.6803  0.6814  0.6826 ...
         0.6838  0.6850  0.6862  0.6874  0.6886  0.6897  0.6909 ...
         0.6921  0.6933  0.6945  0.6957  0.6970  0.6982  0.6995 ...
         0.7008  0.7021  0.7034  0.7049  0.7063  0.7076  0.7107 ...
         0.7138  0.7182  0.7236  0.7300  0.7336  0.7372  0.7412 ...
         0.7451  0.7492  0.7534  0.7576  0.7620  0.7663  0.7707 ...
         0.7749  0.7791  0.7833  0.7874  0.7913  0.7951  0.7988 ...
         0.8022  0.8086  0.8113  0.8138  0.8161  0.8179  0.8195 ...
         0.8208  0.8216     NaN  0.6645  0.6647  0.6650  0.6655 ...
         0.6659  0.6664  0.6670  0.6674  0.6679  0.6683  0.6688 ...
         0.6693  0.6704  0.6714  0.6726  0.6739  0.6758  0.6782 ...
         0.6805  0.6832  0.6855  0.6876  0.6892  0.6912  0.6934 ...
         0.6957  0.6968  0.6982  0.6993  0.7007  0.7020  0.7033 ...
         0.7046  0.7059  0.7072  0.7086  0.7100  0.7113  0.7128 ...
         0.7141  0.7155  0.7168  0.7183  0.7196  0.7211  0.7224 ...
         0.7250  0.7276  0.7303  0.7333  0.7371  0.7416  0.7466 ...
         0.7520  0.7576  0.7636  0.7695  0.7754  0.7811  0.7863 ...
         0.7913  0.7957  0.7993  0.8022  0.8042  0.8049  0.8050 ...
         NaN  0.4671  0.4689  0.4707  0.4741  0.4771  0.4799 ...
         0.4825  0.4850  0.4871  0.4892  0.4911  0.4926  0.4957 ...
         0.4980  0.5000  0.5017  0.5034  0.5050  0.5067  0.5075 ...
         0.5084  0.5092  0.5101  0.5111  0.5120  0.5129  0.5138 ...
         0.5147  0.5157  0.5167  0.5178  0.5188  0.5199  0.5211 ...
         0.5222  0.5246  0.5272  0.5300  0.5329  0.5372  0.5428 ...
         0.5461  0.5495  0.5529  0.5566  0.5601  0.5638  0.5674 ...
         0.5708  0.5771  0.5822  0.5878  0.5911  0.5946  0.5984 ...
         0.6024  0.6064  0.6107  0.6149  0.6189  0.6230  0.6268 ...
         0.6305  0.6339  0.6397  0.6446  0.6512  0.6554  0.6603 ...
         0.6661  0.6692  0.6726     NaN  0.5658  0.5674  0.5691 ...
         0.5705  0.5721  0.5734  0.5749  0.5762  0.5775  0.5787 ...
         0.5800  0.5811  0.5822  0.5843  0.5863  0.5882  0.5900 ...
         0.5916  0.5932  0.5946  0.5961  0.5974  0.5987  0.6000 ...
         0.6017  0.6037  0.6058  0.6082  0.6105  0.6130  0.6157 ...
         0.6182  0.6207  0.6230  0.6251  0.6272  0.6289  0.6304 ...
         0.6316  0.6326  0.6330  0.6332  0.6333  0.6334  0.6334 ...
         0.6336  0.6337  0.6339  0.6343  0.6349  0.6357  0.6368 ...
         0.6397  0.6428  0.6466  0.6511  0.6559  0.6609  0.6655 ...
         0.6695  0.6726  0.6767  0.6818  0.6850  0.6886  0.6926 ...
         NaN  0.5987  0.6024  0.6061  0.6095  0.6128  0.6159 ...
         0.6189  0.6220  0.6247  0.6275  0.6300  0.6325  0.6349 ...
         0.6393  0.6434  0.6471  0.6504  0.6534  0.6562  0.6586 ...
         0.6608  0.6628  0.6645  0.6667  0.6689  0.6713  0.6725 ...
         0.6738  0.6750  0.6763  0.6775  0.6788  0.6800  0.6812 ...
         0.6825  0.6837  0.6849  0.6861  0.6871  0.6882  0.6892 ...
         0.6903  0.6912  0.6921  0.6930  0.6938  0.6953  0.6964 ...
         0.6974  0.6978  0.6978  0.6976  0.6974  0.6971  0.6970 ...
         0.6970  0.6974  0.6984  0.7001  0.7012  0.7022  0.7034 ...
         0.7046  0.7059  0.7071  0.7084  0.7096  0.7118  0.7138 ...
         0.7161  0.7175  0.7192  0.7213  0.7238  0.7268  0.7284 ...
         0.7303     NaN  0.8947  0.8943  0.8939  0.8936  0.8933 ...
         0.8925  0.8918  0.8912  0.8905  0.8899  0.8893  0.8887 ...
         0.8882  0.8876  0.8871  0.8866  0.8861  0.8855  0.8850 ...
         0.8846  0.8841  0.8837  0.8832  0.8824  0.8814  0.8807 ...
         0.8799  0.8791  0.8783  0.8771  0.8763  0.8755  0.8746 ...
         0.8737  0.8728  0.8717  0.8707  0.8695  0.8683  0.8671 ...
         0.8659  0.8647  0.8636  0.8622  0.8611  0.8597  0.8586 ...
         0.8572  0.8561  0.8549  0.8537  0.8526  0.8514  0.8505 ...
         0.8495  0.8486  0.8476  0.8468  0.8454  0.8445  0.8436 ...
         0.8424  0.8413  0.8401  0.8391  0.8380  0.8371  0.8357 ...
         0.8349  0.8339  0.8329  0.8320  0.8308  0.8297  0.8286 ...
         0.8274  0.8263  0.8251  0.8239  0.8229  0.8208  0.8187 ...
         0.8172  0.8155  0.8133  0.8108  0.8078  0.8042     NaN ...
         0.7303  0.7312  0.7321  0.7330  0.7338  0.7355  0.7372 ...
         0.7387  0.7403  0.7417  0.7432  0.7445  0.7457  0.7470 ...
         0.7482  0.7492  0.7503  0.7513  0.7524  0.7533  0.7542 ...
         0.7550  0.7559  0.7574  0.7588  0.7600  0.7612  0.7622 ...
         0.7632  0.7645  0.7651  0.7659  0.7666  0.7674  0.7682 ...
         0.7689  0.7697  0.7705  0.7713  0.7721  0.7730  0.7738 ...
         0.7746  0.7755  0.7763  0.7772  0.7780  0.7788  0.7796 ];
    
    x = x_splineplot * Xscale + Xoff;
    y = y_splineplot * Yscale + Yoff;
  end     
  
  
 case 'bpplotdata'
  
  switch option
   case 'f'
    x = [0.17,0.6,0.6,NaN,0.05,0.95,NaN,0.4,0.4,NaN, 0.2,0.4,NaN, ...
         0.55,0.6,0.65,NaN,0.6,0.8,NaN,0.35,0.4,0.35,NaN,0.65,0.6,0.65];
    y = [0.8,0.8,0.15,NaN,0.4,0.4,NaN,0.15,0.4,NaN, 0.25,0.25,NaN, ...
         0.47,0.4,0.47,NaN,0.25,0.25,NaN,0.3,0.25,0.2,NaN,0.3,0.25,0.2];
   case 'k'
    x = [0.17,0.6,0.6,NaN,0.05,0.95,NaN,0.55,0.6,0.65];
    y = [0.8,0.8,0.4,NaN,0.4,0.4,NaN,0.47,0.4,0.47];
  end
 case 'bppatchdata'
  
  xOffset = [ 0.2, 0.4, 0.72, 0.85 ];
  xScale = 0.05;
  yScale = 0.05;
  x  = [];
  y  = [];
  
  for i=1:4
    x = [ x, NaN, xOffset(i) + xScale * [-1, 0, 1,  0, -1] ];
    y = [ y, NaN, 0.4        + yScale * [ 0, 1, 0, -1,  0] ];
  end
  
 case 'kfdyn'
  
  % ===========================================================================
  %
  % Dynamic dialog for Interpolation, n-D using prelookup block
  %  
  MAX_ON_DIMS_POPUP = 4;
  
  maskVisibilities  = get_param(blk,'MaskVisibilities');
  
  numDimsPopupSelect = get_param(blk,'numDimsPopupSelect');
  if strcmp(numDimsPopupSelect, 'More...')
    numDims = MAX_ON_DIMS_POPUP+1;
  else
    numDims = sscanf(numDimsPopupSelect,'%f');
  end
  
  if numDims > MAX_ON_DIMS_POPUP
    % for the large-dimensions case
    maskVisibilities{2} = 'on';
  else
    % for 'normal' lookup dimension counts
    maskVisibilities{2} = 'off';
  end
  
  % equivalent of [maskVisibilities{1,3:6}] = deal('on');
  set_param(blk,'MaskVisibilities',maskVisibilities);
  
 case 'dynamic'
  
  % ===========================================================================
  %
  % Dynamic dialog for Look-Up Table, n-D block
  %
  MAX_ON_DIMS_POPUP = 4;  % up to this many dimensions via the popup
  numUserFields     = 13;
  
  %maskEnables = get_param(blk,'MaskEnables');
  maskVisibilities = get_param(blk,'MaskVisibilities');
  
  % Number of Dimensions determines what breakpoint
  % fields to display.
  
  numDimsPopupSelect = get_param(blk,'numDimsPopupSelect');
  %explicitNumDims = get_param(blk,'explicitNumDims');
  if strcmp(numDimsPopupSelect, 'More...')
    numDims = MAX_ON_DIMS_POPUP+1;
  else
    numDims = sscanf(numDimsPopupSelect,'%f');
  end
  
  if numDims > MAX_ON_DIMS_POPUP
    % for the large-dimensions case
    [maskVisibilities{2:MAX_ON_DIMS_POPUP+3}] = deal('on');
  elseif numDims == MAX_ON_DIMS_POPUP
    % for max 'normal' lookup dimension count
    [maskVisibilities{2:MAX_ON_DIMS_POPUP+1}] = deal('on');
    [maskVisibilities{MAX_ON_DIMS_POPUP+2:MAX_ON_DIMS_POPUP+3}] = deal('off');
  else
    % for 'normal' lookup dimension counts
    [maskVisibilities{2:numDims+1}] = deal('on');
    [maskVisibilities{numDims+2:MAX_ON_DIMS_POPUP+3}] = deal('off');
  end
  
  maskVisibilities{1} = 'on'; % always!
  [maskVisibilities{MAX_ON_DIMS_POPUP+4:numUserFields}] = deal('on'); % always!
  
  set_param(blk,'MaskVisibilities',maskVisibilities);
  
 case 'predyn'

  % ===========================================================================
  %
  % Dynamic dialog for prelookup index search block
  %
  maskVisibilities  = get_param(blk, 'MaskVisibilities');

  % Show index data type for 'Output only the index' ON case
  % trick: fast switching for 'on'/'off' since values track:
  maskVisibilities{5} = get_param(blk, 'outputFlag');

  set_param(blk, 'MaskVisibilities', maskVisibilities);
 
 otherwise
  % do nothing       
end


Xoff   = 0.05;
Xscale = 0.85;
Yoff   = 0.05;
Yscale = 0.75;

xaxes = [ Xoff, Xoff, Xoff+Xscale ];
yaxes = [ Yoff+Yscale, Yoff, Yoff ];



% ===========================================================================
%
% --- For LookupNDInterpIdx init, set the port labels and adjust the plot
%     when doing sub-table selection.

if doSelect,

  numDims = option;
  if nargin >= 6,
    NumSelectionDims = varargin{1};
  else
    NumSelectionDims = 0;
  end

  % --- Top (common) code for icon display
  
  newLine = sprintf('\n');
  pre60Params = (length(get_param(gcbh, 'Parameters')) == 54) && ...
                ~strcmp(get_param(gcbh, 'LinkStatus'), 'resolved');
  
  if strcmp(get_param(bdroot,'BlockDiagramType'),'library'),
    numDimsStr = 'n';
  else
    numDimsStr = sprintf('%d',numDims);
  end
  iconDimsStr = sprintf(' %s-D T(k,f)', numDimsStr);
  iconStr = ['text(0.5,0.9,''', iconDimsStr, ...
             ''',''horizontalAlignment'',''center'');', newLine];
  if ~pre60Params,
    % --- Don't try to draw the icon - it will fail for pre 6.0 models
    %     with broken library links
    iconStr = [ iconStr, 'plot(x,y);', newLine, 'plot(xaxes,yaxes);', newLine ];
  end
  
  if numDims >= 1 && NumSelectionDims > 0 && NumSelectionDims <= numDims,
    % --- Adjust the axes to fit the port labels
    rot = get_param(gcbh,'Orientation');
    switch rot,
     case 'right',
      xo = 0.25; xs = 0.80; yo = 0.05; ys = 1.0;
     case 'left',
      xo = 0.05; xs = 0.90; yo = 0.05; ys = 1.0;
     case 'up',
      xo = 0.05; xs = 1.00; yo = 0.15; ys = 0.9;
     case 'down',
      xo = 0.25; xs = 1.00; yo = 0.05; ys = 1.0;
    end
    
    x = xo + xs*(x-0.05);
    y = yo + ys*(y-0.05);
    xaxes = xo + xs*(xaxes-0.05);
    yaxes = yo + ys*(yaxes-0.05);
    
    % --- make and set the port labels into the icon display code
    numU = numDims - NumSelectionDims;
    labs = cell(numDims,1);
    for k=1:numU,         labs{k} = sprintf('port_label(''input'',%d,''u%d'');\n',k,k); end
    for k=numU+1:numDims, labs{k} = sprintf('port_label(''input'',%d,''sel%d'');\n',k,k-numU); end

    iconStr = [ iconStr, horzcat(labs{:}) ];
    
  end
  
  % --- Set the command string into the block's MaskDisplay parameter (v6 or later)
  set_param(gcbh, 'MaskDisplay', iconStr);
  
end


%[EOF] ndlookico.m

