'When I run a program it runs for a microsecond and then closes, without any input on my behalf

I'm trying to run a simulation on the Monte Carlo problem. Whenever I try to run my version of the program (meant for up to 100/101 steps) it runs for a split second and then it closes. I can't even add any input whatsoever.

I've tried anything I can think of, including modifying the code of my 50 steps program (which is working accordingly and is exactly the same as my 101 steps program) to try and run it, but the issue remains.

The code as it follows should start by asking the size of the overall net (which should be 50) and, later on the amount of drunkards used (I tipically use 10,000 drunks). The output should be the position of each drunkard, the standard deviation of the amount of drunkards in each position, and an external output with the mount of drunkards per position.

implicit none

integer x, y, T, L, N, B, PL, PV, E, DP1
real *8 S(101, 101)
real *8 r
double precision M
real *8 U
real *8 Pit
real *8 Pitotal
real *8 DP2
real *8 DPF
real *8 PVT
real *8 PLT

read(*,*) L !Tamanho da rede
!read(*,*) U !Quantidade de passos
read(*,*) B !Quantidade de bêbados
!Zerar os vetores

!WRITE(*,*) PV, PL
do x = 1, L
  do y = 1, L
    S(x, y) = 0
    !WRITE(*,*) x, y, S(x, y)
  enddo
enddo
 
!Simular Caminhar e Escrever na Matriz
do T = 1, B
  PV = (L/2)+1
  PL = (L/2)+1
  !Determinar a quantidade de passos dados até 101
  !!! THIS IS WHERE BOTH THE 50 STEPS CODE AND THE 101 STEPS CODE DIFFER THIS ONE'S SUPPOSED TO MULTIPLY THE RANDOM NUMBER IN ORDER TO GET A NUMBER OF STEPS THAT DOESN'T EXCEED 101,. WHILE THE OTHER JUST RANDOMLY ASSIGNS 50 OR 51 STEPS.
  call random_number(U)
  U = U * 101 + 1
  !Simular Caminhar
  do N = 1, int(U)
    call random_seed()  !Gerar a seed aleatória
    call random_number(r)
    if (r < 0.5) then
      PV = PV-1
    else
      PV = PV+1
      !WRITE(*,*) PV, PL
    endif
    
    !Junção de contorno para determinar o ponto final mesmo se estourar a rede
    if (PV > L) then
      !PV = 1
      PV = mod(PV,L)
    elseif (PV < 1) then
      !PV = L
      PV = L - mod(PV,L)
    else
    endif
     
    call random_seed()
    call random_number(r)
    if (r < 0.5) then
      PL = PL-1
    else
      PL = PL+1
    endif
    
    !WRITE(*,*) PV, PL
    !Junção de contorno para determinar o ponto final mesmo se estourar a rede
    if (PL > L) then
      !PL = 1
      PL = mod(PV,L) 
    elseif (PL < 1) then
      !PL = L
      PL = L - mod(PV,L)
    else
    endif
  enddo

  WRITE(*,*) PV, PL
  PVT = PV
  PLT = PL
  !Escrever na matriz
  S(PV,PL) = S(PV,PL) + 1
  !Calcular a distância total relativa ao ponto inicial (pitágoras)
  Pit = sqrt((PVT*PVT)+(PLT*PLT))
  Pitotal = Pitotal + Pit
enddo

WRITE(*,*) Pitotal
!Calcular a distância média
M = Pitotal/B
WRITE(*,*) M
!Calcular o Desvio Padrão
do DP1 = 1,B !Somatório
  E = E + ((Pitotal-M) * (Pitotal-M))
enddo
!Dividir o somatório por B * (B-1)
DP2 = E / (B * (B-1))
!Extrair a raíz da divisão
DPF = sqrt(DP2)
WRITE(*,*) E, DP2, DPF
 
!Escrever os resultados
do x = 1, L
  do y = 1, L
    S(x,y) = S(x,y)/B
    WRITE(10,*) x, y, S(x,y)
  enddo
enddo

The culprit seems to be the number of steps desired, not even using the same method used in the 50/51 steps program seems to solve it (even though it would be incorrect given the fact that this program should generate steps up to 100/101, not just 100/101 steps). Any ideas on how I can solve this?

p.s. I'm using Visual Studio Code to compile the program and trying to run it on cmd, I already tried to use VSC to run it, but the issue persists.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source