# What is IERR (FORTRAN)

Tags:
1. Sep 23, 2015

### ydonna1990

Code (Fortran):

DO

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

ENDDO

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

Last edited by a moderator: Sep 23, 2015
2. Sep 23, 2015

### Staff: Mentor

It means to store the result of the I/O operation in the variable IERR.
Code (Text):

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 (Text):

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. Sep 23, 2015

### ydonna1990

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

EXIT

ENDIF

ENDDO

4. Sep 23, 2015

### Staff: Mentor

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. Sep 23, 2015

### ydonna1990

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. Sep 23, 2015

### Staff: Mentor

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. Sep 23, 2015

### Staff: Mentor

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 whats inside it and piece that information together with what your program is doing to get an understanding of whats actually going on.

8. Sep 23, 2015

### ydonna1990

DO jj=1,nCtrl

WRITE(30,*)g_best(jj)

ENDDO

do j=1,p_num

WRITE(520,*)ii,gf_best

enddo

ENDDO

9. Sep 23, 2015

### Staff: Mentor

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: Sep 23, 2015
10. Sep 23, 2015

### Staff: Mentor

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/