Problem with initial state in FORTRAN

Click For Summary

Discussion Overview

The discussion revolves around a FORTRAN code issue related to initializing a system with periodic boundary conditions and normal distribution of velocities. Participants explore the nature of a compilation error, specifically error 112, and discuss potential causes and solutions.

Discussion Character

  • Technical explanation
  • Debate/contested
  • Homework-related

Main Points Raised

  • One participant reports a compilation error (112) and seeks assistance in identifying the problem.
  • Another participant explains that error 112 refers to a reference to an undefined variable, array element, or function result.
  • Some participants suggest that the issue may stem from the use of the 'FMT=I' in the WRITE statement.
  • There are concerns about the use of comparison operators in the code, with one participant questioning the compatibility with FORTRAN 77 syntax.
  • Another participant inquires about the definition of the function RANDOM_NORMAL_MOD, which is used in the code but not defined within the provided snippet.
  • Suggestions are made to modernize the code by removing common blocks, avoiding line numbers for loops, and improving file handling efficiency.
  • One participant emphasizes the importance of providing the exact compiler output for better assistance.
  • A later reply indicates that the original poster has resolved the issue, but details of the resolution are not provided.

Areas of Agreement / Disagreement

Participants express various opinions on the potential causes of the error, and while some suggestions are made, there is no consensus on a single solution. The discussion reflects differing views on coding practices and compiler compatibility.

Contextual Notes

Limitations include the lack of clarity on the definition and implementation of the RANDOM_NORMAL_MOD function, as well as the specific line of code that triggered the error message. The discussion also highlights the transition from older FORTRAN practices to more modern coding standards.

Jamil
Messages
8
Reaction score
0
I have created an initial state code with perodic boundary conditions and normal distribution of velocities. I not know where is the problem, when I compile the computer detect the 112 error. Could anyone help me please? Thanks!
the code is:
************************************************************
Code:
COMMON / BLOCK1 / RX, RY, RZ, VX, VY, VZ, PVX, PVY, PVZ
!En este fichero programaremos el estado inicial de nuestro sistema.
INTEGER (SELECTED_INT_KIND(2)) N !Número de moléculas
PARAMETER (N=125)
INTEGER (SELECTED_INT_KIND(4)) I !Átomo I-ésimo
REAL RX(N), RY(N), RZ(N) !Posiciones de los distintos átomos
REAL VX(N), VY(N), VZ(N) !Velocidades de los distintos átomos
REAL PVX(N), PVY(N), PVZ(N) !GAUSSIANA EVALUADA (PROBABILIDAD)
REAL VMEDIAX, VMEDIAY, VMEDIAZ
REAL VTOTAL2, ECINETICA !VTORAL2 corresponde al módulo de la velocidad media al cuadrado, ECINETICA es la energía cinética por partículas
REAL L
TRED=2.5
DENSIDAD=0.2
L=(N/DENSIDAD)**(1/3)
VMEDIAX=0
VMEDIAY=0
VMEDIAZ=0
VMEDIA2=0
ECINETICA=0

!El sistema de coordenadas cartesianas estará centrado en el cubo,
!de tal forma que las variables  RX, RY, RZ estarán dentro del intervalo
![-L/2,L/2]
   DO 100 I=1,N
   IF (RX(I)> L/2) RX(I)=RX(I)-L
  IF (RX(I)< -L/2) RX(I)=RX(I)+L 
   IF (RY(I)< L/2) RY(I)=RY(I)-L
  IF (RY(I)> -L/2) RY(I)=RY(I)+L
   IF (RZ(I)< L/2) RZ(I)=RZ(I)-L
  IF (RZ(I)> -L/2) RZ(I)=RZ(I)+L
100 ENDDO

!Las velocidades se medirán en unidades (epsilon/n)**0.5
!De este modo el argumento de la exponencial será la velocidad reducida al
!cuadrado entre la temperatura reducida
   DO 200 I=1,N
     VX(I)= RANDOM_NORMAL_MOD (-VX(I)/TRED,(TRED/2)**0.5)
     VY(I)= RANDOM_NORMAL_MOD (-VY(I)/TRED,(TRED/2)**0.5)
     VZ(I)= RANDOM_NORMAL_MOD (-VZ(I)/TRED,(TRED/2)**0.5)
  PVX(I)= (((2/TRED)**0.5)/(2*2.1416)**0.5)*EXP(-((VX(I))**2)/TRED)
  PVY(I)= (((2/TRED)**0.5)/(2*2.1416)**0.5)*EXP(-((VY(I))**2)/TRED)
  PVZ(I)= (((2/TRED)**0.5)/(2*2.1416)**0.5)*EXP(-((VZ(I))**2)/TRED)
  OPEN(10,FILE='DATOS.DAT',STATUS='OLD')
  WRITE (10,FMT=I)'PROBABILIDADESX' , PVX(I), VX(I)
  WRITE (10,FMT=I)'PROBABILIDADESY' , PVY(I), VY(I)
  WRITE (10,FMT=I)'PROBABILIDADESZ' , PVZ(I), VZ(I)
  CLOSE(10)
  VMEDIAX= VMEDIAX+VX(I)
  VMEDIAY= VMEDIAY+VY(I)
  VMEDIAZ= VMEDIAZ+VZ(I)
  VTOTAL2= VTOTAL2 + (VX(I))**2 + (VY(I))**2 + (VZ(I))**2
