




















































































































 


































































































































































 































































































































































































 





















































 










 








































































































































































































































 










                                
                                

                                
                                

                                
                                

                                





















































































module CarpetProlongateTest
  implicit none
  
contains
  
  
  
  
  function density_time_scale (tt) result (tscale)
    REAL*8 interp_xmax
  integer, parameter :: cctki_use_interp_xmax = kind(interp_xmax)
  REAL*8 interp_xmin
  integer, parameter :: cctki_use_interp_xmin = kind(interp_xmin)
  REAL*8 interp_ymax
  integer, parameter :: cctki_use_interp_ymax = kind(interp_ymax)
  REAL*8 interp_ymin
  integer, parameter :: cctki_use_interp_ymin = kind(interp_ymin)
  REAL*8 interp_zmax
  integer, parameter :: cctki_use_interp_zmax = kind(interp_zmax)
  REAL*8 interp_zmin
  integer, parameter :: cctki_use_interp_zmin = kind(interp_zmin)
  integer*8 interpolator
  integer, parameter :: cctki_use_interpolator = kind(interpolator)
  integer*8 interpolator_options
  integer, parameter :: cctki_use_interpolator_options = kind(interpolator_options)
  integer*8 prolongation
  integer, parameter :: cctki_use_prolongation = kind(prolongation)
  INTEGER*4 interp_nx
  integer, parameter :: cctki_use_interp_nx = kind(interp_nx)
  INTEGER*4 interp_ny
  integer, parameter :: cctki_use_interp_ny = kind(interp_ny)
  INTEGER*4 interp_nz
  integer, parameter :: cctki_use_interp_nz = kind(interp_nz)
  INTEGER*4 power_t
  integer, parameter :: cctki_use_power_t = kind(power_t)
  INTEGER*4 power_x
  integer, parameter :: cctki_use_power_x = kind(power_x)
  INTEGER*4 power_y
  integer, parameter :: cctki_use_power_y = kind(power_y)
  INTEGER*4 power_z
  integer, parameter :: cctki_use_power_z = kind(power_z)
  COMMON /CarpetProlongateTestpriv/interp_xmax, interp_xmin, interp_ymax, interp_ymin, interp_zmax, interp_zmin, interpolator, inte&
  &rpolator_options, prolongation, interp_nx, interp_ny, interp_nz, power_t, power_x, power_y, power_z
    REAL*8, intent(in) :: tt
    REAL*8 :: tscale
    integer   :: n
    
    tscale = 1
    do n = 1, power_t
       tscale = tscale + tt ** n
    end do
  end function density_time_scale
  
  elemental function density_sum (xx, yy, zz) result (res)
    REAL*8 interp_xmax
  integer, parameter :: cctki_use_interp_xmax = kind(interp_xmax)
  REAL*8 interp_xmin
  integer, parameter :: cctki_use_interp_xmin = kind(interp_xmin)
  REAL*8 interp_ymax
  integer, parameter :: cctki_use_interp_ymax = kind(interp_ymax)
  REAL*8 interp_ymin
  integer, parameter :: cctki_use_interp_ymin = kind(interp_ymin)
  REAL*8 interp_zmax
  integer, parameter :: cctki_use_interp_zmax = kind(interp_zmax)
  REAL*8 interp_zmin
  integer, parameter :: cctki_use_interp_zmin = kind(interp_zmin)
  integer*8 interpolator
  integer, parameter :: cctki_use_interpolator = kind(interpolator)
  integer*8 interpolator_options
  integer, parameter :: cctki_use_interpolator_options = kind(interpolator_options)
  integer*8 prolongation
  integer, parameter :: cctki_use_prolongation = kind(prolongation)
  INTEGER*4 interp_nx
  integer, parameter :: cctki_use_interp_nx = kind(interp_nx)
  INTEGER*4 interp_ny
  integer, parameter :: cctki_use_interp_ny = kind(interp_ny)
  INTEGER*4 interp_nz
  integer, parameter :: cctki_use_interp_nz = kind(interp_nz)
  INTEGER*4 power_t
  integer, parameter :: cctki_use_power_t = kind(power_t)
  INTEGER*4 power_x
  integer, parameter :: cctki_use_power_x = kind(power_x)
  INTEGER*4 power_y
  integer, parameter :: cctki_use_power_y = kind(power_y)
  INTEGER*4 power_z
  integer, parameter :: cctki_use_power_z = kind(power_z)
  COMMON /CarpetProlongateTestpriv/interp_xmax, interp_xmin, interp_ymax, interp_ymin, interp_zmax, interp_zmin, interpolator, inte&
  &rpolator_options, prolongation, interp_nx, interp_ny, interp_nz, power_t, power_x, power_y, power_z
    INTEGER*4, parameter :: izero = 0
    REAL*8, intent(in) :: xx, yy, zz
    REAL*8 :: res
    
    res = 0 + &
         1 * density(xx,yy,zz, power_x,izero  ,izero  ) + &
         2 * density(xx,yy,zz, izero  ,power_y,izero  ) + &
         3 * density(xx,yy,zz, izero  ,izero  ,power_z) + &
         4 * density(xx,yy,zz, power_x,power_y,izero  ) + &
         5 * density(xx,yy,zz, power_x,izero  ,power_z) + &
         6 * density(xx,yy,zz, izero  ,power_y,power_z) + &
         7 * density(xx,yy,zz, power_x,power_y,power_z)
  end function density_sum
  
  
  
  elemental function density (xx, yy, zz, px, py, pz) result (res)
    REAL*8, intent(in) :: xx, yy, zz
    INTEGER*4,  intent(in) :: px, py, pz
    REAL*8 :: res
    
    REAL*8, parameter :: xmin = 0
    REAL*8, parameter :: ymin = 0
    REAL*8, parameter :: zmin = 0
    REAL*8, parameter :: xmax = 2
    REAL*8, parameter :: ymax = 2
    REAL*8, parameter :: zmax = 2
    
    REAL*8 :: integral, volume
    
    integral = &
         (xmax**(px+1) - xmin**(px+1)) / (px+1) * &
         (ymax**(py+1) - ymin**(py+1)) / (py+1) * &
         (zmax**(pz+1) - zmin**(pz+1)) / (pz+1)
    volume = (xmax - xmin) * (ymax - ymin) * (zmax - zmin)
    
    res = xx**px * yy**py * zz**pz - integral / volume
  end function density
  
end module CarpetProlongateTest



