Skip to content
Snippets Groups Projects
Commit 67722f4d authored by Yngve Levinsen's avatar Yngve Levinsen
Browse files

make file write working in python3

parent e419f93b
No related branches found
No related tags found
No related merge requests found
Pipeline #5826 passed
......@@ -312,31 +312,37 @@ class LATTICE:
if self.lst[-1].gamma==1.0: self.update_gamma() # Assign gamma, if not done yet
with open(file_name_elem,'w') as file:
with open(file_name_elem,'w') as fname:
for lat_i in self.lst:
try : print >>file,lat_i.get_madx()
except: pass
try:
fname.write(lat_i.get_madx()+'\n')
except AttributeError:
pass
with open(file_name_elem,'r') as file: lst_name=[lin.split(':')[0] for lin in file]
with open(file_name_seq ,'w') as file: print >>file,'linac:line=('+','.join(lst_name)+');'
with open(file_name_elem,'r') as fname: lst_name=[lin.split(':')[0] for lin in fname]
with open(file_name_seq ,'w') as fname: fname.write('linac:line=({});\n'.format(','.join(lst_name)))
def get_fluka(self,file_name='elem.dat'):
if self.lst[-1].gamma==1.0: self.update_gamma() # Assign gamma, if not done yet
with open(file_name,'w') as file:
with open(file_name,'w') as fname:
for lat_i in self.lst:
try : print >>file,lat_i.get_fluka()
except: pass
try:
fname.write(lat_i.get_fluka()+'\n')
except AttributeError:
pass
def get_mars(self,file_name='elem.dat'):
if self.lst[-1].gamma==1.0: self.update_gamma() # Assign gamma, if not done yet
with open(file_name,'w') as file:
with open(file_name,'w') as fname:
for lat_i in self.lst:
try : print >>file,lat_i.get_mars()
except: pass
try:
fname.write(lat_i.get_mars()+'\n')
except AttributeError:
pass
class PROJECT:
'''
......@@ -720,7 +726,7 @@ def x2dst(x,mass,freq,Ibeam,path_file='part_dtl1_new.dst'):
2014.10.03
'''
file=open(path_file,'w')
fname=open(path_file,'w')
out =pack('b',125)
out+=pack('b',100)
out+=pack('i',len(x))
......@@ -730,8 +736,8 @@ def x2dst(x,mass,freq,Ibeam,path_file='part_dtl1_new.dst'):
x=list(chain(*x)) # Flatten x
for x_i in x: out+=pack('d',x_i)
out+=pack('d',mass)
print >>file,out
file.close()
fname.write(out+'\n')
fname.close()
def plt2x(path_file):
'''
......@@ -783,7 +789,7 @@ def x2plt(x,mass,freq,Ibeam,i_unk,i_elem,s,phs,ken,path_file='dtl1_new.plt'):
2014.10.07
'''
file=open(path_file,'w')
fname=open(path_file,'w')
out =pack('b',125)
out+=pack('b',100)
out+=pack('i',len(x))
......@@ -800,8 +806,8 @@ def x2plt(x,mass,freq,Ibeam,i_unk,i_elem,s,phs,ken,path_file='dtl1_new.plt'):
out+=pack('d',ken[i])
x_i=list(chain(*x[i]))
for x_ik in x_i: out+=pack('f',x_ik)
print >>file,out
file.close()
fname.write(out+'\n')
fname.close()
#---- Data related
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment