制作globk H文件列表

需求分析:

1、多个子网的单天H文件合。也就是同一天的H文件都排列到一起,并在文件地址 后面 加上一个符号 “+”,而在单天内最后一个文件不加该符号。

文件特征:

h1704051200_igs1.glx h1706291200_igs7.glx h1709211200_igs6.glx

h1704051200_igs2.glx h1706291200_igs8.glx h1709211200_igs7.glx

h1704051200_igs3.glx h1706301200_igs1.glx h1709211200_igs8.glx

h1704051200_igs4.glx h1706301200_igs2.glx h1709221200_igs1.glx

h1704051200_igs5.glx h1706301200_igs3.glx h1709221200_igs2.glx

h1704051200_igs6.glx h1706301200_igs4.glx h1709221200_igs3.glx

h1704051200_igs7.glx h1706301200_igs5.glx h1709221200_igs4.glx

h1704051200_igs8.glx h1706301200_igs6.glx h1709221200_igs5.glx

h1704061200_igs1.glx h1706301200_igs7.glx h1709221200_igs6.glx

h1704061200_igs2.glx h1706301200_igs8.glx h1709221200_igs7.glx

h1704061200_igs3.glx h1707011200_igs1.glx h1709221200_igs8.glx

如上所示,每个文件都是以.glx后缀结尾;第一个字符是h,然后是10位的日期,例如:1704051200,表示2017年4月5日12点0分,然后是一个下划线,然后是4个字符的子网代码。

最终效果:

h1704051200_igs1.glx +

h1704051200_igs4.glx +

h1704051200_igs5.glx

h1706291200_igs7.glx +

h1706291200_igs8.glx


python代码如下:


# -*- coding:utf-8 -*-  
""" 
coding by python 3.5 
功能:把GAMIT的二进制H文件,进行列表,用于glred平差处理 
输入:二进制H文件所在目录 
输出:以gdl结尾的文本文件 
二进制H文件样例:h1704051200_igs1.glx 
by: [email protected] 
create at 2017-10-5 
"""  
import glob  
import shutil  
import os  
import sys  
  
print('coding by [email protected]')  
print('2017-10-5\n')  
  
hFileFromCatalog = r"E:\ZZH\coding\gamit\example"  # H文件的目录  
outHfileAdress = hFileFromCatalog + os.sep + 'gamitHfiles.gdl'  
  
findFiles = hFileFromCatalog+os.sep+'h*.glx'  # 0级目录搜索  
  
getFileList = []  # 列表 h文件信息存储:文件详细地址 短文件名  10字符日期  
  
for hfile in glob.glob(findFiles):  
    shortFileName = os.path.basename(hfile).lower()  # h1704051200_igs1.glx  
    time10 = shortFileName[1:11].lower()  # 10字符日期 1704051200  
    oneFile = (hfile, shortFileName, time10)  # 元组  
    getFileList.append(oneFile)  
  
# 把H文件列表进行排序  
afterSortHfiles = sorted(getFileList,key=lambda timeHfile:timeHfile[2])  
  
allNumber = len(afterSortHfiles)  
# 单天内H文件合并,单天内除最后一个文件不加‘+’符号外,其余文件后均加符号‘+’  
outHfiles=[]  
for icout in range(0 , allNumber-1):  #最后一个永远都不加符号‘+’  
    sFileOne = afterSortHfiles[icout][2]   # afterSortHfiles[icout][0] + '  ' + '+'  
    sFileTwo=afterSortHfiles[icout+1][2]  
  
    if sFileOne == sFileTwo:  
        goFile = afterSortHfiles[icout][0] + '  ' + '+'  
    else:  
        goFile = afterSortHfiles[icout][0]  
  
    outHfiles.append(goFile)  
  
#添加最后一个不加符号的文件  
goFile = afterSortHfiles[allNumber-1][0]  
outHfiles.append(goFile)  
  
#把outHfiles列表写到文件中去。outHfileAdress  
fopen=open(outHfileAdress,'w')  
for i in outHfiles:  
    fopen.write(i)  
    fopen.write("\n")  
fopen.close()  
  
print("everything is ok!!!")  

你可能感兴趣的:(制作globk H文件列表)