!------------------------------------------------------------------- !------------------------------------------------------------------- !------------------------------------------------------------------- subroutine locate_element (ring, str, loc, err_flag) use cesrv_struct use cesrv_interface implicit none type (lat_struct) ring integer loc, i, ix character :: str*(*), digits*10 = '0123456789' logical err_flag, is_number ! trim leading blanks call string_trim (str, str, ix) if (ix == 0) then print *, 'ERROR IN LOCATE_ELEMENT: NO ELEMENT NAME GIVEN.' err_flag = .true. return endif ! string may be a number (the index of the element) or an element's name. is_number = .true. do i = 1, ix if (index(digits, str(i:i)) == 0) is_number = .false. enddo ! err_flag = .false. ! assume everything is OK if (is_number) then read (str, *) loc if (loc < 0 .or. loc > ring%n_ele_max) then print *, 'ERROR IN LOCATE_ELEMENT: RING INDEX OUT OF RANGE: ', str err_flag = .true. endif return endif ! here if str is an element's name. do loc = 1, ring%n_ele_max if (ring%ele(loc)%name == str(:ix)) return enddo print *, 'ERROR IN LOCATE_ELEMENT: CANNOT MATCH ELEMENT NAME: ', str(:ix) print *, ' WITH ANY ELEMENT IN THE RING.' err_flag = .true. end subroutine