#!/usr/local/env python#-*- coding:utf-8 -*-defgetcrd(crdfile):
D={}
coordlist=open(crdfile,'r')foreachlineincoordlist:
row=eachline.split()
D[row[0]]=row[1]+''+row[2]returnDdefgetlas(D, lasfile):
pathlist=lasfile.split('/')
wellname=lasfile[-1]
pathname='/'.join(pathlist[0:-1])
newpathname=pathname+"/crdlasfile"ifos.path.isdir(newpathname):
crdpath=newpathnameelse:
crdpath=os.mkdir(newpathname)ifwellnameinD.keys():
crd=D[wellname].split()
xcrd=crd[0]
ycrd=crd[1]
oldlasfile=open(lasfile,'r')
resultfilename=crdpath+'/'+wellname+'.las'newlasfile=open(resultfilename,'w')
i=0foralineinoldlasfile:
newlasfile.write(aline)ifaline[0:3]=="UWI":
newlasfile.write("XCRD."+xcrd+": \n")
newlasfile.write("YCRD."+ycrd+": \n")
oldlasfile.close()
newlasfile.close()else:
logname=crdpath+'/log.txt'log=open(logname,'a')
log.write(wellname+"isn't in well coordiante file\n")classTopApp:def__init__(self, root):#sone var for returnself.crdname=tkinter.StringVar()
self.lasname=tkinter.StringVar()#a frame for place widgetsself.frame=tkinter.Frame(root)#the programe name labelself.labeltitle=tkinter.Label(self.frame, text="Add coordinate to Las file", font="Arial -16 bold")
self.labeltitle.pack()#the first labelframe for selecting coordinate fileself.labelcrd=tkinter.LabelFrame(self.frame, text="Select coordinates file:", labelanchor='nw', relief='groove', bd=2)
self.labelcrd.pack(anchor='w', ipadx=2, ipady=2, padx=2, pady=2)
self.entry=tkinter.Entry(self.labelcrd, bd=2, width=50, textvariable=self.crdname)
self.entry.pack(anchor='w', padx=2, pady=5)
self.buttoncrd=tkinter.Button(self.labelcrd, bd=2, text='Select...', width=10, command=self.COnSelectCrd)
self.buttoncrd.pack(after=self.entry, anchor='e', padx=5, pady=2)
self.buttoncrd.bind('', self.COnSelectCrd)#the second labelframe for selecting las filesself.labellas=tkinter.LabelFrame(self.frame, text="Select las files:",labelanchor='nw', relief='groove', bd=2)
self.labellas.pack(anchor='w', ipadx=2, ipady=2, padx=2, pady=2)#a frame for place listbox and scrollbarself.listframe=tkinter.Frame(self.labellas)
self.ysrb=tkinter.Scrollbar(self.listframe, orient="vertical")
self.ysrb.pack(side='right', fill='y')
self.dirlist=tkinter.Listbox(self.listframe, bd=2, width=50, listvariable=self.lasname, yscrollcommand=self.ysrb.set)
self.dirlist.pack(anchor='w', padx=2, pady=2)
self.ysrb["command"]=self.dirlist.yview
self.listframe.pack()#a button for selecting las filesself.buttonlas=tkinter.Button(self.labellas, bd=2, text="Select...", width=10, command=self.COnSelectLas)
self.buttonlas.pack(after=self.listframe, anchor='e', padx=5, pady=2)#the button for exiting programeself.buttonexit=tkinter.Button(self.frame, text="Exit", bd=2, width=10, command=root.quit)
self.buttonexit.pack(side='right', padx=5, pady=2)#the button for running programeself.buttonrun=tkinter.Button(self.frame, text="Run", bd=2, width=10)
self.buttonrun.pack(side='right', anchor='e', padx=5, pady=2)#self.buttonrun.bind('', getlas())self.frame.pack()defCOnSelectCrd(self):
filename=tkinter.filedialog.askopenfilename(title="Coordinate file")
self.crdname.set(filename)defCOnSelectLas(self):
filelist=tkinter.filedialog.askopenfilenames(title="Las files")
self.lasname.set(filelist)if__name__=="__main__":importosimporttkinter
root=tkinter.Tk()
root.title("Crd2Las")
TopApp(root)
root.mainloop()#crd = getcrd("coordinate.prn")#getlas(crd, "Y57.LAS")