	subroutine search(ibeg,iend,iflag,complete_search,length)
	implicit integer (a-z)

	real*4 single_float
	real*8 double_float

	byte buffer(32768),edit_buffer(32768),byte_value,long_array(4),
     1	     word_array(2),single_array(4),double_array(8)
	equivalence (long_array(1),ivalue)
	equivalence (word_array(1),ivalue1)
	equivalence (single_array(1),single_float)
	equivalence (double_array(1),double_float)
	external std_rfa_useropen

	common /buf/ buffer,edit_buffer,length_total

	character*255 search_string
	character*10 record_type

	common /ser/ search_string

	dimension lengths(8)
!
! length in bytes of  A O L W B F D H
!
	data lengths /1,1,4,2,1,4,8,4/
	
	character*63 file_name
	
	common /files/ file_name
	logical fixed_length,complete_search

	if (length.le.0) then
		type 5
 5		format(/' Invalid search string'/)
		return
	 endif

	if (ibeg.gt.iend) then
		type 10
 10		format(/' Invalid record range'/)
		return
	 endif

	fixed_length=.false.

	open(unit=3,name=file_name,type='old',
     1		form='unformatted',readonly,useropen=std_rfa_useropen,
     2		err=9100,shared)
	inquire(3,recl=record_size)
	inquire(3,recordtype=record_type)
	if (record_type.eq.'FIXED') fixed_length=.TRUE.
	close(unit=3)
!
! change record size to get correct number of longwords
!
	if (.not. fixed_length) record_size=record_size+1
!
! added reopen of file because of large fixed length records
!
	open(unit=3,name=file_name,type='old',
     1		form='unformatted',readonly,useropen=std_rfa_useropen,
     2		recl=record_size,recordtype=record_type,shared)

	if (iflag.eq.1) then				! ascii search
		call search_for(ibeg,iend,length,
     1					%ref(search_string(1:length)),
     2					fixed_length,complete_search)
	 endif

	if (iflag.eq.2) then				! octal search
!
! unsigned octal one byte, ignore blanks in processing
!
		byte_value=0
		istat=ots$cvt_to_l(search_string(1:3),byte_value,
     1			%val(1),%val(1))
		call check(istat)
		if (istat.le.0) return
		call search_for(ibeg,iend,lengths(iflag),
     1					byte_value,fixed_length,
     2					complete_search)
	 endif

	if (iflag.eq.3) then				! longword
!
! signed I*4, ignore blanks, 4 bytes
!
		ivalue=0
		istat=ots$cvt_ti_l(search_string(1:length),ivalue,
     1					%val(4),%val(1))
		call check(istat)
		if (istat.le.0) return
		call search_for(ibeg,iend,lengths(iflag),
     1					long_array,fixed_length,
     2					complete_search)
	 endif

	if (iflag.eq.4) then				! word
		ivalue1=0
!
! signed I*2 two bytes, ignore blanks
!
		istat=ots$cvt_ti_l(search_string(1:length),ivalue1,
     1					%val(2),%val(1))
		call check(istat)
		if (istat.le.0) return
		call search_for(ibeg,iend,lengths(iflag),
     1					word_array,fixed_length,
     2					complete_search)
	 endif

	if (iflag.eq.5) then				! signed byte
		ivalue=0
!
! signed L*1 one byte, ignore blanks
!
		istat=ots$cvt_ti_l(search_string(1:length),ivalue,
     1					%val(1),%val(1))
		call check(istat)
		if (istat.le.0) return
		call search_for(ibeg,iend,lengths(iflag),
     1					long_array,fixed_length,
     2					complete_search)
	 endif
	if (iflag.eq.6) then				! floating
		single_float=0.
!
! R*4, 4 bytes, ignore blanks, underflow will error, no rounding
!
		istat=ots$cvt_t_f(search_string(1:length),single_float,
     1					,,%val(13))
		call check(istat)
		if (istat.le.0) return
		call search_for(ibeg,iend,lengths(iflag),
     1					single_array,fixed_length,
     2					complete_search)
	 endif

	if (iflag.eq.7) then				! double floating
		double_float=0.
!
! R*8, 8 bytes, ignore blanks, underflow will error, no rounding
!
		istat=ots$cvt_t_d(search_string(1:length),double_float,
     1					,,%val(13))
		call check(istat)
		if (istat.le.0) return
		call search_for(ibeg,iend,lengths(iflag),
     1					double_array,fixed_length,
     2					complete_search)
	 endif
	if (iflag.eq.8) then				! hex 
!
! hex, 4 bytes, ignore blanks
!
		ivalue=0
		istat=ots$cvt_tz_l(search_string(1:length),ivalue,
     1					%val(4),%val(1))
		call check(istat)
		if (istat.le.0) return
		call search_for(ibeg,iend,lengths(iflag),
     1					long_array,fixed_length,
     2					complete_search)
	 endif

	close(unit=3)
	return
 9100	type *,'unable to open file for searching'
	return
	end
