C
C Print out the spins for debugging purposes.
C

      SUBROUTINE print_spin(level)
      INCLUDE "common.h"
      INCLUDE "cluster.h"
      INTEGER level
      INTEGER i,j, scale, num
      INTEGER imin,imax,jmin,jmax, step

C     scale = 2**level
      imin = 0
      jmin = 0
      imax = isiz+1
      jmax = jsiz+1
C     imax = isiz/scale+1
C     jmax = jsiz/scale+1
      num = imax - imin + 1

      CALL KMULTI(6)
      WRITE(6,*) " "
      DO j=jmin, jmax
         WRITE(6,23) (spin(i,j), i=imin,imax)
  23     FORMAT(10 I3)
      END DO
      WRITE(6,*) " "
      CALL KFLUSH(6)
      CALL KSINGL(6)
      RETURN
      END


C---------------------------------------------------------------------------


C
C Print out the bonds and cluster labels for debugging purposes.
C

      SUBROUTINE print_label(level)
      INCLUDE "common.h"
      INCLUDE "cluster.h"
      INTEGER level
      INTEGER i,j, scale, num
      INTEGER imin,imax,jmin,jmax, step
      INTEGER n,lognum,digits
      CHARACTER ichar(0:MAX_SIDE+1)
      CHARACTER jchar(0:MAX_SIDE+1)

C     scale = 2**level
      imin = 0
      jmin = 0
C     imax = isiz/scale+1;
C     jmax = jsiz/scale+1;
      imax = isiz+1
      jmax = jsiz+1
      num = imax - imin + 1

      CALL KMULTI(6)
      WRITE(6,*) " "
      DO j=jmin, jmax
         DO i=imin, imax
            IF (ibond(i,j)) THEN
	       ichar(i) = "-"
	    ELSE
	       ichar(i) = " "
	    END IF
            IF (jbond(i,j)) THEN
	       jchar(i) = "|"
	    ELSE
	       jchar(i) = " "
	    END IF
	 END DO
         WRITE(6,25) (jchar(i),Npoint(label(i,j)),ichar(i),i=imin,imax)
  25     FORMAT(10 (A1,I3,A1))
      END DO
      WRITE(6,*) " "
      CALL KFLUSH(6)
      CALL KSINGL(6)
      RETURN
      END


C---------------------------------------------------------------------------

C
C   Check that the labeling is consistent.
C

	SUBROUTINE check_labeling
        INCLUDE "common.h"
	INCLUDE "cluster.h"
	INTEGER i,j,n

C ----  Pass edge labels.
        CALL label_edges

	CALL KMULTI(6)
	DO i=1,isiz
	DO j=1,jsiz
	  IF (( ibond(i,j) ).AND.( label(i,j).NE.label(i+1,j) )) THEN
	    WRITE(6,*) 'labeling is incorrect! x dir, proc ',
     &                  procnum, i,j, label(i,j),label(i+1,j)
	  ENDIF
	  IF (( jbond(i,j) ).AND.( label(i,j).NE.label(i,j+1) )) THEN
	    WRITE(6,*) 'labeling is incorrect! y dir, proc ',
     &                  procnum, i,j, label(i,j),label(i,j+1)
	  ENDIF
	ENDDO
	ENDDO
	CALL KFLUSH(6)
	CALL KSINGL(6)
	RETURN 
	END

