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

allow to not specify field map list

if so find them in FIELD_MAP_PATH command instead
parent ea63ed3f
No related branches found
No related tags found
No related merge requests found
...@@ -33,7 +33,7 @@ class LATTICE: ...@@ -33,7 +33,7 @@ class LATTICE:
''' '''
2015.10.14 2015.10.14
''' '''
def __init__(self,file_name_lat,file_name_fmap,freq=352.21,gamma=1.0): def __init__(self,file_name_lat,file_name_fmap=[],freq=352.21,gamma=1.0):
# In case file_name_fmap is str # In case file_name_fmap is str
if isinstance(file_name_fmap,basestring): file_name_fmap=[file_name_fmap] if isinstance(file_name_fmap,basestring): file_name_fmap=[file_name_fmap]
...@@ -68,10 +68,11 @@ class LATTICE: ...@@ -68,10 +68,11 @@ class LATTICE:
typ =lin.split()[0 ].upper() typ =lin.split()[0 ].upper()
para=lin.split()[1:] para=lin.split()[1:]
# Map to a class # Map to a class
if typ == 'FIELD_MAP' : lst.append( FIELD_MAP(name,typ,para,dic_fmap)) if typ == 'FIELD_MAP' : lst.append( FIELD_MAP(name,typ,para,dic_fmap))
elif typ in dic_cls.keys(): lst.append(dic_cls[typ](name,typ,para) ) elif typ == 'FIELD_MAP_PATH' : _update_field_map_dict(dic_fmap,para[0])
elif 'DIAG' in typ : lst.append( DIAG(name,typ,para) ) elif typ in dic_cls.keys() : lst.append(dic_cls[typ](name,typ,para) )
else : lst.append( COMM(name,typ,para) ) elif 'DIAG' in typ : lst.append( DIAG(name,typ,para) )
else : lst.append( COMM(name,typ,para) )
# Break the loop # Break the loop
if typ=='END': break if typ=='END': break
...@@ -938,6 +939,17 @@ def partran_end_all(file_name_in_all,file_name_out): ...@@ -938,6 +939,17 @@ def partran_end_all(file_name_in_all,file_name_out):
else : file_out.write(' %10s'%lin[i]) else : file_out.write(' %10s'%lin[i])
file_out.write('\n') file_out.write('\n')
def _update_field_map_dict(dictionary,folder_path):
import os
for filename in os.listdir(folder_path):
if filename.split('.')[-1]=='edz': # only 1D for now..
key=filename.split('.')[0]
if key not in dictionary: # do not override user selection
dictionary[key]=os.path.join(folder_path,filename)
print key,':',dictionary[key]
#-------- Obsolete classes and functions #-------- Obsolete classes and functions
#---- Old MATCH and LATTICE classes from the time of IPAC'15 (more complex) #---- Old MATCH and LATTICE classes from the time of IPAC'15 (more complex)
......
...@@ -90,6 +90,9 @@ class FIELD_MAP_DATA: ...@@ -90,6 +90,9 @@ class FIELD_MAP_DATA:
''' '''
def __init__(self,file_name): def __init__(self,file_name):
if file_name.split('.')[-1]!='edz':
raise ValueError('Only 1D field maps (Ez) is supported for now')
# Read file # Read file
with open(file_name) as file: lin=file.readlines() with open(file_name) as file: lin=file.readlines()
......
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