subroutine CarpetProlongateTest_Init (cctk_dim,cctk_gsh,cctk_lsh,cctk_lbnd,cctk_ubnd,cctk_tile_min,cctk_tile_max,cctk_ash,cctk_alig&
  &nment,cctk_alignment_offset,cctk_from,cctk_to,cctk_bbox,cctk_delta_time,cctk_time,cctk_delta_space,cctk_origin_space,cctk_levfac&
  &,cctk_levoff,cctk_levoffdenom,cctk_timefac,cctk_convlevel,cctk_convfac,cctk_nghostzones,cctk_iteration,cctkGH,cctk_ash1,cctk_ash&
  &2,cctk_ash3, X0interp_difference,X1interp_difference,X2interp_difference,du,du_p,du_p_p,errornorm,interp_du,interp_errornorm,int&
  &erp_u,interp_u0,interp_x,interp_y,interp_z,u,u_p,u_p_p,u0,u0_p,u0_p_p,uscaled,uscaled_p,uscaled_p_p, coarse_dx,coarse_dy,coarse_&
  &dz,r,x,y,z)
  use CarpetProlongateTest
  implicit none

  INTEGER cctk_dim
  integer, parameter :: cctki_use_cctk_dim = kind(cctk_dim)
  INTEGER cctk_gsh (cctk_dim)
  integer, parameter :: cctki_use_cctk_gsh = kind(cctk_gsh)
  INTEGER cctk_lsh (cctk_dim)
  integer, parameter :: cctki_use_cctk_lsh = kind(cctk_lsh)
  INTEGER cctk_lbnd (cctk_dim)
  integer, parameter :: cctki_use_cctk_lbnd = kind(cctk_lbnd)
  INTEGER cctk_ubnd (cctk_dim)
  integer, parameter :: cctki_use_cctk_ubnd = kind(cctk_ubnd)
  INTEGER cctk_tile_min (cctk_dim)
  integer, parameter :: cctki_use_cctk_tile_min = kind(cctk_tile_min)
  INTEGER cctk_tile_max (cctk_dim)
  integer, parameter :: cctki_use_cctk_tile_max = kind(cctk_tile_max)
  INTEGER cctk_ash (cctk_dim)
  integer, parameter :: cctki_use_cctk_ash = kind(cctk_ash)
  INTEGER cctk_alignment
  integer, parameter :: cctki_use_cctk_alignment = kind(cctk_alignment)
  INTEGER cctk_alignment_offset
  integer, parameter :: cctki_use_cctk_alignment_offset = kind(cctk_alignment_offset)
  INTEGER cctk_from (cctk_dim)
  integer, parameter :: cctki_use_cctk_from = kind(cctk_from)
  INTEGER cctk_to (cctk_dim)
  integer, parameter :: cctki_use_cctk_to = kind(cctk_to)
  INTEGER cctk_bbox (2*cctk_dim)
  integer, parameter :: cctki_use_cctk_bbox = kind(cctk_bbox)
  REAL*8 cctk_delta_time
  integer, parameter :: cctki_use_cctk_delta_time = kind(cctk_delta_time)
  REAL*8 cctk_time
  integer, parameter :: cctki_use_cctk_time = kind(cctk_time)
  REAL*8 cctk_delta_space (cctk_dim)
  integer, parameter :: cctki_use_cctk_delta_space = kind(cctk_delta_space)
  REAL*8 cctk_origin_space (cctk_dim)
  integer, parameter :: cctki_use_cctk_origin_space = kind(cctk_origin_space)
  INTEGER cctk_levfac (cctk_dim)
  integer, parameter :: cctki_use_cctk_levfac = kind(cctk_levfac)
  INTEGER cctk_levoff (cctk_dim)
  integer, parameter :: cctki_use_cctk_levoff = kind(cctk_levoff)
  INTEGER cctk_levoffdenom (cctk_dim)
  integer, parameter :: cctki_use_cctk_levoffdenom = kind(cctk_levoffdenom)
  INTEGER cctk_timefac
  integer, parameter :: cctki_use_cctk_timefac = kind(cctk_timefac)
  INTEGER cctk_convlevel
  integer, parameter :: cctki_use_cctk_convlevel = kind(cctk_convlevel)
  INTEGER cctk_convfac
  integer, parameter :: cctki_use_cctk_convfac = kind(cctk_convfac)
  INTEGER cctk_nghostzones (cctk_dim)
  integer, parameter :: cctki_use_cctk_nghostzones = kind(cctk_nghostzones)
  INTEGER cctk_iteration
  integer, parameter :: cctki_use_cctk_iteration = kind(cctk_iteration)
  integer*8 cctkGH
  integer, parameter :: cctki_use_cctkGH = kind(cctkGH)
  INTEGER cctk_ash1
  integer, parameter :: cctki_use_cctk_ash1 = kind(cctk_ash1)
  INTEGER cctk_ash2
  integer, parameter :: cctki_use_cctk_ash2 = kind(cctk_ash2)
  INTEGER cctk_ash3
  integer, parameter :: cctki_use_cctk_ash3 = kind(cctk_ash3)
  INTEGER X0interp_difference
  INTEGER X1interp_difference
  INTEGER X2interp_difference
  REAL*8 du (cctk_ash1,cctk_ash2,cctk_ash3)
  integer, parameter :: cctki_use_du = kind(du)
  REAL*8 du_p (cctk_ash1,cctk_ash2,cctk_ash3)
  integer, parameter :: cctki_use_du_p = kind(du_p)
  REAL*8 du_p_p (cctk_ash1,cctk_ash2,cctk_ash3)
  integer, parameter :: cctki_use_du_p_p = kind(du_p_p)
  REAL*8 errornorm
  integer, parameter :: cctki_use_errornorm = kind(errornorm)
  REAL*8 interp_du (X0interp_difference,X1interp_difference,X2interp_difference)
  integer, parameter :: cctki_use_interp_du = kind(interp_du)
  REAL*8 interp_errornorm
  integer, parameter :: cctki_use_interp_errornorm = kind(interp_errornorm)
  REAL*8 interp_u (X0interp_difference,X1interp_difference,X2interp_difference)
  integer, parameter :: cctki_use_interp_u = kind(interp_u)
  REAL*8 interp_u0 (X0interp_difference,X1interp_difference,X2interp_difference)
  integer, parameter :: cctki_use_interp_u0 = kind(interp_u0)
  REAL*8 interp_x (X0interp_difference,X1interp_difference,X2interp_difference)
  integer, parameter :: cctki_use_interp_x = kind(interp_x)
  REAL*8 interp_y (X0interp_difference,X1interp_difference,X2interp_difference)
  integer, parameter :: cctki_use_interp_y = kind(interp_y)
  REAL*8 interp_z (X0interp_difference,X1interp_difference,X2interp_difference)
  integer, parameter :: cctki_use_interp_z = kind(interp_z)
  REAL*8 u (cctk_ash1,cctk_ash2,cctk_ash3)
  integer, parameter :: cctki_use_u = kind(u)
  REAL*8 u_p (cctk_ash1,cctk_ash2,cctk_ash3)
  integer, parameter :: cctki_use_u_p = kind(u_p)
  REAL*8 u_p_p (cctk_ash1,cctk_ash2,cctk_ash3)
  integer, parameter :: cctki_use_u_p_p = kind(u_p_p)
  REAL*8 u0 (cctk_ash1,cctk_ash2,cctk_ash3)
  integer, parameter :: cctki_use_u0 = kind(u0)
  REAL*8 u0_p (cctk_ash1,cctk_ash2,cctk_ash3)
  integer, parameter :: cctki_use_u0_p = kind(u0_p)
  REAL*8 u0_p_p (cctk_ash1,cctk_ash2,cctk_ash3)
  integer, parameter :: cctki_use_u0_p_p = kind(u0_p_p)
  REAL*8 uscaled (cctk_ash1,cctk_ash2,cctk_ash3)
  integer, parameter :: cctki_use_uscaled = kind(uscaled)
  REAL*8 uscaled_p (cctk_ash1,cctk_ash2,cctk_ash3)
  integer, parameter :: cctki_use_uscaled_p = kind(uscaled_p)
  REAL*8 uscaled_p_p (cctk_ash1,cctk_ash2,cctk_ash3)
  integer, parameter :: cctki_use_uscaled_p_p = kind(uscaled_p_p)
  REAL*8 coarse_dx
  integer, parameter :: cctki_use_coarse_dx = kind(coarse_dx)
  REAL*8 coarse_dy
  integer, parameter :: cctki_use_coarse_dy = kind(coarse_dy)
  REAL*8 coarse_dz
  integer, parameter :: cctki_use_coarse_dz = kind(coarse_dz)
  REAL*8 r (cctk_ash1,cctk_ash2,cctk_ash3)
  integer, parameter :: cctki_use_r = kind(r)
  REAL*8 x (cctk_ash1,cctk_ash2,cctk_ash3)
  integer, parameter :: cctki_use_x = kind(x)
  REAL*8 y (cctk_ash1,cctk_ash2,cctk_ash3)
  integer, parameter :: cctki_use_y = kind(y)
  REAL*8 z (cctk_ash1,cctk_ash2,cctk_ash3)
  integer, parameter :: cctki_use_z = kind(z)
  REAL*8 interp_xmax
  integer, parameter :: cctki_use_interp_xmax = kind(interp_xmax)
  REAL*8 interp_xmin
  integer, parameter :: cctki_use_interp_xmin = kind(interp_xmin)
  REAL*8 interp_ymax
  integer, parameter :: cctki_use_interp_ymax = kind(interp_ymax)
  REAL*8 interp_ymin
  integer, parameter :: cctki_use_interp_ymin = kind(interp_ymin)
  REAL*8 interp_zmax
  integer, parameter :: cctki_use_interp_zmax = kind(interp_zmax)
  REAL*8 interp_zmin
  integer, parameter :: cctki_use_interp_zmin = kind(interp_zmin)
  integer*8 interpolator
  integer, parameter :: cctki_use_interpolator = kind(interpolator)
  integer*8 interpolator_options
  integer, parameter :: cctki_use_interpolator_options = kind(interpolator_options)
  integer*8 prolongation
  integer, parameter :: cctki_use_prolongation = kind(prolongation)
  INTEGER*4 interp_nx
  integer, parameter :: cctki_use_interp_nx = kind(interp_nx)
  INTEGER*4 interp_ny
  integer, parameter :: cctki_use_interp_ny = kind(interp_ny)
  INTEGER*4 interp_nz
  integer, parameter :: cctki_use_interp_nz = kind(interp_nz)
  INTEGER*4 power_t
  integer, parameter :: cctki_use_power_t = kind(power_t)
  INTEGER*4 power_x
  integer, parameter :: cctki_use_power_x = kind(power_x)
  INTEGER*4 power_y
  integer, parameter :: cctki_use_power_y = kind(power_y)
  INTEGER*4 power_z
  integer, parameter :: cctki_use_power_z = kind(power_z)
  COMMON /CarpetProlongateTestpriv/interp_xmax, interp_xmin, interp_ymax, interp_ymin, interp_zmax, interp_zmin, interpolator, inte&
  &rpolator_options, prolongation, interp_nx, interp_ny, interp_nz, power_t, power_x, power_y, power_z
  


  
  
  
  u = density_time_scale(cctk_time) * density_sum(x+1,y+1,z+1)
  
  uscaled = u * product(cctk_delta_space(:))
end subroutine CarpetProlongateTest_Init



subroutine CarpetProlongateTest_Diff (cctk_dim,cctk_gsh,cctk_lsh,cctk_lbnd,cctk_ubnd,cctk_tile_min,cctk_tile_max,cctk_ash,cctk_alig&
  &nment,cctk_alignment_offset,cctk_from,cctk_to,cctk_bbox,cctk_delta_time,cctk_time,cctk_delta_space,cctk_origin_space,cctk_levfac&
  &,cctk_levoff,cctk_levoffdenom,cctk_timefac,cctk_convlevel,cctk_convfac,cctk_nghostzones,cctk_iteration,cctkGH,cctk_ash1,cctk_ash&
  &2,cctk_ash3, X0interp_difference,X1interp_difference,X2interp_difference,du,du_p,du_p_p,errornorm,interp_du,interp_errornorm,int&
  &erp_u,interp_u0,interp_x,interp_y,interp_z,u,u_p,u_p_p,u0,u0_p,u0_p_p,uscaled,uscaled_p,uscaled_p_p, coarse_dx,coarse_dy,coarse_&
  &dz,r,x,y,z)
  use CarpetProlongateTest
  implicit none

  INTEGER cctk_dim
  integer, parameter :: cctki_use_cctk_dim = kind(cctk_dim)
  INTEGER cctk_gsh (cctk_dim)
  integer, parameter :: cctki_use_cctk_gsh = kind(cctk_gsh)
  INTEGER cctk_lsh (cctk_dim)
  integer, parameter :: cctki_use_cctk_lsh = kind(cctk_lsh)
  INTEGER cctk_lbnd (cctk_dim)
  integer, parameter :: cctki_use_cctk_lbnd = kind(cctk_lbnd)
  INTEGER cctk_ubnd (cctk_dim)
  integer, parameter :: cctki_use_cctk_ubnd = kind(cctk_ubnd)
  INTEGER cctk_tile_min (cctk_dim)
  integer, parameter :: cctki_use_cctk_tile_min = kind(cctk_tile_min)
  INTEGER cctk_tile_max (cctk_dim)
  integer, parameter :: cctki_use_cctk_tile_max = kind(cctk_tile_max)
  INTEGER cctk_ash (cctk_dim)
  integer, parameter :: cctki_use_cctk_ash = kind(cctk_ash)
  INTEGER cctk_alignment
  integer, parameter :: cctki_use_cctk_alignment = kind(cctk_alignment)
  INTEGER cctk_alignment_offset
  integer, parameter :: cctki_use_cctk_alignment_offset = kind(cctk_alignment_offset)
  INTEGER cctk_from (cctk_dim)
  integer, parameter :: cctki_use_cctk_from = kind(cctk_from)
  INTEGER cctk_to (cctk_dim)
  integer, parameter :: cctki_use_cctk_to = kind(cctk_to)
  INTEGER cctk_bbox (2*cctk_dim)
  integer, parameter :: cctki_use_cctk_bbox = kind(cctk_bbox)
  REAL*8 cctk_delta_time
  integer, parameter :: cctki_use_cctk_delta_time = kind(cctk_delta_time)
  REAL*8 cctk_time
  integer, parameter :: cctki_use_cctk_time = kind(cctk_time)
  REAL*8 cctk_delta_space (cctk_dim)
  integer, parameter :: cctki_use_cctk_delta_space = kind(cctk_delta_space)
  REAL*8 cctk_origin_space (cctk_dim)
  integer, parameter :: cctki_use_cctk_origin_space = kind(cctk_origin_space)
  INTEGER cctk_levfac (cctk_dim)
  integer, parameter :: cctki_use_cctk_levfac = kind(cctk_levfac)
  INTEGER cctk_levoff (cctk_dim)
  integer, parameter :: cctki_use_cctk_levoff = kind(cctk_levoff)
  INTEGER cctk_levoffdenom (cctk_dim)
  integer, parameter :: cctki_use_cctk_levoffdenom = kind(cctk_levoffdenom)
  INTEGER cctk_timefac
  integer, parameter :: cctki_use_cctk_timefac = kind(cctk_timefac)
  INTEGER cctk_convlevel
  integer, parameter :: cctki_use_cctk_convlevel = kind(cctk_convlevel)
  INTEGER cctk_convfac
  integer, parameter :: cctki_use_cctk_convfac = kind(cctk_convfac)
  INTEGER cctk_nghostzones (cctk_dim)
  integer, parameter :: cctki_use_cctk_nghostzones = kind(cctk_nghostzones)
  INTEGER cctk_iteration
  integer, parameter :: cctki_use_cctk_iteration = kind(cctk_iteration)
  integer*8 cctkGH
  integer, parameter :: cctki_use_cctkGH = kind(cctkGH)
  INTEGER cctk_ash1
  integer, parameter :: cctki_use_cctk_ash1 = kind(cctk_ash1)
  INTEGER cctk_ash2
  integer, parameter :: cctki_use_cctk_ash2 = kind(cctk_ash2)
  INTEGER cctk_ash3
  integer, parameter :: cctki_use_cctk_ash3 = kind(cctk_ash3)
  INTEGER X0interp_difference
  INTEGER X1interp_difference
  INTEGER X2interp_difference
  REAL*8 du (cctk_ash1,cctk_ash2,cctk_ash3)
  integer, parameter :: cctki_use_du = kind(du)
  REAL*8 du_p (cctk_ash1,cctk_ash2,cctk_ash3)
  integer, parameter :: cctki_use_du_p = kind(du_p)
  REAL*8 du_p_p (cctk_ash1,cctk_ash2,cctk_ash3)
  integer, parameter :: cctki_use_du_p_p = kind(du_p_p)
  REAL*8 errornorm
  integer, parameter :: cctki_use_errornorm = kind(errornorm)
  REAL*8 interp_du (X0interp_difference,X1interp_difference,X2interp_difference)
  integer, parameter :: cctki_use_interp_du = kind(interp_du)
  REAL*8 interp_errornorm
  integer, parameter :: cctki_use_interp_errornorm = kind(interp_errornorm)
  REAL*8 interp_u (X0interp_difference,X1interp_difference,X2interp_difference)
  integer, parameter :: cctki_use_interp_u = kind(interp_u)
  REAL*8 interp_u0 (X0interp_difference,X1interp_difference,X2interp_difference)
  integer, parameter :: cctki_use_interp_u0 = kind(interp_u0)
  REAL*8 interp_x (X0interp_difference,X1interp_difference,X2interp_difference)
  integer, parameter :: cctki_use_interp_x = kind(interp_x)
  REAL*8 interp_y (X0interp_difference,X1interp_difference,X2interp_difference)
  integer, parameter :: cctki_use_interp_y = kind(interp_y)
  REAL*8 interp_z (X0interp_difference,X1interp_difference,X2interp_difference)
  integer, parameter :: cctki_use_interp_z = kind(interp_z)
  REAL*8 u (cctk_ash1,cctk_ash2,cctk_ash3)
  integer, parameter :: cctki_use_u = kind(u)
  REAL*8 u_p (cctk_ash1,cctk_ash2,cctk_ash3)
  integer, parameter :: cctki_use_u_p = kind(u_p)
  REAL*8 u_p_p (cctk_ash1,cctk_ash2,cctk_ash3)
  integer, parameter :: cctki_use_u_p_p = kind(u_p_p)
  REAL*8 u0 (cctk_ash1,cctk_ash2,cctk_ash3)
  integer, parameter :: cctki_use_u0 = kind(u0)
  REAL*8 u0_p (cctk_ash1,cctk_ash2,cctk_ash3)
  integer, parameter :: cctki_use_u0_p = kind(u0_p)
  REAL*8 u0_p_p (cctk_ash1,cctk_ash2,cctk_ash3)
  integer, parameter :: cctki_use_u0_p_p = kind(u0_p_p)
  REAL*8 uscaled (cctk_ash1,cctk_ash2,cctk_ash3)
  integer, parameter :: cctki_use_uscaled = kind(uscaled)
  REAL*8 uscaled_p (cctk_ash1,cctk_ash2,cctk_ash3)
  integer, parameter :: cctki_use_uscaled_p = kind(uscaled_p)
  REAL*8 uscaled_p_p (cctk_ash1,cctk_ash2,cctk_ash3)
  integer, parameter :: cctki_use_uscaled_p_p = kind(uscaled_p_p)
  REAL*8 coarse_dx
  integer, parameter :: cctki_use_coarse_dx = kind(coarse_dx)
  REAL*8 coarse_dy
  integer, parameter :: cctki_use_coarse_dy = kind(coarse_dy)
  REAL*8 coarse_dz
  integer, parameter :: cctki_use_coarse_dz = kind(coarse_dz)
  REAL*8 r (cctk_ash1,cctk_ash2,cctk_ash3)
  integer, parameter :: cctki_use_r = kind(r)
  REAL*8 x (cctk_ash1,cctk_ash2,cctk_ash3)
  integer, parameter :: cctki_use_x = kind(x)
  REAL*8 y (cctk_ash1,cctk_ash2,cctk_ash3)
  integer, parameter :: cctki_use_y = kind(y)
  REAL*8 z (cctk_ash1,cctk_ash2,cctk_ash3)
  integer, parameter :: cctki_use_z = kind(z)
  
  u0 = density_time_scale(cctk_time) * density_sum(x+1,y+1,z+1)
  du = u - u0
