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
Click For Summary
SUMMARY

The error in the SAVEDATA!KEEP subroutine of the Fortran95 program is caused by multiple issues, including the undeclared variable 'archivo', the unallocated array 'V', and the uninitialized integer 'N'. The run-time error message indicates a reference to an undefined variable, specifically at line 24 of salvar.f95 and line 29 of main.f95. To resolve this, 'archivo' should be declared, 'V' should be passed as a parameter to the subroutine, and 'N' should be initialized properly before use.

PREREQUISITES
  • Understanding of Fortran95 programming language
  • Familiarity with subroutine and module structures in Fortran
  • Knowledge of dynamic memory allocation in Fortran
  • Basic debugging techniques for run-time errors in Fortran
NEXT STEPS
  • Learn how to declare and initialize variables in Fortran95
  • Research dynamic memory allocation and deallocation in Fortran95
  • Study parameter passing in Fortran subroutines
  • Explore common run-time errors in Fortran and their resolutions
USEFUL FOR

Fortran developers, programmers debugging Fortran applications, and students learning Fortran95 programming concepts.

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
 
Technology news 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.
 

Similar threads

  • · Replies 4 ·
Replies
4
Views
3K
  • · Replies 8 ·
Replies
8
Views
2K
  • · Replies 8 ·
Replies
8
Views
4K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 16 ·
Replies
16
Views
6K
Replies
3
Views
3K
  • · Replies 4 ·
Replies
4
Views
2K
  • · Replies 11 ·
Replies
11
Views
2K
Replies
11
Views
16K
  • · Replies 3 ·
Replies
3
Views
6K