import numpy as np


def read_data(filename):
    """Function to read data from text files. The program assumes columns"""

    data = np.genfromtxt(
        filename,
        delimiter="\t",  # Adjust delimiter as needed (e.g., ',' for CSV, '\t' for tab-delimited files)
        dtype=float,  # Ensure numeric type
        missing_values="nan",  # Treat the string as a missing value
        filling_values=np.nan,  # Replace missing values with np.nan
    )

    # Separate data into x and y values
    x_values = data[:, 0]  # for x [: takes all rows , of the 0th column]
    y_values = data[:, 1:]  # take all rows from the first and all following

    y_means = np.nanmean(y_values, axis=1)  # calculates the mean of the rows
    y_std = np.nanstd(y_values, 1, ddof=1)

    return x_values, y_means, y_std