end subroutine CarpetProlongateTest_Diff



subroutine CarpetProlongateTest_InterpInit (cctk_dim,cctk_gsh,cctk_lsh,cctk_lbnd,cctk_ubnd,cctk_tile_min,cctk_tile_max,cctk_ash,cct&
  &k_alignment,cctk_alignment_offset,cctk_from,cctk_to,cctk_bbox,cctk_delta_time,cctk_time,cctk_delta_space,cctk_origin_space,cctk_&
  &levfac,cctk_levoff,cctk_levoffdenom,cctk_timefac,cctk_convlevel,cctk_convfac,cctk_nghostzones,cctk_iteration,cctkGH,cctk_ash1,cc&
  &tk_ash2,cctk_ash3, X0interp_difference,X1interp_difference,X2interp_difference,du,du_p,du_p_p,errornorm,interp_du,interp_errorno&
  &rm,interp_u,interp_u0,interp_x,interp_y,interp_z,u,u_p,u_p_p,u0,u0_p,u0_p_p,uscaled,uscaled_p,uscaled_p_p, coarse_dx,coarse_dy,c&
  &oarse_dz,r,x,y,z)
  implicit none

  INTEGER cctk_dim
  integer, parameter :: cctki_use_cctk_dim = kind(cctk_dim)
  INTEGER cctk_gsh (cctk_dim)
  integer, parameter :: cctki_use_cctk_gsh = kind(cctk_gsh)
  INTEGER cctk_lsh (cctk_dim)
  integer, parameter :: cctki_use_cctk_lsh = kind(cctk_lsh)
  INTEGER cctk_lbnd (cctk_dim)
  integer, parameter :: cctki_use_cctk_lbnd = kind(cctk_lbnd)
  INTEGER cctk_ubnd (cctk_dim)
  integer, parameter :: cctki_use_cctk_ubnd = kind(cctk_ubnd)
  INTEGER cctk_tile_min (cctk_dim)
  integer, parameter :: cctki_use_cctk_tile_min = kind(cctk_tile_min)
  INTEGER cctk_tile_max (cctk_dim)
  integer, parameter :: cctki_use_cctk_tile_max = kind(cctk_tile_max)
  INTEGER cctk_ash (cctk_dim)
  integer, parameter :: cctki_use_cctk_ash = kind(cctk_ash)
  INTEGER cctk_alignment
  integer, parameter :: cctki_use_cctk_alignment = kind(cctk_alignment)
  INTEGER cctk_alignment_offset
  integer, parameter :: cctki_use_cctk_alignment_offset = kind(cctk_alignment_offset)
  INTEGER cctk_from (cctk_dim)
  integer, parameter :: cctki_use_cctk_from = kind(cctk_from)
  INTEGER cctk_to (cctk_dim)
  integer, parameter :: cctki_use_cctk_to = kind(cctk_to)
  INTEGER cctk_bbox (2*cctk_dim)
  integer, parameter :: cctki_use_cctk_bbox = kind(cctk_bbox)
  REAL*8 cctk_delta_time
  integer, parameter :: cctki_use_cctk_delta_time = kind(cctk_delta_time)
  REAL*8 cctk_time
  integer, parameter :: cctki_use_cctk_time = kind(cctk_time)
  REAL*8 cctk_delta_space (cctk_dim)
  integer, parameter :: cctki_use_cctk_delta_space = kind(cctk_delta_space)
  REAL*8 cctk_origin_space (cctk_dim)
  integer, parameter :: cctki_use_cctk_origin_space = kind(cctk_origin_space)
  INTEGER cctk_levfac (cctk_dim)
  integer, parameter :: cctki_use_cctk_levfac = kind(cctk_levfac)
  INTEGER cctk_levoff (cctk_dim)
  integer, parameter :: cctki_use_cctk_levoff = kind(cctk_levoff)
  INTEGER cctk_levoffdenom (cctk_dim)
  integer, parameter :: cctki_use_cctk_levoffdenom = kind(cctk_levoffdenom)
  INTEGER cctk_timefac
  integer, parameter :: cctki_use_cctk_timefac = kind(cctk_timefac)
  INTEGER cctk_convlevel
  integer, parameter :: cctki_use_cctk_convlevel = kind(cctk_convlevel)
  INTEGER cctk_convfac
  integer, parameter :: cctki_use_cctk_convfac = kind(cctk_convfac)
  INTEGER cctk_nghostzones (cctk_dim)
  integer, parameter :: cctki_use_cctk_nghostzones = kind(cctk_nghostzones)
  INTEGER cctk_iteration
  integer, parameter :: cctki_use_cctk_iteration = kind(cctk_iteration)
  integer*8 cctkGH
  integer, parameter :: cctki_use_cctkGH = kind(cctkGH)
  INTEGER cctk_ash1
  integer, parameter :: cctki_use_cctk_ash1 = kind(cctk_ash1)
  INTEGER cctk_ash2
  integer, parameter :: cctki_use_cctk_ash2 = kind(cctk_ash2)
  INTEGER cctk_ash3
  integer, parameter :: cctki_use_cctk_ash3 = kind(cctk_ash3)
  integer :: x0interp_difference
  integer :: x1interp_difference
  integer :: x2interp_difference
  REAL*8 :: interp_x (x0interp_difference,x1interp_difference,x2interp_difference)
  integer, parameter :: cctki_use_interp_x = kind(interp_x)
  REAL*8 :: interp_y (x0interp_difference,x1interp_difference,x2interp_difference)
  integer, parameter :: cctki_use_interp_y = kind(interp_y)
  REAL*8 :: interp_z (x0interp_difference,x1interp_difference,x2interp_difference)
  integer, parameter :: cctki_use_interp_z = kind(interp_z)
  characTer*8, intent(IN) :: du
  integer, parameter :: cctki_use_du = kind(du)
  characTer*8, intent(IN) :: du_p
  integer, parameter :: cctki_use_du_p = kind(du_p)
  characTer*8, intent(IN) :: du_p_p
  integer, parameter :: cctki_use_du_p_p = kind(du_p_p)
  characTer*8, intent(IN) :: errornorm
  integer, parameter :: cctki_use_errornorm = kind(errornorm)
  characTer*8, intent(IN) :: interp_du
  integer, parameter :: cctki_use_interp_du = kind(interp_du)
  characTer*8, intent(IN) :: interp_errornorm
  integer, parameter :: cctki_use_interp_errornorm = kind(interp_errornorm)
  characTer*8, intent(IN) :: interp_u
  integer, parameter :: cctki_use_interp_u = kind(interp_u)
  characTer*8, intent(IN) :: interp_u0
  integer, parameter :: cctki_use_interp_u0 = kind(interp_u0)
  characTer*8, intent(IN) :: u
  integer, parameter :: cctki_use_u = kind(u)
  characTer*8, intent(IN) :: u_p
  integer, parameter :: cctki_use_u_p = kind(u_p)
  characTer*8, intent(IN) :: u_p_p
  integer, parameter :: cctki_use_u_p_p = kind(u_p_p)
  characTer*8, intent(IN) :: u0
  integer, parameter :: cctki_use_u0 = kind(u0)
  characTer*8, intent(IN) :: u0_p
  integer, parameter :: cctki_use_u0_p = kind(u0_p)
  characTer*8, intent(IN) :: u0_p_p
  integer, parameter :: cctki_use_u0_p_p = kind(u0_p_p)
  characTer*8, intent(IN) :: uscaled
  integer, parameter :: cctki_use_uscaled = kind(uscaled)
  characTer*8, intent(IN) :: uscaled_p
  integer, parameter :: cctki_use_uscaled_p = kind(uscaled_p)
  characTer*8, intent(IN) :: uscaled_p_p
  integer, parameter :: cctki_use_uscaled_p_p = kind(uscaled_p_p)
  characTer*8, intent(IN) :: coarse_dx
  integer, parameter :: cctki_use_coarse_dx = kind(coarse_dx)
  characTer*8, intent(IN) :: coarse_dy
  integer, parameter :: cctki_use_coarse_dy = kind(coarse_dy)
  characTer*8, intent(IN) :: coarse_dz
  integer, parameter :: cctki_use_coarse_dz = kind(coarse_dz)
  characTer*8, intent(IN) :: r
  integer, parameter :: cctki_use_r = kind(r)
  characTer*8, intent(IN) :: x
  integer, parameter :: cctki_use_x = kind(x)
  characTer*8, intent(IN) :: y
  integer, parameter :: cctki_use_y = kind(y)
  characTer*8, intent(IN) :: z
  integer, parameter :: cctki_use_z = kind(z)
  REAL*8 interp_xmax
  integer, parameter :: cctki_use_interp_xmax = kind(interp_xmax)
  REAL*8 interp_xmin
  integer, parameter :: cctki_use_interp_xmin = kind(interp_xmin)
  REAL*8 interp_ymax
  integer, parameter :: cctki_use_interp_ymax = kind(interp_ymax)
  REAL*8 interp_ymin
  integer, parameter :: cctki_use_interp_ymin = kind(interp_ymin)
  REAL*8 interp_zmax
  integer, parameter :: cctki_use_interp_zmax = kind(interp_zmax)
  REAL*8 interp_zmin
  integer, parameter :: cctki_use_interp_zmin = kind(interp_zmin)
  integer*8 interpolator
  integer, parameter :: cctki_use_interpolator = kind(interpolator)
  integer*8 interpolator_options
  integer, parameter :: cctki_use_interpolator_options = kind(interpolator_options)
  integer*8 prolongation
  integer, parameter :: cctki_use_prolongation = kind(prolongation)
  INTEGER*4 interp_nx
  integer, parameter :: cctki_use_interp_nx = kind(interp_nx)
  INTEGER*4 interp_ny
  integer, parameter :: cctki_use_interp_ny = kind(interp_ny)
  INTEGER*4 interp_nz
  integer, parameter :: cctki_use_interp_nz = kind(interp_nz)
  INTEGER*4 power_t
  integer, parameter :: cctki_use_power_t = kind(power_t)
  INTEGER*4 power_x
  integer, parameter :: cctki_use_power_x = kind(power_x)
  INTEGER*4 power_y
  integer, parameter :: cctki_use_power_y = kind(power_y)
  INTEGER*4 power_z
  integer, parameter :: cctki_use_power_z = kind(power_z)
  COMMON /CarpetProlongateTestpriv/interp_xmax, interp_xmin, interp_ymax, interp_ymin, interp_zmax, interp_zmin, interpolator, inte&
  &rpolator_options, prolongation, interp_nx, interp_ny, interp_nz, power_t, power_x, power_y, power_z
  
  REAL*8 :: dx, dy, dz
  integer   :: lbnd(3), lsh(3), gsh(3)
  integer   :: i,j,k
  integer   :: ierr
  


  
  call CCTK_GrouplbndGN (ierr, cctkGH, 3, lbnd, "CarpetProlongateTest::interp_difference")
  if (ierr/=0) call CCTK_Warn(0,116,"init.F90","CarpetProlongateTest", "internal error")
  call CCTK_GrouplshGN  (ierr, cctkGH, 3, lsh , "CarpetProlongateTest::interp_difference")
  if (ierr/=0) call CCTK_Warn(0,118,"init.F90","CarpetProlongateTest", "internal error")
  call CCTK_GroupgshGN  (ierr, cctkGH, 3, gsh , "CarpetProlongateTest::interp_difference")
  if (ierr/=0) call CCTK_Warn(0,120,"init.F90","CarpetProlongateTest", "internal error")
  
  dx = (interp_xmax - interp_xmin) / (gsh(1)-1)
  dy = (interp_ymax - interp_ymin) / (gsh(2)-1)
  dz = (interp_zmax - interp_zmin) / (gsh(3)-1)
  
  do k=1,lsh(3)
     do j=1,lsh(2)
        do i=1,lsh(1)
           interp_x(i,j,k) = interp_xmin + (lbnd(1)+i-1) * dx
           interp_y(i,j,k) = interp_ymin + (lbnd(2)+j-1) * dy
           interp_z(i,j,k) = interp_zmin + (lbnd(3)+k-1) * dz
        end do
     end do
  end do
