      real*8 function RaGradientBLH(BLH,ksi,hgt,kxx,kyy,nlat,nlon,hd,dr)
      !按严密球面积分公式计算重力场元ksi的径向梯度
	  !kxx,kyy-call HGradientTwo(ksi,hgt,nlat,nlon,hd,kxx,kyy)
      !dr-积分半径m
!-------------------------------------------------------------
      implicit none
	integer::i,j,nlat,nlon,i0,j0,ni,nj,astat(5)
	real*8::dr,ksi(nlat,nlon),hgt(nlat,nlon),kxx(nlat,nlon),kyy(nlat,nlon)
	real*8::hd(6),gp,pi,RAD,ds,mdr,tt,rr,r1,rst,tmp
	real*8::BLH(3),XYZ(3),rln(3),BLH1(3),XYZ1(3),rln1(3)
	real*8 CGrdPntD2,RaGradSng0,ksi0,L1
	real*8::CRS(5),ge,re,tp
      integer::kfn !奇异积分核函数精化参数2*kfn
!-----------------------------------------------------------------
      rst=0.d0;pi=datan(1.d0)*4.d0;RAD=pi/180.d0;kfn=2
      ksi0=CGrdPntD2(BLH(2),BLH(1),ksi,nlat,nlon,hd)
      call BLH_XYZ(CRS,BLH,XYZ);call BLH_RLAT(CRS,BLH,rln);rr=rln(1)
      mdr=rr*hd(5)*RAD*dcos(rln(2)*RAD)/2.d0 !奇异点判断
      ni=nint(dr/rr/RAD/hd(6)+1.d0) !积分半径dr对应的地面格网数
      nj=nint(dr/rr/RAD/hd(5)/dcos(rln(2)*RAD)+1.d0)
	i0=nint((BLH(1)-hd(3))/hd(6)+0.5d0)
	j0=nint((BLH(2)-hd(1))/hd(5)+0.5d0)!计算点所在的地面格网i0,j0
	do i=i0-ni,i0+ni
	  if(i<1.or.i>nlat)goto 9100
        BLH1(1)=hd(3)+(real(i)-0.5d0)*hd(6)
	  do j=j0-nj,j0+nj
	    if(j<1.or.j>nlon)goto 9101
	    BLH1(2)=hd(1)+(real(j)-0.5d0)*hd(5)
          BLH1(3)=hgt(i,j);call BLH_XYZ(CRS,BLH1,XYZ1)
          L1=dsqrt((XYZ1(1)-XYZ(1))**2+(XYZ1(2)-XYZ(2))**2+(XYZ1(3)-XYZ(3))**2)
          if(L1>dr)goto 9101
          if(L1<mdr)then!计算奇异积分
             tmp=RaGradSng0(BLH,ksi,hgt,nlat,nlon,hd,i,j,kfn)
             rst=rst+tmp
             goto 9101 
          endif
          call BLH_RLAT(CRS,BLH1,rln1);r1=rln1(1)
          ds=hd(5)*hd(6)*RAD**2*dcos(rln1(2)*RAD)*r1**2
          rst=rst+(ksi(i,j)-ksi0)*ds/pi/L1**3/2.d0
9101      continue
	  enddo
9100    continue
	enddo
	RaGradientBLH=rst
9002	return
      end
!--------------------------------------------------------------------------------
      real*8 function RaGradSng(BLH,ksi,hgt,hxx,hyy,nlat,nlon,hd,i0,j0,m)
      !细化核函数，计算BLH点的重力场元的径向梯度的奇异积分
      !m-核函数细化为m*m
      !i0,j0-奇异点格网位置
!-------------------------------------------------------------
      implicit none
	integer::m,i,j,nlat,nlon,i0,j0,ni,nj,astat(5)
	real*8::dr,ksi(nlat,nlon),hgt(nlat,nlon),hxx(nlat,nlon),hyy(nlat,nlon)
	real*8::hd(6),gp,pi,RAD,ds,mdr,tt,rr,r1,rst,rv,tx,ty,lon,lat
	real*8::BLH(3),XYZ(3),rln(3),BLH1(3),XYZ1(3),rln1(3)
	real*8 CGrdPntD2,ksi0,ksi1,L1
	real*8::CRS(5)
!-----------------------------------------------------------------
      rst=0.d0;rv=hd(5)/dble(m);pi=datan(1.d0)*4.d0;RAD=pi/180.d0
      lat=hd(3)+real(i0-1)*hd(6);lon=hd(1)+real(j0-1)*hd(5)!格网左下角经纬度
      ksi0=CGrdPntD2(BLH(2),BLH(1),ksi,nlat,nlon,hd)
      call BLH_XYZ(CRS,BLH,XYZ);call BLH_RLAT(CRS,BLH,rln);rr=rln(1)
      mdr=rr*rv*RAD*dcos(rln(2)*RAD)/2.d0 !奇异点判断
	do i=1,m
        BLH1(1)=lat+(real(i)-0.5d0)*rv
	  do j=1,m
	    BLH1(2)=lon+(real(j)-0.5d0)*rv
          BLH1(3)=CGrdPntD2(BLH1(2),BLH1(1),hgt,nlat,nlon,hd)
          call BLH_XYZ(CRS,BLH1,XYZ1)
          L1=dsqrt((XYZ1(1)-XYZ(1))**2+(XYZ1(2)-XYZ(2))**2+(XYZ1(3)-XYZ(3))**2)
          call BLH_RLAT(CRS,BLH1,rln1);r1=rln1(1)
          ds=rv**2*RAD**2*dcos(rln1(2)*RAD)*r1**2
          if(L1<mdr)goto 9100
          ksi1=CGrdPntD2(BLH1(2),BLH1(1),ksi,nlat,nlon,hd)
          rst=rst+(ksi1-ksi0)*ds/pi/L1**3/2.d0
9101      continue
          if(L1<mdr)then !计算奇异积分
            tx=CGrdPntD2(BLH1(2),BLH1(1),hxx,nlat,nlon,hd)
            ty=CGrdPntD2(BLH1(2),BLH1(1),hyy,nlat,nlon,hd)
            rst=rst+(tx+ty)*dsqrt(ds/pi)/4.d0
          endif
	  enddo
9100    continue
	enddo
	RaGradSng=rst
9002	return
      end
