!+ ! Subroutine bmad_modify_element_attribute (ix_lat, ix_ele, ix_attrib, attrib_value) ! ! Modify an element attribute. ! bmad_lattice_bookkeeper needs to be called after all modifications have been made. ! ! Input: ! ix_lat -- Integer: Index of lattice containing element to modify. ! ix_ele -- Integer: Index of element to modify. ! ix_attrib -- Integer: Index of attribute in ele%value(:). ! attrib_value -- Real(rp): Value of attribute !- subroutine bmad_modify_element_attribute (ix_lat, ix_ele, ix_attrib, attrib_value) use bmad_common_mod use bookkeeper_mod implicit none type (lat_struct), pointer :: lat type (ele_struct), pointer :: ele real(rp) attrib_value real(rp), pointer :: a_ptr integer ix_lat, ix_ele, ix_attrib character(32), parameter :: r_name = 'bmad_modify_element_attribute' logical err_flag, err ! call bmad_set_lat_pointer (err, r_name, ix_lat, lat, ix_ele, ele, can_be_in_init = .true.) if (err) then return endif ! Do not want to do unnecessary bookkeeping if value has not changed significantly. if (abs(ele%value(ix_attrib) - attrib_value) <= & 1d-13 * (abs(ele%value(ix_attrib)) + abs(attrib_value)) + 1d-100) return ele%value(ix_attrib) = attrib_value call set_flags_for_changed_attribute (ele, ele%value(ix_attrib)) ! scratch1 for an sbend is used to pass in the total B field if (ele%key == sbend$ .and. ix_attrib == scratch1$) then ele%value(b_field_err$) = ele%value(scratch1$) - ele%value(b_field$) call set_flags_for_changed_attribute (ele, ele%value(b_field_err$)) endif if (ele%key == e_gun$ .and. associated(ele%grid_field)) then ele%grid_field(1)%r0(2) = -ele%value(scratch1$) endif end subroutine