end subroutine CarpetProlongateTest_InterpInit

subroutine CarpetProlongateTest_Interp (cctk_dim,cctk_gsh,cctk_lsh,cctk_lbnd,cctk_ubnd,cctk_tile_min,cctk_tile_max,cctk_ash,cctk_al&
  &ignment,cctk_alignment_offset,cctk_from,cctk_to,cctk_bbox,cctk_delta_time,cctk_time,cctk_delta_space,cctk_origin_space,cctk_levf&
  &ac,cctk_levoff,cctk_levoffdenom,cctk_timefac,cctk_convlevel,cctk_convfac,cctk_nghostzones,cctk_iteration,cctkGH,cctk_ash1,cctk_a&
  &sh2,cctk_ash3, X0interp_difference,X1interp_difference,X2interp_difference,du,du_p,du_p_p,errornorm,interp_du,interp_errornorm,i&
  &nterp_u,interp_u0,interp_x,interp_y,interp_z,u,u_p,u_p_p,u0,u0_p,u0_p_p,uscaled,uscaled_p,uscaled_p_p, coarse_dx,coarse_dy,coars&
  &e_dz,r,x,y,z)
  use cctk
  implicit none

  INTEGER cctk_dim
  integer, parameter :: cctki_use_cctk_dim = kind(cctk_dim)
  INTEGER cctk_gsh (cctk_dim)
  integer, parameter :: cctki_use_cctk_gsh = kind(cctk_gsh)
  INTEGER cctk_lsh (cctk_dim)
  integer, parameter :: cctki_use_cctk_lsh = kind(cctk_lsh)
  INTEGER cctk_lbnd (cctk_dim)
  integer, parameter :: cctki_use_cctk_lbnd = kind(cctk_lbnd)
  INTEGER cctk_ubnd (cctk_dim)
  integer, parameter :: cctki_use_cctk_ubnd = kind(cctk_ubnd)
  INTEGER cctk_tile_min (cctk_dim)
  integer, parameter :: cctki_use_cctk_tile_min = kind(cctk_tile_min)
  INTEGER cctk_tile_max (cctk_dim)
  integer, parameter :: cctki_use_cctk_tile_max = kind(cctk_tile_max)
  INTEGER cctk_ash (cctk_dim)
  integer, parameter :: cctki_use_cctk_ash = kind(cctk_ash)
  INTEGER cctk_alignment
  integer, parameter :: cctki_use_cctk_alignment = kind(cctk_alignment)
  INTEGER cctk_alignment_offset
  integer, parameter :: cctki_use_cctk_alignment_offset = kind(cctk_alignment_offset)
  INTEGER cctk_from (cctk_dim)
  integer, parameter :: cctki_use_cctk_from = kind(cctk_from)
  INTEGER cctk_to (cctk_dim)
  integer, parameter :: cctki_use_cctk_to = kind(cctk_to)
  INTEGER cctk_bbox (2*cctk_dim)
  integer, parameter :: cctki_use_cctk_bbox = kind(cctk_bbox)
  REAL*8 cctk_delta_time
  integer, parameter :: cctki_use_cctk_delta_time = kind(cctk_delta_time)
  REAL*8 cctk_time
  integer, parameter :: cctki_use_cctk_time = kind(cctk_time)
  REAL*8 cctk_delta_space (cctk_dim)
  integer, parameter :: cctki_use_cctk_delta_space = kind(cctk_delta_space)
  REAL*8 cctk_origin_space (cctk_dim)
  integer, parameter :: cctki_use_cctk_origin_space = kind(cctk_origin_space)
  INTEGER cctk_levfac (cctk_dim)
  integer, parameter :: cctki_use_cctk_levfac = kind(cctk_levfac)
  INTEGER cctk_levoff (cctk_dim)
  integer, parameter :: cctki_use_cctk_levoff = kind(cctk_levoff)
  INTEGER cctk_levoffdenom (cctk_dim)
  integer, parameter :: cctki_use_cctk_levoffdenom = kind(cctk_levoffdenom)
  INTEGER cctk_timefac
  integer, parameter :: cctki_use_cctk_timefac = kind(cctk_timefac)
  INTEGER cctk_convlevel
  integer, parameter :: cctki_use_cctk_convlevel = kind(cctk_convlevel)
  INTEGER cctk_convfac
  integer, parameter :: cctki_use_cctk_convfac = kind(cctk_convfac)
  INTEGER cctk_nghostzones (cctk_dim)
  integer, parameter :: cctki_use_cctk_nghostzones = kind(cctk_nghostzones)
  INTEGER cctk_iteration
  integer, parameter :: cctki_use_cctk_iteration = kind(cctk_iteration)
  integer*8 cctkGH
  integer, parameter :: cctki_use_cctkGH = kind(cctkGH)
  INTEGER cctk_ash1
  integer, parameter :: cctki_use_cctk_ash1 = kind(cctk_ash1)
  INTEGER cctk_ash2
  integer, parameter :: cctki_use_cctk_ash2 = kind(cctk_ash2)
  INTEGER cctk_ash3
  integer, parameter :: cctki_use_cctk_ash3 = kind(cctk_ash3)
  integer :: x0interp_difference
  integer :: x1interp_difference
  integer :: x2interp_difference
  REAL*8 :: interp_u (x0interp_difference,x1interp_difference,x2interp_difference)
  integer, parameter :: cctki_use_interp_u = kind(interp_u)
  REAL*8, iNteNt(iN) :: interp_x (x0interp_difference,x1interp_difference,x2interp_difference)
  integer, parameter :: cctki_use_interp_x = kind(interp_x)
  REAL*8, iNteNt(iN) :: interp_y (x0interp_difference,x1interp_difference,x2interp_difference)
  integer, parameter :: cctki_use_interp_y = kind(interp_y)
  REAL*8, iNteNt(iN) :: interp_z (x0interp_difference,x1interp_difference,x2interp_difference)
  integer, parameter :: cctki_use_interp_z = kind(interp_z)
  characTer*8, intent(IN) :: du
  integer, parameter :: cctki_use_du = kind(du)
  characTer*8, intent(IN) :: du_p
  integer, parameter :: cctki_use_du_p = kind(du_p)
  characTer*8, intent(IN) :: du_p_p
  integer, parameter :: cctki_use_du_p_p = kind(du_p_p)
  characTer*8, intent(IN) :: errornorm
  integer, parameter :: cctki_use_errornorm = kind(errornorm)
  characTer*8, intent(IN) :: interp_du
  integer, parameter :: cctki_use_interp_du = kind(interp_du)
  characTer*8, intent(IN) :: interp_errornorm
  integer, parameter :: cctki_use_interp_errornorm = kind(interp_errornorm)
  characTer*8, intent(IN) :: interp_u0
  integer, parameter :: cctki_use_interp_u0 = kind(interp_u0)
  characTer*8, intent(IN) :: u
  integer, parameter :: cctki_use_u = kind(u)
  characTer*8, intent(IN) :: u_p
  integer, parameter :: cctki_use_u_p = kind(u_p)
  characTer*8, intent(IN) :: u_p_p
  integer, parameter :: cctki_use_u_p_p = kind(u_p_p)
  characTer*8, intent(IN) :: u0
  integer, parameter :: cctki_use_u0 = kind(u0)
  characTer*8, intent(IN) :: u0_p
  integer, parameter :: cctki_use_u0_p = kind(u0_p)
  characTer*8, intent(IN) :: u0_p_p
  integer, parameter :: cctki_use_u0_p_p = kind(u0_p_p)
  characTer*8, intent(IN) :: uscaled
  integer, parameter :: cctki_use_uscaled = kind(uscaled)
  characTer*8, intent(IN) :: uscaled_p
  integer, parameter :: cctki_use_uscaled_p = kind(uscaled_p)
  characTer*8, intent(IN) :: uscaled_p_p
  integer, parameter :: cctki_use_uscaled_p_p = kind(uscaled_p_p)
  characTer*8, intent(IN) :: coarse_dx
  integer, parameter :: cctki_use_coarse_dx = kind(coarse_dx)
  characTer*8, intent(IN) :: coarse_dy
  integer, parameter :: cctki_use_coarse_dy = kind(coarse_dy)
  characTer*8, intent(IN) :: coarse_dz
  integer, parameter :: cctki_use_coarse_dz = kind(coarse_dz)
  characTer*8, intent(IN) :: r
  integer, parameter :: cctki_use_r = kind(r)
  characTer*8, intent(IN) :: x
  integer, parameter :: cctki_use_x = kind(x)
  characTer*8, intent(IN) :: y
  integer, parameter :: cctki_use_y = kind(y)
  characTer*8, intent(IN) :: z
  integer, parameter :: cctki_use_z = kind(z)
  interface
  integer*8 function CCTK_PointerTo (var)
  implicit none
  type(*),dimension(..),TARGET :: var
  end function CCTK_PointerTo
  end interface
  interface
  integer function CCTK_Equals (arg1, arg2)
  implicit none
  integer*8 arg1
  character(*) arg2
  end function CCTK_Equals
  integer function CCTK_MyProc (cctkGH)
  implicit none
  integer*8 cctkGH
  end function CCTK_MyProc
  integer function CCTK_nProcs (cctkGH)
  implicit none
  integer*8 cctkGH
  end function CCTK_nProcs
  integer function CCTK_IsThornActive (name)
  implicit none
  character(*) name
  end function CCTK_IsThornActive
  integer*8 function CCTK_NullPointer ()
  implicit none
  end function CCTK_NullPointer
  end interface
  REAL*8 interp_xmax
  integer, parameter :: cctki_use_interp_xmax = kind(interp_xmax)
  REAL*8 interp_xmin
  integer, parameter :: cctki_use_interp_xmin = kind(interp_xmin)
  REAL*8 interp_ymax
  integer, parameter :: cctki_use_interp_ymax = kind(interp_ymax)
  REAL*8 interp_ymin
  integer, parameter :: cctki_use_interp_ymin = kind(interp_ymin)
  REAL*8 interp_zmax
  integer, parameter :: cctki_use_interp_zmax = kind(interp_zmax)
  REAL*8 interp_zmin
  integer, parameter :: cctki_use_interp_zmin = kind(interp_zmin)
  integer*8 interpolator
  integer, parameter :: cctki_use_interpolator = kind(interpolator)
  integer*8 interpolator_options
  integer, parameter :: cctki_use_interpolator_options = kind(interpolator_options)
  integer*8 prolongation
  integer, parameter :: cctki_use_prolongation = kind(prolongation)
  INTEGER*4 interp_nx
  integer, parameter :: cctki_use_interp_nx = kind(interp_nx)
  INTEGER*4 interp_ny
  integer, parameter :: cctki_use_interp_ny = kind(interp_ny)
  INTEGER*4 interp_nz
  integer, parameter :: cctki_use_interp_nz = kind(interp_nz)
  INTEGER*4 power_t
  integer, parameter :: cctki_use_power_t = kind(power_t)
  INTEGER*4 power_x
  integer, parameter :: cctki_use_power_x = kind(power_x)
  INTEGER*4 power_y
  integer, parameter :: cctki_use_power_y = kind(power_y)
  INTEGER*4 power_z
  integer, parameter :: cctki_use_power_z = kind(power_z)
  COMMON /CarpetProlongateTestpriv/interp_xmax, interp_xmin, interp_ymax, interp_ymin, interp_zmax, interp_zmin, interpolator, inte&
  &rpolator_options, prolongation, interp_nx, interp_ny, interp_nz, power_t, power_x, power_y, power_z
  
  integer :: lsh(3)
  
  integer   :: len_interpolator
  integer   :: len_interpolator_options
  character :: fort_interpolator*100
  character :: fort_interpolator_options*1000
  integer   :: coord_handle
  integer   :: interp_handle
  integer   :: options_table
  
  integer      :: coord_type
  integer*8 :: coords(3)
  integer      :: ninputs
  INTEGER*4     :: inputs(1)
  integer      :: input 

  integer      :: noutputs
  INTEGER*4     :: output_types(1)
  integer*8 :: outputs(1)
  integer      :: npoints
  
  integer :: ierr
  


  
  call CCTK_GrouplshGN (ierr, cctkGH, 3, lsh, "CarpetProlongateTest::interp_difference")
  if (ierr/=0) call CCTK_Warn(0,171,"init.F90","CarpetProlongateTest", "internal error")
  
  
  call CCTK_CoordSystemHandle (coord_handle, "cart3d")
  if (coord_handle<0) then
     call CCTK_Warn(0,176,"init.F90","CarpetProlongateTest", "Could not obtain coordinate system handle")
  end if
  
  
  call CCTK_FortranString &
       (len_interpolator, interpolator, fort_interpolator)
  call CCTK_InterpHandle (interp_handle, fort_interpolator)
  if (interp_handle<0) then
     call CCTK_Warn(0,184,"init.F90","CarpetProlongateTest", "Could not obtain interpolator handle")
  end if
  
  
  call CCTK_FortranString &
       (len_interpolator_options, interpolator_options, fort_interpolator_options)
  call Util_TableCreateFromString (options_table, fort_interpolator_options)
  if (options_table<0) then
     call CCTK_Warn(0,192,"init.F90","CarpetProlongateTest", "Could not create interpolator option table")
  end if
  
  npoints = product(lsh)
  
  coord_type = 130
  coords = (/ CCTK_PointerTo(interp_x), CCTK_PointerTo(interp_y), CCTK_PointerTo(interp_z) /)
  
  ninputs = 1
  call CCTK_VarIndex(input, "CarpetProlongateTest::u")
  inputs(1) = input
  if (any(inputs<0)) then
     call CCTK_Warn(0,204,"init.F90","CarpetProlongateTest", "Could not obtain interpolation variable index")
  end if
  
  noutputs     = 1
  output_types = (/ 130 /)
  outputs      = (/ CCTK_PointerTo(interp_u) /)
  
  call CCTK_InterpGridArrays &
       (ierr, cctkGH, 3, &
       interp_handle, options_table, coord_handle, &
       npoints, coord_type, coords, &
       ninputs, inputs, &
       noutputs, output_types, outputs)
  
  if (ierr/=0) then
     call CCTK_Warn(0,219,"init.F90","CarpetProlongateTest", "Interpolator error")
  end if
