function y = fixpt_interp1(xdata,ydata,x,xdt,xscale,ydt,yscale,RndMeth)
%  FIXPT_INTERP1 fixed-point 1-D interpolation (table lookup).
%
%  Y = FIXPT_INTERP1(XDATA,YDATA,X,XDT,XSCALE,YDT,YSCALE,RNDMETH) 
%   implements a look up table.  The location of input x in the vector of xdata 
%   points is found.  If x is in the range determined by xdata, then the output
%   y is found by interpolating between the appropriate pair of ydata points.
%   If x is smaller than the first xdata point, then the output y is the first
%   ydata point.  If x is larger than the last xdata point, then the output
%   is the last ydata point.
%     If the input data type xdt is floating point or the output data type
%   ydt is floating point, then floating point calculation will be used.  
%   Otherwise, all calculations will be integer only calculations that properly
%   handle the inputs scaling xscale and the outputs scaling yscale.
%     Fixed point calculations will obey the specified rounding method RndMeth.
%
%   Inputs
%   XDATA    the breakpoints use by the lookup table approximation
%   YDATA    the output data points corresponding to the breakpoints
%   X        input values to be processed by lookup table
%   XDT      input datatype specified using Fixed-Point Designer conventions.  
%            For example, sfix(16), ufix(8), or float('single')
%   XSCALE   input scaling specified using Fixed-Point Designer conventions.  
%            For example, 2^-6 means 6 bits to the right of the binary point.
%   YDT      output datatype.
%   YSCALE   output scaling.
%   RNDMETH  rounding method.  'floor' (default), 'ceil', 'near', or 'zero'
%
%   Outputs
%   Y        output values corresponding to the input values X.
%
%   Examples: 
%
%   xdata = linspace(0,8,33).';
%   ydata = sin(xdata);
%   x = linspace(-1,9,201);
%   y = fixpt_interp1(xdata, ydata, x, ufix(8), 2^-8, sfix(16), 2^-14, 'Floor');
%
%   See also SFIX, UFIX, FIXPT_LOOK1_FUNC_APPROX, FIXPT_LOOK1_FUNC_PLOT

% Copyright 1994-2017 The MathWorks, Inc.



if nargin > 7
    RndMeth = convertStringsToChars(RndMeth);
end

if nargin < 8
    RndMeth = 'floor';
end

%
% set modes for saturation, doubles override, and interpolation method.
%
boolDoSatur = false;
dblOver = 0;
interpMethod=2;

%
% get data type and scaling vectors
%
OutTypeVec = getdatatypespecs(ydt,yscale,dblOver,0);
InTypeVec  = getdatatypespecs(xdt,xscale,dblOver,0);

%
% get the integer for the rounding method
%
ROUND_ZERO  = 0;
ROUND_NEAR  = 1;
ROUND_CEIL  = 2;
ROUND_FLOOR = 3;
%
switch lower(RndMeth(1)) 
case 'z'    
    iRndMeth = ROUND_ZERO;   
case 'n'    
    iRndMeth = ROUND_NEAR;   
case 'c'    
    iRndMeth = ROUND_CEIL;   
otherwise    
    iRndMeth = ROUND_FLOOR;   
end

SatRndVec = [boolDoSatur iRndMeth];

y = fixpt_interp1_private(xdata,ydata,x,OutTypeVec,InTypeVec,SatRndVec,dblOver,interpMethod);

% LocalWords:  XDT YDT YSCALE RNDMETH xdata ydata xdt ydt yscale Rnd Meth FUNC
