function [gaus,observed,X,nbin] = gaussian(series);
% [gaus,observed,X,nbin] = gaussian(series);
error(nargchk(1,4,nargin))          % check number of input arguments 
% determine the gaussian parent distribution most consistent w/ 
% the histogram of y
nx=size(series,1);
amean = mean(series);
sderr = std(series);
% determine appropriate number of bins from Wilks (eq 3.12)
quant=quantiles(series);
IQR=quant(3)-quant(1);
w=IQR*(log(nx)/nx)^(1/3);
nbin = round((max(series)-min(series))/w)
[observed,X]=hist(series,nbin);
dx = X(2)-X(1);
factor=nx*dx/(sderr*sqrt(2.0*pi));
sum = 0.0;
for i=1:nbin
   aa = X(i)-amean;
   gaus(i) = factor*exp(-aa^2/(2.0*sderr^2));
end