00001 subroutine interpo_gr2grcartesian_4th(fnc,cfn,xc,yc,zc)
00002   use phys_constant, only : long, pi
00003   use grid_parameter, only : nrg, ntg, npg
00004   use coordinate_grav_extended
00005   implicit none
00006   real(long), pointer     :: fnc(:,:,:)
00007   real(long), intent(out) :: fncar
00008   real(long) ::  xc, yc, zc, rc, thc, phic, varpic
00009   real(long) ::  r4(4), th4(4), phi4(4), fr4(4), ft4(4), fp4(4)
00010   integer :: irg, itg, ipg, irgex, itgex, ipgex
00011   integer :: ir0, it0, ip0, irg0 , itg0 , ipg0, ii, jj, kk
00012   real(long), external :: lagint_4th
00013 
00014 
00015 
00016 
00017   rc     = dsqrt(dabs(xc**2 + yc**2 + zc**2))
00018   varpic = dsqrt(dabs(xc**2 + yc**2))
00019   thc  = dmod(2.0d0*pi + datan2(varpic,zc),2.0d0*pi)
00020   phic = dmod(2.0d0*pi + datan2(    yc,xc),2.0d0*pi)
00021 
00022   do irg = 0, nrg
00023     if (rc.lt.rgex(irg).and.rc.ge.rgex(irg-1)) ir0 = min0(irg-2,nrg-3)
00024   end do
00025   do itg = 0, ntg
00026     if (thc.lt.thgex(itg).and.thc.ge.thgex(itg-1)) it0 = itg-2
00027   end do
00028   do ipg = 0, npg
00029     if (phic.lt.phigex(ipg).and.phic.ge.phigex(ipg-1)) ip0 = ipg-2
00030   end do
00031 
00032   do ii = 1, 4
00033     irg0 = ir0 + ii - 1
00034     itg0 = it0 + ii - 1
00035     ipg0 = ip0 + ii - 1
00036     r4(ii) = rgex(irg0)
00037     th4(ii) = thgex(itg0)
00038     phi4(ii) = phigex(ipg0)
00039   end do
00040 
00041 
00042 
00043 
00044 
00045 
00046 
00047 
00048 
00049   do kk = 1, 4
00050     ipg0 = ip0 + kk - 1
00051     do jj = 1, 4
00052       itg0 = it0 + jj - 1
00053       do ii = 1, 4
00054         irg0 = ir0 + ii - 1
00055         irgex = irgex_r(irg0)
00056         itgex = itgex_r(itgex_th(itg0),irg0)
00057         ipgex = ipgex_r(ipgex_th(ipgex_phi(ipg0),itg0),irg0)
00058         fr4(ii) = fnc(irgex,itgex,ipgex)
00059       end do
00060       ft4(jj) = lagint_4th(r4,fr4,rc)
00061     end do
00062     fp4(kk) = lagint_4th(th4,ft4,thc)
00063   end do
00064   cfn = lagint_4th(phi4,fp4,phic)
00065 
00066 end subroutine interpo_gr2grcartesian_4th