function model=CheckParamsAreValid(model)

% Check p is between 0 and 1
if ~isfield(model,'n')
   error('Need to specify n');
elseif ~isfield(model,'p')
   error('Need to specify p');
elseif ~isfield(model,'q')
   error('Need to specify q');
elseif ~isfield(model,'qsigma')
   disp('Quantal variance not specified; setting it to 0')
   model.qsigma=0;
elseif ~isfield(model,'QVtype')
   disp('Quantal variance type not specified; setting it to Type I')
   model.QVtype=1;
elseif ~isfield(model,'pstim')
   disp('Stimulation probability not specified: setting it to 1')
   model.pstim=1;
elseif (model.p<0)
   error('Release probability cannot be negative')
elseif (model.p>1)
   error('Release probability cannot exceed 1')
elseif (model.pstim<0)
   error('Stimulation probability cannot be negative')
elseif (model.pstim>1)
   error('Stimulation probability cannot exceed 1')
elseif (model.noise<0)
   model.noise=abs(model.noise);
elseif (model.q<0)
   model.q=abs(model.q);
elseif (model.qsigma<0)
   model.qsigma=abs(model.qsigma);
elseif model.QVtype~=1 & model.QVtype~=2
   error('QVtype must be 1 (for Type I) or 2 (for "flat")')
end
