subroutine rgtran(new,old_head,dr)
use types
use amr
type(ADAPTIVE_MESH),pointer    :: new,old_head
real(SP), dimension(3)         :: dr

type(ADAPTIVE_MESH),pointer    :: old

!any overlap betwen new child and old structure?

old=>old_head
DO WHILE (associated(old))

if(old%grmax(1)>=new%grmin(1) .and. old%grmax(2)>=new%grmin(2) &
   .and. old%grmax(3)>=new%grmax(3)) then
  if(old%grmin(1)<=new%grmax(1) .and. old%grmin(2)<=new%grmin(2) &
   .and. old%grmin(3)<=new%grmax(3)) then

        !there is an overlap; compute indices
         if(old%grmin(1) >= new%grmin(1)) then
            in = (old%grmin(1)-new%grmin(1)+dr(1))/dr(1) 
            io = 1
         else
            in = 1
            io = (new%grmin(1)-old%grmin(1)+dr(1))/dr(1)
         endif
         if(old%grmin(2) >= new%grmin(2)) then
            jn = (old%grmin(2)-new%grmin(2)+dr(2))/dr(2) 
            jo = 1
         else
            jn = 1
            jo = (new%grmin(2)-old%grmin(2)+dr(2))/dr(2)
         endif
         if(old%grmin(3) >= new%grmin(3)) then
            kn = (old%grmin(3)-new%grmin(3)+dr(3))/dr(3) 
            ko = 1
         else
            kn = 1
            ko = (new%grmin(3)-old%grmin(3)+dr(3))/dr(3)
         endif
         if(old%grmax(1) <= new%grmax(1)) then
            in1 = new%gnr(1)-(new%grmax(1)-old%grmax(1))/dr(1)
            io1 = old%gnr(1)
         else
            in1 = new%gnr(1)
            io1 = old%gnr(1)-(old%grmax(1)-new%grmax(1))/dr(1)
         endif

         if(old%grmax(2) <= new%grmax(2)) then
            jn1 = new%gnr(2)-(new%grmax(2)-old%grmax(2))/dr(2)
            jo1 = old%gnr(2)
         else
            jn1 = new%gnr(2)
            jo1 = old%gnr(2)-(old%grmax(2)-new%grmax(2))/dr(2)
         endif

         if(old%grmax(3) <= new%grmax(3)) then
            kn1 = new%gnr(3)-(new%grmax(3)-old%grmax(3))/dr(3)
            ko1 = old%gnr(3)
         else
            kn1 = new%gnr(3)
            ko1 = old%gnr(3)-(old%grmax(3)-new%grmax(3))/dr(3)
         endif

        !transfer data from old to new grid 

         DO i=1,ninterp
         new%grid%gfcn(what(i))%tlev(1)%data(in:in1,jn:jn1,kn:kn1) = &
         old%grid%gfcn(what(i))%tlev(1)%data(io:io1,jo:jo1,ko:ko1) 
         ENDDO

  endif
endif

old=>old%neighbor 

ENDDO

return
end
