Understanding IERR (FORTRAN): Error Detection & More

  • Fortran
  • Thread starter ydonna1990
  • Start date
  • Tags
    Fortran
In summary, at line 11 the "line" variable holds a space separated list of filenames. If the first character of the "line" variable is a "--" then the second read statement will not be executed and the program will terminate.
  • #1
ydonna1990
15
0
Fortran:
DO
      READ(11,'(a)',iostat=IERR)line

      IF ((line(1:2)/='--').and.(line/=' '))THEN
          READ(line,*,iostat=IERR) posinumber
          EXIT
      ENDIF

ENDDO

What is IERR? Is it related to error? I couldn't find any good answer researching online.

Thanks in advance
 
Last edited by a moderator:
Technology news on Phys.org
  • #2
It means to store the result of the I/O operation in the variable IERR.
Code:
iostat=IERR, ERR=100
A more useful construct - this braches to the 100 line label on error. At line 100 test the value of the IERR variable to find the error number. You have to code the test somewhat like this:
Code:
100  IF (IERR .EQ. FOR$IOS_FILNOTFOU) THEN
          WRITE (6,*) 'File: ', FILNM, ' does not exist '
     ELSE IF (IERR .EQ. FOR$IOS_FILNAMSPE) THEN
        WRITE (6,*) 'File: ', FILNM, ' was bad, enter new file name'
    ELSE
    PRINT *, 'Unrecoverable error, code =', IERR
    STOP
    END IF
Some of the above example is FORTRAN implementation-specific - meaning those FOR$xxxxx constants are not guaranteed to exist for your flavor of FORTRAN. Eeee. I haven't looked at FORTRAN for a long time.
 
  • #3
jim mcnamara said:
It means to store the result of the I/O operation in the variable IERR.
Code:
iostat=IERR, ERR=100
A more useful construct - this braches to the 100 line label on error. At line 100 test the value of the IERR variable to find the error number. You have to code the test somewhat like this:
Code:
100  IF (IERR .EQ. FOR$IOS_FILNOTFOU) THEN
          WRITE (6,*) 'File: ', FILNM, ' does not exist '
     ELSE IF (IERR .EQ. FOR$IOS_FILNAMSPE) THEN
        WRITE (6,*) 'File: ', FILNM, ' was bad, enter new file name'
    ELSE
    PRINT *, 'Unrecoverable error, code =', IERR
    STOP
    END IF
Some of the above example is FORTRAN implementation-specific - meaning those FOR$xxxxx constants are not guaranteed to exist for your flavor of FORTRAN. Eeee. I haven't looked at FORTRAN for a long time.

Thank you for your detailed reply. So that leads me to ask some more questions.

DO

READ(11,'(a)',iostat=IERR)line so I guess this means read the line 11 and test the IERR value there. What is this "(a)" for?

IF ((line(1:2)/='--').and.(line/=' '))THEN

READ(line,*,iostat=IERR) posinumber I must also ask you what this "posinumber" means.

EXIT

ENDIF

ENDDO
 
  • #4
You have what appears to be a 'code snippet' - meaning a piece of incomplete code - I do not know if your FORTRAN compiler will compile and run it. Too many years have elapsed...

1. it is a format specifier - this tells the compiler what kinds of input to expect
Note that there is a * and a (a) - two different flavors of input.
2. it is a variable, presumably it stores positive numbers - in coding your should give meaningful names to variables.
 
  • #5
jim mcnamara said:
You have what appears to be a 'code snippet' - meaning a piece of incomplete code - I do not know if your FORTRAN compiler will compile and run it. Too many years have elapsed...

1. it is a format specifier - this tells the compiler what kinds of input to expect
2. it is a variable, presumably it stores positive numbers - in coding your should give meaningful names to variables.
You are absolutely right. It doesn't run actually. I was given an assignment to fix this and make it run. I am really new to this so I am pretty much clueless. Do you think you can help me in private?
 
  • #6
Ask your questions here, in general we don't help via private messaging because then others won't benefit from your questions and the subsequent answers.
 
  • #7
Your first read is reading data from file 11 and placing it in the "line" variable. I think the "(a)" means read it as text ie alphanumeric data.

