subroutine write_transfermatrix(lat,nbranch) use bmad use parameters_bmad implicit none type (lat_struct), target :: lat type (branch_struct), pointer :: branch type (ele_struct) ele type (coord_struct) co character *2 cbranch real(rp) temp(6,6),m(6,6) integer lun, i, j integer nbranch !compute branch matrix (injection line or full turn) temp = 0. forall(i=1:6)temp(i,i) = 1. branch => lat%branch(nbranch) do i = 1, branch%n_ele_track m = matmul(branch%ele(i)%mat6, temp) temp= m end do lat%branch(nbranch)%ele(0)%mat6=temp write(cbranch,'(i2.2)')nbranch lun = lunget() open(unit = lun, file = trim(directory)//'/'//'transfer_matrix_file_branch'//trim(cbranch)//'.dat') write(lun,'(/,a,i10)')' Element = Branch ', nbranch write(lun,'(4es12.4)')(temp(j,1:4),j=1,4) do i=0,lat%branch(nbranch)%n_ele_track write(lun,'(/,a,a)')' Element = ', trim(lat%branch(nbranch)%ele(i)%name) write(lun,'(4es12.4)')(lat%branch(nbranch)%ele(i)%mat6(j,1:4),j=1,4) call create_taylor_ele(lat%branch(nbranch)%ele(i),co) end do close(unit=lun) return end