function ampl = setampl(preAmpl, nSim)

% SETAMPL - set the signal amplitude for makelist
%
% ampl = setampl(preAmpl, nSim)
%
% preAmpl   intermediate amplitude information from makelist
% nSim      number of amplitudes to determine and return
%
% ampl      determined amplitudes

% $Id: setampl.m,v 1.2 2004/05/10 20:26:14 stuver Exp $

% DETERMINE mode of preAmpl from input length
% IF amplitude if fixed
%   COPY preAmpl nSim times into ampl
% ELSEIF amplitude drawn from logarithmic distribution
%   DETERMINE range of distribution from preAmpl values
%   SET ampl to value from log distribution 
% ELSEIF amplitude drawn from discrete linear distribution
%   GENERATE linear distibution from values in preAmpl
%   SET ampl to value in linear distribution
% ENDIF

ampl = [];

% Find length of preAmpl to determine mode
amplMode = length(preAmpl);

% Set ampl based on preAmpl length
switch amplMode
    case 1 % The amplitude is fixed
        % can leave preAmpl alone
        ampl(1:nSim) = preAmpl;
    case 2 % logarithmic distributed inside range
        % Determine range
        lower = log10(preAmpl(1)); 
        upper = log10(preAmpl(2));
        % Check range for error
        if upper < lower
            error('makelist -> setampl: ampl(1) must be < ampl(2)')
        end
        range = upper-lower;
        % Set ampl to value from log distribution
        logampl = (rand(nSim,1)*range)+lower;
        ampl = 10.^logampl;
    case 3 % Pick ampl randomly from uniformly distributed values
        % Determine range
        lower = preAmpl(1);
        interval = preAmpl(2);
        upper = preAmpl(3);
        % Check range for error
        if upper < lower
            error('makelist -> setampl: ampl(1) must be < ampl(2)')
        end
        if interval <= 0
            error(['makelist -> setampl: The interval, ampl(2), ' ...
                    'must be > 0'])
        end
        % Generate discrete linear distribution
        temp = lower:interval:upper;
        tempLength = length(temp);        
        % Set ampl to value from distribution
        for g = 1:nSim
            ampl(g) = temp(fix(rand(1)*tempLength));
        end
    otherwise
        error(['makelist -> setampl: ampl must be a vector of length '...
                '1, 2 or 3'])
end

return