!------------------------------------------------------------------------ !------------------------------------------------------------------------ !------------------------------------------------------------------------ subroutine get_twiss (ix_ele, ring, twiss_x, twiss_y) use cesrv_struct use cesrv_interface implicit none type (lat_struct) ring integer ix_ele, ix1, ix2 type (twiss_struct) :: twiss_x, twiss_y ! if (ix_ele == 0) then twiss_x%phi = 0 twiss_y%phi = 0 twiss_x%beta = 0 twiss_y%beta = 0 else if (ix_ele > ring%n_ele_track) then ix1 = ring%control(ring%ele(ix_ele)%ix1_slave)%slave%ix_ele - 1 ix2 = ring%control(ring%ele(ix_ele)%ix2_slave)%slave%ix_ele else ix1 = ix_ele - 1 ix2 = ix_ele endif twiss_x%phi = (ring%ele(ix1)%a%phi + ring%ele(ix2)%a%phi) / 2 twiss_y%phi = (ring%ele(ix1)%b%phi + ring%ele(ix2)%b%phi) / 2 twiss_x%beta = (ring%ele(ix1)%a%beta + ring%ele(ix2)%a%beta) / 2 twiss_y%beta = (ring%ele(ix1)%b%beta + ring%ele(ix2)%b%beta) / 2 endif end subroutine