def readFile(fileLocation):
    global data
    global x
    global y
    global y_err
    global ERR
    global numberOfDataPoints
    if (fileLocation == ''):
        return 1
    if ((not fileLocation.endswith('.txt')) and (not fileLocation.endswith('.csv'))):
        return 2
    try:
        with open(fileLocation, 'r') as file:
            clean_lines = [' '.join(line.split()) for line in file]
            for delims in [(' ,', ','), (', ', ','), (' ', ',')]:
                clean_lines = [line.replace(*delims) for line in clean_lines]
            data = np.genfromtxt(clean_lines, delimiter=',', dtype='float_')
    except (TypeError, ValueError, AttributeError):
        return 3
    try:
        if ((not (len(data[0]) == 2)) and (not (len(data[0]) == 3))):
            return 4
    except TypeError:
        return 4
    if (np.any(np.isnan(data)) or np.any(np.isinf(data))):
        return 5
    if ((len(data[0]) == 3) and np.any((data[:, 2] <= 0))):
        return 6
    numberOfDataPoints = len(data)
    data = data[data[:, 0].argsort()]
    x = data[:, 0]
    y = data[:, 1]
    if (len(data[0]) == 2):
        y_err = np.array([1 for i in data])
        ERR = False
    elif (len(data[0]) == 3):
        y_err = data[:, 2]
        ERR = True
    return 0
def readFile(fileLocation):
    global data
    global x
    global y
    global y_err
    global ERR
    global numberOfDataPoints
    if (fileLocation == ):
        return 1
    if ((not fileLocation.endswith('.txt')) and (not fileLocation.endswith('.csv'))):
        return 2
    try:
        with open(fileLocation, 'r') as file:
            clean_lines = [' '.join(line.split()) for line in file]
            for delims in [(' ,', ','), (', ', ','), (' ', ',')]:
                clean_lines = [line.replace(*delims) for line in clean_lines]
            data = np.genfromtxt(clean_lines, delimiter=',', dtype='float_')
    except (TypeError, ValueError, AttributeError):
        return 3
    try:
        if ((not (len(data[0]) == 2)) and (not (len(data[0]) == 3))):
            return 4
    except TypeError:
        return 4
    if (np.any(np.isnan(data)) or np.any(np.isinf(data))):
        return 5
    if ((len(data[0]) == 3) and np.any((data[:, 2] <= 0))):
        return 6
    numberOfDataPoints = len(data)
    data = data[data[:, 0].argsort()]
    x = data[:, 0]
    y = data[:, 1]
    if (len(data[0]) == 2):
        y_err = np.array([1 for i in data])
        ERR = False
    elif (len(data[0]) == 3):
        y_err = data[:, 2]
        ERR = True
    return 0