function x = adc_glue(levels, flag)
% slADCinvals   input & output values for 
%               simulink block "ADC"

N = length(levels);
M = 2*N + 2;

% prevent strange interpolation behavior at 0 of 
% simulink table-lookup function
levels(levels==0) = realmin;

% calculate table-lookup parameters for ADC

if flag == 0
   % calculate inputs for table lookup
   x(M) =  realmax;
   x(1) = -realmax;
   x(2:2:M-2) = levels;
   x(3:2:M-1) = levels;
else
   % calculate outputs for table lookup
   x(2:2:M)   = 0:N;
   x(1:2:M-1) = 0:N;
end
