module bmad_to_autocad_mod use bmad_struct contains !--------------------------------------------------------------------------- !--------------------------------------------------------------------------- !--------------------------------------------------------------------------- !+ ! Subroutine write_autocad_map_table (iu_outfile, lat, ele, xmap, zmap, tmap) ! ! Subroutine to write a file that bmad_to_autocad.lsp can read in AutoCAD ! ! Input: ! iu_outfile -- integer: file unit to write to ! lat -- Lat_stuct: lattice to write ! ele -- ele_stuct: element to match floor position ! xmap -- real(rp): map x-position to match ! zmap -- real(rp): map z-position to match ! tmap -- real(rp): map angle theta to match ! ! Output: ! Writes to iu_outfile ! !- subroutine write_autocad_map_table(iu_outfile, lat, ele, xmap, zmap, tmap) implicit none type(lat_struct), target :: lat type (ele_struct), pointer :: ele integer :: iu_outfile integer i, j, n, i0, ix, n_cell real(dp) x0, z0, th0, c0, s0, xloc, yloc, zloc, theta, phi, psi, xmap, zmap, tmap character(40) name character(30), parameter :: r_name = 'write_autocad_map_table' ! x0=ele%floor%r(1) ; z0=ele%floor%r(3) ; th0=ele%floor%theta c0 = cos(tmap-th0) ; s0 = sin(tmap-th0) !call out_io (s_info$, r_name, 'Using x0 = \es18.10\', r_array = [ x0 ] ) print *, '' print *, 'Using x0 = ', x0 print *, ' z0 = ', z0 print *, ' th0 = ', th0 print *, ' tmap = ', tmap print *, ' at ele: ', trim(ele%name) print *, '' do n = 0, ubound(lat%branch, 1) !do i = 0, lat%branch(n)%n_ele_track do i = 0, lat%branch(n)%n_ele_max if (i == 0 .and. n == 0) cycle ele => lat%branch(n)%ele(i) !Skip slaves if (ele%slave_status == multipass_slave$ .or. ele%slave_status == super_slave$) cycle !Skip BEGINNING_ELE if (ele%key == beginning_ele$) cycle if (ele%key == patch$) cycle if (ele%key == marker$) cycle if (ele%key == match$) cycle if (ele%key == null_ele$) cycle if (ele%key == floor_shift$) cycle if (ele%key == overlay$) cycle xloc = xmap + c0*(ele%floor%r(1)-x0) + s0*(ele%floor%r(3)-z0) yloc = 0.0 zloc = zmap - s0*(ele%floor%r(1)-x0) + c0*(ele%floor%r(3)-z0) name = ele%name ix = ele%ix_ele theta = ele%floor%theta + tmap-th0 phi = ele%floor%phi psi = ele%floor%psi if (i == 0) name = 'BRANCH' write (iu_outfile, '(4a, i6, 6(a, es18.10))', advance='no') 'layer1', ", ", name, ",", ix, ", ", xloc, ", ", yloc, ", ", zloc, ", ",theta, ", ",phi, ", ",psi !write (iu_outfile, '(4a, i6, 6(a, es18.10))', advance='no') 'layer1', ", ", name, ",", ix, ", ", ele%floor%r(1), ", ", 0.0 , ", ", ele%floor%r(3), ", ",ele%floor%theta, ", ",phi, ", ",psi !Sector Bends if (ele%key == sbend$) then write(iu_outfile, '(2a, 3(a, es18.10))', advance = 'no') ", ", key_name(ele%key), ", ", ele%value(l$), ", ", ele%value(x1_limit$), ", ", ele%value(x2_limit$) ! Horizontal bends if (ele%value(ref_tilt_tot$) == 0 ) then write(iu_outfile, '( 3(a, es18.10) )') & ", ", ele%value(angle$), & ", ", sign(1.0_rp, ele%value(angle$)) * ele%value(e1$), & ! Hack for the lisp program to draw the edges properly for negative angles ", ", sign(1.0_rp, ele%value(angle$)) * ele%value(e2$) else ! Vertical bend - draw straight write(iu_outfile, '( 3(a, es18.10) )') & ", ", 1e-6_rp, ", ", 0.0_rp, ", ", 0.0_rp endif !Wigglers else if (ele%key == wiggler$) then write(iu_outfile, '(2a, 3(a, es18.10) )', advance = 'no') ", ", key_name(ele%key), ", ", ele%value(l$), ", ", ele%value(x1_limit$), ", ", ele%value(x2_limit$) write(iu_outfile, '( 2(a, es18.10) )') & ", ", ele%value(n_pole$), & ", ", ele%value(x_ray_line_len$) !Collimators else if ( (ele%key == ecollimator$) .or. (ele%key == rcollimator$)) then write(iu_outfile, '(2a, 3(a, es18.10))', advance = 'yes') ", ", "COLLIMATOR", ", ", ele%value(l$), ", ", ele%value(x1_limit$), ", ", ele%value(x2_limit$) !Misc. elements else if ( (trim(ele%type) == "BPM") & .or. (trim(ele%type) == "SLIDINGJOINT") & .or. (trim(ele%type) == "GATEVALVE") & .or. (trim(ele%type) == "VACUUMGUAGE") & .or. (trim(ele%type) == "PUMPPORT")) then write(iu_outfile, '(2a, 3(a, es18.10))', advance = 'yes') ", ", ele%type, ", ", ele%value(l$), ", ", ele%value(x1_limit$), ", ", ele%value(x2_limit$) !Drifts and Pipes else if ( (ele%key == drift$) .or. (ele%key == pipe$)) then write(iu_outfile, '(2a, 3(a, es18.10))', advance = 'yes') ", ", "DRIFT", ", ", ele%value(l$), ", ", ele%value(x1_limit$), ", ", ele%value(x2_limit$) !All other elements else if ( (ele%key == lcavity$) .or. (ele%key == rfcavity$)) then n_cell = nint(ele%value(n_cell$)) if (n_cell == 0) n_cell = 7 write(iu_outfile, '(2a, 3(a, es18.10))', advance = 'no') ", ", key_name(ele%key), ", ", ele%value(l$), ", ", ele%value(x1_limit$), ", ", ele%value(x2_limit$) write(iu_outfile, '( 1(a, i8) )') & ", ", n_cell !number of cells else write(iu_outfile, '(2a, 3(a, es18.10))', advance = 'yes') ", ", key_name(ele%key), ", ", ele%value(l$), ", ", ele%value(x1_limit$), ", ", ele%value(x2_limit$) endif end do enddo end subroutine write_autocad_map_table end module