end subroutine CarpetProlongateTest_Interp

subroutine CarpetProlongateTest_InterpDiff (cctk_dim,cctk_gsh,cctk_lsh,cctk_lbnd,cctk_ubnd,cctk_tile_min,cctk_tile_max,cctk_ash,cct&
  &k_alignment,cctk_alignment_offset,cctk_from,cctk_to,cctk_bbox,cctk_delta_time,cctk_time,cctk_delta_space,cctk_origin_space,cctk_&
  &levfac,cctk_levoff,cctk_levoffdenom,cctk_timefac,cctk_convlevel,cctk_convfac,cctk_nghostzones,cctk_iteration,cctkGH,cctk_ash1,cc&
  &tk_ash2,cctk_ash3, X0interp_difference,X1interp_difference,X2interp_difference,du,du_p,du_p_p,errornorm,interp_du,interp_errorno&
  &rm,interp_u,interp_u0,interp_x,interp_y,interp_z,u,u_p,u_p_p,u0,u0_p,u0_p_p,uscaled,uscaled_p,uscaled_p_p, coarse_dx,coarse_dy,c&
  &oarse_dz,r,x,y,z)
  use CarpetProlongateTest
  implicit none

  INTEGER cctk_dim
  integer, parameter :: cctki_use_cctk_dim = kind(cctk_dim)
  INTEGER cctk_gsh (cctk_dim)
  integer, parameter :: cctki_use_cctk_gsh = kind(cctk_gsh)
  INTEGER cctk_lsh (cctk_dim)
  integer, parameter :: cctki_use_cctk_lsh = kind(cctk_lsh)
  INTEGER cctk_lbnd (cctk_dim)
  integer, parameter :: cctki_use_cctk_lbnd = kind(cctk_lbnd)
  INTEGER cctk_ubnd (cctk_dim)
  integer, parameter :: cctki_use_cctk_ubnd = kind(cctk_ubnd)
  INTEGER cctk_tile_min (cctk_dim)
  integer, parameter :: cctki_use_cctk_tile_min = kind(cctk_tile_min)
  INTEGER cctk_tile_max (cctk_dim)
  integer, parameter :: cctki_use_cctk_tile_max = kind(cctk_tile_max)
  INTEGER cctk_ash (cctk_dim)
  integer, parameter :: cctki_use_cctk_ash = kind(cctk_ash)
  INTEGER cctk_alignment
  integer, parameter :: cctki_use_cctk_alignment = kind(cctk_alignment)
  INTEGER cctk_alignment_offset
  integer, parameter :: cctki_use_cctk_alignment_offset = kind(cctk_alignment_offset)
  INTEGER cctk_from (cctk_dim)
  integer, parameter :: cctki_use_cctk_from = kind(cctk_from)
  INTEGER cctk_to (cctk_dim)
  integer, parameter :: cctki_use_cctk_to = kind(cctk_to)
  INTEGER cctk_bbox (2*cctk_dim)
  integer, parameter :: cctki_use_cctk_bbox = kind(cctk_bbox)
  REAL*8 cctk_delta_time
  integer, parameter :: cctki_use_cctk_delta_time = kind(cctk_delta_time)
  REAL*8 cctk_time
  integer, parameter :: cctki_use_cctk_time = kind(cctk_time)
  REAL*8 cctk_delta_space (cctk_dim)
  integer, parameter :: cctki_use_cctk_delta_space = kind(cctk_delta_space)
  REAL*8 cctk_origin_space (cctk_dim)
  integer, parameter :: cctki_use_cctk_origin_space = kind(cctk_origin_space)
  INTEGER cctk_levfac (cctk_dim)
  integer, parameter :: cctki_use_cctk_levfac = kind(cctk_levfac)
  INTEGER cctk_levoff (cctk_dim)
  integer, parameter :: cctki_use_cctk_levoff = kind(cctk_levoff)
  INTEGER cctk_levoffdenom (cctk_dim)
  integer, parameter :: cctki_use_cctk_levoffdenom = kind(cctk_levoffdenom)
  INTEGER cctk_timefac
  integer, parameter :: cctki_use_cctk_timefac = kind(cctk_timefac)
  INTEGER cctk_convlevel
  integer, parameter :: cctki_use_cctk_convlevel = kind(cctk_convlevel)
  INTEGER cctk_convfac
  integer, parameter :: cctki_use_cctk_convfac = kind(cctk_convfac)
  INTEGER cctk_nghostzones (cctk_dim)
  integer, parameter :: cctki_use_cctk_nghostzones = kind(cctk_nghostzones)
  INTEGER cctk_iteration
  integer, parameter :: cctki_use_cctk_iteration = kind(cctk_iteration)
  integer*8 cctkGH
  integer, parameter :: cctki_use_cctkGH = kind(cctkGH)
  INTEGER cctk_ash1
  integer, parameter :: cctki_use_cctk_ash1 = kind(cctk_ash1)
  INTEGER cctk_ash2
  integer, parameter :: cctki_use_cctk_ash2 = kind(cctk_ash2)
  INTEGER cctk_ash3
  integer, parameter :: cctki_use_cctk_ash3 = kind(cctk_ash3)
  integer :: x0interp_difference
  integer :: x1interp_difference
  integer :: x2interp_difference
  REAL*8 :: interp_du (x0interp_difference,x1interp_difference,x2interp_difference)
  integer, parameter :: cctki_use_interp_du = kind(interp_du)
  REAL*8, iNteNt(iN) :: interp_u (x0interp_difference,x1interp_difference,x2interp_difference)
  integer, parameter :: cctki_use_interp_u = kind(interp_u)
  REAL*8 :: interp_u0 (x0interp_difference,x1interp_difference,x2interp_difference)
  integer, parameter :: cctki_use_interp_u0 = kind(interp_u0)
  REAL*8, iNteNt(iN) :: interp_x (x0interp_difference,x1interp_difference,x2interp_difference)
  integer, parameter :: cctki_use_interp_x = kind(interp_x)
  REAL*8, iNteNt(iN) :: interp_y (x0interp_difference,x1interp_difference,x2interp_difference)
  integer, parameter :: cctki_use_interp_y = kind(interp_y)
  REAL*8, iNteNt(iN) :: interp_z (x0interp_difference,x1interp_difference,x2interp_difference)
  integer, parameter :: cctki_use_interp_z = kind(interp_z)
  characTer*8, intent(IN) :: du
  integer, parameter :: cctki_use_du = kind(du)
  characTer*8, intent(IN) :: du_p
  integer, parameter :: cctki_use_du_p = kind(du_p)
  characTer*8, intent(IN) :: du_p_p
  integer, parameter :: cctki_use_du_p_p = kind(du_p_p)
  characTer*8, intent(IN) :: errornorm
  integer, parameter :: cctki_use_errornorm = kind(errornorm)
  characTer*8, intent(IN) :: interp_errornorm
  integer, parameter :: cctki_use_interp_errornorm = kind(interp_errornorm)
  characTer*8, intent(IN) :: u
  integer, parameter :: cctki_use_u = kind(u)
  characTer*8, intent(IN) :: u_p
  integer, parameter :: cctki_use_u_p = kind(u_p)
  characTer*8, intent(IN) :: u_p_p
  integer, parameter :: cctki_use_u_p_p = kind(u_p_p)
  characTer*8, intent(IN) :: u0
  integer, parameter :: cctki_use_u0 = kind(u0)
  characTer*8, intent(IN) :: u0_p
  integer, parameter :: cctki_use_u0_p = kind(u0_p)
  characTer*8, intent(IN) :: u0_p_p
  integer, parameter :: cctki_use_u0_p_p = kind(u0_p_p)
  characTer*8, intent(IN) :: uscaled
  integer, parameter :: cctki_use_uscaled = kind(uscaled)
  characTer*8, intent(IN) :: uscaled_p
  integer, parameter :: cctki_use_uscaled_p = kind(uscaled_p)
  characTer*8, intent(IN) :: uscaled_p_p
  integer, parameter :: cctki_use_uscaled_p_p = kind(uscaled_p_p)
  characTer*8, intent(IN) :: coarse_dx
  integer, parameter :: cctki_use_coarse_dx = kind(coarse_dx)
  characTer*8, intent(IN) :: coarse_dy
  integer, parameter :: cctki_use_coarse_dy = kind(coarse_dy)
  characTer*8, intent(IN) :: coarse_dz
  integer, parameter :: cctki_use_coarse_dz = kind(coarse_dz)
  characTer*8, intent(IN) :: r
  integer, parameter :: cctki_use_r = kind(r)
  characTer*8, intent(IN) :: x
  integer, parameter :: cctki_use_x = kind(x)
  characTer*8, intent(IN) :: y
  integer, parameter :: cctki_use_y = kind(y)
  characTer*8, intent(IN) :: z
  integer, parameter :: cctki_use_z = kind(z)
  


  
  interp_u0 = &
       density_time_scale(cctk_time) * &
       density_sum(interp_x+1,interp_y+1,interp_z+1)
  interp_du = interp_u - interp_u0
