!-----------------------------------------------------------------------------------------------------------------------------------
! Very simple program to demonstrate how to mark sites are OCCUPIED.
!
! A site (i,j) that is occupied has lattice(i,j) = .true.
!
!plot sprintf("< echo 128 0.3 1|./p |awk '$1==%d{print $2,$3}'",1) w d
!-----------------------------------------------------------------------------------------------------------------------------------
program percolation_test
 use iso_fortran_env, only: int32, real64
 implicit none
 integer       , parameter :: dp = real64, i4=int32

 integer(i4)               :: L               ! Lattice dimension
 integer(i4)               :: N               ! Total sites
 logical    , allocatable  :: lattice  (:, :)
 real(dp)   , allocatable  :: rand_grid(:, :)
 integer(i4)               :: i, j
 integer                   :: nmeas,imeas
 real   (dp)               :: p

 ! --- Initialization ---
 call random_init(.false.,.true.)
 
 print '(A             )',"# Enter L, p, nmeas: "
 read  *                 ,         L, p, nmeas
 print '(A,I6,F13.8,I12)',"# ",    L, p, nmeas

 N = L * L
 allocate(lattice(L,L),rand_grid(L,L))

 loopmeas: do imeas = 1, nmeas

 ! 1. Generate Lattice (Vectorized)
  call random_number(rand_grid)
  where (rand_grid < p)
   lattice = .true.
  elsewhere
   lattice = .false.
  end where

  do i = 1, L; do j = 1, L

   if(lattice(i,j)) print *,imeas,i,j

  end do     ; end do

 end do loopmeas

end program percolation_test
!===================================================================================================================================
!-----------------------------------------------------------------------------------------------------------------------------------
!  Copyright by Konstantinos N. Anagnostopoulos, Physics Department, National Technical University of Athens, 2025
!  konstant@mail.ntua.gr, www.physics.ntua.gr/konstant
!  
!  This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as 
!  published by the Free Software Foundation, version 3 of the License.
!  
!  This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
!  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
!  
!  You should have received a copy of the GNU General Public Liense along with this program. If not, see http://www.gnu.org/licenses
!-----------------------------------------------------------------------------------------------------------------------------------
