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

Error 112 FORTRAN95

  1. Aug 31, 2014 #1
    I'm new in this space, I have a problem building a program with Fortran95 (I'm also new on this). The program it's really easy, I have to make a random generator using RANMAR subroutine here is the code:

    program random
    use aleatorio; use SAVEDATA
    Implicit none
    real, allocatable :: V(:)

    integer N

    write(*,*) "Choose the numbers"
    read (*,*) N

    allocate (V(N))

    call RANMAR (V,N)

    write(*,*) "Numbers:",V

    call keep()
    deallocate (V)
    end program random

    module SAVEDATA


    subroutine keep()

    real, allocatable :: V(:)
    integer N

    integer :: i
    character (len=30)::fileb

    write (*,*) 'what is the name of your file?'
    read (*,*) archivo

    open (10,file=fileb, access='append')
    do i= 1,N
    write (10, *) V(i)

    end subroutine keep
    end module SAVEDATA

    I've got problems with this subroutine, the other one works! here is the error warning:

    Run-time Error
    *** Error 112, Reference to undefined variable, array element or function result (/UNDEF)

    SAVEDATA!KEEP - in file salvar.f95 at line 24 [+019c]

    main - in file main.f95 at line 29 [+031a]

    If somebody could tell me something about it, I'd be so thankful.

  2. jcsd
  3. Aug 31, 2014 #2


    Staff: Mentor

    The error refers to line 24 of the file salvar.f95, so that's where I would look first. I would also look at line 29 of the file main.f95. Since you haven't said which file we're looking at, I can't say where the problem lies.

    However, I notice a few things about your keep() subroutine.
    1. archivo is not declared, but should be.
    2. The vector V in your subroutine is declared as allocatable, but you don't allocate any space for it. It would be better to pass V and N as parameters in your subroutine.
    3. N is declared in your subroutine, but it is never initialized, so it will contain a garbage value.

    Likely it is one or more of the above that is causing your run-time error.
Share this great discussion with others via Reddit, Google+, Twitter, or Facebook