calc_n_samples function

Count the number of samples