# INTEGER Input: The I Descriptor The Iw and Iw.m descriptors are used for INTEGER input; however, the effect of Iw.d is identical to that of Iw. Therefore, we shall only discuss Iw. The general form of the Iw descriptor is as follows:

rIw

The meaning of r, w and m are:

• I is for INTEGER
• w is the width of field, which indicates that an integer should be read in from the next w positions.
• The w positions must contain an integer with an optional sign. More precisely, an integer starts an option sign (i.e., a + or -) followed by a string of digits. No other symbols can be used; otherwise, the READ statement that uses this format will report an error and stop. If all w positions are spaces, the value is treated as a zero.
• r is the repetition indicator, which gives the number of times the edit descriptor should be repeated. For example, 3I5.3 is equivalent to I5.3, I5.3, I5.3.
• The way of treating blanks in the w positions is important. There are two interpretations:
1. All spaces are ignored. In this case, all spaces in the w positions are removed and the result is treated as an integer. For example, suppose we have
```INTEGER :: a, b, c, d

```
and the input
```         1    1    2
....5....0....5....0
1 3 5 135 135    135
```
Then, all four variables receive the same value, 135. Let us see why. All four variables are read with I5. Variable a takes the first five positions, which contain 1, followed by a space, followed by 3, followed by a space, followed by 5. After removing all spaces, we have 135, which becomes the value for a. You can reach the same conclusion for variables b, c and d.
2. All spaces are treated as zeros. In this case, we may consider that each space in the w positions is a zero. If spaces are treated in this way, the variables a, b, c and d receive 10305, 1350, 13500 and 135, respectively. Consider variable a. It takes the first five positions, which are treated as 1, followed by 0, followed by 3, followed by 0, followed 5, and therefore the value for a is 10305! Similarly, d takes the last five positions, which are zero, zero, 1, 3 and 5, and the result is 00135 = 135.

Whether a space is treated as a zero or ignored is system dependent. But, you can easily figure it out. Type in the following example and run it with the above input. Based on the output, you will know how your Fortran compiler handles spaces.

```PROGRAM  To_see_if_spaces_are_zeros
IMPLICIT  NONE
INTEGER :: a, b, c, d

WRITE(*,*)  a, b, c, d
END PROGRAM  To_see_if_spaces_are_zeros
```
The way of treating spaces affects your input. If your system chooses to ignore spaces, then the input integer can be anywhere in the w positions, even with embedded spaces. Otherwise, all of your input integers must be right-justified. Note that Fortran has edit descriptors to change this behavior (e.g., BN and BZ). Also note that our system ignores spaces. ### Examples

Suppose we have the following input and the system ignores spaces.
```         1    1    2
....5....0....5....0
12 34  56  78  90
```
• What are the values in each variable after reading in the above input?
```INTEGER :: a, b, c, d

READ(*,"(I1, I2, I3, I4)")  a, b, c, d
```
Variable a takes the first position, which contains 1. Thus, a receives 1. Variable b takes the next two positions, which contain 2, followed by a space. Since all spaces are ignored, b receives 2. Variable c takes the next three positions, which contain 3, 4 and a space. Therefore, c receives 34. Variable d takes the next four positions, which contain a space, followed by 5, followed by 6, followed by a space. Thus, d receives 56.

If the system treats spaces as zeros, a, b, c and d receive 1, 20, 340 and 560, respectively.

Since all variables have received values, the remaining input are ignored. This is exactly the same as what you have learned in listed-directed READ.

• What are the values in each variable after reading in the above input?
```INTEGER :: a, b, c, d

READ(*,"(I3, I4, I7, I1)")  a, b, c, d
```
Variable a takes the first 3 positions, which contain 1, 2 and a space. Thus, a receives 12. Variable b takes the next four positions, which contain 3, 4 and two spaces. Thus, b receives 34. Variable c takes the next seven positions, which contains 5, 6, two spaces, 7, 8 and a space. Hence, c receives 5678. Finally, the only position for d contains a space. Since if all w are spaces, the value is considered to be a zero and d receives zero.

If the system treats spaces as zeros, a, b, c and d receive 120, 3400, 5600780 and 0, respectively.

Since all variables have receives values, the remaining input are ignored. This is exactly the same as what you have learning in listed-directed READ.