!+ ! Subroutine bmad_create_bend (ix_lat, c_ele, c_err) ! ! Lattice creation routine to add an element to the lattice. ! ! Input: ! ix_lat -- Integer: Index of lattice to place the element in. ! c_ele -- C_ele: C++ version of the element. ! .value(Bmad::G) -- reference path 1/rho ! .value(Bmad::L) -- reference path length ! b_field_tot -- Real(rp): Total magnetic field. ! ! Output: ! c_err -- C_logical: Set True if there is an error. False otherwise. !- subroutine bmad_create_bend (ix_lat, c_ele, c_err) use bmad_common_mod use superimpose_mod implicit none type (c_ptr), value :: c_ele type (ele_struct), target :: ele type (ele_struct), pointer :: super_ele type (lat_struct), pointer :: lat integer ix_lat logical(c_bool) c_err logical err_flag character(16), parameter :: r_name = 'bmad_create_bend' ! c_err = c_logic(.true.) if (lat_status(ix_lat) /= in_init$) then call out_io (s_error$, r_name, "Bend creation attempted outside of init stage for lat \i0\ ", ix_lat) return endif lat => bd_com(ix_lat)%lat lat%param%bookkeeping_state%s_position = stale$ call s_calc(lat) call ele_to_f(c_ele, c_loc(ele)) ele%value(scratch2$) = ele%value(angle$) ! Save. call add_superimpose (lat, ele, 0, err_flag, super_ele) if (err_flag) then call bmad_remove_lat(ix_lat) return endif call deallocate_ele_pointers (ele) c_err = c_logic(.false.) end subroutine