What could be causing the error in SAVEDATA!KEEP subroutine?

  • Context: Fortran 
  • Thread starter Thread starter spelux11
  • Start date Start date
  • Tags Tags
    Error Fortran95
Join the discussion
Ask a follow-up here, or get your own question answered by working scientists, mathematicians and engineers — people, not an autocomplete.
Real named experts · corrections over time · the nuance an AI answer skips
1 replies · 3K views
spelux11
Messages
1
Reaction score
0
Hi,
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)
stop
end program random

module SAVEDATA


contains

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)
enddo

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.

SPELUX11
 
on Phys.org
spelux11 said:
Hi,
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)
stop
end program random

module SAVEDATA


contains

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)
enddo

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.

SPELUX11

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.