#------------- Functions -------------------------------------
def make_name(a, b):
    return a + "=" + str(b) + ";"


#------------- Check wether there is already a str file for skew from a previous step -------------
try:
    with open('temp_multipole.str') as file:
        str_temp = np.genfromtxt("temp_multipole.str")
except IOError as e:
    str_temp = np.zeros(1184)

#-------------------------- Get the relative phase advances from twiss file ------------------------------------------
bare = TwissTable(
    "/afs/cern.ch/user/s/saumon/FCCee/correction_scheme/correction_scheme_ko_205/response_matrix/beta_beat/response_matrix_v205_10mm/twiss_bare_bpm.twiss"
)
muy0 = bare.get_muy()
mux0 = bare.get_mux()
dx0 = bare.get_dx()

pert_optics = TwissTable("beat.twiss")

muy = pert_optics.get_muy()
mux = pert_optics.get_mux()
dx = pert_optics.get_dx()

phase_advance = np.concatenate((muy - muy0, mux - mux0, dx - dx0), axis=0)

print phase_advance.shape
print phase_advance
#------------- Functions -------------------------------------
def make_name(a, b):
    return a + "=" + str(b) + ";"


#------------- Check wether there is already a str file for skew from a previous step -------------
try:
    with open('temp_multipole.str') as file:
        str_temp = np.genfromtxt("temp_multipole.str")
except IOError as e:
    str_temp = np.zeros(1176)

#-------------------------- Get the relative phase advances from twiss file ------------------------------------------
bare = TwissTable(
    "/afs/cern.ch/user/s/saumon/FCCee/TLEP_lattice_version/ko_175_t_85/lattice/twiss_bare_bpm.twiss"
)
muy0 = bare.get_muy()
mux0 = bare.get_mux()
dx0 = bare.get_dx()

pert_optics = TwissTable("beat.twiss")

muy = pert_optics.get_muy()
mux = pert_optics.get_mux()
dx = pert_optics.get_dx()

phase_advance = np.concatenate((muy - muy0, mux - mux0, dx - dx0), axis=0)

print phase_advance.shape
print phase_advance