#!/usr/bin/awk -f 

# Data averaged is the first column of the numbers provided
# Gives average and error for uncorrelated data.
# Careful: Empty lines will give wrong result! How to go around that? 

{ 
  av += $1;    # the sum of data
  er += $1*$1;  # the sum of squares of data
}
END{

  #we assume NR is the number of data (wrong if empty lines)
  av /= NR;
  er /= NR;
  # formula for error of uncorrelated measurements
  er  = sqrt( (er - av*av)/(NR-1) ); 
  print av, "+/-", er;

}
#  ---------------------------------------------------------------------
#  Copyright by Konstantinos N. Anagnostopoulos (2004-2014)
#  Physics Dept., National Technical University,
#  konstant@mail.ntua.gr, www.physics.ntua.gr/~konstant
#  
#  This program is free software: you can redistribute it and/or modify
#  it under the terms of the GNU General Public License as published by
#  the Free Software Foundation, version 3 of the License.
#  
#  This program is distributed in the hope that it will be useful, but
#  WITHOUT ANY WARRANTY; without even the implied warranty of
#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
#  General Public License for more details.
#  
#  You should have received a copy of the GNU General Public Liense along
#  with this program.  If not, see <http://www.gnu.org/licenses/>.
#  -----------------------------------------------------------------------
