function x = dac_glue(outputs, flag)
% dac_glue      input & output values for 
%               simulink block "DAC"

N = length(outputs);
M = 2*N;

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

% calculate table-lookup parameters for DAC

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