end subroutine CarpetProlongateTest_InterpDiff



subroutine CarpetProlongateTest_NormInit (cctk_dim,cctk_gsh,cctk_lsh,cctk_lbnd,cctk_ubnd,cctk_tile_min,cctk_tile_max,cctk_ash,cctk_&
  &alignment,cctk_alignment_offset,cctk_from,cctk_to,cctk_bbox,cctk_delta_time,cctk_time,cctk_delta_space,cctk_origin_space,cctk_le&
  &vfac,cctk_levoff,cctk_levoffdenom,cctk_timefac,cctk_convlevel,cctk_convfac,cctk_nghostzones,cctk_iteration,cctkGH,cctk_ash1,cctk&
  &_ash2,cctk_ash3, X0interp_difference,X1interp_difference,X2interp_difference,du,du_p,du_p_p,errornorm,interp_du,interp_errornorm&
  &,interp_u,interp_u0,interp_x,interp_y,interp_z,u,u_p,u_p_p,u0,u0_p,u0_p_p,uscaled,uscaled_p,uscaled_p_p, coarse_dx,coarse_dy,coa&
  &rse_dz,r,x,y,z)
  implicit none

  INTEGER cctk_dim
  integer, parameter :: cctki_use_cctk_dim = kind(cctk_dim)
  INTEGER cctk_gsh (cctk_dim)
  integer, parameter :: cctki_use_cctk_gsh = kind(cctk_gsh)
  INTEGER cctk_lsh (cctk_dim)
  integer, parameter :: cctki_use_cctk_lsh = kind(cctk_lsh)
  INTEGER cctk_lbnd (cctk_dim)
  integer, parameter :: cctki_use_cctk_lbnd = kind(cctk_lbnd)
  INTEGER cctk_ubnd (cctk_dim)
  integer, parameter :: cctki_use_cctk_ubnd = kind(cctk_ubnd)
  INTEGER cctk_tile_min (cctk_dim)
  integer, parameter :: cctki_use_cctk_tile_min = kind(cctk_tile_min)
  INTEGER cctk_tile_max (cctk_dim)
  integer, parameter :: cctki_use_cctk_tile_max = kind(cctk_tile_max)
  INTEGER cctk_ash (cctk_dim)
  integer, parameter :: cctki_use_cctk_ash = kind(cctk_ash)
  INTEGER cctk_alignment
  integer, parameter :: cctki_use_cctk_alignment = kind(cctk_alignment)
  INTEGER cctk_alignment_offset
  integer, parameter :: cctki_use_cctk_alignment_offset = kind(cctk_alignment_offset)
  INTEGER cctk_from (cctk_dim)
  integer, parameter :: cctki_use_cctk_from = kind(cctk_from)
  INTEGER cctk_to (cctk_dim)
  integer, parameter :: cctki_use_cctk_to = kind(cctk_to)
  INTEGER cctk_bbox (2*cctk_dim)
  integer, parameter :: cctki_use_cctk_bbox = kind(cctk_bbox)
  REAL*8 cctk_delta_time
  integer, parameter :: cctki_use_cctk_delta_time = kind(cctk_delta_time)
  REAL*8 cctk_time
  integer, parameter :: cctki_use_cctk_time = kind(cctk_time)
  REAL*8 cctk_delta_space (cctk_dim)
  integer, parameter :: cctki_use_cctk_delta_space = kind(cctk_delta_space)
  REAL*8 cctk_origin_space (cctk_dim)
  integer, parameter :: cctki_use_cctk_origin_space = kind(cctk_origin_space)
  INTEGER cctk_levfac (cctk_dim)
  integer, parameter :: cctki_use_cctk_levfac = kind(cctk_levfac)
  INTEGER cctk_levoff (cctk_dim)
  integer, parameter :: cctki_use_cctk_levoff = kind(cctk_levoff)
  INTEGER cctk_levoffdenom (cctk_dim)
  integer, parameter :: cctki_use_cctk_levoffdenom = kind(cctk_levoffdenom)
  INTEGER cctk_timefac
  integer, parameter :: cctki_use_cctk_timefac = kind(cctk_timefac)
  INTEGER cctk_convlevel
  integer, parameter :: cctki_use_cctk_convlevel = kind(cctk_convlevel)
  INTEGER cctk_convfac
  integer, parameter :: cctki_use_cctk_convfac = kind(cctk_convfac)
  INTEGER cctk_nghostzones (cctk_dim)
  integer, parameter :: cctki_use_cctk_nghostzones = kind(cctk_nghostzones)
  INTEGER cctk_iteration
  integer, parameter :: cctki_use_cctk_iteration = kind(cctk_iteration)
  integer*8 cctkGH
  integer, parameter :: cctki_use_cctkGH = kind(cctkGH)
  INTEGER cctk_ash1
  integer, parameter :: cctki_use_cctk_ash1 = kind(cctk_ash1)
  INTEGER cctk_ash2
  integer, parameter :: cctki_use_cctk_ash2 = kind(cctk_ash2)
  INTEGER cctk_ash3
  integer, parameter :: cctki_use_cctk_ash3 = kind(cctk_ash3)
  REAL*8 :: errornorm
  integer, parameter :: cctki_use_errornorm = kind(errornorm)
  REAL*8 :: interp_errornorm
  integer, parameter :: cctki_use_interp_errornorm = kind(interp_errornorm)
  characTer*8, intent(IN) :: x0interp_difference
  integer, parameter :: cctki_use_x0interp_difference = kind(x0interp_difference)
  characTer*8, intent(IN) :: x1interp_difference
  integer, parameter :: cctki_use_x1interp_difference = kind(x1interp_difference)
  characTer*8, intent(IN) :: x2interp_difference
  integer, parameter :: cctki_use_x2interp_difference = kind(x2interp_difference)
  characTer*8, intent(IN) :: du
  integer, parameter :: cctki_use_du = kind(du)
  characTer*8, intent(IN) :: du_p
  integer, parameter :: cctki_use_du_p = kind(du_p)
  characTer*8, intent(IN) :: du_p_p
  integer, parameter :: cctki_use_du_p_p = kind(du_p_p)
  characTer*8, intent(IN) :: interp_du
  integer, parameter :: cctki_use_interp_du = kind(interp_du)
  characTer*8, intent(IN) :: interp_u
  integer, parameter :: cctki_use_interp_u = kind(interp_u)
  characTer*8, intent(IN) :: interp_u0
  integer, parameter :: cctki_use_interp_u0 = kind(interp_u0)
  characTer*8, intent(IN) :: interp_x
  integer, parameter :: cctki_use_interp_x = kind(interp_x)
  characTer*8, intent(IN) :: interp_y
  integer, parameter :: cctki_use_interp_y = kind(interp_y)
  characTer*8, intent(IN) :: interp_z
  integer, parameter :: cctki_use_interp_z = kind(interp_z)
  characTer*8, intent(IN) :: u
  integer, parameter :: cctki_use_u = kind(u)
  characTer*8, intent(IN) :: u_p
  integer, parameter :: cctki_use_u_p = kind(u_p)
  characTer*8, intent(IN) :: u_p_p
  integer, parameter :: cctki_use_u_p_p = kind(u_p_p)
  characTer*8, intent(IN) :: u0
  integer, parameter :: cctki_use_u0 = kind(u0)
  characTer*8, intent(IN) :: u0_p
  integer, parameter :: cctki_use_u0_p = kind(u0_p)
  characTer*8, intent(IN) :: u0_p_p
  integer, parameter :: cctki_use_u0_p_p = kind(u0_p_p)
  characTer*8, intent(IN) :: uscaled
  integer, parameter :: cctki_use_uscaled = kind(uscaled)
  characTer*8, intent(IN) :: uscaled_p
  integer, parameter :: cctki_use_uscaled_p = kind(uscaled_p)
  characTer*8, intent(IN) :: uscaled_p_p
  integer, parameter :: cctki_use_uscaled_p_p = kind(uscaled_p_p)
  characTer*8, intent(IN) :: coarse_dx
  integer, parameter :: cctki_use_coarse_dx = kind(coarse_dx)
  characTer*8, intent(IN) :: coarse_dy
  integer, parameter :: cctki_use_coarse_dy = kind(coarse_dy)
  characTer*8, intent(IN) :: coarse_dz
  integer, parameter :: cctki_use_coarse_dz = kind(coarse_dz)
  characTer*8, intent(IN) :: r
  integer, parameter :: cctki_use_r = kind(r)
  characTer*8, intent(IN) :: x
  integer, parameter :: cctki_use_x = kind(x)
  characTer*8, intent(IN) :: y
  integer, parameter :: cctki_use_y = kind(y)
  characTer*8, intent(IN) :: z
  integer, parameter :: cctki_use_z = kind(z)
  
  errornorm = 0
  interp_errornorm = 0
