import numpy as np
import matplotlib.pyplot as plt


def read_data(dir_str):
    '''
    此函数读取txt文件中的数据
    数据内容：科学计数法保存的多行两列数据
    输入：txt文件的路径
    输出：小数格式的数组，行列与txt文件中相同
    '''
    data_temp=[]
    with open(dir_str) as fdata:
        while True:
            line=fdata.readline()
            if not line:
                break
            #data_temp.append([])
            #print(line)
            #print(i for i in line.split(" "))
            data_temp.append([float(i) for i in line.split(' ')])
    return np.array(data_temp)


data_array1 = read_data('Noforce/4200_no_force_training_noise0.01_test_noise0.01.txt')
data_array2 = read_data('Noforce/8000_no_force_training_no_noise_test_noise0.01.txt')
data_array3 = read_data('Withforce/8400_4direction_10Nor6N_8step-200step_continous_noise0.01_with_noise.txt')
data_array4 = read_data('Withforce/8700_4direction_10Nor6N_8step-200step_continous_test_add_noise0.01.txt')

length1 = data_array1.shape[0]
length2 = data_array2.shape[0]
length3 = data_array3.shape[0]
length4 = data_array4.shape[0]

err1 = max(abs(data_array1[:,0]))
print('Max Error is {}'.format(err1))

err2 = max(abs(data_array2[:,0]))
print('Max Error is {}'.format(err2))

err3 = max(abs(data_array3[:,0]))
print('Max Error is {}'.format(err3))

err4 = max(abs(data_array4[:,0]))
print('Max Error is {}'.format(err4))