gps的一些小程序(1)

今天老师让写的一个鬼东西,我也不知道干什么用。

# -*- coding: utf-8 -*-
"""
Created on Fri Aug  9 21:10:33 2019

@author: 1
"""
import numpy as np
def read_txt(txt_path,out_path):
    
    with open(txt_path,'r') as f:
        date=[]#日期
        N_all=[]#N
        N_Merror=[]#N中误差
        len_N=0
        
        E_all=[]#E
        E_Merror=[]#E中误差
        
        U_all=[]#U
        U_Merror=[]#U中误差
        
        #读取N数据
        for i in range(3):
            line=f.readline().rstrip()
            
        while True:
            line=f.readline()
            if line in ['\n','\r\n']:
                break
            line_split=line.split()
            
            year=line_split[0]
            month=line_split[1].rjust(3)
            day=line_split[2].rjust(3)
            
            date.append(year+month+day)
            N_all.append(float(line_split[5]))#读取N
            N_Merror.append('%.6f'% float(line_split[6]))#读取中误差,保存6位数
            len_N+=1       


        #读取E数据             
        for i in range(6):
            line=f.readline()
        for i in range(len_N):
            line=f.readline()
            line_split=line.split()
            
            E_all.append(float(line_split[5]))
            E_Merror.append('%.6f'% float(line_split[6]))
            
        #读取U数据
        for i in range(7):
            line=f.readline()
        for i in range(len_N):
            line=f.readline()
            line_split=line.split()
            
            U_all.append(float(line_split[5]))
            U_Merror.append('%.6f'% float(line_split[6]))
        f.close()
        print('数据读取完毕.........')
        print('计算N,E,U均值........')
        #计算N,E,U均值
        N_mean=0
        E_mean=0
        U_mean=0
        N_mean='%.6f'% np.mean(np.array(N_all))
        E_mean='%.6f'% np.mean(np.array(E_all))
        U_mean='%.6f'% np.mean(np.array(U_all))
        print('N_mean:',N_mean,'E_mean:',E_mean,'U_mean:',U_mean)
        print('正在写入文件.....')
        
    with open(out_path,'w+') as f1:
        for i in range(len_N):
            N_temp=0
            E_temp=0
            U_temp=0
            N_temp=str('%.6f'% (N_all[i]-float(N_mean)))
            E_temp=str('%.6f'% (E_all[i]-float(E_mean)))
            U_temp=str('%.6f'% (U_all[i]-float(U_mean)))
            write_temp=date[i]+N_temp.rjust(11)+E_temp.rjust(11)+U_temp.rjust(11)+N_Merror[i].rjust(11)+E_Merror[i].rjust(11)+U_Merror[i].rjust(11)+'\r'
            f1.write(write_temp)
        f1.close()
        print('成功写入文件.....')
        
          
if __name__=='__main__':
    print('请输入文件路径:    ps:C:\input.txt')
    in_path=input().replace('\\','/')
    print('请输入保存的路径:   ps:C:\output.neu')
    out_path=input().replace('\\','/')
    read_txt(in_path,out_path)

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值