end subroutine CarpetProlongateTest_NormInit

subroutine CarpetProlongateTest_NormCalc (cctk_dim,cctk_gsh,cctk_lsh,cctk_lbnd,cctk_ubnd,cctk_tile_min,cctk_tile_max,cctk_ash,cctk_&
  &alignment,cctk_alignment_offset,cctk_from,cctk_to,cctk_bbox,cctk_delta_time,cctk_time,cctk_delta_space,cctk_origin_space,cctk_le&
  &vfac,cctk_levoff,cctk_levoffdenom,cctk_timefac,cctk_convlevel,cctk_convfac,cctk_nghostzones,cctk_iteration,cctkGH,cctk_ash1,cctk&
  &_ash2,cctk_ash3, X0interp_difference,X1interp_difference,X2interp_difference,du,du_p,du_p_p,errornorm,interp_du,interp_errornorm&
  &,interp_u,interp_u0,interp_x,interp_y,interp_z,u,u_p,u_p_p,u0,u0_p,u0_p_p,uscaled,uscaled_p,uscaled_p_p, coarse_dx,coarse_dy,coa&
  &rse_dz,r,x,y,z)
  implicit none

  INTEGER cctk_dim
  integer, parameter :: cctki_use_cctk_dim = kind(cctk_dim)
  INTEGER cctk_gsh (cctk_dim)
  integer, parameter :: cctki_use_cctk_gsh = kind(cctk_gsh)
  INTEGER cctk_lsh (cctk_dim)
  integer, parameter :: cctki_use_cctk_lsh = kind(cctk_lsh)
  INTEGER cctk_lbnd (cctk_dim)
  integer, parameter :: cctki_use_cctk_lbnd = kind(cctk_lbnd)
  INTEGER cctk_ubnd (cctk_dim)
  integer, parameter :: cctki_use_cctk_ubnd = kind(cctk_ubnd)
  INTEGER cctk_tile_min (cctk_dim)
  integer, parameter :: cctki_use_cctk_tile_min = kind(cctk_tile_min)
  INTEGER cctk_tile_max (cctk_dim)
  integer, parameter :: cctki_use_cctk_tile_max = kind(cctk_tile_max)
  INTEGER cctk_ash (cctk_dim)
  integer, parameter :: cctki_use_cctk_ash = kind(cctk_ash)
  INTEGER cctk_alignment
  integer, parameter :: cctki_use_cctk_alignment = kind(cctk_alignment)
  INTEGER cctk_alignment_offset
  integer, parameter :: cctki_use_cctk_alignment_offset = kind(cctk_alignment_offset)
  INTEGER cctk_from (cctk_dim)
  integer, parameter :: cctki_use_cctk_from = kind(cctk_from)
  INTEGER cctk_to (cctk_dim)
  integer, parameter :: cctki_use_cctk_to = kind(cctk_to)
  INTEGER cctk_bbox (2*cctk_dim)
  integer, parameter :: cctki_use_cctk_bbox = kind(cctk_bbox)
  REAL*8 cctk_delta_time
  integer, parameter :: cctki_use_cctk_delta_time = kind(cctk_delta_time)
  REAL*8 cctk_time
  integer, parameter :: cctki_use_cctk_time = kind(cctk_time)
  REAL*8 cctk_delta_space (cctk_dim)
  integer, parameter :: cctki_use_cctk_delta_space = kind(cctk_delta_space)
  REAL*8 cctk_origin_space (cctk_dim)
  integer, parameter :: cctki_use_cctk_origin_space = kind(cctk_origin_space)
  INTEGER cctk_levfac (cctk_dim)
  integer, parameter :: cctki_use_cctk_levfac = kind(cctk_levfac)
  INTEGER cctk_levoff (cctk_dim)
  integer, parameter :: cctki_use_cctk_levoff = kind(cctk_levoff)
  INTEGER cctk_levoffdenom (cctk_dim)
  integer, parameter :: cctki_use_cctk_levoffdenom = kind(cctk_levoffdenom)
  INTEGER cctk_timefac
  integer, parameter :: cctki_use_cctk_timefac = kind(cctk_timefac)
  INTEGER cctk_convlevel
  integer, parameter :: cctki_use_cctk_convlevel = kind(cctk_convlevel)
  INTEGER cctk_convfac
  integer, parameter :: cctki_use_cctk_convfac = kind(cctk_convfac)
  INTEGER cctk_nghostzones (cctk_dim)
  integer, parameter :: cctki_use_cctk_nghostzones = kind(cctk_nghostzones)
  INTEGER cctk_iteration
  integer, parameter :: cctki_use_cctk_iteration = kind(cctk_iteration)
  integer*8 cctkGH
  integer, parameter :: cctki_use_cctkGH = kind(cctkGH)
  INTEGER cctk_ash1
  integer, parameter :: cctki_use_cctk_ash1 = kind(cctk_ash1)
  INTEGER cctk_ash2
  integer, parameter :: cctki_use_cctk_ash2 = kind(cctk_ash2)
  INTEGER cctk_ash3
  integer, parameter :: cctki_use_cctk_ash3 = kind(cctk_ash3)
  INTEGER X0interp_difference
  INTEGER X1interp_difference
  INTEGER X2interp_difference
  REAL*8 du (cctk_ash1,cctk_ash2,cctk_ash3)
  integer, parameter :: cctki_use_du = kind(du)
  REAL*8 du_p (cctk_ash1,cctk_ash2,cctk_ash3)
  integer, parameter :: cctki_use_du_p = kind(du_p)
  REAL*8 du_p_p (cctk_ash1,cctk_ash2,cctk_ash3)
  integer, parameter :: cctki_use_du_p_p = kind(du_p_p)
  REAL*8 errornorm
  integer, parameter :: cctki_use_errornorm = kind(errornorm)
  REAL*8 interp_du (X0interp_difference,X1interp_difference,X2interp_difference)
  integer, parameter :: cctki_use_interp_du = kind(interp_du)
  REAL*8 interp_errornorm
  integer, parameter :: cctki_use_interp_errornorm = kind(interp_errornorm)
  REAL*8 interp_u (X0interp_difference,X1interp_difference,X2interp_difference)
  integer, parameter :: cctki_use_interp_u = kind(interp_u)
  REAL*8 interp_u0 (X0interp_difference,X1interp_difference,X2interp_difference)
  integer, parameter :: cctki_use_interp_u0 = kind(interp_u0)
  REAL*8 interp_x (X0interp_difference,X1interp_difference,X2interp_difference)
  integer, parameter :: cctki_use_interp_x = kind(interp_x)
  REAL*8 interp_y (X0interp_difference,X1interp_difference,X2interp_difference)
  integer, parameter :: cctki_use_interp_y = kind(interp_y)
  REAL*8 interp_z (X0interp_difference,X1interp_difference,X2interp_difference)
  integer, parameter :: cctki_use_interp_z = kind(interp_z)
  REAL*8 u (cctk_ash1,cctk_ash2,cctk_ash3)
  integer, parameter :: cctki_use_u = kind(u)
  REAL*8 u_p (cctk_ash1,cctk_ash2,cctk_ash3)
  integer, parameter :: cctki_use_u_p = kind(u_p)
  REAL*8 u_p_p (cctk_ash1,cctk_ash2,cctk_ash3)
  integer, parameter :: cctki_use_u_p_p = kind(u_p_p)
  REAL*8 u0 (cctk_ash1,cctk_ash2,cctk_ash3)
  integer, parameter :: cctki_use_u0 = kind(u0)
  REAL*8 u0_p (cctk_ash1,cctk_ash2,cctk_ash3)
  integer, parameter :: cctki_use_u0_p = kind(u0_p)
  REAL*8 u0_p_p (cctk_ash1,cctk_ash2,cctk_ash3)
  integer, parameter :: cctki_use_u0_p_p = kind(u0_p_p)
  REAL*8 uscaled (cctk_ash1,cctk_ash2,cctk_ash3)
  integer, parameter :: cctki_use_uscaled = kind(uscaled)
  REAL*8 uscaled_p (cctk_ash1,cctk_ash2,cctk_ash3)
  integer, parameter :: cctki_use_uscaled_p = kind(uscaled_p)
  REAL*8 uscaled_p_p (cctk_ash1,cctk_ash2,cctk_ash3)
  integer, parameter :: cctki_use_uscaled_p_p = kind(uscaled_p_p)
  REAL*8 coarse_dx
  integer, parameter :: cctki_use_coarse_dx = kind(coarse_dx)
  REAL*8 coarse_dy
  integer, parameter :: cctki_use_coarse_dy = kind(coarse_dy)
  REAL*8 coarse_dz
  integer, parameter :: cctki_use_coarse_dz = kind(coarse_dz)
  REAL*8 r (cctk_ash1,cctk_ash2,cctk_ash3)
  integer, parameter :: cctki_use_r = kind(r)
  REAL*8 x (cctk_ash1,cctk_ash2,cctk_ash3)
  integer, parameter :: cctki_use_x = kind(x)
  REAL*8 y (cctk_ash1,cctk_ash2,cctk_ash3)
  integer, parameter :: cctki_use_y = kind(y)
  REAL*8 z (cctk_ash1,cctk_ash2,cctk_ash3)
  integer, parameter :: cctki_use_z = kind(z)
  
  errornorm = max (errornorm, maxval(abs(du)))
  interp_errornorm = max (interp_errornorm, maxval(abs(interp_du)))