200 ENDDO
VMEDIA2=VMEDIA2/N
ECINETICA=0.5*VTOTAL2 !Es la energía cinética por partículas y por unidad de masa, la cual corresponde a la masa de las moléculas de nuestro sistema.
PRINT *, "El valor medio de la velocidad a lo largo del eje x es: ", VMEDIAX
PRINT *, "El valor medio de la velocidad a lo largo del eje Y es: ", VMEDIAY
PRINT *, "El valor medio de la velocidad a lo largo del eje Z es: ", VMEDIAZ
PRINT *, "El valor de la energía cinética media por partículas y por unidad de masa es: " , ECINETICA

END
************************************************
Thank you!
 
Technology news on Phys.org
Jamil said:
when I compile the computer detect the 112 error.

What is a 112 error? Or at least, which compiler are you using?

(The meaning of error codes depends on which compiler is being used.)
 
error 112: reference to undefined variable, array element or function result.
Thank you jtbell!
 
I don't get such an error when trying to compile your code. The only problem is the use of 'FMT=I' in WRITE (10,FMT=I).
 
the problem is in :
Code:
IF (RX(I) >  L*0.5) RX(I)=RX(I)-L
IF (RX(I) < -L*0.5) RX(I)=RX(I)+L
IF (RY(I) >  L*0.5) RY(I)=RY(I)-L
IF (RY(I) < -L*0.5) RY(I)=RY(I)+L
IF (RZ(I) >  L*0.5) RZ(I)=RZ(I)-L
IF (RZ(I) < -L*0.5) RZ(I)=RZ(I)+L
but I don't know why.
o_O
 
You appear to be using a function named RANDOM_NORMAL_MOD. Where is it defined?
 
are you using Fortran 77? Because I don't think " < " is part of it...you would need to use " .LT. ", instead.

Please indicate what compiler you are using and please copy and paste the error message, a few lines if need be.
 
I am using FORTRAN 95, and the error message is: ''Error 112, reference to undefined variable, array element or function result (/UNDEF)''
Thanks for your interest! :smile:
 
The function named RANDOM_NORMAL_MOD is defined in other page.
 
  • #10
Does the error message tell you which line of your code it refers to?
 
  • #11
Yeap...that is precisely why I explicitly asked Jamil to copy and paste the compiler output, it most probably prints a line with where it thinks the problem is and the following line with a caret " ^ " pointing to the variable or something.

Jamil:

If you are using Fortran 95, then, use Fortran 95:
  • Add proper "program pname" and corresponding "end program pname"
  • Stop using common blocks
  • Stop using using numbers to refer to lines. For example, do-loops like "DO 200 I=1,N " are no longer necessary. Do-loops used to be done with "do 200 . . . 200 continue" ; nowadays, it is done with " do . . . enddo " ... so, your use of "200 enddo" is in fact a mix of styles!
  • You do not need to open and close the file inside the loop...you can open it right before the loop and close it right after...much more efficient
  • When asking for help, you should follow instructions...if you have not solved the problem and you do not know how to interpret the compiler error message, do as I asked and paste the compiler output and see if we can help further. When pasting, make sure to also paste the command line you are using to compile...you keep saying RANDOM_NORMAL_MOD is somewhere else...where? and how does this program know about it?
 
  • Like
Likes   Reactions: Mark44
  • #12
gsal said:
Yeap...that is precisely why I explicitly asked Jamil to copy and paste the compiler output, it most probably prints a line with where it thinks the problem is and the following line with a caret " ^ " pointing to the variable or something.

Jamil:

If you are using Fortran 95, then, use Fortran 95:
  • Add proper "program pname" and corresponding "end program pname"
  • Stop using common blocks
  • Stop using using numbers to refer to lines. For example, do-loops like "DO 200 I=1,N " are no longer necessary. Do-loops used to be done with "do 200 . . . 200 continue" ; nowadays, it is done with " do . . . enddo " ... so, your use of "200 enddo" is in fact a mix of styles!
  • You do not need to open and close the file inside the loop...you can open it right before the loop and close it right after...much more efficient
  • When asking for help, you should follow instructions...if you have not solved the problem and you do not know how to interpret the compiler error message, do as I asked and paste the compiler output and see if we can help further. When pasting, make sure to also paste the command line you are using to compile...you keep saying RANDOM_NORMAL_MOD is somewhere else...where? and how does this program know about it?
Very good points, all, and especially the advice to move the file open/close outside the loop. It is very inefficient to open and close the file 125 times.
 
  • #13
Thank you for you help! I have solved the problem! :smile:
 

Similar threads

  • · Replies 2 ·
Replies
2
Views
3K
Replies
14
Views
5K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 4 ·
Replies
4
Views
2K
  • · Replies 4 ·
Replies
4
Views
3K
  • · Replies 4 ·
Replies
4
Views
2K
  • · Replies 5 ·
Replies
5
Views
2K
  • · Replies 3 ·
Replies
3
Views
2K
Replies
3
Views
2K
Replies
9
Views
2K