The "if" statement looks at the first two characters of the "line" variable to see if its "--" or two spaces and if NOT then it processes the second "read" statement

The second "read" statement is reading from whatever file the "line" variable now holds.

I would look at the file read by the first "read" statement to see what's inside it and piece that information together with what your program is doing to get an understanding of what's actually going on.
 
  • #8
jedishrfu said:
Your first read is reading data from file 11 and placing it in the "line" variable. I think the "(a)" means read it as text ie alphanumeric data.

The "if" statement looks at the first two characters of the "line" variable to see if its "--" or two spaces and if NOT then it processes the second "read" statement

The second "read" statement is reading from whatever file the "line" variable now holds.

I would look at the file read by the first "read" statement to see what's inside it and piece that information together with what your program is doing to get an understanding of what's actually going on.

O.K. Thanks. What about this nCtrl here. I googled and found that it means node control. What does that mean?

DO jj=1,nCtrl

WRITE(30,*)g_best(jj)

ENDDO

do j=1,p_num

WRITE(520,*)ii,gf_best

enddo

ENDDO
 
  • #9
ydonna1990 said:
What about this nCtrl here. I googled and found that it means node control. What does that mean?

Functionally, it determines how many times the DO loop will be executed. The WRITE statement will be executed nCtrl times. For any further "meaning" of that variable, you'll have to ask the person who wrote the code. Or it may be described by a comment somewhere in the code, or in any documentation that might have come with the code.

[added later] The name of the variable (nCtrl) has nothing to do with the operation of the loop, as described in my first two sentences above. What matters is the value (number) stored in that variable: 10, 25, 1634 or whatever. Whether that variable (and the number stored in it) indicates "number of controls" or "node control" or something else, depends on the overall purpose of the code and the intention of the person who wrote it.
 
Last edited:
  • #10
Also a lot of your questions are very basic.

I would suggest reading a book on fortran programming so you understand what "read", "write" statements are used for and how "do" and "if" statements are used.

Here's one such reference to Fortran which may or may not apply to the version of fortran you are using:

http://web.stanford.edu/class/me200c/tutorial_77/
 

Related to Understanding IERR (FORTRAN): Error Detection & More

What is IERR in FORTRAN?

IERR stands for "internal error." In FORTRAN, it is a specific type of error that occurs when the program detects an error in its own internal operations, rather than an error in the input or output of the program. IERR is typically used to indicate a problem with the program's logic or structure.

How is IERR detected in FORTRAN?

In FORTRAN, IERR is typically detected through the use of the "IF IERR" statement. This statement checks the value of the IERR variable and executes a specific set of instructions if the value is non-zero. Programmers can also use the "IERR=0" statement to reset the IERR variable to zero, indicating that no internal errors have been detected.

What are some common causes of IERR in FORTRAN?

IERR can be caused by a variety of factors, such as incorrect syntax or logic errors in the program, insufficient memory or storage space, or unexpected input data. It can also be caused by a failure in the compiler or other system software used to run the program.

How can IERR be prevented in FORTRAN?

To prevent IERR in FORTRAN, it is important for programmers to carefully review and debug their code, ensuring that all syntax and logic errors have been addressed. Additionally, proper memory management and handling of input data can help prevent unexpected errors from occurring.

What are some other error types in FORTRAN?

In addition to IERR, other common error types in FORTRAN include syntax errors, logical errors, and runtime errors. Syntax errors occur when the code does not follow the proper syntax rules of the language. Logical errors occur when the code does not produce the expected output due to incorrect logic or calculations. Runtime errors occur during the execution of the program and can be caused by factors such as invalid input data or insufficient memory.

Similar threads

  • Programming and Computer Science
Replies
12
Views
3K
  • Programming and Computer Science
Replies
12
Views
1K
  • Programming and Computer Science
2
Replies
54
Views
4K
  • Programming and Computer Science
Replies
16
Views
2K
  • Programming and Computer Science
Replies
1
Views
2K
  • Programming and Computer Science
Replies
4
Views
10K
  • Programming and Computer Science
Replies
5
Views
4K
  • Programming and Computer Science
Replies
6
Views
2K
  • Programming and Computer Science
Replies
19
Views
5K
  • Programming and Computer Science
Replies
5
Views
3K
Back
Top