def get_sMatrix(elem, squid):
    '''
    This is where the assembly of the model happens using ABCD Matrixes
    SM represents the SQUID response
    M1 respresents 3 sections of Transmission lines (L1,Z1)(L2,Z2)(L3,Z3)
    Zsq is the impedance of the SQUID (flux) (vector)
    Assembly is done for each flux point and change in Zsq
    '''
    Zsq = get_Zsq(squid)
    b = 2.0 * pi * squid.f0 / 2.0e8
    SM = np.zeros((len(Zsq), 2, 2)) * 1j  # complex matrix
    M1 = (tline(elem.Z1, b, elem.L1) *
          tline(elem.Z2, b, elem.L2) *
          tline(elem.Z3, b, elem.L3))  # transmission lines
    for ii, Zsq1 in enumerate(Zsq):
        M2 = sres(Zsq1) * shunt(elem.Z4)
        M4 = M1 * M2
        SM[ii] = elem.get_SM(M4)  # complex S-Matrix shape [2 2 fluxlength]
    return SM
           pt = 11) #8 pts for S 4x2 values
dim_3._Z0 = 50

head1 = make_header(magnet, freq, dim_3, 'S11 S12 S21 S22 Z L')
dim_3.prepare_data_save(magnet, freq, dim_3)


for jj, f0 in enumerate(freq.lin):
    for ii, flux in enumerate(magnet.lin):
        # b = k = 2pi/wavelength; wavelength = velocity / frequency
        b = 2.0*pi*f0/v
        L = flux0 / (Ic*2.0*pi* abs(cos(pi*flux/flux0)))
        Ysq = (1.0/R + 1.0/(i*2.0*pi*f0*L +i*1e-90) + i*2.0*pi*f0*Cap)
        Zsq = 1.0/Ysq

        ABCD_Matrix = tline(70,b,0.01)*tline(50,b,0.3)*tline(10,b,900e-6)*sres(Zsq)*shunt(0.1)

        #record stuff into dim_3._SMat
        dim_3.record_SM(ABCD_Matrix,jj,ii)
        dim_3.record_ZL(Zsq,L, jj,ii)

    dim_3.unwrap_SM(jj)
    dim_3._SMat[9,jj] = unwrap(dim_3._SMat[9,jj])

plt.figure(1)
plt.subplot(2, 1, 1)
plt.imshow(dim_3._SMat[0], aspect = 'auto',cmap=plt.get_cmap('seismic'))
plt.subplot(2, 1, 2)
plt.imshow(dim_3._SMat[1], aspect = 'auto',cmap=plt.get_cmap('seismic'))
plt.show()