Index: interface.ccl
===================================================================
--- interface.ccl	(revision 22)
+++ interface.ccl	(working copy)
@@ -3,8 +3,6 @@
 
 IMPLEMENTS: Periodic
 
-INCLUDES HEADER: periodic.h IN Periodic.h
-
 USES INCLUDE HEADER: Slab.h
 
 
@@ -28,6 +26,43 @@
   CCTK_INT ARRAY OUT table_handles, CCTK_STRING IN bc_name)
 REQUIRES FUNCTION Boundary_SelectedGVs
 
+
+CCTK_INT FUNCTION Periodic_ApplyVI(                                           \
+    CCTK_POINTER_TO_CONST IN cctkGH,                                          \
+    CCTK_INT IN size,                                                         \
+    CCTK_INT IN ARRAY stencil,                                                \
+    CCTK_INT IN ARRAY do_periodic,                                            \
+    CCTK_INT IN var_index                                                     \
+    )
+PROVIDES FUNCTION Periodic_ApplyVI WITH BndPeriodicVI LANGUAGE C
+
+CCTK_INT FUNCTION Periodic_ApplyVN(                                           \
+    CCTK_POINTER_TO_CONST IN cctkGH,                                          \
+    CCTK_INT IN size,                                                         \
+    CCTK_INT IN ARRAY stencil,                                                \
+    CCTK_INT IN ARRAY do_periodic,                                            \
+    CCTK_STRING IN var_name                                                   \
+    )
+PROVIDES FUNCTION Periodic_ApplyVN WITH BndPeriodicVN LANGUAGE C
+
+CCTK_INT FUNCTION Periodic_ApplyGI(                                           \
+    CCTK_POINTER_TO_CONST IN cctkGH,                                          \
+    CCTK_INT IN size,                                                         \
+    CCTK_INT IN ARRAY stencil,                                                \
+    CCTK_INT IN ARRAY do_periodic,                                            \
+    CCTK_INT IN group_index                                                   \
+    )
+PROVIDES FUNCTION Periodic_ApplyGI WITH BndPeriodicGI LANGUAGE C
+
+CCTK_INT FUNCTION Periodic_ApplyGN(                                           \
+    CCTK_POINTER_TO_CONST IN cctkGH,                                          \
+    CCTK_INT IN size,                                                         \
+    CCTK_INT IN ARRAY stencil,                                                \
+    CCTK_INT IN ARRAY do_periodic,                                            \
+    CCTK_STRING IN group_name                                                 \
+    )
+PROVIDES FUNCTION Periodic_ApplyGN WITH BndPeriodicGN LANGUAGE C
+
 CCTK_INT FUNCTION GetBoundarySpecification \
   (CCTK_INT IN size, \
    CCTK_INT OUT ARRAY nboundaryzones, \
Index: src/periodic.c
===================================================================
--- src/periodic.c	(revision 22)
+++ src/periodic.c	(working copy)
@@ -6,7 +6,6 @@
 #include "cctk.h"
 #include "cctk_Parameters.h"
 #include "Slab.h"
-#include "periodic.h"
 
 static const char * restrict const rcsid = "$Header$";
 CCTK_FILEVERSION(TAT_Periodic_periodic_c);
@@ -14,18 +13,18 @@
 
 
 int
-BndPeriodicVI (cGH const * restrict const cctkGH,
+BndPeriodicVI (CCTK_POINTER_TO_CONST _GH,
+               int size,
                int const * restrict const stencil,
+               int const do_periodic[3],
                int const vi)
 {
-  DECLARE_CCTK_PARAMETERS;
-  
+  cGH const * restrict const cctkGH = _GH;
+
   cGroup group;
   cGroupDynamicData data;
-  char * restrict fullname;
   void * restrict varptr;
   struct xferinfo * restrict xferinfo;
-  int do_periodic[3];
   int global_bbox[6];
   int global_lbnd[3], global_ubnd[3];
   int fake_bbox[6];
@@ -39,15 +38,6 @@
   assert (stencil);
   assert (vi>=0 && vi<CCTK_NumVars());
   
-  if (verbose) {
-    fullname = CCTK_FullName(vi);
-    assert (fullname);
-    CCTK_VInfo (CCTK_THORNSTRING,
-                "Applying periodicity boundary conditions to \"%s\"",
-                fullname);
-    free (fullname);
-  }
-  
   /* Get and check group info */
   gi = CCTK_GroupIndexFromVarI (vi);
   assert (gi>=0 && gi<CCTK_NumGroups());
@@ -57,6 +47,12 @@
   assert (group.grouptype == CCTK_GF);
   assert (group.disttype == CCTK_DISTRIB_DEFAULT);
   assert (group.stagtype == 0);
+
+  if(group.dim != size) {
+    CCTK_VWarn(0, __LINE__, __FILE__, CCTK_THORNSTRING,
+               "The group \"%s\" has dimension %d, but the given stencil has "
+               "size %d.", CCTK_GroupNameFromVarI(vi), group.dim, size);
+  }
   
   ierr = CCTK_GroupDynamicData (cctkGH, gi, &data);
   assert (!ierr);
@@ -64,11 +60,6 @@
   varptr = CCTK_VarDataPtrI (cctkGH, 0, vi);
   assert (varptr);
   
-  /* Condition periodicity information */
-  do_periodic[0] = periodic || periodic_x;
-  do_periodic[1] = periodic || periodic_y;
-  do_periodic[2] = periodic || periodic_z;
-  
   {
     int min_handle, max_handle;
     CCTK_REAL local[6], global[6];
@@ -108,13 +99,7 @@
       assert (stencil[dir] >= 0);
       
       if (data.gsh[dir] < 2*stencil[dir]+1) {
-        CCTK_VWarn (0, __LINE__, __FILE__, CCTK_THORNSTRING,
-                    "The group \"%s\" has in the %c-direction only %d grid points.  "
-                    "This is not large enough for a periodic boundary that is %d grid points wide.  "
-                    "The group needs to have at least %d grid points in that direction.",
-                    CCTK_GroupNameFromVarI(vi), "xyz"[dir], data.gsh[dir],
-                    stencil[dir],
-                    2*stencil[dir]+1);
+        return dir+1;
       }
       
       /* Loop over faces */
@@ -214,22 +199,30 @@
 
 
 int
-BndPeriodicVN (cGH const * restrict const cctkGH,
+BndPeriodicVN (CCTK_POINTER_TO_CONST _GH,
+               int size,
                int const * restrict const stencil,
+               int const do_periodic[3],
                char const * restrict const vn)
 {
+  cGH const * restrict const cctkGH = _GH;
+
   int const vi = CCTK_VarIndex (vn);
   assert (vi>=0 && vi<CCTK_NumVars());
-  return BndPeriodicVI (cctkGH, stencil, vi);
+  return BndPeriodicVI (_GH, size, stencil, do_periodic, vi);
 }
 
 
 
 int
-BndPeriodicGI (cGH const * restrict const cctkGH,
+BndPeriodicGI (CCTK_POINTER_TO_CONST _GH,
+               int size,
                int const * restrict const stencil,
+               int const do_periodic[3],
                int const gi)
 {
+  cGH const * restrict const cctkGH = _GH;
+
   int v1, nv;
   int vi;
   int ierr;
@@ -240,7 +233,7 @@
     v1 = CCTK_FirstVarIndexI(gi);
     assert (v1>=0 && v1<CCTK_NumVars());
     for (vi=v1; vi<v1+nv; ++vi) {
-      ierr = BndPeriodicVI (cctkGH, stencil, vi);
+      ierr = BndPeriodicVI (_GH, size, stencil, do_periodic, vi);
       if (ierr) return ierr;
     }
   }
@@ -250,13 +243,15 @@
 
 
 int
-BndPeriodicGN (cGH const * restrict const cctkGH,
+BndPeriodicGN (CCTK_POINTER_TO_CONST _GH,
+               int size,
                int const * restrict const stencil,
+               int const do_periodic[3],
                char const * restrict const gn)
 {
   int const gi = CCTK_GroupIndex (gn);
   assert (gi>=0 && gi<CCTK_NumGroups());
-  return BndPeriodicGI (cctkGH, stencil, gi);
+  return BndPeriodicGI (_GH, size, stencil, do_periodic, gi);
 }
 
 
@@ -303,6 +298,15 @@
 void
 Periodic_ApplyBC (cGH const * restrict const cctkGH)
 {
+  DECLARE_CCTK_PARAMETERS;
+
+  int do_periodic[3];
+  do_periodic[0] = periodic || periodic_x;
+  do_periodic[1] = periodic || periodic_y;
+  do_periodic[2] = periodic || periodic_z;
+
+  char * fullname;
+ 
   int nvars;
   CCTK_INT * restrict indices;
   CCTK_INT * restrict faces;
@@ -346,7 +350,40 @@
     ierr = CCTK_GroupnghostzonesVI (cctkGH, dim, stencil, vi);
     assert (!ierr);
     
-    ierr = BndPeriodicVI (cctkGH, stencil, vi);
+    if (verbose) {
+      fullname = CCTK_FullName(vi);
+      assert (fullname);
+      CCTK_VInfo (CCTK_THORNSTRING,
+                  "Applying periodicity boundary conditions to \"%s\"",
+                  fullname);
+      free (fullname);
+    }
+
+    ierr = BndPeriodicVI (cctkGH, dim, stencil, do_periodic,  vi);
+
+    if(ierr > 0 && ierr < 4) {
+      int dir = ierr-1;
+
+      int gi;
+      cGroup group;
+      cGroupDynamicData data;
+
+      gi = CCTK_GroupIndexFromVarI (vi);
+      ierr = CCTK_GroupData (gi, &group);
+      assert (!ierr);
+
+      ierr = CCTK_GroupDynamicData (cctkGH, gi, &data);
+      assert (!ierr);
+
+      CCTK_VWarn (0, __LINE__, __FILE__, CCTK_THORNSTRING,
+                    "The group \"%s\" has in the %c-direction only %d grid points.  "
+                    "This is not large enough for a periodic boundary that is %d grid points wide.  "
+                    "The group needs to have at least %d grid points in that direction.",
+                    CCTK_GroupNameFromVarI(vi), "xyz"[dir], data.gsh[dir],
+                    stencil[dir],
+                    2*stencil[dir]+1);
+    }
+
     assert (!ierr);
     
     free (stencil);
Index: src/periodic.h
===================================================================
--- src/periodic.h	(revision 22)
+++ src/periodic.h	(working copy)
@@ -1,37 +0,0 @@
-/* $Header$ */
-
-#ifndef PERIODIC_H
-#define PERIODIC_H
-
-#include "cctk.h"
-
-int
-BndPeriodicVI (cGH const * restrict const cctkGH,
-               int const * restrict const stencil,
-               int const vi);
-
-int
-BndPeriodicVN (cGH const * restrict const cctkGH,
-               int const * restrict const stencil,
-               char const * restrict const vn);
-
-int
-BndPeriodicGI (cGH const * restrict const cctkGH,
-               int const * restrict const stencil,
-               int const gi);
-
-int
-BndPeriodicGN (cGH const * restrict const cctkGH,
-               int const * restrict const stencil,
-               char const * restrict const gn);
-
-
-
-void
-Periodic_RegisterBC (cGH * restrict const cctkGH);
-
-void
-Periodic_ApplyBC (cGH const * restrict const cctkGH);
-
-#endif /* defined PERIODIC_H */
-
