
C----------------------------------------------------------------------C
C                                                                      C
C  Read in the parameters for the simulation.                          C
C                                                                      C
C----------------------------------------------------------------------C
 
      SUBROUTINE input(seed,start)
      INCLUDE 'common.h'
      INTEGER seed,start

  1   WRITE(6,50) 'Length of the lattice (must be <= ',MAX_SIDE,')? '
  50  FORMAT(A,I4,A)
      READ *,  side
      PRINT *, side
      IF ( (side.GT.MAX_SIDE).OR.(side.LT.1) ) THEN
        WRITE(6,*) 'You entered a bogus length - try again.'
        GOTO 1
      ENDIF
      sites = side * side
      volume = FLOAT(sites)
      PRINT *, 'Volume = ', sites

      PRINT *, 'Number of thermalization sweeps? '
      READ *,  therm_sweeps
      PRINT *, therm_sweeps

      PRINT *, 'Number of sweeps per measurement? '
      READ *,  sweeps
      PRINT *, sweeps

      PRINT *, 'Bin size? '
      READ *,  bin_size
      PRINT *, bin_size

      PRINT *, 'Number of bins? '
      READ *,  num_bins
      PRINT *, num_bins

      measurements = bin_size * num_bins
      PRINT *, 'Number of measurements = bin size x number of bins ='
      PRINT *, measurements

      PRINT *, 'Beta (inverse temperature)? '
      READ *,  beta
      PRINT *, beta

      PRINT *, 'Ordered (0) or random (1) start? '
      READ *,  start
      PRINT *, start

      PRINT *, 'Seed for the random number generator? '
      READ *,  seed
      PRINT *, seed

      RETURN 
      END


 
C----------------------------------------------------------------------C
C                                                                      C
C  Initialize the spins with an ordered or random start.               C
C                                                                      C
C----------------------------------------------------------------------C
 
      SUBROUTINE init_spins(start)
      INCLUDE "common.h"
      INTEGER start
      INTEGER i,j
      REAL rand
	
      IF (start.EQ.0) THEN
C ----  Ordered (cold) start
        DO i=1,side
        DO j=1,side
          spin(i,j) = 1
        ENDDO
        ENDDO
      ELSE 
C ----  Random (hot) start
        DO i=1,side
        DO j=1,side
          IF (rand() .LT. 0.5) THEN
            spin(i,j) = 1
          ELSE
            spin(i,j) = -1
          ENDIF
        ENDDO
        ENDDO
      ENDIF
      RETURN 
      END



 
C----------------------------------------------------------------------C
C                                                                      C
C  Look-up table of neighbors to impose periodic boundary conditions.  C
C                                                                      C
C----------------------------------------------------------------------C
 
      SUBROUTINE neighbors
      INCLUDE "common.h"
      INTEGER i
      DO i=1,side
        pos(i) = MOD(i,side) + 1
        neg(i) = MOD(i+side-2,side) + 1 
      ENDDO
      RETURN 
      END


