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

In summary: Please try initializing N and passing V and N to your subroutine and see if that works. Good luck!In summary, the conversation discusses a problem with a Fortran95 program that involves creating a random generator using the RANMAR subroutine. The user is having trouble with the keep() subroutine and receives an error message referring to an undefined variable or function. The expert suggests looking at line 24 of the file salvar.f95 and initializing variables and passing them as parameters in the subroutine to resolve the issue.
  • #1
spelux11
1
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
  • #2
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.
 

What is Error 112 in FORTRAN95?

Error 112 in FORTRAN95 is a common error that occurs when the program tries to read or write a file that does not exist or cannot be accessed. This error is also known as a "file not found" error.

How do I fix Error 112 in FORTRAN95?

To fix Error 112 in FORTRAN95, you will need to check the file path and make sure the file exists in the specified location. If the file does not exist, you will need to create it or specify a different file. You should also ensure that the file is accessible and not being used by another program.

Why does Error 112 occur when I try to open a file in FORTRAN95?

Error 112 occurs when FORTRAN95 is unable to locate or access the file you are trying to open. This could be due to a typo in the file path, the file not existing, or the file being locked by another program.

Can I prevent Error 112 from occurring in FORTRAN95?

Yes, you can prevent Error 112 from occurring in FORTRAN95 by ensuring that all file paths are correctly specified and that the files you are trying to access exist and are not in use by another program. It is also a good idea to use error handling techniques in your code to catch and handle any potential errors.

Is Error 112 in FORTRAN95 a fatal error?

No, Error 112 is not a fatal error in FORTRAN95. It is a recoverable error that can be fixed by correcting the file path or creating/accessing the file correctly. However, if the error is not handled properly in the code, it could lead to unexpected results or cause the program to crash.

Similar threads

  • Programming and Computer Science
Replies
4
Views
612
  • Programming and Computer Science
Replies
8
Views
1K
  • Programming and Computer Science
Replies
8
Views
3K
  • Programming and Computer Science
Replies
2
Views
1K
  • Programming and Computer Science
Replies
11
Views
1K
  • Programming and Computer Science
Replies
4
Views
2K
  • Programming and Computer Science
Replies
4
Views
2K
  • Programming and Computer Science
Replies
11
Views
14K
  • Programming and Computer Science
Replies
16
Views
5K
  • Programming and Computer Science
Replies
8
Views
2K
Back
Top