C
C Print out the spins for debugging purposes.
C

      SUBROUTINE print_spin
      INCLUDE  "exp_wolff.h"
      INTEGER  i,j,k,m,x,y,d
      INTEGER  pnum(0:Nrow_max-1)
      INTEGER  ori_spin(0:Nrow_max-1,0:Nrow_max-1)

      DO k=1, nproc
            DO j=0,ntile-1
               DO i=0, Nrow-1
                  DO m=0,width-1
                     IF(procnum .EQ. proc_order(k)) THEN
                        y=(k-1)*width+j*twidth+m
                        x=j*width+m
                        pnum(y)=proc_order(k)
                        ori_spin(i,y)=spin(i,x)
                     ENDIF
                  ENDDO
               ENDDO
            ENDDO
         d=KXBROD(ori_spin,proc_order(k), N*N*4,IALNOD,0,i+111)
         d=KXBROD(pnum,proc_order(k),N*4,IALNOD,0,i+112)  
      ENDDO

      WRITE(6,55)
      WRITE(6,33) (pnum(j), j=0,N-1)
      DO i=0,N-1
         WRITE(6,33) (ori_spin(i,j), j=0,N-1)
 33      FORMAT(32 I3)
      ENDDO
      WRITE(6,55)
 55   FORMAT(///)

      RETURN
      END

C=================================================================

      SUBROUTINE print_cluster(c)
      INCLUDE  "exp_wolff.h"
      INTEGER  c,i,j,k,m,x,y,d
      INTEGER  pnum(0:Nrow_max-1)
      INTEGER  ori_spin(0:Nrow_max-1,0:Nrow_max-1)

      DO k=1, nproc
            DO j=0,ntile-1
               DO i=0, Nrow-1
                  DO m=0,width-1
                     IF(procnum .EQ. proc_order(k)) THEN
                        y=(k-1)*width+j*twidth+m
                        x=j*width+m
                        pnum(y)=proc_order(k)
                        ori_spin(i,y)=spin(i,x)
                     ENDIF
                  ENDDO
               ENDDO
            ENDDO
         d=KXBROD(ori_spin,proc_order(k), N*N*4,IALNOD,0,i+111)
         d=KXBROD(pnum,proc_order(k),N*4,IALNOD,0,i+112)  
      ENDDO

      IF(c .EQ. 0) THEN
         DO i=0,N-1
            DO j=0,N-1
               oldspin(i,j)=ori_spin(i,j)
            ENDDO
         ENDDO
      ENDIF

      DO i=0,N-1
         DO j=0,N-1
            IF(ori_spin(i,j) .EQ. oldspin(i,j)) THEN
c               WRITE(6,44) i,j,c1,c2,c3
            ENDIF
         ENDDO
      ENDDO

C--- Black and White
C
      DO i=0,N-1
         DO j=0,N-1
            IF(ori_spin(i,j) .EQ. 1) THEN
               WRITE(6,*) i,j
            ENDIF
         ENDDO
      ENDDO

      DO i=0,N-1
         DO j=0,N-1
            oldspin(i,j)=ori_spin(i,j)
         ENDDO
      ENDDO
      

      RETURN
      END