end subroutine CarpetProlongateTest_NormCalc

subroutine CarpetProlongateTest_NormReduce (cctk_dim,cctk_gsh,cctk_lsh,cctk_lbnd,cctk_ubnd,cctk_tile_min,cctk_tile_max,cctk_ash,cct&
  &k_alignment,cctk_alignment_offset,cctk_from,cctk_to,cctk_bbox,cctk_delta_time,cctk_time,cctk_delta_space,cctk_origin_space,cctk_&
  &levfac,cctk_levoff,cctk_levoffdenom,cctk_timefac,cctk_convlevel,cctk_convfac,cctk_nghostzones,cctk_iteration,cctkGH,cctk_ash1,cc&
  &tk_ash2,cctk_ash3, X0interp_difference,X1interp_difference,X2interp_difference,du,du_p,du_p_p,errornorm,interp_du,interp_errorno&
  &rm,interp_u,interp_u0,interp_x,interp_y,interp_z,u,u_p,u_p_p,u0,u0_p,u0_p_p,uscaled,uscaled_p,uscaled_p_p, coarse_dx,coarse_dy,c&
  &oarse_dz,r,x,y,z)
  implicit none

  INTEGER cctk_dim
  integer, parameter :: cctki_use_cctk_dim = kind(cctk_dim)
  INTEGER cctk_gsh (cctk_dim)
  integer, parameter :: cctki_use_cctk_gsh = kind(cctk_gsh)
  INTEGER cctk_lsh (cctk_dim)
  integer, parameter :: cctki_use_cctk_lsh = kind(cctk_lsh)
  INTEGER cctk_lbnd (cctk_dim)
  integer, parameter :: cctki_use_cctk_lbnd = kind(cctk_lbnd)
  INTEGER cctk_ubnd (cctk_dim)
  integer, parameter :: cctki_use_cctk_ubnd = kind(cctk_ubnd)
  INTEGER cctk_tile_min (cctk_dim)
  integer, parameter :: cctki_use_cctk_tile_min = kind(cctk_tile_min)
  INTEGER cctk_tile_max (cctk_dim)
  integer, parameter :: cctki_use_cctk_tile_max = kind(cctk_tile_max)
  INTEGER cctk_ash (cctk_dim)
  integer, parameter :: cctki_use_cctk_ash = kind(cctk_ash)
  INTEGER cctk_alignment
  integer, parameter :: cctki_use_cctk_alignment = kind(cctk_alignment)
  INTEGER cctk_alignment_offset
  integer, parameter :: cctki_use_cctk_alignment_offset = kind(cctk_alignment_offset)
  INTEGER cctk_from (cctk_dim)
  integer, parameter :: cctki_use_cctk_from = kind(cctk_from)
  INTEGER cctk_to (cctk_dim)
  integer, parameter :: cctki_use_cctk_to = kind(cctk_to)
  INTEGER cctk_bbox (2*cctk_dim)
  integer, parameter :: cctki_use_cctk_bbox = kind(cctk_bbox)
  REAL*8 cctk_delta_time
  integer, parameter :: cctki_use_cctk_delta_time = kind(cctk_delta_time)
  REAL*8 cctk_time
  integer, parameter :: cctki_use_cctk_time = kind(cctk_time)
  REAL*8 cctk_delta_space (cctk_dim)
  integer, parameter :: cctki_use_cctk_delta_space = kind(cctk_delta_space)
  REAL*8 cctk_origin_space (cctk_dim)
  integer, parameter :: cctki_use_cctk_origin_space = kind(cctk_origin_space)
  INTEGER cctk_levfac (cctk_dim)
  integer, parameter :: cctki_use_cctk_levfac = kind(cctk_levfac)
  INTEGER cctk_levoff (cctk_dim)
  integer, parameter :: cctki_use_cctk_levoff = kind(cctk_levoff)
  INTEGER cctk_levoffdenom (cctk_dim)
  integer, parameter :: cctki_use_cctk_levoffdenom = kind(cctk_levoffdenom)
  INTEGER cctk_timefac
  integer, parameter :: cctki_use_cctk_timefac = kind(cctk_timefac)
  INTEGER cctk_convlevel
  integer, parameter :: cctki_use_cctk_convlevel = kind(cctk_convlevel)
  INTEGER cctk_convfac
  integer, parameter :: cctki_use_cctk_convfac = kind(cctk_convfac)
  INTEGER cctk_nghostzones (cctk_dim)
  integer, parameter :: cctki_use_cctk_nghostzones = kind(cctk_nghostzones)
  INTEGER cctk_iteration
  integer, parameter :: cctki_use_cctk_iteration = kind(cctk_iteration)
  integer*8 cctkGH
  integer, parameter :: cctki_use_cctkGH = kind(cctkGH)
  INTEGER cctk_ash1
  integer, parameter :: cctki_use_cctk_ash1 = kind(cctk_ash1)
  INTEGER cctk_ash2
  integer, parameter :: cctki_use_cctk_ash2 = kind(cctk_ash2)
  INTEGER cctk_ash3
  integer, parameter :: cctki_use_cctk_ash3 = kind(cctk_ash3)
  INTEGER X0interp_difference
  INTEGER X1interp_difference
  INTEGER X2interp_difference
  REAL*8 du (cctk_ash1,cctk_ash2,cctk_ash3)
  integer, parameter :: cctki_use_du = kind(du)
  REAL*8 du_p (cctk_ash1,cctk_ash2,cctk_ash3)
  integer, parameter :: cctki_use_du_p = kind(du_p)
  REAL*8 du_p_p (cctk_ash1,cctk_ash2,cctk_ash3)
  integer, parameter :: cctki_use_du_p_p = kind(du_p_p)
  REAL*8 errornorm
  integer, parameter :: cctki_use_errornorm = kind(errornorm)
  REAL*8 interp_du (X0interp_difference,X1interp_difference,X2interp_difference)
  integer, parameter :: cctki_use_interp_du = kind(interp_du)
  REAL*8 interp_errornorm
  integer, parameter :: cctki_use_interp_errornorm = kind(interp_errornorm)
  REAL*8 interp_u (X0interp_difference,X1interp_difference,X2interp_difference)
  integer, parameter :: cctki_use_interp_u = kind(interp_u)
  REAL*8 interp_u0 (X0interp_difference,X1interp_difference,X2interp_difference)
  integer, parameter :: cctki_use_interp_u0 = kind(interp_u0)
  REAL*8 interp_x (X0interp_difference,X1interp_difference,X2interp_difference)
  integer, parameter :: cctki_use_interp_x = kind(interp_x)
  REAL*8 interp_y (X0interp_difference,X1interp_difference,X2interp_difference)
  integer, parameter :: cctki_use_interp_y = kind(interp_y)
  REAL*8 interp_z (X0interp_difference,X1interp_difference,X2interp_difference)
  integer, parameter :: cctki_use_interp_z = kind(interp_z)
  REAL*8 u (cctk_ash1,cctk_ash2,cctk_ash3)
  integer, parameter :: cctki_use_u = kind(u)
  REAL*8 u_p (cctk_ash1,cctk_ash2,cctk_ash3)
  integer, parameter :: cctki_use_u_p = kind(u_p)
  REAL*8 u_p_p (cctk_ash1,cctk_ash2,cctk_ash3)
  integer, parameter :: cctki_use_u_p_p = kind(u_p_p)
  REAL*8 u0 (cctk_ash1,cctk_ash2,cctk_ash3)
  integer, parameter :: cctki_use_u0 = kind(u0)
  REAL*8 u0_p (cctk_ash1,cctk_ash2,cctk_ash3)
  integer, parameter :: cctki_use_u0_p = kind(u0_p)
  REAL*8 u0_p_p (cctk_ash1,cctk_ash2,cctk_ash3)
  integer, parameter :: cctki_use_u0_p_p = kind(u0_p_p)
  REAL*8 uscaled (cctk_ash1,cctk_ash2,cctk_ash3)
  integer, parameter :: cctki_use_uscaled = kind(uscaled)
  REAL*8 uscaled_p (cctk_ash1,cctk_ash2,cctk_ash3)
  integer, parameter :: cctki_use_uscaled_p = kind(uscaled_p)
  REAL*8 uscaled_p_p (cctk_ash1,cctk_ash2,cctk_ash3)
  integer, parameter :: cctki_use_uscaled_p_p = kind(uscaled_p_p)
  REAL*8 coarse_dx
  integer, parameter :: cctki_use_coarse_dx = kind(coarse_dx)
  REAL*8 coarse_dy
  integer, parameter :: cctki_use_coarse_dy = kind(coarse_dy)
  REAL*8 coarse_dz
  integer, parameter :: cctki_use_coarse_dz = kind(coarse_dz)
  REAL*8 r (cctk_ash1,cctk_ash2,cctk_ash3)
  integer, parameter :: cctki_use_r = kind(r)
  REAL*8 x (cctk_ash1,cctk_ash2,cctk_ash3)
  integer, parameter :: cctki_use_x = kind(x)
  REAL*8 y (cctk_ash1,cctk_ash2,cctk_ash3)
  integer, parameter :: cctki_use_y = kind(y)
  REAL*8 z (cctk_ash1,cctk_ash2,cctk_ash3)
  integer, parameter :: cctki_use_z = kind(z)
  
  integer   :: max_handle
  integer   :: ierr
  REAL*8 :: tmp
  
  call CCTK_ReductionArrayHandle (max_handle, "maximum")
  if (max_handle < 0) then
     call CCTK_Warn(0,265,"init.F90","CarpetProlongateTest", "Could not obtain norm handle")
  end if
  
  call CCTK_ReduceLocScalar &
       (ierr, cctkGH, -1, max_handle, errornorm, tmp, 130)
  if (ierr/=0) then
     call CCTK_Warn(0,271,"init.F90","CarpetProlongateTest", "Could not evaluate norm")
  end if
  errornorm = tmp
  
  call CCTK_ReduceLocScalar &
       (ierr, cctkGH, -1, max_handle, interp_errornorm, tmp, 130)
  if (ierr/=0) then
     call CCTK_Warn(0,278,"init.F90","CarpetProlongateTest", "Could not evaluate norm")
  end if
  interp_errornorm = tmp
end subroutine CarpetProlongateTest_NormReduce
