Error 112 /undef when running fortran code

In summary, the conversation revolves around a problem with a Fortran code where the code is stopped on the last line and an error message appears. The issue seems to be with the OPEN and READ statements, and the conversation suggests checking the iostat value and the file name for any errors. It is recommended to use string manipulations or zero-padding to avoid blank spaces in the file name.
  • #1
Marco87
2
0
Hi,

I am a new Fortran User.

I have a problem when I run my code (not errors during building), in fact the code is stopped in the last line and this message appears "Error 112, Reference to undefined variable, array elements or function result"

...
write(number,100)k1
open (unit=12, file='diff//number//'.txt', status='old', POSITION='APPEND', iostat=ISTATUS, action='read',form='formatted')
READ (12,*, iostat=ISTATUS) i1r, i2r, i3r, sr, kr
close(12)
write(*,*) i1r
...

I checked the iostat value and it is 0 in open and -1 in read.

" 5 10 1 1.00000 1" (This is the first line of my txt file)

Where is the problem?
 
Technology news on Phys.org
  • #2
Without seeing more of your code, I don't think a positive answer can be given.

However, in your OPEN statement, the FILE= option is missing ' after 'diff// ...

This could lead to some confusion on the part of the compiler.
 
  • #3
The FILE option is BEFORE the "diff", part...see it?

I would like to see how "number" is defined.

I (and you too) would like to see what the resulting file name is when you concatenate diff//number//'.txt' ...it may be that you are getting something line "diff3 .txt" simply because of the way (length) the character variable "number" might have been defined.

I would like to see the entire content of the file you are trying to open and read from.
 
  • #4
So...put together the file name BEFORE you attempt to use it in the read statement, use another character variable, say, "fname" to put the name into and write out to the terminal to see what it looks like.
 
  • #5
Hi,

Number is defined in this way:

"CHARACTER(len=8) :: number"

then it is initialized

"write(number,100)1
[...]
do k1=1, k
do
write(number,100)k1

open (unit=12, file='diff'//number//'.txt', status='old', POSITION='APPEND', iostat=ISTATUS, action='read',form='formatted')
READ (12,*, iostat=ISTATUS) i1r, i2r, i3r, sr, kr
close(12)
write(*,*) i1r
[...]
enddo
end do"

in the file "diff 1.txt", i have these number:
5 10 1 1.00000 1
5 10 1 1.00000 1

I can write in this file, when I try to read I have a problem! I think that the line
"READ (12,*, iostat=ISTATUS) i1r, i2r, i3r, sr, kr"
does not work!

Thanks
Marco
 
  • #6
so you are getting blank spaces as part of the file name? maybe that's your problem...why don't you do some string manipulations or zero-padding on the left or something to get a nice file name without blank spaces in the middle of it?
 

What is "Error 112 /undef" when running fortran code?

"Error 112 /undef" is a common error that occurs when a variable or function is used but has not been defined in the code. This means that the computer cannot find the necessary information to execute the command, resulting in the error message.

How can I fix "Error 112 /undef" in my fortran code?

To fix this error, you will need to go back to your code and make sure all variables and functions are properly defined. This includes checking for spelling errors, ensuring all necessary variables have been declared, and making sure functions are properly called. Fixing these errors should resolve the "Error 112 /undef" issue.

Why am I getting "Error 112 /undef" even though I defined all my variables?

It is possible that you may have defined your variables in one section of your code, but are trying to use them in a different section. Make sure your variables are defined in the correct scope and are accessible from where they are being used. Also, check for any potential conflicts with variable names.

Can a typo in my code cause "Error 112 /undef"?

Yes, a simple typo such as misspelling a variable name or function name can result in the "Error 112 /undef" message. It is important to carefully review your code for any spelling errors or incorrect syntax.

What other factors can contribute to "Error 112 /undef" in fortran code?

Aside from variable and function definitions, other factors such as incorrect data types, missing library files, or issues with the compiler can also lead to "Error 112 /undef". It is important to thoroughly check all aspects of your code and ensure everything is in order to avoid this error.

Similar threads

  • Programming and Computer Science
Replies
4
Views
602
  • Programming and Computer Science
Replies
9
Views
6K
  • Programming and Computer Science
Replies
12
Views
1K
  • Programming and Computer Science
Replies
5
Views
4K
  • Programming and Computer Science
Replies
4
Views
1K
  • Programming and Computer Science
Replies
14
Views
1K
  • Programming and Computer Science
Replies
2
Views
294
  • Programming and Computer Science
Replies
2
Views
1K
  • Programming and Computer Science
Replies
2
Views
2K
  • Programming and Computer Science
Replies
8
Views
1K
Back
Top