Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Problem with initial state in FORTRAN

  1. Mar 12, 2015 #1
    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 (Text):

    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!!!
     
  2. jcsd
  3. Mar 12, 2015 #2

    jtbell

    User Avatar

    Staff: Mentor

    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.)
     
  4. Mar 12, 2015 #3
    error 112: reference to undefined variable, array element or function result.
    Thank you jtbell!
     
  5. Mar 12, 2015 #4

    DrClaude

    User Avatar

    Staff: Mentor

    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).
     
  6. Mar 13, 2015 #5
    the problem is in :
    Code (Text):
    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 dont know why.
    o_O
     
  7. Mar 13, 2015 #6

    jtbell

    User Avatar

    Staff: Mentor

    You appear to be using a function named RANDOM_NORMAL_MOD. Where is it defined?
     
  8. Mar 13, 2015 #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.
     
  9. Mar 18, 2015 #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:
     
  10. Mar 18, 2015 #9
    The function named RANDOM_NORMAL_MOD is defined in other page.
     
  11. Mar 18, 2015 #10

    jtbell

    User Avatar

    Staff: Mentor

    Does the error message tell you which line of your code it refers to?
     
  12. Mar 18, 2015 #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?
     
  13. Mar 18, 2015 #12

    Mark44

    Staff: Mentor

    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.
     
  14. Mar 21, 2015 #13
    Thank you for you help!! I have solved the problem!!! :smile:
     
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook




Similar Discussions: Problem with initial state in FORTRAN
  1. Problems In Fortran (Replies: 2)

  2. Fortran problem (Replies: 1)

  3. Function problem (Replies: 8)

Loading...