	program ising
	integer s(0:100,0:100)
        integer e,mm
c
	read (5,*) ix,jx,nstop,w,iseed
        call ranset(iseed)
        open(2,file="moment.data",status="replace",
     &         form="formatted")     
        mx=(ix-1)*(jx-1)
        do j=0,jx
          do i=0,ix
	     s(i,j)=1
          end do
        end do 
c
        do ns=1,nstop
	   do m=0,mx
	      i=int((ix-1)*ranf())+1
              j=int((jx-1)*ranf())+1
              e=-s(i,j)*(s(i,j-1)+s(i,j+1)+s(i-1,j)+s(i+1,j))
              p=exp((e-4)/w)
	      if (ranf().lt.p) then
                  s(i,j)=-s(i,j)
              endif
              if ((i.eq.ix-1).or.(i.eq.1).or.
     &            (j.eq.jx-1).or.(j.eq.1)) then
	          s(ix,j)=s(1,j)
                  s(0,j) =s(ix-1,j)
                  s(i,jx)=s(i,1)
                  s(i,0) =s(i,jx-1)
                  s(ix,jx)=s(1,1)
                  s(ix,0) =s(0,jx-1)
                  s(0,0)  =s(ix-1,jx-1)
                  s(0,jx) =s(ix-1,1)
              endif
           end do
           mm = 0
           do j=1,jx-1
              do i=1,ix-1
                 mm = mm+s(i,j)
              end do
           end do
           pl = mm/real(mx)
           write(2,'(I4,F9.4)') ns,pl
        end do 
c
        do j=0,jx
           do i=0,ix
              if (s(i,j).eq.1) write(6,600) i,j
600           format(' ',2I5)
           end do
        end do
        close(2)
c
        end
 
