subroutine f2test(fun1,fun2,inump,xmin,xmax,ymin,ymax, &
     name,namex,namey)
  use iso_c_binding, only: fp => c_double
  !
  !   test/compare 2 methods of evaluation of 2d function values and derivatives
  !
  !     passed:
  !       subroutine fun1(x,y,fget1(1..6))
  !       subroutine fun1(x,y,fget2(1..6))
  !
  !          (input x,y, return vector of 6 numbers containing, in order:
  !            f,df/dx,df/dy,d2f/dx2,d2f/dy2,d2f/dxdy)
  !
  !============
  implicit none
  integer icyc,i,ict,iy,ix
  !============
  real(fp) :: zy,zx,zdifa
  !============
  external fun1,fun2
  !
  integer inump                     ! #evals per dimension
  !
  real(fp) :: xmin,xmax                    ! x range
  real(fp) :: ymin,ymax                    ! y range
  !
  character(len=*) name                ! name/label for fcns --
  character(len=*) namex,namey         ! name/label for x & y dims
  !
  !  NOTE `name*' should be short with no leading or trailing blanks
  !
  !  local:
  !
  real(fp) :: fget1(6),fget2(6),fmin(6),fmax(6),fdifa(6)
  !
  !  output of routine:  stats written to unit 6
  !
  !--------------------------------
  !
  data icyc/100000/
  !
  do i=1,6
     fmin(i)=1.0E35_fp
     fmax(i)=-1.0E35_fp
     fdifa(i)=0.0_fp
  end do
  !
  ict=0
  !
  do iy=1,inump
     zy=ymin+real(iy-1,fp)*(ymax-ymin)/real(inump-1,fp)
     do ix=1,inump
        zx=xmin+real(ix-1,fp)*(xmax-xmin)/real(inump-1,fp)
        !
        ict=ict+1
        if(icyc*(ict/icyc).eq.ict) then
           write(6,1001) ix,zx,iy,zy,ict
1001       format('  ...f2test: evaluating at x(',i5,')=',1pe11.4, &
                ', y(',i5,')=',1pe11.4,' #=',i8)
        end if
        !
        call fun1(zx,zy,fget1)
        call fun2(zx,zy,fget2)
        !
        do i=1,6
           fmin(i)=min(fmin(i),fget1(i),fget2(i))
           fmax(i)=max(fmax(i),fget1(i),fget2(i))
           zdifa=abs(fget1(i)-fget2(i))
           fdifa(i)=max(fdifa(i),zdifa)
        end do
        !
     end do
  end do
  !
  write(6,1002) namex,namey,name, &
       (name,fmin(i),fmax(i),fdifa(i),i=1,6)
1002 format(/ &
       '  test function comparison:'/ &
       '     x stands for "',a,'";  y stands for "',a,'".'/ &
       '     (',a,')     min value   max value   max |diff|'/ &
       '   ',a,':      ',3(1pe11.3,2x)/ &
       '  d',a,'/dx:   ',3(1pe11.3,2x)/ &
       '  d',a,'/dy:   ',3(1pe11.3,2x)/ &
       ' d2',a,'/dx2:  ',3(1pe11.3,2x)/ &
       ' d2',a,'/dy2:  ',3(1pe11.3,2x)/ &
       ' d2',a,'/dxdy: ',3(1pe11.3,2x)/)
  !
  return
end subroutine f2test
