	program test_trigram_fortran

c		Note: with read(*,*), it is difficult to get characters
c		like blank into the program for testing purposes

	character*100 string,result
	character*10 replacement
	character*1 key

	integer trigram,un_trigram

 100	format (a)

   5	continue
	read (*,100,end=50) string
	read (*,100) replacement
	read (*,100) key

        do 10 i=100,1,-1
          if (string(i:i).ne.' ') then
	    string(i+1:i+1) = char(0)
	    go to 20
	  endif
  10	continue
  20    do 30 j=10,1,-1
	  if (replacement(j:j).ne.' ') then
	    replacement(j+1:j+1) = char(0)
	    go to 40
	  endif
  30	continue
  40	continue
	if (j.eq.1) replacement(2:2) = char(0)

	isize = 100
c	ireturn = trigram(result,string,0,replacement,0,key,isize)
	ireturn = trigram(result,string,i,replacement,j,key,isize)
	if (ireturn.eq.1) then
	  write(*,*) result(1:isize),'length',isize
	  isize = 100
	  ireturn = un_trigram(result,result,0,key,isize)
	  if (ireturn.eq.1) then
	    write(*,*) result(1:isize),'length',isize
	  else if (ireturn.eq.0) then
	    write(*,*) 'un_trigram problem',isize
	  else if (ireturn.eq.-1) then
	    write (*,*) 'un_trigram_ problem',isize
	  else
	    write (*,*) 'unknown return from un_trigram',ireturn
	  endif
	else if (ireturn.eq.0) then
	  write(*,*) 'trigram problem',isize
	else if (ireturn.eq.-1) then
	  write(*,*) 'trigram_ problem',isize
	else
	  write(*,*) 'unknown return from trigram_',ireturn
	endif

        go to 5
  50	stop
	end
