Problem with initial state in FORTRAN

In summary, the conversation discusses a code for creating an initial state of a system and the use of a function called RANDOM_NORMAL_MOD. The code uses common blocks and numbers to refer to lines, which is not necessary in Fortran 95. The error code 112 is mentioned, indicating a reference to an undefined variable or function. The conversation also suggests improvements, such as properly defining the program and not opening and closing the file inside the loop. The person asking for help is advised to follow instructions and provide the compiler output for further assistance.
  • #1
Jamil
8
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
  • #2
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.)
 
  • #3
error 112: reference to undefined variable, array element or function result.
Thank you jtbell!
 
  • #4
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).
 
  • #5
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
 
  • #6
You appear to be using a function named RANDOM_NORMAL_MOD. Where is it defined?
 
  • #7
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.
 
  • #8
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:
 
  • #9
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 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:
 

What is the "Problem with initial state" in FORTRAN?

The "Problem with initial state" refers to an issue that can occur when using the FORTRAN programming language. It can arise when the initial values of variables are not properly defined, leading to unexpected or incorrect results.

How does the "Problem with initial state" affect FORTRAN programs?

The "Problem with initial state" can cause errors, bugs, and incorrect calculations in FORTRAN programs. This can be frustrating for programmers and can make it difficult to obtain reliable results from the code.

What are some common causes of the "Problem with initial state" in FORTRAN?

Some common causes of this problem include not properly initializing variables, using uninitialized variables in calculations, or using the wrong data type for a variable. It can also occur when the order of operations is incorrect or when variables are not declared in the correct scope.

How can I prevent the "Problem with initial state" in my FORTRAN code?

To prevent this problem, it is important to properly initialize all variables before using them in calculations. It is also helpful to use the correct data types and to ensure that variables are declared in the correct scope. Additionally, following best practices for programming and debugging can help catch and prevent this issue.

What steps should I take if I encounter the "Problem with initial state" in my FORTRAN program?

If you encounter this problem, the first step is to carefully review your code and check for any uninitialized variables or incorrect data types. You may also want to use a debugger to step through your code and identify where the issue is occurring. If you are still having trouble, reaching out to others for help or consulting FORTRAN documentation may also be beneficial.

Similar threads

  • Programming and Computer Science
Replies
2
Views
2K
  • Programming and Computer Science
Replies
14
Views
4K
  • Programming and Computer Science
Replies
2
Views
1K
  • Programming and Computer Science
Replies
4
Views
1K
  • Engineering and Comp Sci Homework Help
Replies
4
Views
1K
  • Programming and Computer Science
Replies
5
Views
2K
  • Programming and Computer Science
Replies
4
Views
2K
  • Introductory Physics Homework Help
Replies
3
Views
1K
  • Introductory Physics Homework Help
Replies
9
Views
784
  • Introductory Physics Homework Help
Replies
4
Views
2K
Back
Top